summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcos <cos>2024-07-05 17:27:44 +0200
committercos <cos>2024-10-12 17:29:20 +0200
commit7eab0b937578b9adcd63606629a6837dff5d7475 (patch)
tree8640c611e9bd6f46e27210d17461e1d25737c1dc
parente41536783edab8145e9882dfbf3647e93707c509 (diff)
downloadAntennaPod-fix/inform_on_db_moved.zip
Inform user about CorruptDatabaseBackup.dbfix/inform_on_db_moved
Prior to this commit, the user gets no feedback what-so-ever of what is going on when a corrupted database gets renamed. Which we should assume can be a quite horrifying experience. This adds a friendly message about what has happened, and suggests what to do. GitHub issue #6212, named "More useful error message for corrupted databases", might still be relevant for the "more useful" part. By reusing the design and making the dual-alternative of HomeFragment into instead one of three container views, the code changes stay small and complexity low. Easy to merge, and easy to revert once some code for a better implementation actually gets available. The date parsing, used when logging detection of a corrupt database, is copied verbatim from CrashReportWriter.java which presumably should make it reasonable enough.
-rw-r--r--app/src/main/java/de/danoeh/antennapod/ui/screen/home/HomeFragment.java28
-rw-r--r--app/src/main/res/layout/home_fragment.xml29
-rw-r--r--storage/database/src/main/java/de/danoeh/antennapod/storage/database/PodDBAdapter.java2
-rw-r--r--ui/i18n/src/main/res/values/strings.xml2
4 files changed, 60 insertions, 1 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/ui/screen/home/HomeFragment.java b/app/src/main/java/de/danoeh/antennapod/ui/screen/home/HomeFragment.java
index 0b6132ef0..cfd0082b4 100644
--- a/app/src/main/java/de/danoeh/antennapod/ui/screen/home/HomeFragment.java
+++ b/app/src/main/java/de/danoeh/antennapod/ui/screen/home/HomeFragment.java
@@ -44,8 +44,11 @@ import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
+import java.io.File;
+import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;
+import java.util.Locale;
/**
* Shows unread or recently published episodes
@@ -178,11 +181,34 @@ public class HomeFragment extends Fragment implements Toolbar.OnMenuItemClickLis
if (disposable != null) {
disposable.dispose();
}
+ boolean hasCorruptBackup = false;
+ try {
+ // These needs to correspond with where the database is move in:
+ // storage/database/src/main/java/de/danoeh/antennapod/storage/database/PodDBAdapter.java
+ File backupFolder = getContext().getExternalFilesDir(null);
+ File backupFile = new File(backupFolder, "CorruptedDatabaseBackup.db");
+ hasCorruptBackup = backupFile.exists();
+ if (hasCorruptBackup) {
+ Log.d(TAG, "There is a " + backupFile.getName() + " file, last modified: "
+ + new SimpleDateFormat("dd-MM-yyyy HH:mm:ss", Locale.getDefault())
+ .format(backupFile.lastModified()));
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ final boolean hasCorruptBackupFinal = hasCorruptBackup;
+
disposable = Observable.fromCallable(() -> DBReader.getTotalEpisodeCount(FeedItemFilter.unfiltered()))
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(numEpisodes -> {
- viewBinding.welcomeContainer.setVisibility(numEpisodes == 0 ? View.VISIBLE : View.GONE);
+ if (hasCorruptBackupFinal) {
+ viewBinding.welcomeContainer.setVisibility(View.GONE);
+ viewBinding.dbMovedContainer.setVisibility(numEpisodes == 0 ? View.VISIBLE : View.GONE);
+ } else {
+ viewBinding.welcomeContainer.setVisibility(numEpisodes == 0 ? View.VISIBLE : View.GONE);
+ viewBinding.dbMovedContainer.setVisibility(View.GONE);
+ }
viewBinding.homeContainer.setVisibility(numEpisodes == 0 ? View.GONE : View.VISIBLE);
viewBinding.swipeRefresh.setVisibility(numEpisodes == 0 ? View.GONE : View.VISIBLE);
if (numEpisodes == 0) {
diff --git a/app/src/main/res/layout/home_fragment.xml b/app/src/main/res/layout/home_fragment.xml
index 3ef602334..d0c80ed32 100644
--- a/app/src/main/res/layout/home_fragment.xml
+++ b/app/src/main/res/layout/home_fragment.xml
@@ -65,6 +65,35 @@
</LinearLayout>
+ <LinearLayout
+ android:id="@+id/dbMovedContainer"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical"
+ android:visibility="gone"
+ android:paddingHorizontal="32dp">
+
+ <TextView
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/home_dbmoved_title"
+ android:layout_marginBottom="8dp"
+ android:layout_gravity="center_horizontal"
+ android:textAlignment="center"
+ android:textColor="?android:attr/textColorPrimary"
+ android:textSize="20sp" />
+
+ <TextView
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/home_dbmoved_text"
+ android:layout_gravity="center_horizontal"
+ android:textAlignment="center"
+ android:textColor="?android:attr/textColorPrimary"
+ android:textSize="14sp" />
+
+ </LinearLayout>
+
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipeRefresh"
android:layout_width="match_parent"
diff --git a/storage/database/src/main/java/de/danoeh/antennapod/storage/database/PodDBAdapter.java b/storage/database/src/main/java/de/danoeh/antennapod/storage/database/PodDBAdapter.java
index 8f8d03927..641699d29 100644
--- a/storage/database/src/main/java/de/danoeh/antennapod/storage/database/PodDBAdapter.java
+++ b/storage/database/src/main/java/de/danoeh/antennapod/storage/database/PodDBAdapter.java
@@ -1473,6 +1473,8 @@ public class PodDBAdapter {
Log.e(TAG, "Database corrupted: " + db.getPath());
File dbPath = new File(db.getPath());
+ // These needs to correspond with where the user is notified, in:
+ // app/src/main/java/de/danoeh/antennapod/ui/screen/home/HomeFragment.java
File backupFolder = PodDBAdapter.context.getExternalFilesDir(null);
File backupFile = new File(backupFolder, "CorruptedDatabaseBackup.db");
try {
diff --git a/ui/i18n/src/main/res/values/strings.xml b/ui/i18n/src/main/res/values/strings.xml
index ae6b3b743..07e442629 100644
--- a/ui/i18n/src/main/res/values/strings.xml
+++ b/ui/i18n/src/main/res/values/strings.xml
@@ -67,6 +67,8 @@
<string name="home_downloads_empty_text">You can download any episode to listen to it offline.</string>
<string name="home_welcome_title">Welcome to AntennaPod!</string>
<string name="home_welcome_text">You are not subscribed to any podcasts yet. Open the side menu to add a podcast.</string>
+ <string name="home_dbmoved_title">Stay calm!</string>
+ <string name="home_dbmoved_text">AntennaPod encountered an error with the database and renamed it CorruptedDatabaseBackup.db. Visit https://antennapod.org/documentation/bugs-first-aid/database-error for instructions on ways to recover. https://forum.antennapod.org is open for support, or for venting that this bug bit you.</string>
<string name="notification_permission_text">AntennaPod needs your permission to show notifications. By default, AntennaPod only shows notifications while something is being downloaded or when something goes wrong.</string>
<string name="notification_permission_denied">You denied the permission.</string>
<string name="notification_permission_deny_warning">If you disable notifications and something goes wrong, you might be unable to find out why it went wrong.</string>