aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2020-08-20 03:17:33 +0000
committerAlex Ning <chineseperson5@gmail.com>2020-08-20 03:17:33 +0000
commit53ef74b70e445763fc50b6a1382cd8ee2dab3299 (patch)
treecc8a9e34c1acb57e23179a9db3aaa801a96ac54b /app/src/main/java
parent24348b256fd1db6c395fc22304fe425b13b82edc (diff)
downloadinfinity-for-reddit-53ef74b70e445763fc50b6a1382cd8ee2dab3299.tar
infinity-for-reddit-53ef74b70e445763fc50b6a1382cd8ee2dab3299.tar.gz
infinity-for-reddit-53ef74b70e445763fc50b6a1382cd8ee2dab3299.tar.bz2
infinity-for-reddit-53ef74b70e445763fc50b6a1382cd8ee2dab3299.tar.lz
infinity-for-reddit-53ef74b70e445763fc50b6a1382cd8ee2dab3299.tar.xz
infinity-for-reddit-53ef74b70e445763fc50b6a1382cd8ee2dab3299.tar.zst
infinity-for-reddit-53ef74b70e445763fc50b6a1382cd8ee2dab3299.zip
Remove legacy code for CustomizeMainPageTabsFragment.
Diffstat (limited to '')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SettingsActivity.java6
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java5
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Settings/CustomizeMainPageTabsFragment.java595
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Settings/CustomizeMainPageTabsTestFragment.java501
4 files changed, 471 insertions, 636 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SettingsActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SettingsActivity.java
index d93374c4..325e8e91 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SettingsActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SettingsActivity.java
@@ -28,7 +28,7 @@ import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.Settings.AboutPreferenceFragment;
-import ml.docilealligator.infinityforreddit.Settings.CustomizeMainPageTabsTestFragment;
+import ml.docilealligator.infinityforreddit.Settings.CustomizeMainPageTabsFragment;
import ml.docilealligator.infinityforreddit.Settings.FontPreferenceFragment;
import ml.docilealligator.infinityforreddit.Settings.InterfacePreferenceFragment;
import ml.docilealligator.infinityforreddit.Settings.MainPreferenceFragment;
@@ -154,8 +154,8 @@ public class SettingsActivity extends BaseActivity implements
final Fragment fragment = getSupportFragmentManager().getFragmentFactory().instantiate(
getClassLoader(),
pref.getFragment());
- if (fragment instanceof CustomizeMainPageTabsTestFragment) {
- args.putString(CustomizeMainPageTabsTestFragment.EXTRA_ACCOUNT_NAME, mAccountName);
+ if (fragment instanceof CustomizeMainPageTabsFragment) {
+ args.putString(CustomizeMainPageTabsFragment.EXTRA_ACCOUNT_NAME, mAccountName);
}
fragment.setArguments(args);
fragment.setTargetFragment(caller, 0);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java
index 5e9dcd45..35705736 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java
@@ -58,7 +58,6 @@ import ml.docilealligator.infinityforreddit.Service.DownloadVideoService;
import ml.docilealligator.infinityforreddit.Service.SubmitPostService;
import ml.docilealligator.infinityforreddit.Settings.AdvancedPreferenceFragment;
import ml.docilealligator.infinityforreddit.Settings.CustomizeMainPageTabsFragment;
-import ml.docilealligator.infinityforreddit.Settings.CustomizeMainPageTabsTestFragment;
import ml.docilealligator.infinityforreddit.Settings.GesturesAndButtonsPreferenceFragment;
import ml.docilealligator.infinityforreddit.Settings.MainPreferenceFragment;
import ml.docilealligator.infinityforreddit.Settings.NotificationPreferenceFragment;
@@ -168,8 +167,6 @@ public interface AppComponent {
void inject(ReportActivity reportActivity);
- void inject(CustomizeMainPageTabsFragment customizeMainPageTabsFragment);
-
void inject(ViewImgurMediaActivity viewImgurMediaActivity);
void inject(ViewImgurVideoFragment viewImgurVideoFragment);
@@ -190,5 +187,5 @@ public interface AppComponent {
void inject(ViewRedditGalleryVideoFragment viewRedditGalleryVideoFragment);
- void inject(CustomizeMainPageTabsTestFragment customizeMainPageTabsTestFragment);
+ void inject(CustomizeMainPageTabsFragment customizeMainPageTabsFragment);
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/CustomizeMainPageTabsFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/CustomizeMainPageTabsFragment.java
index 96226448..68d324b8 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/CustomizeMainPageTabsFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/CustomizeMainPageTabsFragment.java
@@ -1,162 +1,501 @@
package ml.docilealligator.infinityforreddit.Settings;
+import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.inputmethod.InputMethodManager;
+import android.widget.EditText;
+import android.widget.LinearLayout;
+import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
-import androidx.preference.PreferenceFragmentCompat;
+
+import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import javax.inject.Inject;
import javax.inject.Named;
-import ml.docilealligator.infinityforreddit.Activity.SettingsActivity;
-import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
+import butterknife.BindView;
+import butterknife.ButterKnife;
+import ml.docilealligator.infinityforreddit.Infinity;
+import ml.docilealligator.infinityforreddit.R;
+import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
-/**
- * A simple {@link Fragment} subclass.
- */
-public class CustomizeMainPageTabsFragment extends PreferenceFragmentCompat {
+public class CustomizeMainPageTabsFragment extends Fragment {
+ public static final String EXTRA_ACCOUNT_NAME = "EAN";
+
+ @BindView(R.id.info_text_view_customize_main_page_tabs_fragment)
+ TextView infoTextView;
+ @BindView(R.id.divider_1_customize_main_page_tabs_fragment)
+ View divider1;
+ @BindView(R.id.tab_1_group_summary_customize_main_page_tabs_fragment)
+ TextView tab1GroupSummaryTextView;
+ @BindView(R.id.tab_1_title_linear_layout_customize_main_page_tabs_fragment)
+ LinearLayout tab1TitleLinearLayout;
+ @BindView(R.id.tab_1_title_summary_text_view_customize_main_page_tabs_fragment)
+ TextView tab1TitleSummaryTextView;
+ @BindView(R.id.tab_1_type_linear_layout_customize_main_page_tabs_fragment)
+ LinearLayout tab1TypeLinearLayout;
+ @BindView(R.id.tab_1_type_summary_text_view_customize_main_page_tabs_fragment)
+ TextView tab1TypeSummaryTextView;
+ @BindView(R.id.tab_1_name_linear_layout_customize_main_page_tabs_fragment)
+ LinearLayout tab1NameLinearLayout;
+ @BindView(R.id.tab_1_name_title_text_view_customize_main_page_tabs_fragment)
+ TextView tab1NameTitleTextView;
+ @BindView(R.id.tab_1_name_summary_text_view_customize_main_page_tabs_fragment)
+ TextView tab1NameSummaryTextView;
+ @BindView(R.id.divider_2_customize_main_page_tabs_fragment)
+ View divider2;
+ @BindView(R.id.tab_2_group_summary_customize_main_page_tabs_fragment)
+ TextView tab2GroupSummaryTextView;
+ @BindView(R.id.tab_2_title_linear_layout_customize_main_page_tabs_fragment)
+ LinearLayout tab2TitleLinearLayout;
+ @BindView(R.id.tab_2_title_summary_text_view_customize_main_page_tabs_fragment)
+ TextView tab2TitleSummaryTextView;
+ @BindView(R.id.tab_2_type_linear_layout_customize_main_page_tabs_fragment)
+ LinearLayout tab2TypeLinearLayout;
+ @BindView(R.id.tab_2_type_summary_text_view_customize_main_page_tabs_fragment)
+ TextView tab2TypeSummaryTextView;
+ @BindView(R.id.tab_2_name_linear_layout_customize_main_page_tabs_fragment)
+ LinearLayout tab2NameLinearLayout;
+ @BindView(R.id.tab_2_name_title_text_view_customize_main_page_tabs_fragment)
+ TextView tab2NameTitleTextView;
+ @BindView(R.id.tab_2_name_summary_text_view_customize_main_page_tabs_fragment)
+ TextView tab2NameSummaryTextView;
+ @BindView(R.id.divider_3_customize_main_page_tabs_fragment)
+ View divider3;
+ @BindView(R.id.tab_3_group_summary_customize_main_page_tabs_fragment)
+ TextView tab3GroupSummaryTextView;
+ @BindView(R.id.tab_3_title_linear_layout_customize_main_page_tabs_fragment)
+ LinearLayout tab3TitleLinearLayout;
+ @BindView(R.id.tab_3_title_summary_text_view_customize_main_page_tabs_fragment)
+ TextView tab3TitleSummaryTextView;
+ @BindView(R.id.tab_3_type_linear_layout_customize_main_page_tabs_fragment)
+ LinearLayout tab3TypeLinearLayout;
+ @BindView(R.id.tab_3_type_summary_text_view_customize_main_page_tabs_fragment)
+ TextView tab3TypeSummaryTextView;
+ @BindView(R.id.tab_3_name_linear_layout_customize_main_page_tabs_fragment)
+ LinearLayout tab3NameLinearLayout;
+ @BindView(R.id.tab_3_name_title_text_view_customize_main_page_tabs_fragment)
+ TextView tab3NameTitleTextView;
+ @BindView(R.id.tab_3_name_summary_text_view_customize_main_page_tabs_fragment)
+ TextView tab3NameSummaryTextView;
@Inject
- @Named("default")
- SharedPreferences mSharedPreferences;
- @Inject
- CustomThemeWrapper customThemeWrapper;
- private SettingsActivity activity;
+ @Named("main_activity_tabs")
+ SharedPreferences sharedPreferences;
+ private Activity activity;
+ private String tab1CurrentTitle;
+ private int tab1CurrentPostType;
+ private String tab1CurrentName;
+ private String tab2CurrentTitle;
+ private int tab2CurrentPostType;
+ private String tab2CurrentName;
+ private String tab3CurrentTitle;
+ private int tab3CurrentPostType;
+ private String tab3CurrentName;
+
+ public CustomizeMainPageTabsFragment() {
+ // Required empty public constructor
+ }
@Override
- public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
- /*setPreferencesFromResource(R.xml.customize_main_page_tabs_preferences, rootKey);
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ // Inflate the layout for this fragment
+ View rootView = inflater.inflate(R.layout.fragment_customize_main_page_tabs, container, false);
((Infinity) activity.getApplication()).getAppComponent().inject(this);
- EditTextPreference tab1TitlePreference = findPreference(SharedPreferencesUtils.MAIN_PAGE_TAB_1_TITLE);
- EditTextPreference tab2TitlePreference = findPreference(SharedPreferencesUtils.MAIN_PAGE_TAB_2_TITLE);
- EditTextPreference tab3TitlePreference = findPreference(SharedPreferencesUtils.MAIN_PAGE_TAB_3_TITLE);
- ListPreference tab1PostTypePreference = findPreference(SharedPreferencesUtils.MAIN_PAGE_TAB_1_POST_TYPE);
- ListPreference tab2PostTypePreference = findPreference(SharedPreferencesUtils.MAIN_PAGE_TAB_2_POST_TYPE);
- ListPreference tab3PostTypePreference = findPreference(SharedPreferencesUtils.MAIN_PAGE_TAB_3_POST_TYPE);
- EditTextPreference tab1NamePreference = findPreference(SharedPreferencesUtils.MAIN_PAGE_TAB_1_NAME);
- EditTextPreference tab2NamePreference = findPreference(SharedPreferencesUtils.MAIN_PAGE_TAB_2_NAME);
- EditTextPreference tab3NamePreference = findPreference(SharedPreferencesUtils.MAIN_PAGE_TAB_3_NAME);
-
- if (tab1TitlePreference != null && tab1PostTypePreference != null && tab1NamePreference != null) {
- String postType = mSharedPreferences.getString(SharedPreferencesUtils.MAIN_PAGE_TAB_1_POST_TYPE,
- SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_HOME);
- if (SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_SUBREDDIT.equals(postType)) {
- tab1NamePreference.setVisible(true);
- tab1NamePreference.setTitle(R.string.settings_tab_subreddit_name);
- } else if (SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_MULTIREDDIT.equals(postType)) {
- tab1NamePreference.setVisible(true);
- tab1NamePreference.setTitle(R.string.settings_tab_multi_reddit_name);
- } else if (SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_USER.equals(postType)) {
- tab1NamePreference.setVisible(true);
- tab1NamePreference.setTitle(R.string.settings_tab_username);
- }
+ ButterKnife.bind(this, rootView);
- tab1PostTypePreference.setOnPreferenceChangeListener((preference, newValue) -> {
- switch ((String) newValue) {
- case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_HOME:
- case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_POPULAR:
- case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_ALL:
- tab1NamePreference.setVisible(false);
- break;
- case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_SUBREDDIT:
- tab1NamePreference.setVisible(true);
- tab1NamePreference.setTitle(R.string.settings_tab_subreddit_name);
- break;
- case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_MULTIREDDIT:
- tab1NamePreference.setVisible(true);
- tab1NamePreference.setTitle(R.string.settings_tab_multi_reddit_name);
- break;
- case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_USER:
- tab1NamePreference.setVisible(true);
- tab1NamePreference.setTitle(R.string.settings_tab_username);
- }
- return true;
- });
+ String accountName = getArguments().getString(EXTRA_ACCOUNT_NAME);
+
+ if (accountName == null) {
+ infoTextView.setText(R.string.settings_customize_tabs_in_main_page_summary);
+ divider1.setVisibility(View.GONE);
+ tab1GroupSummaryTextView.setVisibility(View.GONE);
+ tab1TitleLinearLayout.setVisibility(View.GONE);
+ tab1TypeLinearLayout.setVisibility(View.GONE);
+ divider2.setVisibility(View.GONE);
+ tab2GroupSummaryTextView.setVisibility(View.GONE);
+ tab2TitleLinearLayout.setVisibility(View.GONE);
+ tab2TypeLinearLayout.setVisibility(View.GONE);
+ divider3.setVisibility(View.GONE);
+ tab3GroupSummaryTextView.setVisibility(View.GONE);
+ tab3TitleLinearLayout.setVisibility(View.GONE);
+ tab3TypeLinearLayout.setVisibility(View.GONE);
+
+ return rootView;
}
- if (tab2TitlePreference != null && tab2PostTypePreference != null && tab2NamePreference != null) {
- String postType = mSharedPreferences.getString(SharedPreferencesUtils.MAIN_PAGE_TAB_2_POST_TYPE,
- SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_POPULAR);
- if (SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_SUBREDDIT.equals(postType)) {
- tab2NamePreference.setVisible(true);
- tab2NamePreference.setTitle(R.string.settings_tab_subreddit_name);
- } else if (SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_MULTIREDDIT.equals(postType)) {
- tab2NamePreference.setVisible(true);
- tab2NamePreference.setTitle(R.string.settings_tab_multi_reddit_name);
- } else if (SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_USER.equals(postType)) {
- tab2NamePreference.setVisible(true);
- tab2NamePreference.setTitle(R.string.settings_tab_username);
+ String[] typeValues = activity.getResources().getStringArray(R.array.settings_tab_post_type);
+
+ tab1CurrentTitle = sharedPreferences.getString((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_1_TITLE, getString(R.string.home));
+ tab1CurrentPostType = sharedPreferences.getInt((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_1_POST_TYPE, SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_HOME);
+ tab1CurrentName = sharedPreferences.getString((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_1_NAME, "");
+ tab1TypeSummaryTextView.setText(typeValues[tab1CurrentPostType]);
+ tab1TitleSummaryTextView.setText(tab1CurrentTitle);
+ tab1NameSummaryTextView.setText(tab1CurrentName);
+ applyTab1NameView(tab1NameLinearLayout, tab1NameTitleTextView, tab1CurrentPostType);
+
+ View dialogView = activity.getLayoutInflater().inflate(R.layout.dialog_edit_text, null);
+ EditText editText = dialogView.findViewById(R.id.edit_text_edit_text_dialog);
+
+ tab1TitleLinearLayout.setOnClickListener(view -> {
+ editText.setHint(R.string.settings_tab_title);
+ editText.setText(tab1CurrentTitle);
+ editText.requestFocus();
+ InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
+ if (imm != null) {
+ imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
}
+ if (dialogView.getParent() != null) {
+ ((ViewGroup) dialogView.getParent()).removeView(dialogView);
+ }
+ new MaterialAlertDialogBuilder(activity, R.style.MaterialAlertDialogTheme)
+ .setTitle(R.string.settings_tab_title)
+ .setView(dialogView)
+ .setPositiveButton(R.string.ok, (dialogInterface, i)
+ -> {
+ tab1CurrentTitle = editText.getText().toString();
+ sharedPreferences.edit().putString((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_1_TITLE, tab1CurrentTitle).apply();
+ tab1TitleSummaryTextView.setText(tab1CurrentTitle);
+ if (imm != null) {
+ imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
+ }
+ })
+ .setNegativeButton(R.string.cancel, (dialogInterface, i) -> {
+ if (imm != null) {
+ imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
+ }
+ })
+ .show();
+ });
- tab2PostTypePreference.setOnPreferenceChangeListener((preference, newValue) -> {
- switch ((String) newValue) {
- case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_HOME:
- case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_POPULAR:
- case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_ALL:
- tab2NamePreference.setVisible(false);
- break;
- case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_SUBREDDIT:
- tab2NamePreference.setVisible(true);
- tab2NamePreference.setTitle(R.string.settings_tab_subreddit_name);
- break;
- case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_MULTIREDDIT:
- tab2NamePreference.setVisible(true);
- tab2NamePreference.setTitle(R.string.settings_tab_multi_reddit_name);
- break;
- case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_USER:
- tab2NamePreference.setVisible(true);
- tab2NamePreference.setTitle(R.string.settings_tab_username);
- }
- return true;
- });
- }
+ tab1TypeLinearLayout.setOnClickListener(view -> {
+ new MaterialAlertDialogBuilder(activity, R.style.MaterialAlertDialogTheme)
+ .setTitle(R.string.settings_tab_title)
+ .setSingleChoiceItems(typeValues, tab1CurrentPostType, (dialogInterface, i) -> {
+ tab1CurrentPostType = i;
+ sharedPreferences.edit().putInt((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_1_POST_TYPE, i).apply();
+ tab1TypeSummaryTextView.setText(typeValues[i]);
+ applyTab1NameView(tab1NameLinearLayout, tab1NameTitleTextView, i);
+ dialogInterface.dismiss();
+ })
+ .setNegativeButton(R.string.cancel, null)
+ .show();
+ });
+
+ tab1NameLinearLayout.setOnClickListener(view -> {
+ int titleId;
+ switch (tab1CurrentPostType) {
+ case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_SUBREDDIT:
+ titleId = R.string.settings_tab_subreddit_name;
+ break;
+ case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_MULTIREDDIT:
+ titleId = R.string.settings_tab_multi_reddit_name;
+ break;
+ case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_USER:
+ titleId = R.string.settings_tab_username;
+ break;
+ default:
+ return;
+ }
+ editText.setText(tab1CurrentName);
+ editText.setHint(titleId);
+ editText.requestFocus();
+ InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
+ if (imm != null) {
+ imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
+ }
+ if (dialogView.getParent() != null) {
+ ((ViewGroup) dialogView.getParent()).removeView(dialogView);
+ }
+ new MaterialAlertDialogBuilder(activity, R.style.MaterialAlertDialogTheme)
+ .setTitle(titleId)
+ .setView(dialogView)
+ .setPositiveButton(R.string.ok, (dialogInterface, i)
+ -> {
+ tab1CurrentName = editText.getText().toString();
+ sharedPreferences.edit().putString((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_1_NAME, tab1CurrentName).apply();
+ tab1NameSummaryTextView.setText(tab1CurrentName);
+ if (imm != null) {
+ imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
+ }
+ })
+ .setNegativeButton(R.string.cancel, (dialogInterface, i) -> {
+ if (imm != null) {
+ imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
+ }
+ })
+ .show();
+ });
+
+ tab2CurrentTitle = sharedPreferences.getString((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_2_TITLE, getString(R.string.popular));
+ tab2CurrentPostType = sharedPreferences.getInt((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_2_POST_TYPE, SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_POPULAR);
+ tab2CurrentName = sharedPreferences.getString((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_2_NAME, "");
+ tab2TypeSummaryTextView.setText(typeValues[tab2CurrentPostType]);
+ tab2TitleSummaryTextView.setText(tab2CurrentTitle);
+ tab2NameSummaryTextView.setText(tab2CurrentName);
+ applyTab2NameView(tab2NameLinearLayout, tab2NameTitleTextView, tab2CurrentPostType);
+
+ tab2TitleLinearLayout.setOnClickListener(view -> {
+ editText.setHint(R.string.settings_tab_title);
+ editText.setText(tab2CurrentTitle);
+ editText.requestFocus();
+ InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
+ if (imm != null) {
+ imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
+ }
+ if (dialogView.getParent() != null) {
+ ((ViewGroup) dialogView.getParent()).removeView(dialogView);
+ }
+ new MaterialAlertDialogBuilder(activity, R.style.MaterialAlertDialogTheme)
+ .setTitle(R.string.settings_tab_title)
+ .setView(dialogView)
+ .setPositiveButton(R.string.ok, (dialogInterface, i)
+ -> {
+ tab2CurrentTitle = editText.getText().toString();
+ sharedPreferences.edit().putString((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_2_TITLE, tab2CurrentTitle).apply();
+ tab2TitleSummaryTextView.setText(tab2CurrentTitle);
+ if (imm != null) {
+ imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
+ }
+ })
+ .setNegativeButton(R.string.cancel, (dialogInterface, i) -> {
+ if (imm != null) {
+ imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
+ }
+ })
+ .show();
+ });
- if (tab3TitlePreference != null && tab3PostTypePreference != null && tab3NamePreference != null) {
- String postType = mSharedPreferences.getString(SharedPreferencesUtils.MAIN_PAGE_TAB_3_POST_TYPE,
- SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_ALL);
- if (SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_SUBREDDIT.equals(postType)) {
- tab3NamePreference.setVisible(true);
- tab3NamePreference.setTitle(R.string.settings_tab_subreddit_name);
- } else if (SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_MULTIREDDIT.equals(postType)) {
- tab3NamePreference.setVisible(true);
- tab3NamePreference.setTitle(R.string.settings_tab_multi_reddit_name);
- } else if (SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_USER.equals(postType)) {
- tab3NamePreference.setVisible(true);
- tab3NamePreference.setTitle(R.string.settings_tab_username);
+ tab2TypeLinearLayout.setOnClickListener(view -> {
+ new MaterialAlertDialogBuilder(activity, R.style.MaterialAlertDialogTheme)
+ .setTitle(R.string.settings_tab_title)
+ .setSingleChoiceItems(typeValues, tab2CurrentPostType, (dialogInterface, i) -> {
+ tab2CurrentPostType = i;
+ sharedPreferences.edit().putInt((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_2_POST_TYPE, i).apply();
+ tab2TypeSummaryTextView.setText(typeValues[i]);
+ applyTab2NameView(tab2NameLinearLayout, tab2NameTitleTextView, i);
+ dialogInterface.dismiss();
+ })
+ .setNegativeButton(R.string.cancel, null)
+ .show();
+ });
+
+ tab2NameLinearLayout.setOnClickListener(view -> {
+ int titleId;
+ switch (tab2CurrentPostType) {
+ case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_SUBREDDIT:
+ titleId = R.string.settings_tab_subreddit_name;
+ break;
+ case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_MULTIREDDIT:
+ titleId = R.string.settings_tab_multi_reddit_name;
+ break;
+ case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_USER:
+ titleId = R.string.settings_tab_username;
+ break;
+ default:
+ return;
+ }
+ editText.setText(tab2CurrentName);
+ editText.setHint(titleId);
+ editText.requestFocus();
+ InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
+ if (imm != null) {
+ imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
+ }
+ if (dialogView.getParent() != null) {
+ ((ViewGroup) dialogView.getParent()).removeView(dialogView);
}
+ new MaterialAlertDialogBuilder(activity, R.style.MaterialAlertDialogTheme)
+ .setTitle(titleId)
+ .setView(dialogView)
+ .setPositiveButton(R.string.ok, (dialogInterface, i)
+ -> {
+ tab2CurrentName = editText.getText().toString();
+ sharedPreferences.edit().putString((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_2_NAME, tab2CurrentName).apply();
+ tab2NameSummaryTextView.setText(tab2CurrentName);
+ if (imm != null) {
+ imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
+ }
+ })
+ .setNegativeButton(R.string.cancel, (dialogInterface, i) -> {
+ if (imm != null) {
+ imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
+ }
+ })
+ .show();
+ });
- tab3PostTypePreference.setOnPreferenceChangeListener((preference, newValue) -> {
- switch ((String) newValue) {
- case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_HOME:
- case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_POPULAR:
- case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_ALL:
- tab3NamePreference.setVisible(false);
- break;
- case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_SUBREDDIT:
- tab3NamePreference.setVisible(true);
- tab3NamePreference.setTitle(R.string.settings_tab_subreddit_name);
- break;
- case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_MULTIREDDIT:
- tab3NamePreference.setVisible(true);
- tab3NamePreference.setTitle(R.string.settings_tab_multi_reddit_name);
- break;
- case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_USER:
- tab3NamePreference.setVisible(true);
- tab3NamePreference.setTitle(R.string.settings_tab_username);
- }
- return true;
- });
- }*/
+ tab3CurrentTitle = sharedPreferences.getString((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_3_TITLE, getString(R.string.all));
+ tab3CurrentPostType = sharedPreferences.getInt((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_3_POST_TYPE, SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_ALL);
+ tab3CurrentName = sharedPreferences.getString((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_3_NAME, "");
+ tab3TypeSummaryTextView.setText(typeValues[tab3CurrentPostType]);
+ tab3TitleSummaryTextView.setText(tab3CurrentTitle);
+ tab3NameSummaryTextView.setText(tab3CurrentName);
+ applyTab3NameView(tab3NameLinearLayout, tab3NameTitleTextView, tab3CurrentPostType);
+
+ tab3TitleLinearLayout.setOnClickListener(view -> {
+ editText.setHint(R.string.settings_tab_title);
+ editText.setText(tab3CurrentTitle);
+ editText.requestFocus();
+ InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
+ if (imm != null) {
+ imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
+ }
+ if (dialogView.getParent() != null) {
+ ((ViewGroup) dialogView.getParent()).removeView(dialogView);
+ }
+ new MaterialAlertDialogBuilder(activity, R.style.MaterialAlertDialogTheme)
+ .setTitle(R.string.settings_tab_title)
+ .setView(dialogView)
+ .setPositiveButton(R.string.ok, (dialogInterface, i)
+ -> {
+ tab3CurrentTitle = editText.getText().toString();
+ sharedPreferences.edit().putString((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_3_TITLE, tab3CurrentTitle).apply();
+ tab3TitleSummaryTextView.setText(tab3CurrentTitle);
+ if (imm != null) {
+ imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
+ }
+ })
+ .setNegativeButton(R.string.cancel, (dialogInterface, i) -> {
+ if (imm != null) {
+ imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
+ }
+ })
+ .show();
+ });
+
+ tab3TypeLinearLayout.setOnClickListener(view -> {
+ new MaterialAlertDialogBuilder(activity, R.style.MaterialAlertDialogTheme)
+ .setTitle(R.string.settings_tab_title)
+ .setSingleChoiceItems(typeValues, tab3CurrentPostType, (dialogInterface, i) -> {
+ tab3CurrentPostType = i;
+ sharedPreferences.edit().putInt((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_3_POST_TYPE, i).apply();
+ tab3TypeSummaryTextView.setText(typeValues[i]);
+ applyTab3NameView(tab3NameLinearLayout, tab3NameTitleTextView, i);
+ dialogInterface.dismiss();
+ })
+ .setNegativeButton(R.string.cancel, null)
+ .show();
+ });
+
+ tab3NameLinearLayout.setOnClickListener(view -> {
+ int titleId;
+ switch (tab3CurrentPostType) {
+ case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_SUBREDDIT:
+ titleId = R.string.settings_tab_subreddit_name;
+ break;
+ case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_MULTIREDDIT:
+ titleId = R.string.settings_tab_multi_reddit_name;
+ break;
+ case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_USER:
+ titleId = R.string.settings_tab_username;
+ break;
+ default:
+ return;
+ }
+ editText.setText(tab3CurrentName);
+ editText.setHint(titleId);
+ editText.requestFocus();
+ InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
+ if (imm != null) {
+ imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
+ }
+ if (dialogView.getParent() != null) {
+ ((ViewGroup) dialogView.getParent()).removeView(dialogView);
+ }
+ new MaterialAlertDialogBuilder(activity, R.style.MaterialAlertDialogTheme)
+ .setTitle(titleId)
+ .setView(dialogView)
+ .setPositiveButton(R.string.ok, (dialogInterface, i)
+ -> {
+ tab3CurrentName = editText.getText().toString();
+ sharedPreferences.edit().putString((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_3_NAME, tab3CurrentName).apply();
+ tab3NameSummaryTextView.setText(tab3CurrentName);
+ if (imm != null) {
+ imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
+ }
+ })
+ .setNegativeButton(R.string.cancel, (dialogInterface, i) -> {
+ if (imm != null) {
+ imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
+ }
+ })
+ .show();
+ });
+
+ return rootView;
+ }
+
+ private void applyTab1NameView(LinearLayout linearLayout, TextView titleTextView, int postType) {
+ switch (postType) {
+ case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_SUBREDDIT:
+ linearLayout.setVisibility(View.VISIBLE);
+ titleTextView.setText(R.string.settings_tab_subreddit_name);
+ break;
+ case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_MULTIREDDIT:
+ linearLayout.setVisibility(View.VISIBLE);
+ titleTextView.setText(R.string.settings_tab_multi_reddit_name);
+ break;
+ case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_USER:
+ linearLayout.setVisibility(View.VISIBLE);
+ titleTextView.setText(R.string.settings_tab_username);
+ break;
+ default:
+ linearLayout.setVisibility(View.GONE);
+ }
+ }
+
+ private void applyTab2NameView(LinearLayout linearLayout, TextView titleTextView, int postType) {
+ switch (postType) {
+ case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_SUBREDDIT:
+ linearLayout.setVisibility(View.VISIBLE);
+ titleTextView.setText(R.string.settings_tab_subreddit_name);
+ break;
+ case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_MULTIREDDIT:
+ linearLayout.setVisibility(View.VISIBLE);
+ titleTextView.setText(R.string.settings_tab_multi_reddit_name);
+ break;
+ case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_USER:
+ linearLayout.setVisibility(View.VISIBLE);
+ titleTextView.setText(R.string.settings_tab_username);
+ break;
+ default:
+ linearLayout.setVisibility(View.GONE);
+ }
+ }
+
+ private void applyTab3NameView(LinearLayout linearLayout, TextView titleTextView, int postType) {
+ switch (postType) {
+ case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_SUBREDDIT:
+ linearLayout.setVisibility(View.VISIBLE);
+ titleTextView.setText(R.string.settings_tab_subreddit_name);
+ break;
+ case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_MULTIREDDIT:
+ linearLayout.setVisibility(View.VISIBLE);
+ titleTextView.setText(R.string.settings_tab_multi_reddit_name);
+ break;
+ case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_USER:
+ linearLayout.setVisibility(View.VISIBLE);
+ titleTextView.setText(R.string.settings_tab_username);
+ break;
+ default:
+ linearLayout.setVisibility(View.GONE);
+ }
}
@Override
public void onAttach(@NonNull Context context) {
super.onAttach(context);
- activity = (SettingsActivity) context;
+ activity = (Activity) context;
}
-}
+} \ No newline at end of file
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/CustomizeMainPageTabsTestFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/CustomizeMainPageTabsTestFragment.java
deleted file mode 100644
index 88baf556..00000000
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/CustomizeMainPageTabsTestFragment.java
+++ /dev/null
@@ -1,501 +0,0 @@
-package ml.docilealligator.infinityforreddit.Settings;
-
-import android.app.Activity;
-import android.content.Context;
-import android.content.SharedPreferences;
-import android.os.Bundle;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.view.inputmethod.InputMethodManager;
-import android.widget.EditText;
-import android.widget.LinearLayout;
-import android.widget.TextView;
-
-import androidx.annotation.NonNull;
-import androidx.fragment.app.Fragment;
-
-import com.google.android.material.dialog.MaterialAlertDialogBuilder;
-
-import javax.inject.Inject;
-import javax.inject.Named;
-
-import butterknife.BindView;
-import butterknife.ButterKnife;
-import ml.docilealligator.infinityforreddit.Infinity;
-import ml.docilealligator.infinityforreddit.R;
-import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
-
-public class CustomizeMainPageTabsTestFragment extends Fragment {
-
- public static final String EXTRA_ACCOUNT_NAME = "EAN";
-
- @BindView(R.id.info_text_view_customize_main_page_tabs_fragment)
- TextView infoTextView;
- @BindView(R.id.divider_1_customize_main_page_tabs_fragment)
- View divider1;
- @BindView(R.id.tab_1_group_summary_customize_main_page_tabs_fragment)
- TextView tab1GroupSummaryTextView;
- @BindView(R.id.tab_1_title_linear_layout_customize_main_page_tabs_fragment)
- LinearLayout tab1TitleLinearLayout;
- @BindView(R.id.tab_1_title_summary_text_view_customize_main_page_tabs_fragment)
- TextView tab1TitleSummaryTextView;
- @BindView(R.id.tab_1_type_linear_layout_customize_main_page_tabs_fragment)
- LinearLayout tab1TypeLinearLayout;
- @BindView(R.id.tab_1_type_summary_text_view_customize_main_page_tabs_fragment)
- TextView tab1TypeSummaryTextView;
- @BindView(R.id.tab_1_name_linear_layout_customize_main_page_tabs_fragment)
- LinearLayout tab1NameLinearLayout;
- @BindView(R.id.tab_1_name_title_text_view_customize_main_page_tabs_fragment)
- TextView tab1NameTitleTextView;
- @BindView(R.id.tab_1_name_summary_text_view_customize_main_page_tabs_fragment)
- TextView tab1NameSummaryTextView;
- @BindView(R.id.divider_2_customize_main_page_tabs_fragment)
- View divider2;
- @BindView(R.id.tab_2_group_summary_customize_main_page_tabs_fragment)
- TextView tab2GroupSummaryTextView;
- @BindView(R.id.tab_2_title_linear_layout_customize_main_page_tabs_fragment)
- LinearLayout tab2TitleLinearLayout;
- @BindView(R.id.tab_2_title_summary_text_view_customize_main_page_tabs_fragment)
- TextView tab2TitleSummaryTextView;
- @BindView(R.id.tab_2_type_linear_layout_customize_main_page_tabs_fragment)
- LinearLayout tab2TypeLinearLayout;
- @BindView(R.id.tab_2_type_summary_text_view_customize_main_page_tabs_fragment)
- TextView tab2TypeSummaryTextView;
- @BindView(R.id.tab_2_name_linear_layout_customize_main_page_tabs_fragment)
- LinearLayout tab2NameLinearLayout;
- @BindView(R.id.tab_2_name_title_text_view_customize_main_page_tabs_fragment)
- TextView tab2NameTitleTextView;
- @BindView(R.id.tab_2_name_summary_text_view_customize_main_page_tabs_fragment)
- TextView tab2NameSummaryTextView;
- @BindView(R.id.divider_3_customize_main_page_tabs_fragment)
- View divider3;
- @BindView(R.id.tab_3_group_summary_customize_main_page_tabs_fragment)
- TextView tab3GroupSummaryTextView;
- @BindView(R.id.tab_3_title_linear_layout_customize_main_page_tabs_fragment)
- LinearLayout tab3TitleLinearLayout;
- @BindView(R.id.tab_3_title_summary_text_view_customize_main_page_tabs_fragment)
- TextView tab3TitleSummaryTextView;
- @BindView(R.id.tab_3_type_linear_layout_customize_main_page_tabs_fragment)
- LinearLayout tab3TypeLinearLayout;
- @BindView(R.id.tab_3_type_summary_text_view_customize_main_page_tabs_fragment)
- TextView tab3TypeSummaryTextView;
- @BindView(R.id.tab_3_name_linear_layout_customize_main_page_tabs_fragment)
- LinearLayout tab3NameLinearLayout;
- @BindView(R.id.tab_3_name_title_text_view_customize_main_page_tabs_fragment)
- TextView tab3NameTitleTextView;
- @BindView(R.id.tab_3_name_summary_text_view_customize_main_page_tabs_fragment)
- TextView tab3NameSummaryTextView;
- @Inject
- @Named("main_activity_tabs")
- SharedPreferences sharedPreferences;
- private Activity activity;
- private String tab1CurrentTitle;
- private int tab1CurrentPostType;
- private String tab1CurrentName;
- private String tab2CurrentTitle;
- private int tab2CurrentPostType;
- private String tab2CurrentName;
- private String tab3CurrentTitle;
- private int tab3CurrentPostType;
- private String tab3CurrentName;
-
- public CustomizeMainPageTabsTestFragment() {
- // Required empty public constructor
- }
-
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- // Inflate the layout for this fragment
- View rootView = inflater.inflate(R.layout.fragment_customize_main_page_tabs_test, container, false);
-
- ((Infinity) activity.getApplication()).getAppComponent().inject(this);
-
- ButterKnife.bind(this, rootView);
-
- String accountName = getArguments().getString(EXTRA_ACCOUNT_NAME);
-
- if (accountName == null) {
- infoTextView.setText(R.string.settings_customize_tabs_in_main_page_summary);
- divider1.setVisibility(View.GONE);
- tab1GroupSummaryTextView.setVisibility(View.GONE);
- tab1TitleLinearLayout.setVisibility(View.GONE);
- tab1TypeLinearLayout.setVisibility(View.GONE);
- divider2.setVisibility(View.GONE);
- tab2GroupSummaryTextView.setVisibility(View.GONE);
- tab2TitleLinearLayout.setVisibility(View.GONE);
- tab2TypeLinearLayout.setVisibility(View.GONE);
- divider3.setVisibility(View.GONE);
- tab3GroupSummaryTextView.setVisibility(View.GONE);
- tab3TitleLinearLayout.setVisibility(View.GONE);
- tab3TypeLinearLayout.setVisibility(View.GONE);
-
- return rootView;
- }
-
- String[] typeValues = activity.getResources().getStringArray(R.array.settings_tab_post_type);
-
- tab1CurrentTitle = sharedPreferences.getString((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_1_TITLE, getString(R.string.home));
- tab1CurrentPostType = sharedPreferences.getInt((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_1_POST_TYPE, SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_HOME);
- tab1CurrentName = sharedPreferences.getString((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_1_NAME, "");
- tab1TypeSummaryTextView.setText(typeValues[tab1CurrentPostType]);
- tab1TitleSummaryTextView.setText(tab1CurrentTitle);
- tab1NameSummaryTextView.setText(tab1CurrentName);
- applyTab1NameView(tab1NameLinearLayout, tab1NameTitleTextView, tab1CurrentPostType);
-
- View dialogView = activity.getLayoutInflater().inflate(R.layout.dialog_edit_text, null);
- EditText editText = dialogView.findViewById(R.id.edit_text_edit_text_dialog);
-
- tab1TitleLinearLayout.setOnClickListener(view -> {
- editText.setHint(R.string.settings_tab_title);
- editText.setText(tab1CurrentTitle);
- editText.requestFocus();
- InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
- if (imm != null) {
- imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
- }
- if (dialogView.getParent() != null) {
- ((ViewGroup) dialogView.getParent()).removeView(dialogView);
- }
- new MaterialAlertDialogBuilder(activity, R.style.MaterialAlertDialogTheme)
- .setTitle(R.string.settings_tab_title)
- .setView(dialogView)
- .setPositiveButton(R.string.ok, (dialogInterface, i)
- -> {
- tab1CurrentTitle = editText.getText().toString();
- sharedPreferences.edit().putString((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_1_TITLE, tab1CurrentTitle).apply();
- tab1TitleSummaryTextView.setText(tab1CurrentTitle);
- if (imm != null) {
- imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
- }
- })
- .setNegativeButton(R.string.cancel, (dialogInterface, i) -> {
- if (imm != null) {
- imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
- }
- })
- .show();
- });
-
- tab1TypeLinearLayout.setOnClickListener(view -> {
- new MaterialAlertDialogBuilder(activity, R.style.MaterialAlertDialogTheme)
- .setTitle(R.string.settings_tab_title)
- .setSingleChoiceItems(typeValues, tab1CurrentPostType, (dialogInterface, i) -> {
- tab1CurrentPostType = i;
- sharedPreferences.edit().putInt((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_1_POST_TYPE, i).apply();
- tab1TypeSummaryTextView.setText(typeValues[i]);
- applyTab1NameView(tab1NameLinearLayout, tab1NameTitleTextView, i);
- dialogInterface.dismiss();
- })
- .setNegativeButton(R.string.cancel, null)
- .show();
- });
-
- tab1NameLinearLayout.setOnClickListener(view -> {
- int titleId;
- switch (tab1CurrentPostType) {
- case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_SUBREDDIT:
- titleId = R.string.settings_tab_subreddit_name;
- break;
- case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_MULTIREDDIT:
- titleId = R.string.settings_tab_multi_reddit_name;
- break;
- case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_USER:
- titleId = R.string.settings_tab_username;
- break;
- default:
- return;
- }
- editText.setText(tab1CurrentName);
- editText.setHint(titleId);
- editText.requestFocus();
- InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
- if (imm != null) {
- imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
- }
- if (dialogView.getParent() != null) {
- ((ViewGroup) dialogView.getParent()).removeView(dialogView);
- }
- new MaterialAlertDialogBuilder(activity, R.style.MaterialAlertDialogTheme)
- .setTitle(titleId)
- .setView(dialogView)
- .setPositiveButton(R.string.ok, (dialogInterface, i)
- -> {
- tab1CurrentName = editText.getText().toString();
- sharedPreferences.edit().putString((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_1_NAME, tab1CurrentName).apply();
- tab1NameSummaryTextView.setText(tab1CurrentName);
- if (imm != null) {
- imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
- }
- })
- .setNegativeButton(R.string.cancel, (dialogInterface, i) -> {
- if (imm != null) {
- imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
- }
- })
- .show();
- });
-
- tab2CurrentTitle = sharedPreferences.getString((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_2_TITLE, getString(R.string.popular));
- tab2CurrentPostType = sharedPreferences.getInt((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_2_POST_TYPE, SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_POPULAR);
- tab2CurrentName = sharedPreferences.getString((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_2_NAME, "");
- tab2TypeSummaryTextView.setText(typeValues[tab2CurrentPostType]);
- tab2TitleSummaryTextView.setText(tab2CurrentTitle);
- tab2NameSummaryTextView.setText(tab2CurrentName);
- applyTab2NameView(tab2NameLinearLayout, tab2NameTitleTextView, tab2CurrentPostType);
-
- tab2TitleLinearLayout.setOnClickListener(view -> {
- editText.setHint(R.string.settings_tab_title);
- editText.setText(tab2CurrentTitle);
- editText.requestFocus();
- InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
- if (imm != null) {
- imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
- }
- if (dialogView.getParent() != null) {
- ((ViewGroup) dialogView.getParent()).removeView(dialogView);
- }
- new MaterialAlertDialogBuilder(activity, R.style.MaterialAlertDialogTheme)
- .setTitle(R.string.settings_tab_title)
- .setView(dialogView)
- .setPositiveButton(R.string.ok, (dialogInterface, i)
- -> {
- tab2CurrentTitle = editText.getText().toString();
- sharedPreferences.edit().putString((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_2_TITLE, tab2CurrentTitle).apply();
- tab2TitleSummaryTextView.setText(tab2CurrentTitle);
- if (imm != null) {
- imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
- }
- })
- .setNegativeButton(R.string.cancel, (dialogInterface, i) -> {
- if (imm != null) {
- imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
- }
- })
- .show();
- });
-
- tab2TypeLinearLayout.setOnClickListener(view -> {
- new MaterialAlertDialogBuilder(activity, R.style.MaterialAlertDialogTheme)
- .setTitle(R.string.settings_tab_title)
- .setSingleChoiceItems(typeValues, tab2CurrentPostType, (dialogInterface, i) -> {
- tab2CurrentPostType = i;
- sharedPreferences.edit().putInt((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_2_POST_TYPE, i).apply();
- tab2TypeSummaryTextView.setText(typeValues[i]);
- applyTab2NameView(tab2NameLinearLayout, tab2NameTitleTextView, i);
- dialogInterface.dismiss();
- })
- .setNegativeButton(R.string.cancel, null)
- .show();
- });
-
- tab2NameLinearLayout.setOnClickListener(view -> {
- int titleId;
- switch (tab2CurrentPostType) {
- case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_SUBREDDIT:
- titleId = R.string.settings_tab_subreddit_name;
- break;
- case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_MULTIREDDIT:
- titleId = R.string.settings_tab_multi_reddit_name;
- break;
- case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_USER:
- titleId = R.string.settings_tab_username;
- break;
- default:
- return;
- }
- editText.setText(tab2CurrentName);
- editText.setHint(titleId);
- editText.requestFocus();
- InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
- if (imm != null) {
- imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
- }
- if (dialogView.getParent() != null) {
- ((ViewGroup) dialogView.getParent()).removeView(dialogView);
- }
- new MaterialAlertDialogBuilder(activity, R.style.MaterialAlertDialogTheme)
- .setTitle(titleId)
- .setView(dialogView)
- .setPositiveButton(R.string.ok, (dialogInterface, i)
- -> {
- tab2CurrentName = editText.getText().toString();
- sharedPreferences.edit().putString((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_2_NAME, tab2CurrentName).apply();
- tab2NameSummaryTextView.setText(tab2CurrentName);
- if (imm != null) {
- imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
- }
- })
- .setNegativeButton(R.string.cancel, (dialogInterface, i) -> {
- if (imm != null) {
- imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
- }
- })
- .show();
- });
-
- tab3CurrentTitle = sharedPreferences.getString((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_3_TITLE, getString(R.string.all));
- tab3CurrentPostType = sharedPreferences.getInt((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_3_POST_TYPE, SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_ALL);
- tab3CurrentName = sharedPreferences.getString((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_3_NAME, "");
- tab3TypeSummaryTextView.setText(typeValues[tab3CurrentPostType]);
- tab3TitleSummaryTextView.setText(tab3CurrentTitle);
- tab3NameSummaryTextView.setText(tab3CurrentName);
- applyTab3NameView(tab3NameLinearLayout, tab3NameTitleTextView, tab3CurrentPostType);
-
- tab3TitleLinearLayout.setOnClickListener(view -> {
- editText.setHint(R.string.settings_tab_title);
- editText.setText(tab3CurrentTitle);
- editText.requestFocus();
- InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
- if (imm != null) {
- imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
- }
- if (dialogView.getParent() != null) {
- ((ViewGroup) dialogView.getParent()).removeView(dialogView);
- }
- new MaterialAlertDialogBuilder(activity, R.style.MaterialAlertDialogTheme)
- .setTitle(R.string.settings_tab_title)
- .setView(dialogView)
- .setPositiveButton(R.string.ok, (dialogInterface, i)
- -> {
- tab3CurrentTitle = editText.getText().toString();
- sharedPreferences.edit().putString((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_3_TITLE, tab3CurrentTitle).apply();
- tab3TitleSummaryTextView.setText(tab3CurrentTitle);
- if (imm != null) {
- imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
- }
- })
- .setNegativeButton(R.string.cancel, (dialogInterface, i) -> {
- if (imm != null) {
- imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
- }
- })
- .show();
- });
-
- tab3TypeLinearLayout.setOnClickListener(view -> {
- new MaterialAlertDialogBuilder(activity, R.style.MaterialAlertDialogTheme)
- .setTitle(R.string.settings_tab_title)
- .setSingleChoiceItems(typeValues, tab3CurrentPostType, (dialogInterface, i) -> {
- tab3CurrentPostType = i;
- sharedPreferences.edit().putInt((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_3_POST_TYPE, i).apply();
- tab3TypeSummaryTextView.setText(typeValues[i]);
- applyTab3NameView(tab3NameLinearLayout, tab3NameTitleTextView, i);
- dialogInterface.dismiss();
- })
- .setNegativeButton(R.string.cancel, null)
- .show();
- });
-
- tab3NameLinearLayout.setOnClickListener(view -> {
- int titleId;
- switch (tab3CurrentPostType) {
- case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_SUBREDDIT:
- titleId = R.string.settings_tab_subreddit_name;
- break;
- case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_MULTIREDDIT:
- titleId = R.string.settings_tab_multi_reddit_name;
- break;
- case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_USER:
- titleId = R.string.settings_tab_username;
- break;
- default:
- return;
- }
- editText.setText(tab3CurrentName);
- editText.setHint(titleId);
- editText.requestFocus();
- InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
- if (imm != null) {
- imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
- }
- if (dialogView.getParent() != null) {
- ((ViewGroup) dialogView.getParent()).removeView(dialogView);
- }
- new MaterialAlertDialogBuilder(activity, R.style.MaterialAlertDialogTheme)
- .setTitle(titleId)
- .setView(dialogView)
- .setPositiveButton(R.string.ok, (dialogInterface, i)
- -> {
- tab3CurrentName = editText.getText().toString();
- sharedPreferences.edit().putString((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_3_NAME, tab3CurrentName).apply();
- tab3NameSummaryTextView.setText(tab3CurrentName);
- if (imm != null) {
- imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
- }
- })
- .setNegativeButton(R.string.cancel, (dialogInterface, i) -> {
- if (imm != null) {
- imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
- }
- })
- .show();
- });
-
- return rootView;
- }
-
- private void applyTab1NameView(LinearLayout linearLayout, TextView titleTextView, int postType) {
- switch (postType) {
- case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_SUBREDDIT:
- linearLayout.setVisibility(View.VISIBLE);
- titleTextView.setText(R.string.settings_tab_subreddit_name);
- break;
- case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_MULTIREDDIT:
- linearLayout.setVisibility(View.VISIBLE);
- titleTextView.setText(R.string.settings_tab_multi_reddit_name);
- break;
- case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_USER:
- linearLayout.setVisibility(View.VISIBLE);
- titleTextView.setText(R.string.settings_tab_username);
- break;
- default:
- linearLayout.setVisibility(View.GONE);
- }
- }
-
- private void applyTab2NameView(LinearLayout linearLayout, TextView titleTextView, int postType) {
- switch (postType) {
- case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_SUBREDDIT:
- linearLayout.setVisibility(View.VISIBLE);
- titleTextView.setText(R.string.settings_tab_subreddit_name);
- break;
- case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_MULTIREDDIT:
- linearLayout.setVisibility(View.VISIBLE);
- titleTextView.setText(R.string.settings_tab_multi_reddit_name);
- break;
- case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_USER:
- linearLayout.setVisibility(View.VISIBLE);
- titleTextView.setText(R.string.settings_tab_username);
- break;
- default:
- linearLayout.setVisibility(View.GONE);
- }
- }
-
- private void applyTab3NameView(LinearLayout linearLayout, TextView titleTextView, int postType) {
- switch (postType) {
- case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_SUBREDDIT:
- linearLayout.setVisibility(View.VISIBLE);
- titleTextView.setText(R.string.settings_tab_subreddit_name);
- break;
- case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_MULTIREDDIT:
- linearLayout.setVisibility(View.VISIBLE);
- titleTextView.setText(R.string.settings_tab_multi_reddit_name);
- break;
- case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_USER:
- linearLayout.setVisibility(View.VISIBLE);
- titleTextView.setText(R.string.settings_tab_username);
- break;
- default:
- linearLayout.setVisibility(View.GONE);
- }
- }
-
- @Override
- public void onAttach(@NonNull Context context) {
- super.onAttach(context);
- activity = (Activity) context;
- }
-} \ No newline at end of file