From 3cbe738fd79ec136d9e01e0614f515ed516a0577 Mon Sep 17 00:00:00 2001 From: Severiano Jaramillo Date: Wed, 28 Nov 2018 14:28:18 -0600 Subject: [PATCH] Move deleteAll method from TransferRepository to an async thread, to avoid app crashes for doing db operations in the main thread. --- .../processors/TransfersLoader.kt | 2 +- .../repositories/TransferRepository.kt | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/cy/agorise/bitsybitshareswallet/processors/TransfersLoader.kt b/app/src/main/java/cy/agorise/bitsybitshareswallet/processors/TransfersLoader.kt index 62f8d49..06deb79 100644 --- a/app/src/main/java/cy/agorise/bitsybitshareswallet/processors/TransfersLoader.kt +++ b/app/src/main/java/cy/agorise/bitsybitshareswallet/processors/TransfersLoader.kt @@ -53,7 +53,7 @@ class TransfersLoader(private var mContext: Context?, private val mLifeCycle: Li private val TAG = this.javaClass.name /** Constant that specifies if we are on debug mode */ - private val DEBUG = false + private val DEBUG = true /* Constant used to fix the number of historical transfers to fetch from the network in one batch */ private val HISTORICAL_TRANSFER_BATCH_SIZE = 100 diff --git a/app/src/main/java/cy/agorise/bitsybitshareswallet/repositories/TransferRepository.kt b/app/src/main/java/cy/agorise/bitsybitshareswallet/repositories/TransferRepository.kt index 7f7f2f1..821d754 100644 --- a/app/src/main/java/cy/agorise/bitsybitshareswallet/repositories/TransferRepository.kt +++ b/app/src/main/java/cy/agorise/bitsybitshareswallet/repositories/TransferRepository.kt @@ -25,7 +25,7 @@ class TransferRepository internal constructor(context: Context) { } fun deleteAll() { - mTransferDao.deleteAll() + deleteAllAsyncTask(mTransferDao).execute() } private class insertAllAsyncTask internal constructor(private val mAsyncTaskDao: TransferDao) : @@ -36,4 +36,13 @@ class TransferRepository internal constructor(context: Context) { return null } } + + private class deleteAllAsyncTask internal constructor(private val mAsyncTaskDao: TransferDao) : + AsyncTask() { + + override fun doInBackground(vararg params: Void?): Void? { + mAsyncTaskDao.deleteAll() + return null + } + } } \ No newline at end of file