fix clear notifications crash (#458)
This commit is contained in:
parent
10313951be
commit
e3fe9819bf
@ -156,6 +156,10 @@ public class MainActivity extends BaseActivity implements ActionButtonActivity {
|
||||
viewPager.setCurrentItem(tab.getPosition());
|
||||
|
||||
tintTab(tab, true);
|
||||
|
||||
if(tab.getPosition() == 1) {
|
||||
NotificationManager.clearNotifications(MainActivity.this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -210,6 +214,10 @@ public class MainActivity extends BaseActivity implements ActionButtonActivity {
|
||||
.putBoolean("refreshProfileHeader", false)
|
||||
.apply();
|
||||
}
|
||||
|
||||
if(viewPager.getCurrentItem() == 1) {
|
||||
NotificationManager.clearNotifications(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -250,16 +250,6 @@ public class NotificationsFragment extends SFragment implements
|
||||
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
|
||||
public void onRefresh() {
|
||||
sendFetchNotificationsRequest(null, topId, FetchEnd.TOP, -1);
|
||||
|
@ -210,15 +210,17 @@ public class NotificationManager {
|
||||
}
|
||||
}
|
||||
|
||||
public static void clearNotifications(Context context) {
|
||||
SharedPreferences notificationPreferences =
|
||||
context.getSharedPreferences("Notifications", Context.MODE_PRIVATE);
|
||||
notificationPreferences.edit().putString("current", "[]").apply();
|
||||
public static void clearNotifications(@Nullable Context context) {
|
||||
if(context != null) {
|
||||
SharedPreferences notificationPreferences =
|
||||
context.getSharedPreferences("Notifications", Context.MODE_PRIVATE);
|
||||
notificationPreferences.edit().putString("current", "[]").apply();
|
||||
|
||||
android.app.NotificationManager manager = (android.app.NotificationManager)
|
||||
context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
//noinspection ConstantConditions
|
||||
manager.cancel(NotificationPullJobCreator.NOTIFY_ID);
|
||||
android.app.NotificationManager manager = (android.app.NotificationManager)
|
||||
context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
//noinspection ConstantConditions
|
||||
manager.cancel(NotificationPullJobCreator.NOTIFY_ID);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean filterNotification(SharedPreferences preferences,
|
||||
|
Loading…
Reference in New Issue
Block a user