From 51e0428968b9e7f5ab9aa33844180f9d0b6c7cb6 Mon Sep 17 00:00:00 2001 From: ZaneYork Date: Wed, 1 Apr 2020 10:06:43 +0800 Subject: [PATCH] 1.Bug fix --- app/build.gradle | 4 +-- .../download/DownloadableContentAdapter.java | 18 +++++----- .../ui/install/InstallFragment.java | 8 ++--- .../smapiinstaller/utils/DialogUtils.java | 34 +++++++++++++++---- 4 files changed, 41 insertions(+), 23 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index f4275e1..f9082a5 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -12,8 +12,8 @@ android { applicationId "com.zane.smapiinstaller" minSdkVersion 19 targetSdkVersion 28 - versionCode 29 - versionName "1.4.0" + versionCode 30 + versionName "1.4.1" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" multiDexEnabled true diff --git a/app/src/main/java/com/zane/smapiinstaller/ui/download/DownloadableContentAdapter.java b/app/src/main/java/com/zane/smapiinstaller/ui/download/DownloadableContentAdapter.java index d018ca0..a381615 100644 --- a/app/src/main/java/com/zane/smapiinstaller/ui/download/DownloadableContentAdapter.java +++ b/app/src/main/java/com/zane/smapiinstaller/ui/download/DownloadableContentAdapter.java @@ -1,11 +1,5 @@ package com.zane.smapiinstaller.ui.download; -import androidx.annotation.NonNull; -import androidx.recyclerview.widget.RecyclerView; -import butterknife.BindView; -import butterknife.ButterKnife; -import butterknife.OnClick; - import android.content.Context; import android.view.LayoutInflater; import android.view.View; @@ -37,6 +31,12 @@ import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; +import butterknife.BindView; +import butterknife.ButterKnife; +import butterknife.OnClick; + /** * {@link RecyclerView.Adapter} that can display a {@link DownloadableContent} * @author Zane @@ -162,8 +162,7 @@ public class DownloadableContentAdapter extends RecyclerView.Adapter response) { super.onError(response); - ProgressDialog dialog = dialogRef.get(); - dialog.dismiss(); + DialogUtils.dismissDialog(itemView, dialogRef.get()); downloading.set(false); DialogUtils.showAlertDialog(itemView, R.string.error, R.string.error_failed_to_download); } @@ -180,8 +179,7 @@ public class DownloadableContentAdapter extends RecyclerView.Adapter response) { - ProgressDialog dialog = dialogRef.get(); - dialog.dismiss(); + DialogUtils.dismissDialog(itemView, dialogRef.get()); downloading.set(false); File downloadedFile = response.body(); String hash = com.zane.smapiinstaller.utils.FileUtils.getFileHash(downloadedFile); diff --git a/app/src/main/java/com/zane/smapiinstaller/ui/install/InstallFragment.java b/app/src/main/java/com/zane/smapiinstaller/ui/install/InstallFragment.java index cd8179b..3527d6c 100644 --- a/app/src/main/java/com/zane/smapiinstaller/ui/install/InstallFragment.java +++ b/app/src/main/java/com/zane/smapiinstaller/ui/install/InstallFragment.java @@ -1,6 +1,6 @@ package com.zane.smapiinstaller.ui.install; -import android.content.Context; +import android.app.Activity; import android.os.Build; import android.os.Bundle; import android.view.LayoutInflater; @@ -32,7 +32,7 @@ import butterknife.OnClick; */ public class InstallFragment extends Fragment { - private Context context; + private Activity context; private Thread task; @@ -120,9 +120,7 @@ public class InstallFragment extends Fragment { Crashes.trackError(e); DialogUtils.showAlertDialog(root, R.string.error, e.getLocalizedMessage()); } finally { - if(dialog != null) { - dialog.dismiss(); - } + DialogUtils.dismissDialog(root, dialog); } }); task.start(); diff --git a/app/src/main/java/com/zane/smapiinstaller/utils/DialogUtils.java b/app/src/main/java/com/zane/smapiinstaller/utils/DialogUtils.java index 5268cbd..552dbef 100644 --- a/app/src/main/java/com/zane/smapiinstaller/utils/DialogUtils.java +++ b/app/src/main/java/com/zane/smapiinstaller/utils/DialogUtils.java @@ -173,13 +173,35 @@ public class DialogUtils { public static void dismissDialog(View view, MaterialDialog dialog) { Activity activity = CommonLogic.getActivityFromView(view); if (activity != null && !activity.isFinishing()) { - if (dialog != null && dialog.isShowing()) { - try { - dialog.dismiss(); - } catch (Exception e) { - Crashes.trackError(e); + activity.runOnUiThread(()->{ + if (dialog != null && dialog.isShowing()) { + try { + dialog.dismiss(); + } catch (Exception e) { + Crashes.trackError(e); + } } - } + }); + } + } + /** + * 解散指定对话框 + * + * @param view view + * @param dialog 对话框 + */ + public static void dismissDialog(View view, ProgressDialog dialog) { + Activity activity = CommonLogic.getActivityFromView(view); + if (activity != null && !activity.isFinishing()) { + activity.runOnUiThread(()->{ + if (dialog != null) { + try { + dialog.dismiss(); + } catch (Exception e) { + Crashes.trackError(e); + } + } + }); } }