1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-11-22 22:57:29 +00:00
This commit is contained in:
Ammar Githam 2021-03-16 22:45:34 +09:00
parent 04637da854
commit 2cd1ffdeb1

View File

@ -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 -> {
if (isSafeToNavigate(navController)) {
final NavDirections navDirections = MorePreferencesFragmentDirections.actionGlobalStoryListViewerFragment("archive"); final NavDirections navDirections = MorePreferencesFragmentDirections.actionGlobalStoryListViewerFragment("archive");
NavHostFragment.findNavController(this).navigate(navDirections); 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 -> {
if (isSafeToNavigate(navController)) {
final NavDirections navDirections = MorePreferencesFragmentDirections.actionMorePreferencesFragmentToFavoritesFragment(); final NavDirections navDirections = MorePreferencesFragmentDirections.actionMorePreferencesFragmentToFavoritesFragment();
NavHostFragment.findNavController(this).navigate(navDirections); 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 -> {
if (isSafeToNavigate(navController)) {
final NavDirections navDirections = MorePreferencesFragmentDirections.actionMorePreferencesFragmentToSettingsPreferencesFragment(); final NavDirections navDirections = MorePreferencesFragmentDirections.actionMorePreferencesFragmentToSettingsPreferencesFragment();
NavHostFragment.findNavController(this).navigate(navDirections); 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 -> {
if (isSafeToNavigate(navController)) {
final NavDirections navDirections = MorePreferencesFragmentDirections.actionMorePreferencesFragmentToBackupPreferencesFragment(); final NavDirections navDirections = MorePreferencesFragmentDirections.actionMorePreferencesFragmentToBackupPreferencesFragment();
NavHostFragment.findNavController(this).navigate(navDirections); 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 -> {
if (isSafeToNavigate(navController)) {
final NavDirections navDirections = MorePreferencesFragmentDirections.actionMorePreferencesFragmentToAboutFragment(); final NavDirections navDirections = MorePreferencesFragmentDirections.actionMorePreferencesFragmentToAboutFragment();
NavHostFragment.findNavController(this).navigate(navDirections); 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) {