migrate dialogs to viewbinding
This commit is contained in:
parent
1972063ca6
commit
dccded4d72
|
@ -5,15 +5,15 @@ import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
|||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||
import com.simplemobiletools.keyboard.R
|
||||
import com.simplemobiletools.keyboard.databinding.DialogAddOrEditClipBinding
|
||||
import com.simplemobiletools.keyboard.helpers.ClipsHelper
|
||||
import com.simplemobiletools.keyboard.models.Clip
|
||||
import kotlinx.android.synthetic.main.dialog_add_or_edit_clip.view.*
|
||||
|
||||
class AddOrEditClipDialog(val activity: BaseSimpleActivity, val originalClip: Clip?, val callback: () -> Unit) {
|
||||
init {
|
||||
val view = activity.layoutInflater.inflate(R.layout.dialog_add_or_edit_clip, null).apply {
|
||||
val binding = DialogAddOrEditClipBinding.inflate(activity.layoutInflater).apply {
|
||||
if (originalClip != null) {
|
||||
add_clip_value.setText(originalClip.value)
|
||||
addClipValue.setText(originalClip.value)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,10 +21,10 @@ class AddOrEditClipDialog(val activity: BaseSimpleActivity, val originalClip: Cl
|
|||
.setPositiveButton(R.string.ok, null)
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.apply {
|
||||
activity.setupDialogStuff(view, this) { alertDialog ->
|
||||
alertDialog.showKeyboard(view.add_clip_value)
|
||||
activity.setupDialogStuff(binding.root, this) { alertDialog ->
|
||||
alertDialog.showKeyboard(binding.addClipValue)
|
||||
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
|
||||
val clipValue = view.add_clip_value.value
|
||||
val clipValue = binding.addClipValue.value
|
||||
if (clipValue.isEmpty()) {
|
||||
activity.toast(R.string.value_cannot_be_empty)
|
||||
return@setOnClickListener
|
||||
|
|
|
@ -6,8 +6,8 @@ import com.simplemobiletools.commons.dialogs.ConfirmationDialog
|
|||
import com.simplemobiletools.commons.dialogs.FilePickerDialog
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.keyboard.R
|
||||
import com.simplemobiletools.keyboard.databinding.DialogExportClipsBinding
|
||||
import com.simplemobiletools.keyboard.extensions.config
|
||||
import kotlinx.android.synthetic.main.dialog_export_clips.view.*
|
||||
|
||||
class ExportClipsDialog(
|
||||
val activity: BaseSimpleActivity, path: String, val hidePath: Boolean, callback: (path: String, filename: String) -> Unit
|
||||
|
@ -19,17 +19,17 @@ class ExportClipsDialog(
|
|||
activity.internalStoragePath
|
||||
}
|
||||
|
||||
val view = activity.layoutInflater.inflate(R.layout.dialog_export_clips, null).apply {
|
||||
export_clips_filename.setText("${activity.getString(R.string.app_launcher_name)}_${activity.getCurrentFormattedDateTime()}")
|
||||
val binding = DialogExportClipsBinding.inflate(activity.layoutInflater).apply {
|
||||
exportClipsFilename.setText("${activity.getString(R.string.app_launcher_name)}_${activity.getCurrentFormattedDateTime()}")
|
||||
|
||||
if (hidePath) {
|
||||
export_clips_path_label.beGone()
|
||||
export_clips_path.beGone()
|
||||
exportClipsPathLabel.beGone()
|
||||
exportClipsPath.beGone()
|
||||
} else {
|
||||
export_clips_path.text = activity.humanizePath(folder)
|
||||
export_clips_path.setOnClickListener {
|
||||
exportClipsPath.text = activity.humanizePath(folder)
|
||||
exportClipsPath.setOnClickListener {
|
||||
FilePickerDialog(activity, folder, false, showFAB = true) {
|
||||
export_clips_path.text = activity.humanizePath(it)
|
||||
exportClipsPath.text = activity.humanizePath(it)
|
||||
folder = it
|
||||
}
|
||||
}
|
||||
|
@ -40,10 +40,10 @@ class ExportClipsDialog(
|
|||
.setPositiveButton(R.string.ok, null)
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.apply {
|
||||
activity.setupDialogStuff(view, this, R.string.export_clipboard_items) { alertDialog ->
|
||||
alertDialog.showKeyboard(view.export_clips_filename)
|
||||
activity.setupDialogStuff(binding.root, this, R.string.export_clipboard_items) { alertDialog ->
|
||||
alertDialog.showKeyboard(binding.exportClipsFilename)
|
||||
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
|
||||
val filename = view.export_clips_filename.value
|
||||
val filename = binding.exportClipsFilename.value
|
||||
if (filename.isEmpty()) {
|
||||
activity.toast(R.string.filename_cannot_be_empty)
|
||||
return@setOnClickListener
|
||||
|
|
|
@ -6,8 +6,8 @@ import android.view.View
|
|||
import android.view.ViewGroup
|
||||
import android.widget.RadioButton
|
||||
import android.widget.RadioGroup
|
||||
import android.widget.ScrollView
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import com.simplemobiletools.commons.databinding.DialogRadioGroupBinding
|
||||
import com.simplemobiletools.commons.extensions.onGlobalLayout
|
||||
import com.simplemobiletools.commons.models.RadioItem
|
||||
import com.simplemobiletools.keyboard.R
|
||||
|
@ -31,8 +31,8 @@ class KeyboardRadioGroupDialog(
|
|||
private val layoutInflater = LayoutInflater.from(context)
|
||||
|
||||
init {
|
||||
val view = layoutInflater.inflate(R.layout.dialog_radio_group, null)
|
||||
val radioGroup = view.findViewById<RadioGroup>(R.id.dialog_radio_group).apply {
|
||||
val binding = DialogRadioGroupBinding.inflate(layoutInflater)
|
||||
binding.dialogRadioGroup.apply {
|
||||
for (i in 0 until items.size) {
|
||||
val radioButton = (layoutInflater.inflate(R.layout.radio_button, null) as RadioButton).apply {
|
||||
text = items[i].title
|
||||
|
@ -57,15 +57,15 @@ class KeyboardRadioGroupDialog(
|
|||
}
|
||||
|
||||
builder.apply {
|
||||
context.setupKeyboardDialogStuff(inputView.windowToken, view, this, titleId) { alertDialog ->
|
||||
context.setupKeyboardDialogStuff(inputView.windowToken, binding.root, this, titleId) { alertDialog ->
|
||||
dialog = alertDialog
|
||||
}
|
||||
}
|
||||
|
||||
if (selectedItemId != -1) {
|
||||
view.findViewById<ScrollView>(R.id.dialog_radio_holder).apply {
|
||||
binding.dialogRadioHolder.apply {
|
||||
onGlobalLayout {
|
||||
scrollY = radioGroup.findViewById<View>(selectedItemId).bottom - height
|
||||
scrollY = binding.dialogRadioGroup.findViewById<View>(selectedItemId).bottom - height
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue