Various small changes

This commit is contained in:
topjohnwu 2017-01-10 22:30:05 +08:00
parent fa73b41fa7
commit 742055c43b
11 changed files with 36 additions and 53 deletions

View File

@ -1,12 +1,12 @@
package com.topjohnwu.magisk; package com.topjohnwu.magisk;
import android.app.AlertDialog;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBar;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.text.Html; import android.text.Html;
@ -39,14 +39,13 @@ public class AboutActivity extends AppCompatActivity {
@BindView(R.id.app_source_code) AboutCardRow appSourceCode; @BindView(R.id.app_source_code) AboutCardRow appSourceCode;
@BindView(R.id.support_thread) AboutCardRow supportThread; @BindView(R.id.support_thread) AboutCardRow supportThread;
@BindView(R.id.donation) AboutCardRow donation; @BindView(R.id.donation) AboutCardRow donation;
private AlertDialog.Builder builder;
@Override @Override
protected void onCreate(@Nullable Bundle savedInstanceState) { protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
String theme = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("theme", ""); String theme = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("theme", "");
Logger.dev("AboutActivity: Theme is " + theme); Logger.dev("AboutActivity: Theme is " + theme);
if (Utils.isDarkTheme(theme, this)) { if (Utils.isDarkTheme) {
setTheme(R.style.AppTheme_dh); setTheme(R.style.AppTheme_dh);
} }
setContentView(R.layout.activity_about); setContentView(R.layout.activity_about);
@ -77,11 +76,6 @@ public class AboutActivity extends AppCompatActivity {
} }
appChangelog.removeSummary(); appChangelog.removeSummary();
if (Utils.isDarkTheme(theme, this)) {
builder = new AlertDialog.Builder(this, R.style.AlertDialog_dh);
} else {
builder = new AlertDialog.Builder(this);
}
if (changes == null) { if (changes == null) {
appChangelog.setVisibility(View.GONE); appChangelog.setVisibility(View.GONE);
} else { } else {
@ -92,13 +86,11 @@ public class AboutActivity extends AppCompatActivity {
result = Html.fromHtml(changes); result = Html.fromHtml(changes);
} }
appChangelog.setOnClickListener(v -> { appChangelog.setOnClickListener(v -> {
AlertDialog d = builder AlertDialog d = Utils.getAlertDialogBuilder(this)
.setTitle(R.string.app_changelog) .setTitle(R.string.app_changelog)
.setMessage(result) .setMessage(result)
.setPositiveButton(android.R.string.ok, null) .setPositiveButton(android.R.string.ok, null)
.create(); .show();
d.show();
//noinspection ConstantConditions //noinspection ConstantConditions
((TextView) d.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance()); ((TextView) d.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());
@ -113,7 +105,7 @@ public class AboutActivity extends AppCompatActivity {
} else { } else {
result = Html.fromHtml(getString(R.string.app_developers_)); result = Html.fromHtml(getString(R.string.app_developers_));
} }
AlertDialog d = builder AlertDialog d = Utils.getAlertDialogBuilder(this)
.setTitle(R.string.app_developers) .setTitle(R.string.app_developers)
.setMessage(result) .setMessage(result)
.setPositiveButton(android.R.string.ok, null) .setPositiveButton(android.R.string.ok, null)

View File

@ -53,7 +53,7 @@ public class InstallFragment extends Fragment implements CallbackHandler.EventLi
} }
String filename = "Magisk-v" + StatusFragment.remoteMagiskVersion + ".zip"; String filename = "Magisk-v" + StatusFragment.remoteMagiskVersion + ".zip";
String finalBootImage = bootImage; String finalBootImage = bootImage;
MainActivity.alertBuilder Utils.getAlertDialogBuilder(getActivity())
.setTitle(getString(R.string.repo_install_title, getString(R.string.magisk))) .setTitle(getString(R.string.repo_install_title, getString(R.string.magisk)))
.setMessage(getString(R.string.repo_install_msg, filename)) .setMessage(getString(R.string.repo_install_msg, filename))
.setCancelable(true) .setCancelable(true)

View File

@ -1,7 +1,6 @@
package com.topjohnwu.magisk; package com.topjohnwu.magisk;
import android.Manifest; import android.Manifest;
import android.app.AlertDialog;
import android.app.Fragment; import android.app.Fragment;
import android.app.FragmentTransaction; import android.app.FragmentTransaction;
import android.content.Intent; import android.content.Intent;
@ -25,7 +24,6 @@ import android.view.MenuItem;
import android.view.View; import android.view.View;
import com.topjohnwu.magisk.utils.CallbackHandler; import com.topjohnwu.magisk.utils.CallbackHandler;
import com.topjohnwu.magisk.utils.Logger;
import com.topjohnwu.magisk.utils.Shell; import com.topjohnwu.magisk.utils.Shell;
import com.topjohnwu.magisk.utils.Utils; import com.topjohnwu.magisk.utils.Utils;
@ -35,8 +33,6 @@ import butterknife.ButterKnife;
public class MainActivity extends AppCompatActivity public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener, CallbackHandler.EventListener { implements NavigationView.OnNavigationItemSelectedListener, CallbackHandler.EventListener {
public static AlertDialog.Builder alertBuilder = null;
private static final String SELECTED_ITEM_ID = "SELECTED_ITEM_ID"; private static final String SELECTED_ITEM_ID = "SELECTED_ITEM_ID";
private final Handler mDrawerHandler = new Handler(); private final Handler mDrawerHandler = new Handler();
@ -54,13 +50,8 @@ public class MainActivity extends AppCompatActivity
prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
String theme = prefs.getString("theme", ""); if (Utils.isDarkTheme) {
Logger.dev("MainActivity: Theme is " + theme);
if (Utils.isDarkTheme(theme, this)) {
setTheme(R.style.AppTheme_dh); setTheme(R.style.AppTheme_dh);
alertBuilder = new AlertDialog.Builder(this, R.style.AlertDialog_dh);
} else {
alertBuilder = new AlertDialog.Builder(this);
} }
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
@ -116,7 +107,6 @@ public class MainActivity extends AppCompatActivity
protected void onDestroy() { protected void onDestroy() {
super.onDestroy(); super.onDestroy();
CallbackHandler.unRegister(StatusFragment.updateCheckDone, this); CallbackHandler.unRegister(StatusFragment.updateCheckDone, this);
alertBuilder = null;
} }
@Override @Override

View File

@ -30,7 +30,7 @@ public class SettingsActivity extends AppCompatActivity {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
String theme = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("theme", ""); String theme = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("theme", "");
Logger.dev("AboutActivity: Theme is " + theme); Logger.dev("AboutActivity: Theme is " + theme);
if (Utils.isDarkTheme(theme, this)) { if (Utils.isDarkTheme) {
setTheme(R.style.AppTheme_dh); setTheme(R.style.AppTheme_dh);
} }
@ -120,10 +120,11 @@ public class SettingsActivity extends AppCompatActivity {
switch (key) { switch (key) {
case "theme": case "theme":
String theme = prefs.getString(key, ""); String theme = prefs.getString("theme", getString(R.string.theme_default_value));
Utils.isDarkTheme = theme.equalsIgnoreCase(getString(R.string.theme_dark_value));
themePreference.setSummary(theme); themePreference.setSummary(theme);
if (Utils.isDarkTheme(theme, getActivity())) { if (Utils.isDarkTheme) {
getActivity().getApplication().setTheme(R.style.AppTheme_dh); getActivity().getApplication().setTheme(R.style.AppTheme_dh);
} else { } else {
getActivity().getApplication().setTheme(R.style.AppTheme); getActivity().getApplication().setTheme(R.style.AppTheme);

View File

@ -17,7 +17,11 @@ public class SplashActivity extends AppCompatActivity {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplication()); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplication());
if (Utils.isDarkTheme(prefs.getString("theme", null), this)) {
String theme = prefs.getString("theme", getString(R.string.theme_default_value));
Utils.isDarkTheme = theme.equalsIgnoreCase(getString(R.string.theme_dark_value));
if (Utils.isDarkTheme) {
setTheme(R.style.AppTheme_dh); setTheme(R.style.AppTheme_dh);
} }

View File

@ -3,8 +3,6 @@ package com.topjohnwu.magisk;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.Fragment; import android.app.Fragment;
import android.app.FragmentTransaction; import android.app.FragmentTransaction;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
@ -21,6 +19,7 @@ import com.topjohnwu.magisk.utils.Async;
import com.topjohnwu.magisk.utils.CallbackHandler; import com.topjohnwu.magisk.utils.CallbackHandler;
import com.topjohnwu.magisk.utils.Logger; import com.topjohnwu.magisk.utils.Logger;
import com.topjohnwu.magisk.utils.Shell; import com.topjohnwu.magisk.utils.Shell;
import com.topjohnwu.magisk.utils.Utils;
import java.util.List; import java.util.List;
@ -108,7 +107,8 @@ public class StatusFragment extends Fragment implements CallbackHandler.EventLis
}); });
if (magiskVersion < 0 && Shell.rootAccess() && !noDialog) { if (magiskVersion < 0 && Shell.rootAccess() && !noDialog) {
MainActivity.alertBuilder noDialog = true;
Utils.getAlertDialogBuilder(getActivity())
.setTitle(R.string.no_magisk_title) .setTitle(R.string.no_magisk_title)
.setMessage(R.string.no_magisk_msg) .setMessage(R.string.no_magisk_msg)
.setCancelable(true) .setCancelable(true)
@ -120,7 +120,7 @@ public class StatusFragment extends Fragment implements CallbackHandler.EventLis
transaction.replace(R.id.content_frame, new InstallFragment(), "install").commit(); transaction.replace(R.id.content_frame, new InstallFragment(), "install").commit();
} catch (IllegalStateException ignored) {} } catch (IllegalStateException ignored) {}
}) })
.setNegativeButton(R.string.no_thanks, (dialogInterface, i) -> noDialog = true) .setNegativeButton(R.string.no_thanks, null)
.show(); .show();
} }
@ -240,7 +240,7 @@ public class StatusFragment extends Fragment implements CallbackHandler.EventLis
magiskCheckUpdatesProgress.setVisibility(View.GONE); magiskCheckUpdatesProgress.setVisibility(View.GONE);
mSwipeRefreshLayout.setRefreshing(false); mSwipeRefreshLayout.setRefreshing(false);
updateMagisk = MainActivity.alertBuilder updateMagisk = Utils.getAlertDialogBuilder(getActivity())
.setTitle(R.string.magisk_update_title) .setTitle(R.string.magisk_update_title)
.setMessage(getString(R.string.magisk_update_message, remoteMagiskVersion)) .setMessage(getString(R.string.magisk_update_message, remoteMagiskVersion))
.setCancelable(true) .setCancelable(true)
@ -255,12 +255,13 @@ public class StatusFragment extends Fragment implements CallbackHandler.EventLis
.setNeutralButton(R.string.check_release_notes, (dialog, which) -> { .setNeutralButton(R.string.check_release_notes, (dialog, which) -> {
getActivity().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(releaseNoteLink))); getActivity().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(releaseNoteLink)));
}) })
.setNegativeButton(R.string.no_thanks, (dialogInterface, i) -> noDialog = true) .setNegativeButton(R.string.no_thanks, null)
.create(); .create();
if (magiskVersion < remoteMagiskVersion && Shell.rootAccess()) { if (magiskVersion < remoteMagiskVersion && Shell.rootAccess()) {
magiskStatusContainer.setOnClickListener(view -> updateMagisk.show()); magiskStatusContainer.setOnClickListener(view -> updateMagisk.show());
if (!noDialog) { if (!noDialog) {
noDialog = true;
updateMagisk.show(); updateMagisk.show();
} }
} }

View File

@ -17,7 +17,6 @@ import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import com.topjohnwu.magisk.MainActivity;
import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.module.Repo; import com.topjohnwu.magisk.module.Repo;
import com.topjohnwu.magisk.receivers.RepoDlReceiver; import com.topjohnwu.magisk.receivers.RepoDlReceiver;
@ -99,7 +98,7 @@ public class ReposAdapter extends RecyclerView.Adapter<ReposAdapter.ViewHolder>
}); });
holder.updateImage.setOnClickListener(view -> { holder.updateImage.setOnClickListener(view -> {
String filename = repo.getName() + "-" + repo.getVersion() + ".zip"; String filename = repo.getName() + "-" + repo.getVersion() + ".zip";
MainActivity.alertBuilder Utils.getAlertDialogBuilder(mContext)
.setTitle(mContext.getString(R.string.repo_install_title, repo.getName())) .setTitle(mContext.getString(R.string.repo_install_title, repo.getName()))
.setMessage(mContext.getString(R.string.repo_install_msg, filename)) .setMessage(mContext.getString(R.string.repo_install_msg, filename))
.setCancelable(true) .setCancelable(true)

View File

@ -13,7 +13,6 @@ import android.widget.Toast;
import com.topjohnwu.magisk.InstallFragment; import com.topjohnwu.magisk.InstallFragment;
import com.topjohnwu.magisk.MagiskHideFragment; import com.topjohnwu.magisk.MagiskHideFragment;
import com.topjohnwu.magisk.MainActivity;
import com.topjohnwu.magisk.ModulesFragment; import com.topjohnwu.magisk.ModulesFragment;
import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.ReposFragment; import com.topjohnwu.magisk.ReposFragment;
@ -292,7 +291,7 @@ public class Async {
StatusFragment.updateCheckDone.trigger(); StatusFragment.updateCheckDone.trigger();
new LoadModules().exec(); new LoadModules().exec();
MainActivity.alertBuilder Utils.getAlertDialogBuilder(mContext)
.setTitle(R.string.reboot_title) .setTitle(R.string.reboot_title)
.setMessage(R.string.reboot_msg) .setMessage(R.string.reboot_msg)
.setPositiveButton(R.string.reboot, (dialogInterface1, i) -> Shell.sh("su -c reboot")) .setPositiveButton(R.string.reboot, (dialogInterface1, i) -> Shell.sh("su -c reboot"))

View File

@ -1,6 +1,7 @@
package com.topjohnwu.magisk.utils; package com.topjohnwu.magisk.utils;
import android.Manifest; import android.Manifest;
import android.app.AlertDialog;
import android.app.DownloadManager; import android.app.DownloadManager;
import android.content.Context; import android.content.Context;
import android.content.IntentFilter; import android.content.IntentFilter;
@ -34,6 +35,7 @@ import javax.crypto.spec.DESKeySpec;
public class Utils { public class Utils {
public static boolean isDownloading = false; public static boolean isDownloading = false;
public static boolean isDarkTheme;
private static final String cryptoPass = "MagiskRox666"; private static final String cryptoPass = "MagiskRox666";
private static final String secret = "GTYybRBTYf5his9kQ16ZNO7qgkBJ/5MyVe4CGceAOIoXgSnnk8FTd4F1dE9p5Eus"; private static final String secret = "GTYybRBTYf5his9kQ16ZNO7qgkBJ/5MyVe4CGceAOIoXgSnnk8FTd4F1dE9p5Eus";
@ -164,8 +166,12 @@ public class Utils {
return null; return null;
} }
public static boolean isDarkTheme(String theme, Context resources) { public static AlertDialog.Builder getAlertDialogBuilder(Context context) {
return theme != null && theme.equalsIgnoreCase(resources.getString(R.string.theme_dark_value)); if (isDarkTheme) {
return new AlertDialog.Builder(context, R.style.AlertDialog_dh);
} else {
return new AlertDialog.Builder(context);
}
} }
public static class ByteArrayInOutStream extends ByteArrayOutputStream { public static class ByteArrayInOutStream extends ByteArrayOutputStream {

View File

@ -1,24 +1,15 @@
package com.topjohnwu.magisk.utils; package com.topjohnwu.magisk.utils;
import android.app.AlertDialog;
import android.content.Context; import android.content.Context;
import android.preference.PreferenceManager;
import android.support.v7.app.AlertDialog;
import android.webkit.WebResourceRequest; import android.webkit.WebResourceRequest;
import android.webkit.WebView; import android.webkit.WebView;
import android.webkit.WebViewClient; import android.webkit.WebViewClient;
import com.topjohnwu.magisk.R;
public class WebWindow { public class WebWindow {
public WebWindow(String title, String url, Context context) { public WebWindow(String title, String url, Context context) {
AlertDialog.Builder alert; AlertDialog.Builder alert = Utils.getAlertDialogBuilder(context);
String theme = PreferenceManager.getDefaultSharedPreferences(context).getString("theme", "");
if (Utils.isDarkTheme(theme, context)) {
alert = new AlertDialog.Builder(context, R.style.AlertDialog_dh);
} else {
alert = new AlertDialog.Builder(context);
}
alert.setTitle(title); alert.setTitle(title);
Logger.dev("WebView: URL = " + url); Logger.dev("WebView: URL = " + url);

View File

@ -21,7 +21,7 @@
android:orientation="vertical" android:orientation="vertical"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:padding="15dp"> android:padding="5dp">
<TextView <TextView
android:id="@+id/install_title" android:id="@+id/install_title"