Update status UI

This commit is contained in:
topjohnwu
2017-05-19 08:37:57 -07:00
parent 55b8079e86
commit e69b99f089
10 changed files with 105 additions and 129 deletions

View File

@@ -32,7 +32,6 @@ import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import butterknife.BindView;
import butterknife.ButterKnife;

View File

@@ -13,7 +13,6 @@ import com.topjohnwu.magisk.module.Module;
import com.topjohnwu.magisk.module.Repo;
import com.topjohnwu.magisk.superuser.Policy;
import com.topjohnwu.magisk.utils.CallbackEvent;
import com.topjohnwu.magisk.utils.Logger;
import com.topjohnwu.magisk.utils.Shell;
import com.topjohnwu.magisk.utils.Utils;
import com.topjohnwu.magisk.utils.ValueSortedMap;

View File

@@ -12,7 +12,6 @@ import com.topjohnwu.magisk.asyncs.GetBootBlocks;
import com.topjohnwu.magisk.asyncs.LoadApps;
import com.topjohnwu.magisk.asyncs.LoadModules;
import com.topjohnwu.magisk.asyncs.LoadRepos;
import com.topjohnwu.magisk.asyncs.MagiskHide;
import com.topjohnwu.magisk.components.Activity;
import com.topjohnwu.magisk.services.UpdateCheckService;

View File

@@ -31,16 +31,15 @@ public class StatusFragment extends Fragment implements CallbackEvent.Listener<V
private Unbinder unbinder;
@BindView(R.id.swipeRefreshLayout) SwipeRefreshLayout mSwipeRefreshLayout;
@BindView(R.id.magisk_status_container) View magiskStatusContainer;
@BindView(R.id.magisk_status_icon) ImageView magiskStatusIcon;
@BindView(R.id.magisk_version) TextView magiskVersionText;
@BindView(R.id.magisk_update_icon) ImageView magiskUpdateIcon;
@BindView(R.id.magisk_update_status) TextView magiskUpdateText;
@BindView(R.id.magisk_check_updates_progress) ProgressBar magiskCheckUpdatesProgress;
@BindView(R.id.root_status_container) View rootStatusContainer;
@BindView(R.id.magisk_status_icon) ImageView magiskStatusIcon;
@BindView(R.id.magisk_version) TextView magiskVersionText;
@BindView(R.id.root_status_icon) ImageView rootStatusIcon;
@BindView(R.id.root_status) TextView rootStatusText;
@BindView(R.id.root_info) TextView rootInfoText;
@BindView(R.id.safetyNet_container) View safetyNetContainer;
@BindView(R.id.safetyNet_icon) ImageView safetyNetIcon;
@@ -60,32 +59,31 @@ public class StatusFragment extends Fragment implements CallbackEvent.Listener<V
safetyNetContainer.setBackgroundColor(trans);
safetyNetIcon.setImageResource(0);
safetyNetStatusText.setText(R.string.checking_safetyNet_status);
Utils.checkSafetyNet(getApplication());
Utils.checkSafetyNet(magiskManager);
}
@OnClick(R.id.magisk_status_container)
public void gotoInstall() {
if (getApplication().remoteMagiskVersionCode > 0) {
if (magiskManager.remoteMagiskVersionCode > 0) {
((MainActivity) getActivity()).navigate(R.id.install);
}
}
private int defaultColor;
private MagiskManager magiskManager;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_status, container, false);
unbinder = ButterKnife.bind(this, v);
magiskManager = getApplication();
defaultColor = magiskUpdateText.getCurrentTextColor();
mSwipeRefreshLayout.setOnRefreshListener(() -> {
magiskStatusContainer.setBackgroundColor(trans);
magiskStatusIcon.setImageResource(0);
magiskUpdateText.setText(R.string.checking_for_updates);
magiskCheckUpdatesProgress.setVisibility(View.VISIBLE);
magiskUpdateText.setTextColor(defaultColor);
magiskUpdateIcon.setVisibility(View.GONE);
safetyNetProgress.setVisibility(View.GONE);
safetyNetContainer.setBackgroundColor(colorNeutral);
@@ -93,14 +91,14 @@ public class StatusFragment extends Fragment implements CallbackEvent.Listener<V
safetyNetStatusText.setText(R.string.safetyNet_check_text);
safetyNetStatusText.setTextColor(defaultColor);
getApplication().safetyNetDone.isTriggered = false;
magiskManager.safetyNetDone.isTriggered = false;
noDialog = false;
updateUI();
new CheckUpdates(getActivity()).exec();
});
if (getApplication().magiskVersionCode < 0 && Shell.rootAccess() && !noDialog) {
if (magiskManager.magiskVersionCode < 0 && Shell.rootAccess() && !noDialog) {
noDialog = true;
new AlertDialogBuilder(getActivity())
.setTitle(R.string.no_magisk_title)
@@ -113,9 +111,9 @@ public class StatusFragment extends Fragment implements CallbackEvent.Listener<V
updateUI();
if (getApplication().updateCheckDone.isTriggered)
if (magiskManager.updateCheckDone.isTriggered)
updateCheckUI();
if (getApplication().safetyNetDone.isTriggered)
if (magiskManager.safetyNetDone.isTriggered)
updateSafetyNetUI();
return v;
@@ -123,10 +121,10 @@ public class StatusFragment extends Fragment implements CallbackEvent.Listener<V
@Override
public void onTrigger(CallbackEvent<Void> event) {
if (event == getApplication().updateCheckDone) {
if (event == magiskManager.updateCheckDone) {
Logger.dev("StatusFragment: Update Check UI refresh triggered");
updateCheckUI();
} else if (event == getApplication().safetyNetDone) {
} else if (event == magiskManager.safetyNetDone) {
Logger.dev("StatusFragment: SafetyNet UI refresh triggered");
updateSafetyNetUI();
}
@@ -135,15 +133,15 @@ public class StatusFragment extends Fragment implements CallbackEvent.Listener<V
@Override
public void onStart() {
super.onStart();
getApplication().updateCheckDone.register(this);
getApplication().safetyNetDone.register(this);
magiskManager.updateCheckDone.register(this);
magiskManager.safetyNetDone.register(this);
getActivity().setTitle(R.string.status);
}
@Override
public void onStop() {
getApplication().updateCheckDone.unRegister(this);
getApplication().safetyNetDone.unRegister(this);
magiskManager.updateCheckDone.unRegister(this);
magiskManager.safetyNetDone.unRegister(this);
super.onStop();
}
@@ -156,29 +154,32 @@ public class StatusFragment extends Fragment implements CallbackEvent.Listener<V
private void updateUI() {
int image, color;
getApplication().updateMagiskInfo();
magiskManager.updateMagiskInfo();
if (getApplication().magiskVersionCode < 0) {
if (magiskManager.magiskVersionCode < 0) {
color = colorBad;
image = R.drawable.ic_cancel;
magiskVersionText.setText(R.string.magisk_version_error);
} else if (getApplication().disabled) {
magiskVersionText.setText(getString(R.string.magisk_version_core_only, getApplication().magiskVersionString));
} else {
magiskVersionText.setText(getString(R.string.magisk_version, getApplication().magiskVersionString));
color = colorOK;
image = R.drawable.ic_check_circle;
magiskVersionText.setText(getString(R.string.current_magisk_title, "v" + magiskManager.magiskVersionString));
}
magiskStatusIcon.setImageResource(image);
magiskStatusIcon.setColorFilter(color);
switch (Shell.rootStatus) {
case 0:
color = colorBad;
image = R.drawable.ic_cancel;
rootStatusText.setText(R.string.not_rooted);
rootInfoText.setText(R.string.root_info_warning);
break;
case 1:
if (getApplication().suVersion != null) {
if (magiskManager.suVersion != null) {
color = colorOK;
image = R.drawable.ic_check_circle;
rootStatusText.setText(R.string.proper_root);
rootInfoText.setText(getApplication().suVersion);
rootStatusText.setText(magiskManager.suVersion);
break;
}
case -1:
@@ -186,40 +187,28 @@ public class StatusFragment extends Fragment implements CallbackEvent.Listener<V
color = colorNeutral;
image = R.drawable.ic_help;
rootStatusText.setText(R.string.root_error);
rootInfoText.setText(R.string.root_info_warning);
}
rootStatusContainer.setBackgroundColor(color);
rootStatusText.setTextColor(color);
rootInfoText.setTextColor(color);
rootStatusIcon.setImageResource(image);
rootStatusIcon.setColorFilter(color);
}
private void updateCheckUI() {
int image, color;
if (getApplication().remoteMagiskVersionCode < 0) {
if (magiskManager.remoteMagiskVersionCode < 0) {
color = colorNeutral;
image = R.drawable.ic_help;
magiskUpdateText.setText(R.string.cannot_check_updates);
} else if (getApplication().remoteMagiskVersionCode > getApplication().magiskVersionCode) {
color = colorInfo;
image = R.drawable.ic_update;
magiskUpdateText.setText(getString(R.string.magisk_update_available, getApplication().remoteMagiskVersionString));
} else {
color = colorOK;
image = R.drawable.ic_check_circle;
magiskUpdateText.setText(getString(R.string.up_to_date, getString(R.string.magisk)));
magiskUpdateText.setText(getString(R.string.install_magisk_title, "v" + magiskManager.remoteMagiskVersionString));
}
if (getApplication().magiskVersionCode < 0) {
color = colorBad;
image = R.drawable.ic_cancel;
}
magiskStatusContainer.setBackgroundColor(color);
magiskVersionText.setTextColor(color);
magiskUpdateText.setTextColor(color);
magiskStatusIcon.setImageResource(image);
magiskUpdateIcon.setImageResource(image);
magiskUpdateIcon.setColorFilter(color);
magiskUpdateIcon.setVisibility(View.VISIBLE);
magiskCheckUpdatesProgress.setVisibility(View.GONE);
mSwipeRefreshLayout.setRefreshing(false);
@@ -228,7 +217,7 @@ public class StatusFragment extends Fragment implements CallbackEvent.Listener<V
private void updateSafetyNetUI() {
int image, color;
safetyNetProgress.setVisibility(View.GONE);
switch (getApplication().SNCheckResult) {
switch (magiskManager.SNCheckResult) {
case -3:
color = colorNeutral;
image = R.drawable.ic_help;

View File

@@ -4,14 +4,9 @@ import android.app.Activity;
import android.app.ProgressDialog;
import android.net.Uri;
import com.topjohnwu.magisk.MagiskManager;
import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.utils.Logger;
import com.topjohnwu.magisk.utils.Shell;
import com.topjohnwu.magisk.utils.Utils;
import com.topjohnwu.magisk.utils.ZipUtils;
import java.io.File;
public class ProcessMagiskZip extends ParallelTask<Void, Void, Boolean> {