fix clear notifications crash (#458)

This commit is contained in:
Konrad Pozniak 2017-11-15 21:18:35 +01:00 committed by GitHub
parent ed22d65c68
commit 3204223af7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 18 deletions

View file

@ -156,6 +156,10 @@ public class MainActivity extends BaseActivity implements ActionButtonActivity {
viewPager.setCurrentItem(tab.getPosition()); viewPager.setCurrentItem(tab.getPosition());
tintTab(tab, true); tintTab(tab, true);
if(tab.getPosition() == 1) {
NotificationManager.clearNotifications(MainActivity.this);
}
} }
@Override @Override
@ -210,6 +214,10 @@ public class MainActivity extends BaseActivity implements ActionButtonActivity {
.putBoolean("refreshProfileHeader", false) .putBoolean("refreshProfileHeader", false)
.apply(); .apply();
} }
if(viewPager.getCurrentItem() == 1) {
NotificationManager.clearNotifications(this);
}
} }
@Override @Override

View file

@ -250,16 +250,6 @@ public class NotificationsFragment extends SFragment implements
super.onDestroyView(); super.onDestroyView();
} }
@Override
public void setUserVisibleHint(boolean isVisibleToUser) {
super.setUserVisibleHint(isVisibleToUser);
if (isVisibleToUser) {
//noinspection ConstantConditions
((NotificationManager) getContext().getSystemService(Context.NOTIFICATION_SERVICE))
.cancel(NotificationPullJobCreator.NOTIFY_ID);
}
}
@Override @Override
public void onRefresh() { public void onRefresh() {
sendFetchNotificationsRequest(null, topId, FetchEnd.TOP, -1); sendFetchNotificationsRequest(null, topId, FetchEnd.TOP, -1);

View file

@ -210,7 +210,8 @@ public class NotificationManager {
} }
} }
public static void clearNotifications(Context context) { public static void clearNotifications(@Nullable Context context) {
if(context != null) {
SharedPreferences notificationPreferences = SharedPreferences notificationPreferences =
context.getSharedPreferences("Notifications", Context.MODE_PRIVATE); context.getSharedPreferences("Notifications", Context.MODE_PRIVATE);
notificationPreferences.edit().putString("current", "[]").apply(); notificationPreferences.edit().putString("current", "[]").apply();
@ -220,6 +221,7 @@ public class NotificationManager {
//noinspection ConstantConditions //noinspection ConstantConditions
manager.cancel(NotificationPullJobCreator.NOTIFY_ID); manager.cancel(NotificationPullJobCreator.NOTIFY_ID);
} }
}
private static boolean filterNotification(SharedPreferences preferences, private static boolean filterNotification(SharedPreferences preferences,
Notification notification) { Notification notification) {