Fix counter issues
This commit is contained in:
parent
6a712f2d36
commit
a3ecc7cbc9
|
@ -2135,6 +2135,7 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
displayStatusFragment.updateLastReadToot();
|
||||
} else if(tl.getType() == ManageTimelines.Type.NOTIFICATION) {
|
||||
countNewNotifications = 0;
|
||||
|
||||
updateNotifCounter();
|
||||
}else {
|
||||
View tabCustom = tab.getCustomView();
|
||||
|
@ -2469,6 +2470,16 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
}else {
|
||||
tabCounterNotif.setVisibility(View.GONE);
|
||||
}
|
||||
try{
|
||||
TabLayoutNotificationsFragment tabLayoutNotificationsFragment = (TabLayoutNotificationsFragment) mPageReferenceMap.get(position);
|
||||
ViewPager notifViewPager = tabLayoutNotificationsFragment.getViewPager();
|
||||
|
||||
if( notifViewPager != null && notifViewPager.getAdapter() != null) {
|
||||
DisplayNotificationsFragment displayNotificationsFragment = (DisplayNotificationsFragment) notifViewPager.getAdapter().instantiateItem(notifViewPager, 0);
|
||||
displayNotificationsFragment.updateNotificationRead();
|
||||
}
|
||||
}catch (Exception ignored){}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1615,8 +1615,8 @@ public class API {
|
|||
}else{
|
||||
if( statuses.size() > 0) {
|
||||
if( statuses.get(0).getId().matches("\\d+")){
|
||||
apiResponse.setSince_id(String.valueOf(Long.parseLong(statuses.get(0).getId())+1));
|
||||
apiResponse.setMax_id(String.valueOf(Long.parseLong(statuses.get(statuses.size() - 1).getId())-1));
|
||||
apiResponse.setSince_id(String.valueOf(statuses.get(0).getId()));
|
||||
apiResponse.setMax_id(statuses.get(statuses.size() - 1).getId());
|
||||
}else{
|
||||
apiResponse.setSince_id(statuses.get(0).getId());
|
||||
apiResponse.setMax_id(statuses.get(statuses.size() - 1).getId());
|
||||
|
@ -1697,8 +1697,8 @@ public class API {
|
|||
statuses = GNUAPI.parseStatuses(context, new JSONArray(response));
|
||||
if( statuses.size() > 0) {
|
||||
if(statuses.get(0).getId() != null && statuses.get(0).getId().matches("-?\\d+(\\.\\d+)?")) {
|
||||
apiResponse.setSince_id(String.valueOf(Long.parseLong(statuses.get(0).getId()) + 1));
|
||||
apiResponse.setMax_id(String.valueOf(Long.parseLong(statuses.get(statuses.size() - 1).getId()) - 1));
|
||||
apiResponse.setSince_id(String.valueOf(statuses.get(0).getId()));
|
||||
apiResponse.setMax_id(String.valueOf(statuses.get(statuses.size() - 1).getId()));
|
||||
}else{
|
||||
apiResponse.setSince_id(statuses.get(0).getId());
|
||||
apiResponse.setMax_id(statuses.get(statuses.size() - 1).getId());
|
||||
|
|
|
@ -259,8 +259,8 @@ public class GNUAPI {
|
|||
String response = httpsConnection.get(getAbsoluteUrl("/statusnet/groups/list.json"), 60, params, prefKeyOauthTokenT);
|
||||
accounts = parseGroups(context, new JSONArray(response));
|
||||
if( accounts.size() > 0) {
|
||||
apiResponse.setSince_id(String.valueOf(Long.parseLong(accounts.get(0).getId())+1));
|
||||
apiResponse.setMax_id(String.valueOf(Long.parseLong(accounts.get(accounts.size() - 1).getId())-1));
|
||||
apiResponse.setSince_id(accounts.get(0).getId());
|
||||
apiResponse.setMax_id(accounts.get(accounts.size() - 1).getId());
|
||||
}
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
setError(e.getStatusCode(), e);
|
||||
|
@ -369,8 +369,8 @@ public class GNUAPI {
|
|||
String response = httpsConnection.get(url, 60, params, prefKeyOauthTokenT);
|
||||
statuses = parseStatuses(context, new JSONArray(response));
|
||||
if( statuses.size() > 0) {
|
||||
apiResponse.setSince_id(String.valueOf(Long.parseLong(statuses.get(0).getId())+1));
|
||||
apiResponse.setMax_id(String.valueOf(Long.parseLong(statuses.get(statuses.size() - 1).getId())-1));
|
||||
apiResponse.setSince_id(statuses.get(0).getId());
|
||||
apiResponse.setMax_id(statuses.get(statuses.size() - 1).getId());
|
||||
}
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
setError(e.getStatusCode(), e);
|
||||
|
@ -573,8 +573,8 @@ public class GNUAPI {
|
|||
String response = httpsConnection.get(getAbsoluteUrl("/statuses/user_timeline.json"), 60, params, prefKeyOauthTokenT);
|
||||
statuses = parseStatuses(context, new JSONArray(response));
|
||||
if( statuses.size() > 0) {
|
||||
apiResponse.setSince_id(String.valueOf(Long.parseLong(statuses.get(0).getId())+1));
|
||||
apiResponse.setMax_id(String.valueOf(Long.parseLong(statuses.get(statuses.size() - 1).getId())-1));
|
||||
apiResponse.setSince_id(statuses.get(0).getId());
|
||||
apiResponse.setMax_id(statuses.get(statuses.size() - 1).getId());
|
||||
}
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
setError(e.getStatusCode(), e);
|
||||
|
@ -836,8 +836,8 @@ public class GNUAPI {
|
|||
String response = httpsConnection.get(getAbsoluteUrl("/direct_messages.json"), 60, params, prefKeyOauthTokenT);
|
||||
statuses = parseStatuses(context, new JSONArray(response));
|
||||
if( statuses.size() > 0) {
|
||||
apiResponse.setSince_id(String.valueOf(Long.parseLong(statuses.get(0).getId())+1));
|
||||
apiResponse.setMax_id(String.valueOf(Long.parseLong(statuses.get(statuses.size() - 1).getId())-1));
|
||||
apiResponse.setSince_id(statuses.get(0).getId());
|
||||
apiResponse.setMax_id(statuses.get(statuses.size() - 1).getId());
|
||||
}
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
setError(e.getStatusCode(), e);
|
||||
|
@ -910,8 +910,8 @@ public class GNUAPI {
|
|||
String response = httpsConnection.get(getAbsoluteUrl("/statuses/home_timeline.json"), 60, params, prefKeyOauthTokenT);
|
||||
statuses = parseStatuses(context, new JSONArray(response));
|
||||
if( statuses.size() > 0) {
|
||||
apiResponse.setSince_id(String.valueOf(Long.parseLong(statuses.get(0).getId())+1));
|
||||
apiResponse.setMax_id(String.valueOf(Long.parseLong(statuses.get(statuses.size() - 1).getId())-1));
|
||||
apiResponse.setSince_id(statuses.get(0).getId());
|
||||
apiResponse.setMax_id(statuses.get(statuses.size() - 1).getId());
|
||||
}
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
setError(e.getStatusCode(), e);
|
||||
|
@ -1004,8 +1004,8 @@ public class GNUAPI {
|
|||
String response = httpsConnection.get(url, 60, params, prefKeyOauthTokenT);
|
||||
statuses = parseStatuses(context, new JSONArray(response));
|
||||
if( statuses.size() > 0) {
|
||||
apiResponse.setSince_id(String.valueOf(Long.parseLong(statuses.get(0).getId())+1));
|
||||
apiResponse.setMax_id(String.valueOf(Long.parseLong(statuses.get(statuses.size() - 1).getId())-1));
|
||||
apiResponse.setSince_id(statuses.get(0).getId());
|
||||
apiResponse.setMax_id(statuses.get(statuses.size() - 1).getId());
|
||||
}
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
setError(e.getStatusCode(), e);
|
||||
|
@ -1156,8 +1156,8 @@ public class GNUAPI {
|
|||
String response = httpsConnection.get(getAbsoluteUrl(String.format("/timelines/tag/%s",query)), 60, params, prefKeyOauthTokenT);
|
||||
statuses = parseStatuses(context, new JSONArray(response));
|
||||
if( statuses.size() > 0) {
|
||||
apiResponse.setSince_id(String.valueOf(Long.parseLong(statuses.get(0).getId())+1));
|
||||
apiResponse.setMax_id(String.valueOf(Long.parseLong(statuses.get(statuses.size() - 1).getId())-1));
|
||||
apiResponse.setSince_id(statuses.get(0).getId());
|
||||
apiResponse.setMax_id(statuses.get(statuses.size() - 1).getId());
|
||||
}
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
setError(e.getStatusCode(), e);
|
||||
|
@ -1346,8 +1346,8 @@ public class GNUAPI {
|
|||
String response = httpsConnection.get(getAbsoluteUrl("/favorites.json"), 60, params, prefKeyOauthTokenT);
|
||||
statuses = parseStatuses(context, new JSONArray(response));
|
||||
if( statuses.size() > 0) {
|
||||
apiResponse.setSince_id(String.valueOf(Long.parseLong(statuses.get(0).getId())+1));
|
||||
apiResponse.setMax_id(String.valueOf(Long.parseLong(statuses.get(statuses.size() - 1).getId())-1));
|
||||
apiResponse.setSince_id(statuses.get(0).getId());
|
||||
apiResponse.setMax_id(statuses.get(statuses.size() - 1).getId());
|
||||
}
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
setError(e.getStatusCode(), e);
|
||||
|
@ -1826,8 +1826,8 @@ public class GNUAPI {
|
|||
String response = httpsConnection.get(getAbsoluteRemoteUrl(instance, "/statusnet/tags/timeline/"+query.trim().toLowerCase().replaceAll("\\#","")+".json"), 60, params, null);
|
||||
List<Status> statuses = parseStatuses(context, new JSONArray(response));
|
||||
if( statuses.size() > 0) {
|
||||
apiResponse.setSince_id(String.valueOf(Long.parseLong(statuses.get(0).getId())+1));
|
||||
apiResponse.setMax_id(String.valueOf(Long.parseLong(statuses.get(statuses.size() - 1).getId())-1));
|
||||
apiResponse.setSince_id(statuses.get(0).getId());
|
||||
apiResponse.setMax_id(statuses.get(statuses.size() - 1).getId());
|
||||
}
|
||||
apiResponse.setStatuses(statuses);
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
|
@ -1904,8 +1904,8 @@ public class GNUAPI {
|
|||
String response = httpsConnection.get(getAbsoluteUrl("/statusnet/tags/timeline/"+query.trim().toLowerCase().replaceAll("\\#","")+".json"), 60, params, null);
|
||||
List<Status> statuses = parseStatuses(context, new JSONArray(response));
|
||||
if( statuses.size() > 0) {
|
||||
apiResponse.setSince_id(String.valueOf(Long.parseLong(statuses.get(0).getId())+1));
|
||||
apiResponse.setMax_id(String.valueOf(Long.parseLong(statuses.get(statuses.size() - 1).getId())-1));
|
||||
apiResponse.setSince_id(statuses.get(0).getId());
|
||||
apiResponse.setMax_id(statuses.get(statuses.size() - 1).getId());
|
||||
}
|
||||
apiResponse.setStatuses(statuses);
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
|
|
|
@ -326,7 +326,7 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
|
|||
for(Notification tmpNotification: notifications){
|
||||
|
||||
if(type == Type.ALL) {
|
||||
if (lastReadNotifications != null && Long.parseLong(tmpNotification.getId()) > Long.parseLong(lastReadNotifications)) {
|
||||
if (lastReadNotifications != null && tmpNotification.getId().compareTo(lastReadNotifications) > 0) {
|
||||
countNewNotifications++;
|
||||
}
|
||||
try {
|
||||
|
@ -338,7 +338,7 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
|
|||
}
|
||||
if( firstLoad && type == Type.ALL) {
|
||||
//Update the id of the last notification retrieved
|
||||
if( MainActivity.lastNotificationId == null || Long.parseLong(notifications.get(0).getId()) > Long.parseLong(MainActivity.lastNotificationId)) {
|
||||
if( MainActivity.lastNotificationId == null || notifications.get(0).getId().compareTo(MainActivity.lastNotificationId) > 0) {
|
||||
MainActivity.lastNotificationId = notifications.get(0).getId();
|
||||
updateNotificationLastId(notifications.get(0).getId());
|
||||
}
|
||||
|
@ -452,7 +452,7 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
|
|||
int inserted = 0;
|
||||
for (int i = notifications.size()-1 ; i >= 0 ; i--) {
|
||||
if (this.notifications != null && this.notifications.size() == 0 ||
|
||||
notifications.get(i).getId().compareTo(this.notifications.get(0).getId()) >= 1) {
|
||||
notifications.get(i).getId().compareTo(this.notifications.get(0).getId()) > 0) {
|
||||
countNewNotifications++;
|
||||
this.notifications.add(0, notifications.get(i));
|
||||
inserted++;
|
||||
|
@ -474,7 +474,7 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
|
|||
private void updateNotificationLastId(String notificationId){
|
||||
if( type == Type.ALL) {
|
||||
String lastNotif = sharedpreferences.getString(Helper.LAST_NOTIFICATION_MAX_ID + userId + instance, null);
|
||||
if (lastNotif == null || notificationId.compareTo(lastNotif) >= 1) {
|
||||
if (lastNotif == null || notificationId.compareTo(lastNotif) >= 0) {
|
||||
countNewNotifications = 0;
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putString(Helper.LAST_NOTIFICATION_MAX_ID + userId + instance, notificationId);
|
||||
|
@ -482,4 +482,20 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Records the id of the notification only if its greater than the previous one.
|
||||
*/
|
||||
public void updateNotificationRead(){
|
||||
if( type == Type.ALL) {
|
||||
String lastNotif = sharedpreferences.getString(Helper.LAST_NOTIFICATION_MAX_ID + userId + instance, null);
|
||||
countNewNotifications = 0;
|
||||
if( this.notifications != null && this.notifications.size() > 0 && this.notifications.get(0).getId().compareTo(lastNotif) > 0) {
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putString(Helper.LAST_NOTIFICATION_MAX_ID + userId + instance, this.notifications.get(0).getId());
|
||||
editor.apply();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -244,7 +244,7 @@ public class DisplayPeertubeNotificationsFragment extends Fragment implements O
|
|||
private void updateNotificationLastId(String notificationId){
|
||||
|
||||
String lastNotif = sharedpreferences.getString(Helper.LAST_NOTIFICATION_MAX_ID + userId + instance, null);
|
||||
if( lastNotif == null || Long.parseLong(notificationId) > Long.parseLong(lastNotif)){
|
||||
if( lastNotif == null || notificationId.compareTo(lastNotif) > 0){
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putString(Helper.LAST_NOTIFICATION_MAX_ID + userId + instance, notificationId);
|
||||
editor.apply();
|
||||
|
@ -292,7 +292,7 @@ public class DisplayPeertubeNotificationsFragment extends Fragment implements O
|
|||
}
|
||||
if( firstLoad) {
|
||||
//Update the id of the last notification retrieved
|
||||
if( MainActivity.lastNotificationId == null || Long.parseLong(notifications.get(0).getId()) > Long.parseLong(MainActivity.lastNotificationId))
|
||||
if( MainActivity.lastNotificationId == null || notifications.get(0).getId().compareTo(MainActivity.lastNotificationId) > 0)
|
||||
MainActivity.lastNotificationId = notifications.get(0).getId();
|
||||
updateNotificationLastId(notifications.get(0).getId());
|
||||
}
|
||||
|
|
|
@ -158,7 +158,7 @@ public class NotificationsSyncJob extends Job {
|
|||
final List<Notification> notifications = new ArrayList<>();
|
||||
int pos = 0;
|
||||
for(Notification notif: notificationsReceived){
|
||||
if( max_id == null || Long.parseLong(notif.getId()) > Long.parseLong(max_id) ) {
|
||||
if( max_id == null || notif.getId().compareTo(max_id) > 0 ) {
|
||||
notifications.add(pos, notif);
|
||||
pos++;
|
||||
}
|
||||
|
@ -290,7 +290,7 @@ public class NotificationsSyncJob extends Job {
|
|||
notify_user(getContext(), account, intent, BitmapFactory.decodeResource(getContext().getResources(),
|
||||
R.drawable.mastodonlogo), finalNotifType, finalTitle, message);
|
||||
String lastNotif = sharedpreferences.getString(Helper.LAST_NOTIFICATION_MAX_ID + account.getId() + account.getInstance(), null);
|
||||
if( lastNotif == null || Long.parseLong(notifications.get(0).getId()) > Long.parseLong(lastNotif)){
|
||||
if( lastNotif == null || notifications.get(0).getId().compareTo(lastNotif) > 0){
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putString(Helper.LAST_NOTIFICATION_MAX_ID + account.getId() + account.getInstance(), notifications.get(0).getId());
|
||||
editor.apply();
|
||||
|
@ -303,7 +303,7 @@ public class NotificationsSyncJob extends Job {
|
|||
public void onResourceReady(@NonNull Bitmap resource, Transition<? super Bitmap> transition) {
|
||||
notify_user(getContext(), account, intent, resource, finalNotifType, finalTitle, message);
|
||||
String lastNotif = sharedpreferences.getString(Helper.LAST_NOTIFICATION_MAX_ID + account.getId() + account.getInstance(), null);
|
||||
if( lastNotif == null || Long.parseLong(notifications.get(0).getId()) > Long.parseLong(lastNotif)){
|
||||
if( lastNotif == null || notifications.get(0).getId().compareTo(lastNotif) > 0){
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putString(Helper.LAST_NOTIFICATION_MAX_ID + account.getId() + account.getInstance(), notifications.get(0).getId());
|
||||
editor.apply();
|
||||
|
|
|
@ -394,12 +394,6 @@ public class LiveNotificationService extends Service implements NetworkStateRece
|
|||
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) {
|
||||
Helper.notify_user(getApplicationContext(),account, intent, BitmapFactory.decodeResource(getResources(),
|
||||
R.drawable.mastodonlogo), finalNotifType, finalTitle, "@" + account.getAcct() + "@" + account.getInstance());
|
||||
String lastNotif = sharedpreferences.getString(Helper.LAST_NOTIFICATION_MAX_ID + account.getId() + account.getInstance(), null);
|
||||
if (lastNotif == null || notification.getId().compareTo(lastNotif) >= 1) {
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putString(Helper.LAST_NOTIFICATION_MAX_ID + account.getId() + account.getInstance(), notification.getId());
|
||||
editor.apply();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
})
|
||||
|
@ -408,12 +402,6 @@ public class LiveNotificationService extends Service implements NetworkStateRece
|
|||
public void onResourceReady(@NonNull Bitmap resource, Transition<? super Bitmap> transition) {
|
||||
|
||||
Helper.notify_user(getApplicationContext(), account,intent, resource, finalNotifType, finalTitle, "@" + account.getAcct() + "@" + account.getInstance());
|
||||
String lastNotif = sharedpreferences.getString(Helper.LAST_NOTIFICATION_MAX_ID + account.getId() + account.getInstance(), null);
|
||||
if (lastNotif == null || notification.getId().compareTo(lastNotif) >= 1) {
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putString(Helper.LAST_NOTIFICATION_MAX_ID + account.getId() + account.getInstance(), notification.getId());
|
||||
editor.apply();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue