mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-06-12 21:27:41 +02:00
Improve installation UI and dialog
This commit is contained in:
@ -30,6 +30,7 @@ public class InstallFragment extends Fragment implements CallbackHandler.EventLi
|
||||
public static List<String> blockList;
|
||||
public static String bootBlock = null;
|
||||
|
||||
@BindView(R.id.current_version_title) TextView currentVersionTitle;
|
||||
@BindView(R.id.install_title) TextView installTitle;
|
||||
@BindView(R.id.block_spinner) Spinner spinner;
|
||||
@BindView(R.id.detect_bootimage) Button detectButton;
|
||||
@ -43,13 +44,14 @@ public class InstallFragment extends Fragment implements CallbackHandler.EventLi
|
||||
View v = inflater.inflate(R.layout.install_fragment, container, false);
|
||||
ButterKnife.bind(this, v);
|
||||
detectButton.setOnClickListener(v1 -> toAutoDetect());
|
||||
currentVersionTitle.setText(getString(R.string.current_magisk_title, StatusFragment.magiskVersionString));
|
||||
installTitle.setText(getString(R.string.install_magisk_title, StatusFragment.remoteMagiskVersion));
|
||||
flashButton.setOnClickListener(v1 -> {
|
||||
String bootImage = bootBlock;
|
||||
if (bootImage == null) {
|
||||
bootImage = blockList.get(spinner.getSelectedItemPosition() - 1);
|
||||
}
|
||||
String filename = "Magisk-v" + String.valueOf(StatusFragment.remoteMagiskVersion) + ".zip";
|
||||
String filename = "Magisk-v" + StatusFragment.remoteMagiskVersion + ".zip";
|
||||
String finalBootImage = bootImage;
|
||||
MainActivity.alertBuilder
|
||||
.setTitle(getString(R.string.repo_install_title, getString(R.string.magisk)))
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.topjohnwu.magisk;
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Fragment;
|
||||
import android.app.FragmentTransaction;
|
||||
import android.content.Intent;
|
||||
@ -17,7 +18,6 @@ import android.support.v4.app.ActivityCompat;
|
||||
import android.support.v4.view.GravityCompat;
|
||||
import android.support.v4.widget.DrawerLayout;
|
||||
import android.support.v7.app.ActionBarDrawerToggle;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.Menu;
|
||||
|
@ -1,7 +1,12 @@
|
||||
package com.topjohnwu.magisk;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Fragment;
|
||||
import android.app.FragmentTransaction;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
@ -26,9 +31,11 @@ import butterknife.ButterKnife;
|
||||
public class StatusFragment extends Fragment implements CallbackHandler.EventListener {
|
||||
|
||||
public static double magiskVersion, remoteMagiskVersion = -1;
|
||||
public static String magiskVersionString, magiskLink, magiskChangelog;
|
||||
public static String magiskVersionString = "(none)", magiskLink, releaseNoteLink;
|
||||
public static int SNCheckResult = -1;
|
||||
|
||||
private static boolean noDialog = false;
|
||||
|
||||
public static final CallbackHandler.Event updateCheckDone = new CallbackHandler.Event();
|
||||
public static final CallbackHandler.Event safetyNetDone = new CallbackHandler.Event();
|
||||
|
||||
@ -62,6 +69,8 @@ public class StatusFragment extends Fragment implements CallbackHandler.EventLis
|
||||
checkMagiskInfo();
|
||||
}
|
||||
|
||||
private AlertDialog updateMagisk;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
@ -84,13 +93,12 @@ public class StatusFragment extends Fragment implements CallbackHandler.EventLis
|
||||
safetyNetStatusText.setTextColor(defaultColor);
|
||||
|
||||
safetyNetDone.isTriggered = false;
|
||||
noDialog = false;
|
||||
|
||||
updateUI();
|
||||
new Async.CheckUpdates().exec();
|
||||
});
|
||||
|
||||
updateUI();
|
||||
|
||||
safetyNetContainer.setOnClickListener(view -> {
|
||||
safetyNetProgress.setVisibility(View.VISIBLE);
|
||||
safetyNetContainer.setBackgroundColor(trans);
|
||||
@ -99,7 +107,7 @@ public class StatusFragment extends Fragment implements CallbackHandler.EventLis
|
||||
Async.checkSafetyNet(getActivity());
|
||||
});
|
||||
|
||||
if (magiskVersion < 0 && Shell.rootAccess()) {
|
||||
if (magiskVersion < 0 && Shell.rootAccess() && !noDialog) {
|
||||
MainActivity.alertBuilder
|
||||
.setTitle(R.string.no_magisk_title)
|
||||
.setMessage(R.string.no_magisk_msg)
|
||||
@ -112,10 +120,12 @@ public class StatusFragment extends Fragment implements CallbackHandler.EventLis
|
||||
transaction.replace(R.id.content_frame, new InstallFragment(), "install").commit();
|
||||
} catch (IllegalStateException ignored) {}
|
||||
})
|
||||
.setNegativeButton(R.string.no_thanks, null)
|
||||
.setNegativeButton(R.string.no_thanks, (dialogInterface, i) -> noDialog = true)
|
||||
.show();
|
||||
}
|
||||
|
||||
updateUI();
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
@ -229,6 +239,31 @@ public class StatusFragment extends Fragment implements CallbackHandler.EventLis
|
||||
|
||||
magiskCheckUpdatesProgress.setVisibility(View.GONE);
|
||||
mSwipeRefreshLayout.setRefreshing(false);
|
||||
|
||||
updateMagisk = MainActivity.alertBuilder
|
||||
.setTitle(R.string.magisk_update_title)
|
||||
.setMessage(getString(R.string.magisk_update_message, remoteMagiskVersion))
|
||||
.setCancelable(true)
|
||||
.setPositiveButton(R.string.goto_install, (dialogInterface, i) -> {
|
||||
((MainActivity) getActivity()).navigationView.setCheckedItem(R.id.install);
|
||||
FragmentTransaction transaction = getFragmentManager().beginTransaction();
|
||||
transaction.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out);
|
||||
try {
|
||||
transaction.replace(R.id.content_frame, new InstallFragment(), "install").commit();
|
||||
} catch (IllegalStateException ignored) {}
|
||||
})
|
||||
.setNeutralButton(R.string.check_release_notes, (dialog, which) -> {
|
||||
getActivity().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(releaseNoteLink)));
|
||||
})
|
||||
.setNegativeButton(R.string.no_thanks, (dialogInterface, i) -> noDialog = true)
|
||||
.create();
|
||||
|
||||
if (magiskVersion < remoteMagiskVersion && Shell.rootAccess()) {
|
||||
magiskStatusContainer.setOnClickListener(view -> updateMagisk.show());
|
||||
if (!noDialog) {
|
||||
updateMagisk.show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateSafetyNetUI() {
|
||||
|
@ -59,12 +59,10 @@ public class Async {
|
||||
String jsonStr = WebRequest.makeWebServiceCall(UPDATE_JSON, WebRequest.GET);
|
||||
try {
|
||||
JSONObject json = new JSONObject(jsonStr);
|
||||
|
||||
JSONObject magisk = json.getJSONObject("magisk");
|
||||
|
||||
StatusFragment.remoteMagiskVersion = magisk.getDouble("versionCode");
|
||||
StatusFragment.magiskLink = magisk.getString("link");
|
||||
StatusFragment.magiskChangelog = magisk.getString("changelog");
|
||||
StatusFragment.releaseNoteLink = magisk.getString("note");
|
||||
} catch (JSONException ignored) {}
|
||||
return null;
|
||||
}
|
||||
|
Reference in New Issue
Block a user