Advertisement
Kvarz

LoaderManager

Sep 23rd, 2016
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.92 KB | None | 0 0
  1.     private void initializeSortManager(final List<Call> callList, final IRequestView iRequestView) {
  2.         LoaderManager.LoaderCallbacks<ArrayList<BarEntry>> arrayListLoaderCallbacks = new LoaderManager.LoaderCallbacks<ArrayList<BarEntry>>() {
  3.             @Override
  4.             public Loader<ArrayList<BarEntry>> onCreateLoader(int id, Bundle args) {
  5.                 if (iRequestView instanceof CallsPresenter.ICallsView) {
  6.                     Timber.d("return new CallsEntryLoader");
  7.                     return new CallsEntryLoader(getActivity(), callList);
  8.                 } else if (iRequestView instanceof MessagesPresenter.IMessagesView) {
  9.                     Timber.d("return new MessagesEntryLoader");
  10.                     return new MessagesEntryLoader(getActivity(), callList);
  11.                 }
  12.                 throw new RuntimeException("Invalid Loader type");
  13.             }
  14.  
  15.             @Override
  16.             public void onLoadFinished(Loader<ArrayList<BarEntry>> loader, ArrayList<BarEntry> callEntries) {
  17.                 if (iRequestView instanceof CallsPresenter.ICallsView) {
  18.                     Timber.d("setCallsChartData Calls");
  19.                     setCallsChartData(callEntries);
  20.                 } else if (iRequestView instanceof MessagesPresenter.IMessagesView) {
  21.                     Timber.d("setCallsChartData Messages");
  22.                     setMessagesChartData(callEntries);
  23.                 }
  24.             }
  25.  
  26.             @Override
  27.             public void onLoaderReset(Loader<ArrayList<BarEntry>> loader) {
  28.  
  29.             }
  30.         };
  31.         if (isVisible() && iRequestView instanceof CallsPresenter.ICallsView) {
  32.             getLoaderManager().initLoader(0, null, arrayListLoaderCallbacks).forceLoad();
  33.         } else if (isVisible() && iRequestView instanceof MessagesPresenter.IMessagesView) {
  34.             getLoaderManager().initLoader(1, null, arrayListLoaderCallbacks).forceLoad();
  35.         }
  36.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement