mirror of
https://github.com/KokaKiwi/BarInsta
synced 2024-12-23 13:26:59 +00:00
Reselect proper tab immediately after logging off
This commit is contained in:
parent
e89cf7af46
commit
444c51a36d
@ -369,32 +369,26 @@ public class MainActivity extends BaseLanguageActivity {
|
|||||||
final boolean isLoggedIn = !TextUtils.isEmpty(cookie) && CookieUtils.getUserIdFromCookie(cookie) != null;
|
final boolean isLoggedIn = !TextUtils.isEmpty(cookie) && CookieUtils.getUserIdFromCookie(cookie) != null;
|
||||||
if (!isLoggedIn) {
|
if (!isLoggedIn) {
|
||||||
main_nav_ids = R.array.logged_out_main_nav_ids;
|
main_nav_ids = R.array.logged_out_main_nav_ids;
|
||||||
|
final int selectedItemId = binding.bottomNavView.getSelectedItemId();
|
||||||
binding.bottomNavView.getMenu().clear();
|
binding.bottomNavView.getMenu().clear();
|
||||||
binding.bottomNavView.inflateMenu(R.menu.logged_out_bottom_navigation_menu);
|
binding.bottomNavView.inflateMenu(R.menu.logged_out_bottom_navigation_menu);
|
||||||
|
if (selectedItemId == R.id.profile_nav_graph
|
||||||
|
|| selectedItemId == R.id.more_nav_graph) {
|
||||||
|
binding.bottomNavView.setSelectedItemId(selectedItemId);
|
||||||
|
} else {
|
||||||
|
setBottomNavSelectedItem(R.navigation.profile_nav_graph);
|
||||||
}
|
}
|
||||||
final TypedArray navIds = getResources().obtainTypedArray(main_nav_ids);
|
|
||||||
final List<Integer> mainNavList = new ArrayList<>(navIds.length());
|
|
||||||
final int length = navIds.length();
|
|
||||||
for (int i = 0; i < length; i++) {
|
|
||||||
final int resourceId = navIds.getResourceId(i, -1);
|
|
||||||
if (resourceId < 0) continue;
|
|
||||||
mainNavList.add(resourceId);
|
|
||||||
}
|
}
|
||||||
navIds.recycle();
|
final List<Integer> mainNavList = getMainNavList(main_nav_ids);
|
||||||
if (setDefaultFromSettings || !isLoggedIn) {
|
if (setDefaultFromSettings) {
|
||||||
final String defaultTabIdString = settingsHelper.getString(Constants.DEFAULT_TAB);
|
final String defaultTabIdString = settingsHelper.getString(Constants.DEFAULT_TAB);
|
||||||
try {
|
try {
|
||||||
final int defaultNavId = TextUtils.isEmpty(defaultTabIdString) || !isLoggedIn
|
final int defaultNavId = TextUtils.isEmpty(defaultTabIdString)
|
||||||
? R.navigation.profile_nav_graph
|
? R.navigation.profile_nav_graph
|
||||||
: Integer.parseInt(defaultTabIdString);
|
: Integer.parseInt(defaultTabIdString);
|
||||||
final int index = mainNavList.indexOf(defaultNavId);
|
final int index = mainNavList.indexOf(defaultNavId);
|
||||||
if (index >= 0) {
|
if (index >= 0) firstFragmentGraphIndex = index;
|
||||||
firstFragmentGraphIndex = index;
|
setBottomNavSelectedItem(defaultNavId);
|
||||||
final Integer menuId = NAV_TO_MENU_ID_MAP.get(defaultNavId);
|
|
||||||
if (menuId != null) {
|
|
||||||
binding.bottomNavView.setSelectedItemId(menuId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
Log.e(TAG, "Error parsing id", e);
|
Log.e(TAG, "Error parsing id", e);
|
||||||
}
|
}
|
||||||
@ -410,6 +404,27 @@ public class MainActivity extends BaseLanguageActivity {
|
|||||||
currentNavControllerLiveData = navControllerLiveData;
|
currentNavControllerLiveData = navControllerLiveData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setBottomNavSelectedItem(final int navId) {
|
||||||
|
final Integer menuId = NAV_TO_MENU_ID_MAP.get(navId);
|
||||||
|
if (menuId != null) {
|
||||||
|
binding.bottomNavView.setSelectedItemId(menuId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
private List<Integer> getMainNavList(final int main_nav_ids) {
|
||||||
|
final TypedArray navIds = getResources().obtainTypedArray(main_nav_ids);
|
||||||
|
final List<Integer> mainNavList = new ArrayList<>(navIds.length());
|
||||||
|
final int length = navIds.length();
|
||||||
|
for (int i = 0; i < length; i++) {
|
||||||
|
final int resourceId = navIds.getResourceId(i, -1);
|
||||||
|
if (resourceId < 0) continue;
|
||||||
|
mainNavList.add(resourceId);
|
||||||
|
}
|
||||||
|
navIds.recycle();
|
||||||
|
return mainNavList;
|
||||||
|
}
|
||||||
|
|
||||||
private void setupNavigation(final NavController navController) {
|
private void setupNavigation(final NavController navController) {
|
||||||
NavigationUI.setupWithNavController(binding.toolbar, navController);
|
NavigationUI.setupWithNavController(binding.toolbar, navController);
|
||||||
navController.addOnDestinationChangedListener((controller, destination, arguments) -> {
|
navController.addOnDestinationChangedListener((controller, destination, arguments) -> {
|
||||||
|
Loading…
Reference in New Issue
Block a user