Move deleteAll method from TransferRepository to an async thread, to avoid app crashes for doing db operations in the main thread.
This commit is contained in:
parent
d979d366cf
commit
3cbe738fd7
2 changed files with 11 additions and 2 deletions
|
@ -53,7 +53,7 @@ class TransfersLoader(private var mContext: Context?, private val mLifeCycle: Li
|
||||||
private val TAG = this.javaClass.name
|
private val TAG = this.javaClass.name
|
||||||
|
|
||||||
/** Constant that specifies if we are on debug mode */
|
/** 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 */
|
/* Constant used to fix the number of historical transfers to fetch from the network in one batch */
|
||||||
private val HISTORICAL_TRANSFER_BATCH_SIZE = 100
|
private val HISTORICAL_TRANSFER_BATCH_SIZE = 100
|
||||||
|
|
|
@ -25,7 +25,7 @@ class TransferRepository internal constructor(context: Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun deleteAll() {
|
fun deleteAll() {
|
||||||
mTransferDao.deleteAll()
|
deleteAllAsyncTask(mTransferDao).execute()
|
||||||
}
|
}
|
||||||
|
|
||||||
private class insertAllAsyncTask internal constructor(private val mAsyncTaskDao: TransferDao) :
|
private class insertAllAsyncTask internal constructor(private val mAsyncTaskDao: TransferDao) :
|
||||||
|
@ -36,4 +36,13 @@ class TransferRepository internal constructor(context: Context) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class deleteAllAsyncTask internal constructor(private val mAsyncTaskDao: TransferDao) :
|
||||||
|
AsyncTask<Void, Void, Void>() {
|
||||||
|
|
||||||
|
override fun doInBackground(vararg params: Void?): Void? {
|
||||||
|
mAsyncTaskDao.deleteAll()
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue