Fix unwanted opening of the dialog task #187

This commit is contained in:
J-Jamet
2020-05-17 14:19:52 +02:00
parent 45bcbb3a3d
commit d989f48226
2 changed files with 13 additions and 13 deletions

View File

@@ -93,11 +93,11 @@ class ProgressDialogThread(private val activity: FragmentActivity) {
TimeoutHelper.temporarilyDisableTimeout()
// Stop the opening notification
DatabaseOpenNotificationService.stop(activity)
startOrUpdateDialog(titleId, messageId, warningId)
startDialog(titleId, messageId, warningId)
}
override fun onUpdateAction(titleId: Int?, messageId: Int?, warningId: Int?) {
startOrUpdateDialog(titleId, messageId, warningId)
updateDialog(titleId, messageId, warningId)
}
override fun onStopAction(actionTask: String, result: ActionRunnable.Result) {
@@ -120,7 +120,9 @@ class ProgressDialogThread(private val activity: FragmentActivity) {
}
}
private fun startOrUpdateDialog(titleId: Int?, messageId: Int?, warningId: Int?) {
private fun startDialog(titleId: Int? = null,
messageId: Int? = null,
warningId: Int? = null) {
if (progressTaskDialogFragment == null) {
progressTaskDialogFragment = activity.supportFragmentManager
.findFragmentByTag(PROGRESS_TASK_DIALOG_TAG) as ProgressTaskDialogFragment?
@@ -129,6 +131,10 @@ class ProgressDialogThread(private val activity: FragmentActivity) {
progressTaskDialogFragment = ProgressTaskDialogFragment()
progressTaskDialogFragment?.show(activity.supportFragmentManager, PROGRESS_TASK_DIALOG_TAG)
}
updateDialog(titleId, messageId, warningId)
}
private fun updateDialog(titleId: Int?, messageId: Int?, warningId: Int?) {
progressTaskDialogFragment?.apply {
titleId?.let {
updateTitle(it)
@@ -192,8 +198,11 @@ class ProgressDialogThread(private val activity: FragmentActivity) {
DATABASE_START_TASK_ACTION -> {
// Bind to the service when is starting
bindService()
startDialog()
}
DATABASE_STOP_TASK_ACTION -> {
// Remove the progress task
stopDialog()
unBindService()
}
}

View File

@@ -39,7 +39,6 @@ import com.kunzisoft.keepass.tasks.ProgressTaskUpdater
import com.kunzisoft.keepass.utils.DATABASE_START_TASK_ACTION
import com.kunzisoft.keepass.utils.DATABASE_STOP_TASK_ACTION
import java.util.*
import java.util.concurrent.atomic.AtomicBoolean
import kotlin.collections.ArrayList
class DatabaseTaskNotificationService : NotificationService(), ProgressTaskUpdater {
@@ -61,8 +60,6 @@ class DatabaseTaskNotificationService : NotificationService(), ProgressTaskUpdat
fun addActionTaskListener(actionTaskListener: ActionTaskListener) {
mActionTaskListeners.add(actionTaskListener)
// To prevent task dialog to be unbound before the display
actionRunnableAsyncTask?.allowFinishTask?.set(true)
}
fun removeActionTaskListener(actionTaskListener: ActionTaskListener) {
@@ -78,7 +75,7 @@ class DatabaseTaskNotificationService : NotificationService(), ProgressTaskUpdat
fun checkAction() {
mActionTaskListeners.forEach { actionTaskListener ->
actionTaskListener.onUpdateAction(mTitleId, mMessageId, mWarningId)
actionTaskListener.onStartAction(mTitleId, mMessageId, mWarningId)
}
}
@@ -571,8 +568,6 @@ class DatabaseTaskNotificationService : NotificationService(), ProgressTaskUpdat
private val onPostExecute: (result: ActionRunnable.Result) -> Unit)
: AsyncTask<((ProgressTaskUpdater?) -> ActionRunnable), Void, ActionRunnable.Result>() {
var allowFinishTask = AtomicBoolean(false)
override fun onPreExecute() {
super.onPreExecute()
onPreExecute.invoke()
@@ -586,10 +581,6 @@ class DatabaseTaskNotificationService : NotificationService(), ProgressTaskUpdat
resultTask = result
}
}
// Additional wait if the dialog take time to show
while(!allowFinishTask.get()) {
Thread.sleep(250)
}
return resultTask
}