Fix UI refreshes

This commit is contained in:
topjohnwu 2016-09-26 10:45:34 +08:00
parent 6692b618ea
commit 91d3d2ad1f
13 changed files with 230 additions and 220 deletions

View File

@ -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;

View File

@ -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);

View File

@ -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<ModulesAdapter.ViewHold
DialogInterface.OnClickListener dialogClickListener = (dialog, which) -> {
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");

View File

@ -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<Module> 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<Void, Void, Void> {
private class UpdateUI extends AsyncTask<Void, Void, Void> {
// 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);
}
}

View File

@ -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<ReposAdapter.ViewHolder>
private SharedPreferences prefs;
public ReposAdapter(ReposFragment reposFragment, List<Repo> list) {
ReposFragment reposFragment1 = reposFragment;
public ReposAdapter(List<Repo> list) {
alertPackage = "";
alertUpdate = false;
this.mList = list;
@ -145,7 +145,7 @@ public class ReposAdapter extends RecyclerView.Adapter<ReposAdapter.ViewHolder>
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");

View File

@ -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<Repo> 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<Repo> 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<Void, Void, Void> {
protected List<Repo> 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();
// }
//
// }
}

View File

@ -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;

View File

@ -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;

View File

@ -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);
}

View File

@ -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);

View File

@ -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);

View File

@ -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)) {

View File

@ -57,35 +57,35 @@
android:textAppearance="@style/TextAppearance.AppCompat.Headline"/>
</LinearLayout>
<com.topjohnwu.magisk.utils.RowItem
<com.topjohnwu.magisk.RowItem
android:id="@+id/app_version_info"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:icon="@drawable/ic_info_outline"
app:text="@string/app_version"/>
<com.topjohnwu.magisk.utils.RowItem
<com.topjohnwu.magisk.RowItem
android:id="@+id/app_changelog"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:icon="@drawable/ic_history"
app:text="@string/app_changelog"/>
<com.topjohnwu.magisk.utils.RowItem
<com.topjohnwu.magisk.RowItem
android:id="@+id/app_developers"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:icon="@drawable/ic_person"
app:text="@string/app_developers"/>
<com.topjohnwu.magisk.utils.RowItem
<com.topjohnwu.magisk.RowItem
android:id="@+id/app_translators"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:icon="@drawable/ic_language"
app:text="@string/app_translators"/>
<com.topjohnwu.magisk.utils.RowItem
<com.topjohnwu.magisk.RowItem
android:id="@+id/app_source_code"
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -104,7 +104,7 @@
style="?attr/cardStyle"
app:cardUseCompatPadding="true">
<com.topjohnwu.magisk.utils.RowItem
<com.topjohnwu.magisk.RowItem
android:id="@+id/support_thread"
android:layout_width="match_parent"
android:layout_height="wrap_content"