mirror of
https://github.com/KokaKiwi/BarInsta
synced 2024-11-04 14:17:30 +00:00
Remove usage of final arrays to hold values
This commit is contained in:
parent
8829f4a66e
commit
951117c769
@ -24,6 +24,10 @@ import awais.instagrabber.R;
|
|||||||
* from architecture-components-samples. Some modifications have been done, check git history.
|
* from architecture-components-samples. Some modifications have been done, check git history.
|
||||||
*/
|
*/
|
||||||
public class NavigationExtensions {
|
public class NavigationExtensions {
|
||||||
|
|
||||||
|
private static String selectedItemTag;
|
||||||
|
private static boolean isOnFirstFragment;
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public static LiveData<NavController> setupWithNavController(@NonNull final BottomNavigationView bottomNavigationView,
|
public static LiveData<NavController> setupWithNavController(@NonNull final BottomNavigationView bottomNavigationView,
|
||||||
@NonNull List<Integer> navGraphIds,
|
@NonNull List<Integer> navGraphIds,
|
||||||
@ -51,15 +55,15 @@ public class NavigationExtensions {
|
|||||||
detachNavHostFragment(fragmentManager, navHostFragment);
|
detachNavHostFragment(fragmentManager, navHostFragment);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final String[] selectedItemTag = {graphIdToTagMap.get(bottomNavigationView.getSelectedItemId())};
|
selectedItemTag = graphIdToTagMap.get(bottomNavigationView.getSelectedItemId());
|
||||||
final String firstFragmentTag = graphIdToTagMap.get(firstFragmentGraphId);
|
final String firstFragmentTag = graphIdToTagMap.get(firstFragmentGraphId);
|
||||||
final boolean[] isOnFirstFragment = {selectedItemTag[0] != null && selectedItemTag[0].equals(firstFragmentTag)};
|
isOnFirstFragment = selectedItemTag != null && selectedItemTag.equals(firstFragmentTag);
|
||||||
bottomNavigationView.setOnNavigationItemSelectedListener(item -> {
|
bottomNavigationView.setOnNavigationItemSelectedListener(item -> {
|
||||||
if (fragmentManager.isStateSaved()) {
|
if (fragmentManager.isStateSaved()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
String newlySelectedItemTag = graphIdToTagMap.get(item.getItemId());
|
String newlySelectedItemTag = graphIdToTagMap.get(item.getItemId());
|
||||||
String tag = selectedItemTag[0];
|
String tag = selectedItemTag;
|
||||||
if (tag != null && !tag.equals(newlySelectedItemTag)) {
|
if (tag != null && !tag.equals(newlySelectedItemTag)) {
|
||||||
fragmentManager.popBackStack(firstFragmentTag, FragmentManager.POP_BACK_STACK_INCLUSIVE);
|
fragmentManager.popBackStack(firstFragmentTag, FragmentManager.POP_BACK_STACK_INCLUSIVE);
|
||||||
Fragment fragment = fragmentManager.findFragmentByTag(newlySelectedItemTag);
|
Fragment fragment = fragmentManager.findFragmentByTag(newlySelectedItemTag);
|
||||||
@ -94,8 +98,8 @@ public class NavigationExtensions {
|
|||||||
.setReorderingAllowed(true)
|
.setReorderingAllowed(true)
|
||||||
.commit();
|
.commit();
|
||||||
}
|
}
|
||||||
selectedItemTag[0] = newlySelectedItemTag;
|
selectedItemTag = newlySelectedItemTag;
|
||||||
isOnFirstFragment[0] = selectedItemTag[0].equals(firstFragmentTag);
|
isOnFirstFragment = selectedItemTag.equals(firstFragmentTag);
|
||||||
selectedNavController.setValue(selectedFragment.getNavController());
|
selectedNavController.setValue(selectedFragment.getNavController());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -105,7 +109,7 @@ public class NavigationExtensions {
|
|||||||
setupDeepLinks(bottomNavigationView, navGraphIds, fragmentManager, containerId, intent);
|
setupDeepLinks(bottomNavigationView, navGraphIds, fragmentManager, containerId, intent);
|
||||||
final int finalFirstFragmentGraphId = firstFragmentGraphId;
|
final int finalFirstFragmentGraphId = firstFragmentGraphId;
|
||||||
fragmentManager.addOnBackStackChangedListener(() -> {
|
fragmentManager.addOnBackStackChangedListener(() -> {
|
||||||
if (!isOnFirstFragment[0]) {
|
if (!isOnFirstFragment) {
|
||||||
if (firstFragmentTag == null) {
|
if (firstFragmentTag == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user