From b8783c2488f0c5e1a6aeb75477c8fd104607f6b0 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Sun, 4 Oct 2020 17:13:39 +0800 Subject: Add go to subreddit, go to user, and random to FAB options. --- .../infinityforreddit/Activity/MainActivity.java | 140 +++++++++++++-------- .../Activity/ViewSubredditDetailActivity.java | 140 +++++++++++++-------- .../Utils/SharedPreferencesUtils.java | 6 + 3 files changed, 176 insertions(+), 110 deletions(-) (limited to 'app/src/main/java') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java index c96e5544..90302bea 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java @@ -576,6 +576,15 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb case SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_SEARCH: fab.setImageResource(R.drawable.ic_search_black_24dp); break; + case SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_GO_TO_SUBREDDIT: + fab.setImageResource(R.drawable.ic_subreddit_24dp); + break; + case SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_GO_TO_USER: + fab.setImageResource(R.drawable.ic_user_24dp); + break; + case SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_RANDOM: + fab.setImageResource(R.drawable.ic_random_24dp); + break; default: fab.setImageResource(R.drawable.ic_add_day_night_24dp); break; @@ -601,6 +610,15 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb startActivity(intent); break; } + case SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_GO_TO_SUBREDDIT: + goToSubreddit(); + break; + case SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_GO_TO_USER: + goToUser(); + break; + case SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_RANDOM: + randomThing(); + break; default: postTypeBottomSheetFragment.show(getSupportFragmentManager(), postTypeBottomSheetFragment.getTag()); break; @@ -1166,72 +1184,84 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb startActivity(intent); break; case FABMoreOptionsBottomSheetFragment.FAB_OPTION_GO_TO_SUBREDDIT: { - EditText thingEditText = (EditText) getLayoutInflater().inflate(R.layout.dialog_go_to_thing_edit_text, null); - thingEditText.requestFocus(); - InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); - if (imm != null) { - imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); - } - new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme) - .setTitle(R.string.go_to_user) - .setView(thingEditText) - .setPositiveButton(R.string.ok, (dialogInterface, i) - -> { - if (imm != null) { - imm.hideSoftInputFromWindow(thingEditText.getWindowToken(), 0); - } - Intent subredditIntent = new Intent(this, ViewSubredditDetailActivity.class); - subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, thingEditText.getText().toString()); - startActivity(subredditIntent); - }) - .setNegativeButton(R.string.cancel, null) - .setOnDismissListener(dialogInterface -> { - if (imm != null) { - imm.hideSoftInputFromWindow(thingEditText.getWindowToken(), 0); - } - }) - .show(); + goToSubreddit(); break; } case FABMoreOptionsBottomSheetFragment.FAB_OPTION_GO_TO_USER: { - EditText thingEditText = (EditText) getLayoutInflater().inflate(R.layout.dialog_go_to_thing_edit_text, null); - thingEditText.requestFocus(); - InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); - if (imm != null) { - imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); - } - new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme) - .setTitle(R.string.go_to_user) - .setView(thingEditText) - .setPositiveButton(R.string.ok, (dialogInterface, i) - -> { - if (imm != null) { - imm.hideSoftInputFromWindow(thingEditText.getWindowToken(), 0); - } - Intent userIntent = new Intent(this, ViewUserDetailActivity.class); - userIntent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, thingEditText.getText().toString()); - startActivity(userIntent); - }) - .setNegativeButton(R.string.cancel, null) - .setOnDismissListener(dialogInterface -> { - if (imm != null) { - imm.hideSoftInputFromWindow(thingEditText.getWindowToken(), 0); - } - }) - .show(); + goToUser(); break; } case FABMoreOptionsBottomSheetFragment.FAB_RANDOM: { - RandomBottomSheetFragment randomBottomSheetFragment = new RandomBottomSheetFragment(); - Bundle bundle = new Bundle(); - bundle.putBoolean(RandomBottomSheetFragment.EXTRA_IS_NSFW, mNsfwAndSpoilerSharedPreferences.getBoolean((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.NSFW_BASE, false)); - randomBottomSheetFragment.setArguments(bundle); - randomBottomSheetFragment.show(getSupportFragmentManager(), randomBottomSheetFragment.getTag()); + randomThing(); break; } } } + private void goToSubreddit() { + EditText thingEditText = (EditText) getLayoutInflater().inflate(R.layout.dialog_go_to_thing_edit_text, null); + thingEditText.requestFocus(); + InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); + if (imm != null) { + imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); + } + new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme) + .setTitle(R.string.go_to_user) + .setView(thingEditText) + .setPositiveButton(R.string.ok, (dialogInterface, i) + -> { + if (imm != null) { + imm.hideSoftInputFromWindow(thingEditText.getWindowToken(), 0); + } + Intent subredditIntent = new Intent(this, ViewSubredditDetailActivity.class); + subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, thingEditText.getText().toString()); + startActivity(subredditIntent); + }) + .setNegativeButton(R.string.cancel, null) + .setOnDismissListener(dialogInterface -> { + if (imm != null) { + imm.hideSoftInputFromWindow(thingEditText.getWindowToken(), 0); + } + }) + .show(); + } + + private void goToUser() { + EditText thingEditText = (EditText) getLayoutInflater().inflate(R.layout.dialog_go_to_thing_edit_text, null); + thingEditText.requestFocus(); + InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); + if (imm != null) { + imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); + } + new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme) + .setTitle(R.string.go_to_user) + .setView(thingEditText) + .setPositiveButton(R.string.ok, (dialogInterface, i) + -> { + if (imm != null) { + imm.hideSoftInputFromWindow(thingEditText.getWindowToken(), 0); + } + Intent userIntent = new Intent(this, ViewUserDetailActivity.class); + userIntent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, thingEditText.getText().toString()); + startActivity(userIntent); + }) + .setNegativeButton(R.string.cancel, null) + .setOnDismissListener(dialogInterface -> { + if (imm != null) { + imm.hideSoftInputFromWindow(thingEditText.getWindowToken(), 0); + } + }) + .show(); + } + + private void randomThing() { + RandomBottomSheetFragment randomBottomSheetFragment = new RandomBottomSheetFragment(); + Bundle bundle = new Bundle(); + bundle.putBoolean(RandomBottomSheetFragment.EXTRA_IS_NSFW, mNsfwAndSpoilerSharedPreferences.getBoolean((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.NSFW_BASE, false)); + randomBottomSheetFragment.setArguments(bundle); + randomBottomSheetFragment.show(getSupportFragmentManager(), randomBottomSheetFragment.getTag()); + } + @Override public void randomOptionSelected(int option) { Intent intent = new Intent(this, FetchRandomSubredditOrPostActivity.class); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java index 7db3a9cc..f53bd244 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java @@ -681,6 +681,15 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_SEARCH: fab.setImageResource(R.drawable.ic_search_black_24dp); break; + case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_GO_TO_SUBREDDIT: + fab.setImageResource(R.drawable.ic_subreddit_24dp); + break; + case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_GO_TO_USER: + fab.setImageResource(R.drawable.ic_user_24dp); + break; + case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_RANDOM: + fab.setImageResource(R.drawable.ic_random_24dp); + break; default: fab.setImageResource(R.drawable.ic_add_day_night_24dp); break; @@ -707,6 +716,15 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp startActivity(intent); break; } + case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_GO_TO_SUBREDDIT: + goToSubreddit(); + break; + case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_GO_TO_USER: + goToUser(); + break; + case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_RANDOM: + random(); + break; default: postTypeBottomSheetFragment.show(getSupportFragmentManager(), postTypeBottomSheetFragment.getTag()); break; @@ -1071,72 +1089,84 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp startActivity(intent); break; case FABMoreOptionsBottomSheetFragment.FAB_OPTION_GO_TO_SUBREDDIT: { - EditText thingEditText = (EditText) getLayoutInflater().inflate(R.layout.dialog_go_to_thing_edit_text, null); - thingEditText.requestFocus(); - InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); - if (imm != null) { - imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); - } - new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme) - .setTitle(R.string.go_to_user) - .setView(thingEditText) - .setPositiveButton(R.string.ok, (dialogInterface, i) - -> { - if (imm != null) { - imm.hideSoftInputFromWindow(thingEditText.getWindowToken(), 0); - } - Intent subredditIntent = new Intent(this, ViewSubredditDetailActivity.class); - subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, thingEditText.getText().toString()); - startActivity(subredditIntent); - }) - .setNegativeButton(R.string.cancel, null) - .setOnDismissListener(dialogInterface -> { - if (imm != null) { - imm.hideSoftInputFromWindow(thingEditText.getWindowToken(), 0); - } - }) - .show(); + goToSubreddit(); break; } case FABMoreOptionsBottomSheetFragment.FAB_OPTION_GO_TO_USER: { - EditText thingEditText = (EditText) getLayoutInflater().inflate(R.layout.dialog_go_to_thing_edit_text, null); - thingEditText.requestFocus(); - InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); - if (imm != null) { - imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); - } - new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme) - .setTitle(R.string.go_to_user) - .setView(thingEditText) - .setPositiveButton(R.string.ok, (dialogInterface, i) - -> { - if (imm != null) { - imm.hideSoftInputFromWindow(thingEditText.getWindowToken(), 0); - } - Intent userIntent = new Intent(this, ViewUserDetailActivity.class); - userIntent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, thingEditText.getText().toString()); - startActivity(userIntent); - }) - .setNegativeButton(R.string.cancel, null) - .setOnDismissListener(dialogInterface -> { - if (imm != null) { - imm.hideSoftInputFromWindow(thingEditText.getWindowToken(), 0); - } - }) - .show(); + goToUser(); break; } case FABMoreOptionsBottomSheetFragment.FAB_RANDOM: { - RandomBottomSheetFragment randomBottomSheetFragment = new RandomBottomSheetFragment(); - Bundle bundle = new Bundle(); - bundle.putBoolean(RandomBottomSheetFragment.EXTRA_IS_NSFW, mNsfwAndSpoilerSharedPreferences.getBoolean((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.NSFW_BASE, false)); - randomBottomSheetFragment.setArguments(bundle); - randomBottomSheetFragment.show(getSupportFragmentManager(), randomBottomSheetFragment.getTag()); + random(); break; } } } + private void goToSubreddit() { + EditText thingEditText = (EditText) getLayoutInflater().inflate(R.layout.dialog_go_to_thing_edit_text, null); + thingEditText.requestFocus(); + InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); + if (imm != null) { + imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); + } + new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme) + .setTitle(R.string.go_to_user) + .setView(thingEditText) + .setPositiveButton(R.string.ok, (dialogInterface, i) + -> { + if (imm != null) { + imm.hideSoftInputFromWindow(thingEditText.getWindowToken(), 0); + } + Intent subredditIntent = new Intent(this, ViewSubredditDetailActivity.class); + subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, thingEditText.getText().toString()); + startActivity(subredditIntent); + }) + .setNegativeButton(R.string.cancel, null) + .setOnDismissListener(dialogInterface -> { + if (imm != null) { + imm.hideSoftInputFromWindow(thingEditText.getWindowToken(), 0); + } + }) + .show(); + } + + private void goToUser() { + EditText thingEditText = (EditText) getLayoutInflater().inflate(R.layout.dialog_go_to_thing_edit_text, null); + thingEditText.requestFocus(); + InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); + if (imm != null) { + imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); + } + new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme) + .setTitle(R.string.go_to_user) + .setView(thingEditText) + .setPositiveButton(R.string.ok, (dialogInterface, i) + -> { + if (imm != null) { + imm.hideSoftInputFromWindow(thingEditText.getWindowToken(), 0); + } + Intent userIntent = new Intent(this, ViewUserDetailActivity.class); + userIntent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, thingEditText.getText().toString()); + startActivity(userIntent); + }) + .setNegativeButton(R.string.cancel, null) + .setOnDismissListener(dialogInterface -> { + if (imm != null) { + imm.hideSoftInputFromWindow(thingEditText.getWindowToken(), 0); + } + }) + .show(); + } + + private void random() { + RandomBottomSheetFragment randomBottomSheetFragment = new RandomBottomSheetFragment(); + Bundle bundle = new Bundle(); + bundle.putBoolean(RandomBottomSheetFragment.EXTRA_IS_NSFW, mNsfwAndSpoilerSharedPreferences.getBoolean((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.NSFW_BASE, false)); + randomBottomSheetFragment.setArguments(bundle); + randomBottomSheetFragment.show(getSupportFragmentManager(), randomBottomSheetFragment.getTag()); + } + @Override public void randomOptionSelected(int option) { Intent intent = new Intent(this, FetchRandomSubredditOrPostActivity.class); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java index 78c1567f..cb659c23 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java @@ -179,6 +179,9 @@ public class SharedPreferencesUtils { public static final int MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_CHANGE_SORT_TYPE = 2; public static final int MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_CHANGE_POST_LAYOUT = 3; public static final int MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_SEARCH = 4; + public static final int MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_GO_TO_SUBREDDIT = 5; + public static final int MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_GO_TO_USER = 6; + public static final int MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_RANDOM = 7; public static final int OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_HOME = 0; public static final int OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_SUBSCRIPTIONS = 1; public static final int OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_INBOX = 2; @@ -189,6 +192,9 @@ public class SharedPreferencesUtils { public static final int OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_CHANGE_SORT_TYPE = 2; public static final int OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_CHANGE_POST_LAYOUT = 3; public static final int OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_SEARCH = 4; + public static final int OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_GO_TO_SUBREDDIT = 5; + public static final int OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_GO_TO_USER = 6; + public static final int OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_RANDOM = 7; public static final String NSFW_AND_SPOILER_SHARED_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit.nsfw_and_spoiler"; public static final String NSFW_BASE = "_nsfw"; -- cgit v1.2.3