Improve settings
This commit is contained in:
parent
61e2c3444a
commit
01d847ae4e
@ -35,6 +35,8 @@ public class MainActivity extends AppCompatActivity
|
||||
|
||||
private static final String SELECTED_ITEM_ID = "SELECTED_ITEM_ID";
|
||||
|
||||
public static CallbackHandler.Event recreate = new CallbackHandler.Event();
|
||||
|
||||
private final Handler mDrawerHandler = new Handler();
|
||||
private SharedPreferences prefs;
|
||||
|
||||
@ -90,23 +92,29 @@ public class MainActivity extends AppCompatActivity
|
||||
}
|
||||
|
||||
navigationView.setNavigationItemSelectedListener(this);
|
||||
|
||||
if (StatusFragment.updateCheckDone.isTriggered) {
|
||||
onTrigger(StatusFragment.updateCheckDone);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
CallbackHandler.register(StatusFragment.updateCheckDone, this);
|
||||
CallbackHandler.register(recreate, this);
|
||||
if (StatusFragment.updateCheckDone.isTriggered) {
|
||||
onTrigger(StatusFragment.updateCheckDone);
|
||||
}
|
||||
checkHideSection();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
CallbackHandler.unRegister(StatusFragment.updateCheckDone, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
CallbackHandler.unRegister(StatusFragment.updateCheckDone, this);
|
||||
CallbackHandler.unRegister(recreate, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -135,18 +143,22 @@ public class MainActivity extends AppCompatActivity
|
||||
|
||||
@Override
|
||||
public void onTrigger(CallbackHandler.Event event) {
|
||||
if (event == StatusFragment.updateCheckDone) {
|
||||
Menu menu = navigationView.getMenu();
|
||||
menu.findItem(R.id.install).setVisible(StatusFragment.remoteMagiskVersion > 0 &&
|
||||
Shell.rootAccess());
|
||||
} else if (event == recreate) {
|
||||
recreate();
|
||||
}
|
||||
}
|
||||
|
||||
private void checkHideSection() {
|
||||
Menu menu = navigationView.getMenu();
|
||||
menu.findItem(R.id.magiskhide).setVisible(StatusFragment.magiskVersion > 0 &&
|
||||
menu.findItem(R.id.magiskhide).setVisible(StatusFragment.magiskVersion >= 8 &&
|
||||
prefs.getBoolean("magiskhide", false) && Shell.rootAccess());
|
||||
menu.findItem(R.id.modules).setVisible(StatusFragment.magiskVersion > 0 &&
|
||||
menu.findItem(R.id.modules).setVisible(StatusFragment.magiskVersion >= 4 &&
|
||||
Shell.rootAccess());
|
||||
menu.findItem(R.id.downloads).setVisible(StatusFragment.magiskVersion > 0 &&
|
||||
menu.findItem(R.id.downloads).setVisible(StatusFragment.magiskVersion >= 4 &&
|
||||
Shell.rootAccess());
|
||||
menu.findItem(R.id.log).setVisible(Shell.rootAccess());
|
||||
menu.findItem(R.id.install).setVisible(Shell.rootAccess());
|
||||
|
@ -1,10 +1,11 @@
|
||||
package com.topjohnwu.magisk;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.preference.CheckBoxPreference;
|
||||
import android.preference.ListPreference;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceFragment;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v7.app.ActionBar;
|
||||
@ -15,6 +16,7 @@ import android.widget.Toast;
|
||||
|
||||
import com.topjohnwu.magisk.utils.Async;
|
||||
import com.topjohnwu.magisk.utils.Logger;
|
||||
import com.topjohnwu.magisk.utils.ModuleHelper;
|
||||
import com.topjohnwu.magisk.utils.Shell;
|
||||
import com.topjohnwu.magisk.utils.Utils;
|
||||
|
||||
@ -86,14 +88,34 @@ public class SettingsActivity extends AppCompatActivity {
|
||||
CheckBoxPreference busyboxPreference = (CheckBoxPreference) findPreference("busybox");
|
||||
CheckBoxPreference magiskhidePreference = (CheckBoxPreference) findPreference("magiskhide");
|
||||
CheckBoxPreference hostsPreference = (CheckBoxPreference) findPreference("hosts");
|
||||
Preference clear = findPreference("clear");
|
||||
|
||||
themePreference.setSummary(themePreference.getValue());
|
||||
clear.setOnPreferenceClickListener((pref) -> {
|
||||
SharedPreferences repoMap = getActivity().getSharedPreferences(ModuleHelper.FILE_KEY, Context.MODE_PRIVATE);
|
||||
repoMap.edit()
|
||||
.putString(ModuleHelper.ETAG_KEY, "")
|
||||
.putInt(ModuleHelper.VERSION_KEY, 0)
|
||||
.apply();
|
||||
new Async.LoadRepos(getActivity()).exec();
|
||||
Toast.makeText(getActivity(), R.string.repo_cache_cleared, Toast.LENGTH_LONG).show();
|
||||
return true;
|
||||
});
|
||||
|
||||
if (Utils.isDarkTheme) {
|
||||
themePreference.setSummary(R.string.theme_dark);
|
||||
} else {
|
||||
themePreference.setSummary(R.string.theme_default);
|
||||
}
|
||||
|
||||
if (StatusFragment.magiskVersion < 9) {
|
||||
hostsPreference.setEnabled(false);
|
||||
busyboxPreference.setEnabled(false);
|
||||
} else if (StatusFragment.magiskVersion < 8) {
|
||||
magiskhidePreference.setEnabled(false);
|
||||
} else if (! Shell.rootAccess()) {
|
||||
busyboxPreference.setEnabled(false);
|
||||
magiskhidePreference.setEnabled(false);
|
||||
hostsPreference.setEnabled(false);
|
||||
} else {
|
||||
busyboxPreference.setEnabled(true);
|
||||
magiskhidePreference.setEnabled(true);
|
||||
@ -121,81 +143,61 @@ public class SettingsActivity extends AppCompatActivity {
|
||||
switch (key) {
|
||||
case "theme":
|
||||
String theme = prefs.getString("theme", getString(R.string.theme_default_value));
|
||||
Utils.isDarkTheme = theme.equalsIgnoreCase(getString(R.string.theme_dark_value));
|
||||
|
||||
themePreference.setSummary(theme);
|
||||
if (Utils.isDarkTheme) {
|
||||
getActivity().getApplication().setTheme(R.style.AppTheme_dh);
|
||||
} else {
|
||||
getActivity().getApplication().setTheme(R.style.AppTheme);
|
||||
if (Utils.isDarkTheme != theme.equalsIgnoreCase(getString(R.string.theme_dark_value))) {
|
||||
Utils.isDarkTheme = !Utils.isDarkTheme;
|
||||
getActivity().recreate();
|
||||
MainActivity.recreate.trigger();
|
||||
}
|
||||
Intent intent = new Intent(getActivity(), MainActivity.class);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
startActivity(intent);
|
||||
break;
|
||||
case "magiskhide":
|
||||
checked = prefs.getBoolean("magiskhide", false);
|
||||
if (checked) {
|
||||
new Async.RootTask<Void, Void, Void>() {
|
||||
private boolean enable = checked;
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
if (enable) {
|
||||
Utils.createFile("/magisk/.core/magiskhide/enable");
|
||||
return null;
|
||||
}
|
||||
}.exec();
|
||||
} else {
|
||||
new Async.RootTask<Void, Void, Void>() {
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
Utils.removeItem("/magisk/.core/magiskhide/enable");
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}.exec();
|
||||
}
|
||||
Toast.makeText(getActivity(), R.string.settings_reboot_toast, Toast.LENGTH_LONG).show();
|
||||
break;
|
||||
case "busybox":
|
||||
checked = prefs.getBoolean("busybox", false);
|
||||
if (checked) {
|
||||
new Async.RootTask<Void, Void, Void>() {
|
||||
private boolean enable = checked;
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
if (enable) {
|
||||
Utils.createFile("/magisk/.core/busybox/enable");
|
||||
return null;
|
||||
}
|
||||
}.exec();
|
||||
} else {
|
||||
new Async.RootTask<Void, Void, Void>() {
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
Utils.removeItem("/magisk/.core/busybox/enable");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}.exec();
|
||||
}
|
||||
Toast.makeText(getActivity(), R.string.settings_reboot_toast, Toast.LENGTH_LONG).show();
|
||||
break;
|
||||
case "hosts":
|
||||
checked = prefs.getBoolean("hosts", false);
|
||||
if (checked) {
|
||||
new Async.RootTask<Void, Void, Void>() {
|
||||
private boolean enable = checked;
|
||||
@Override
|
||||
protected Void doInBackground(Void... voids) {
|
||||
Shell.su("cp -af /system/etc/hosts /magisk/.core/hosts");
|
||||
return null;
|
||||
}
|
||||
}.exec();
|
||||
if (enable) {
|
||||
Shell.su("cp -af /system/etc/hosts /magisk/.core/hosts",
|
||||
"mount -o bind /magisk/.core/hosts /system/etc/hosts");
|
||||
} else {
|
||||
new Async.RootTask<Void, Void, Void>() {
|
||||
@Override
|
||||
protected Void doInBackground(Void... voids) {
|
||||
Shell.su("umount -l /system/etc/hosts", "rm -f /magisk/.core/hosts");
|
||||
Shell.su("umount -l /system/etc/hosts",
|
||||
"rm -f /magisk/.core/hosts");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}.exec();
|
||||
}
|
||||
Toast.makeText(getActivity(), R.string.settings_reboot_toast, Toast.LENGTH_LONG).show();
|
||||
break;
|
||||
case "developer_logging":
|
||||
Logger.devLog = prefs.getBoolean("developer_logging", false);
|
||||
|
@ -28,10 +28,10 @@ import java.util.Map;
|
||||
|
||||
public class ModuleHelper {
|
||||
private static final String MAGISK_PATH = "/magisk";
|
||||
private static final String FILE_KEY = "RepoMap";
|
||||
public static final String FILE_KEY = "RepoMap";
|
||||
private static final String REPO_KEY = "repomap";
|
||||
private static final String VERSION_KEY = "version";
|
||||
private static final String ETAG_KEY = "ETag";
|
||||
public static final String VERSION_KEY = "version";
|
||||
public static final String ETAG_KEY = "ETag";
|
||||
private static final int DATABASE_VER = 1;
|
||||
|
||||
private static ValueSortedMap<String, Repo> repoMap = new ValueSortedMap<>();
|
||||
|
@ -108,7 +108,9 @@
|
||||
<string name="downloading_toast">Downloading %1$s</string>
|
||||
<string name="magisk_update_title">New Magisk Update Available!</string>
|
||||
<string name="magisk_update_message">Magisk v%1$.1f update is live, do you want to install?</string>
|
||||
<string name="settings_reboot_toast">Reboot to apply settings</string>
|
||||
<string name="check_release_notes">Check release notes</string>
|
||||
<string name="repo_cache_cleared">Repo cache cleared</string>
|
||||
|
||||
<!--URL Templates-->
|
||||
<string name="url_main" translatable="false">https://api.github.com/orgs/Magisk-Modules-Repo/repos</string>
|
||||
@ -121,6 +123,8 @@
|
||||
<string name="settings_theme_summary">Select a theme</string>
|
||||
<string name="theme_default">Default</string>
|
||||
<string name="theme_dark">Dark</string>
|
||||
<string name="settings_clear_cache_title">Clear Repo Cache</string>
|
||||
<string name="settings_clear_cache_summary">Clear the cached information for online repos, forces the app to refresh online</string>
|
||||
|
||||
<string name="settings_magiskhide_title">Enable Magisk Hide</string>
|
||||
<string name="settings_magiskhide_summary">Hide Magisk from various detections</string>
|
||||
@ -131,14 +135,13 @@
|
||||
|
||||
<string name="settings_development_category">Development</string>
|
||||
<string name="settings_developer_logging_title">Enable advanced debug logging</string>
|
||||
<string name="settings_developer_logging_summary">Check this to enable more verbose logging.</string>
|
||||
<string name="settings_developer_logging_summary">Check this to enable verbose logging</string>
|
||||
<string name="settings_shell_logging_title">Enable shell command debug logging</string>
|
||||
<string name="settings_shell_logging_summary">Check this to enable logging all shell commands and output</string>
|
||||
|
||||
<string name="settings_reboot_toast">Reboot to apply settings</string>
|
||||
<string name="settings_shell_logging_summary">Check this to enable logging all shell commands and its output</string>
|
||||
|
||||
<!-- Themes -->
|
||||
<string name="theme_default_value" translatable="false">default</string>
|
||||
<string name="theme_dark_value" translatable="false">dark</string>
|
||||
|
||||
|
||||
</resources>
|
||||
|
@ -12,6 +12,11 @@
|
||||
android:entries="@array/themes"
|
||||
android:entryValues="@array/themes_values"/>
|
||||
|
||||
<Preference
|
||||
android:key="clear"
|
||||
android:title="@string/settings_clear_cache_title"
|
||||
android:summary="@string/settings_clear_cache_summary" />
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory
|
||||
|
Loading…
Reference in New Issue
Block a user