migrate dialogs to viewbinding

This commit is contained in:
fatih ergin 2023-08-09 18:20:10 +03:00
parent 7e104d5910
commit 1ddf7ffc9b
7 changed files with 78 additions and 81 deletions

View file

@ -1,34 +1,33 @@
package com.simplemobiletools.filemanager.pro.dialogs
import android.view.View
import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.extensions.beVisibleIf
import com.simplemobiletools.commons.extensions.getAlertDialogBuilder
import com.simplemobiletools.commons.extensions.setupDialogStuff
import com.simplemobiletools.commons.helpers.*
import com.simplemobiletools.filemanager.pro.R
import com.simplemobiletools.filemanager.pro.databinding.DialogChangeSortingBinding
import com.simplemobiletools.filemanager.pro.extensions.config
import kotlinx.android.synthetic.main.dialog_change_sorting.view.*
class ChangeSortingDialog(val activity: BaseSimpleActivity, val path: String = "", val callback: () -> Unit) {
private var currSorting = 0
private var config = activity.config
private var view: View
private val binding: DialogChangeSortingBinding
init {
currSorting = config.getFolderSorting(path)
view = activity.layoutInflater.inflate(R.layout.dialog_change_sorting, null).apply {
sorting_dialog_use_for_this_folder.isChecked = config.hasCustomSorting(path)
binding = DialogChangeSortingBinding.inflate(activity.layoutInflater).apply {
sortingDialogUseForThisFolder.isChecked = config.hasCustomSorting(path)
sorting_dialog_numeric_sorting.beVisibleIf(currSorting and SORT_BY_NAME != 0)
sorting_dialog_numeric_sorting.isChecked = currSorting and SORT_USE_NUMERIC_VALUE != 0
sortingDialogNumericSorting.beVisibleIf(currSorting and SORT_BY_NAME != 0)
sortingDialogNumericSorting.isChecked = currSorting and SORT_USE_NUMERIC_VALUE != 0
}
activity.getAlertDialogBuilder()
.setPositiveButton(R.string.ok) { dialog, which -> dialogConfirmed() }
.setNegativeButton(R.string.cancel, null)
.apply {
activity.setupDialogStuff(view, this, R.string.sort_by)
activity.setupDialogStuff(binding.root, this, R.string.sort_by)
}
setupSortRadio()
@ -36,34 +35,33 @@ class ChangeSortingDialog(val activity: BaseSimpleActivity, val path: String = "
}
private fun setupSortRadio() {
val sortingRadio = view.sorting_dialog_radio_sorting
binding.apply {
sortingDialogRadioSorting.setOnCheckedChangeListener { group, checkedId ->
val isSortingByName = checkedId == sortingDialogRadioName.id
binding.sortingDialogNumericSorting.beVisibleIf(isSortingByName)
}
sortingRadio.setOnCheckedChangeListener { group, checkedId ->
val isSortingByName = checkedId == sortingRadio.sorting_dialog_radio_name.id
view.sorting_dialog_numeric_sorting.beVisibleIf(isSortingByName)
val sortBtn = when {
currSorting and SORT_BY_SIZE != 0 -> sortingDialogRadioSize
currSorting and SORT_BY_DATE_MODIFIED != 0 -> sortingDialogRadioLastModified
currSorting and SORT_BY_EXTENSION != 0 -> sortingDialogRadioExtension
else -> sortingDialogRadioName
}
sortBtn.isChecked = true
}
val sortBtn = when {
currSorting and SORT_BY_SIZE != 0 -> sortingRadio.sorting_dialog_radio_size
currSorting and SORT_BY_DATE_MODIFIED != 0 -> sortingRadio.sorting_dialog_radio_last_modified
currSorting and SORT_BY_EXTENSION != 0 -> sortingRadio.sorting_dialog_radio_extension
else -> sortingRadio.sorting_dialog_radio_name
}
sortBtn.isChecked = true
}
private fun setupOrderRadio() {
val orderRadio = view.sorting_dialog_radio_order
var orderBtn = orderRadio.sorting_dialog_radio_ascending
var orderBtn = binding.sortingDialogRadioAscending
if (currSorting and SORT_DESCENDING != 0) {
orderBtn = orderRadio.sorting_dialog_radio_descending
orderBtn = binding.sortingDialogRadioDescending
}
orderBtn.isChecked = true
}
private fun dialogConfirmed() {
val sortingRadio = view.sorting_dialog_radio_sorting
val sortingRadio = binding.sortingDialogRadioSorting
var sorting = when (sortingRadio.checkedRadioButtonId) {
R.id.sorting_dialog_radio_name -> SORT_BY_NAME
R.id.sorting_dialog_radio_size -> SORT_BY_SIZE
@ -71,15 +69,15 @@ class ChangeSortingDialog(val activity: BaseSimpleActivity, val path: String = "
else -> SORT_BY_EXTENSION
}
if (view.sorting_dialog_radio_order.checkedRadioButtonId == R.id.sorting_dialog_radio_descending) {
if (binding.sortingDialogRadioOrder.checkedRadioButtonId == R.id.sorting_dialog_radio_descending) {
sorting = sorting or SORT_DESCENDING
}
if (view.sorting_dialog_numeric_sorting.isChecked) {
if (binding.sortingDialogNumericSorting.isChecked) {
sorting = sorting or SORT_USE_NUMERIC_VALUE
}
if (view.sorting_dialog_use_for_this_folder.isChecked) {
if (binding.sortingDialogUseForThisFolder.isChecked) {
config.saveCustomSorting(path, sorting)
} else {
config.removeCustomSorting(path)

View file

@ -1,6 +1,5 @@
package com.simplemobiletools.filemanager.pro.dialogs
import android.view.View
import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.extensions.beGone
import com.simplemobiletools.commons.extensions.getAlertDialogBuilder
@ -8,29 +7,29 @@ import com.simplemobiletools.commons.extensions.setupDialogStuff
import com.simplemobiletools.commons.helpers.VIEW_TYPE_GRID
import com.simplemobiletools.commons.helpers.VIEW_TYPE_LIST
import com.simplemobiletools.filemanager.pro.R
import com.simplemobiletools.filemanager.pro.databinding.DialogChangeViewTypeBinding
import com.simplemobiletools.filemanager.pro.extensions.config
import kotlinx.android.synthetic.main.dialog_change_view_type.view.*
class ChangeViewTypeDialog(val activity: BaseSimpleActivity, val path: String = "", showFolderCheck: Boolean = true, val callback: () -> Unit) {
private var view: View
private var binding: DialogChangeViewTypeBinding
private var config = activity.config
init {
view = activity.layoutInflater.inflate(R.layout.dialog_change_view_type, null).apply {
binding = DialogChangeViewTypeBinding.inflate(activity.layoutInflater).apply {
val currViewType = config.getFolderViewType(this@ChangeViewTypeDialog.path)
val viewToCheck = if (currViewType == VIEW_TYPE_GRID) {
change_view_type_dialog_radio_grid.id
changeViewTypeDialogRadioGrid.id
} else {
change_view_type_dialog_radio_list.id
changeViewTypeDialogRadioList.id
}
change_view_type_dialog_radio.check(viewToCheck)
changeViewTypeDialogRadio.check(viewToCheck)
if (!showFolderCheck) {
use_for_this_folder_divider.beGone()
change_view_type_dialog_use_for_this_folder.beGone()
useForThisFolderDivider.beGone()
changeViewTypeDialogUseForThisFolder.beGone()
}
change_view_type_dialog_use_for_this_folder.apply {
changeViewTypeDialogUseForThisFolder.apply {
isChecked = config.hasCustomViewType(this@ChangeViewTypeDialog.path)
}
}
@ -39,18 +38,18 @@ class ChangeViewTypeDialog(val activity: BaseSimpleActivity, val path: String =
.setPositiveButton(R.string.ok) { dialog, which -> dialogConfirmed() }
.setNegativeButton(R.string.cancel, null)
.apply {
activity.setupDialogStuff(view, this)
activity.setupDialogStuff(binding.root, this)
}
}
private fun dialogConfirmed() {
val viewType = if (view.change_view_type_dialog_radio.checkedRadioButtonId == view.change_view_type_dialog_radio_grid.id) {
val viewType = if (binding.changeViewTypeDialogRadio.checkedRadioButtonId == binding.changeViewTypeDialogRadioGrid.id) {
VIEW_TYPE_GRID
} else {
VIEW_TYPE_LIST
}
if (view.change_view_type_dialog_use_for_this_folder.isChecked) {
if (binding.changeViewTypeDialogUseForThisFolder.isChecked) {
config.saveFolderViewType(this.path, viewType)
} else {
config.removeFolderViewType(this.path)

View file

@ -6,11 +6,11 @@ import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.dialogs.FilePickerDialog
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.filemanager.pro.R
import com.simplemobiletools.filemanager.pro.databinding.DialogCompressAsBinding
import com.simplemobiletools.filemanager.pro.extensions.config
import kotlinx.android.synthetic.main.dialog_compress_as.view.*
class CompressAsDialog(val activity: BaseSimpleActivity, val path: String, val callback: (destination: String, password: String?) -> Unit) {
private val view = activity.layoutInflater.inflate(R.layout.dialog_compress_as, null)
private val binding = DialogCompressAsBinding.inflate(activity.layoutInflater)
init {
val filename = path.getFilenameFromPath()
@ -18,8 +18,8 @@ class CompressAsDialog(val activity: BaseSimpleActivity, val path: String, val c
val baseFilename = filename.substring(0, indexOfDot)
var realPath = path.getParentPath()
view.apply {
filename_value.setText(baseFilename)
binding.apply {
filenameValue.setText(baseFilename)
folder.setText(activity.humanizePath(realPath))
folder.setOnClickListener {
@ -29,8 +29,8 @@ class CompressAsDialog(val activity: BaseSimpleActivity, val path: String, val c
}
}
password_protect.setOnCheckedChangeListener { _, _ ->
enter_password_hint.beVisibleIf(password_protect.isChecked)
passwordProtect.setOnCheckedChangeListener { _, _ ->
enterPasswordHint.beVisibleIf(passwordProtect.isChecked)
}
}
@ -38,13 +38,13 @@ class CompressAsDialog(val activity: BaseSimpleActivity, val path: String, val c
.setPositiveButton(R.string.ok, null)
.setNegativeButton(R.string.cancel, null)
.apply {
activity.setupDialogStuff(view, this, R.string.compress_as) { alertDialog ->
alertDialog.showKeyboard(view.filename_value)
activity.setupDialogStuff(binding.root, this, R.string.compress_as) { alertDialog ->
alertDialog.showKeyboard(binding.filenameValue)
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(View.OnClickListener {
val name = view.filename_value.value
val name = binding.filenameValue.value
var password: String? = null
if (view.password_protect.isChecked) {
password = view.password.value
if (binding.passwordProtect.isChecked) {
password = binding.password.value
if (password.isEmpty()) {
activity.toast(R.string.empty_password_new)
return@OnClickListener

View file

@ -6,23 +6,23 @@ import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.isRPlus
import com.simplemobiletools.filemanager.pro.R
import com.simplemobiletools.filemanager.pro.activities.SimpleActivity
import com.simplemobiletools.filemanager.pro.databinding.DialogCreateNewBinding
import com.simplemobiletools.filemanager.pro.helpers.RootHelpers
import kotlinx.android.synthetic.main.dialog_create_new.view.*
import java.io.File
import java.io.IOException
class CreateNewItemDialog(val activity: SimpleActivity, val path: String, val callback: (success: Boolean) -> Unit) {
private val view = activity.layoutInflater.inflate(R.layout.dialog_create_new, null)
private val binding = DialogCreateNewBinding.inflate(activity.layoutInflater)
init {
activity.getAlertDialogBuilder()
.setPositiveButton(R.string.ok, null)
.setNegativeButton(R.string.cancel, null)
.apply {
activity.setupDialogStuff(view, this, R.string.create_new) { alertDialog ->
alertDialog.showKeyboard(view.item_title)
activity.setupDialogStuff(binding.root, this, R.string.create_new) { alertDialog ->
alertDialog.showKeyboard(binding.itemTitle)
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(View.OnClickListener {
val name = view.item_title.value
val name = binding.itemTitle.value
if (name.isEmpty()) {
activity.toast(R.string.empty_name)
} else if (name.isAValidFilename()) {
@ -32,7 +32,7 @@ class CreateNewItemDialog(val activity: SimpleActivity, val path: String, val ca
return@OnClickListener
}
if (view.dialog_radio_group.checkedRadioButtonId == R.id.dialog_radio_directory) {
if (binding.dialogRadioGroup.checkedRadioButtonId == R.id.dialog_radio_directory) {
createDirectory(newPath, alertDialog) {
callback(it)
}

View file

@ -4,23 +4,23 @@ import androidx.appcompat.app.AlertDialog
import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.filemanager.pro.R
import kotlinx.android.synthetic.main.dialog_insert_filename.view.*
import com.simplemobiletools.filemanager.pro.databinding.DialogInsertFilenameBinding
class InsertFilenameDialog(
val activity: BaseSimpleActivity, var path: String, val callback: (filename: String) -> Unit
) {
init {
val view = activity.layoutInflater.inflate(R.layout.dialog_insert_filename, null)
val binding = DialogInsertFilenameBinding.inflate(activity.layoutInflater)
activity.getAlertDialogBuilder()
.setPositiveButton(R.string.ok, null)
.setNegativeButton(R.string.cancel, null)
.apply {
activity.setupDialogStuff(view, this, R.string.filename) { alertDialog ->
alertDialog.showKeyboard(view.insert_filename_title)
activity.setupDialogStuff(binding.root, this, R.string.filename) { alertDialog ->
alertDialog.showKeyboard(binding.insertFilenameTitle)
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
val filename = view.insert_filename_title.value
val extension = view.insert_filename_extension_title.value
val filename = binding.insertFilenameTitle.value
val extension = binding.insertFilenameExtensionTitle.value
if (filename.isEmpty()) {
activity.toast(R.string.filename_cannot_be_empty)

View file

@ -10,12 +10,12 @@ import com.simplemobiletools.commons.helpers.TAB_STORAGE_ANALYSIS
import com.simplemobiletools.commons.helpers.isOreoPlus
import com.simplemobiletools.commons.views.MyAppCompatCheckbox
import com.simplemobiletools.filemanager.pro.R
import com.simplemobiletools.filemanager.pro.databinding.DialogManageVisibleTabsBinding
import com.simplemobiletools.filemanager.pro.extensions.config
import com.simplemobiletools.filemanager.pro.helpers.ALL_TABS_MASK
import kotlinx.android.synthetic.main.dialog_manage_visible_tabs.view.*
class ManageVisibleTabsDialog(val activity: BaseSimpleActivity) {
private var view = activity.layoutInflater.inflate(R.layout.dialog_manage_visible_tabs, null)
private val binding = DialogManageVisibleTabsBinding.inflate(activity.layoutInflater)
private val tabs = LinkedHashMap<Int, Int>()
init {
@ -26,26 +26,26 @@ class ManageVisibleTabsDialog(val activity: BaseSimpleActivity) {
}
if (!isOreoPlus()) {
view.manage_visible_tabs_storage_analysis.beGone()
binding.manageVisibleTabsStorageAnalysis.beGone()
}
val showTabs = activity.config.showTabs
for ((key, value) in tabs) {
view.findViewById<MyAppCompatCheckbox>(value).isChecked = showTabs and key != 0
binding.root.findViewById<MyAppCompatCheckbox>(value).isChecked = showTabs and key != 0
}
activity.getAlertDialogBuilder()
.setPositiveButton(R.string.ok) { dialog, which -> dialogConfirmed() }
.setNegativeButton(R.string.cancel, null)
.apply {
activity.setupDialogStuff(view, this)
activity.setupDialogStuff(binding.root, this)
}
}
private fun dialogConfirmed() {
var result = 0
for ((key, value) in tabs) {
if (view.findViewById<MyAppCompatCheckbox>(value).isChecked) {
if (binding.root.findViewById<MyAppCompatCheckbox>(value).isChecked) {
result += key
}
}

View file

@ -6,7 +6,7 @@ import com.simplemobiletools.commons.dialogs.ConfirmationDialog
import com.simplemobiletools.commons.dialogs.FilePickerDialog
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.filemanager.pro.R
import kotlinx.android.synthetic.main.dialog_save_as.view.*
import com.simplemobiletools.filemanager.pro.databinding.DialogSaveAsBinding
class SaveAsDialog(
val activity: BaseSimpleActivity, var path: String, val hidePath: Boolean,
@ -19,8 +19,8 @@ class SaveAsDialog(
}
var realPath = path.getParentPath()
val view = activity.layoutInflater.inflate(R.layout.dialog_save_as, null).apply {
folder_value.setText(activity.humanizePath(realPath))
val binding = DialogSaveAsBinding.inflate(activity.layoutInflater).apply {
folderValue.setText(activity.humanizePath(realPath))
val fullName = path.getFilenameFromPath()
val dotAt = fullName.lastIndexOf(".")
@ -29,17 +29,17 @@ class SaveAsDialog(
if (dotAt > 0) {
name = fullName.substring(0, dotAt)
val extension = fullName.substring(dotAt + 1)
extension_value.setText(extension)
extensionValue.setText(extension)
}
filename_value.setText(name)
filenameValue.setText(name)
if (hidePath) {
folder_hint.beGone()
folderHint.beGone()
} else {
folder_value.setOnClickListener {
folderValue.setOnClickListener {
FilePickerDialog(activity, realPath, false, false, true, true, showFavoritesButton = true) {
folder_value.setText(activity.humanizePath(it))
folderValue.setText(activity.humanizePath(it))
realPath = it
}
}
@ -50,11 +50,11 @@ class SaveAsDialog(
.setPositiveButton(R.string.ok, null)
.setNegativeButton(R.string.cancel, null)
.apply {
activity.setupDialogStuff(view, this, R.string.save_as) { alertDialog ->
alertDialog.showKeyboard(view.filename_value)
activity.setupDialogStuff(binding.root, this, R.string.save_as) { alertDialog ->
alertDialog.showKeyboard(binding.filenameValue)
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
val filename = view.filename_value.value
val extension = view.extension_value.value
val filename = binding.filenameValue.value
val extension = binding.extensionValue.value
if (filename.isEmpty()) {
activity.toast(R.string.filename_cannot_be_empty)