From 17749bb14a5a4a28445cf3cf8821d6d0c5ef023e Mon Sep 17 00:00:00 2001 From: d8ahazard Date: Sun, 25 Sep 2016 01:16:08 -0500 Subject: [PATCH] Code cleanup, fixing thangs... --- .../com/topjohnwu/magisk/MagiskFragment.java | 53 ++++++++++--------- .../com/topjohnwu/magisk/MainActivity.java | 37 ++----------- .../com/topjohnwu/magisk/ReposFragment.java | 21 +------- .../com/topjohnwu/magisk/RootFragment.java | 3 -- .../topjohnwu/magisk/SettingsFragment.java | 23 +++----- .../com/topjohnwu/magisk/SplashActivity.java | 7 ++- app/src/main/res/layout/list_item_module.xml | 10 ++-- app/src/main/res/values/styles.xml | 12 +++++ 8 files changed, 64 insertions(+), 102 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/MagiskFragment.java b/app/src/main/java/com/topjohnwu/magisk/MagiskFragment.java index 911462f36..16e8da0d5 100644 --- a/app/src/main/java/com/topjohnwu/magisk/MagiskFragment.java +++ b/app/src/main/java/com/topjohnwu/magisk/MagiskFragment.java @@ -102,8 +102,9 @@ public class MagiskFragment extends Fragment { magiskStatusContainer.setBackgroundColor(colorOK); magiskStatusIcon.setImageResource(statusOK); - magiskVersion.setTextColor(colorOK); + magiskVersion.setText(getString(R.string.magisk_version, String.valueOf(Utils.magiskVersion))); + magiskVersion.setTextColor(colorOK); } if (Utils.remoteMagiskVersion == -1) { @@ -115,55 +116,55 @@ public class MagiskFragment extends Fragment { appCheckUpdatesStatus.setText(R.string.cannot_check_updates); magiskCheckUpdatesStatus.setText(R.string.cannot_check_updates); + magiskCheckUpdatesStatus.setTextColor(colorWarn); } else { if (Utils.remoteMagiskVersion > Utils.magiskVersion) { magiskCheckUpdatesContainer.setBackgroundColor(colorNeutral); magiskCheckUpdatesIcon.setImageResource(R.drawable.ic_file_download); magiskCheckUpdatesStatus.setText(getString(R.string.magisk_update_available, String.valueOf(Utils.remoteMagiskVersion))); + magiskCheckUpdatesStatus.setTextColor(colorNeutral); magiskUpdateView.setOnClickListener(view -> new AlertDialog.Builder(getActivity()) .setTitle(getString(R.string.update_title, getString(R.string.magisk))) .setMessage(getString(R.string.update_msg, getString(R.string.magisk), String.valueOf(Utils.remoteMagiskVersion), Utils.magiskChangelog)) .setCancelable(true) - .setPositiveButton(R.string.download_install, (dialogInterface, i) -> { - Utils.downloadAndReceive( - getActivity(), - new Utils.DownloadReceiver(getString(R.string.magisk)) { - @Override - public void task(File file) { - new Async.FlashZIP(mContext, mName, file.getPath()).execute(); - } - }, - Utils.magiskLink, "latest_magisk.zip"); - }) + .setPositiveButton(R.string.download_install, (dialogInterface, i) -> Utils.downloadAndReceive( + getActivity(), + new Utils.DownloadReceiver(getString(R.string.magisk)) { + @Override + public void task(File file) { + new Async.FlashZIP(mContext, mName, file.getPath()).execute(); + } + }, + Utils.magiskLink, "latest_magisk.zip")) .setNegativeButton(R.string.no_thanks, null) .show()); } else { magiskCheckUpdatesContainer.setBackgroundColor(colorOK); magiskCheckUpdatesIcon.setImageResource(R.drawable.ic_check_circle); magiskCheckUpdatesStatus.setText(getString(R.string.up_to_date, getString(R.string.magisk))); + magiskCheckUpdatesStatus.setTextColor(colorOK); } if (Utils.remoteAppVersion > BuildConfig.VERSION_CODE) { appCheckUpdatesContainer.setBackgroundColor(colorNeutral); appCheckUpdatesIcon.setImageResource(R.drawable.ic_file_download); appCheckUpdatesStatus.setText(getString(R.string.app_update_available, String.valueOf(Utils.remoteAppVersion))); + appCheckUpdatesStatus.setTextColor(colorNeutral); appUpdateView.setOnClickListener(view -> new AlertDialog.Builder(getActivity()) .setTitle(getString(R.string.update_title, getString(R.string.app_name))) .setMessage(getString(R.string.update_msg, getString(R.string.app_name), String.valueOf(Utils.remoteAppVersion), Utils.appChangelog)) .setCancelable(true) - .setPositiveButton(R.string.download_install, (dialogInterface, i) -> { - Utils.downloadAndReceive(getActivity(), - new Utils.DownloadReceiver() { - @Override - public void task(File file) { - Intent install = new Intent(Intent.ACTION_INSTALL_PACKAGE); - install.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); - install.setData(FileProvider.getUriForFile(mContext, "com.topjohnwu.magisk.provider", file)); - mContext.startActivity(install); - } - }, - Utils.appLink, "latest_manager.apk"); - }) + .setPositiveButton(R.string.download_install, (dialogInterface, i) -> Utils.downloadAndReceive(getActivity(), + new Utils.DownloadReceiver() { + @Override + public void task(File file) { + Intent install = new Intent(Intent.ACTION_INSTALL_PACKAGE); + install.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); + install.setData(FileProvider.getUriForFile(mContext, "com.topjohnwu.magisk.provider", file)); + mContext.startActivity(install); + } + }, + Utils.appLink, "latest_manager.apk")) .setNegativeButton(R.string.no_thanks, null) .show() ); @@ -171,6 +172,8 @@ public class MagiskFragment extends Fragment { appCheckUpdatesContainer.setBackgroundColor(colorOK); appCheckUpdatesIcon.setImageResource(R.drawable.ic_check_circle); appCheckUpdatesStatus.setText(getString(R.string.up_to_date, getString(R.string.app_name))); + appCheckUpdatesStatus.setTextColor(colorOK); + } } diff --git a/app/src/main/java/com/topjohnwu/magisk/MainActivity.java b/app/src/main/java/com/topjohnwu/magisk/MainActivity.java index 2d340a551..194d51471 100644 --- a/app/src/main/java/com/topjohnwu/magisk/MainActivity.java +++ b/app/src/main/java/com/topjohnwu/magisk/MainActivity.java @@ -5,7 +5,6 @@ import android.app.Fragment; import android.app.FragmentTransaction; import android.content.Intent; import android.content.pm.PackageManager; -import android.graphics.Color; import android.os.Build; import android.os.Bundle; import android.os.Handler; @@ -21,12 +20,10 @@ import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.view.MenuItem; import android.view.View; -import android.widget.ImageButton; import com.topjohnwu.magisk.utils.Logger; import com.topjohnwu.magisk.utils.Utils; - import butterknife.BindView; import butterknife.ButterKnife; @@ -36,7 +33,6 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On private final Handler mDrawerHandler = new Handler(); private String currentTitle; - private View mView; @BindView(R.id.toolbar) Toolbar toolbar; @@ -51,7 +47,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On @Override protected void onCreate(final Bundle savedInstanceState) { - String theme = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("theme",""); + String theme = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("theme", ""); Logger.dh("MainActivity: Theme is " + theme); if (theme.equals("Dark")) { setTheme(R.style.AppTheme_dh); @@ -113,8 +109,6 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On } } - - ); setSupportActionBar(toolbar); @@ -145,45 +139,22 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On } navigationView.setNavigationItemSelectedListener(this); - mView = getToolbarNavigationButton(); - Bundle extras = getIntent().getExtras(); - if(extras != null) { + if (extras != null) { + navigate(R.id.settings); Logger.dh("MainActivity: Intent has extras " + getIntent().getExtras().getString("Relaunch")); - String data = extras.getString("Relaunch"); // retrieve the data using keyName - if (data.contains("Settings")) { - navigate(R.id.settings); - } + } } - public ImageButton getToolbarNavigationButton() { - int size = toolbar.getChildCount(); - for (int i = 0; i < size; i++) { - View child = toolbar.getChildAt(i); - if (child instanceof ImageButton) { - ImageButton btn = (ImageButton) child; - if (btn.getDrawable() == toolbar.getNavigationIcon()) { - return btn; - } - } - } - return null; - } - @Override protected void onDestroy() { super.onDestroy(); } - private void startTour() { - navigate(R.id.root); - - } - @Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); diff --git a/app/src/main/java/com/topjohnwu/magisk/ReposFragment.java b/app/src/main/java/com/topjohnwu/magisk/ReposFragment.java index 54d6d7ad5..374963da8 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ReposFragment.java +++ b/app/src/main/java/com/topjohnwu/magisk/ReposFragment.java @@ -2,12 +2,8 @@ package com.topjohnwu.magisk; import android.app.Fragment; import android.content.DialogInterface; -import android.content.SharedPreferences; -import android.graphics.Color; import android.os.Bundle; -import android.preference.PreferenceManager; import android.support.annotation.Nullable; -import android.app.Fragment; import android.support.v4.widget.SwipeRefreshLayout; import android.support.v7.app.AlertDialog; import android.support.v7.widget.RecyclerView; @@ -21,7 +17,6 @@ import com.topjohnwu.magisk.module.Repo; import com.topjohnwu.magisk.module.RepoHelper; import com.topjohnwu.magisk.utils.Async; import com.topjohnwu.magisk.utils.Utils; -import com.wooplr.spotlight.SpotlightView; import java.io.File; import java.util.ArrayList; @@ -31,8 +26,6 @@ import java.util.List; import butterknife.BindView; import butterknife.ButterKnife; -import static com.topjohnwu.magisk.R.menu.drawer; - public class ReposFragment extends Fragment { public static List mListRepos = new ArrayList<>(); @@ -104,7 +97,7 @@ public class ReposFragment extends Fragment { super.onAttachFragment(childFragment); } - private void LoadRepo (boolean doReload) { + private void LoadRepo(boolean doReload) { RepoHelper.TaskDelegate taskDelegate = result -> { if (result.equals("Complete")) { Log.d("Magisk", "ReposFragment, got delegate"); @@ -159,23 +152,20 @@ public class ReposFragment extends Fragment { } } - @Override public void onResume() { super.onResume(); LoadRepo(false); getActivity().setTitle("Magisk"); - } - protected List listRepos() { return mListRepos; } private void UpdateUI() { - Log.d("Magisk","ReposFragment: UpdateUI Called, size is " + listRepos().size()); + Log.d("Magisk", "ReposFragment: UpdateUI Called, size is " + listRepos().size()); if (listRepos().size() == 0) { emptyTv.setVisibility(View.VISIBLE); @@ -190,13 +180,6 @@ public class ReposFragment extends Fragment { NotifyOfAlerts(); } - } - - - - - - } diff --git a/app/src/main/java/com/topjohnwu/magisk/RootFragment.java b/app/src/main/java/com/topjohnwu/magisk/RootFragment.java index 796d07da5..578f99728 100644 --- a/app/src/main/java/com/topjohnwu/magisk/RootFragment.java +++ b/app/src/main/java/com/topjohnwu/magisk/RootFragment.java @@ -30,12 +30,9 @@ import com.topjohnwu.magisk.utils.Utils; import java.io.File; import java.util.List; -import butterknife.BindColor; import butterknife.BindView; import butterknife.ButterKnife; -import static com.topjohnwu.magisk.R.attr.cardStyle; - public class RootFragment extends Fragment { public SharedPreferences prefs; diff --git a/app/src/main/java/com/topjohnwu/magisk/SettingsFragment.java b/app/src/main/java/com/topjohnwu/magisk/SettingsFragment.java index 07a6b0e19..6bf831cc7 100644 --- a/app/src/main/java/com/topjohnwu/magisk/SettingsFragment.java +++ b/app/src/main/java/com/topjohnwu/magisk/SettingsFragment.java @@ -8,7 +8,6 @@ import android.preference.ListPreference; import android.preference.Preference; import android.preference.PreferenceFragment; import android.preference.PreferenceManager; -import android.preference.PreferenceScreen; import android.util.TypedValue; import android.view.LayoutInflater; import android.view.View; @@ -19,11 +18,12 @@ import com.topjohnwu.magisk.utils.Utils; import butterknife.ButterKnife; - -public class SettingsFragment extends PreferenceFragment implements SharedPreferences.OnSharedPreferenceChangeListener{ +public class SettingsFragment extends PreferenceFragment implements SharedPreferences.OnSharedPreferenceChangeListener { private CheckBoxPreference quickTilePreference; private ListPreference themePreference; - private SharedPreferences.OnSharedPreferenceChangeListener listener; + + public SettingsFragment() { + } @Override public void onCreate(Bundle savedInstanceState) { @@ -69,7 +69,6 @@ public class SettingsFragment extends PreferenceFragment implements SharedPrefer hideRootNotificationPreference.setEnabled(true); } - Preference.OnPreferenceClickListener preferenceClickListener = preference -> { if (preference == quickTilePreference) { boolean isChecked = quickTilePreference.isChecked(); @@ -84,10 +83,6 @@ public class SettingsFragment extends PreferenceFragment implements SharedPrefer return false; }; - - - - quickTilePreference.setOnPreferenceClickListener(preferenceClickListener); // calculate margins int horizontalMargin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2, getResources().getDisplayMetrics()); @@ -100,19 +95,16 @@ public class SettingsFragment extends PreferenceFragment implements SharedPrefer view.setPadding(horizontalMargin, actionBarHeight, horizontalMargin, verticalMargin); - return view; } - - @Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { Logger.dh("Settings: NewValue is " + key); if (key.equals("theme")) { - String pref = sharedPreferences.getString(key,""); + String pref = sharedPreferences.getString(key, ""); themePreference.setSummary(pref); if (pref.equals("Dark")) { @@ -123,15 +115,12 @@ public class SettingsFragment extends PreferenceFragment implements SharedPrefer Intent intent = new Intent(getActivity(), MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - intent.putExtra("Relaunch","Settings"); + intent.putExtra("Relaunch", "Settings"); startActivity(intent); - Logger.dh("SettingsFragment: theme is " + pref); } - - } } \ No newline at end of file diff --git a/app/src/main/java/com/topjohnwu/magisk/SplashActivity.java b/app/src/main/java/com/topjohnwu/magisk/SplashActivity.java index 5c3c8bb61..7e7bd9901 100644 --- a/app/src/main/java/com/topjohnwu/magisk/SplashActivity.java +++ b/app/src/main/java/com/topjohnwu/magisk/SplashActivity.java @@ -42,8 +42,13 @@ public class SplashActivity extends AppCompatActivity { } // Set up toggle states based on preferences, start services, disable root if set - if (Utils.autoToggleEnabled(getApplicationContext())) { + if (!Utils.hasServicePermission(getApplicationContext())) { + Utils.toggleAutoRoot(false,getApplicationContext()); + } + } + if (Utils.autoToggleEnabled(getApplicationContext())) { + if (!Utils.isMyServiceRunning(MonitorService.class, getApplicationContext())) { Intent myIntent = new Intent(getApplication(), MonitorService.class); getApplication().startService(myIntent); diff --git a/app/src/main/res/layout/list_item_module.xml b/app/src/main/res/layout/list_item_module.xml index ee50a5304..8ed40d379 100644 --- a/app/src/main/res/layout/list_item_module.xml +++ b/app/src/main/res/layout/list_item_module.xml @@ -2,6 +2,7 @@ @@ -19,7 +19,9 @@ android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:minHeight="?android:attr/listPreferredItemHeight" - android:padding="@dimen/card_layout_padding"> + android:padding="@dimen/card_layout_padding" + android:paddingEnd="@dimen/card_layout_padding" + android:paddingStart="@dimen/card_layout_padding"> @@ -141,7 +143,7 @@ diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index c9fea33bb..1b74500e8 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -24,6 +24,7 @@ @color/primary_text @color/icons + +