Skip to content

Commit 1ddf7ff

Browse files
committed
migrate dialogs to viewbinding
1 parent 7e104d5 commit 1ddf7ff

7 files changed

Lines changed: 78 additions & 81 deletions

File tree

app/src/main/kotlin/com/simplemobiletools/filemanager/pro/dialogs/ChangeSortingDialog.kt

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,83 @@
11
package com.simplemobiletools.filemanager.pro.dialogs
22

3-
import android.view.View
43
import com.simplemobiletools.commons.activities.BaseSimpleActivity
54
import com.simplemobiletools.commons.extensions.beVisibleIf
65
import com.simplemobiletools.commons.extensions.getAlertDialogBuilder
76
import com.simplemobiletools.commons.extensions.setupDialogStuff
87
import com.simplemobiletools.commons.helpers.*
98
import com.simplemobiletools.filemanager.pro.R
9+
import com.simplemobiletools.filemanager.pro.databinding.DialogChangeSortingBinding
1010
import com.simplemobiletools.filemanager.pro.extensions.config
11-
import kotlinx.android.synthetic.main.dialog_change_sorting.view.*
1211

1312
class ChangeSortingDialog(val activity: BaseSimpleActivity, val path: String = "", val callback: () -> Unit) {
1413
private var currSorting = 0
1514
private var config = activity.config
16-
private var view: View
15+
private val binding: DialogChangeSortingBinding
1716

1817
init {
1918
currSorting = config.getFolderSorting(path)
20-
view = activity.layoutInflater.inflate(R.layout.dialog_change_sorting, null).apply {
21-
sorting_dialog_use_for_this_folder.isChecked = config.hasCustomSorting(path)
19+
binding = DialogChangeSortingBinding.inflate(activity.layoutInflater).apply {
20+
sortingDialogUseForThisFolder.isChecked = config.hasCustomSorting(path)
2221

23-
sorting_dialog_numeric_sorting.beVisibleIf(currSorting and SORT_BY_NAME != 0)
24-
sorting_dialog_numeric_sorting.isChecked = currSorting and SORT_USE_NUMERIC_VALUE != 0
22+
sortingDialogNumericSorting.beVisibleIf(currSorting and SORT_BY_NAME != 0)
23+
sortingDialogNumericSorting.isChecked = currSorting and SORT_USE_NUMERIC_VALUE != 0
2524
}
2625

2726
activity.getAlertDialogBuilder()
2827
.setPositiveButton(R.string.ok) { dialog, which -> dialogConfirmed() }
2928
.setNegativeButton(R.string.cancel, null)
3029
.apply {
31-
activity.setupDialogStuff(view, this, R.string.sort_by)
30+
activity.setupDialogStuff(binding.root, this, R.string.sort_by)
3231
}
3332

3433
setupSortRadio()
3534
setupOrderRadio()
3635
}
3736

3837
private fun setupSortRadio() {
39-
val sortingRadio = view.sorting_dialog_radio_sorting
40-
41-
sortingRadio.setOnCheckedChangeListener { group, checkedId ->
42-
val isSortingByName = checkedId == sortingRadio.sorting_dialog_radio_name.id
43-
view.sorting_dialog_numeric_sorting.beVisibleIf(isSortingByName)
44-
}
38+
binding.apply {
39+
sortingDialogRadioSorting.setOnCheckedChangeListener { group, checkedId ->
40+
val isSortingByName = checkedId == sortingDialogRadioName.id
41+
binding.sortingDialogNumericSorting.beVisibleIf(isSortingByName)
42+
}
4543

46-
val sortBtn = when {
47-
currSorting and SORT_BY_SIZE != 0 -> sortingRadio.sorting_dialog_radio_size
48-
currSorting and SORT_BY_DATE_MODIFIED != 0 -> sortingRadio.sorting_dialog_radio_last_modified
49-
currSorting and SORT_BY_EXTENSION != 0 -> sortingRadio.sorting_dialog_radio_extension
50-
else -> sortingRadio.sorting_dialog_radio_name
44+
val sortBtn = when {
45+
currSorting and SORT_BY_SIZE != 0 -> sortingDialogRadioSize
46+
currSorting and SORT_BY_DATE_MODIFIED != 0 -> sortingDialogRadioLastModified
47+
currSorting and SORT_BY_EXTENSION != 0 -> sortingDialogRadioExtension
48+
else -> sortingDialogRadioName
49+
}
50+
sortBtn.isChecked = true
5151
}
52-
sortBtn.isChecked = true
5352
}
5453

5554
private fun setupOrderRadio() {
56-
val orderRadio = view.sorting_dialog_radio_order
57-
var orderBtn = orderRadio.sorting_dialog_radio_ascending
55+
var orderBtn = binding.sortingDialogRadioAscending
5856

5957
if (currSorting and SORT_DESCENDING != 0) {
60-
orderBtn = orderRadio.sorting_dialog_radio_descending
58+
orderBtn = binding.sortingDialogRadioDescending
6159
}
6260
orderBtn.isChecked = true
6361
}
6462

6563
private fun dialogConfirmed() {
66-
val sortingRadio = view.sorting_dialog_radio_sorting
64+
val sortingRadio = binding.sortingDialogRadioSorting
6765
var sorting = when (sortingRadio.checkedRadioButtonId) {
6866
R.id.sorting_dialog_radio_name -> SORT_BY_NAME
6967
R.id.sorting_dialog_radio_size -> SORT_BY_SIZE
7068
R.id.sorting_dialog_radio_last_modified -> SORT_BY_DATE_MODIFIED
7169
else -> SORT_BY_EXTENSION
7270
}
7371

74-
if (view.sorting_dialog_radio_order.checkedRadioButtonId == R.id.sorting_dialog_radio_descending) {
72+
if (binding.sortingDialogRadioOrder.checkedRadioButtonId == R.id.sorting_dialog_radio_descending) {
7573
sorting = sorting or SORT_DESCENDING
7674
}
7775

78-
if (view.sorting_dialog_numeric_sorting.isChecked) {
76+
if (binding.sortingDialogNumericSorting.isChecked) {
7977
sorting = sorting or SORT_USE_NUMERIC_VALUE
8078
}
8179

82-
if (view.sorting_dialog_use_for_this_folder.isChecked) {
80+
if (binding.sortingDialogUseForThisFolder.isChecked) {
8381
config.saveCustomSorting(path, sorting)
8482
} else {
8583
config.removeCustomSorting(path)

app/src/main/kotlin/com/simplemobiletools/filemanager/pro/dialogs/ChangeViewTypeDialog.kt

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,35 @@
11
package com.simplemobiletools.filemanager.pro.dialogs
22

3-
import android.view.View
43
import com.simplemobiletools.commons.activities.BaseSimpleActivity
54
import com.simplemobiletools.commons.extensions.beGone
65
import com.simplemobiletools.commons.extensions.getAlertDialogBuilder
76
import com.simplemobiletools.commons.extensions.setupDialogStuff
87
import com.simplemobiletools.commons.helpers.VIEW_TYPE_GRID
98
import com.simplemobiletools.commons.helpers.VIEW_TYPE_LIST
109
import com.simplemobiletools.filemanager.pro.R
10+
import com.simplemobiletools.filemanager.pro.databinding.DialogChangeViewTypeBinding
1111
import com.simplemobiletools.filemanager.pro.extensions.config
12-
import kotlinx.android.synthetic.main.dialog_change_view_type.view.*
1312

1413
class ChangeViewTypeDialog(val activity: BaseSimpleActivity, val path: String = "", showFolderCheck: Boolean = true, val callback: () -> Unit) {
15-
private var view: View
14+
private var binding: DialogChangeViewTypeBinding
1615
private var config = activity.config
1716

1817
init {
19-
view = activity.layoutInflater.inflate(R.layout.dialog_change_view_type, null).apply {
18+
binding = DialogChangeViewTypeBinding.inflate(activity.layoutInflater).apply {
2019
val currViewType = config.getFolderViewType(this@ChangeViewTypeDialog.path)
2120
val viewToCheck = if (currViewType == VIEW_TYPE_GRID) {
22-
change_view_type_dialog_radio_grid.id
21+
changeViewTypeDialogRadioGrid.id
2322
} else {
24-
change_view_type_dialog_radio_list.id
23+
changeViewTypeDialogRadioList.id
2524
}
2625

27-
change_view_type_dialog_radio.check(viewToCheck)
26+
changeViewTypeDialogRadio.check(viewToCheck)
2827
if (!showFolderCheck) {
29-
use_for_this_folder_divider.beGone()
30-
change_view_type_dialog_use_for_this_folder.beGone()
28+
useForThisFolderDivider.beGone()
29+
changeViewTypeDialogUseForThisFolder.beGone()
3130
}
3231

33-
change_view_type_dialog_use_for_this_folder.apply {
32+
changeViewTypeDialogUseForThisFolder.apply {
3433
isChecked = config.hasCustomViewType(this@ChangeViewTypeDialog.path)
3534
}
3635
}
@@ -39,18 +38,18 @@ class ChangeViewTypeDialog(val activity: BaseSimpleActivity, val path: String =
3938
.setPositiveButton(R.string.ok) { dialog, which -> dialogConfirmed() }
4039
.setNegativeButton(R.string.cancel, null)
4140
.apply {
42-
activity.setupDialogStuff(view, this)
41+
activity.setupDialogStuff(binding.root, this)
4342
}
4443
}
4544

4645
private fun dialogConfirmed() {
47-
val viewType = if (view.change_view_type_dialog_radio.checkedRadioButtonId == view.change_view_type_dialog_radio_grid.id) {
46+
val viewType = if (binding.changeViewTypeDialogRadio.checkedRadioButtonId == binding.changeViewTypeDialogRadioGrid.id) {
4847
VIEW_TYPE_GRID
4948
} else {
5049
VIEW_TYPE_LIST
5150
}
5251

53-
if (view.change_view_type_dialog_use_for_this_folder.isChecked) {
52+
if (binding.changeViewTypeDialogUseForThisFolder.isChecked) {
5453
config.saveFolderViewType(this.path, viewType)
5554
} else {
5655
config.removeFolderViewType(this.path)

app/src/main/kotlin/com/simplemobiletools/filemanager/pro/dialogs/CompressAsDialog.kt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,20 @@ import com.simplemobiletools.commons.activities.BaseSimpleActivity
66
import com.simplemobiletools.commons.dialogs.FilePickerDialog
77
import com.simplemobiletools.commons.extensions.*
88
import com.simplemobiletools.filemanager.pro.R
9+
import com.simplemobiletools.filemanager.pro.databinding.DialogCompressAsBinding
910
import com.simplemobiletools.filemanager.pro.extensions.config
10-
import kotlinx.android.synthetic.main.dialog_compress_as.view.*
1111

1212
class CompressAsDialog(val activity: BaseSimpleActivity, val path: String, val callback: (destination: String, password: String?) -> Unit) {
13-
private val view = activity.layoutInflater.inflate(R.layout.dialog_compress_as, null)
13+
private val binding = DialogCompressAsBinding.inflate(activity.layoutInflater)
1414

1515
init {
1616
val filename = path.getFilenameFromPath()
1717
val indexOfDot = if (filename.contains('.') && !activity.getIsPathDirectory(path)) filename.lastIndexOf(".") else filename.length
1818
val baseFilename = filename.substring(0, indexOfDot)
1919
var realPath = path.getParentPath()
2020

21-
view.apply {
22-
filename_value.setText(baseFilename)
21+
binding.apply {
22+
filenameValue.setText(baseFilename)
2323

2424
folder.setText(activity.humanizePath(realPath))
2525
folder.setOnClickListener {
@@ -29,22 +29,22 @@ class CompressAsDialog(val activity: BaseSimpleActivity, val path: String, val c
2929
}
3030
}
3131

32-
password_protect.setOnCheckedChangeListener { _, _ ->
33-
enter_password_hint.beVisibleIf(password_protect.isChecked)
32+
passwordProtect.setOnCheckedChangeListener { _, _ ->
33+
enterPasswordHint.beVisibleIf(passwordProtect.isChecked)
3434
}
3535
}
3636

3737
activity.getAlertDialogBuilder()
3838
.setPositiveButton(R.string.ok, null)
3939
.setNegativeButton(R.string.cancel, null)
4040
.apply {
41-
activity.setupDialogStuff(view, this, R.string.compress_as) { alertDialog ->
42-
alertDialog.showKeyboard(view.filename_value)
41+
activity.setupDialogStuff(binding.root, this, R.string.compress_as) { alertDialog ->
42+
alertDialog.showKeyboard(binding.filenameValue)
4343
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(View.OnClickListener {
44-
val name = view.filename_value.value
44+
val name = binding.filenameValue.value
4545
var password: String? = null
46-
if (view.password_protect.isChecked) {
47-
password = view.password.value
46+
if (binding.passwordProtect.isChecked) {
47+
password = binding.password.value
4848
if (password.isEmpty()) {
4949
activity.toast(R.string.empty_password_new)
5050
return@OnClickListener

app/src/main/kotlin/com/simplemobiletools/filemanager/pro/dialogs/CreateNewItemDialog.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,23 @@ import com.simplemobiletools.commons.extensions.*
66
import com.simplemobiletools.commons.helpers.isRPlus
77
import com.simplemobiletools.filemanager.pro.R
88
import com.simplemobiletools.filemanager.pro.activities.SimpleActivity
9+
import com.simplemobiletools.filemanager.pro.databinding.DialogCreateNewBinding
910
import com.simplemobiletools.filemanager.pro.helpers.RootHelpers
10-
import kotlinx.android.synthetic.main.dialog_create_new.view.*
1111
import java.io.File
1212
import java.io.IOException
1313

1414
class CreateNewItemDialog(val activity: SimpleActivity, val path: String, val callback: (success: Boolean) -> Unit) {
15-
private val view = activity.layoutInflater.inflate(R.layout.dialog_create_new, null)
15+
private val binding = DialogCreateNewBinding.inflate(activity.layoutInflater)
1616

1717
init {
1818
activity.getAlertDialogBuilder()
1919
.setPositiveButton(R.string.ok, null)
2020
.setNegativeButton(R.string.cancel, null)
2121
.apply {
22-
activity.setupDialogStuff(view, this, R.string.create_new) { alertDialog ->
23-
alertDialog.showKeyboard(view.item_title)
22+
activity.setupDialogStuff(binding.root, this, R.string.create_new) { alertDialog ->
23+
alertDialog.showKeyboard(binding.itemTitle)
2424
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(View.OnClickListener {
25-
val name = view.item_title.value
25+
val name = binding.itemTitle.value
2626
if (name.isEmpty()) {
2727
activity.toast(R.string.empty_name)
2828
} else if (name.isAValidFilename()) {
@@ -32,7 +32,7 @@ class CreateNewItemDialog(val activity: SimpleActivity, val path: String, val ca
3232
return@OnClickListener
3333
}
3434

35-
if (view.dialog_radio_group.checkedRadioButtonId == R.id.dialog_radio_directory) {
35+
if (binding.dialogRadioGroup.checkedRadioButtonId == R.id.dialog_radio_directory) {
3636
createDirectory(newPath, alertDialog) {
3737
callback(it)
3838
}

app/src/main/kotlin/com/simplemobiletools/filemanager/pro/dialogs/InsertFilenameDialog.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,23 @@ import androidx.appcompat.app.AlertDialog
44
import com.simplemobiletools.commons.activities.BaseSimpleActivity
55
import com.simplemobiletools.commons.extensions.*
66
import com.simplemobiletools.filemanager.pro.R
7-
import kotlinx.android.synthetic.main.dialog_insert_filename.view.*
7+
import com.simplemobiletools.filemanager.pro.databinding.DialogInsertFilenameBinding
88

99
class InsertFilenameDialog(
1010
val activity: BaseSimpleActivity, var path: String, val callback: (filename: String) -> Unit
1111
) {
1212
init {
13-
val view = activity.layoutInflater.inflate(R.layout.dialog_insert_filename, null)
13+
val binding = DialogInsertFilenameBinding.inflate(activity.layoutInflater)
1414

1515
activity.getAlertDialogBuilder()
1616
.setPositiveButton(R.string.ok, null)
1717
.setNegativeButton(R.string.cancel, null)
1818
.apply {
19-
activity.setupDialogStuff(view, this, R.string.filename) { alertDialog ->
20-
alertDialog.showKeyboard(view.insert_filename_title)
19+
activity.setupDialogStuff(binding.root, this, R.string.filename) { alertDialog ->
20+
alertDialog.showKeyboard(binding.insertFilenameTitle)
2121
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
22-
val filename = view.insert_filename_title.value
23-
val extension = view.insert_filename_extension_title.value
22+
val filename = binding.insertFilenameTitle.value
23+
val extension = binding.insertFilenameExtensionTitle.value
2424

2525
if (filename.isEmpty()) {
2626
activity.toast(R.string.filename_cannot_be_empty)

app/src/main/kotlin/com/simplemobiletools/filemanager/pro/dialogs/ManageVisibleTabsDialog.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ import com.simplemobiletools.commons.helpers.TAB_STORAGE_ANALYSIS
1010
import com.simplemobiletools.commons.helpers.isOreoPlus
1111
import com.simplemobiletools.commons.views.MyAppCompatCheckbox
1212
import com.simplemobiletools.filemanager.pro.R
13+
import com.simplemobiletools.filemanager.pro.databinding.DialogManageVisibleTabsBinding
1314
import com.simplemobiletools.filemanager.pro.extensions.config
1415
import com.simplemobiletools.filemanager.pro.helpers.ALL_TABS_MASK
15-
import kotlinx.android.synthetic.main.dialog_manage_visible_tabs.view.*
1616

1717
class ManageVisibleTabsDialog(val activity: BaseSimpleActivity) {
18-
private var view = activity.layoutInflater.inflate(R.layout.dialog_manage_visible_tabs, null)
18+
private val binding = DialogManageVisibleTabsBinding.inflate(activity.layoutInflater)
1919
private val tabs = LinkedHashMap<Int, Int>()
2020

2121
init {
@@ -26,26 +26,26 @@ class ManageVisibleTabsDialog(val activity: BaseSimpleActivity) {
2626
}
2727

2828
if (!isOreoPlus()) {
29-
view.manage_visible_tabs_storage_analysis.beGone()
29+
binding.manageVisibleTabsStorageAnalysis.beGone()
3030
}
3131

3232
val showTabs = activity.config.showTabs
3333
for ((key, value) in tabs) {
34-
view.findViewById<MyAppCompatCheckbox>(value).isChecked = showTabs and key != 0
34+
binding.root.findViewById<MyAppCompatCheckbox>(value).isChecked = showTabs and key != 0
3535
}
3636

3737
activity.getAlertDialogBuilder()
3838
.setPositiveButton(R.string.ok) { dialog, which -> dialogConfirmed() }
3939
.setNegativeButton(R.string.cancel, null)
4040
.apply {
41-
activity.setupDialogStuff(view, this)
41+
activity.setupDialogStuff(binding.root, this)
4242
}
4343
}
4444

4545
private fun dialogConfirmed() {
4646
var result = 0
4747
for ((key, value) in tabs) {
48-
if (view.findViewById<MyAppCompatCheckbox>(value).isChecked) {
48+
if (binding.root.findViewById<MyAppCompatCheckbox>(value).isChecked) {
4949
result += key
5050
}
5151
}

0 commit comments

Comments
 (0)