Add a button to directly select subreddit, user or multireddit in CustomizeMainPageTabsFragment.

This commit is contained in:
Alex Ning 2021-10-16 14:46:01 +08:00
parent 1d18e2c75b
commit 1d7fbe3a99
6 changed files with 290 additions and 81 deletions

View File

@ -46,7 +46,7 @@ import retrofit2.Retrofit;
public class MultiredditSelectionActivity extends BaseActivity implements ActivityToolbarInterface { public class MultiredditSelectionActivity extends BaseActivity implements ActivityToolbarInterface {
static final String EXTRA_RETURN_MULTIREDDIT = "ERM"; public static final String EXTRA_RETURN_MULTIREDDIT = "ERM";
private static final String INSERT_SUBSCRIBED_MULTIREDDIT_STATE = "ISSS"; private static final String INSERT_SUBSCRIBED_MULTIREDDIT_STATE = "ISSS";
private static final String FRAGMENT_OUT_STATE = "FOS"; private static final String FRAGMENT_OUT_STATE = "FOS";

View File

@ -58,19 +58,19 @@ import retrofit2.Retrofit;
public class SearchActivity extends BaseActivity { public class SearchActivity extends BaseActivity {
static final String EXTRA_QUERY = "EQ"; public static final String EXTRA_QUERY = "EQ";
static final String EXTRA_SUBREDDIT_NAME = "ESN"; public static final String EXTRA_SUBREDDIT_NAME = "ESN";
static final String EXTRA_SUBREDDIT_IS_USER = "ESIU"; public static final String EXTRA_SUBREDDIT_IS_USER = "ESIU";
static final String EXTRA_SEARCH_ONLY_SUBREDDITS = "ESOS"; public static final String EXTRA_SEARCH_ONLY_SUBREDDITS = "ESOS";
static final String EXTRA_SEARCH_ONLY_USERS = "ESOU"; public static final String EXTRA_SEARCH_ONLY_USERS = "ESOU";
static final String EXTRA_RETURN_SUBREDDIT_NAME = "ERSN"; public static final String EXTRA_RETURN_SUBREDDIT_NAME = "ERSN";
static final String EXTRA_RETURN_SUBREDDIT_ICON_URL = "ERSIU"; public static final String EXTRA_RETURN_SUBREDDIT_ICON_URL = "ERSIU";
static final String RETURN_EXTRA_SELECTED_SUBREDDIT_NAMES = "RESSN"; public static final String RETURN_EXTRA_SELECTED_SUBREDDIT_NAMES = "RESSN";
static final String RETURN_EXTRA_SELECTED_USERNAMES = "RESU"; public static final String RETURN_EXTRA_SELECTED_USERNAMES = "RESU";
static final String EXTRA_RETURN_USER_NAME = "ERUN"; public static final String EXTRA_RETURN_USER_NAME = "ERUN";
static final String EXTRA_RETURN_USER_ICON_URL = "ERUIU"; public static final String EXTRA_RETURN_USER_ICON_URL = "ERUIU";
static final String EXTRA_IS_MULTI_SELECTION = "EIMS"; public static final String EXTRA_IS_MULTI_SELECTION = "EIMS";
static final int SUICIDE_PREVENTION_ACTIVITY_REQUEST_CODE = 101; public static final int SUICIDE_PREVENTION_ACTIVITY_REQUEST_CODE = 101;
private static final String SUBREDDIT_NAME_STATE = "SNS"; private static final String SUBREDDIT_NAME_STATE = "SNS";
private static final String SUBREDDIT_IS_USER_STATE = "SIUS"; private static final String SUBREDDIT_IS_USER_STATE = "SIUS";

View File

@ -49,10 +49,10 @@ import retrofit2.Retrofit;
public class SubredditSelectionActivity extends BaseActivity implements ActivityToolbarInterface { public class SubredditSelectionActivity extends BaseActivity implements ActivityToolbarInterface {
static final String EXTRA_EXTRA_CLEAR_SELECTION = "EECS"; public static final String EXTRA_EXTRA_CLEAR_SELECTION = "EECS";
static final String EXTRA_RETURN_SUBREDDIT_NAME = "ERSN"; public static final String EXTRA_RETURN_SUBREDDIT_NAME = "ERSN";
static final String EXTRA_RETURN_SUBREDDIT_ICON_URL = "ERSIURL"; public static final String EXTRA_RETURN_SUBREDDIT_ICON_URL = "ERSIURL";
static final String EXTRA_RETURN_SUBREDDIT_IS_USER = "ERSIU"; public static final String EXTRA_RETURN_SUBREDDIT_IS_USER = "ERSIU";
private static final int SUBREDDIT_SEARCH_REQUEST_CODE = 0; private static final int SUBREDDIT_SEARCH_REQUEST_CODE = 0;
private static final String INSERT_SUBSCRIBED_SUBREDDIT_STATE = "ISSS"; private static final String INSERT_SUBSCRIBED_SUBREDDIT_STATE = "ISSS";

View File

@ -2,6 +2,7 @@ package ml.docilealligator.infinityforreddit.settings;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@ -9,10 +10,13 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodManager;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.google.android.material.dialog.MaterialAlertDialogBuilder;
@ -25,6 +29,10 @@ import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.activities.MultiredditSelectionActivity;
import ml.docilealligator.infinityforreddit.activities.SearchActivity;
import ml.docilealligator.infinityforreddit.activities.SubredditSelectionActivity;
import ml.docilealligator.infinityforreddit.multireddit.MultiReddit;
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
public class CustomizeMainPageTabsFragment extends Fragment { public class CustomizeMainPageTabsFragment extends Fragment {
@ -53,12 +61,14 @@ public class CustomizeMainPageTabsFragment extends Fragment {
LinearLayout tab1TypeLinearLayout; LinearLayout tab1TypeLinearLayout;
@BindView(R.id.tab_1_type_summary_text_view_customize_main_page_tabs_fragment) @BindView(R.id.tab_1_type_summary_text_view_customize_main_page_tabs_fragment)
TextView tab1TypeSummaryTextView; TextView tab1TypeSummaryTextView;
@BindView(R.id.tab_1_name_linear_layout_customize_main_page_tabs_fragment) @BindView(R.id.tab_1_name_constraint_layout_customize_main_page_tabs_fragment)
LinearLayout tab1NameLinearLayout; ConstraintLayout tab1NameConstraintLayout;
@BindView(R.id.tab_1_name_title_text_view_customize_main_page_tabs_fragment) @BindView(R.id.tab_1_name_title_text_view_customize_main_page_tabs_fragment)
TextView tab1NameTitleTextView; TextView tab1NameTitleTextView;
@BindView(R.id.tab_1_name_summary_text_view_customize_main_page_tabs_fragment) @BindView(R.id.tab_1_name_summary_text_view_customize_main_page_tabs_fragment)
TextView tab1NameSummaryTextView; TextView tab1NameSummaryTextView;
@BindView(R.id.tab_1_name_add_image_view_customize_main_page_tabs_fragment)
ImageView tab1AddImageView;
@BindView(R.id.divider_2_customize_main_page_tabs_fragment) @BindView(R.id.divider_2_customize_main_page_tabs_fragment)
View divider2; View divider2;
@BindView(R.id.tab_2_group_summary_customize_main_page_tabs_fragment) @BindView(R.id.tab_2_group_summary_customize_main_page_tabs_fragment)
@ -71,12 +81,14 @@ public class CustomizeMainPageTabsFragment extends Fragment {
LinearLayout tab2TypeLinearLayout; LinearLayout tab2TypeLinearLayout;
@BindView(R.id.tab_2_type_summary_text_view_customize_main_page_tabs_fragment) @BindView(R.id.tab_2_type_summary_text_view_customize_main_page_tabs_fragment)
TextView tab2TypeSummaryTextView; TextView tab2TypeSummaryTextView;
@BindView(R.id.tab_2_name_linear_layout_customize_main_page_tabs_fragment) @BindView(R.id.tab_2_name_constraint_layout_customize_main_page_tabs_fragment)
LinearLayout tab2NameLinearLayout; ConstraintLayout tab2NameConstraintLayout;
@BindView(R.id.tab_2_name_title_text_view_customize_main_page_tabs_fragment) @BindView(R.id.tab_2_name_title_text_view_customize_main_page_tabs_fragment)
TextView tab2NameTitleTextView; TextView tab2NameTitleTextView;
@BindView(R.id.tab_2_name_summary_text_view_customize_main_page_tabs_fragment) @BindView(R.id.tab_2_name_summary_text_view_customize_main_page_tabs_fragment)
TextView tab2NameSummaryTextView; TextView tab2NameSummaryTextView;
@BindView(R.id.tab_2_name_add_image_view_customize_main_page_tabs_fragment)
ImageView tab2AddImageView;
@BindView(R.id.divider_3_customize_main_page_tabs_fragment) @BindView(R.id.divider_3_customize_main_page_tabs_fragment)
View divider3; View divider3;
@BindView(R.id.tab_3_group_summary_customize_main_page_tabs_fragment) @BindView(R.id.tab_3_group_summary_customize_main_page_tabs_fragment)
@ -89,12 +101,14 @@ public class CustomizeMainPageTabsFragment extends Fragment {
LinearLayout tab3TypeLinearLayout; LinearLayout tab3TypeLinearLayout;
@BindView(R.id.tab_3_type_summary_text_view_customize_main_page_tabs_fragment) @BindView(R.id.tab_3_type_summary_text_view_customize_main_page_tabs_fragment)
TextView tab3TypeSummaryTextView; TextView tab3TypeSummaryTextView;
@BindView(R.id.tab_3_name_linear_layout_customize_main_page_tabs_fragment) @BindView(R.id.tab_3_name_constraint_layout_customize_main_page_tabs_fragment)
LinearLayout tab3NameLinearLayout; ConstraintLayout tab3NameConstraintLayout;
@BindView(R.id.tab_3_name_title_text_view_customize_main_page_tabs_fragment) @BindView(R.id.tab_3_name_title_text_view_customize_main_page_tabs_fragment)
TextView tab3NameTitleTextView; TextView tab3NameTitleTextView;
@BindView(R.id.tab_3_name_summary_text_view_customize_main_page_tabs_fragment) @BindView(R.id.tab_3_name_summary_text_view_customize_main_page_tabs_fragment)
TextView tab3NameSummaryTextView; TextView tab3NameSummaryTextView;
@BindView(R.id.tab_3_name_add_image_view_customize_main_page_tabs_fragment)
ImageView tab3AddImageView;
@BindView(R.id.divider_4_customize_main_page_tabs_fragment) @BindView(R.id.divider_4_customize_main_page_tabs_fragment)
View divider4; View divider4;
@BindView(R.id.more_tabs_group_summary_customize_main_page_tabs_fragment) @BindView(R.id.more_tabs_group_summary_customize_main_page_tabs_fragment)
@ -121,6 +135,7 @@ public class CustomizeMainPageTabsFragment extends Fragment {
@Named("main_activity_tabs") @Named("main_activity_tabs")
SharedPreferences mainActivityTabsSharedPreferences; SharedPreferences mainActivityTabsSharedPreferences;
private Activity activity; private Activity activity;
private String accountName;
private int tabCount; private int tabCount;
private String tab1CurrentTitle; private String tab1CurrentTitle;
private int tab1CurrentPostType; private int tab1CurrentPostType;
@ -146,7 +161,7 @@ public class CustomizeMainPageTabsFragment extends Fragment {
ButterKnife.bind(this, rootView); ButterKnife.bind(this, rootView);
String accountName = getArguments().getString(EXTRA_ACCOUNT_NAME); accountName = getArguments().getString(EXTRA_ACCOUNT_NAME);
String[] typeValues; String[] typeValues;
if (accountName == null) { if (accountName == null) {
@ -180,7 +195,7 @@ public class CustomizeMainPageTabsFragment extends Fragment {
tab1TypeSummaryTextView.setText(typeValues[tab1CurrentPostType]); tab1TypeSummaryTextView.setText(typeValues[tab1CurrentPostType]);
tab1TitleSummaryTextView.setText(tab1CurrentTitle); tab1TitleSummaryTextView.setText(tab1CurrentTitle);
tab1NameSummaryTextView.setText(tab1CurrentName); tab1NameSummaryTextView.setText(tab1CurrentName);
applyTab1NameView(tab1NameLinearLayout, tab1NameTitleTextView, tab1CurrentPostType); applyTab1NameView(tab1NameConstraintLayout, tab1NameTitleTextView, tab1CurrentPostType);
View dialogView = activity.getLayoutInflater().inflate(R.layout.dialog_edit_text, null); View dialogView = activity.getLayoutInflater().inflate(R.layout.dialog_edit_text, null);
EditText editText = dialogView.findViewById(R.id.edit_text_edit_text_dialog); EditText editText = dialogView.findViewById(R.id.edit_text_edit_text_dialog);
@ -223,14 +238,14 @@ public class CustomizeMainPageTabsFragment extends Fragment {
tab1CurrentPostType = i; tab1CurrentPostType = i;
mainActivityTabsSharedPreferences.edit().putInt((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_1_POST_TYPE, i).apply(); mainActivityTabsSharedPreferences.edit().putInt((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_1_POST_TYPE, i).apply();
tab1TypeSummaryTextView.setText(typeValues[i]); tab1TypeSummaryTextView.setText(typeValues[i]);
applyTab1NameView(tab1NameLinearLayout, tab1NameTitleTextView, i); applyTab1NameView(tab1NameConstraintLayout, tab1NameTitleTextView, i);
dialogInterface.dismiss(); dialogInterface.dismiss();
}) })
.setNegativeButton(R.string.cancel, null) .setNegativeButton(R.string.cancel, null)
.show(); .show();
}); });
tab1NameLinearLayout.setOnClickListener(view -> { tab1NameConstraintLayout.setOnClickListener(view -> {
int titleId; int titleId;
switch (tab1CurrentPostType) { switch (tab1CurrentPostType) {
case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_SUBREDDIT: case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_SUBREDDIT:
@ -275,13 +290,15 @@ public class CustomizeMainPageTabsFragment extends Fragment {
.show(); .show();
}); });
tab1AddImageView.setOnClickListener(view -> selectName(0));
tab2CurrentTitle = mainActivityTabsSharedPreferences.getString((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_2_TITLE, getString(R.string.popular)); tab2CurrentTitle = mainActivityTabsSharedPreferences.getString((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_2_TITLE, getString(R.string.popular));
tab2CurrentPostType = mainActivityTabsSharedPreferences.getInt((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_2_POST_TYPE, SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_POPULAR); tab2CurrentPostType = mainActivityTabsSharedPreferences.getInt((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_2_POST_TYPE, SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_POPULAR);
tab2CurrentName = mainActivityTabsSharedPreferences.getString((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_2_NAME, ""); tab2CurrentName = mainActivityTabsSharedPreferences.getString((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_2_NAME, "");
tab2TypeSummaryTextView.setText(typeValues[tab2CurrentPostType]); tab2TypeSummaryTextView.setText(typeValues[tab2CurrentPostType]);
tab2TitleSummaryTextView.setText(tab2CurrentTitle); tab2TitleSummaryTextView.setText(tab2CurrentTitle);
tab2NameSummaryTextView.setText(tab2CurrentName); tab2NameSummaryTextView.setText(tab2CurrentName);
applyTab2NameView(tab2NameLinearLayout, tab2NameTitleTextView, tab2CurrentPostType); applyTab2NameView(tab2NameConstraintLayout, tab2NameTitleTextView, tab2CurrentPostType);
tab2TitleLinearLayout.setOnClickListener(view -> { tab2TitleLinearLayout.setOnClickListener(view -> {
editText.setHint(R.string.settings_tab_title); editText.setHint(R.string.settings_tab_title);
@ -321,14 +338,14 @@ public class CustomizeMainPageTabsFragment extends Fragment {
tab2CurrentPostType = i; tab2CurrentPostType = i;
mainActivityTabsSharedPreferences.edit().putInt((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_2_POST_TYPE, i).apply(); mainActivityTabsSharedPreferences.edit().putInt((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_2_POST_TYPE, i).apply();
tab2TypeSummaryTextView.setText(typeValues[i]); tab2TypeSummaryTextView.setText(typeValues[i]);
applyTab2NameView(tab2NameLinearLayout, tab2NameTitleTextView, i); applyTab2NameView(tab2NameConstraintLayout, tab2NameTitleTextView, i);
dialogInterface.dismiss(); dialogInterface.dismiss();
}) })
.setNegativeButton(R.string.cancel, null) .setNegativeButton(R.string.cancel, null)
.show(); .show();
}); });
tab2NameLinearLayout.setOnClickListener(view -> { tab2NameConstraintLayout.setOnClickListener(view -> {
int titleId; int titleId;
switch (tab2CurrentPostType) { switch (tab2CurrentPostType) {
case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_SUBREDDIT: case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_SUBREDDIT:
@ -373,13 +390,15 @@ public class CustomizeMainPageTabsFragment extends Fragment {
.show(); .show();
}); });
tab2AddImageView.setOnClickListener(view -> selectName(1));
tab3CurrentTitle = mainActivityTabsSharedPreferences.getString((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_3_TITLE, getString(R.string.all)); tab3CurrentTitle = mainActivityTabsSharedPreferences.getString((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_3_TITLE, getString(R.string.all));
tab3CurrentPostType = mainActivityTabsSharedPreferences.getInt((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_3_POST_TYPE, SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_ALL); tab3CurrentPostType = mainActivityTabsSharedPreferences.getInt((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_3_POST_TYPE, SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_ALL);
tab3CurrentName = mainActivityTabsSharedPreferences.getString((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_3_NAME, ""); tab3CurrentName = mainActivityTabsSharedPreferences.getString((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_3_NAME, "");
tab3TypeSummaryTextView.setText(typeValues[tab3CurrentPostType]); tab3TypeSummaryTextView.setText(typeValues[tab3CurrentPostType]);
tab3TitleSummaryTextView.setText(tab3CurrentTitle); tab3TitleSummaryTextView.setText(tab3CurrentTitle);
tab3NameSummaryTextView.setText(tab3CurrentName); tab3NameSummaryTextView.setText(tab3CurrentName);
applyTab3NameView(tab3NameLinearLayout, tab3NameTitleTextView, tab3CurrentPostType); applyTab3NameView(tab3NameConstraintLayout, tab3NameTitleTextView, tab3CurrentPostType);
tab3TitleLinearLayout.setOnClickListener(view -> { tab3TitleLinearLayout.setOnClickListener(view -> {
editText.setHint(R.string.settings_tab_title); editText.setHint(R.string.settings_tab_title);
@ -419,14 +438,14 @@ public class CustomizeMainPageTabsFragment extends Fragment {
tab3CurrentPostType = i; tab3CurrentPostType = i;
mainActivityTabsSharedPreferences.edit().putInt((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_3_POST_TYPE, i).apply(); mainActivityTabsSharedPreferences.edit().putInt((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_3_POST_TYPE, i).apply();
tab3TypeSummaryTextView.setText(typeValues[i]); tab3TypeSummaryTextView.setText(typeValues[i]);
applyTab3NameView(tab3NameLinearLayout, tab3NameTitleTextView, i); applyTab3NameView(tab3NameConstraintLayout, tab3NameTitleTextView, i);
dialogInterface.dismiss(); dialogInterface.dismiss();
}) })
.setNegativeButton(R.string.cancel, null) .setNegativeButton(R.string.cancel, null)
.show(); .show();
}); });
tab3NameLinearLayout.setOnClickListener(view -> { tab3NameConstraintLayout.setOnClickListener(view -> {
int titleId; int titleId;
switch (tab3CurrentPostType) { switch (tab3CurrentPostType) {
case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_SUBREDDIT: case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_SUBREDDIT:
@ -471,6 +490,8 @@ public class CustomizeMainPageTabsFragment extends Fragment {
.show(); .show();
}); });
tab3AddImageView.setOnClickListener(view -> selectName(2));
showMultiredditsSwitchMaterial.setChecked(mainActivityTabsSharedPreferences.getBoolean(accountName + SharedPreferencesUtils.MAIN_PAGE_SHOW_MULTIREDDITS, false)); showMultiredditsSwitchMaterial.setChecked(mainActivityTabsSharedPreferences.getBoolean(accountName + SharedPreferencesUtils.MAIN_PAGE_SHOW_MULTIREDDITS, false));
showMultiredditsSwitchMaterial.setOnCheckedChangeListener((compoundButton, b) -> mainActivityTabsSharedPreferences.edit().putBoolean(accountName + SharedPreferencesUtils.MAIN_PAGE_SHOW_MULTIREDDITS, b).apply()); showMultiredditsSwitchMaterial.setOnCheckedChangeListener((compoundButton, b) -> mainActivityTabsSharedPreferences.edit().putBoolean(accountName + SharedPreferencesUtils.MAIN_PAGE_SHOW_MULTIREDDITS, b).apply());
showMultiredditsLinearLayout.setOnClickListener(view -> { showMultiredditsLinearLayout.setOnClickListener(view -> {
@ -498,7 +519,26 @@ public class CustomizeMainPageTabsFragment extends Fragment {
return rootView; return rootView;
} }
private void applyTab1NameView(LinearLayout linearLayout, TextView titleTextView, int postType) { private void applyTab1NameView(ConstraintLayout constraintLayout, TextView titleTextView, int postType) {
switch (postType) {
case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_SUBREDDIT:
constraintLayout.setVisibility(View.VISIBLE);
titleTextView.setText(R.string.settings_tab_subreddit_name);
break;
case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_MULTIREDDIT:
constraintLayout.setVisibility(View.VISIBLE);
titleTextView.setText(R.string.settings_tab_multi_reddit_name);
break;
case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_USER:
constraintLayout.setVisibility(View.VISIBLE);
titleTextView.setText(R.string.settings_tab_username);
break;
default:
constraintLayout.setVisibility(View.GONE);
}
}
private void applyTab2NameView(ConstraintLayout linearLayout, TextView titleTextView, int postType) {
switch (postType) { switch (postType) {
case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_SUBREDDIT: case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_SUBREDDIT:
linearLayout.setVisibility(View.VISIBLE); linearLayout.setVisibility(View.VISIBLE);
@ -517,41 +557,150 @@ public class CustomizeMainPageTabsFragment extends Fragment {
} }
} }
private void applyTab2NameView(LinearLayout linearLayout, TextView titleTextView, int postType) { private void applyTab3NameView(ConstraintLayout constraintLayout, TextView titleTextView, int postType) {
switch (postType) { switch (postType) {
case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_SUBREDDIT: case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_SUBREDDIT:
linearLayout.setVisibility(View.VISIBLE); constraintLayout.setVisibility(View.VISIBLE);
titleTextView.setText(R.string.settings_tab_subreddit_name); titleTextView.setText(R.string.settings_tab_subreddit_name);
break; break;
case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_MULTIREDDIT: case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_MULTIREDDIT:
linearLayout.setVisibility(View.VISIBLE); constraintLayout.setVisibility(View.VISIBLE);
titleTextView.setText(R.string.settings_tab_multi_reddit_name); titleTextView.setText(R.string.settings_tab_multi_reddit_name);
break; break;
case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_USER: case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_USER:
linearLayout.setVisibility(View.VISIBLE); constraintLayout.setVisibility(View.VISIBLE);
titleTextView.setText(R.string.settings_tab_username); titleTextView.setText(R.string.settings_tab_username);
break; break;
default: default:
linearLayout.setVisibility(View.GONE); constraintLayout.setVisibility(View.GONE);
} }
} }
private void applyTab3NameView(LinearLayout linearLayout, TextView titleTextView, int postType) { private void selectName(int tab) {
switch (postType) { switch (tab) {
case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_SUBREDDIT: case 0:
linearLayout.setVisibility(View.VISIBLE); switch (tab1CurrentPostType) {
titleTextView.setText(R.string.settings_tab_subreddit_name); case 3: {
Intent intent = new Intent(activity, SubredditSelectionActivity.class);
startActivityForResult(intent, tab);
break; break;
case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_MULTIREDDIT: }
linearLayout.setVisibility(View.VISIBLE); case 4: {
titleTextView.setText(R.string.settings_tab_multi_reddit_name); Intent intent = new Intent(activity, MultiredditSelectionActivity.class);
startActivityForResult(intent, tab);
break; break;
case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_USER: }
linearLayout.setVisibility(View.VISIBLE); case 5: {
titleTextView.setText(R.string.settings_tab_username); Intent intent = new Intent(activity, SearchActivity.class);
intent.putExtra(SearchActivity.EXTRA_SEARCH_ONLY_USERS, true);
startActivityForResult(intent, tab);
break; break;
default: }
linearLayout.setVisibility(View.GONE); }
break;
case 1:
switch (tab2CurrentPostType) {
case 3: {
Intent intent = new Intent(activity, SubredditSelectionActivity.class);
startActivityForResult(intent, tab);
break;
}
case 4: {
Intent intent = new Intent(activity, MultiredditSelectionActivity.class);
startActivityForResult(intent, tab);
break;
}
case 5: {
Intent intent = new Intent(activity, SearchActivity.class);
intent.putExtra(SearchActivity.EXTRA_SEARCH_ONLY_USERS, true);
startActivityForResult(intent, tab);
break;
}
}
break;
case 2:
switch (tab3CurrentPostType) {
case 3: {
Intent intent = new Intent(activity, SubredditSelectionActivity.class);
startActivityForResult(intent, tab);
break;
}
case 4: {
Intent intent = new Intent(activity, MultiredditSelectionActivity.class);
startActivityForResult(intent, tab);
break;
}
case 5: {
Intent intent = new Intent(activity, SearchActivity.class);
intent.putExtra(SearchActivity.EXTRA_SEARCH_ONLY_USERS, true);
startActivityForResult(intent, tab);
break;
}
}
break;
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == Activity.RESULT_OK && data != null) {
switch (requestCode) {
case 0:
if (data.hasExtra(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_NAME)) {
tab1CurrentName = data.getStringExtra(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_NAME);
tab1NameSummaryTextView.setText(tab1CurrentName);
mainActivityTabsSharedPreferences.edit().putString((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_1_NAME, tab1CurrentName).apply();
} else if (data.hasExtra(MultiredditSelectionActivity.EXTRA_RETURN_MULTIREDDIT)) {
MultiReddit multireddit = data.getParcelableExtra(MultiredditSelectionActivity.EXTRA_RETURN_MULTIREDDIT);
if (multireddit != null) {
tab1CurrentName = multireddit.getPath();
tab1NameSummaryTextView.setText(tab1CurrentName);
mainActivityTabsSharedPreferences.edit().putString((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_1_NAME, tab1CurrentName).apply();
}
} else if (data.hasExtra(SearchActivity.EXTRA_RETURN_USER_NAME)) {
tab1CurrentName = data.getStringExtra(SearchActivity.EXTRA_RETURN_USER_NAME);
tab1NameSummaryTextView.setText(tab1CurrentName);
mainActivityTabsSharedPreferences.edit().putString((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_1_NAME, tab1CurrentName).apply();
}
break;
case 1:
if (data.hasExtra(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_NAME)) {
tab2CurrentName = data.getStringExtra(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_NAME);
tab2NameSummaryTextView.setText(tab2CurrentName);
mainActivityTabsSharedPreferences.edit().putString((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_2_NAME, tab2CurrentName).apply();
} else if (data.hasExtra(MultiredditSelectionActivity.EXTRA_RETURN_MULTIREDDIT)) {
MultiReddit multireddit = data.getParcelableExtra(MultiredditSelectionActivity.EXTRA_RETURN_MULTIREDDIT);
if (multireddit != null) {
tab2CurrentName = multireddit.getPath();
tab2NameSummaryTextView.setText(tab2CurrentName);
mainActivityTabsSharedPreferences.edit().putString((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_2_NAME, tab2CurrentName).apply();
}
} else if (data.hasExtra(SearchActivity.EXTRA_RETURN_USER_NAME)) {
tab2CurrentName = data.getStringExtra(SearchActivity.EXTRA_RETURN_USER_NAME);
tab2NameSummaryTextView.setText(tab2CurrentName);
mainActivityTabsSharedPreferences.edit().putString((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_2_NAME, tab2CurrentName).apply();
}
break;
case 2:
if (data.hasExtra(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_NAME)) {
tab3CurrentName = data.getStringExtra(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_NAME);
tab3NameSummaryTextView.setText(tab3CurrentName);
mainActivityTabsSharedPreferences.edit().putString((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_3_NAME, tab3CurrentName).apply();
} else if (data.hasExtra(MultiredditSelectionActivity.EXTRA_RETURN_MULTIREDDIT)) {
MultiReddit multireddit = data.getParcelableExtra(MultiredditSelectionActivity.EXTRA_RETURN_MULTIREDDIT);
if (multireddit != null) {
tab3CurrentName = multireddit.getPath();
tab3NameSummaryTextView.setText(tab3CurrentName);
mainActivityTabsSharedPreferences.edit().putString((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_3_NAME, tab3CurrentName).apply();
}
} else if (data.hasExtra(SearchActivity.EXTRA_RETURN_USER_NAME)) {
tab3CurrentName = data.getStringExtra(SearchActivity.EXTRA_RETURN_USER_NAME);
tab3NameSummaryTextView.setText(tab3CurrentName);
mainActivityTabsSharedPreferences.edit().putString((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_3_NAME, tab3CurrentName).apply();
}
break;
}
} }
} }

View File

@ -175,37 +175,57 @@
</LinearLayout> </LinearLayout>
<LinearLayout <androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/tab_1_name_linear_layout_customize_main_page_tabs_fragment" android:id="@+id/tab_1_name_constraint_layout_customize_main_page_tabs_fragment"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical" android:background="?attr/selectableItemBackground"
android:paddingTop="16dp"
android:paddingBottom="16dp"
android:paddingStart="72dp"
android:paddingEnd="16dp"
android:clickable="true" android:clickable="true"
android:focusable="true" android:focusable="true"
android:background="?attr/selectableItemBackground" android:orientation="vertical"
android:paddingStart="72dp"
android:paddingTop="16dp"
android:paddingEnd="16dp"
android:paddingBottom="16dp"
android:visibility="gone"> android:visibility="gone">
<TextView <TextView
android:id="@+id/tab_1_name_title_text_view_customize_main_page_tabs_fragment" android:id="@+id/tab_1_name_title_text_view_customize_main_page_tabs_fragment"
android:layout_width="match_parent" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:fontFamily="?attr/font_family"
android:textColor="@color/primaryTextColor" android:textColor="@color/primaryTextColor"
android:textSize="?attr/font_16" android:textSize="?attr/font_16"
android:fontFamily="?attr/font_family" /> app:layout_constraintEnd_toStartOf="@id/tab_1_name_add_image_view_customize_main_page_tabs_fragment"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView <TextView
android:id="@+id/tab_1_name_summary_text_view_customize_main_page_tabs_fragment" android:id="@+id/tab_1_name_summary_text_view_customize_main_page_tabs_fragment"
android:layout_width="match_parent" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:fontFamily="?attr/font_family"
android:textColor="?attr/secondaryTextColor" android:textColor="?attr/secondaryTextColor"
android:textSize="?attr/font_default" android:textSize="?attr/font_default"
android:fontFamily="?attr/font_family" /> app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/tab_1_name_add_image_view_customize_main_page_tabs_fragment"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tab_1_name_title_text_view_customize_main_page_tabs_fragment" />
</LinearLayout> <ImageView
android:id="@+id/tab_1_name_add_image_view_customize_main_page_tabs_fragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:background="?actionBarItemBackground"
android:clickable="true"
android:focusable="true"
android:src="@drawable/ic_add_day_night_24dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<View <View
android:id="@+id/divider_2_customize_main_page_tabs_fragment" android:id="@+id/divider_2_customize_main_page_tabs_fragment"
@ -287,8 +307,8 @@
</LinearLayout> </LinearLayout>
<LinearLayout <androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/tab_2_name_linear_layout_customize_main_page_tabs_fragment" android:id="@+id/tab_2_name_constraint_layout_customize_main_page_tabs_fragment"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical" android:orientation="vertical"
@ -303,21 +323,41 @@
<TextView <TextView
android:id="@+id/tab_2_name_title_text_view_customize_main_page_tabs_fragment" android:id="@+id/tab_2_name_title_text_view_customize_main_page_tabs_fragment"
android:layout_width="match_parent" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textColor="@color/primaryTextColor" android:textColor="@color/primaryTextColor"
android:textSize="?attr/font_16" android:textSize="?attr/font_16"
android:fontFamily="?attr/font_family" /> android:fontFamily="?attr/font_family"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@id/tab_2_name_add_image_view_customize_main_page_tabs_fragment" />
<TextView <TextView
android:id="@+id/tab_2_name_summary_text_view_customize_main_page_tabs_fragment" android:id="@+id/tab_2_name_summary_text_view_customize_main_page_tabs_fragment"
android:layout_width="match_parent" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textColor="?attr/secondaryTextColor" android:textColor="?attr/secondaryTextColor"
android:textSize="?attr/font_default" android:textSize="?attr/font_default"
android:fontFamily="?attr/font_family" /> android:fontFamily="?attr/font_family"
app:layout_constraintTop_toBottomOf="@id/tab_2_name_title_text_view_customize_main_page_tabs_fragment"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@id/tab_2_name_add_image_view_customize_main_page_tabs_fragment" />
</LinearLayout> <ImageView
android:id="@+id/tab_2_name_add_image_view_customize_main_page_tabs_fragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:src="@drawable/ic_add_day_night_24dp"
android:background="?actionBarItemBackground"
android:clickable="true"
android:focusable="true"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<View <View
android:id="@+id/divider_3_customize_main_page_tabs_fragment" android:id="@+id/divider_3_customize_main_page_tabs_fragment"
@ -399,8 +439,8 @@
</LinearLayout> </LinearLayout>
<LinearLayout <androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/tab_3_name_linear_layout_customize_main_page_tabs_fragment" android:id="@+id/tab_3_name_constraint_layout_customize_main_page_tabs_fragment"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical" android:orientation="vertical"
@ -415,21 +455,41 @@
<TextView <TextView
android:id="@+id/tab_3_name_title_text_view_customize_main_page_tabs_fragment" android:id="@+id/tab_3_name_title_text_view_customize_main_page_tabs_fragment"
android:layout_width="match_parent" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textColor="@color/primaryTextColor" android:textColor="@color/primaryTextColor"
android:textSize="?attr/font_16" android:textSize="?attr/font_16"
android:fontFamily="?attr/font_family" /> android:fontFamily="?attr/font_family"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@id/tab_3_name_add_image_view_customize_main_page_tabs_fragment" />
<TextView <TextView
android:id="@+id/tab_3_name_summary_text_view_customize_main_page_tabs_fragment" android:id="@+id/tab_3_name_summary_text_view_customize_main_page_tabs_fragment"
android:layout_width="match_parent" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textColor="?attr/secondaryTextColor" android:textColor="?attr/secondaryTextColor"
android:textSize="?attr/font_default" android:textSize="?attr/font_default"
android:fontFamily="?attr/font_family" /> android:fontFamily="?attr/font_family"
app:layout_constraintTop_toBottomOf="@id/tab_3_name_title_text_view_customize_main_page_tabs_fragment"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@id/tab_3_name_add_image_view_customize_main_page_tabs_fragment" />
</LinearLayout> <ImageView
android:id="@+id/tab_3_name_add_image_view_customize_main_page_tabs_fragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:src="@drawable/ic_add_day_night_24dp"
android:background="?actionBarItemBackground"
android:clickable="true"
android:focusable="true"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<View <View
android:id="@+id/divider_4_customize_main_page_tabs_fragment" android:id="@+id/divider_4_customize_main_page_tabs_fragment"

View File

@ -507,7 +507,7 @@
<string name="settings_tab_title">Title</string> <string name="settings_tab_title">Title</string>
<string name="settings_tab_post_type">Type</string> <string name="settings_tab_post_type">Type</string>
<string name="settings_tab_subreddit_name">Subreddit Name (Without r/ prefix)</string> <string name="settings_tab_subreddit_name">Subreddit Name (Without r/ prefix)</string>
<string name="settings_tab_multi_reddit_name">MultiReddit Name (/user/yourusername/m/yourmultiredditname)</string> <string name="settings_tab_multi_reddit_name">MultiReddit Path (/user/yourusername/m/yourmultiredditname)</string>
<string name="settings_tab_username">Username (Without u/ prefix)</string> <string name="settings_tab_username">Username (Without u/ prefix)</string>
<string name="no_developer_easter_egg">There\'s no developer options here</string> <string name="no_developer_easter_egg">There\'s no developer options here</string>
<string name="settings_download_location_title">Download Location</string> <string name="settings_download_location_title">Download Location</string>