From 91d3d2ad1f996b1f6481cae21c449083152ba067 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Mon, 26 Sep 2016 10:45:34 +0800 Subject: [PATCH] Fix UI refreshes --- .../com/topjohnwu/magisk/AboutActivity.java | 1 - .../com/topjohnwu/magisk/MagiskFragment.java | 5 +- .../com/topjohnwu/magisk/ModulesAdapter.java | 3 +- .../com/topjohnwu/magisk/ModulesFragment.java | 37 ++-- .../com/topjohnwu/magisk/ReposAdapter.java | 6 +- .../com/topjohnwu/magisk/ReposFragment.java | 201 ++++++++++-------- .../com/topjohnwu/magisk/RootFragment.java | 56 ++--- .../topjohnwu/magisk/{utils => }/RowItem.java | 2 +- .../magisk/receivers/DownloadReceiver.java | 58 +++++ .../receivers/PrivateBroadcastReceiver.java | 4 +- .../com/topjohnwu/magisk/utils/Async.java | 13 +- .../com/topjohnwu/magisk/utils/Utils.java | 52 +---- app/src/main/res/layout/activity_about.xml | 12 +- 13 files changed, 230 insertions(+), 220 deletions(-) rename app/src/main/java/com/topjohnwu/magisk/{utils => }/RowItem.java (98%) create mode 100644 app/src/main/java/com/topjohnwu/magisk/receivers/DownloadReceiver.java diff --git a/app/src/main/java/com/topjohnwu/magisk/AboutActivity.java b/app/src/main/java/com/topjohnwu/magisk/AboutActivity.java index 2847159f9..4654be57b 100644 --- a/app/src/main/java/com/topjohnwu/magisk/AboutActivity.java +++ b/app/src/main/java/com/topjohnwu/magisk/AboutActivity.java @@ -19,7 +19,6 @@ import android.view.WindowManager; import android.widget.TextView; import com.topjohnwu.magisk.utils.Logger; -import com.topjohnwu.magisk.utils.RowItem; import java.io.IOException; import java.io.InputStream; diff --git a/app/src/main/java/com/topjohnwu/magisk/MagiskFragment.java b/app/src/main/java/com/topjohnwu/magisk/MagiskFragment.java index 1ceb9770d..f204fa543 100644 --- a/app/src/main/java/com/topjohnwu/magisk/MagiskFragment.java +++ b/app/src/main/java/com/topjohnwu/magisk/MagiskFragment.java @@ -18,6 +18,7 @@ import android.widget.ImageView; import android.widget.ProgressBar; import android.widget.TextView; +import com.topjohnwu.magisk.receivers.DownloadReceiver; import com.topjohnwu.magisk.utils.Async; import com.topjohnwu.magisk.utils.Utils; @@ -137,7 +138,7 @@ public class MagiskFragment extends Fragment { .setCancelable(true) .setPositiveButton(R.string.download_install, (dialogInterface, i) -> Utils.downloadAndReceive( getActivity(), - new Utils.DownloadReceiver(getString(R.string.magisk)) { + new DownloadReceiver(getString(R.string.magisk)) { @Override public void task(File file) { new Async.FlashZIP(mContext, mName, file.getPath()).executeOnExecutor(AsyncTask.SERIAL_EXECUTOR); @@ -163,7 +164,7 @@ public class MagiskFragment extends Fragment { .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() { + new DownloadReceiver() { @Override public void task(File file) { Intent install = new Intent(Intent.ACTION_INSTALL_PACKAGE); diff --git a/app/src/main/java/com/topjohnwu/magisk/ModulesAdapter.java b/app/src/main/java/com/topjohnwu/magisk/ModulesAdapter.java index 9e7b5823c..b39b177b0 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ModulesAdapter.java +++ b/app/src/main/java/com/topjohnwu/magisk/ModulesAdapter.java @@ -22,6 +22,7 @@ import android.widget.LinearLayout; import android.widget.TextView; import com.topjohnwu.magisk.module.Module; +import com.topjohnwu.magisk.receivers.DownloadReceiver; import com.topjohnwu.magisk.utils.Async; import com.topjohnwu.magisk.utils.Shell; import com.topjohnwu.magisk.utils.Utils; @@ -107,7 +108,7 @@ public class ModulesAdapter extends RecyclerView.Adapter { switch (which) { case DialogInterface.BUTTON_POSITIVE: - Utils.DownloadReceiver receiver = new Utils.DownloadReceiver() { + DownloadReceiver receiver = new DownloadReceiver() { @Override public void task(File file) { Log.d("Magisk", "Task firing"); diff --git a/app/src/main/java/com/topjohnwu/magisk/ModulesFragment.java b/app/src/main/java/com/topjohnwu/magisk/ModulesFragment.java index f8ce14866..b16eed2bf 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ModulesFragment.java +++ b/app/src/main/java/com/topjohnwu/magisk/ModulesFragment.java @@ -18,7 +18,6 @@ import android.view.View; import android.view.ViewGroup; import android.widget.CheckBox; import android.widget.TextView; -import android.widget.Toast; import com.ipaulpro.afilechooser.FileInfo; import com.ipaulpro.afilechooser.utils.FileUtils; @@ -32,38 +31,36 @@ import butterknife.BindView; import butterknife.ButterKnife; public class ModulesFragment extends Fragment { - @BindView(R.id.swipeRefreshLayout) - SwipeRefreshLayout mSwipeRefreshLayout; - @BindView(R.id.recyclerView) - RecyclerView recyclerView; - @BindView(R.id.empty_rv) - TextView emptyTv; private static final int FETCH_ZIP_CODE = 2; + + @BindView(R.id.swipeRefreshLayout) SwipeRefreshLayout mSwipeRefreshLayout; + @BindView(R.id.recyclerView) RecyclerView recyclerView; + @BindView(R.id.empty_rv) TextView emptyTv; + @BindView(R.id.fab) FloatingActionButton fabio; + private SharedPreferences prefs; public static List listModules = new ArrayList<>(); - @BindView(R.id.fab) - FloatingActionButton fabio; @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View viewMain = inflater.inflate(R.layout.modules_fragment, container, false); - ButterKnife.bind(this, viewMain); + + mSwipeRefreshLayout.setRefreshing(true); fabio.setOnClickListener(v -> { Intent getContentIntent = FileUtils.createGetContentIntent(null); getContentIntent.setType("application/zip"); Intent fileIntent = Intent.createChooser(getContentIntent, "Select a file"); - startActivityForResult(fileIntent, FETCH_ZIP_CODE); - }); - prefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); - mSwipeRefreshLayout.setOnRefreshListener(() -> { + prefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); + + mSwipeRefreshLayout.setOnRefreshListener(() -> { recyclerView.setVisibility(View.GONE); new Async.LoadModules(getActivity()).executeOnExecutor(AsyncTask.SERIAL_EXECUTOR); - new updateUI().executeOnExecutor(AsyncTask.SERIAL_EXECUTOR); + new UpdateUI().executeOnExecutor(AsyncTask.SERIAL_EXECUTOR); prefs.edit().putBoolean("ignoreUpdateAlerts", false).apply(); }); @@ -72,12 +69,10 @@ public class ModulesFragment extends Fragment { if (s.contains("updated")) { viewMain.invalidate(); viewMain.requestLayout(); - } }); - new updateUI().executeOnExecutor(AsyncTask.SERIAL_EXECUTOR); - + new UpdateUI().executeOnExecutor(AsyncTask.SERIAL_EXECUTOR); return viewMain; } @@ -104,8 +99,9 @@ public class ModulesFragment extends Fragment { getActivity().setTitle("Modules"); } - private class updateUI extends AsyncTask { + private class UpdateUI extends AsyncTask { + // Just for blocking @Override protected Void doInBackground(Void... voids) { return null; @@ -142,8 +138,7 @@ public class ModulesFragment extends Fragment { Snackbar.make(undeleteBtn, R.string.remove_file_deleted, Snackbar.LENGTH_SHORT).show(); })); - if (mSwipeRefreshLayout.isRefreshing()) - mSwipeRefreshLayout.setRefreshing(false); + mSwipeRefreshLayout.setRefreshing(false); } } diff --git a/app/src/main/java/com/topjohnwu/magisk/ReposAdapter.java b/app/src/main/java/com/topjohnwu/magisk/ReposAdapter.java index 01720b46e..386793d40 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ReposAdapter.java +++ b/app/src/main/java/com/topjohnwu/magisk/ReposAdapter.java @@ -22,6 +22,7 @@ import android.widget.TextView; import android.widget.Toast; import com.topjohnwu.magisk.module.Repo; +import com.topjohnwu.magisk.receivers.DownloadReceiver; import com.topjohnwu.magisk.utils.Async; import com.topjohnwu.magisk.utils.Utils; import com.topjohnwu.magisk.utils.WebWindow; @@ -48,8 +49,7 @@ public class ReposAdapter extends RecyclerView.Adapter private SharedPreferences prefs; - public ReposAdapter(ReposFragment reposFragment, List list) { - ReposFragment reposFragment1 = reposFragment; + public ReposAdapter(List list) { alertPackage = ""; alertUpdate = false; this.mList = list; @@ -145,7 +145,7 @@ public class ReposAdapter extends RecyclerView.Adapter if (view.getId() == mHolder.updateImage.getId()) { if (!repo.isInstalled() | repo.canUpdate()) { - Utils.DownloadReceiver receiver = new Utils.DownloadReceiver() { + DownloadReceiver receiver = new DownloadReceiver() { @Override public void task(File file) { Log.d("Magisk", "Task firing"); diff --git a/app/src/main/java/com/topjohnwu/magisk/ReposFragment.java b/app/src/main/java/com/topjohnwu/magisk/ReposFragment.java index eb8d92de5..4bd6b6c9f 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ReposFragment.java +++ b/app/src/main/java/com/topjohnwu/magisk/ReposFragment.java @@ -55,21 +55,21 @@ public class ReposFragment extends Fragment { mView = view; ButterKnife.bind(this, view); swipeRefreshLayout.setOnRefreshListener(() -> { - this.LoadRepo(true); + new Async.LoadRepos(getActivity()).executeOnExecutor(AsyncTask.SERIAL_EXECUTOR); + new UpdateUI().executeOnExecutor(AsyncTask.SERIAL_EXECUTOR); ignoreAlertUpdate = false; - }); - LoadRepo(false); + //LoadRepo(false); + new UpdateUI().executeOnExecutor(AsyncTask.SERIAL_EXECUTOR); setHasOptionsMenu(false); alertUpdate = false; - if (mListRepos.size() == 0) { - emptyTv.setVisibility(View.VISIBLE); - recyclerView.setVisibility(View.GONE); - return view; - } - CheckForUpdates(); - Log.d("Magisk", "ReposFragment: ListRepos size is " + listRepos().size()); - recyclerView.setAdapter(new ReposAdapter(this, mListRepos)); +// if (mListRepos.size() == 0) { +// emptyTv.setVisibility(View.VISIBLE); +// recyclerView.setVisibility(View.GONE); +// return view; +// } + //CheckForUpdates(); + //recyclerView.setAdapter(new ReposAdapter(this, mListRepos)); return view; } @@ -89,96 +89,117 @@ public class ReposFragment extends Fragment { super.onAttachFragment(childFragment); } - private void LoadRepo(boolean doReload) { - RepoHelper.TaskDelegate taskDelegate = result -> { - if (result.equals("Complete")) { - Log.d("Magisk", "ReposFragment, got delegate"); - UpdateUI(); - if (mView != null) { - mView.invalidate(); - mView.requestLayout(); - } +// private void LoadRepo(boolean doReload) { +// RepoHelper.TaskDelegate taskDelegate = result -> { +// if (result.equals("Complete")) { +// Log.d("Magisk", "ReposFragment, got delegate"); +// UpdateUI(); +// if (mView != null) { +// mView.invalidate(); +// mView.requestLayout(); +// } +// +// } +// +// }; +// Log.d("Magisk", "ReposFragment, LoadRepo called"); +// new Async.LoadRepos(getActivity()); +// } - } - - }; - Log.d("Magisk", "ReposFragment, LoadRepo called"); - new Async.LoadRepos(getActivity()); - } - - private void NotifyOfAlerts() { - if (alertUpdate && !ignoreAlertUpdate) { - Iterator iterRepo = mListReposToUpdate.iterator(); - while (iterRepo.hasNext()) { - Repo repo = iterRepo.next(); - DialogInterface.OnClickListener dialogClickListener = (dialog, which) -> { - switch (which) { - case DialogInterface.BUTTON_POSITIVE: - Utils.DownloadReceiver receiver = new Utils.DownloadReceiver() { - @Override - public void task(File file) { - Log.d("Magisk", "Task firing"); - new Async.FlashZIP(getActivity(), repo.getId(), file.toString()).executeOnExecutor(AsyncTask.SERIAL_EXECUTOR); - } - }; - String filename = repo.getId().replace(" ", "") + ".zip"; - Utils.downloadAndReceive(getActivity(), receiver, repo.getZipUrl(), filename); - - break; - - case DialogInterface.BUTTON_NEGATIVE: -// ignoreAlertUpdate = true; -// SharedPreferences.Editor editor = prefs.edit(); -// editor.putBoolean("ignoreUpdateAlerts", ignoreAlertUpdate); -// editor.apply(); - break; - } - }; - - String theme = PreferenceManager.getDefaultSharedPreferences(getActivity()).getString("theme", ""); - Logger.dh("ReposFragment: Theme is " + theme); - if (theme.equals("Dark")) { - builder = new AlertDialog.Builder(getActivity(),R.style.AlertDialog_dh); - } else { - builder = new AlertDialog.Builder(getActivity()); - } - builder.setMessage("An update is available for " + repo.getName() + ". Would you like to install it?").setPositiveButton("Yes", dialogClickListener) - .setNegativeButton("No", dialogClickListener).show(); - iterRepo.remove(); - - } - - } - } +// private void NotifyOfAlerts() { +// if (alertUpdate && !ignoreAlertUpdate) { +// Iterator iterRepo = mListReposToUpdate.iterator(); +// while (iterRepo.hasNext()) { +// Repo repo = iterRepo.next(); +// DialogInterface.OnClickListener dialogClickListener = (dialog, which) -> { +// switch (which) { +// case DialogInterface.BUTTON_POSITIVE: +// Utils.DownloadReceiver receiver = new Utils.DownloadReceiver() { +// @Override +// public void task(File file) { +// Log.d("Magisk", "Task firing"); +// new Async.FlashZIP(getActivity(), repo.getId(), file.toString()).executeOnExecutor(AsyncTask.SERIAL_EXECUTOR); +// } +// }; +// String filename = repo.getId().replace(" ", "") + ".zip"; +// Utils.downloadAndReceive(getActivity(), receiver, repo.getZipUrl(), filename); +// +// break; +// +// case DialogInterface.BUTTON_NEGATIVE: +//// ignoreAlertUpdate = true; +//// SharedPreferences.Editor editor = prefs.edit(); +//// editor.putBoolean("ignoreUpdateAlerts", ignoreAlertUpdate); +//// editor.apply(); +// break; +// } +// }; +// +// String theme = PreferenceManager.getDefaultSharedPreferences(getActivity()).getString("theme", ""); +// Logger.dh("ReposFragment: Theme is " + theme); +// if (theme.equals("Dark")) { +// builder = new AlertDialog.Builder(getActivity(),R.style.AlertDialog_dh); +// } else { +// builder = new AlertDialog.Builder(getActivity()); +// } +// builder.setMessage("An update is available for " + repo.getName() + ". Would you like to install it?").setPositiveButton("Yes", dialogClickListener) +// .setNegativeButton("No", dialogClickListener).show(); +// iterRepo.remove(); +// +// } +// +// } +// } @Override public void onResume() { super.onResume(); - LoadRepo(false); + //LoadRepo(false); getActivity().setTitle("Magisk"); } + + private class UpdateUI extends AsyncTask { - protected List listRepos() { - return mListRepos; - } - - private void UpdateUI() { - Log.d("Magisk", "ReposFragment: UpdateUI Called, size is " + listRepos().size()); - - if (listRepos().size() == 0) { - emptyTv.setVisibility(View.VISIBLE); - recyclerView.setVisibility(View.GONE); - - } - Log.d("Magisk", "ReposFragment: ListRepos size is " + listRepos().size()); - recyclerView.setAdapter(new ReposAdapter(this, listRepos())); - if (swipeRefreshLayout.isRefreshing()) { - swipeRefreshLayout.setRefreshing(false); - CheckForUpdates(); - //NotifyOfAlerts(); + @Override + protected Void doInBackground(Void... voids) { + return null; } + @Override + protected void onPostExecute(Void v) { + super.onPostExecute(v); + if (mListRepos.size() == 0) { + emptyTv.setVisibility(View.VISIBLE); + recyclerView.setVisibility(View.GONE); + + } + Log.d("Magisk", "ReposFragment: ListRepos size is " + mListRepos.size()); + recyclerView.setAdapter(new ReposAdapter(mListRepos)); + if (swipeRefreshLayout.isRefreshing()) { + swipeRefreshLayout.setRefreshing(false); + //CheckForUpdates(); + //NotifyOfAlerts(); + } + } } +// private void UpdateUI() { +// Log.d("Magisk", "ReposFragment: UpdateUI Called, size is " + mListRepos.size()); +// +// if (mListRepos.size() == 0) { +// emptyTv.setVisibility(View.VISIBLE); +// recyclerView.setVisibility(View.GONE); +// +// } +// Log.d("Magisk", "ReposFragment: ListRepos size is " + mListRepos.size()); +// recyclerView.setAdapter(new ReposAdapter(this, mListRepos)); +// if (swipeRefreshLayout.isRefreshing()) { +// swipeRefreshLayout.setRefreshing(false); +// CheckForUpdates(); +// //NotifyOfAlerts(); +// } +// +// } + } diff --git a/app/src/main/java/com/topjohnwu/magisk/RootFragment.java b/app/src/main/java/com/topjohnwu/magisk/RootFragment.java index 6be2ce78c..53d629a67 100644 --- a/app/src/main/java/com/topjohnwu/magisk/RootFragment.java +++ b/app/src/main/java/com/topjohnwu/magisk/RootFragment.java @@ -36,42 +36,26 @@ import butterknife.ButterKnife; public class RootFragment extends Fragment { public SharedPreferences prefs; - @BindView(R.id.progressBar) - ProgressBar progressBar; - @BindView(R.id.rootSwitchView) - View rootToggleView; - @BindView(R.id.autoRootSwitchView) - View autoRootToggleView; - @BindView(R.id.selinuxSwitchView) - View selinuxToggleView; - @BindView(R.id.rootStatusView) - View rootStatusView; - @BindView(R.id.safetynetStatusView) - View safetynetStatusView; - @BindView(R.id.selinuxStatusView) - View selinuxStatusView; - @BindView(R.id.root_toggle) - Switch rootToggle; - @BindView(R.id.auto_root_toggle) - Switch autoRootToggle; - @BindView(R.id.selinux_toggle) - Switch selinuxToggle; - @BindView(R.id.root_status_container) - View rootStatusContainer; - @BindView(R.id.root_status_icon) - ImageView rootStatusIcon; - @BindView(R.id.root_status) - TextView rootStatus; - @BindView(R.id.selinux_status_container) - View selinuxStatusContainer; - @BindView(R.id.selinux_status_icon) - ImageView selinuxStatusIcon; - @BindView(R.id.selinux_status) - TextView selinuxStatus; - @BindView(R.id.safety_net_status) - TextView safetyNetStatus; - @BindView(R.id.safety_net_icon) - ImageView safetyNetStatusIcon; + + @BindView(R.id.progressBar) ProgressBar progressBar; + @BindView(R.id.rootSwitchView) View rootToggleView; + @BindView(R.id.autoRootSwitchView) View autoRootToggleView; + @BindView(R.id.selinuxSwitchView) View selinuxToggleView; + @BindView(R.id.rootStatusView) View rootStatusView; + @BindView(R.id.safetynetStatusView) View safetynetStatusView; + @BindView(R.id.selinuxStatusView) View selinuxStatusView; + @BindView(R.id.root_toggle) Switch rootToggle; + @BindView(R.id.auto_root_toggle) Switch autoRootToggle; + @BindView(R.id.selinux_toggle) Switch selinuxToggle; + @BindView(R.id.root_status_container) View rootStatusContainer; + @BindView(R.id.root_status_icon) ImageView rootStatusIcon; + @BindView(R.id.root_status) TextView rootStatus; + @BindView(R.id.selinux_status_container) View selinuxStatusContainer; + @BindView(R.id.selinux_status_icon) ImageView selinuxStatusIcon; + @BindView(R.id.selinux_status) TextView selinuxStatus; + @BindView(R.id.safety_net_status) TextView safetyNetStatus; + @BindView(R.id.safety_net_icon) ImageView safetyNetStatusIcon; + int statusOK = R.drawable.ic_check_circle; int statusAuto = R.drawable.ic_autoroot; int statusError = R.drawable.ic_error; diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/RowItem.java b/app/src/main/java/com/topjohnwu/magisk/RowItem.java similarity index 98% rename from app/src/main/java/com/topjohnwu/magisk/utils/RowItem.java rename to app/src/main/java/com/topjohnwu/magisk/RowItem.java index 96c7d2f4e..f53be56b2 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/RowItem.java +++ b/app/src/main/java/com/topjohnwu/magisk/RowItem.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.topjohnwu.magisk.utils; +package com.topjohnwu.magisk; import android.content.Context; import android.content.res.TypedArray; diff --git a/app/src/main/java/com/topjohnwu/magisk/receivers/DownloadReceiver.java b/app/src/main/java/com/topjohnwu/magisk/receivers/DownloadReceiver.java new file mode 100644 index 000000000..8e86f03f0 --- /dev/null +++ b/app/src/main/java/com/topjohnwu/magisk/receivers/DownloadReceiver.java @@ -0,0 +1,58 @@ +package com.topjohnwu.magisk.receivers; + +import android.app.DownloadManager; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.database.Cursor; +import android.net.Uri; +import android.widget.Toast; + +import com.topjohnwu.magisk.R; + +import java.io.File; + +public abstract class DownloadReceiver extends BroadcastReceiver { + public Context mContext; + long downloadID; + public String mName; + + public DownloadReceiver() { + } + + public DownloadReceiver(String name) { + mName = name; + } + + @Override + public void onReceive(Context context, Intent intent) { + mContext = context; + DownloadManager downloadManager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE); + String action = intent.getAction(); + if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) { + DownloadManager.Query query = new DownloadManager.Query(); + query.setFilterById(downloadID); + Cursor c = downloadManager.query(query); + if (c.moveToFirst()) { + int columnIndex = c.getColumnIndex(DownloadManager.COLUMN_STATUS); + int status = c.getInt(columnIndex); + switch (status) { + case DownloadManager.STATUS_SUCCESSFUL: + File file = new File(Uri.parse(c.getString(c.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI))).getPath()); + task(file); + break; + default: + Toast.makeText(context, R.string.download_file_error, Toast.LENGTH_LONG).show(); + break; + } + context.unregisterReceiver(this); + } + } + } + + public void setDownloadID(long id) { + downloadID = id; + } + + public abstract void task(File file); +} diff --git a/app/src/main/java/com/topjohnwu/magisk/receivers/PrivateBroadcastReceiver.java b/app/src/main/java/com/topjohnwu/magisk/receivers/PrivateBroadcastReceiver.java index 01d7cd560..1da217462 100644 --- a/app/src/main/java/com/topjohnwu/magisk/receivers/PrivateBroadcastReceiver.java +++ b/app/src/main/java/com/topjohnwu/magisk/receivers/PrivateBroadcastReceiver.java @@ -25,11 +25,11 @@ public final class PrivateBroadcastReceiver extends BroadcastReceiver { } if (ACTION_ENABLEROOT.equals(action)) { Utils.toggleAutoRoot(false, context); - Utils.toggleRoot(true,context); + Utils.toggleRoot(true, context); } if (ACTION_DISABLEROOT.equals(action)) { Utils.toggleAutoRoot(false, context); - Utils.toggleRoot(false,context); + Utils.toggleRoot(false, context); } Utils.SetupQuickSettingsTile(context); diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/Async.java b/app/src/main/java/com/topjohnwu/magisk/utils/Async.java index d117995e6..74f9575b0 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/Async.java +++ b/app/src/main/java/com/topjohnwu/magisk/utils/Async.java @@ -17,6 +17,7 @@ import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.ReposFragment; import com.topjohnwu.magisk.module.Module; import com.topjohnwu.magisk.module.RepoHelper; +import com.topjohnwu.magisk.receivers.DownloadReceiver; import org.json.JSONException; import org.json.JSONObject; @@ -118,13 +119,13 @@ public class Async { .setPositiveButton(R.string.download_install, (dialogInterface, i) -> new AlertDialog.Builder(mContext) .setTitle(R.string.root_method_title) .setItems(new String[]{mContext.getString(R.string.phh), mContext.getString(R.string.supersu)}, (dialogInterface1, root) -> { - Utils.DownloadReceiver rootReceiver; + DownloadReceiver rootReceiver; String link, filename; switch (root) { case 0: link = Utils.phhLink; filename = "phhsu.zip"; - rootReceiver = new Utils.DownloadReceiver(mContext.getString(R.string.phh)) { + rootReceiver = new DownloadReceiver(mContext.getString(R.string.phh)) { @Override public void task(File file) { new FlashZIP(mContext, mName, file.getPath()).executeOnExecutor(AsyncTask.SERIAL_EXECUTOR); @@ -134,7 +135,7 @@ public class Async { case 1: link = Utils.supersuLink; filename = "supersu.zip"; - rootReceiver = new Utils.DownloadReceiver(mContext.getString(R.string.supersu)) { + rootReceiver = new DownloadReceiver(mContext.getString(R.string.supersu)) { @Override public void task(File file) { new FlashZIP(mContext, mName, file.getPath()).executeOnExecutor(AsyncTask.SERIAL_EXECUTOR); @@ -145,7 +146,7 @@ public class Async { rootReceiver = null; link = filename = null; } - Utils.DownloadReceiver magiskReceiver = new Utils.DownloadReceiver(mContext.getString(R.string.magisk)) { + DownloadReceiver magiskReceiver = new DownloadReceiver(mContext.getString(R.string.magisk)) { @Override public void task(File file) { Context temp = mContext; @@ -174,7 +175,7 @@ public class Async { case 0: Utils.downloadAndReceive( mContext, - new Utils.DownloadReceiver(mContext.getString(R.string.phh)) { + new DownloadReceiver(mContext.getString(R.string.phh)) { @Override public void task(File file) { new FlashZIP(mContext, mName, file.getPath()).executeOnExecutor(AsyncTask.SERIAL_EXECUTOR); @@ -185,7 +186,7 @@ public class Async { case 1: Utils.downloadAndReceive( mContext, - new Utils.DownloadReceiver(mContext.getString(R.string.supersu)) { + new DownloadReceiver(mContext.getString(R.string.supersu)) { @Override public void task(File file) { new FlashZIP(mContext, mName, file.getPath()).executeOnExecutor(AsyncTask.SERIAL_EXECUTOR); diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java b/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java index 72df3437d..72298e43e 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java +++ b/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java @@ -1,23 +1,18 @@ package com.topjohnwu.magisk.utils; import android.Manifest; -import android.app.Activity; import android.app.ActivityManager; import android.app.DownloadManager; -import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.SharedPreferences; import android.content.pm.PackageManager; -import android.database.Cursor; import android.net.Uri; import android.os.Build; import android.os.Environment; import android.preference.PreferenceManager; import android.provider.Settings; -import android.service.quicksettings.TileService; -import android.support.design.widget.Snackbar; import android.support.v4.app.ActivityCompat; import android.text.TextUtils; import android.util.Base64; @@ -27,8 +22,8 @@ import android.widget.Toast; import com.kcoppock.broadcasttilesupport.BroadcastTileIntentBuilder; import com.topjohnwu.magisk.R; -import com.topjohnwu.magisk.RootFragment; import com.topjohnwu.magisk.module.BaseModule; +import com.topjohnwu.magisk.receivers.DownloadReceiver; import com.topjohnwu.magisk.receivers.PrivateBroadcastReceiver; import com.topjohnwu.magisk.services.MonitorService; import com.topjohnwu.magisk.services.TileServiceCompat; @@ -423,51 +418,6 @@ public class Utils { return false; } - public abstract static class DownloadReceiver extends BroadcastReceiver { - public Context mContext; - long downloadID; - public String mName; - - public DownloadReceiver() { - } - - public DownloadReceiver(String name) { - mName = name; - } - - @Override - public void onReceive(Context context, Intent intent) { - mContext = context; - DownloadManager downloadManager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE); - String action = intent.getAction(); - if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) { - DownloadManager.Query query = new DownloadManager.Query(); - query.setFilterById(downloadID); - Cursor c = downloadManager.query(query); - if (c.moveToFirst()) { - int columnIndex = c.getColumnIndex(DownloadManager.COLUMN_STATUS); - int status = c.getInt(columnIndex); - switch (status) { - case DownloadManager.STATUS_SUCCESSFUL: - File file = new File(Uri.parse(c.getString(c.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI))).getPath()); - task(file); - break; - default: - Toast.makeText(context, R.string.download_file_error, Toast.LENGTH_LONG).show(); - break; - } - context.unregisterReceiver(this); - } - } - } - - public void setDownloadID(long id) { - downloadID = id; - } - - public abstract void task(File file); - } - public static boolean isMyServiceRunning(Class serviceClass, Context context) { ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) { diff --git a/app/src/main/res/layout/activity_about.xml b/app/src/main/res/layout/activity_about.xml index 3a60caf49..83340256b 100644 --- a/app/src/main/res/layout/activity_about.xml +++ b/app/src/main/res/layout/activity_about.xml @@ -57,35 +57,35 @@ android:textAppearance="@style/TextAppearance.AppCompat.Headline"/> - - - - - -