Prevent pull notifications from notifying about things already loaded in fragment
Dismiss notifications when viewing fragment (moved to onResume)
This commit is contained in:
parent
51a0cf9330
commit
03fb9f45b2
|
@ -17,6 +17,7 @@ package com.keylesspalace.tusky;
|
||||||
|
|
||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
|
@ -58,9 +59,6 @@ public class NotificationsFragment extends SFragment implements
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
NotificationManager notificationManager =
|
|
||||||
(NotificationManager) getActivity().getSystemService(Context.NOTIFICATION_SERVICE);
|
|
||||||
notificationManager.cancel(PullNotificationService.NOTIFY_ID);
|
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,6 +117,15 @@ public class NotificationsFragment extends SFragment implements
|
||||||
return rootView;
|
return rootView;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
|
||||||
|
// When we view this fragment, dismiss the notifications
|
||||||
|
NotificationManager notificationManager = (NotificationManager) getActivity().getSystemService(Context.NOTIFICATION_SERVICE);
|
||||||
|
notificationManager.cancel(PullNotificationService.NOTIFY_ID);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroyView() {
|
public void onDestroyView() {
|
||||||
TabLayout tabLayout = (TabLayout) getActivity().findViewById(R.id.tab_layout);
|
TabLayout tabLayout = (TabLayout) getActivity().findViewById(R.id.tab_layout);
|
||||||
|
@ -165,6 +172,13 @@ public class NotificationsFragment extends SFragment implements
|
||||||
if (notifications.size() > 0 && !findNotification(notifications, fromId)) {
|
if (notifications.size() > 0 && !findNotification(notifications, fromId)) {
|
||||||
setFetchTimelineState(FooterViewHolder.State.LOADING);
|
setFetchTimelineState(FooterViewHolder.State.LOADING);
|
||||||
adapter.addItems(notifications);
|
adapter.addItems(notifications);
|
||||||
|
|
||||||
|
// Set last update id for pull notifications so that we don't get notified
|
||||||
|
// about things we already loaded here
|
||||||
|
SharedPreferences preferences = getActivity().getSharedPreferences(getString(R.string.preferences_file_key), Context.MODE_PRIVATE);
|
||||||
|
SharedPreferences.Editor editor = preferences.edit();
|
||||||
|
editor.putString("lastUpdateId", notifications.get(0).id);
|
||||||
|
editor.apply();
|
||||||
} else {
|
} else {
|
||||||
setFetchTimelineState(FooterViewHolder.State.END_OF_TIMELINE);
|
setFetchTimelineState(FooterViewHolder.State.END_OF_TIMELINE);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue