Skip to content
This repository was archived by the owner on May 4, 2023. It is now read-only.

Commit 3ba8f4b

Browse files
Work on setup and enhance themes
Signed-off-by: androidacy-user <opensource@androidacy.com>
1 parent 3c990bf commit 3ba8f4b

File tree

6 files changed

+122
-55
lines changed

6 files changed

+122
-55
lines changed

app/src/main/java/com/fox2code/mmm/MainActivity.java

Lines changed: 57 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222
import android.widget.CheckBox;
2323
import android.widget.EditText;
2424
import android.widget.LinearLayout;
25-
import android.widget.RadioGroup;
2625
import android.widget.TextView;
2726
import android.widget.Toast;
2827

2928
import androidx.annotation.NonNull;
3029
import androidx.appcompat.app.ActionBar;
30+
import androidx.appcompat.widget.PopupMenu;
3131
import androidx.appcompat.widget.SearchView;
3232
import androidx.cardview.widget.CardView;
3333
import androidx.core.app.ActivityCompat;
@@ -57,6 +57,7 @@
5757
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
5858
import com.google.android.material.materialswitch.MaterialSwitch;
5959
import com.google.android.material.progressindicator.LinearProgressIndicator;
60+
import com.topjohnwu.superuser.internal.UiThreadHandler;
6061

6162
import org.chromium.net.ExperimentalCronetEngine;
6263
import org.chromium.net.urlconnection.CronetURLStreamHandlerFactory;
@@ -767,12 +768,66 @@ private void checkShowInitialSetup() {
767768
((MaterialSwitch) Objects.requireNonNull(view.findViewById(R.id.setup_androidacy_repo))).setOnCheckedChangeListener((buttonView, isChecked) -> Log.i("SetupWizard", "Androidacy Repo: " + isChecked));
768769
((MaterialSwitch) Objects.requireNonNull(view.findViewById(R.id.setup_magisk_alt_repo))).setOnCheckedChangeListener((buttonView, isChecked) -> Log.i("SetupWizard", "Magisk Alt Repo: " + isChecked));
769770
}
771+
// Setup popup dialogue for the setup_theme_button
772+
MaterialButton themeButton = view.findViewById(R.id.setup_theme_button);
773+
themeButton.setOnClickListener(v -> {
774+
// Create a new popup menu
775+
PopupMenu popupMenu = new PopupMenu(this, themeButton);
776+
// Inflate the menu
777+
popupMenu.getMenuInflater().inflate(R.menu.theme_menu, popupMenu.getMenu());
778+
// if pref_theme is set, check the relevant theme_* menu item, otherwise check the default (theme_system)
779+
String prefTheme = prefs.getString("pref_theme", "system");
780+
if (BuildConfig.DEBUG)
781+
Log.i("SetupWizard", "pref_theme: " + prefTheme);
782+
switch (prefTheme) {
783+
case "light":
784+
popupMenu.getMenu().findItem(R.id.theme_light).setChecked(true);
785+
break;
786+
case "dark":
787+
popupMenu.getMenu().findItem(R.id.theme_dark).setChecked(true);
788+
break;
789+
case "system":
790+
popupMenu.getMenu().findItem(R.id.theme_system).setChecked(true);
791+
break;
792+
// Black and transparent_light
793+
case "black":
794+
popupMenu.getMenu().findItem(R.id.theme_black).setChecked(true);
795+
break;
796+
case "transparent_light":
797+
popupMenu.getMenu().findItem(R.id.theme_transparent_light).setChecked(true);
798+
break;
799+
}
800+
// Set the on click listener
801+
popupMenu.setOnMenuItemClickListener(item -> {
802+
if (item == null) {
803+
return false;
804+
}
805+
// Make sure it.s an actual item, not the overflow menu. Actual items have an id of theme_* (see theme_menu.xml)
806+
// Check if item id contains theme_ and return false if it doesn't
807+
String itemId = getResources().getResourceEntryName(item.getItemId());
808+
if (!itemId.contains("theme_")) {
809+
return false;
810+
}
811+
// Save the theme. ID is theme_* so we need to remove the first 6 characters
812+
// Possible values are light, dark, system, transparent_light, and black
813+
prefs.edit().putString("pref_theme", item.getItemId() == R.id.theme_light ? "light" : item.getItemId() == R.id.theme_dark ? "dark" : item.getItemId() == R.id.theme_system ? "system" : item.getItemId() == R.id.theme_transparent_light ? "transparent_light" : "black").commit();
814+
// Set the theme
815+
UiThreadHandler.handler.postDelayed(() -> {
816+
MainApplication.getINSTANCE().updateTheme();
817+
FoxActivity.getFoxActivity(this).setThemeRecreate(
818+
MainApplication.getINSTANCE().getManagerThemeResId());
819+
}, 1);
820+
return true;
821+
});
822+
// Show the popup menu
823+
popupMenu.show();
824+
});
770825
// Set up the buttons
771826
// Cancel button
772827
MaterialButton cancelButton = view.findViewById(R.id.setup_cancel);
773828
cancelButton.setText(R.string.cancel);
774829
cancelButton.setOnClickListener(v -> {
775-
// Set first launch to false and finish the activity
830+
// Set first launch to false and restart the activity
776831
prefs.edit().putBoolean("first_time_user", false).commit();
777832
finish();
778833
startActivity(getIntent());
@@ -792,21 +847,6 @@ private void checkShowInitialSetup() {
792847
// first pref_magisk_alt_repo_enabled then pref_androidacy_repo_enabled
793848
editor.putBoolean("pref_magisk_alt_repo_enabled", ((MaterialSwitch) Objects.requireNonNull(view.findViewById(R.id.setup_magisk_alt_repo))).isChecked());
794849
editor.putBoolean("pref_androidacy_repo_enabled", ((MaterialSwitch) Objects.requireNonNull(view.findViewById(R.id.setup_androidacy_repo))).isChecked());
795-
// Loop through the setup_theme radio group and set the theme pref
796-
RadioGroup themeRadioGroup = view.findViewById(R.id.setup_theme);
797-
int selectedTheme = themeRadioGroup.getCheckedRadioButtonId();
798-
// system, light, dark, black, and transparent_light
799-
if (selectedTheme == R.id.setup_theme_light) {
800-
editor.putString("pref_theme", "light");
801-
} else if (selectedTheme == R.id.setup_theme_dark) {
802-
editor.putString("pref_theme", "dark");
803-
} else if (selectedTheme == R.id.setup_theme_system) {
804-
editor.putString("pref_theme", "system");
805-
} else if (selectedTheme == R.id.setup_theme_black) {
806-
editor.putString("pref_theme", "black");
807-
} else if (selectedTheme == R.id.setup_theme_transparent_light) {
808-
editor.putString("pref_theme", "transparent_light");
809-
}
810850
// Commit the changes
811851
editor.commit();
812852
// Sleep for 1 second to allow the user to see the changes

app/src/main/java/com/fox2code/mmm/module/ModuleViewAdapter.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,11 @@ public boolean update(ModuleHolder moduleHolder) {
368368
if (bgColor == Color.WHITE) {
369369
bgColor = 0xFFF8F8F8;
370370
}
371-
if (theme.getResources().getBoolean(R.bool.force_transparency)) {
371+
// if force_transparency is true or theme is transparent_light, set diff bgColor
372+
// get string value of Theme
373+
String themeName = theme.toString();
374+
if (theme.getResources().getBoolean(R.bool.force_transparency) ||
375+
themeName.contains("transparent")) {
372376
bgColor = ColorUtils.setAlphaComponent(bgColor, 0x80);
373377
}
374378
this.titleText.setTextColor(fgColor);

app/src/main/java/com/fox2code/mmm/utils/SentryMain.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ public static void initialize(final MainApplication mainApplication) {
5353
options.setEnableNdk(true);
5454
// Intercept okhttp requests to add sentry headers
5555
options.addInAppInclude("com.fox2code.mmm");
56+
options.addInAppInclude("com.fox2code.mmm.debug");
57+
options.addInAppInclude("com.fox2code.mmm.fdroid");
58+
options.addInAppExclude("com.fox2code.mmm.utils.SentryMain");
5659
// Sentry sends ABSOLUTELY NO Personally Identifiable Information (PII) by default.
5760
// Already set to false by default, just set it again to make peoples feel safer.
5861
options.setSendDefaultPii(false);

app/src/main/res/layout/setup_box.xml

Lines changed: 18 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -48,43 +48,25 @@
4848
android:text="@string/setup_theme_header"
4949
android:textAppearance="@style/TextAppearance.Material3.HeadlineSmall" />
5050

51-
<RadioGroup
52-
android:id="@+id/setup_theme"
51+
<!-- Button to trigger theme selection -->
52+
<com.google.android.material.button.MaterialButton
53+
android:id="@+id/setup_theme_button"
5354
android:layout_width="match_parent"
54-
android:layout_height="wrap_content">
55-
56-
<com.google.android.material.radiobutton.MaterialRadioButton
57-
android:id="@+id/setup_theme_system"
58-
android:layout_width="match_parent"
59-
android:layout_height="wrap_content"
60-
android:checked="true"
61-
android:text="@string/setup_theme_system" />
62-
63-
<com.google.android.material.radiobutton.MaterialRadioButton
64-
android:id="@+id/setup_theme_light"
65-
android:layout_width="match_parent"
66-
android:layout_height="wrap_content"
67-
android:text="@string/setup_theme_light" />
68-
69-
<com.google.android.material.radiobutton.MaterialRadioButton
70-
android:id="@+id/setup_theme_dark"
71-
android:layout_width="match_parent"
72-
android:layout_height="wrap_content"
73-
android:text="@string/setup_theme_dark" />
74-
75-
<com.google.android.material.radiobutton.MaterialRadioButton
76-
android:id="@+id/setup_theme_black"
77-
android:layout_width="match_parent"
78-
android:layout_height="wrap_content"
79-
android:text="@string/setup_theme_black" />
80-
81-
<com.google.android.material.radiobutton.MaterialRadioButton
82-
android:id="@+id/setup_theme_transparent_light"
83-
android:layout_width="match_parent"
84-
android:layout_height="wrap_content"
85-
android:text="@string/setup_theme_transparent_light" />
86-
87-
</RadioGroup>
55+
android:layout_height="wrap_content"
56+
android:layout_marginTop="4dp"
57+
android:backgroundTint="@color/gray_900"
58+
android:foreground="?attr/selectableItemBackground"
59+
android:padding="8dp"
60+
android:text="@string/setup_theme_button"
61+
android:textColor="@color/white"
62+
android:textSize="16sp"
63+
app:cornerRadius="8dp"
64+
app:icon="@drawable/ic_baseline_palette_24"
65+
app:iconGravity="textStart"
66+
app:iconPadding="8dp"
67+
app:iconTint="@color/white"
68+
app:iconTintMode="src_in"
69+
app:rippleColor="@color/gray_800" />
8870

8971
<com.google.android.material.textview.MaterialTextView
9072
android:layout_width="match_parent"
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto">
3+
<!-- Options for system, dark, light, black, transparent_light -->
4+
<!-- Only one of these can be selected at a time -->
5+
<!-- Radio buttons -->
6+
<!-- Themes are taken from theme_values_names string array -->
7+
<item
8+
android:id="@+id/theme"
9+
android:icon="@drawable/ic_baseline_design_services_24"
10+
android:title="@string/theme"
11+
app:showAsAction="never">
12+
<menu>
13+
<group android:checkableBehavior="single">
14+
<!-- System is default selected -->
15+
<item
16+
android:id="@+id/theme_system"
17+
android:title="@string/theme_system"
18+
app:showAsAction="never" />
19+
<item
20+
android:id="@+id/theme_dark"
21+
android:title="@string/theme_dark"
22+
app:showAsAction="never" />
23+
<item
24+
android:id="@+id/theme_black"
25+
android:title="@string/theme_black"
26+
app:showAsAction="never" />
27+
<item
28+
android:id="@+id/theme_transparent_light"
29+
android:title="@string/theme_transparent_light"
30+
app:showAsAction="never" />
31+
<item
32+
android:id="@+id/theme_light"
33+
android:title="@string/theme_light"
34+
app:showAsAction="never" />
35+
</group>
36+
</menu>
37+
</item>
38+
</menu>

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,5 +248,5 @@
248248
<string name="debug_build">This is a debug build. Expect some bugs and worse performance.</string>
249249
<string name="androidacy_repo_name">Androidacy Repo</string>
250250
<string name="magisk_alt_repo_name">Magisk Alt Repo</string>
251-
<string name="repo_enabled_changed">You\'ve enabled or disabled a repo. Please refresh the module list or restart the app.</string><string name="finish">Finish</string><string name="setup_theme">Choose a theme</string><string name="setup_theme_header">Choose a theme</string><string name="setup_theme_system">System theme</string><string name="setup_theme_light">Light theme</string><string name="setup_theme_dark">Dark theme</string><string name="setup_theme_black">AMOLED Black theme</string><string name="setup_theme_transparent_light">Transparent light theme - will disable monet and blur!</string>
251+
<string name="repo_enabled_changed">You\'ve enabled or disabled a repo. Please refresh the module list or restart the app.</string><string name="finish">Finish</string><string name="setup_theme">Choose a theme</string><string name="setup_theme_header">Choose a theme</string><string name="setup_theme_system">System theme</string><string name="setup_theme_light">Light theme</string><string name="setup_theme_dark">Dark theme</string><string name="setup_theme_black">AMOLED Black theme</string><string name="setup_theme_transparent_light">Transparent light theme - will disable monet and blur!</string><string name="setup_theme_button">Choose a theme</string><string name="theme">Theme</string><string name="theme_system">System</string><string name="theme_dark">Dark</string><string name="theme_black">AMOLED Black</string><string name="theme_transparent_light">Light (transparency)</string><string name="theme_light">Light</string>
252252
</resources>

0 commit comments

Comments
 (0)