Update Install Fragment UI

This commit is contained in:
topjohnwu 2016-12-25 22:36:51 +08:00
parent 8fe4cfecb6
commit c78209604c
14 changed files with 217 additions and 171 deletions

View File

@ -1,10 +1,8 @@
package com.topjohnwu.magisk;
import android.app.Fragment;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -13,22 +11,21 @@ import android.widget.Button;
import android.widget.Spinner;
import android.widget.TextView;
import com.topjohnwu.magisk.receivers.DownloadReceiver;
import com.topjohnwu.magisk.utils.Async;
import com.topjohnwu.magisk.utils.Shell;
import com.topjohnwu.magisk.utils.Utils;
import com.topjohnwu.magisk.utils.ZipUtils;
import com.topjohnwu.magisk.utils.CallbackHandler;
import java.io.File;
import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
public class InstallFragment extends Fragment {
public class InstallFragment extends Fragment implements CallbackHandler.EventListener {
private List<String> blockList;
public static final CallbackHandler.Event blockDetectionDone = new CallbackHandler.Event();
public static List<String> blockList;
public static String bootBlock = null;
@BindView(R.id.install_title) TextView installTitle;
@BindView(R.id.block_spinner) Spinner spinner;
@BindView(R.id.detect_bootimage) Button detectButton;
@ -37,56 +34,46 @@ public class InstallFragment extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.install_fragment, container, false);
ButterKnife.bind(this, v);
detectButton.setOnClickListener(v1 -> detectBootImage());
getBlockList();
detectButton.setOnClickListener(v1 -> toAutoDetect());
installTitle.setText(getString(R.string.install_magisk_title, StatusFragment.remoteMagiskVersion));
if (blockDetectionDone.isTriggered) {
updateUI();
}
return v;
}
private void getBlockList() {
new Async.RootTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
blockList = Utils.getBlockList();
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
ArrayAdapter<String> adapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_spinner_item, blockList);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
detectBootImage();
}
}.exec();
@Override
public void onTrigger(CallbackHandler.Event event) {
updateUI();
}
private void detectBootImage() {
new Async.RootTask<Void, Void, Void>() {
String boot;
@Override
protected Void doInBackground(Void... params) {
boot = Utils.detectBootImage();
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
if (boot != null) {
int idx = blockList.indexOf(boot);
if (idx != -1) {
spinner.setSelection(idx);
}
}
}
}.exec();
private void updateUI() {
blockList.add(0, getString(R.string.auto_detect, bootBlock));
ArrayAdapter<String> adapter = new ArrayAdapter<>(getActivity(),
android.R.layout.simple_spinner_item, blockList);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
toAutoDetect();
}
private void toAutoDetect() {
if (bootBlock != null) {
spinner.setSelection(0);
}
}
@Override
public void onResume() {
super.onResume();
getActivity().setTitle(R.string.install);
CallbackHandler.register(blockDetectionDone, this);
}
@Override
public void onDestroy() {
super.onDestroy();
CallbackHandler.unRegister(blockDetectionDone, this);
}
}
// private AlertDialog.OnClickListener flashMagisk = (dialogInterface, i) -> Utils.dlAndReceive(

View File

@ -4,10 +4,12 @@ import android.Manifest;
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.preference.Preference;
import android.preference.PreferenceManager;
import android.support.annotation.IdRes;
import android.support.annotation.NonNull;
@ -22,16 +24,19 @@ import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import com.topjohnwu.magisk.utils.CallbackHandler;
import com.topjohnwu.magisk.utils.Logger;
import butterknife.BindView;
import butterknife.ButterKnife;
public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener, CallbackHandler.EventListener {
private static final String SELECTED_ITEM_ID = "SELECTED_ITEM_ID";
private final Handler mDrawerHandler = new Handler();
private SharedPreferences prefs;
@BindView(R.id.toolbar) Toolbar toolbar;
@BindView(R.id.drawer_layout) DrawerLayout drawer;
@ -43,7 +48,9 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
@Override
protected void onCreate(final Bundle savedInstanceState) {
String theme = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("theme", "");
prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
String theme = prefs.getString("theme", "");
Logger.dev("MainActivity: Theme is " + theme);
if (theme.equals("Dark")) {
setTheme(R.style.AppTheme_dh);
@ -85,14 +92,25 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
}
navigationView.setNavigationItemSelectedListener(this);
if (StatusFragment.updateCheckDone.isTriggered) {
onTrigger(StatusFragment.updateCheckDone);
}
}
@Override
protected void onResume() {
super.onResume();
CallbackHandler.register(StatusFragment.updateCheckDone, this);
checkHideSection();
}
@Override
protected void onDestroy() {
super.onDestroy();
CallbackHandler.unRegister(StatusFragment.updateCheckDone, this);
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
@ -117,17 +135,26 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
return true;
}
@Override
public void onTrigger(CallbackHandler.Event event) {
Menu menu = navigationView.getMenu();
if (StatusFragment.remoteMagiskVersion < 0) {
menu.findItem(R.id.install).setVisible(false);
} else {
menu.findItem(R.id.install).setVisible(true);
}
}
private void checkHideSection() {
Menu menu = navigationView.getMenu();
if (StatusFragment.magiskVersion == -1) {
if (StatusFragment.magiskVersion < 0) {
menu.findItem(R.id.magiskhide).setVisible(false);
menu.findItem(R.id.modules).setVisible(false);
menu.findItem(R.id.downloads).setVisible(false);
} else {
menu.findItem(R.id.modules).setVisible(true);
menu.findItem(R.id.downloads).setVisible(true);
menu.findItem(R.id.magiskhide).setVisible(
PreferenceManager.getDefaultSharedPreferences(this).getBoolean("magiskhide", false));
menu.findItem(R.id.magiskhide).setVisible(prefs.getBoolean("magiskhide", false));
}
}

View File

@ -31,6 +31,8 @@ public class SplashActivity extends AppCompatActivity {
.putBoolean("hosts", Utils.itemExist(false, "/magisk/.core/hosts"))
.apply();
// Start all async tasks
new Async.GetBootBlocks().exec();
new Async.CheckUpdates().exec();
Async.checkSafetyNet(getApplicationContext());
new Async.LoadModules() {
@ -38,12 +40,12 @@ public class SplashActivity extends AppCompatActivity {
protected void onPostExecute(Void v) {
super.onPostExecute(v);
new Async.LoadRepos(getApplicationContext()).exec();
// Start main activity
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
startActivity(intent);
finish();
}
}.exec();
// Start main activity
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
startActivity(intent);
finish();
}
}

View File

@ -62,6 +62,10 @@ public class StatusFragment extends Fragment implements CallbackHandler.EventLis
private AlertDialog.Builder builder;
static {
checkMagiskInfo();
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
@ -147,13 +151,10 @@ public class StatusFragment extends Fragment implements CallbackHandler.EventLis
CallbackHandler.unRegister(safetyNetDone, this);
}
private void updateUI() {
int image, color;
private static void checkMagiskInfo() {
List<String> ret = Shell.sh("getprop magisk.version");
if (ret.get(0).length() == 0) {
magiskVersion = -1;
magiskVersionText.setText(R.string.magisk_version_error);
} else {
try {
magiskVersionString = ret.get(0);
@ -162,6 +163,17 @@ public class StatusFragment extends Fragment implements CallbackHandler.EventLis
// Custom version don't need to receive updates
magiskVersion = Double.POSITIVE_INFINITY;
}
}
}
private void updateUI() {
int image, color;
checkMagiskInfo();
if (magiskVersion < 0) {
magiskVersionText.setText(R.string.magisk_version_error);
} else {
magiskVersionText.setText(getString(R.string.magisk_version, magiskVersionString));
}
@ -199,7 +211,7 @@ public class StatusFragment extends Fragment implements CallbackHandler.EventLis
} else if (remoteMagiskVersion > magiskVersion) {
color = colorInfo;
image = R.drawable.ic_update;
magiskUpdateText.setText(getString(R.string.magisk_update_available, String.valueOf(remoteMagiskVersion)));
magiskUpdateText.setText(getString(R.string.magisk_update_available, remoteMagiskVersion));
} else {
color = colorOK;
image = R.drawable.ic_check_circle;

View File

@ -12,6 +12,7 @@ import android.support.v7.app.AlertDialog;
import android.util.Log;
import android.widget.Toast;
import com.topjohnwu.magisk.InstallFragment;
import com.topjohnwu.magisk.ModulesFragment;
import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.ReposFragment;
@ -293,4 +294,20 @@ public class Async {
}
}
public static class GetBootBlocks extends RootTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... params) {
InstallFragment.blockList = Shell.su("ls /dev/block | grep mmc");
if (InstallFragment.bootBlock == null) {
InstallFragment.bootBlock = Utils.detectBootImage();
}
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
InstallFragment.blockDetectionDone.trigger();
}
}
}

View File

@ -138,10 +138,6 @@ public class Utils {
.replace("#", "").replace("@", "").replace("*", "");
}
public static List<String> getBlockList() {
return Shell.su("ls /dev/block | grep mmc");
}
public static String detectBootImage() {
String[] commands = {
"for PARTITION in kern-a KERN-A android_boot ANDROID_BOOT kernel KERNEL boot BOOT lnx LNX; do",

View File

@ -18,114 +18,125 @@
app:cardUseCompatPadding="true">
<TextView
android:id="@+id/install_info"
android:id="@+id/install_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:padding="15dp"
android:textStyle="bold"
android:text="Install Magisk Version: v10" />
android:textStyle="bold" />
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="@+id/bootimage_card"
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_width="350dp"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="6dp"
style="?attr/cardStyle"
app:cardUseCompatPadding="true">
android:maxWidth="400dp"
android:minWidth="400dp">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="15dp"
android:layout_marginBottom="15dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:paddingBottom="10dp"
android:text="Boot Image Location"
android:textStyle="bold" />
<android.support.v7.widget.CardView
android:id="@+id/bootimage_card"
android:layout_gravity="center"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="6dp"
style="?attr/cardStyle"
app:cardUseCompatPadding="true"
android:layout_width="match_parent">
<LinearLayout
android:orientation="horizontal"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:layout_marginTop="15dp"
android:layout_marginBottom="15dp">
<Spinner
android:layout_width="0dp"
android:layout_height="match_parent"
android:id="@+id/block_spinner"
android:layout_weight="1" />
<Button
android:text="Detect"
android:layout_width="wrap_content"
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/detect_bootimage"/>
android:layout_gravity="center"
android:gravity="center"
android:paddingBottom="10dp"
android:text="@string/boot_image_title"
android:textStyle="bold" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginEnd="15dp"
android:layout_marginStart="15dp">
<Spinner
android:layout_width="0dp"
android:layout_height="match_parent"
android:id="@+id/block_spinner"
android:layout_weight="1" />
<Button
android:text="@string/detect_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/detect_bootimage"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="@+id/install_option_card"
android:layout_gravity="center"
android:layout_width="350dp"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="6dp"
style="?attr/cardStyle"
app:cardUseCompatPadding="true">
<android.support.v7.widget.CardView
android:id="@+id/install_option_card"
android:layout_gravity="center"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="6dp"
style="?attr/cardStyle"
app:cardUseCompatPadding="true"
android:layout_width="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="15dp"
android:layout_marginBottom="15dp">
<TextView
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:paddingBottom="10dp"
android:text="Advanced Settings"
android:textStyle="bold" />
android:layout_height="match_parent"
android:layout_marginTop="15dp"
android:layout_marginBottom="15dp">
<CheckBox
android:text="Keep force encryption"
android:id="@+id/keep_force_enc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="25dp"
android:layout_marginStart="25dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:paddingBottom="10dp"
android:text="@string/advanced_settings_title"
android:textStyle="bold" />
<CheckBox
android:text="Keep dm-verity"
android:id="@+id/keep_verity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="25dp"
android:layout_marginStart="25dp" />
<CheckBox
android:text="@string/keep_force_encryption"
android:id="@+id/keep_force_enc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="25dp"
android:layout_marginStart="25dp" />
<CheckBox
android:text="@string/keep_dm_verity"
android:id="@+id/keep_verity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="25dp"
android:layout_marginStart="25dp" />
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
</LinearLayout>

View File

@ -13,7 +13,8 @@
<item
android:id="@+id/install"
android:icon="@drawable/magisk"
android:title="@string/install"/>
android:title="@string/install"
android:visible="false"/>
<item
android:id="@+id/modules"

View File

@ -13,8 +13,7 @@
<string name="magisk_version">Magisk v%1$s installiert</string>
<string name="magisk_version_error">Haben Sie Magisk installiert?</string>
<string name="app_update_available">Magisk Manager App v%1$s update!</string>
<string name="magisk_update_available">Magisk v%1$s update!</string>
<string name="magisk_update_available">Magisk v%1$.1f update!</string>
<string name="cannot_check_updates">Kann nicht auf Aktualisierungen prüfen</string>
<string name="up_to_date">Aktuellste Version von %1$s installiert</string>
@ -61,8 +60,6 @@
<string name="permissionNotGranted">Diese Funktion wird ohne erlaubnis auf den externen Speicher zu schreiben nicht funktionieren.</string>
<string name="no_root_access">Kein root Zugriff, Funktion eingeschränkt</string>
<string name="no_thanks">Nein Danke</string>
<string name="update_title">%1$s Aktualisierung!</string>
<string name="update_msg">Neue Version v%2$s von %1$s ist verfügbar!\nChangelog:\n%3$s</string>
<string name="repo_install_title">Installiere %1$s</string>
<string name="repo_install_msg">Wollen Sie %1$s installieren?</string>
<string name="download_install">Herunterladen und Installieren</string>

View File

@ -14,8 +14,7 @@
<string name="magisk_version">Instalado Magisk v%1$s</string>
<string name="magisk_version_error">¿Has instalado Magisk?</string>
<string name="app_update_available">¡Actualización aplicación Magisk Manager v%1$s!</string>
<string name="magisk_update_available">¡Actualización Magisk v%1$s!</string>
<string name="magisk_update_available">¡Actualización Magisk v%1$.1f!</string>
<string name="cannot_check_updates">No se pueden buscar actualizaciones</string>
<string name="up_to_date">Última versión de %1$s instalada</string>
@ -63,8 +62,6 @@
<string name="permissionNotGranted">Esta opción no funcionará sin permiso de escritura en la memoria externa</string>
<string name="no_root_access">No hay acceso a root, funcionalidad limitada</string>
<string name="no_thanks">No gracias</string>
<string name="update_title">¡Actualización de %1$s!</string>
<string name="update_msg">Disponible nueva versión v%2$s de %1$s!\nCambios:\n%3$s</string>
<string name="repo_install_title">Instalar %1$s</string>
<string name="repo_install_msg">¿ Quieres instalar %1$s ?</string>
<string name="download_install">Descargar e instalar</string>

View File

@ -13,8 +13,7 @@
<string name="magisk_version">Versione Magisk: v%1$s</string>
<string name="magisk_version_error">Hai installato Magisk?</string>
<string name="app_update_available">Magisk Manager App v%1$s update!</string>
<string name="magisk_update_available">Magisk v%1$s update!</string>
<string name="magisk_update_available">Magisk v%1$.1f update!</string>
<string name="cannot_check_updates">Impossibile controllare aggiornamenti</string>
<string name="up_to_date">L\'ultima versione di %1$s è installata</string>
@ -61,8 +60,6 @@
<string name="permissionNotGranted">Questa funzione non funziona senza il permesso di scrivere sulla memoria di archiviazione esterna</string>
<string name="no_root_access">Accesso Root non trovato, funzionalità limitate</string>
<string name="no_thanks">No grazie</string>
<string name="update_title">%1$s Update!</string>
<string name="update_msg">Nuova versione di v%2$s di %1$s è disponibile! \nChangelog:\n%3$s</string>
<string name="repo_install_title">Installazione %1$s</string>
<string name="repo_install_msg">Vuoi installare %1$s ?</string>
<string name="download_install">Scarica e installa</string>

View File

@ -13,8 +13,7 @@
<string name="magisk_version">Geïnstalleerde Magisk: v%1$s</string>
<string name="magisk_version_error">Heb jij Magisk wel geïnstalleerd?</string>
<string name="app_update_available">Magisk Manager App v%1$s update!</string>
<string name="magisk_update_available">Magisk v%1$s update!</string>
<string name="magisk_update_available">Magisk v%1$.1f update!</string>
<string name="cannot_check_updates">Kan niet controleren op updates.</string>
<string name="up_to_date">Nieuwste versie van %1$s geïnstalleerd</string>
@ -61,8 +60,6 @@
<string name="permissionNotGranted">Deze feature zal niet werken zonder permissie om op de externe opslag te schrijven.</string>
<string name="no_root_access">Geen root, functionaliteit beperkt</string>
<string name="no_thanks">Nee bedankt</string>
<string name="update_title">%1$s Update!</string>
<string name="update_msg">Nieuwe versie v%2$s van %1$s is beschikbaar!\nChangelog:\n%3$s</string>
<string name="repo_install_title">Installeer %1$s</string>
<string name="repo_install_msg">Wilt u %1$s installeren?</string>
<string name="download_install">Downloaden en installeren</string>

View File

@ -11,8 +11,7 @@
<string name="magisk_version">Magisk v%1$s Instalado</string>
<string name="magisk_version_error">Você instalou o Magisk?</string>
<string name="app_update_available">Atualização para Magisk Manager App v%1$s!</string>
<string name="magisk_update_available">Atualização para Magisk v%1$s!</string>
<string name="magisk_update_available">Atualização para Magisk v%1$.1f!</string>
<string name="cannot_check_updates">Não é possível verificar se há atualizações</string>
<string name="up_to_date">Última versão do %1$s instalado</string>
@ -59,8 +58,6 @@
<string name="permissionNotGranted">Este recurso não funcionará sem permissão de escrita do armazenamento externo.</string>
<string name="no_root_access">Sem acesso ao root, funcionalidade limitada</string>
<string name="no_thanks">Não, Obrigado</string>
<string name="update_title">%1$s Atualização!</string>
<string name="update_msg">Nova versão v%2$s de %1$s está disponível!\nChangelog:\n%3$s</string>
<string name="repo_install_title">Instalar %1$s</string>
<string name="repo_install_msg">Você deseja instalar%1$s ?</string>
<string name="download_install">Baixar e instalar</string>

View File

@ -19,7 +19,7 @@
<string name="magisk_version_error">Magisk not installed</string>
<string name="checking_for_updates">Checking for updates…</string>
<string name="magisk_update_available">Magisk v%1$s available!</string>
<string name="magisk_update_available">Magisk v%1$.1f available!</string>
<string name="cannot_check_updates">Cannot check for updates, no Internet?</string>
<string name="up_to_date">Latest version of %1$s installed</string>
<string name="root_error">Rooted but no root permission, not allowed?</string>
@ -118,4 +118,12 @@
<string name="settings_reboot_toast">Reboot to apply settings</string>
<string name="auto_detect">"(Auto Detect) %1$s"</string>
<string name="boot_image_title">Boot Image Location</string>
<string name="detect_button">Detect</string>
<string name="advanced_settings_title">Advanced Settings</string>
<string name="keep_force_encryption">Keep force encryption</string>
<string name="keep_dm_verity">Keep dm-verity</string>
<string name="install_magisk_title">Install Magisk Version: v%1$.1f</string>
</resources>