Add a warning message in save progress dialog

This commit is contained in:
J-Jamet
2019-03-14 18:16:49 +01:00
parent e5902b9cf6
commit 1bfdae53c6
5 changed files with 36 additions and 6 deletions

View File

@@ -26,7 +26,7 @@ import com.kunzisoft.keepass.tasks.ActionRunnable
import com.kunzisoft.keepass.tasks.ProgressTaskDialogFragment
import com.kunzisoft.keepass.tasks.ProgressTaskUpdater
open class SaveDatabaseProgressDialogRunnable(var contextDatabase: FragmentActivity,
open class SaveDatabaseProgressDialogRunnable(private var contextDatabase: FragmentActivity,
database: Database,
private val actionRunnable: ((ProgressTaskUpdater)-> ActionRunnable)?,
save: Boolean):
@@ -36,7 +36,9 @@ open class SaveDatabaseProgressDialogRunnable(var contextDatabase: FragmentActiv
// Show the dialog
val progressTaskUpdater : ProgressTaskUpdater = ProgressTaskDialogFragment.start(
contextDatabase.supportFragmentManager,
R.string.saving_database)
R.string.saving_database,
null,
R.string.do_not_kill_app)
// Do the action if defined
actionRunnable?.invoke(progressTaskUpdater)?.run()

View File

@@ -40,9 +40,12 @@ open class ProgressTaskDialogFragment : DialogFragment(), ProgressTaskUpdater {
private var title = UNDEFINED
@StringRes
private var message = UNDEFINED
@StringRes
private var warning = UNDEFINED
private var titleView: TextView? = null
private var messageView: TextView? = null
private var warningView: TextView? = null
private var progressView: ProgressBar? = null
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
@@ -60,10 +63,12 @@ open class ProgressTaskDialogFragment : DialogFragment(), ProgressTaskUpdater {
titleView = root.findViewById(R.id.progress_dialog_title)
messageView = root.findViewById(R.id.progress_dialog_message)
warningView = root.findViewById(R.id.progress_dialog_warning)
progressView = root.findViewById(R.id.progress_dialog_bar)
updateTitle(title)
updateMessage(message)
updateWarning(warning)
isCancelable = false
Util.lockScreenOrientation(it)
@@ -91,16 +96,21 @@ open class ProgressTaskDialogFragment : DialogFragment(), ProgressTaskUpdater {
}
}
fun updateTitle(resId: Int) {
fun updateTitle(@StringRes resId: Int) {
this.title = resId
updateView(titleView, title)
}
override fun updateMessage(resId: Int) {
override fun updateMessage(@StringRes resId: Int) {
this.message = resId
updateView(messageView, message)
}
fun updateWarning(@StringRes resId: Int) {
this.warning = resId
updateView(warningView, warning)
}
companion object {
private const val PROGRESS_TASK_DIALOG_TAG = "progressDialogFragment"
@@ -109,13 +119,17 @@ open class ProgressTaskDialogFragment : DialogFragment(), ProgressTaskUpdater {
fun start(fragmentManager: FragmentManager,
@StringRes titleId: Int,
@StringRes messageId: Int? = null): ProgressTaskDialogFragment {
@StringRes messageId: Int? = null,
@StringRes warningId: Int? = null): ProgressTaskDialogFragment {
// Create an instance of the dialog fragment and show it
val dialog = ProgressTaskDialogFragment()
dialog.updateTitle(titleId)
messageId?.let {
dialog.updateMessage(it)
}
warningId?.let {
dialog.updateWarning(it)
}
dialog.show(fragmentManager, PROGRESS_TASK_DIALOG_TAG)
return dialog
}

View File

@@ -19,6 +19,8 @@
*/
package com.kunzisoft.keepass.tasks;
import android.support.annotation.StringRes;
public interface ProgressTaskUpdater {
void updateMessage(int resId);
void updateMessage(@StringRes int resId);
}

View File

@@ -26,6 +26,17 @@
android:layout_marginEnd="20dp"
style="@style/KeepassDXStyle.TextAppearance.SmallTitle"/>
<TextView
android:id="@+id/progress_dialog_warning"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
style="@style/KeepassDXStyle.TextAppearance.WarningTextStyle"/>
<ProgressBar
android:id="@+id/progress_dialog_bar"
style="?android:attr/progressBarStyleHorizontal"

View File

@@ -174,6 +174,7 @@
<string name="parallelism">Parallelism</string>
<string name="parallelism_explanation">Degree of parallelism (i.e. number of threads) used by the key derivation function.</string>
<string name="saving_database">Saving database…</string>
<string name="do_not_kill_app">Do not kill the app…</string>
<string name="space">Space</string>
<string name="search_label">Search</string>
<string name="sort_menu">Sort</string>