Fix clipboard notification timeout

This commit is contained in:
J-Jamet
2019-10-28 12:20:22 +01:00
parent 5a6c466ebd
commit 14020ec0b5
5 changed files with 7 additions and 29 deletions

View File

@@ -35,11 +35,9 @@ import java.util.*
class ClipboardEntryNotificationService : LockNotificationService() {
override var notificationId = 485
private var cleanNotificationTimerTask: Thread? = null
private var notificationTimeoutMilliSecs: Long = 0
override val notificationId = 485
private var clipboardHelper: ClipboardHelper? = null
private var notificationTimeoutMilliSecs: Long = 0
private var cleanCopyNotificationTimerTask: Thread? = null
override fun onCreate() {
@@ -131,29 +129,11 @@ class ClipboardEntryNotificationService : LockNotificationService() {
getCopyPendingIntent(fieldToAdd, fieldsToAdd))
}
}
notificationManager?.cancel(notificationId)
notificationManager?.notify(++notificationId, builder.build())
val myNotificationId = notificationId
stopTask(cleanNotificationTimerTask)
// If timer
if (notificationTimeoutMilliSecs != NEVER) {
cleanNotificationTimerTask = Thread {
try {
Thread.sleep(notificationTimeoutMilliSecs)
} catch (e: InterruptedException) {
cleanNotificationTimerTask = null
}
notificationManager?.cancel(myNotificationId)
}
cleanNotificationTimerTask?.start()
}
notificationManager?.notify(notificationId, builder.build())
}
private fun copyField(fieldToCopy: ClipboardEntryNotificationField, nextFields: ArrayList<ClipboardEntryNotificationField>) {
stopTask(cleanCopyNotificationTimerTask)
stopTask(cleanNotificationTimerTask)
try {
clipboardHelper?.copyToClipboard(fieldToCopy.label, fieldToCopy.value)
@@ -231,9 +211,7 @@ class ClipboardEntryNotificationService : LockNotificationService() {
override fun onDestroy() {
stopTask(cleanCopyNotificationTimerTask)
stopTask(cleanNotificationTimerTask)
cleanCopyNotificationTimerTask = null
cleanNotificationTimerTask = null
super.onDestroy()
}

View File

@@ -10,7 +10,7 @@ import com.kunzisoft.keepass.utils.LOCK_ACTION
class DatabaseOpenNotificationService: LockNotificationService() {
override var notificationId: Int = 340
override val notificationId: Int = 340
private fun stopNotificationAndSendLock() {
// Send lock action

View File

@@ -26,7 +26,7 @@ import kotlin.collections.ArrayList
class DatabaseTaskNotificationService : NotificationService(), ProgressTaskUpdater {
override var notificationId: Int = 575
override val notificationId: Int = 575
private var actionRunnableAsyncTask: ActionRunnableAsyncTask? = null

View File

@@ -14,7 +14,7 @@ import com.kunzisoft.keepass.utils.LOCK_ACTION
class KeyboardEntryNotificationService : LockNotificationService() {
override var notificationId = 486
override val notificationId = 486
private var cleanNotificationTimerTask: Thread? = null
private var notificationTimeoutMilliSecs: Long = 0

View File

@@ -18,7 +18,7 @@ abstract class NotificationService : Service() {
protected var notificationManager: NotificationManagerCompat? = null
private var colorNotificationAccent: Int = 0
protected abstract var notificationId: Int
protected abstract val notificationId: Int
override fun onBind(intent: Intent): IBinder? {
return null