diff --git a/app/src/main/kotlin/com/simplemobiletools/applauncher/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/applauncher/activities/MainActivity.kt index 378d92d..d3dc5e4 100644 --- a/app/src/main/kotlin/com/simplemobiletools/applauncher/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/applauncher/activities/MainActivity.kt @@ -7,6 +7,7 @@ import com.simplemobiletools.applauncher.BuildConfig import com.simplemobiletools.applauncher.LauncherAdapterUpdateListener import com.simplemobiletools.applauncher.R import com.simplemobiletools.applauncher.adapters.LaunchersAdapter +import com.simplemobiletools.applauncher.databinding.ActivityMainBinding import com.simplemobiletools.applauncher.dialogs.AddLaunchersDialog import com.simplemobiletools.applauncher.dialogs.ChangeSortingDialog import com.simplemobiletools.applauncher.extensions.config @@ -22,11 +23,13 @@ import com.simplemobiletools.commons.models.RadioItem import com.simplemobiletools.commons.models.Release import com.simplemobiletools.commons.views.MyGridLayoutManager import com.simplemobiletools.commons.views.MyRecyclerView -import kotlinx.android.synthetic.main.activity_main.* class MainActivity : SimpleActivity(), LauncherAdapterUpdateListener { - private val MAX_COLUMN_COUNT = 15 + companion object { + private const val MAX_COLUMN_COUNT = 15 + } + private val binding by lazy(LazyThreadSafetyMode.NONE) { ActivityMainBinding.inflate(layoutInflater) } private var launchersIgnoringSearch = ArrayList() private var allLaunchers: ArrayList? = null private var zoomListener: MyRecyclerView.MyZoomListener? = null @@ -37,12 +40,12 @@ class MainActivity : SimpleActivity(), LauncherAdapterUpdateListener { override fun onCreate(savedInstanceState: Bundle?) { isMaterialActivity = true super.onCreate(savedInstanceState) - setContentView(R.layout.activity_main) + setContentView(binding.root) appLaunched(BuildConfig.APPLICATION_ID) setupOptionsMenu() refreshMenuItems() - updateMaterialActivityViews(main_coordinator, launchers_grid, useTransparentNavigation = true, useTopSearchMenu = true) + updateMaterialActivityViews(binding.mainCoordinator, binding.launchersGrid, useTransparentNavigation = true, useTopSearchMenu = true) setupEmptyView() setupLaunchers() @@ -50,7 +53,7 @@ class MainActivity : SimpleActivity(), LauncherAdapterUpdateListener { storeStateVariables() setupGridLayoutManager() - fab.setOnClickListener { + binding.fab.setOnClickListener { fabClicked() } } @@ -70,10 +73,13 @@ class MainActivity : SimpleActivity(), LauncherAdapterUpdateListener { } } - updateTextColors(coordinator_layout) - no_items_placeholder_2.setTextColor(properPrimaryColor) - launchers_fastscroller.updateColors(properPrimaryColor) - (fab.layoutParams as CoordinatorLayout.LayoutParams).bottomMargin = navigationBarHeight + resources.getDimension(R.dimen.activity_margin).toInt() + binding.apply { + updateTextColors(coordinatorLayout) + noItemsPlaceholder2.setTextColor(properPrimaryColor) + launchersFastscroller.updateColors(properPrimaryColor) + (fab.layoutParams as CoordinatorLayout.LayoutParams).bottomMargin = navigationBarHeight + resources.getDimension(R.dimen.activity_margin).toInt() + + } } override fun onPause() { @@ -82,39 +88,41 @@ class MainActivity : SimpleActivity(), LauncherAdapterUpdateListener { } override fun onBackPressed() { - if (main_menu.isSearchOpen) { - main_menu.closeSearch() + if (binding.mainMenu.isSearchOpen) { + binding.mainMenu.closeSearch() } else { super.onBackPressed() } } private fun refreshMenuItems() { - main_menu.getToolbar().menu.apply { + binding.mainMenu.getToolbar().menu.apply { findItem(R.id.more_apps_from_us).isVisible = !resources.getBoolean(R.bool.hide_google_relations) } } private fun setupOptionsMenu() { - main_menu.getToolbar().inflateMenu(R.menu.menu) - main_menu.toggleHideOnScroll(false) - main_menu.setupMenu() + binding.mainMenu.apply { + getToolbar().inflateMenu(R.menu.menu) + toggleHideOnScroll(false) + setupMenu() - main_menu.onSearchTextChangedListener = { text -> - searchTextChanged(text) - } - - main_menu.getToolbar().setOnMenuItemClickListener { menuItem -> - when (menuItem.itemId) { - R.id.sort -> showSortingDialog() - R.id.toggle_app_name -> toggleAppName() - R.id.column_count -> changeColumnCount() - R.id.more_apps_from_us -> launchMoreAppsFromUsIntent() - R.id.settings -> launchSettings() - R.id.about -> launchAbout() - else -> return@setOnMenuItemClickListener false + onSearchTextChangedListener = { text -> + searchTextChanged(text) + } + + getToolbar().setOnMenuItemClickListener { menuItem -> + when (menuItem.itemId) { + R.id.sort -> showSortingDialog() + R.id.toggle_app_name -> toggleAppName() + R.id.column_count -> changeColumnCount() + R.id.more_apps_from_us -> launchMoreAppsFromUsIntent() + R.id.settings -> launchSettings() + R.id.about -> launchAbout() + else -> return@setOnMenuItemClickListener false + } + return@setOnMenuItemClickListener true } - return@setOnMenuItemClickListener true } } @@ -125,10 +133,10 @@ class MainActivity : SimpleActivity(), LauncherAdapterUpdateListener { private fun updateMenuColors() { updateStatusbarColor(getProperBackgroundColor()) - main_menu.updateColors() + binding.mainMenu.updateColors() } - private fun getGridAdapter() = launchers_grid.adapter as? LaunchersAdapter + private fun getGridAdapter() = binding.launchersGrid.adapter as? LaunchersAdapter private fun setupLaunchers() { launchersIgnoringSearch = dbHelper.getLaunchers() @@ -145,7 +153,7 @@ class MainActivity : SimpleActivity(), LauncherAdapterUpdateListener { activity = this, launchers = launchers, listener = this, - recyclerView = launchers_grid, + recyclerView = binding.launchersGrid, ) { hideKeyboard() val launchIntent = packageManager.getLaunchIntentForPackage((it as AppLauncher).packageName) @@ -167,7 +175,7 @@ class MainActivity : SimpleActivity(), LauncherAdapterUpdateListener { } }.apply { setupZoomListener(zoomListener) - launchers_grid.adapter = this + binding.launchersGrid.adapter = this } maybeShowEmptyView() @@ -193,11 +201,11 @@ class MainActivity : SimpleActivity(), LauncherAdapterUpdateListener { items.add(RadioItem(i, resources.getQuantityString(R.plurals.column_counts, i, i))) } - val currentColumnCount = (launchers_grid.layoutManager as MyGridLayoutManager).spanCount + val currentColumnCount = (binding.launchersGrid.layoutManager as MyGridLayoutManager).spanCount RadioGroupDialog(this, items, currentColumnCount) { val newColumnCount = it as Int if (currentColumnCount != newColumnCount) { - (launchers_grid.layoutManager as MyGridLayoutManager).spanCount = newColumnCount + (binding.launchersGrid.layoutManager as MyGridLayoutManager).spanCount = newColumnCount if (portrait) { config.portraitColumnCnt = newColumnCount } else { @@ -209,7 +217,7 @@ class MainActivity : SimpleActivity(), LauncherAdapterUpdateListener { } private fun increaseColumnCount() { - val newColumnCount = ++(launchers_grid.layoutManager as MyGridLayoutManager).spanCount + val newColumnCount = ++(binding.launchersGrid.layoutManager as MyGridLayoutManager).spanCount if (portrait) { config.portraitColumnCnt = newColumnCount } else { @@ -219,7 +227,7 @@ class MainActivity : SimpleActivity(), LauncherAdapterUpdateListener { } private fun reduceColumnCount() { - val newColumnCount = --(launchers_grid.layoutManager as MyGridLayoutManager).spanCount + val newColumnCount = --(binding.launchersGrid.layoutManager as MyGridLayoutManager).spanCount if (portrait) { config.portraitColumnCnt = newColumnCount } else { @@ -237,7 +245,7 @@ class MainActivity : SimpleActivity(), LauncherAdapterUpdateListener { } private fun setupGridLayoutManager() { - val layoutManager = launchers_grid.layoutManager as MyGridLayoutManager + val layoutManager = binding.launchersGrid.layoutManager as MyGridLayoutManager if (portrait) { layoutManager.spanCount = config.portraitColumnCnt } else { @@ -246,7 +254,7 @@ class MainActivity : SimpleActivity(), LauncherAdapterUpdateListener { } private fun initZoomListener() { - val layoutManager = launchers_grid.layoutManager as MyGridLayoutManager + val layoutManager = binding.launchersGrid.layoutManager as MyGridLayoutManager zoomListener = object : MyRecyclerView.MyZoomListener { override fun zoomIn() { if (layoutManager.spanCount > 1) { @@ -283,7 +291,7 @@ class MainActivity : SimpleActivity(), LauncherAdapterUpdateListener { } override fun refreshItems() { - main_menu.closeSearch() + binding.mainMenu.closeSearch() setupLaunchers() } @@ -308,23 +316,27 @@ class MainActivity : SimpleActivity(), LauncherAdapterUpdateListener { } private fun setupEmptyView() { - val properPrimaryColor = getProperPrimaryColor() - no_items_placeholder_2.underlineText() - no_items_placeholder_2.setTextColor(properPrimaryColor) - no_items_placeholder_2.setOnClickListener { - fabClicked() + binding.noItemsPlaceholder2.apply { + val properPrimaryColor = getProperPrimaryColor() + underlineText() + setTextColor(properPrimaryColor) + setOnClickListener { + fabClicked() + } } } private fun maybeShowEmptyView() { - if (getGridAdapter()?.launchers?.isEmpty() == true) { - launchers_fastscroller.beGone() - no_items_placeholder_2.beVisibleIf(main_menu.getCurrentQuery().isEmpty()) - no_items_placeholder.beVisible() - } else { - no_items_placeholder_2.beGone() - no_items_placeholder.beGone() - launchers_fastscroller.beVisible() + binding.apply { + if (getGridAdapter()?.launchers?.isEmpty() == true) { + launchersFastscroller.beGone() + noItemsPlaceholder2.beVisibleIf(mainMenu.getCurrentQuery().isEmpty()) + noItemsPlaceholder.beVisible() + } else { + noItemsPlaceholder2.beGone() + noItemsPlaceholder.beGone() + launchersFastscroller.beVisible() + } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/applauncher/activities/SettingsActivity.kt b/app/src/main/kotlin/com/simplemobiletools/applauncher/activities/SettingsActivity.kt index e748dfa..317be6d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/applauncher/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/applauncher/activities/SettingsActivity.kt @@ -1,79 +1,93 @@ package com.simplemobiletools.applauncher.activities import android.os.Bundle -import com.simplemobiletools.applauncher.R +import com.simplemobiletools.applauncher.databinding.ActivitySettingsBinding import com.simplemobiletools.applauncher.extensions.config import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.helpers.NavigationIcon import com.simplemobiletools.commons.helpers.isTiramisuPlus -import kotlinx.android.synthetic.main.activity_settings.* -import java.util.* +import java.util.Locale import kotlin.system.exitProcess class SettingsActivity : SimpleActivity() { + private val binding by lazy(LazyThreadSafetyMode.NONE) { ActivitySettingsBinding.inflate(layoutInflater) } override fun onCreate(savedInstanceState: Bundle?) { isMaterialActivity = true super.onCreate(savedInstanceState) - setContentView(R.layout.activity_settings) + setContentView(binding.root) - updateMaterialActivityViews(settings_coordinator, settings_holder, useTransparentNavigation = true, useTopSearchMenu = false) - setupMaterialScrollListener(settings_nested_scrollview, settings_toolbar) + binding.apply { + updateMaterialActivityViews(settingsCoordinator, settingsHolder, useTransparentNavigation = true, useTopSearchMenu = false) + setupMaterialScrollListener(settingsNestedScrollview, settingsToolbar) + } } override fun onResume() { super.onResume() - setupToolbar(settings_toolbar, NavigationIcon.Arrow) + setupToolbar(binding.settingsToolbar, NavigationIcon.Arrow) setupPurchaseThankYou() setupCustomizeColors() setupUseEnglish() setupLanguage() setupCloseApp() - updateTextColors(settings_holder) + updateTextColors(binding.settingsHolder) - arrayOf(settings_color_customization_section_label, settings_general_settings_label).forEach { - it.setTextColor(getProperPrimaryColor()) + binding.apply { + arrayOf(settingsColorCustomizationSectionLabel, settingsGeneralSettingsLabel).forEach { + it.setTextColor(getProperPrimaryColor()) + } } } private fun setupPurchaseThankYou() { - settings_purchase_thank_you_holder.beGoneIf(isOrWasThankYouInstalled()) - settings_purchase_thank_you_holder.setOnClickListener { - launchPurchaseThankYouIntent() + binding.settingsPurchaseThankYouHolder.apply { + beGoneIf(isOrWasThankYouInstalled()) + setOnClickListener { + launchPurchaseThankYouIntent() + } } } private fun setupCustomizeColors() { - settings_color_customization_label.text = getCustomizeColorsString() - settings_color_customization_holder.setOnClickListener { - handleCustomizeColorsClick() + binding.apply { + settingsColorCustomizationLabel.text = getCustomizeColorsString() + settingsColorCustomizationHolder.setOnClickListener { + handleCustomizeColorsClick() + } } } private fun setupUseEnglish() { - settings_use_english_holder.beVisibleIf((config.wasUseEnglishToggled || Locale.getDefault().language != "en") && !isTiramisuPlus()) - settings_use_english.isChecked = config.useEnglish - settings_use_english_holder.setOnClickListener { - settings_use_english.toggle() - config.useEnglish = settings_use_english.isChecked - exitProcess(0) + binding.apply { + settingsUseEnglishHolder.beVisibleIf((config.wasUseEnglishToggled || Locale.getDefault().language != "en") && !isTiramisuPlus()) + settingsUseEnglish.isChecked = config.useEnglish + settingsUseEnglishHolder.setOnClickListener { + settingsUseEnglish.toggle() + config.useEnglish = settingsUseEnglish.isChecked + exitProcess(0) + } } } private fun setupLanguage() { - settings_language.text = Locale.getDefault().displayLanguage - settings_language_holder.beVisibleIf(isTiramisuPlus()) - settings_language_holder.setOnClickListener { - launchChangeAppLanguageIntent() + binding.apply { + settingsLanguage.text = Locale.getDefault().displayLanguage + settingsLanguageHolder.beVisibleIf(isTiramisuPlus()) + settingsLanguageHolder.setOnClickListener { + launchChangeAppLanguageIntent() + } } } private fun setupCloseApp() { - settings_close_app.isChecked = config.closeApp - settings_close_app_holder.setOnClickListener { - settings_close_app.toggle() - config.closeApp = settings_close_app.isChecked + binding.apply { + settingsCloseApp.isChecked = config.closeApp + settingsCloseAppHolder.setOnClickListener { + settingsCloseApp.toggle() + config.closeApp = settingsCloseApp.isChecked + } } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/applauncher/adapters/AddLaunchersAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/applauncher/adapters/AddLaunchersAdapter.kt index c005630..0d4bb85 100644 --- a/app/src/main/kotlin/com/simplemobiletools/applauncher/adapters/AddLaunchersAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/applauncher/adapters/AddLaunchersAdapter.kt @@ -1,18 +1,17 @@ package com.simplemobiletools.applauncher.adapters import android.app.Activity -import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.recyclerview.widget.RecyclerView -import com.simplemobiletools.applauncher.R +import com.simplemobiletools.applauncher.databinding.ItemAddLauncherBinding import com.simplemobiletools.applauncher.models.AppLauncher import com.simplemobiletools.commons.extensions.getProperPrimaryColor import com.simplemobiletools.commons.extensions.getProperTextColor -import kotlinx.android.synthetic.main.item_add_launcher.view.* class AddLaunchersAdapter(activity: Activity, val allLaunchers: ArrayList, val shownLaunchers: ArrayList) : RecyclerView.Adapter() { + private var layoutInflater = activity.layoutInflater private var textColor = activity.getProperTextColor() private var adjustedPrimaryColor = activity.getProperPrimaryColor() private var selectedKeys = HashSet() @@ -42,8 +41,7 @@ class AddLaunchersAdapter(activity: Activity, val allLaunchers: ArrayList - setupView(itemView, launcher, holder) + setupView(Binding.getByAppConfig(activity.config.showAppName).bind(itemView), launcher, holder) } bindViewHolder(holder) } @@ -185,14 +183,14 @@ class LaunchersAdapter( } } - private fun setupView(view: View, launcher: AppLauncher, holder: ViewHolder) { - view.apply { + private fun setupView(binding: ItemViewBinding, launcher: AppLauncher, holder: ViewHolder) { + binding.apply { val isSelected = selectedKeys.contains(launcher.packageName.hashCode()) - launcher_check?.beInvisibleIf(!isSelected) - launcher_label?.text = launcher.title - launcher_label?.setTextColor(textColor) - launcher_label?.beVisibleIf(activity.config.showAppName) - launcher_icon.setImageDrawable(launcher.drawable!!) + launcherCheck?.beInvisibleIf(!isSelected) + launcherLabel?.text = launcher.title + launcherLabel?.setTextColor(textColor) + launcherLabel?.beVisibleIf(activity.config.showAppName) + launcherIcon.setImageDrawable(launcher.drawable!!) val bottomPadding = if (activity.config.showAppName) { 0 @@ -200,11 +198,11 @@ class LaunchersAdapter( iconPadding } - launcher_icon.setPadding(iconPadding, iconPadding, iconPadding, bottomPadding) - launcher_drag_handle.beVisibleIf(isChangingOrder) + launcherIcon.setPadding(iconPadding, iconPadding, iconPadding, bottomPadding) + launcherDragHandle.beVisibleIf(isChangingOrder) if (isChangingOrder) { - launcher_drag_handle.applyColorFilter(textColor) - launcher_drag_handle.setOnTouchListener { v, event -> + launcherDragHandle.applyColorFilter(textColor) + launcherDragHandle.setOnTouchListener { v, event -> if (event.action == MotionEvent.ACTION_DOWN) { startReorderDragListener.requestDrag(holder) } @@ -213,7 +211,7 @@ class LaunchersAdapter( } if (isSelected) { - launcher_check?.background?.applyColorFilter(properPrimaryColor) + launcherCheck?.background?.applyColorFilter(properPrimaryColor) } } } @@ -238,4 +236,64 @@ class LaunchersAdapter( override fun onRowSelected(myViewHolder: ViewHolder?) {} override fun onChange(position: Int) = launchers.getOrNull(position)?.getBubbleText() ?: "" + + private sealed interface Binding { + companion object { + fun getByAppConfig(showAppName: Boolean): Binding { + return if (showAppName) { + ItemLauncherLabel + } else { + ItemLauncherNoLabel + } + } + } + + fun inflate(layoutInflater: LayoutInflater, viewGroup: ViewGroup, attachToRoot: Boolean): ItemViewBinding + fun bind(view: View): ItemViewBinding + + data object ItemLauncherLabel : Binding { + override fun inflate(layoutInflater: LayoutInflater, viewGroup: ViewGroup, attachToRoot: Boolean): ItemViewBinding { + return ItemLauncherLabelBindingAdapter(ItemLauncherLabelBinding.inflate(layoutInflater, viewGroup, attachToRoot)) + } + + override fun bind(view: View): ItemViewBinding { + return ItemLauncherLabelBindingAdapter(ItemLauncherLabelBinding.bind(view)) + } + } + + data object ItemLauncherNoLabel : Binding { + override fun inflate(layoutInflater: LayoutInflater, viewGroup: ViewGroup, attachToRoot: Boolean): ItemViewBinding { + return ItemLauncherNoLabelBindingAdapter(ItemLauncherNoLabelBinding.inflate(layoutInflater, viewGroup, attachToRoot)) + } + + override fun bind(view: View): ItemViewBinding { + return ItemLauncherNoLabelBindingAdapter(ItemLauncherNoLabelBinding.bind(view)) + } + } + } + + private interface ItemViewBinding : ViewBinding { + val launcherCheck: ImageView + val launcherIcon: ImageView + val launcherDragHandle: ImageView + val launcherLabel: TextView? + } + + private class ItemLauncherLabelBindingAdapter(val binding: ItemLauncherLabelBinding) : ItemViewBinding { + override val launcherCheck: ImageView = binding.launcherCheck + override val launcherIcon: ImageView = binding.launcherIcon + override val launcherDragHandle: ImageView = binding.launcherDragHandle + override val launcherLabel: TextView = binding.launcherLabel + + override fun getRoot(): View = binding.root + } + + private class ItemLauncherNoLabelBindingAdapter(val binding: ItemLauncherNoLabelBinding) : ItemViewBinding { + override val launcherCheck: ImageView = binding.launcherCheck + override val launcherIcon: ImageView = binding.launcherIcon + override val launcherDragHandle: ImageView = binding.launcherDragHandle + override val launcherLabel: TextView? = null + + override fun getRoot(): View = binding.root + } } diff --git a/app/src/main/kotlin/com/simplemobiletools/applauncher/dialogs/AddLaunchersDialog.kt b/app/src/main/kotlin/com/simplemobiletools/applauncher/dialogs/AddLaunchersDialog.kt index fa73d58..fcfeb7f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/applauncher/dialogs/AddLaunchersDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/applauncher/dialogs/AddLaunchersDialog.kt @@ -1,15 +1,14 @@ package com.simplemobiletools.applauncher.dialogs import android.app.Activity -import android.view.ViewGroup import com.simplemobiletools.applauncher.R import com.simplemobiletools.applauncher.adapters.AddLaunchersAdapter +import com.simplemobiletools.applauncher.databinding.DialogAddLaunchersBinding import com.simplemobiletools.applauncher.extensions.dbHelper import com.simplemobiletools.applauncher.models.AppLauncher import com.simplemobiletools.commons.extensions.areSystemAnimationsEnabled import com.simplemobiletools.commons.extensions.getAlertDialogBuilder import com.simplemobiletools.commons.extensions.setupDialogStuff -import kotlinx.android.synthetic.main.dialog_add_launchers.view.* class AddLaunchersDialog( val activity: Activity, @@ -17,20 +16,21 @@ class AddLaunchersDialog( val shownLaunchers: ArrayList, val callback: () -> Unit ) { - private var view = (activity.layoutInflater.inflate(R.layout.dialog_add_launchers, null) as ViewGroup) private var adapter: AddLaunchersAdapter? = null init { + val binding = DialogAddLaunchersBinding.inflate(activity.layoutInflater) + activity.getAlertDialogBuilder() .setPositiveButton(R.string.ok) { dialogInterface, i -> confirmSelection() } .setNegativeButton(R.string.cancel, null) .apply { - activity.setupDialogStuff(view, this) { + activity.setupDialogStuff(binding.root, this) { adapter = AddLaunchersAdapter(activity, allLaunchers, shownLaunchers) - view.add_launchers_holder.adapter = adapter + binding.addLaunchersHolder.adapter = adapter if (activity.areSystemAnimationsEnabled) { - view.add_launchers_holder.scheduleLayoutAnimation() + binding.addLaunchersHolder.scheduleLayoutAnimation() } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/applauncher/dialogs/ChangeSortingDialog.kt b/app/src/main/kotlin/com/simplemobiletools/applauncher/dialogs/ChangeSortingDialog.kt index 8c90d86..ed5a76f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/applauncher/dialogs/ChangeSortingDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/applauncher/dialogs/ChangeSortingDialog.kt @@ -1,6 +1,7 @@ package com.simplemobiletools.applauncher.dialogs import com.simplemobiletools.applauncher.R +import com.simplemobiletools.applauncher.databinding.DialogChangeSortingBinding import com.simplemobiletools.applauncher.extensions.config import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.extensions.beGoneIf @@ -9,19 +10,18 @@ import com.simplemobiletools.commons.extensions.setupDialogStuff import com.simplemobiletools.commons.helpers.SORT_BY_CUSTOM import com.simplemobiletools.commons.helpers.SORT_BY_TITLE import com.simplemobiletools.commons.helpers.SORT_DESCENDING -import kotlinx.android.synthetic.main.dialog_change_sorting.view.* class ChangeSortingDialog(val activity: BaseSimpleActivity, private val callback: () -> Unit) { private var currSorting = 0 private var config = activity.config - private var view = activity.layoutInflater.inflate(R.layout.dialog_change_sorting, null) + private val binding = DialogChangeSortingBinding.inflate(activity.layoutInflater) init { 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) } currSorting = config.sorting @@ -30,38 +30,38 @@ class ChangeSortingDialog(val activity: BaseSimpleActivity, private val callback } private fun setupSortRadio() { - val sortingRadio = view.sorting_dialog_radio_sorting - sortingRadio.setOnCheckedChangeListener { group, checkedId -> - val isCustomSorting = checkedId == sortingRadio.sorting_dialog_radio_custom.id - view.sorting_dialog_radio_order.beGoneIf(isCustomSorting) - view.sorting_dialog_divider.beGoneIf(isCustomSorting) + binding.apply { + sortingDialogRadioSorting.setOnCheckedChangeListener { group, checkedId -> + val isCustomSorting = checkedId == sortingDialogRadioCustom.id + sortingDialogRadioOrder.beGoneIf(isCustomSorting) + sortingDialogDivider.beGoneIf(isCustomSorting) + } } val sortBtn = when { - currSorting and SORT_BY_TITLE != 0 -> sortingRadio.sorting_dialog_radio_title - else -> sortingRadio.sorting_dialog_radio_custom + currSorting and SORT_BY_TITLE != 0 -> binding.sortingDialogRadioTitle + else -> binding.sortingDialogRadioCustom } 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_title -> SORT_BY_TITLE else -> SORT_BY_CUSTOM } - if (sortingRadio.checkedRadioButtonId != R.id.sorting_dialog_radio_custom && view.sorting_dialog_radio_order.checkedRadioButtonId == R.id.sorting_dialog_radio_descending) { + if (sortingRadio.checkedRadioButtonId != R.id.sorting_dialog_radio_custom && binding.sortingDialogRadioOrder.checkedRadioButtonId == R.id.sorting_dialog_radio_descending) { sorting = sorting or SORT_DESCENDING } diff --git a/app/src/main/kotlin/com/simplemobiletools/applauncher/dialogs/EditDialog.kt b/app/src/main/kotlin/com/simplemobiletools/applauncher/dialogs/EditDialog.kt index e86180d..4a1ef10 100644 --- a/app/src/main/kotlin/com/simplemobiletools/applauncher/dialogs/EditDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/applauncher/dialogs/EditDialog.kt @@ -2,27 +2,26 @@ package com.simplemobiletools.applauncher.dialogs import android.app.Activity import android.app.AlertDialog -import android.view.ViewGroup import com.simplemobiletools.applauncher.R +import com.simplemobiletools.applauncher.databinding.DialogEditLauncherBinding import com.simplemobiletools.applauncher.extensions.dbHelper import com.simplemobiletools.applauncher.models.AppLauncher import com.simplemobiletools.commons.extensions.* -import kotlinx.android.synthetic.main.dialog_edit_launcher.view.* class EditDialog(val activity: Activity, val appLauncher: AppLauncher, val callback: () -> Unit) { init { - val view = (activity.layoutInflater.inflate(R.layout.dialog_edit_launcher, null) as ViewGroup) - view.edit_launcher_edittext.setText(appLauncher.title) + val binding = DialogEditLauncherBinding.inflate(activity.layoutInflater) + binding.editLauncherEdittext.setText(appLauncher.title) activity.getAlertDialogBuilder() .setPositiveButton(R.string.ok, null) .setNegativeButton(R.string.cancel, null) .apply { - activity.setupDialogStuff(view, this, R.string.rename) { alertDialog -> - alertDialog.showKeyboard(view.edit_launcher_edittext) + activity.setupDialogStuff(binding.root, this, R.string.rename) { alertDialog -> + alertDialog.showKeyboard(binding.editLauncherEdittext) alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener { - val newName = view.edit_launcher_edittext.value + val newName = binding.editLauncherEdittext.value if (!newName.isEmpty()) { if (activity.dbHelper.updateLauncherName(appLauncher.id, newName)) { callback()