Fix counter issue with notifications
This commit is contained in:
parent
48171de012
commit
db0fbc3b3c
|
@ -76,6 +76,7 @@ import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
|
|
||||||
|
@ -2339,7 +2340,11 @@ public abstract class BaseMainActivity extends BaseActivity
|
||||||
View tabHome = tabLayout.getTabAt(i).getCustomView();
|
View tabHome = tabLayout.getTabAt(i).getCustomView();
|
||||||
if( tabHome != null){
|
if( tabHome != null){
|
||||||
TextView tabCounterHome = tabHome.findViewById(R.id.tab_counter);
|
TextView tabCounterHome = tabHome.findViewById(R.id.tab_counter);
|
||||||
tabCounterHome.setText(String.valueOf(countNewStatus));
|
if(countNewStatus == Helper.TOOTS_PER_PAGE){
|
||||||
|
tabCounterHome.setText(String.format(Locale.getDefault(), "%d+", countNewStatus));
|
||||||
|
}else{
|
||||||
|
tabCounterHome.setText(String.valueOf(countNewStatus));
|
||||||
|
}
|
||||||
if( countNewStatus> 0){
|
if( countNewStatus> 0){
|
||||||
//New data are available
|
//New data are available
|
||||||
//The fragment is not displayed, so the counter is displayed
|
//The fragment is not displayed, so the counter is displayed
|
||||||
|
@ -2398,7 +2403,11 @@ public abstract class BaseMainActivity extends BaseActivity
|
||||||
TextView tabCounterNotif = tabNotif.findViewById(R.id.tab_counter);
|
TextView tabCounterNotif = tabNotif.findViewById(R.id.tab_counter);
|
||||||
if( tabCounterNotif == null)
|
if( tabCounterNotif == null)
|
||||||
return;
|
return;
|
||||||
tabCounterNotif.setText(String.valueOf(countNewNotifications));
|
if(countNewNotifications == Helper.NOTIFICATIONS_PER_PAGE){
|
||||||
|
tabCounterNotif.setText(String.format(Locale.getDefault(), "%d+", countNewNotifications));
|
||||||
|
}else{
|
||||||
|
tabCounterNotif.setText(String.valueOf(countNewNotifications));
|
||||||
|
}
|
||||||
if( countNewNotifications > 0){
|
if( countNewNotifications > 0){
|
||||||
tabCounterNotif.setVisibility(View.VISIBLE);
|
tabCounterNotif.setVisibility(View.VISIBLE);
|
||||||
}else {
|
}else {
|
||||||
|
|
|
@ -30,6 +30,7 @@ import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
@ -54,6 +55,8 @@ import app.fedilab.android.asynctasks.UpdateAccountInfoAsyncTask;
|
||||||
import app.fedilab.android.interfaces.OnRetrieveMissingNotificationsInterface;
|
import app.fedilab.android.interfaces.OnRetrieveMissingNotificationsInterface;
|
||||||
import app.fedilab.android.interfaces.OnRetrieveNotificationsInterface;
|
import app.fedilab.android.interfaces.OnRetrieveNotificationsInterface;
|
||||||
|
|
||||||
|
import static app.fedilab.android.activities.BaseMainActivity.countNewNotifications;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Thomas on 28/04/2017.
|
* Created by Thomas on 28/04/2017.
|
||||||
|
@ -188,7 +191,7 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
|
||||||
flag_loading = true;
|
flag_loading = true;
|
||||||
swiped = true;
|
swiped = true;
|
||||||
if(type == Type.ALL) {
|
if(type == Type.ALL) {
|
||||||
MainActivity.countNewNotifications = 0;
|
countNewNotifications = 0;
|
||||||
try {
|
try {
|
||||||
((MainActivity) context).updateNotifCounter();
|
((MainActivity) context).updateNotifCounter();
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
|
@ -300,7 +303,7 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
|
||||||
|
|
||||||
if(type == Type.ALL) {
|
if(type == Type.ALL) {
|
||||||
if (lastReadNotifications != null && Long.parseLong(tmpNotification.getId()) > Long.parseLong(lastReadNotifications)) {
|
if (lastReadNotifications != null && Long.parseLong(tmpNotification.getId()) > Long.parseLong(lastReadNotifications)) {
|
||||||
MainActivity.countNewNotifications++;
|
countNewNotifications++;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
((MainActivity) context).updateNotifCounter();
|
((MainActivity) context).updateNotifCounter();
|
||||||
|
@ -333,7 +336,7 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
|
||||||
* Called from main activity in onResume to retrieve missing notifications
|
* Called from main activity in onResume to retrieve missing notifications
|
||||||
* @param sinceId String
|
* @param sinceId String
|
||||||
*/
|
*/
|
||||||
public void retrieveMissingNotifications(String sinceId){
|
void retrieveMissingNotifications(String sinceId){
|
||||||
asyncTask = new RetrieveMissingNotificationsAsyncTask(context, type, sinceId, DisplayNotificationsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
asyncTask = new RetrieveMissingNotificationsAsyncTask(context, type, sinceId, DisplayNotificationsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -366,7 +369,7 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
|
||||||
flag_loading = true;
|
flag_loading = true;
|
||||||
swiped = true;
|
swiped = true;
|
||||||
if(type == Type.ALL) {
|
if(type == Type.ALL) {
|
||||||
MainActivity.countNewNotifications = 0;
|
countNewNotifications = 0;
|
||||||
}
|
}
|
||||||
asyncTask = new RetrieveNotificationsAsyncTask(context, type,true, null, null, DisplayNotificationsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
asyncTask = new RetrieveNotificationsAsyncTask(context, type,true, null, null, DisplayNotificationsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||||
}
|
}
|
||||||
|
@ -383,7 +386,7 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
|
||||||
notifications.add(0, notification);
|
notifications.add(0, notification);
|
||||||
if( type == Type.ALL) {
|
if( type == Type.ALL) {
|
||||||
MainActivity.lastNotificationId = notification.getId();
|
MainActivity.lastNotificationId = notification.getId();
|
||||||
MainActivity.countNewNotifications++;
|
countNewNotifications++;
|
||||||
try {
|
try {
|
||||||
((MainActivity) context).updateNotifCounter();
|
((MainActivity) context).updateNotifCounter();
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
|
@ -411,10 +414,9 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
|
||||||
notificationsListAdapter.notifyItemRangeChanged(0,this.notifications.size());
|
notificationsListAdapter.notifyItemRangeChanged(0,this.notifications.size());
|
||||||
}
|
}
|
||||||
if( notifications != null && notifications.size() > 0) {
|
if( notifications != null && notifications.size() > 0) {
|
||||||
|
|
||||||
if( type == Type.ALL) {
|
if( type == Type.ALL) {
|
||||||
//Update the id of the last notification retrieved
|
//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 || Long.parseLong(notifications.get(0).getId()) >= Long.parseLong(MainActivity.lastNotificationId)) {
|
||||||
MainActivity.lastNotificationId = notifications.get(0).getId();
|
MainActivity.lastNotificationId = notifications.get(0).getId();
|
||||||
updateNotificationLastId(notifications.get(0).getId());
|
updateNotificationLastId(notifications.get(0).getId());
|
||||||
}
|
}
|
||||||
|
@ -427,7 +429,7 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
|
||||||
for (int i = notifications.size()-1 ; i >= 0 ; i--) {
|
for (int i = notifications.size()-1 ; i >= 0 ; i--) {
|
||||||
if (this.notifications != null && this.notifications.size() == 0 ||
|
if (this.notifications != null && this.notifications.size() == 0 ||
|
||||||
Long.parseLong(notifications.get(i).getId()) > Long.parseLong(this.notifications.get(0).getId())) {
|
Long.parseLong(notifications.get(i).getId()) > Long.parseLong(this.notifications.get(0).getId())) {
|
||||||
MainActivity.countNewNotifications++;
|
countNewNotifications++;
|
||||||
this.notifications.add(0, notifications.get(i));
|
this.notifications.add(0, notifications.get(i));
|
||||||
inserted++;
|
inserted++;
|
||||||
}
|
}
|
||||||
|
@ -449,7 +451,7 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
|
||||||
if( type == Type.ALL) {
|
if( type == Type.ALL) {
|
||||||
String lastNotif = sharedpreferences.getString(Helper.LAST_NOTIFICATION_MAX_ID + userId + instance, null);
|
String lastNotif = sharedpreferences.getString(Helper.LAST_NOTIFICATION_MAX_ID + userId + instance, null);
|
||||||
if (lastNotif == null || Long.parseLong(notificationId) > Long.parseLong(lastNotif)) {
|
if (lastNotif == null || Long.parseLong(notificationId) > Long.parseLong(lastNotif)) {
|
||||||
MainActivity.countNewNotifications = 0;
|
countNewNotifications = 0;
|
||||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||||
editor.putString(Helper.LAST_NOTIFICATION_MAX_ID + userId + instance, notificationId);
|
editor.putString(Helper.LAST_NOTIFICATION_MAX_ID + userId + instance, notificationId);
|
||||||
editor.apply();
|
editor.apply();
|
||||||
|
|
Loading…
Reference in New Issue