diff --git a/app/src/main/java/app/fedilab/android/BaseMainActivity.java b/app/src/main/java/app/fedilab/android/BaseMainActivity.java index ecc91c571..eb7c4c297 100644 --- a/app/src/main/java/app/fedilab/android/BaseMainActivity.java +++ b/app/src/main/java/app/fedilab/android/BaseMainActivity.java @@ -1096,7 +1096,7 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt binding.bottomNavView.removeBadge(R.id.nav_privates); } } - selectTab(Timeline.TimeLineEnum.CONVERSATION.getValue(), count); + setCounterToTab(Timeline.TimeLineEnum.CONVERSATION.getValue(), count); } @Override @@ -1112,9 +1112,15 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt binding.bottomNavView.removeBadge(R.id.nav_notifications); } } - selectTab(Timeline.TimeLineEnum.NOTIFICATION.getValue(), count); + setCounterToTab(Timeline.TimeLineEnum.NOTIFICATION.getValue(), count); } + /** + * Get the tab depending of its position + * + * @param slug String slug for the timeline + * @return int - position + */ private int getTabPosition(String slug) { int position = 0; for (int i = 0; i < binding.tabLayout.getTabCount(); i++) { @@ -1127,7 +1133,13 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt return -1; } - private void selectTab(String slug, int count) { + /** + * Set the counter to the tab depending of the slug + * + * @param slug - String slug for the pinned timeline + * @param count - int new messages + */ + private void setCounterToTab(String slug, int count) { int position = getTabPosition(slug); if (position >= 0 && position < binding.tabLayout.getTabCount()) { TabLayout.Tab tab = binding.tabLayout.getTabAt(position); @@ -1141,9 +1153,6 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt if (count > 0) { counter.setVisibility(View.VISIBLE); counter.setText(String.valueOf(count)); - } else { - counter.setVisibility(View.GONE); - counter.setText("0"); } } } @@ -1203,7 +1212,7 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt break; } } - selectTab(slug, count); + setCounterToTab(slug, count); } @Override diff --git a/app/src/main/java/app/fedilab/android/helper/PinnedTimelineHelper.java b/app/src/main/java/app/fedilab/android/helper/PinnedTimelineHelper.java index cb574adb5..8bae379fb 100644 --- a/app/src/main/java/app/fedilab/android/helper/PinnedTimelineHelper.java +++ b/app/src/main/java/app/fedilab/android/helper/PinnedTimelineHelper.java @@ -35,6 +35,7 @@ import android.view.View; import android.view.ViewGroup; import android.widget.EditText; import android.widget.LinearLayout; +import android.widget.TextView; import android.widget.Toast; import androidx.appcompat.app.AlertDialog; @@ -68,6 +69,7 @@ import app.fedilab.android.databinding.TabCustomViewBinding; import app.fedilab.android.exception.DBException; import app.fedilab.android.ui.fragment.timeline.FragmentMastodonConversation; import app.fedilab.android.ui.fragment.timeline.FragmentMastodonTimeline; +import app.fedilab.android.ui.fragment.timeline.FragmentNotificationContainer; import app.fedilab.android.ui.pageadapter.FedilabPageAdapter; import es.dmoral.toasty.Toasty; @@ -121,6 +123,11 @@ public class PinnedTimelineHelper { params.setMargins(0, 0, 0, actionBarHeight); } } + //Remove badge when reselecting + activityMainBinding.bottomNavView.setOnItemReselectedListener(item -> { + activityMainBinding.bottomNavView.removeBadge(item.getItemId()); + }); + activityMainBinding.viewPager.setLayoutParams(params); List pinnedTimelines = pinned.pinnedTimelines; @@ -495,10 +502,20 @@ public class PinnedTimelineHelper { @Override public void onTabReselected(TabLayout.Tab tab) { Fragment fragment = fedilabPageAdapter.getCurrentFragment(); + View view = tab.getCustomView(); + if (view != null) { + TextView counter = view.findViewById(R.id.tab_counter); + if (counter != null) { + counter.setVisibility(View.GONE); + counter.setText("0"); + } + } if (fragment instanceof FragmentMastodonTimeline) { ((FragmentMastodonTimeline) fragment).scrollToTop(); } else if (fragment instanceof FragmentMastodonConversation) { ((FragmentMastodonConversation) fragment).scrollToTop(); + } else if (fragment instanceof FragmentNotificationContainer) { + ((FragmentNotificationContainer) fragment).scrollToTop(); } } }); diff --git a/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonTimeline.java b/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonTimeline.java index 02485cc6b..12b6e937e 100644 --- a/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonTimeline.java +++ b/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonTimeline.java @@ -324,7 +324,7 @@ 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 || direction == DIRECTION.REFRESH)) { + if (insertedStatus >= 0 && update != null && direction != DIRECTION.FETCH_NEW && !fetchingMissing) { update.onUpdate(insertedStatus, timelineType, slug); } if (direction == DIRECTION.TOP && fetchingMissing) {