Loading app/src/main/java/app/fedilab/android/BaseMainActivity.java +31 −6 Original line number Diff line number Diff line Loading @@ -37,7 +37,6 @@ import android.os.Looper; import android.text.Editable; import android.text.Html; import android.text.TextWatcher; import android.util.Log; import android.util.Patterns; import android.view.ContextThemeWrapper; import android.view.Gravity; Loading Loading @@ -150,7 +149,7 @@ import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; public abstract class BaseMainActivity extends BaseActivity implements NetworkStateReceiver.NetworkStateReceiverListener, FragmentMastodonTimeline.UpdateCounters { public abstract class BaseMainActivity extends BaseActivity implements NetworkStateReceiver.NetworkStateReceiverListener, FragmentMastodonTimeline.UpdateCounters, FragmentNotificationContainer.UpdateCounters, FragmentMastodonConversation.UpdateCounters { public static String currentInstance, currentToken, currentUserID, client_id, client_secret, software; public static HashMap<String, List<Emoji>> emojis = new HashMap<>(); Loading Loading @@ -1084,6 +1083,36 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt } } @Override public void onUpdateConversation(int count) { SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(BaseMainActivity.this); boolean singleBar = sharedpreferences.getBoolean(getString(R.string.SET_USE_SINGLE_TOPBAR), false); if (!singleBar) { if (count > 0) { binding.bottomNavView.getOrCreateBadge(R.id.nav_privates).setNumber(count); binding.bottomNavView.getBadge(R.id.nav_privates).setBackgroundColor(ContextCompat.getColor(BaseMainActivity.this, R.color.cyanea_accent_reference)); binding.bottomNavView.getBadge(R.id.nav_privates).setBadgeTextColor(ThemeHelper.getAttColor(BaseMainActivity.this, R.attr.mTextColor)); } else { binding.bottomNavView.removeBadge(R.id.nav_privates); } } } @Override public void onUpdateNotification(int count, String slug) { SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(BaseMainActivity.this); boolean singleBar = sharedpreferences.getBoolean(getString(R.string.SET_USE_SINGLE_TOPBAR), false); if (!singleBar) { if (count > 0) { binding.bottomNavView.getOrCreateBadge(R.id.nav_notifications).setNumber(count); binding.bottomNavView.getBadge(R.id.nav_notifications).setBackgroundColor(ContextCompat.getColor(BaseMainActivity.this, R.color.cyanea_accent_reference)); binding.bottomNavView.getBadge(R.id.nav_notifications).setBadgeTextColor(ThemeHelper.getAttColor(BaseMainActivity.this, R.attr.mTextColor)); } else { binding.bottomNavView.removeBadge(R.id.nav_notifications); } } } @Override public void onUpdate(int count, Timeline.TimeLineEnum type, String slug) { SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(BaseMainActivity.this); Loading Loading @@ -1139,16 +1168,12 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt } int selectedTab = binding.tabLayout.getSelectedTabPosition(); TabLayout.Tab tab = binding.tabLayout.getTabAt(selectedTab); Log.v(Helper.TAG, "selectedTab: " + selectedTab); Log.v(Helper.TAG, "tab: " + tab); View view = null; if (tab != null) { view = tab.getCustomView(); } if (view != null) { Log.v(Helper.TAG, "view: " + view); TextView counter = view.findViewById(R.id.tab_counter); Log.v(Helper.TAG, "counter: " + counter); if (counter != null) { if (count > 0) { counter.setVisibility(View.VISIBLE); Loading app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonConversation.java +15 −3 Original line number Diff line number Diff line Loading @@ -56,6 +56,7 @@ public class FragmentMastodonConversation extends Fragment implements Conversati private String max_id, min_id, min_id_fetch_more, max_id_fetch_more; private ConversationAdapter conversationAdapter; private LinearLayoutManager mLayoutManager; public UpdateCounters update; public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Loading Loading @@ -318,7 +319,11 @@ public class FragmentMastodonConversation extends Fragment implements Conversati flagLoading = fetched_conversations.pagination.max_id == null; binding.noAction.setVisibility(View.GONE); //Update the timeline with new statuses updateConversationListWith(fetched_conversations.conversations); int insertedConversations = updateConversationListWith(fetched_conversations.conversations); //For these directions, the app will display counters for new messages if (insertedConversations >= 0 && update != null && (direction == FragmentMastodonTimeline.DIRECTION.FETCH_NEW || direction == FragmentMastodonTimeline.DIRECTION.SCROLL_TOP || direction == FragmentMastodonTimeline.DIRECTION.REFRESH)) { update.onUpdateConversation(insertedConversations); } if (direction == FragmentMastodonTimeline.DIRECTION.TOP && fetchingMissing) { binding.recyclerView.scrollToPosition(getPosition(fetched_conversations.conversations.get(fetched_conversations.conversations.size() - 1)) + 1); } Loading Loading @@ -365,7 +370,8 @@ public class FragmentMastodonConversation extends Fragment implements Conversati * * @param conversationsReceived - List<Conversation> Conversation received */ private void updateConversationListWith(List<Conversation> conversationsReceived) { private int updateConversationListWith(List<Conversation> conversationsReceived) { int insertedConversations = 0; if (conversationsReceived != null && conversationsReceived.size() > 0) { for (Conversation conversationReceived : conversationsReceived) { int position = 0; Loading @@ -379,6 +385,9 @@ public class FragmentMastodonConversation extends Fragment implements Conversati if (!conversationList.contains(conversationReceived)) { conversationList.add(position, conversationReceived); conversationAdapter.notifyItemInserted(position); if (!conversationReceived.cached) { insertedConversations++; } } break; } Loading @@ -392,6 +401,7 @@ public class FragmentMastodonConversation extends Fragment implements Conversati } } } return insertedConversations; } Loading @@ -411,5 +421,7 @@ public class FragmentMastodonConversation extends Fragment implements Conversati route(FragmentMastodonTimeline.DIRECTION.BOTTOM, true, conversationToUpdate); } public interface UpdateCounters { void onUpdateConversation(int count); } } No newline at end of file app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonNotification.java +12 −2 Original line number Diff line number Diff line Loading @@ -63,6 +63,7 @@ public class FragmentMastodonNotification extends Fragment implements Notificati private boolean flagLoading; private List<Notification> notificationList; private NotificationAdapter notificationAdapter; private final BroadcastReceiver receive_action = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { Loading Loading @@ -465,7 +466,10 @@ public class FragmentMastodonNotification extends Fragment implements Notificati flagLoading = fetched_notifications.pagination.max_id == null; binding.noAction.setVisibility(View.GONE); //Update the timeline with new statuses updateNotificationListWith(fetched_notifications.notifications); int insertedStatus = updateNotificationListWith(fetched_notifications.notifications); if (insertedStatus >= 0 && FragmentNotificationContainer.update != null && notificationType == NotificationTypeEnum.ALL && (direction == FragmentMastodonTimeline.DIRECTION.FETCH_NEW || direction == FragmentMastodonTimeline.DIRECTION.SCROLL_TOP || direction == FragmentMastodonTimeline.DIRECTION.REFRESH)) { FragmentNotificationContainer.update.onUpdateNotification(insertedStatus, notificationType.getValue()); } if (direction == FragmentMastodonTimeline.DIRECTION.TOP && fetchingMissing) { binding.recyclerView.scrollToPosition(getPosition(fetched_notifications.notifications.get(fetched_notifications.notifications.size() - 1)) + 1); } Loading @@ -492,7 +496,8 @@ public class FragmentMastodonNotification extends Fragment implements Notificati * * @param notificationsReceived - List<Notification> Notifications received */ private void updateNotificationListWith(List<Notification> notificationsReceived) { private int updateNotificationListWith(List<Notification> notificationsReceived) { int insertedNotifications = 0; if (notificationsReceived != null && notificationsReceived.size() > 0) { for (Notification notificationReceived : notificationsReceived) { int position = 0; Loading @@ -506,6 +511,9 @@ public class FragmentMastodonNotification extends Fragment implements Notificati if (!notificationList.contains(notificationReceived)) { notificationList.add(position, notificationReceived); notificationAdapter.notifyItemInserted(position); if (!notificationReceived.cached) { insertedNotifications++; } } break; } Loading @@ -519,6 +527,7 @@ public class FragmentMastodonNotification extends Fragment implements Notificati } } } return insertedNotifications; } Loading Loading @@ -575,4 +584,5 @@ public class FragmentMastodonNotification extends Fragment implements Notificati return value; } } } No newline at end of file app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonTimeline.java +2 −3 Original line number Diff line number Diff line Loading @@ -323,9 +323,8 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter. } //Update the timeline with new statuses int insertedStatus = updateStatusListWith(fetched_statuses.statuses); //For these directions, the app will display counters for new messages if (insertedStatus >= 0 && update != null && (direction == DIRECTION.FETCH_NEW || direction == DIRECTION.SCROLL_TOP)) { if (insertedStatus >= 0 && update != null && (direction == DIRECTION.FETCH_NEW || direction == DIRECTION.SCROLL_TOP || direction == DIRECTION.REFRESH)) { update.onUpdate(insertedStatus, timelineType, slug); } if (direction == DIRECTION.TOP && fetchingMissing) { Loading Loading @@ -528,7 +527,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter. //Initialize with default params timelineParams = new TimelinesVM.TimelineParams(timelineType, direction, ident); timelineParams.limit = MastodonHelper.statusesPerCall(requireActivity()); if (direction == DIRECTION.REFRESH || direction == DIRECTION.SCROLL_TOP) { if (direction == DIRECTION.REFRESH || direction == DIRECTION.SCROLL_TOP || direction == DIRECTION.FETCH_NEW) { timelineParams.maxId = null; timelineParams.minId = null; } else if (direction == DIRECTION.BOTTOM) { Loading app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentNotificationContainer.java +4 −0 Original line number Diff line number Diff line Loading @@ -54,6 +54,7 @@ import es.dmoral.toasty.Toasty; public class FragmentNotificationContainer extends Fragment { private FragmentNotificationContainerBinding binding; public static UpdateCounters update; public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Loading Loading @@ -268,4 +269,7 @@ public class FragmentNotificationContainer extends Fragment { } public interface UpdateCounters { void onUpdateNotification(int count, String slug); } } Loading
app/src/main/java/app/fedilab/android/BaseMainActivity.java +31 −6 Original line number Diff line number Diff line Loading @@ -37,7 +37,6 @@ import android.os.Looper; import android.text.Editable; import android.text.Html; import android.text.TextWatcher; import android.util.Log; import android.util.Patterns; import android.view.ContextThemeWrapper; import android.view.Gravity; Loading Loading @@ -150,7 +149,7 @@ import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; public abstract class BaseMainActivity extends BaseActivity implements NetworkStateReceiver.NetworkStateReceiverListener, FragmentMastodonTimeline.UpdateCounters { public abstract class BaseMainActivity extends BaseActivity implements NetworkStateReceiver.NetworkStateReceiverListener, FragmentMastodonTimeline.UpdateCounters, FragmentNotificationContainer.UpdateCounters, FragmentMastodonConversation.UpdateCounters { public static String currentInstance, currentToken, currentUserID, client_id, client_secret, software; public static HashMap<String, List<Emoji>> emojis = new HashMap<>(); Loading Loading @@ -1084,6 +1083,36 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt } } @Override public void onUpdateConversation(int count) { SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(BaseMainActivity.this); boolean singleBar = sharedpreferences.getBoolean(getString(R.string.SET_USE_SINGLE_TOPBAR), false); if (!singleBar) { if (count > 0) { binding.bottomNavView.getOrCreateBadge(R.id.nav_privates).setNumber(count); binding.bottomNavView.getBadge(R.id.nav_privates).setBackgroundColor(ContextCompat.getColor(BaseMainActivity.this, R.color.cyanea_accent_reference)); binding.bottomNavView.getBadge(R.id.nav_privates).setBadgeTextColor(ThemeHelper.getAttColor(BaseMainActivity.this, R.attr.mTextColor)); } else { binding.bottomNavView.removeBadge(R.id.nav_privates); } } } @Override public void onUpdateNotification(int count, String slug) { SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(BaseMainActivity.this); boolean singleBar = sharedpreferences.getBoolean(getString(R.string.SET_USE_SINGLE_TOPBAR), false); if (!singleBar) { if (count > 0) { binding.bottomNavView.getOrCreateBadge(R.id.nav_notifications).setNumber(count); binding.bottomNavView.getBadge(R.id.nav_notifications).setBackgroundColor(ContextCompat.getColor(BaseMainActivity.this, R.color.cyanea_accent_reference)); binding.bottomNavView.getBadge(R.id.nav_notifications).setBadgeTextColor(ThemeHelper.getAttColor(BaseMainActivity.this, R.attr.mTextColor)); } else { binding.bottomNavView.removeBadge(R.id.nav_notifications); } } } @Override public void onUpdate(int count, Timeline.TimeLineEnum type, String slug) { SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(BaseMainActivity.this); Loading Loading @@ -1139,16 +1168,12 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt } int selectedTab = binding.tabLayout.getSelectedTabPosition(); TabLayout.Tab tab = binding.tabLayout.getTabAt(selectedTab); Log.v(Helper.TAG, "selectedTab: " + selectedTab); Log.v(Helper.TAG, "tab: " + tab); View view = null; if (tab != null) { view = tab.getCustomView(); } if (view != null) { Log.v(Helper.TAG, "view: " + view); TextView counter = view.findViewById(R.id.tab_counter); Log.v(Helper.TAG, "counter: " + counter); if (counter != null) { if (count > 0) { counter.setVisibility(View.VISIBLE); Loading
app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonConversation.java +15 −3 Original line number Diff line number Diff line Loading @@ -56,6 +56,7 @@ public class FragmentMastodonConversation extends Fragment implements Conversati private String max_id, min_id, min_id_fetch_more, max_id_fetch_more; private ConversationAdapter conversationAdapter; private LinearLayoutManager mLayoutManager; public UpdateCounters update; public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Loading Loading @@ -318,7 +319,11 @@ public class FragmentMastodonConversation extends Fragment implements Conversati flagLoading = fetched_conversations.pagination.max_id == null; binding.noAction.setVisibility(View.GONE); //Update the timeline with new statuses updateConversationListWith(fetched_conversations.conversations); int insertedConversations = updateConversationListWith(fetched_conversations.conversations); //For these directions, the app will display counters for new messages if (insertedConversations >= 0 && update != null && (direction == FragmentMastodonTimeline.DIRECTION.FETCH_NEW || direction == FragmentMastodonTimeline.DIRECTION.SCROLL_TOP || direction == FragmentMastodonTimeline.DIRECTION.REFRESH)) { update.onUpdateConversation(insertedConversations); } if (direction == FragmentMastodonTimeline.DIRECTION.TOP && fetchingMissing) { binding.recyclerView.scrollToPosition(getPosition(fetched_conversations.conversations.get(fetched_conversations.conversations.size() - 1)) + 1); } Loading Loading @@ -365,7 +370,8 @@ public class FragmentMastodonConversation extends Fragment implements Conversati * * @param conversationsReceived - List<Conversation> Conversation received */ private void updateConversationListWith(List<Conversation> conversationsReceived) { private int updateConversationListWith(List<Conversation> conversationsReceived) { int insertedConversations = 0; if (conversationsReceived != null && conversationsReceived.size() > 0) { for (Conversation conversationReceived : conversationsReceived) { int position = 0; Loading @@ -379,6 +385,9 @@ public class FragmentMastodonConversation extends Fragment implements Conversati if (!conversationList.contains(conversationReceived)) { conversationList.add(position, conversationReceived); conversationAdapter.notifyItemInserted(position); if (!conversationReceived.cached) { insertedConversations++; } } break; } Loading @@ -392,6 +401,7 @@ public class FragmentMastodonConversation extends Fragment implements Conversati } } } return insertedConversations; } Loading @@ -411,5 +421,7 @@ public class FragmentMastodonConversation extends Fragment implements Conversati route(FragmentMastodonTimeline.DIRECTION.BOTTOM, true, conversationToUpdate); } public interface UpdateCounters { void onUpdateConversation(int count); } } No newline at end of file
app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonNotification.java +12 −2 Original line number Diff line number Diff line Loading @@ -63,6 +63,7 @@ public class FragmentMastodonNotification extends Fragment implements Notificati private boolean flagLoading; private List<Notification> notificationList; private NotificationAdapter notificationAdapter; private final BroadcastReceiver receive_action = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { Loading Loading @@ -465,7 +466,10 @@ public class FragmentMastodonNotification extends Fragment implements Notificati flagLoading = fetched_notifications.pagination.max_id == null; binding.noAction.setVisibility(View.GONE); //Update the timeline with new statuses updateNotificationListWith(fetched_notifications.notifications); int insertedStatus = updateNotificationListWith(fetched_notifications.notifications); if (insertedStatus >= 0 && FragmentNotificationContainer.update != null && notificationType == NotificationTypeEnum.ALL && (direction == FragmentMastodonTimeline.DIRECTION.FETCH_NEW || direction == FragmentMastodonTimeline.DIRECTION.SCROLL_TOP || direction == FragmentMastodonTimeline.DIRECTION.REFRESH)) { FragmentNotificationContainer.update.onUpdateNotification(insertedStatus, notificationType.getValue()); } if (direction == FragmentMastodonTimeline.DIRECTION.TOP && fetchingMissing) { binding.recyclerView.scrollToPosition(getPosition(fetched_notifications.notifications.get(fetched_notifications.notifications.size() - 1)) + 1); } Loading @@ -492,7 +496,8 @@ public class FragmentMastodonNotification extends Fragment implements Notificati * * @param notificationsReceived - List<Notification> Notifications received */ private void updateNotificationListWith(List<Notification> notificationsReceived) { private int updateNotificationListWith(List<Notification> notificationsReceived) { int insertedNotifications = 0; if (notificationsReceived != null && notificationsReceived.size() > 0) { for (Notification notificationReceived : notificationsReceived) { int position = 0; Loading @@ -506,6 +511,9 @@ public class FragmentMastodonNotification extends Fragment implements Notificati if (!notificationList.contains(notificationReceived)) { notificationList.add(position, notificationReceived); notificationAdapter.notifyItemInserted(position); if (!notificationReceived.cached) { insertedNotifications++; } } break; } Loading @@ -519,6 +527,7 @@ public class FragmentMastodonNotification extends Fragment implements Notificati } } } return insertedNotifications; } Loading Loading @@ -575,4 +584,5 @@ public class FragmentMastodonNotification extends Fragment implements Notificati return value; } } } No newline at end of file
app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonTimeline.java +2 −3 Original line number Diff line number Diff line Loading @@ -323,9 +323,8 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter. } //Update the timeline with new statuses int insertedStatus = updateStatusListWith(fetched_statuses.statuses); //For these directions, the app will display counters for new messages if (insertedStatus >= 0 && update != null && (direction == DIRECTION.FETCH_NEW || direction == DIRECTION.SCROLL_TOP)) { if (insertedStatus >= 0 && update != null && (direction == DIRECTION.FETCH_NEW || direction == DIRECTION.SCROLL_TOP || direction == DIRECTION.REFRESH)) { update.onUpdate(insertedStatus, timelineType, slug); } if (direction == DIRECTION.TOP && fetchingMissing) { Loading Loading @@ -528,7 +527,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter. //Initialize with default params timelineParams = new TimelinesVM.TimelineParams(timelineType, direction, ident); timelineParams.limit = MastodonHelper.statusesPerCall(requireActivity()); if (direction == DIRECTION.REFRESH || direction == DIRECTION.SCROLL_TOP) { if (direction == DIRECTION.REFRESH || direction == DIRECTION.SCROLL_TOP || direction == DIRECTION.FETCH_NEW) { timelineParams.maxId = null; timelineParams.minId = null; } else if (direction == DIRECTION.BOTTOM) { Loading
app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentNotificationContainer.java +4 −0 Original line number Diff line number Diff line Loading @@ -54,6 +54,7 @@ import es.dmoral.toasty.Toasty; public class FragmentNotificationContainer extends Fragment { private FragmentNotificationContainerBinding binding; public static UpdateCounters update; public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Loading Loading @@ -268,4 +269,7 @@ public class FragmentNotificationContainer extends Fragment { } public interface UpdateCounters { void onUpdateNotification(int count, String slug); } }