Moves task in onAttach to avoid null context

This commit is contained in:
stom79 2017-11-03 08:38:36 +01:00
parent eb15a19413
commit ea10840893
1 changed files with 5 additions and 5 deletions

View File

@ -103,7 +103,7 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
int visibleItemCount = mLayoutManager.getChildCount();
int totalItemCount = mLayoutManager.getItemCount();
int firstVisibleItem = mLayoutManager.findFirstVisibleItemPosition();
if (firstVisibleItem + visibleItemCount == totalItemCount) {
if (firstVisibleItem + visibleItemCount == totalItemCount && context != null) {
if (!flag_loading) {
flag_loading = true;
asyncTask = new RetrieveNotificationsAsyncTask(context, true, null, null, max_id, null, null, DisplayNotificationsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
@ -125,16 +125,14 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
flag_loading = true;
swiped = true;
MainActivity.countNewNotifications = 0;
asyncTask = new RetrieveNotificationsAsyncTask(context, true, null, null, max_id, null, null, DisplayNotificationsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
if( context != null)
asyncTask = new RetrieveNotificationsAsyncTask(context, true, null, null, max_id, null, null, DisplayNotificationsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
});
swipeRefreshLayout.setColorSchemeResources(R.color.mastodonC4,
R.color.mastodonC2,
R.color.mastodonC3);
asyncTask = new RetrieveNotificationsAsyncTask(context, true, null, null, max_id, null, null, DisplayNotificationsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
return rootView;
}
@ -152,6 +150,8 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
public void onAttach(Context context) {
super.onAttach(context);
this.context = context;
if( context != null)
asyncTask = new RetrieveNotificationsAsyncTask(context, true, null, null, max_id, null, null, DisplayNotificationsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
public void onDestroy() {