Add options to customize FAB.

This commit is contained in:
Alex Ning 2020-09-25 15:39:48 +08:00
parent b6ebcf1c4c
commit 1b983c1ff8
5 changed files with 123 additions and 2 deletions

View File

@ -3,6 +3,7 @@ package ml.docilealligator.infinityforreddit.Settings;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
@ -54,6 +55,10 @@ public class CustomizeBottomAppBarFragment extends Fragment {
LinearLayout mainActivityOption4LinearLayout;
@BindView(R.id.main_activity_option_4_text_view_customize_bottom_app_bar_fragment)
TextView mainActivityOption4TextView;
@BindView(R.id.main_activity_fab_linear_layout_customize_bottom_app_bar_fragment)
LinearLayout mainActivityFABLinearLayout;
@BindView(R.id.main_activity_fab_text_view_customize_bottom_app_bar_fragment)
TextView mainActivityFABTextView;
@BindView(R.id.divider_2_customize_bottom_app_bar_fragment)
View divider2;
@ -79,6 +84,10 @@ public class CustomizeBottomAppBarFragment extends Fragment {
LinearLayout otherActivitiesOption4LinearLayout;
@BindView(R.id.other_activities_option_4_text_view_customize_bottom_app_bar_fragment)
TextView otherActivitiesOption4TextView;
@BindView(R.id.other_activities_fab_linear_layout_customize_bottom_app_bar_fragment)
LinearLayout otherActivitiesFABLinearLayout;
@BindView(R.id.other_activities_fab_text_view_customize_bottom_app_bar_fragment)
TextView otherActivitiesFABTextView;
@Inject
@Named("bottom_app_bar")
SharedPreferences sharedPreferences;
@ -88,11 +97,13 @@ public class CustomizeBottomAppBarFragment extends Fragment {
private int mainActivityOption2;
private int mainActivityOption3;
private int mainActivityOption4;
private int mainActivityFAB;
private int otherActivitiesOptionCount;
private int otherActivitiesOption1;
private int otherActivitiesOption2;
private int otherActivitiesOption3;
private int otherActivitiesOption4;
private int otherActivitiesFAB;
public CustomizeBottomAppBarFragment() {
// Required empty public constructor
@ -119,6 +130,7 @@ public class CustomizeBottomAppBarFragment extends Fragment {
mainActivityOption2LinearLayout.setVisibility(View.GONE);
mainActivityOption3LinearLayout.setVisibility(View.GONE);
mainActivityOption4LinearLayout.setVisibility(View.GONE);
mainActivityFABLinearLayout.setVisibility(View.GONE);
divider2.setVisibility(View.GONE);
otherActivitiesGroupSummaryTextView.setVisibility(View.GONE);
otherActivitiesOptionCountLinearLayout.setVisibility(View.GONE);
@ -126,22 +138,27 @@ public class CustomizeBottomAppBarFragment extends Fragment {
otherActivitiesOption2LinearLayout.setVisibility(View.GONE);
otherActivitiesOption3LinearLayout.setVisibility(View.GONE);
otherActivitiesOption4LinearLayout.setVisibility(View.GONE);
otherActivitiesFABLinearLayout.setVisibility(View.GONE);
return rootView;
}
String[] mainActivityOptions = activity.getResources().getStringArray(R.array.settings_main_activity_bottom_app_bar_options);
Resources resources = activity.getResources();
String[] mainActivityOptions = resources.getStringArray(R.array.settings_main_activity_bottom_app_bar_options);
String[] fabOptions = resources.getStringArray(R.array.settings_bottom_app_bar_fab_options);
mainActivityOptionCount = sharedPreferences.getInt(SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_COUNT, 4);
mainActivityOption1 = sharedPreferences.getInt(SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_1, 0);
mainActivityOption2 = sharedPreferences.getInt(SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_2, 1);
mainActivityOption3 = sharedPreferences.getInt(SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_3, 2);
mainActivityOption4 = sharedPreferences.getInt(SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_4, 3);
mainActivityFAB = sharedPreferences.getInt(SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB, 0);
mainActivityOptionCountTextView.setText(Integer.toString(mainActivityOptionCount));
mainActivityOption1TextView.setText(mainActivityOptions[mainActivityOption1]);
mainActivityOption2TextView.setText(mainActivityOptions[mainActivityOption2]);
mainActivityOption3TextView.setText(mainActivityOptions[mainActivityOption3]);
mainActivityOption4TextView.setText(mainActivityOptions[mainActivityOption4]);
mainActivityFABTextView.setText(fabOptions[mainActivityFAB]);
mainActivityOptionCountLinearLayout.setOnClickListener(view -> {
new MaterialAlertDialogBuilder(activity, R.style.MaterialAlertDialogTheme)
@ -203,18 +220,32 @@ public class CustomizeBottomAppBarFragment extends Fragment {
.show();
});
String[] otherActivitiesOptions = activity.getResources().getStringArray(R.array.settings_other_activities_bottom_app_bar_options);
mainActivityFABLinearLayout.setOnClickListener(view -> {
new MaterialAlertDialogBuilder(activity, R.style.MaterialAlertDialogTheme)
.setTitle(R.string.settings_bottom_app_bar_fab)
.setSingleChoiceItems(fabOptions, mainActivityFAB, (dialogInterface, i) -> {
mainActivityFAB = i;
sharedPreferences.edit().putInt(SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB, mainActivityFAB).apply();
mainActivityFABTextView.setText(fabOptions[mainActivityFAB]);
dialogInterface.dismiss();
})
.show();
});
String[] otherActivitiesOptions = resources.getStringArray(R.array.settings_other_activities_bottom_app_bar_options);
otherActivitiesOptionCount = sharedPreferences.getInt(SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_COUNT, 4);
otherActivitiesOption1 = sharedPreferences.getInt(SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_1, 0);
otherActivitiesOption2 = sharedPreferences.getInt(SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_2, 1);
otherActivitiesOption3 = sharedPreferences.getInt(SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_3, 2);
otherActivitiesOption4 = sharedPreferences.getInt(SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_4, 3);
otherActivitiesFAB = sharedPreferences.getInt(SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB, 0);
otherActivitiesOptionCountTextView.setText(Integer.toString(otherActivitiesOptionCount));
otherActivitiesOption1TextView.setText(otherActivitiesOptions[otherActivitiesOption1]);
otherActivitiesOption2TextView.setText(otherActivitiesOptions[otherActivitiesOption2]);
otherActivitiesOption3TextView.setText(otherActivitiesOptions[otherActivitiesOption3]);
otherActivitiesOption4TextView.setText(otherActivitiesOptions[otherActivitiesOption4]);
otherActivitiesFABTextView.setText(fabOptions[otherActivitiesFAB]);
otherActivitiesOptionCountLinearLayout.setOnClickListener(view -> {
new MaterialAlertDialogBuilder(activity, R.style.MaterialAlertDialogTheme)
@ -276,6 +307,18 @@ public class CustomizeBottomAppBarFragment extends Fragment {
.show();
});
otherActivitiesFABLinearLayout.setOnClickListener(view -> {
new MaterialAlertDialogBuilder(activity, R.style.MaterialAlertDialogTheme)
.setTitle(R.string.settings_bottom_app_bar_fab)
.setSingleChoiceItems(fabOptions, otherActivitiesFAB, (dialogInterface, i) -> {
otherActivitiesFAB = i;
sharedPreferences.edit().putInt(SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB, otherActivitiesFAB).apply();
otherActivitiesFABTextView.setText(fabOptions[otherActivitiesFAB]);
dialogInterface.dismiss();
})
.show();
});
return rootView;
}

View File

@ -157,11 +157,13 @@ public class SharedPreferencesUtils {
public static final String MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_2 = "main_activity_bottom_app_bar_option_2";
public static final String MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_3 = "main_activity_bottom_app_bar_option_3";
public static final String MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_4 = "main_activity_bottom_app_bar_option_4";
public static final String MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB = "main_activity_bottom_app_bar_fab";
public static final String OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_COUNT = "other_activities_bottom_app_bar_option_count";
public static final String OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_1 = "other_activities_bottom_app_bar_option_1";
public static final String OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_2 = "other_activities_bottom_app_bar_option_2";
public static final String OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_3 = "other_activities_bottom_app_bar_option_3";
public static final String OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_4 = "other_activities_bottom_app_bar_option_4";
public static final String OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB = "other_activities_bottom_app_bar_fab";
public static final String NSFW_AND_SPOILER_SHARED_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit.nsfw_and_spoiler";
public static final String NSFW_BASE = "_nsfw";

View File

@ -209,6 +209,39 @@
</LinearLayout>
<LinearLayout
android:id="@+id/main_activity_fab_linear_layout_customize_bottom_app_bar_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingTop="16dp"
android:paddingBottom="16dp"
android:paddingStart="72dp"
android:paddingEnd="16dp"
android:clickable="true"
android:focusable="true"
android:background="?attr/selectableItemBackground">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:text="@string/settings_bottom_app_bar_fab"
android:textColor="?attr/primaryTextColor"
android:textSize="?attr/font_16"
android:fontFamily="?attr/font_family" />
<TextView
android:id="@+id/main_activity_fab_text_view_customize_bottom_app_bar_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:textColor="?attr/secondaryTextColor"
android:textSize="?attr/font_default"
android:fontFamily="?attr/font_family" />
</LinearLayout>
<View
android:id="@+id/divider_2_customize_bottom_app_bar_fragment"
android:layout_width="match_parent"
@ -394,6 +427,39 @@
</LinearLayout>
<LinearLayout
android:id="@+id/other_activities_fab_linear_layout_customize_bottom_app_bar_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingTop="16dp"
android:paddingBottom="16dp"
android:paddingStart="72dp"
android:paddingEnd="16dp"
android:clickable="true"
android:focusable="true"
android:background="?attr/selectableItemBackground">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:text="@string/settings_bottom_app_bar_fab"
android:textColor="?attr/primaryTextColor"
android:textSize="?attr/font_16"
android:fontFamily="?attr/font_family" />
<TextView
android:id="@+id/other_activities_fab_text_view_customize_bottom_app_bar_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:textColor="?attr/secondaryTextColor"
android:textSize="?attr/font_default"
android:fontFamily="?attr/font_family" />
</LinearLayout>
</LinearLayout>
</androidx.core.widget.NestedScrollView>

View File

@ -249,4 +249,13 @@
<item>Inbox</item>
<item>Profile</item>
</string-array>
<string-array name="settings_bottom_app_bar_fab_options">
<item>Submit posts</item>
<item>Refresh</item>
<item>Change sort type</item>
<item>Change post layout</item>
<item>Search</item>
</string-array>
</resources>

View File

@ -484,6 +484,7 @@
<string name="settings_bottom_app_bar_option_2">Option 2</string>
<string name="settings_bottom_app_bar_option_3">Option 3</string>
<string name="settings_bottom_app_bar_option_4">Option 4</string>
<string name="settings_bottom_app_bar_fab">Floating Action Button</string>
<string name="no_link_available">Cannot get the link</string>