From ef47c46171da2f589fc999c9c5b5b6d641811c75 Mon Sep 17 00:00:00 2001 From: stom79 Date: Wed, 6 Feb 2019 17:53:49 +0100 Subject: [PATCH] Fix some errors --- .../mastodon/activities/BaseMainActivity.java | 8 ++-- .../DisplayNotificationsFragment.java | 40 +++++++++---------- .../fragments/DisplayStatusFragment.java | 10 +++-- .../gouv/etalab/mastodon/helper/Helper.java | 1 - 4 files changed, 31 insertions(+), 28 deletions(-) diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseMainActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseMainActivity.java index 78248b08f..02591207f 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseMainActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseMainActivity.java @@ -2040,20 +2040,20 @@ public abstract class BaseMainActivity extends BaseActivity public void onResume(){ super.onResume(); PreferenceManager.getDefaultSharedPreferences(this).edit().putBoolean("isMainActivityRunning", true).apply(); - updateNotifCounter(); - updateHomeCounter(); + // updateNotifCounter(); + // updateHomeCounter(); //Proceeds to update of the authenticated account if(Helper.isLoggedIn(getApplicationContext())) { new UpdateAccountInfoByIDAsyncTask(getApplicationContext(), social, BaseMainActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } - if( lastHomeId != null && homeFragment != null){ + /*if( lastHomeId != null && homeFragment != null){ homeFragment.retrieveMissingToots(lastHomeId); } if( lastNotificationId != null && tabLayoutNotificationsFragment != null){ tabLayoutNotificationsFragment.retrieveMissingNotifications(lastNotificationId); - } + }*/ } diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayNotificationsFragment.java b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayNotificationsFragment.java index ceab98399..726ec35ca 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayNotificationsFragment.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayNotificationsFragment.java @@ -78,7 +78,7 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve private String userId, instance; private SharedPreferences sharedpreferences; LinearLayoutManager mLayoutManager; - private static BroadcastReceiver receive_action; + private BroadcastReceiver receive_action; private static BroadcastReceiver receive_data; public DisplayNotificationsFragment(){ @@ -145,7 +145,7 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve } }); - if( type == Type.ALL) { + if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) { if (receive_action != null) @@ -163,25 +163,25 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve } }; LocalBroadcastManager.getInstance(context).registerReceiver(receive_action, new IntentFilter(Helper.RECEIVE_ACTION)); - - if (receive_data != null) - LocalBroadcastManager.getInstance(context).unregisterReceiver(receive_data); - receive_data = new BroadcastReceiver() { - @Override - public void onReceive(Context context, Intent intent) { - Bundle b = intent.getExtras(); - assert b != null; - String userIdService = b.getString("userIdService", null); - if (userIdService != null && userIdService.equals(userId)) { - Notification notification = b.getParcelable("data"); - refresh(notification); - if (context instanceof MainActivity) - ((MainActivity) context).updateNotifCounter(); + if( type == Type.ALL) { + if (receive_data != null) + LocalBroadcastManager.getInstance(context).unregisterReceiver(receive_data); + receive_data = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + Bundle b = intent.getExtras(); + assert b != null; + String userIdService = b.getString("userIdService", null); + if (userIdService != null && userIdService.equals(userId)) { + Notification notification = b.getParcelable("data"); + refresh(notification); + if (context instanceof MainActivity) + ((MainActivity) context).updateNotifCounter(); + } } - } - }; - LocalBroadcastManager.getInstance(context).registerReceiver(receive_data, new IntentFilter(Helper.RECEIVE_DATA)); - } + }; + LocalBroadcastManager.getInstance(context).registerReceiver(receive_data, new IntentFilter(Helper.RECEIVE_DATA)); + } } swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayStatusFragment.java b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayStatusFragment.java index d5a34a9b0..62a3f6baf 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayStatusFragment.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayStatusFragment.java @@ -624,8 +624,9 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn context.startService(streamingHomeIntent); }catch (Exception ignored){} } - if( statuses != null && statuses.size() > 0) + if( statuses != null && statuses.size() > 0) { retrieveMissingToots(statuses.get(0).getId()); + } } } else if( type == RetrieveFeedsAsyncTask.Type.PUBLIC){ if( getUserVisibleHint() ){ @@ -704,8 +705,8 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn int batteryProfile = sharedpreferences.getInt(Helper.SET_BATTERY_PROFILE, Helper.BATTERY_PROFILE_NORMAL); //Store last toot id for home timeline to avoid to notify for those that have been already seen if (type == RetrieveFeedsAsyncTask.Type.HOME ) { - if (visible) { + SharedPreferences.Editor editor = sharedpreferences.edit(); editor.putBoolean(Helper.SHOULD_CONTINUE_STREAMING_HOME + userId + instance, true); editor.apply(); @@ -715,8 +716,9 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn context.startService(streamingHomeIntent); }catch (Exception ignored){} } - if( statuses != null && statuses.size() > 0) + if( statuses != null && statuses.size() > 0) { retrieveMissingToots(statuses.get(0).getId()); + } }else { if( streamingHomeIntent != null ){ SharedPreferences.Editor editor = sharedpreferences.edit(); @@ -915,6 +917,8 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn @Override public void onRetrieveFeedsAfterBookmark(APIResponse apiResponse) { + if( statusListAdapter == null) + return; if( apiResponse == null || (apiResponse.getError() != null && apiResponse.getError().getStatusCode() != 404) ){ if( apiResponse == null) Toasty.error(context, context.getString(R.string.toast_error),Toast.LENGTH_LONG).show(); diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java b/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java index c0927c2ff..afbc0302d 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java @@ -79,7 +79,6 @@ import android.text.TextPaint; import android.text.style.ClickableSpan; import android.text.style.URLSpan; import android.util.DisplayMetrics; -import android.util.Log; import android.util.Patterns; import android.view.Menu; import android.view.MenuItem;