diff options
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> |