mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Listener for task dialog
This commit is contained in:
@@ -120,6 +120,12 @@ class ProgressDialogThread(private val activity: FragmentActivity) {
|
||||
}
|
||||
}
|
||||
|
||||
private var progressDisplayListener = object: ProgressTaskDialogFragment.DisplayListener {
|
||||
override fun onDisplayDialog() {
|
||||
mBinder?.allowFinishTask()
|
||||
}
|
||||
}
|
||||
|
||||
private fun startOrUpdateDialog(titleId: Int?, messageId: Int?, warningId: Int?) {
|
||||
if (progressTaskDialogFragment == null) {
|
||||
progressTaskDialogFragment = activity.supportFragmentManager
|
||||
@@ -127,6 +133,7 @@ class ProgressDialogThread(private val activity: FragmentActivity) {
|
||||
}
|
||||
if (progressTaskDialogFragment == null) {
|
||||
progressTaskDialogFragment = ProgressTaskDialogFragment()
|
||||
progressTaskDialogFragment?.displayListener = progressDisplayListener
|
||||
progressTaskDialogFragment?.show(activity.supportFragmentManager, PROGRESS_TASK_DIALOG_TAG)
|
||||
}
|
||||
progressTaskDialogFragment?.apply {
|
||||
@@ -143,6 +150,7 @@ class ProgressDialogThread(private val activity: FragmentActivity) {
|
||||
}
|
||||
|
||||
private fun stopDialog() {
|
||||
progressTaskDialogFragment?.displayListener = null
|
||||
progressTaskDialogFragment?.dismissAllowingStateLoss()
|
||||
progressTaskDialogFragment = null
|
||||
}
|
||||
|
||||
@@ -59,8 +59,12 @@ class DatabaseTaskNotificationService : NotificationService(), ProgressTaskUpdat
|
||||
|
||||
fun getService(): DatabaseTaskNotificationService = this@DatabaseTaskNotificationService
|
||||
|
||||
fun addActionTaskListener(actionTaskListener: ActionTaskListener) {
|
||||
fun allowFinishTask() {
|
||||
// To prevent task dialog to be unbound before the display
|
||||
actionRunnableAsyncTask?.allowFinishTask?.set(true)
|
||||
}
|
||||
|
||||
fun addActionTaskListener(actionTaskListener: ActionTaskListener) {
|
||||
mActionTaskListeners.add(actionTaskListener)
|
||||
}
|
||||
|
||||
@@ -178,8 +182,6 @@ class DatabaseTaskNotificationService : NotificationService(), ProgressTaskUpdat
|
||||
stopSelf()
|
||||
}
|
||||
)
|
||||
// To keep the task active until a binder is connected
|
||||
actionRunnableAsyncTask?.allowFinishTask?.set(mActionTaskListeners.size >= 1)
|
||||
actionRunnableAsyncTask?.execute({ actionRunnableNotNull })
|
||||
}
|
||||
|
||||
@@ -587,8 +589,6 @@ class DatabaseTaskNotificationService : NotificationService(), ProgressTaskUpdat
|
||||
resultTask = result
|
||||
}
|
||||
}
|
||||
// Min wait to show the dialog
|
||||
Thread.sleep(200)
|
||||
// Additional wait if the dialog take time to show (device with low memory)
|
||||
while(!allowFinishTask.get()) {
|
||||
Thread.sleep(100)
|
||||
|
||||
@@ -44,6 +44,8 @@ open class ProgressTaskDialogFragment : DialogFragment(), ProgressTaskUpdater {
|
||||
private var warningView: TextView? = null
|
||||
private var progressView: ProgressBar? = null
|
||||
|
||||
var displayListener: DisplayListener? = null
|
||||
|
||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||
|
||||
activity?.let {
|
||||
@@ -73,6 +75,11 @@ open class ProgressTaskDialogFragment : DialogFragment(), ProgressTaskUpdater {
|
||||
return super.onCreateDialog(savedInstanceState)
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
displayListener?.onDisplayDialog()
|
||||
}
|
||||
|
||||
fun setTitle(@StringRes titleId: Int) {
|
||||
this.title = titleId
|
||||
}
|
||||
@@ -103,6 +110,10 @@ open class ProgressTaskDialogFragment : DialogFragment(), ProgressTaskUpdater {
|
||||
updateView(warningView, warning)
|
||||
}
|
||||
|
||||
interface DisplayListener {
|
||||
fun onDisplayDialog()
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
const val PROGRESS_TASK_DIALOG_TAG = "progressDialogFragment"
|
||||
|
||||
@@ -119,7 +119,7 @@ fun Context.closeDatabase() {
|
||||
// Stop the notification service
|
||||
stopService(Intent(this, ClipboardEntryNotificationService::class.java))
|
||||
|
||||
Log.i(Context::class.java.name, "Shutdown after inactivity or manual lock")
|
||||
Log.i(Context::class.java.name, "Close database after inactivity or manual lock")
|
||||
(getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager?)?.apply {
|
||||
cancelAll()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user