migrate dialogs to viewbinding

This commit is contained in:
fatih ergin 2023-08-17 00:22:58 +03:00
parent 1972063ca6
commit dccded4d72
3 changed files with 23 additions and 23 deletions

View File

@ -5,15 +5,15 @@ import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.ensureBackgroundThread import com.simplemobiletools.commons.helpers.ensureBackgroundThread
import com.simplemobiletools.keyboard.R import com.simplemobiletools.keyboard.R
import com.simplemobiletools.keyboard.databinding.DialogAddOrEditClipBinding
import com.simplemobiletools.keyboard.helpers.ClipsHelper import com.simplemobiletools.keyboard.helpers.ClipsHelper
import com.simplemobiletools.keyboard.models.Clip 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) { class AddOrEditClipDialog(val activity: BaseSimpleActivity, val originalClip: Clip?, val callback: () -> Unit) {
init { 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) { 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) .setPositiveButton(R.string.ok, null)
.setNegativeButton(R.string.cancel, null) .setNegativeButton(R.string.cancel, null)
.apply { .apply {
activity.setupDialogStuff(view, this) { alertDialog -> activity.setupDialogStuff(binding.root, this) { alertDialog ->
alertDialog.showKeyboard(view.add_clip_value) alertDialog.showKeyboard(binding.addClipValue)
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener { alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
val clipValue = view.add_clip_value.value val clipValue = binding.addClipValue.value
if (clipValue.isEmpty()) { if (clipValue.isEmpty()) {
activity.toast(R.string.value_cannot_be_empty) activity.toast(R.string.value_cannot_be_empty)
return@setOnClickListener return@setOnClickListener

View File

@ -6,8 +6,8 @@ import com.simplemobiletools.commons.dialogs.ConfirmationDialog
import com.simplemobiletools.commons.dialogs.FilePickerDialog import com.simplemobiletools.commons.dialogs.FilePickerDialog
import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.keyboard.R import com.simplemobiletools.keyboard.R
import com.simplemobiletools.keyboard.databinding.DialogExportClipsBinding
import com.simplemobiletools.keyboard.extensions.config import com.simplemobiletools.keyboard.extensions.config
import kotlinx.android.synthetic.main.dialog_export_clips.view.*
class ExportClipsDialog( class ExportClipsDialog(
val activity: BaseSimpleActivity, path: String, val hidePath: Boolean, callback: (path: String, filename: String) -> Unit val activity: BaseSimpleActivity, path: String, val hidePath: Boolean, callback: (path: String, filename: String) -> Unit
@ -19,17 +19,17 @@ class ExportClipsDialog(
activity.internalStoragePath activity.internalStoragePath
} }
val view = activity.layoutInflater.inflate(R.layout.dialog_export_clips, null).apply { val binding = DialogExportClipsBinding.inflate(activity.layoutInflater).apply {
export_clips_filename.setText("${activity.getString(R.string.app_launcher_name)}_${activity.getCurrentFormattedDateTime()}") exportClipsFilename.setText("${activity.getString(R.string.app_launcher_name)}_${activity.getCurrentFormattedDateTime()}")
if (hidePath) { if (hidePath) {
export_clips_path_label.beGone() exportClipsPathLabel.beGone()
export_clips_path.beGone() exportClipsPath.beGone()
} else { } else {
export_clips_path.text = activity.humanizePath(folder) exportClipsPath.text = activity.humanizePath(folder)
export_clips_path.setOnClickListener { exportClipsPath.setOnClickListener {
FilePickerDialog(activity, folder, false, showFAB = true) { FilePickerDialog(activity, folder, false, showFAB = true) {
export_clips_path.text = activity.humanizePath(it) exportClipsPath.text = activity.humanizePath(it)
folder = it folder = it
} }
} }
@ -40,10 +40,10 @@ class ExportClipsDialog(
.setPositiveButton(R.string.ok, null) .setPositiveButton(R.string.ok, null)
.setNegativeButton(R.string.cancel, null) .setNegativeButton(R.string.cancel, null)
.apply { .apply {
activity.setupDialogStuff(view, this, R.string.export_clipboard_items) { alertDialog -> activity.setupDialogStuff(binding.root, this, R.string.export_clipboard_items) { alertDialog ->
alertDialog.showKeyboard(view.export_clips_filename) alertDialog.showKeyboard(binding.exportClipsFilename)
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener { alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
val filename = view.export_clips_filename.value val filename = binding.exportClipsFilename.value
if (filename.isEmpty()) { if (filename.isEmpty()) {
activity.toast(R.string.filename_cannot_be_empty) activity.toast(R.string.filename_cannot_be_empty)
return@setOnClickListener return@setOnClickListener

View File

@ -6,8 +6,8 @@ import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.RadioButton import android.widget.RadioButton
import android.widget.RadioGroup import android.widget.RadioGroup
import android.widget.ScrollView
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import com.simplemobiletools.commons.databinding.DialogRadioGroupBinding
import com.simplemobiletools.commons.extensions.onGlobalLayout import com.simplemobiletools.commons.extensions.onGlobalLayout
import com.simplemobiletools.commons.models.RadioItem import com.simplemobiletools.commons.models.RadioItem
import com.simplemobiletools.keyboard.R import com.simplemobiletools.keyboard.R
@ -31,8 +31,8 @@ class KeyboardRadioGroupDialog(
private val layoutInflater = LayoutInflater.from(context) private val layoutInflater = LayoutInflater.from(context)
init { init {
val view = layoutInflater.inflate(R.layout.dialog_radio_group, null) val binding = DialogRadioGroupBinding.inflate(layoutInflater)
val radioGroup = view.findViewById<RadioGroup>(R.id.dialog_radio_group).apply { binding.dialogRadioGroup.apply {
for (i in 0 until items.size) { for (i in 0 until items.size) {
val radioButton = (layoutInflater.inflate(R.layout.radio_button, null) as RadioButton).apply { val radioButton = (layoutInflater.inflate(R.layout.radio_button, null) as RadioButton).apply {
text = items[i].title text = items[i].title
@ -57,15 +57,15 @@ class KeyboardRadioGroupDialog(
} }
builder.apply { builder.apply {
context.setupKeyboardDialogStuff(inputView.windowToken, view, this, titleId) { alertDialog -> context.setupKeyboardDialogStuff(inputView.windowToken, binding.root, this, titleId) { alertDialog ->
dialog = alertDialog dialog = alertDialog
} }
} }
if (selectedItemId != -1) { if (selectedItemId != -1) {
view.findViewById<ScrollView>(R.id.dialog_radio_holder).apply { binding.dialogRadioHolder.apply {
onGlobalLayout { onGlobalLayout {
scrollY = radioGroup.findViewById<View>(selectedItemId).bottom - height scrollY = binding.dialogRadioGroup.findViewById<View>(selectedItemId).bottom - height
} }
} }
} }