adding the dialog for inserting new clips

This commit is contained in:
tibbi
2022-01-27 22:43:48 +01:00
parent 8191ad7017
commit 565a149d6d
16 changed files with 112 additions and 18 deletions

View File

@ -0,0 +1,44 @@
package com.simplemobiletools.keyboard.dialogs
import androidx.appcompat.app.AlertDialog
import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.extensions.setupDialogStuff
import com.simplemobiletools.commons.extensions.showKeyboard
import com.simplemobiletools.commons.extensions.toast
import com.simplemobiletools.commons.extensions.value
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
import com.simplemobiletools.keyboard.R
import com.simplemobiletools.keyboard.extensions.clipsDB
import com.simplemobiletools.keyboard.models.Clip
import kotlinx.android.synthetic.main.dialog_add_clip.view.*
class AddClipDialog(val activity: BaseSimpleActivity, val callback: () -> Unit) {
init {
val view = activity.layoutInflater.inflate(R.layout.dialog_add_clip, null)
AlertDialog.Builder(activity)
.setPositiveButton(R.string.ok, null)
.setNegativeButton(R.string.cancel, null)
.create().apply {
activity.setupDialogStuff(view, this) {
showKeyboard(view.add_clip_value)
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
val clipValue = view.add_clip_value.value
if (clipValue.isEmpty()) {
activity.toast(R.string.value_cannot_be_empty)
return@setOnClickListener
}
val clip = Clip(null, clipValue)
ensureBackgroundThread {
activity.clipsDB.insertOrUpdate(clip)
activity.runOnUiThread {
callback()
dismiss()
}
}
}
}
}
}
}