Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Override
- public int bulkInsert(Uri uri, ContentValues[] values) {
- final SQLiteDatabase db = feederDbHelper.getWritableDatabase();
- int match = sUriMatcher.match(uri);
- switch (match) {
- case CODE_INSERT_SOURCE:
- //Return the number of rows inserted from our implementation of bulkInsert
- return insertRecords(FeederContract.SourceEntry.TABLE_NAME, db, values, uri);
- case CODE_INSERT_ARTICLE:
- return insertRecords(FeederContract.ArticleEntry.TABLE_NAME, db, values, uri);
- default:
- return super.bulkInsert(uri, values);
- }
- }
- public int insertRecords(String tabbleName, SQLiteDatabase db, ContentValues[] values, Uri uri) {
- db.beginTransaction();
- int rowsInserted = 0;
- try {
- for (ContentValues value : values) {
- long _id = db.insertWithOnConflict(tabbleName, null, value, SQLiteDatabase.CONFLICT_REPLACE);
- if (_id != -1) {
- rowsInserted++;
- }
- }
- db.setTransactionSuccessful();
- } finally {
- db.endTransaction();
- }
- if (rowsInserted > 0) {
- getContext().getContentResolver().notifyChange(uri, null);
- }
- //Return the number of rows inserted from our implementation of bulkInsert
- return rowsInserted;
- }
- @Nullable
- @Override
- public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
- View view = inflater.inflate(R.layout.feeds_fragment, container, false);
- ButterKnife.bind(this, view);
- loadAd();
- initRc();
- // Starting service to download feeds
- FeederSyncUtil.startSync(getActivity());
- // Starting loader to load feeds
- getActivity().getSupportLoaderManager().initLoader(ID_FEEDS_LOADER, null, this);
- return view;
- }
- @Override
- public Loader<Cursor> onCreateLoader(int id, Bundle args) {
- return new CursorLoader(getActivity(),
- FeederContract.ArticleEntry.CONTENT_URI,
- MAIN_FEED_PROJECTION,
- null,
- null,
- null);
- }
- @Override
- public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
- Log.d(TAG, data.getCount() + "");
- mFeedsAdapter.swapCursor(data);
- }
- @Override
- public void onLoaderReset(Loader<Cursor> loader) {
- mFeedsAdapter.swapCursor(null);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement