mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Use DatabaseTaskProvider to retrieve database from service
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user