From 6a0d161815dfb0fc60606b98c4dd990ff2a9e74a Mon Sep 17 00:00:00 2001 From: Georgi Mirchev Date: Sat, 8 Jun 2019 07:58:43 +0300 Subject: [PATCH] Fix bugs that occur the most on Fabric --- .../mediaoverlay/MediaController.java | 2 + .../folioreader/model/sqlite/DbAdapter.java | 45 ------------------- .../folioreader/ui/activity/FolioActivity.kt | 4 +- .../ui/fragment/FolioPageFragment.kt | 8 ++-- 4 files changed, 10 insertions(+), 49 deletions(-) diff --git a/folioreader/src/main/java/com/folioreader/mediaoverlay/MediaController.java b/folioreader/src/main/java/com/folioreader/mediaoverlay/MediaController.java index be9d2ee90..8fddb2499 100644 --- a/folioreader/src/main/java/com/folioreader/mediaoverlay/MediaController.java +++ b/folioreader/src/main/java/com/folioreader/mediaoverlay/MediaController.java @@ -107,6 +107,8 @@ public void onInit(int status) { if (status != TextToSpeech.ERROR) { mTextToSpeech.setLanguage(Locale.UK); mTextToSpeech.setSpeechRate(0.70f); + } else { + return; } mTextToSpeech.setOnUtteranceCompletedListener( diff --git a/folioreader/src/main/java/com/folioreader/model/sqlite/DbAdapter.java b/folioreader/src/main/java/com/folioreader/model/sqlite/DbAdapter.java index 869541dd9..dd7f5fdac 100644 --- a/folioreader/src/main/java/com/folioreader/model/sqlite/DbAdapter.java +++ b/folioreader/src/main/java/com/folioreader/model/sqlite/DbAdapter.java @@ -19,59 +19,14 @@ public static void terminate() { FolioDatabaseHelper.clearInstance(); } - public static boolean insert(String table, ContentValues contentValues) { - - return mDatabase.insert(table, null, contentValues) > 0; - } - - public static boolean update(String table, String key, String value, ContentValues contentValues) { - - return mDatabase.update(table, contentValues, key + "=?", new String[]{value}) > 0; - } - public static Cursor getHighLightsForBookId(String bookId) { return mDatabase.rawQuery("SELECT * FROM " + HighLightTable.TABLE_NAME + " WHERE " + HighLightTable.COL_BOOK_ID + " = \"" + bookId + "\"", null); } - public boolean deleteAll(String table) { - return mDatabase.delete(table, null, null) > 0; - } - - public boolean deleteAll(String table, String whereClause, String[] whereArgs) { - return mDatabase.delete(table, whereClause + "=?", whereArgs) > 0; - } - - public Cursor getAll(String table, String[] projection, String selection, - String[] selectionArgs, String orderBy) { - return mDatabase.query(table, projection, selection, selectionArgs, null, null, orderBy); - } - - public Cursor getAll(String table) { - return getAll(table, null, null, null, null); - } - - public Cursor get(String table, long id, String[] projection, String key) throws SQLException { - return mDatabase.query(table, projection, - key + "=?", new String[]{String.valueOf(id)}, null, null, null, null); - } - - public static Cursor getAllByKey(String table, String[] projection, String key, String value) throws SQLException { - return mDatabase.query(table, projection, - key + "=?", new String[]{value}, null, null, null, null); - } - - public Cursor get(String table, long id) throws SQLException { - return get(table, id, null, FolioDatabaseHelper.KEY_ID); - } - public static boolean deleteById(String table, String key, String value) { return mDatabase.delete(table, key + "=?", new String[]{value}) > 0; } - public Cursor getMaxId(String tableName, String key) { - return mDatabase.rawQuery("SELECT MAX(" + key + ") FROM " + tableName, null); - } - public static long saveHighLight(ContentValues highlightContentValues) { return mDatabase.insert(HighLightTable.TABLE_NAME, null, highlightContentValues); } diff --git a/folioreader/src/main/java/com/folioreader/ui/activity/FolioActivity.kt b/folioreader/src/main/java/com/folioreader/ui/activity/FolioActivity.kt index 8df26fbe8..a01ba0889 100644 --- a/folioreader/src/main/java/com/folioreader/ui/activity/FolioActivity.kt +++ b/folioreader/src/main/java/com/folioreader/ui/activity/FolioActivity.kt @@ -54,6 +54,7 @@ import com.folioreader.model.HighlightImpl import com.folioreader.model.event.MediaOverlayPlayPauseEvent import com.folioreader.model.locators.ReadLocator import com.folioreader.model.locators.SearchLocator +import com.folioreader.model.sqlite.DbAdapter import com.folioreader.ui.adapter.FolioPageFragmentAdapter import com.folioreader.ui.adapter.SearchAdapter import com.folioreader.ui.fragment.FolioPageFragment @@ -244,6 +245,7 @@ class FolioActivity : AppCompatActivity(), FolioActivityCallback, MediaControlle // Need to add when vector drawables support library is used. AppCompatDelegate.setCompatVectorFromResourcesEnabled(true) + DbAdapter.initialize(this) handler = Handler() val display = windowManager.defaultDisplay @@ -1060,4 +1062,4 @@ class FolioActivity : AppCompatActivity(), FolioActivityCallback, MediaControlle } } } -} \ No newline at end of file +} diff --git a/folioreader/src/main/java/com/folioreader/ui/fragment/FolioPageFragment.kt b/folioreader/src/main/java/com/folioreader/ui/fragment/FolioPageFragment.kt index 801f0e6a1..90a16a673 100644 --- a/folioreader/src/main/java/com/folioreader/ui/fragment/FolioPageFragment.kt +++ b/folioreader/src/main/java/com/folioreader/ui/fragment/FolioPageFragment.kt @@ -472,8 +472,10 @@ class FolioPageFragment : Fragment(), if (readLocator != null) { val cfi = readLocator.locations.cfi - Log.v(LOG_TAG, "-> onPageFinished -> readLocator -> " + cfi!!) - mWebview!!.loadUrl(String.format(getString(R.string.callScrollToCfi), cfi)) + cfi?.let { + Log.v(LOG_TAG, "-> onPageFinished -> readLocator -> $cfi") + mWebview!!.loadUrl(String.format(getString(R.string.callScrollToCfi), cfi)) + } } else { loadingView!!.hide() } @@ -839,7 +841,7 @@ class FolioPageFragment : Fragment(), if (outState != null) outState!!.putSerializable(BUNDLE_READ_LOCATOR_CONFIG_CHANGE, lastReadLocator) if (activity != null && !activity!!.isFinishing) - mActivityCallback!!.storeLastReadLocator(lastReadLocator) + mActivityCallback?.storeLastReadLocator(lastReadLocator) } if (mWebview != null) mWebview!!.destroy() }