Advertisement
Guest User

Untitled

a guest
Feb 26th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. @Override
  2. public int bulkInsert(Uri uri, ContentValues[] values) {
  3. final SQLiteDatabase db = feederDbHelper.getWritableDatabase();
  4. int match = sUriMatcher.match(uri);
  5. switch (match) {
  6. case CODE_INSERT_SOURCE:
  7. //Return the number of rows inserted from our implementation of bulkInsert
  8. return insertRecords(FeederContract.SourceEntry.TABLE_NAME, db, values, uri);
  9. case CODE_INSERT_ARTICLE:
  10. return insertRecords(FeederContract.ArticleEntry.TABLE_NAME, db, values, uri);
  11. default:
  12. return super.bulkInsert(uri, values);
  13. }
  14. }
  15.  
  16. public int insertRecords(String tabbleName, SQLiteDatabase db, ContentValues[] values, Uri uri) {
  17. db.beginTransaction();
  18. int rowsInserted = 0;
  19. try {
  20. for (ContentValues value : values) {
  21. long _id = db.insertWithOnConflict(tabbleName, null, value, SQLiteDatabase.CONFLICT_REPLACE);
  22. if (_id != -1) {
  23. rowsInserted++;
  24. }
  25. }
  26. db.setTransactionSuccessful();
  27. } finally {
  28. db.endTransaction();
  29. }
  30.  
  31. if (rowsInserted > 0) {
  32. getContext().getContentResolver().notifyChange(uri, null);
  33. }
  34. //Return the number of rows inserted from our implementation of bulkInsert
  35. return rowsInserted;
  36. }
  37.  
  38. @Nullable
  39. @Override
  40. public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
  41. View view = inflater.inflate(R.layout.feeds_fragment, container, false);
  42. ButterKnife.bind(this, view);
  43. loadAd();
  44. initRc();
  45. // Starting service to download feeds
  46. FeederSyncUtil.startSync(getActivity());
  47. // Starting loader to load feeds
  48. getActivity().getSupportLoaderManager().initLoader(ID_FEEDS_LOADER, null, this);
  49. return view;
  50. }
  51.  
  52. @Override
  53. public Loader<Cursor> onCreateLoader(int id, Bundle args) {
  54. return new CursorLoader(getActivity(),
  55. FeederContract.ArticleEntry.CONTENT_URI,
  56. MAIN_FEED_PROJECTION,
  57. null,
  58. null,
  59. null);
  60. }
  61.  
  62. @Override
  63. public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
  64. Log.d(TAG, data.getCount() + "");
  65. mFeedsAdapter.swapCursor(data);
  66. }
  67.  
  68. @Override
  69. public void onLoaderReset(Loader<Cursor> loader) {
  70. mFeedsAdapter.swapCursor(null);
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement