Use DatabaseTaskProvider to retrieve database from service

This commit is contained in:
J-Jamet
2021-08-09 17:00:34 +02:00
parent bcd5b024f0
commit 5721bca5a3
9 changed files with 142 additions and 79 deletions

View File

@@ -27,6 +27,7 @@ import android.os.Binder
import android.os.IBinder
import android.util.Log
import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.database.action.DatabaseTaskProvider
import com.kunzisoft.keepass.database.element.Attachment
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.model.AttachmentState
@@ -41,6 +42,9 @@ import java.util.concurrent.CopyOnWriteArrayList
class AttachmentFileNotificationService: LockNotificationService() {
private var mDatabaseTaskProvider: DatabaseTaskProvider? = null
private var mDatabase: Database? = null
override val notificationId: Int = 10000
private val attachmentNotificationList = CopyOnWriteArrayList<AttachmentNotification>()
@@ -80,6 +84,16 @@ class AttachmentFileNotificationService: LockNotificationService() {
}
}
override fun onCreate() {
super.onCreate()
mDatabaseTaskProvider = DatabaseTaskProvider(this)
mDatabaseTaskProvider?.registerProgressTask()
mDatabaseTaskProvider?.onDatabaseRetrieved = { database ->
this.mDatabase = database
}
}
interface ActionTaskListener {
fun onAttachmentAction(fileUri: Uri, entryAttachmentState: EntryAttachmentState)
}
@@ -247,6 +261,7 @@ class AttachmentFileNotificationService: LockNotificationService() {
notificationManager?.cancel(attachmentNotification.notificationId)
}
attachmentNotificationList.clear()
mDatabaseTaskProvider?.unregisterProgressTask()
super.onDestroy()
}
@@ -287,8 +302,7 @@ class AttachmentFileNotificationService: LockNotificationService() {
// Add action to the list on start
attachmentNotificationList.add(attachmentNotification)
// TODO Database
Database.getInstance()?.let { database ->
mDatabase?.let { database ->
mainScope.launch {
AttachmentFileAction(attachmentNotification,
database,