From cac34e678501bc87e711797c5231fd892864a994 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Mon, 15 Jul 2019 13:01:33 +0100 Subject: [PATCH] Import: verify activity is not null when finishing import. This is really just an ugly workaround for a crash. This whole thing needs to be redone. It's currently quite broken when it comes to lifecycle handling and a source for many issues. --- .../ui/importlocal/LocalCalendarImportFragment.kt | 9 ++++++++- .../ui/importlocal/LocalContactImportFragment.kt | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/etesync/syncadapter/ui/importlocal/LocalCalendarImportFragment.kt b/app/src/main/java/com/etesync/syncadapter/ui/importlocal/LocalCalendarImportFragment.kt index 5e55a51d..c740b8ea 100644 --- a/app/src/main/java/com/etesync/syncadapter/ui/importlocal/LocalCalendarImportFragment.kt +++ b/app/src/main/java/com/etesync/syncadapter/ui/importlocal/LocalCalendarImportFragment.kt @@ -18,6 +18,7 @@ import at.bitfire.ical4android.CalendarStorageException import com.etesync.syncadapter.Constants.KEY_ACCOUNT import com.etesync.syncadapter.Constants.KEY_COLLECTION_INFO import com.etesync.syncadapter.R +import com.etesync.syncadapter.log.Logger import com.etesync.syncadapter.model.CollectionInfo import com.etesync.syncadapter.resource.LocalCalendar import com.etesync.syncadapter.resource.LocalEvent @@ -190,7 +191,13 @@ class LocalCalendarImportFragment : ListFragment() { } override fun onPostExecute(result: ResultFragment.ImportResult) { - if (progressDialog.isShowing && !activity!!.isDestroyed) { + val activity = activity + if (activity == null) { + Logger.log.warning("Activity is null on import.") + return + } + + if (progressDialog.isShowing && !activity.isDestroyed) { progressDialog.dismiss() } (activity as ResultFragment.OnImportCallback).onImportResult(result) diff --git a/app/src/main/java/com/etesync/syncadapter/ui/importlocal/LocalContactImportFragment.kt b/app/src/main/java/com/etesync/syncadapter/ui/importlocal/LocalContactImportFragment.kt index 87876554..cfc6b540 100644 --- a/app/src/main/java/com/etesync/syncadapter/ui/importlocal/LocalContactImportFragment.kt +++ b/app/src/main/java/com/etesync/syncadapter/ui/importlocal/LocalContactImportFragment.kt @@ -24,6 +24,7 @@ import at.bitfire.vcard4android.ContactsStorageException import com.etesync.syncadapter.Constants.KEY_ACCOUNT import com.etesync.syncadapter.Constants.KEY_COLLECTION_INFO import com.etesync.syncadapter.R +import com.etesync.syncadapter.log.Logger import com.etesync.syncadapter.model.CollectionInfo import com.etesync.syncadapter.resource.LocalAddressBook import com.etesync.syncadapter.resource.LocalContact @@ -124,7 +125,13 @@ class LocalContactImportFragment : Fragment() { } override fun onPostExecute(result: ResultFragment.ImportResult) { - if (progressDialog.isShowing && !activity!!.isDestroyed) { + val activity = activity + if (activity == null) { + Logger.log.warning("Activity is null on import.") + return + } + + if (progressDialog.isShowing && !activity.isDestroyed) { progressDialog.dismiss() } (activity as ResultFragment.OnImportCallback).onImportResult(result)