mirror of
https://github.com/KokaKiwi/BarInsta
synced 2024-11-26 08:37:29 +00:00
Check if it is safe to navigate. Should fix https://github.com/austinhuang0131/barinsta/issues/708
This commit is contained in:
parent
04637da854
commit
2cd1ffdeb1
@ -14,6 +14,7 @@ import androidx.appcompat.app.AlertDialog;
|
|||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import androidx.fragment.app.FragmentActivity;
|
import androidx.fragment.app.FragmentActivity;
|
||||||
import androidx.fragment.app.FragmentManager;
|
import androidx.fragment.app.FragmentManager;
|
||||||
|
import androidx.navigation.NavController;
|
||||||
import androidx.navigation.NavDirections;
|
import androidx.navigation.NavDirections;
|
||||||
import androidx.navigation.fragment.NavHostFragment;
|
import androidx.navigation.fragment.NavHostFragment;
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
@ -132,43 +133,58 @@ public class MorePreferencesFragment extends BasePreferencesFragment {
|
|||||||
// generalCategory.setIconSpaceReserved(false);
|
// generalCategory.setIconSpaceReserved(false);
|
||||||
// screen.addPreference(generalCategory);
|
// screen.addPreference(generalCategory);
|
||||||
screen.addPreference(getDivider(context));
|
screen.addPreference(getDivider(context));
|
||||||
|
final NavController navController = NavHostFragment.findNavController(this);
|
||||||
if (isLoggedIn) {
|
if (isLoggedIn) {
|
||||||
screen.addPreference(getPreference(R.string.action_notif, R.drawable.ic_not_liked, preference -> {
|
screen.addPreference(getPreference(R.string.action_notif, R.drawable.ic_not_liked, preference -> {
|
||||||
final NavDirections navDirections = MorePreferencesFragmentDirections.actionGlobalNotificationsViewerFragment("notif", 0l);
|
if (isSafeToNavigate(navController)) {
|
||||||
NavHostFragment.findNavController(this).navigate(navDirections);
|
final NavDirections navDirections = MorePreferencesFragmentDirections.actionGlobalNotificationsViewerFragment("notif", 0L);
|
||||||
|
navController.navigate(navDirections);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}));
|
}));
|
||||||
screen.addPreference(getPreference(R.string.action_ayml, R.drawable.ic_suggested_users, preference -> {
|
screen.addPreference(getPreference(R.string.action_ayml, R.drawable.ic_suggested_users, preference -> {
|
||||||
final NavDirections navDirections = MorePreferencesFragmentDirections.actionGlobalNotificationsViewerFragment("ayml", 0l);
|
if (isSafeToNavigate(navController)) {
|
||||||
NavHostFragment.findNavController(this).navigate(navDirections);
|
final NavDirections navDirections = MorePreferencesFragmentDirections.actionGlobalNotificationsViewerFragment("ayml", 0L);
|
||||||
|
navController.navigate(navDirections);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}));
|
}));
|
||||||
screen.addPreference(getPreference(R.string.action_archive, R.drawable.ic_archive, preference -> {
|
screen.addPreference(getPreference(R.string.action_archive, R.drawable.ic_archive, preference -> {
|
||||||
final NavDirections navDirections = MorePreferencesFragmentDirections.actionGlobalStoryListViewerFragment("archive");
|
if (isSafeToNavigate(navController)) {
|
||||||
NavHostFragment.findNavController(this).navigate(navDirections);
|
final NavDirections navDirections = MorePreferencesFragmentDirections.actionGlobalStoryListViewerFragment("archive");
|
||||||
|
navController.navigate(navDirections);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
screen.addPreference(getPreference(R.string.title_favorites, R.drawable.ic_star_24, preference -> {
|
screen.addPreference(getPreference(R.string.title_favorites, R.drawable.ic_star_24, preference -> {
|
||||||
final NavDirections navDirections = MorePreferencesFragmentDirections.actionMorePreferencesFragmentToFavoritesFragment();
|
if (isSafeToNavigate(navController)) {
|
||||||
NavHostFragment.findNavController(this).navigate(navDirections);
|
final NavDirections navDirections = MorePreferencesFragmentDirections.actionMorePreferencesFragmentToFavoritesFragment();
|
||||||
|
navController.navigate(navDirections);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}));
|
}));
|
||||||
|
|
||||||
screen.addPreference(getDivider(context));
|
screen.addPreference(getDivider(context));
|
||||||
screen.addPreference(getPreference(R.string.action_settings, R.drawable.ic_outline_settings_24, preference -> {
|
screen.addPreference(getPreference(R.string.action_settings, R.drawable.ic_outline_settings_24, preference -> {
|
||||||
final NavDirections navDirections = MorePreferencesFragmentDirections.actionMorePreferencesFragmentToSettingsPreferencesFragment();
|
if (isSafeToNavigate(navController)) {
|
||||||
NavHostFragment.findNavController(this).navigate(navDirections);
|
final NavDirections navDirections = MorePreferencesFragmentDirections.actionMorePreferencesFragmentToSettingsPreferencesFragment();
|
||||||
|
navController.navigate(navDirections);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}));
|
}));
|
||||||
screen.addPreference(getPreference(R.string.backup_and_restore, R.drawable.ic_settings_backup_restore_24, preference -> {
|
screen.addPreference(getPreference(R.string.backup_and_restore, R.drawable.ic_settings_backup_restore_24, preference -> {
|
||||||
final NavDirections navDirections = MorePreferencesFragmentDirections.actionMorePreferencesFragmentToBackupPreferencesFragment();
|
if (isSafeToNavigate(navController)) {
|
||||||
NavHostFragment.findNavController(this).navigate(navDirections);
|
final NavDirections navDirections = MorePreferencesFragmentDirections.actionMorePreferencesFragmentToBackupPreferencesFragment();
|
||||||
|
navController.navigate(navDirections);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}));
|
}));
|
||||||
screen.addPreference(getPreference(R.string.action_about, R.drawable.ic_outline_info_24, preference1 -> {
|
screen.addPreference(getPreference(R.string.action_about, R.drawable.ic_outline_info_24, preference1 -> {
|
||||||
final NavDirections navDirections = MorePreferencesFragmentDirections.actionMorePreferencesFragmentToAboutFragment();
|
if (isSafeToNavigate(navController)) {
|
||||||
NavHostFragment.findNavController(this).navigate(navDirections);
|
final NavDirections navDirections = MorePreferencesFragmentDirections.actionMorePreferencesFragmentToAboutFragment();
|
||||||
|
navController.navigate(navDirections);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@ -187,6 +203,11 @@ public class MorePreferencesFragment extends BasePreferencesFragment {
|
|||||||
screen.addPreference(reminderPreference);
|
screen.addPreference(reminderPreference);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isSafeToNavigate(final NavController navController) {
|
||||||
|
return navController.getCurrentDestination() != null
|
||||||
|
&& navController.getCurrentDestination().getId() == R.id.morePreferencesFragment;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onActivityResult(final int requestCode, final int resultCode, @Nullable final Intent data) {
|
public void onActivityResult(final int requestCode, final int resultCode, @Nullable final Intent data) {
|
||||||
if (resultCode == Constants.LOGIN_RESULT_CODE) {
|
if (resultCode == Constants.LOGIN_RESULT_CODE) {
|
||||||
|
Loading…
Reference in New Issue
Block a user