[app] Add reinstall (#1287)

This commit is contained in:
南宫雪珊 2021-10-17 03:27:34 +08:00 committed by GitHub
parent d35e421b2d
commit 24c468164e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 18 deletions

View File

@ -187,7 +187,7 @@ dependencies {
implementation("dev.rikka.rikkax.material:material:1.6.6")
implementation("dev.rikka.rikkax.preference:simplemenu-preference:1.0.3")
implementation("dev.rikka.rikkax.recyclerview:recyclerview-ktx:1.2.2")
implementation("dev.rikka.rikkax.widget:borderview:1.0.1")
implementation("dev.rikka.rikkax.widget:borderview:1.1.0")
implementation("dev.rikka.rikkax.widget:switchbar:1.0.2")
implementation("dev.rikka.rikkax.layoutinflater:layoutinflater:1.1.0")
implementation("me.zhanghai.android.appiconloader:appiconloader:1.3.1")

View File

@ -33,9 +33,11 @@ public class FlashDialogBuilder extends BlurBehindDialogBuilder {
private final TextView textView;
private final BorderNestedScrollView rootView;
public FlashDialogBuilder(@NonNull Context context, String zipPath, String notes) {
public FlashDialogBuilder(@NonNull Context context) {
super(context);
this.zipPath = zipPath;
var pref = App.getPreferences();
var notes = pref.getString("release_notes", "");
this.zipPath = pref.getString("zip_file", null);
setTitle(R.string.update_lsposed);
textView = new MaterialTextView(context);
@ -58,13 +60,9 @@ public class FlashDialogBuilder extends BlurBehindDialogBuilder {
public AlertDialog show() {
var dialog = super.show();
var button = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
button.setEnabled(false);
rootView.setOnScrollChangeListener((View.OnScrollChangeListener)
(v, scrollX, scrollY, oldScrollX, oldScrollY) -> button.setEnabled(
v.getScrollY() + v.getHeight() - v.getPaddingTop() - v.getPaddingBottom()
== rootView.getChildAt(0).getHeight()));
rootView.setBorderVisibilityChangedListener((t, ot, b, ob) -> button.setEnabled(!b));
button.setOnClickListener((v) -> {
rootView.setOnScrollChangeListener((View.OnScrollChangeListener) null);
rootView.setBorderVisibilityChangedListener(null);
setFlashView(v, dialog);
});
return dialog;

View File

@ -101,18 +101,20 @@ public class HomeFragment extends BaseFragment {
new InfoDialogBuilder(activity).show();
}
} else {
if (UpdateUtil.canUpdate()) {
var pref = App.getPreferences();
var zip = pref.getString("zip_file", null);
var notes = pref.getString("release_notes", "");
if (zip != null) {
new FlashDialogBuilder(activity, zip, notes).show();
return;
}
if (UpdateUtil.canInstall()) {
new FlashDialogBuilder(activity).show();
return;
}
NavUtil.startURL(activity, getString(R.string.about_source));
}
});
binding.status.setOnLongClickListener(v -> {
if (UpdateUtil.canInstall()) {
new FlashDialogBuilder(activity).show();
return true;
}
return false;
});
binding.modules.setOnClickListener(new StartFragmentListener(R.id.action_modules_fragment, true));
binding.download.setOnClickListener(new StartFragmentListener(R.id.action_repo_fragment, false));
binding.logs.setOnClickListener(new StartFragmentListener(R.id.action_logs_fragment, true));

View File

@ -110,9 +110,11 @@ public class UpdateUtil {
return zip;
}
public static boolean canUpdate() {
public static boolean canInstall() {
if (!ConfigManager.isBinderAlive()) return false;
var pref = App.getPreferences();
var zip = pref.getString("zip_file", null);
if (zip == null || !new File(zip).isFile()) return false;
var zipTime = pref.getLong("zip_time", BuildConfig.BUILD_TIME);
return zipTime > BuildConfig.BUILD_TIME;
}