From 7eab0b937578b9adcd63606629a6837dff5d7475 Mon Sep 17 00:00:00 2001 From: cos Date: Fri, 5 Jul 2024 17:27:44 +0200 Subject: Inform user about CorruptDatabaseBackup.db 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. --- .../antennapod/ui/screen/home/HomeFragment.java | 28 ++++++++++++++++++++- app/src/main/res/layout/home_fragment.xml | 29 ++++++++++++++++++++++ .../antennapod/storage/database/PodDBAdapter.java | 2 ++ ui/i18n/src/main/res/values/strings.xml | 2 ++ 4 files changed, 60 insertions(+), 1 deletion(-) 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 @@ + + + + + + + + You can download any episode to listen to it offline. Welcome to AntennaPod! You are not subscribed to any podcasts yet. Open the side menu to add a podcast. + Stay calm! + 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. AntennaPod needs your permission to show notifications. By default, AntennaPod only shows notifications while something is being downloaded or when something goes wrong. You denied the permission. If you disable notifications and something goes wrong, you might be unable to find out why it went wrong. -- cgit v1.2.3