Skip to content

Commit f9ad941

Browse files
committed
Filter broken prayer ids from bookmarks and reset the recents
when a new db is copied
1 parent a2c3c6f commit f9ad941

File tree

7 files changed

+27
-17
lines changed

7 files changed

+27
-17
lines changed

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ android {
99
minSdkVersion 19
1010
targetSdkVersion 30
1111
versionCode 18
12-
versionName '2.1.0'
12+
versionName '2.1.1'
1313
vectorDrawables.useSupportLibrary = true
1414
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1515
}

app/proguard-rules.pro

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,3 @@
1616
# public *;
1717
#}
1818
-keepattributes *Annotation*
19-
-keepclassmembers class ** {
20-
@com.squareup.otto.Subscribe public *;
21-
@com.squareup.otto.Produce public *;
22-
}
23-
24-
-keepclassmembers class android.support.design.internal.BottomNavigationMenuView {
25-
boolean mShiftingMode;
26-
}

app/src/main/java/com/arashpayan/prayerbook/App.java

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import android.os.Looper;
66
import android.webkit.WebSettings;
77

8+
import com.arashpayan.prayerbook.database.Prayer;
89
import com.arashpayan.prayerbook.database.PrayersDB;
910
import com.arashpayan.prayerbook.database.UserDB;
1011
import com.arashpayan.prayerbook.thread.UiRunnable;
@@ -17,10 +18,12 @@
1718
import java.io.FileOutputStream;
1819
import java.io.IOException;
1920
import java.io.OutputStream;
21+
import java.util.ArrayList;
2022
import java.util.concurrent.ExecutorService;
2123
import java.util.concurrent.Executors;
2224

2325
import androidx.annotation.AnyThread;
26+
import androidx.annotation.NonNull;
2427
import androidx.appcompat.app.AppCompatDelegate;
2528

2629
public class App extends Application {
@@ -29,20 +32,22 @@ public class App extends Application {
2932
private ExecutorService mExecutor;
3033

3134
private static volatile App app;
32-
private static final int LatestDatabaseVersion = 20;
35+
private static final int LatestDatabaseVersion = 21;
3336

3437
@Override
3538
public void onCreate() {
3639
app = this;
3740
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
3841
super.onCreate();
3942

40-
Prefs.init(this);
41-
copyDatabaseFile();
42-
UserDB.set(new UserDB(this, false));
4343
mMainThreadHandler = new Handler(Looper.getMainLooper());
4444
mExecutor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
4545

46+
Prefs.init(this);
47+
UserDB.set(new UserDB(this, false));
48+
UserDB.get().addBookmark(44);
49+
copyDatabaseFile();
50+
4651
// Load as much of the webview libraries as much as possible in the background
4752
// https://groups.google.com/a/chromium.org/d/msg/android-webview-dev/hjn1h7dBlH8/Iv0j08O6AQAJ
4853
runInBackground(new WorkerRunnable() {
@@ -72,12 +77,25 @@ private void copyDatabaseFile() {
7277
is.close();
7378
os.close();
7479
Prefs.get().setDatabaseVersion(LatestDatabaseVersion);
80+
filterBrokenPrayerIds(PrayersDB.get(), UserDB.get());
7581
} catch (IOException ex) {
7682
L.w("Error writing prayer database", ex);
7783
}
7884
}
7985
}
8086

87+
private void filterBrokenPrayerIds(@NonNull PrayersDB db, UserDB userDB) {
88+
ArrayList<Long> bookmarks = userDB.getBookmarks();
89+
for (Long id : bookmarks) {
90+
Prayer prayer = db.getPrayer(id);
91+
if (prayer == null) {
92+
userDB.deleteBookmark(id);
93+
}
94+
}
95+
96+
userDB.clearRecents();
97+
}
98+
8199
@AnyThread
82100
public static void runOnUiThread(UiRunnable r) {
83101
app.mMainThreadHandler.post(r);

app/src/main/java/com/arashpayan/prayerbook/CategoriesFragment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public void run() {
6868
}
6969

7070
@Override
71-
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
71+
public void onCreateOptionsMenu(@NonNull Menu menu, MenuInflater inflater) {
7272
inflater.inflate(R.menu.categories, menu);
7373
}
7474

app/src/main/java/com/arashpayan/prayerbook/PrayerFragment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public void run() {
9999
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
100100
requireActivity().getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
101101

102-
mWebView = new WebView(this.getActivity());
102+
mWebView = new WebView(requireContext());
103103
mWebView.getSettings().setSupportZoom(true);
104104
mWebView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
105105
mWebView.setKeepScreenOn(true);

app/src/main/java/com/arashpayan/prayerbook/database/PrayersDB.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,15 +160,15 @@ public Cursor getPrayersWithKeywords(String []keywords, Language[] languages) {
160160
}
161161

162162
@WorkerThread
163-
@NonNull
163+
@Nullable
164164
public Prayer getPrayer(long prayerId) {
165165
String[] cols = {PRAYERTEXT_COLUMN, AUTHOR_COLUMN, CITATION_COLUMN, SEARCHTEXT_COLUMN, LANGUAGE_COLUMN};
166166
String selectionClause = ID_COLUMN + "=?";
167167
String[] selectionArgs = {Long.valueOf(prayerId).toString()};
168168

169169
try (Cursor c = pbDatabase.query(PRAYERS_TABLE, cols, selectionClause, selectionArgs, null, null, null)) {
170170
if (!c.moveToFirst()) {
171-
throw new RuntimeException("Invalid prayer id: " + prayerId);
171+
return null;
172172
}
173173

174174
Prayer p = new Prayer();

0 commit comments

Comments
 (0)