From c3477a75d90c9510643d2fc9c042cf6a961ca610 Mon Sep 17 00:00:00 2001 From: Aleksey Chernov Date: Thu, 3 Sep 2020 23:33:47 +0400 Subject: [PATCH] Fixed a NullPointer exception in the code related to Google Drive sync. In Android 6.0, during an exit event when syncing (to Drive) starts, mReaderView is null. --- android/src/org/coolreader/CoolReader.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/android/src/org/coolreader/CoolReader.java b/android/src/org/coolreader/CoolReader.java index abd4409254..64b8d401f2 100644 --- a/android/src/org/coolreader/CoolReader.java +++ b/android/src/org/coolreader/CoolReader.java @@ -324,13 +324,13 @@ public void onSyncStarted(Synchronizer.SyncDirection direction) { @Override public void OnSyncProgress(Synchronizer.SyncDirection direction, int current, int total) { - runInReader(() -> { + log.v("sync progress: current=" + current + "; total=" + total); + if (null != mReaderView) { int total_ = total; - log.v("sync progress: current=" + current + "; total=" + total); if (current > total_) total_ = current; mReaderView.showCloudSyncProgress(10000 * current / total_); - }); + }; } @Override @@ -338,13 +338,15 @@ public void onSyncCompleted(Synchronizer.SyncDirection direction) { log.d("Google Drive SyncTo successfully completed"); showToast(R.string.googledrive_sync_completed); // Hide sync indicator - runInReader(() -> mReaderView.hideSyncProgress()); + if (null != mReaderView) + mReaderView.hideSyncProgress(); } @Override public void onSyncError(Synchronizer.SyncDirection direction, String errorString) { // Hide sync indicator - runInReader(() -> mReaderView.hideSyncProgress()); + if (null != mReaderView) + mReaderView.hideSyncProgress(); if (null != errorString) showToast(R.string.googledrive_sync_failed_with, errorString); else @@ -354,7 +356,8 @@ public void onSyncError(Synchronizer.SyncDirection direction, String errorString @Override public void onAborted(Synchronizer.SyncDirection direction) { // Hide sync indicator - runInReader(() -> mReaderView.hideSyncProgress()); + if (null != mReaderView) + mReaderView.hideSyncProgress(); showToast(R.string.googledrive_sync_aborted); }