1
0
mirror of https://github.com/topjohnwu/Magisk.git synced 2025-04-15 22:31:25 +00:00

108 lines
4.0 KiB
Java
Raw Normal View History

2016-12-25 03:05:22 +08:00
package com.topjohnwu.magisk;
import android.app.Fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
2016-12-27 04:38:16 +08:00
import android.support.v7.widget.CardView;
2016-12-25 03:05:22 +08:00
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
2016-12-25 17:17:20 +08:00
import android.widget.ArrayAdapter;
import android.widget.Button;
2016-12-27 04:38:16 +08:00
import android.widget.CheckBox;
2016-12-25 17:17:20 +08:00
import android.widget.Spinner;
import android.widget.TextView;
2016-12-25 03:05:22 +08:00
2016-12-27 04:38:16 +08:00
import com.topjohnwu.magisk.receivers.MagiskDlReceiver;
2016-12-25 22:36:51 +08:00
import com.topjohnwu.magisk.utils.CallbackHandler;
2016-12-27 04:38:16 +08:00
import com.topjohnwu.magisk.utils.Utils;
2016-12-25 03:05:22 +08:00
2016-12-27 04:38:16 +08:00
import java.util.ArrayList;
2016-12-25 17:17:20 +08:00
import java.util.List;
2016-12-25 03:05:22 +08:00
2016-12-25 17:17:20 +08:00
import butterknife.BindView;
2016-12-25 03:05:22 +08:00
import butterknife.ButterKnife;
2016-12-25 22:36:51 +08:00
public class InstallFragment extends Fragment implements CallbackHandler.EventListener {
2016-12-25 03:05:22 +08:00
2016-12-25 22:36:51 +08:00
public static final CallbackHandler.Event blockDetectionDone = new CallbackHandler.Event();
2016-12-25 17:17:20 +08:00
2016-12-25 22:36:51 +08:00
public static List<String> blockList;
public static String bootBlock = null;
2017-01-07 02:46:50 +08:00
@BindView(R.id.current_version_title) TextView currentVersionTitle;
2016-12-25 22:36:51 +08:00
@BindView(R.id.install_title) TextView installTitle;
2016-12-25 17:17:20 +08:00
@BindView(R.id.block_spinner) Spinner spinner;
@BindView(R.id.detect_bootimage) Button detectButton;
2016-12-27 04:38:16 +08:00
@BindView(R.id.flash_button) CardView flashButton;
@BindView(R.id.keep_force_enc) CheckBox keepEncChkbox;
@BindView(R.id.keep_verity) CheckBox keepVerityChkbox;
2016-12-25 17:17:20 +08:00
2016-12-25 03:05:22 +08:00
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.install_fragment, container, false);
ButterKnife.bind(this, v);
2016-12-25 22:36:51 +08:00
detectButton.setOnClickListener(v1 -> toAutoDetect());
2017-01-07 02:46:50 +08:00
currentVersionTitle.setText(getString(R.string.current_magisk_title, StatusFragment.magiskVersionString));
2016-12-25 22:36:51 +08:00
installTitle.setText(getString(R.string.install_magisk_title, StatusFragment.remoteMagiskVersion));
2016-12-27 04:38:16 +08:00
flashButton.setOnClickListener(v1 -> {
String bootImage = bootBlock;
if (bootImage == null) {
bootImage = blockList.get(spinner.getSelectedItemPosition() - 1);
}
2017-01-07 02:46:50 +08:00
String filename = "Magisk-v" + StatusFragment.remoteMagiskVersion + ".zip";
2016-12-28 04:48:40 +08:00
String finalBootImage = bootImage;
2017-01-10 22:30:05 +08:00
Utils.getAlertDialogBuilder(getActivity())
2016-12-28 04:48:40 +08:00
.setTitle(getString(R.string.repo_install_title, getString(R.string.magisk)))
.setMessage(getString(R.string.repo_install_msg, filename))
.setCancelable(true)
.setPositiveButton(R.string.download_install, (dialogInterface, i) -> Utils.dlAndReceive(
getActivity(),
new MagiskDlReceiver(finalBootImage, keepEncChkbox.isChecked(), keepVerityChkbox.isChecked()),
StatusFragment.magiskLink,
Utils.getLegalFilename(filename)))
.setNegativeButton(R.string.no_thanks, null)
.show();
2016-12-27 04:38:16 +08:00
});
2016-12-25 22:36:51 +08:00
if (blockDetectionDone.isTriggered) {
updateUI();
}
2016-12-25 03:05:22 +08:00
return v;
}
2016-12-25 22:36:51 +08:00
@Override
public void onTrigger(CallbackHandler.Event event) {
updateUI();
}
private void updateUI() {
2016-12-27 04:38:16 +08:00
List<String> items = new ArrayList<>(blockList);
items.add(0, getString(R.string.auto_detect, bootBlock));
2016-12-25 22:36:51 +08:00
ArrayAdapter<String> adapter = new ArrayAdapter<>(getActivity(),
2016-12-27 04:38:16 +08:00
android.R.layout.simple_spinner_item, items);
2016-12-25 22:36:51 +08:00
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
toAutoDetect();
2016-12-25 17:17:20 +08:00
}
2016-12-25 22:36:51 +08:00
private void toAutoDetect() {
if (bootBlock != null) {
spinner.setSelection(0);
}
2016-12-25 17:17:20 +08:00
}
2016-12-25 03:05:22 +08:00
@Override
public void onResume() {
super.onResume();
getActivity().setTitle(R.string.install);
2016-12-25 22:36:51 +08:00
CallbackHandler.register(blockDetectionDone, this);
2016-12-25 03:05:22 +08:00
}
2016-12-25 22:36:51 +08:00
@Override
public void onDestroy() {
super.onDestroy();
CallbackHandler.unRegister(blockDetectionDone, this);
}
2016-12-25 03:05:22 +08:00
}