forked from mirrors/Fedilab
		
	Fix counters
This commit is contained in:
		
							parent
							
								
									a2406f23a5
								
							
						
					
					
						commit
						77dcb6db31
					
				
					 3 changed files with 34 additions and 8 deletions
				
			
		|  | @ -1096,7 +1096,7 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt | ||||||
|                 binding.bottomNavView.removeBadge(R.id.nav_privates); |                 binding.bottomNavView.removeBadge(R.id.nav_privates); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         selectTab(Timeline.TimeLineEnum.CONVERSATION.getValue(), count); |         setCounterToTab(Timeline.TimeLineEnum.CONVERSATION.getValue(), count); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @Override |     @Override | ||||||
|  | @ -1112,9 +1112,15 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt | ||||||
|                 binding.bottomNavView.removeBadge(R.id.nav_notifications); |                 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) { |     private int getTabPosition(String slug) { | ||||||
|         int position = 0; |         int position = 0; | ||||||
|         for (int i = 0; i < binding.tabLayout.getTabCount(); i++) { |         for (int i = 0; i < binding.tabLayout.getTabCount(); i++) { | ||||||
|  | @ -1127,7 +1133,13 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt | ||||||
|         return -1; |         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); |         int position = getTabPosition(slug); | ||||||
|         if (position >= 0 && position < binding.tabLayout.getTabCount()) { |         if (position >= 0 && position < binding.tabLayout.getTabCount()) { | ||||||
|             TabLayout.Tab tab = binding.tabLayout.getTabAt(position); |             TabLayout.Tab tab = binding.tabLayout.getTabAt(position); | ||||||
|  | @ -1141,9 +1153,6 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt | ||||||
|                     if (count > 0) { |                     if (count > 0) { | ||||||
|                         counter.setVisibility(View.VISIBLE); |                         counter.setVisibility(View.VISIBLE); | ||||||
|                         counter.setText(String.valueOf(count)); |                         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; |                     break; | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         selectTab(slug, count); |         setCounterToTab(slug, count); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @Override |     @Override | ||||||
|  |  | ||||||
|  | @ -35,6 +35,7 @@ import android.view.View; | ||||||
| import android.view.ViewGroup; | import android.view.ViewGroup; | ||||||
| import android.widget.EditText; | import android.widget.EditText; | ||||||
| import android.widget.LinearLayout; | import android.widget.LinearLayout; | ||||||
|  | import android.widget.TextView; | ||||||
| import android.widget.Toast; | import android.widget.Toast; | ||||||
| 
 | 
 | ||||||
| import androidx.appcompat.app.AlertDialog; | 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.exception.DBException; | ||||||
| import app.fedilab.android.ui.fragment.timeline.FragmentMastodonConversation; | import app.fedilab.android.ui.fragment.timeline.FragmentMastodonConversation; | ||||||
| import app.fedilab.android.ui.fragment.timeline.FragmentMastodonTimeline; | import app.fedilab.android.ui.fragment.timeline.FragmentMastodonTimeline; | ||||||
|  | import app.fedilab.android.ui.fragment.timeline.FragmentNotificationContainer; | ||||||
| import app.fedilab.android.ui.pageadapter.FedilabPageAdapter; | import app.fedilab.android.ui.pageadapter.FedilabPageAdapter; | ||||||
| import es.dmoral.toasty.Toasty; | import es.dmoral.toasty.Toasty; | ||||||
| 
 | 
 | ||||||
|  | @ -121,6 +123,11 @@ public class PinnedTimelineHelper { | ||||||
|                 params.setMargins(0, 0, 0, actionBarHeight); |                 params.setMargins(0, 0, 0, actionBarHeight); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |         //Remove badge when reselecting | ||||||
|  |         activityMainBinding.bottomNavView.setOnItemReselectedListener(item -> { | ||||||
|  |             activityMainBinding.bottomNavView.removeBadge(item.getItemId()); | ||||||
|  |         }); | ||||||
|  | 
 | ||||||
|         activityMainBinding.viewPager.setLayoutParams(params); |         activityMainBinding.viewPager.setLayoutParams(params); | ||||||
|         List<PinnedTimeline> pinnedTimelines = pinned.pinnedTimelines; |         List<PinnedTimeline> pinnedTimelines = pinned.pinnedTimelines; | ||||||
| 
 | 
 | ||||||
|  | @ -495,10 +502,20 @@ public class PinnedTimelineHelper { | ||||||
|             @Override |             @Override | ||||||
|             public void onTabReselected(TabLayout.Tab tab) { |             public void onTabReselected(TabLayout.Tab tab) { | ||||||
|                 Fragment fragment = fedilabPageAdapter.getCurrentFragment(); |                 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) { |                 if (fragment instanceof FragmentMastodonTimeline) { | ||||||
|                     ((FragmentMastodonTimeline) fragment).scrollToTop(); |                     ((FragmentMastodonTimeline) fragment).scrollToTop(); | ||||||
|                 } else if (fragment instanceof FragmentMastodonConversation) { |                 } else if (fragment instanceof FragmentMastodonConversation) { | ||||||
|                     ((FragmentMastodonConversation) fragment).scrollToTop(); |                     ((FragmentMastodonConversation) fragment).scrollToTop(); | ||||||
|  |                 } else if (fragment instanceof FragmentNotificationContainer) { | ||||||
|  |                     ((FragmentNotificationContainer) fragment).scrollToTop(); | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|         }); |         }); | ||||||
|  |  | ||||||
|  | @ -324,7 +324,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter. | ||||||
|             //Update the timeline with new statuses |             //Update the timeline with new statuses | ||||||
|             int insertedStatus = updateStatusListWith(fetched_statuses.statuses); |             int insertedStatus = updateStatusListWith(fetched_statuses.statuses); | ||||||
|             //For these directions, the app will display counters for new messages |             //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); |                 update.onUpdate(insertedStatus, timelineType, slug); | ||||||
|             } |             } | ||||||
|             if (direction == DIRECTION.TOP && fetchingMissing) { |             if (direction == DIRECTION.TOP && fetchingMissing) { | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue