Detects tab with tag
This commit is contained in:
parent
d8f8c2dc0d
commit
a2406f23a5
|
@ -1096,10 +1096,11 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUpdateNotification(int count, String slug) {
|
public void onUpdateNotification(int count) {
|
||||||
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(BaseMainActivity.this);
|
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(BaseMainActivity.this);
|
||||||
boolean singleBar = sharedpreferences.getBoolean(getString(R.string.SET_USE_SINGLE_TOPBAR), false);
|
boolean singleBar = sharedpreferences.getBoolean(getString(R.string.SET_USE_SINGLE_TOPBAR), false);
|
||||||
if (!singleBar) {
|
if (!singleBar) {
|
||||||
|
@ -1111,6 +1112,42 @@ 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getTabPosition(String slug) {
|
||||||
|
int position = 0;
|
||||||
|
for (int i = 0; i < binding.tabLayout.getTabCount(); i++) {
|
||||||
|
TabLayout.Tab tab = binding.tabLayout.getTabAt(i);
|
||||||
|
if (tab != null && tab.getTag() != null && tab.getTag().equals(slug)) {
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
position++;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void selectTab(String slug, int count) {
|
||||||
|
int position = getTabPosition(slug);
|
||||||
|
if (position >= 0 && position < binding.tabLayout.getTabCount()) {
|
||||||
|
TabLayout.Tab tab = binding.tabLayout.getTabAt(position);
|
||||||
|
View view = null;
|
||||||
|
if (tab != null) {
|
||||||
|
view = tab.getCustomView();
|
||||||
|
}
|
||||||
|
if (view != null) {
|
||||||
|
TextView counter = view.findViewById(R.id.tab_counter);
|
||||||
|
if (counter != null) {
|
||||||
|
if (count > 0) {
|
||||||
|
counter.setVisibility(View.VISIBLE);
|
||||||
|
counter.setText(String.valueOf(count));
|
||||||
|
} else {
|
||||||
|
counter.setVisibility(View.GONE);
|
||||||
|
counter.setText("0");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1166,25 +1203,7 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int selectedTab = binding.tabLayout.getSelectedTabPosition();
|
selectTab(slug, count);
|
||||||
TabLayout.Tab tab = binding.tabLayout.getTabAt(selectedTab);
|
|
||||||
View view = null;
|
|
||||||
if (tab != null) {
|
|
||||||
view = tab.getCustomView();
|
|
||||||
}
|
|
||||||
if (view != null) {
|
|
||||||
TextView counter = view.findViewById(R.id.tab_counter);
|
|
||||||
if (counter != null) {
|
|
||||||
if (count > 0) {
|
|
||||||
counter.setVisibility(View.VISIBLE);
|
|
||||||
counter.setText(String.valueOf(count));
|
|
||||||
} else {
|
|
||||||
counter.setVisibility(View.GONE);
|
|
||||||
counter.setText("0");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -245,6 +245,7 @@ public class PinnedTimelineHelper {
|
||||||
List<PinnedTimeline> pinnedToRemove = new ArrayList<>();
|
List<PinnedTimeline> pinnedToRemove = new ArrayList<>();
|
||||||
for (PinnedTimeline pinnedTimeline : pinned.pinnedTimelines) {
|
for (PinnedTimeline pinnedTimeline : pinned.pinnedTimelines) {
|
||||||
//Default timelines are not added if we are not in the single bar mode
|
//Default timelines are not added if we are not in the single bar mode
|
||||||
|
String ident = null;
|
||||||
if (!singleBar) {
|
if (!singleBar) {
|
||||||
switch (pinnedTimeline.type) {
|
switch (pinnedTimeline.type) {
|
||||||
case HOME:
|
case HOME:
|
||||||
|
@ -262,14 +263,23 @@ public class PinnedTimelineHelper {
|
||||||
switch (pinnedTimeline.type) {
|
switch (pinnedTimeline.type) {
|
||||||
case LIST:
|
case LIST:
|
||||||
name = pinnedTimeline.mastodonList.title;
|
name = pinnedTimeline.mastodonList.title;
|
||||||
|
ident = "@l@" + pinnedTimeline.mastodonList.id;
|
||||||
break;
|
break;
|
||||||
case TAG:
|
case TAG:
|
||||||
name = pinnedTimeline.tagTimeline.displayName != null && !pinnedTimeline.tagTimeline.displayName.isEmpty() ? pinnedTimeline.tagTimeline.displayName : pinnedTimeline.tagTimeline.name.replaceAll("#", "");
|
name = pinnedTimeline.tagTimeline.displayName != null && !pinnedTimeline.tagTimeline.displayName.isEmpty() ? pinnedTimeline.tagTimeline.displayName : pinnedTimeline.tagTimeline.name.replaceAll("#", "");
|
||||||
|
ident = "@T@" + name;
|
||||||
break;
|
break;
|
||||||
case REMOTE:
|
case REMOTE:
|
||||||
name = pinnedTimeline.remoteInstance.host;
|
name = pinnedTimeline.remoteInstance.host;
|
||||||
|
if (pinnedTimeline.remoteInstance.type == RemoteInstance.InstanceType.NITTER) {
|
||||||
|
String remoteInstance = sharedpreferences.getString(activity.getString(R.string.SET_NITTER_HOST), activity.getString(R.string.DEFAULT_NITTER_HOST)).toLowerCase();
|
||||||
|
ident = "@R@" + remoteInstance;
|
||||||
|
} else {
|
||||||
|
ident = "@R@" + pinnedTimeline.remoteInstance.host;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pinnedTimeline.type == Timeline.TimeLineEnum.LIST || pinnedTimeline.type == Timeline.TimeLineEnum.TAG || pinnedTimeline.type == Timeline.TimeLineEnum.REMOTE) {
|
if (pinnedTimeline.type == Timeline.TimeLineEnum.LIST || pinnedTimeline.type == Timeline.TimeLineEnum.TAG || pinnedTimeline.type == Timeline.TimeLineEnum.REMOTE) {
|
||||||
TabCustomViewBinding tabCustomViewBinding = TabCustomViewBinding.inflate(activity.getLayoutInflater());
|
TabCustomViewBinding tabCustomViewBinding = TabCustomViewBinding.inflate(activity.getLayoutInflater());
|
||||||
tabCustomViewBinding.title.setText(name);
|
tabCustomViewBinding.title.setText(name);
|
||||||
|
@ -326,6 +336,9 @@ public class PinnedTimelineHelper {
|
||||||
}
|
}
|
||||||
tab.setCustomView(tabCustomDefaultViewBinding.getRoot());
|
tab.setCustomView(tabCustomDefaultViewBinding.getRoot());
|
||||||
}
|
}
|
||||||
|
//We be used to fetch position of tabs
|
||||||
|
String slug = pinnedTimeline.type.getValue() + (ident != null ? "|" + ident : "");
|
||||||
|
tab.setTag(slug);
|
||||||
activityMainBinding.tabLayout.addTab(tab);
|
activityMainBinding.tabLayout.addTab(tab);
|
||||||
pinnedTimelineVisibleList.add(pinnedTimeline);
|
pinnedTimelineVisibleList.add(pinnedTimeline);
|
||||||
}
|
}
|
||||||
|
|
|
@ -468,7 +468,7 @@ public class FragmentMastodonNotification extends Fragment implements Notificati
|
||||||
//Update the timeline with new statuses
|
//Update the timeline with new statuses
|
||||||
int insertedStatus = 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)) {
|
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());
|
FragmentNotificationContainer.update.onUpdateNotification(insertedStatus);
|
||||||
}
|
}
|
||||||
if (direction == FragmentMastodonTimeline.DIRECTION.TOP && fetchingMissing) {
|
if (direction == FragmentMastodonTimeline.DIRECTION.TOP && fetchingMissing) {
|
||||||
binding.recyclerView.scrollToPosition(getPosition(fetched_notifications.notifications.get(fetched_notifications.notifications.size() - 1)) + 1);
|
binding.recyclerView.scrollToPosition(getPosition(fetched_notifications.notifications.get(fetched_notifications.notifications.size() - 1)) + 1);
|
||||||
|
|
|
@ -270,6 +270,6 @@ public class FragmentNotificationContainer extends Fragment {
|
||||||
|
|
||||||
|
|
||||||
public interface UpdateCounters {
|
public interface UpdateCounters {
|
||||||
void onUpdateNotification(int count, String slug);
|
void onUpdateNotification(int count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue