migrate to viewbinding

This commit is contained in:
fatih ergin 2023-08-16 01:08:17 +03:00
parent ee64d29218
commit 20605da669
7 changed files with 226 additions and 145 deletions

View File

@ -7,6 +7,7 @@ import com.simplemobiletools.applauncher.BuildConfig
import com.simplemobiletools.applauncher.LauncherAdapterUpdateListener import com.simplemobiletools.applauncher.LauncherAdapterUpdateListener
import com.simplemobiletools.applauncher.R import com.simplemobiletools.applauncher.R
import com.simplemobiletools.applauncher.adapters.LaunchersAdapter import com.simplemobiletools.applauncher.adapters.LaunchersAdapter
import com.simplemobiletools.applauncher.databinding.ActivityMainBinding
import com.simplemobiletools.applauncher.dialogs.AddLaunchersDialog import com.simplemobiletools.applauncher.dialogs.AddLaunchersDialog
import com.simplemobiletools.applauncher.dialogs.ChangeSortingDialog import com.simplemobiletools.applauncher.dialogs.ChangeSortingDialog
import com.simplemobiletools.applauncher.extensions.config 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.models.Release
import com.simplemobiletools.commons.views.MyGridLayoutManager import com.simplemobiletools.commons.views.MyGridLayoutManager
import com.simplemobiletools.commons.views.MyRecyclerView import com.simplemobiletools.commons.views.MyRecyclerView
import kotlinx.android.synthetic.main.activity_main.*
class MainActivity : SimpleActivity(), LauncherAdapterUpdateListener { 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<AppLauncher>() private var launchersIgnoringSearch = ArrayList<AppLauncher>()
private var allLaunchers: ArrayList<AppLauncher>? = null private var allLaunchers: ArrayList<AppLauncher>? = null
private var zoomListener: MyRecyclerView.MyZoomListener? = null private var zoomListener: MyRecyclerView.MyZoomListener? = null
@ -37,12 +40,12 @@ class MainActivity : SimpleActivity(), LauncherAdapterUpdateListener {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
isMaterialActivity = true isMaterialActivity = true
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main) setContentView(binding.root)
appLaunched(BuildConfig.APPLICATION_ID) appLaunched(BuildConfig.APPLICATION_ID)
setupOptionsMenu() setupOptionsMenu()
refreshMenuItems() refreshMenuItems()
updateMaterialActivityViews(main_coordinator, launchers_grid, useTransparentNavigation = true, useTopSearchMenu = true) updateMaterialActivityViews(binding.mainCoordinator, binding.launchersGrid, useTransparentNavigation = true, useTopSearchMenu = true)
setupEmptyView() setupEmptyView()
setupLaunchers() setupLaunchers()
@ -50,7 +53,7 @@ class MainActivity : SimpleActivity(), LauncherAdapterUpdateListener {
storeStateVariables() storeStateVariables()
setupGridLayoutManager() setupGridLayoutManager()
fab.setOnClickListener { binding.fab.setOnClickListener {
fabClicked() fabClicked()
} }
} }
@ -70,10 +73,13 @@ class MainActivity : SimpleActivity(), LauncherAdapterUpdateListener {
} }
} }
updateTextColors(coordinator_layout) binding.apply {
no_items_placeholder_2.setTextColor(properPrimaryColor) updateTextColors(coordinatorLayout)
launchers_fastscroller.updateColors(properPrimaryColor) noItemsPlaceholder2.setTextColor(properPrimaryColor)
(fab.layoutParams as CoordinatorLayout.LayoutParams).bottomMargin = navigationBarHeight + resources.getDimension(R.dimen.activity_margin).toInt() launchersFastscroller.updateColors(properPrimaryColor)
(fab.layoutParams as CoordinatorLayout.LayoutParams).bottomMargin = navigationBarHeight + resources.getDimension(R.dimen.activity_margin).toInt()
}
} }
override fun onPause() { override fun onPause() {
@ -82,39 +88,41 @@ class MainActivity : SimpleActivity(), LauncherAdapterUpdateListener {
} }
override fun onBackPressed() { override fun onBackPressed() {
if (main_menu.isSearchOpen) { if (binding.mainMenu.isSearchOpen) {
main_menu.closeSearch() binding.mainMenu.closeSearch()
} else { } else {
super.onBackPressed() super.onBackPressed()
} }
} }
private fun refreshMenuItems() { 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) findItem(R.id.more_apps_from_us).isVisible = !resources.getBoolean(R.bool.hide_google_relations)
} }
} }
private fun setupOptionsMenu() { private fun setupOptionsMenu() {
main_menu.getToolbar().inflateMenu(R.menu.menu) binding.mainMenu.apply {
main_menu.toggleHideOnScroll(false) getToolbar().inflateMenu(R.menu.menu)
main_menu.setupMenu() toggleHideOnScroll(false)
setupMenu()
main_menu.onSearchTextChangedListener = { text -> onSearchTextChangedListener = { text ->
searchTextChanged(text) searchTextChanged(text)
} }
main_menu.getToolbar().setOnMenuItemClickListener { menuItem -> getToolbar().setOnMenuItemClickListener { menuItem ->
when (menuItem.itemId) { when (menuItem.itemId) {
R.id.sort -> showSortingDialog() R.id.sort -> showSortingDialog()
R.id.toggle_app_name -> toggleAppName() R.id.toggle_app_name -> toggleAppName()
R.id.column_count -> changeColumnCount() R.id.column_count -> changeColumnCount()
R.id.more_apps_from_us -> launchMoreAppsFromUsIntent() R.id.more_apps_from_us -> launchMoreAppsFromUsIntent()
R.id.settings -> launchSettings() R.id.settings -> launchSettings()
R.id.about -> launchAbout() R.id.about -> launchAbout()
else -> return@setOnMenuItemClickListener false else -> return@setOnMenuItemClickListener false
}
return@setOnMenuItemClickListener true
} }
return@setOnMenuItemClickListener true
} }
} }
@ -125,10 +133,10 @@ class MainActivity : SimpleActivity(), LauncherAdapterUpdateListener {
private fun updateMenuColors() { private fun updateMenuColors() {
updateStatusbarColor(getProperBackgroundColor()) 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() { private fun setupLaunchers() {
launchersIgnoringSearch = dbHelper.getLaunchers() launchersIgnoringSearch = dbHelper.getLaunchers()
@ -145,7 +153,7 @@ class MainActivity : SimpleActivity(), LauncherAdapterUpdateListener {
activity = this, activity = this,
launchers = launchers, launchers = launchers,
listener = this, listener = this,
recyclerView = launchers_grid, recyclerView = binding.launchersGrid,
) { ) {
hideKeyboard() hideKeyboard()
val launchIntent = packageManager.getLaunchIntentForPackage((it as AppLauncher).packageName) val launchIntent = packageManager.getLaunchIntentForPackage((it as AppLauncher).packageName)
@ -167,7 +175,7 @@ class MainActivity : SimpleActivity(), LauncherAdapterUpdateListener {
} }
}.apply { }.apply {
setupZoomListener(zoomListener) setupZoomListener(zoomListener)
launchers_grid.adapter = this binding.launchersGrid.adapter = this
} }
maybeShowEmptyView() maybeShowEmptyView()
@ -193,11 +201,11 @@ class MainActivity : SimpleActivity(), LauncherAdapterUpdateListener {
items.add(RadioItem(i, resources.getQuantityString(R.plurals.column_counts, i, i))) 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) { RadioGroupDialog(this, items, currentColumnCount) {
val newColumnCount = it as Int val newColumnCount = it as Int
if (currentColumnCount != newColumnCount) { if (currentColumnCount != newColumnCount) {
(launchers_grid.layoutManager as MyGridLayoutManager).spanCount = newColumnCount (binding.launchersGrid.layoutManager as MyGridLayoutManager).spanCount = newColumnCount
if (portrait) { if (portrait) {
config.portraitColumnCnt = newColumnCount config.portraitColumnCnt = newColumnCount
} else { } else {
@ -209,7 +217,7 @@ class MainActivity : SimpleActivity(), LauncherAdapterUpdateListener {
} }
private fun increaseColumnCount() { private fun increaseColumnCount() {
val newColumnCount = ++(launchers_grid.layoutManager as MyGridLayoutManager).spanCount val newColumnCount = ++(binding.launchersGrid.layoutManager as MyGridLayoutManager).spanCount
if (portrait) { if (portrait) {
config.portraitColumnCnt = newColumnCount config.portraitColumnCnt = newColumnCount
} else { } else {
@ -219,7 +227,7 @@ class MainActivity : SimpleActivity(), LauncherAdapterUpdateListener {
} }
private fun reduceColumnCount() { private fun reduceColumnCount() {
val newColumnCount = --(launchers_grid.layoutManager as MyGridLayoutManager).spanCount val newColumnCount = --(binding.launchersGrid.layoutManager as MyGridLayoutManager).spanCount
if (portrait) { if (portrait) {
config.portraitColumnCnt = newColumnCount config.portraitColumnCnt = newColumnCount
} else { } else {
@ -237,7 +245,7 @@ class MainActivity : SimpleActivity(), LauncherAdapterUpdateListener {
} }
private fun setupGridLayoutManager() { private fun setupGridLayoutManager() {
val layoutManager = launchers_grid.layoutManager as MyGridLayoutManager val layoutManager = binding.launchersGrid.layoutManager as MyGridLayoutManager
if (portrait) { if (portrait) {
layoutManager.spanCount = config.portraitColumnCnt layoutManager.spanCount = config.portraitColumnCnt
} else { } else {
@ -246,7 +254,7 @@ class MainActivity : SimpleActivity(), LauncherAdapterUpdateListener {
} }
private fun initZoomListener() { private fun initZoomListener() {
val layoutManager = launchers_grid.layoutManager as MyGridLayoutManager val layoutManager = binding.launchersGrid.layoutManager as MyGridLayoutManager
zoomListener = object : MyRecyclerView.MyZoomListener { zoomListener = object : MyRecyclerView.MyZoomListener {
override fun zoomIn() { override fun zoomIn() {
if (layoutManager.spanCount > 1) { if (layoutManager.spanCount > 1) {
@ -283,7 +291,7 @@ class MainActivity : SimpleActivity(), LauncherAdapterUpdateListener {
} }
override fun refreshItems() { override fun refreshItems() {
main_menu.closeSearch() binding.mainMenu.closeSearch()
setupLaunchers() setupLaunchers()
} }
@ -308,23 +316,27 @@ class MainActivity : SimpleActivity(), LauncherAdapterUpdateListener {
} }
private fun setupEmptyView() { private fun setupEmptyView() {
val properPrimaryColor = getProperPrimaryColor() binding.noItemsPlaceholder2.apply {
no_items_placeholder_2.underlineText() val properPrimaryColor = getProperPrimaryColor()
no_items_placeholder_2.setTextColor(properPrimaryColor) underlineText()
no_items_placeholder_2.setOnClickListener { setTextColor(properPrimaryColor)
fabClicked() setOnClickListener {
fabClicked()
}
} }
} }
private fun maybeShowEmptyView() { private fun maybeShowEmptyView() {
if (getGridAdapter()?.launchers?.isEmpty() == true) { binding.apply {
launchers_fastscroller.beGone() if (getGridAdapter()?.launchers?.isEmpty() == true) {
no_items_placeholder_2.beVisibleIf(main_menu.getCurrentQuery().isEmpty()) launchersFastscroller.beGone()
no_items_placeholder.beVisible() noItemsPlaceholder2.beVisibleIf(mainMenu.getCurrentQuery().isEmpty())
} else { noItemsPlaceholder.beVisible()
no_items_placeholder_2.beGone() } else {
no_items_placeholder.beGone() noItemsPlaceholder2.beGone()
launchers_fastscroller.beVisible() noItemsPlaceholder.beGone()
launchersFastscroller.beVisible()
}
} }
} }

View File

@ -1,79 +1,93 @@
package com.simplemobiletools.applauncher.activities package com.simplemobiletools.applauncher.activities
import android.os.Bundle import android.os.Bundle
import com.simplemobiletools.applauncher.R import com.simplemobiletools.applauncher.databinding.ActivitySettingsBinding
import com.simplemobiletools.applauncher.extensions.config import com.simplemobiletools.applauncher.extensions.config
import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.NavigationIcon import com.simplemobiletools.commons.helpers.NavigationIcon
import com.simplemobiletools.commons.helpers.isTiramisuPlus import com.simplemobiletools.commons.helpers.isTiramisuPlus
import kotlinx.android.synthetic.main.activity_settings.* import java.util.Locale
import java.util.*
import kotlin.system.exitProcess import kotlin.system.exitProcess
class SettingsActivity : SimpleActivity() { class SettingsActivity : SimpleActivity() {
private val binding by lazy(LazyThreadSafetyMode.NONE) { ActivitySettingsBinding.inflate(layoutInflater) }
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
isMaterialActivity = true isMaterialActivity = true
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.activity_settings) setContentView(binding.root)
updateMaterialActivityViews(settings_coordinator, settings_holder, useTransparentNavigation = true, useTopSearchMenu = false) binding.apply {
setupMaterialScrollListener(settings_nested_scrollview, settings_toolbar) updateMaterialActivityViews(settingsCoordinator, settingsHolder, useTransparentNavigation = true, useTopSearchMenu = false)
setupMaterialScrollListener(settingsNestedScrollview, settingsToolbar)
}
} }
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
setupToolbar(settings_toolbar, NavigationIcon.Arrow) setupToolbar(binding.settingsToolbar, NavigationIcon.Arrow)
setupPurchaseThankYou() setupPurchaseThankYou()
setupCustomizeColors() setupCustomizeColors()
setupUseEnglish() setupUseEnglish()
setupLanguage() setupLanguage()
setupCloseApp() setupCloseApp()
updateTextColors(settings_holder) updateTextColors(binding.settingsHolder)
arrayOf(settings_color_customization_section_label, settings_general_settings_label).forEach { binding.apply {
it.setTextColor(getProperPrimaryColor()) arrayOf(settingsColorCustomizationSectionLabel, settingsGeneralSettingsLabel).forEach {
it.setTextColor(getProperPrimaryColor())
}
} }
} }
private fun setupPurchaseThankYou() { private fun setupPurchaseThankYou() {
settings_purchase_thank_you_holder.beGoneIf(isOrWasThankYouInstalled()) binding.settingsPurchaseThankYouHolder.apply {
settings_purchase_thank_you_holder.setOnClickListener { beGoneIf(isOrWasThankYouInstalled())
launchPurchaseThankYouIntent() setOnClickListener {
launchPurchaseThankYouIntent()
}
} }
} }
private fun setupCustomizeColors() { private fun setupCustomizeColors() {
settings_color_customization_label.text = getCustomizeColorsString() binding.apply {
settings_color_customization_holder.setOnClickListener { settingsColorCustomizationLabel.text = getCustomizeColorsString()
handleCustomizeColorsClick() settingsColorCustomizationHolder.setOnClickListener {
handleCustomizeColorsClick()
}
} }
} }
private fun setupUseEnglish() { private fun setupUseEnglish() {
settings_use_english_holder.beVisibleIf((config.wasUseEnglishToggled || Locale.getDefault().language != "en") && !isTiramisuPlus()) binding.apply {
settings_use_english.isChecked = config.useEnglish settingsUseEnglishHolder.beVisibleIf((config.wasUseEnglishToggled || Locale.getDefault().language != "en") && !isTiramisuPlus())
settings_use_english_holder.setOnClickListener { settingsUseEnglish.isChecked = config.useEnglish
settings_use_english.toggle() settingsUseEnglishHolder.setOnClickListener {
config.useEnglish = settings_use_english.isChecked settingsUseEnglish.toggle()
exitProcess(0) config.useEnglish = settingsUseEnglish.isChecked
exitProcess(0)
}
} }
} }
private fun setupLanguage() { private fun setupLanguage() {
settings_language.text = Locale.getDefault().displayLanguage binding.apply {
settings_language_holder.beVisibleIf(isTiramisuPlus()) settingsLanguage.text = Locale.getDefault().displayLanguage
settings_language_holder.setOnClickListener { settingsLanguageHolder.beVisibleIf(isTiramisuPlus())
launchChangeAppLanguageIntent() settingsLanguageHolder.setOnClickListener {
launchChangeAppLanguageIntent()
}
} }
} }
private fun setupCloseApp() { private fun setupCloseApp() {
settings_close_app.isChecked = config.closeApp binding.apply {
settings_close_app_holder.setOnClickListener { settingsCloseApp.isChecked = config.closeApp
settings_close_app.toggle() settingsCloseAppHolder.setOnClickListener {
config.closeApp = settings_close_app.isChecked settingsCloseApp.toggle()
config.closeApp = settingsCloseApp.isChecked
}
} }
} }
} }

View File

@ -1,18 +1,17 @@
package com.simplemobiletools.applauncher.adapters package com.simplemobiletools.applauncher.adapters
import android.app.Activity import android.app.Activity
import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView 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.applauncher.models.AppLauncher
import com.simplemobiletools.commons.extensions.getProperPrimaryColor import com.simplemobiletools.commons.extensions.getProperPrimaryColor
import com.simplemobiletools.commons.extensions.getProperTextColor import com.simplemobiletools.commons.extensions.getProperTextColor
import kotlinx.android.synthetic.main.item_add_launcher.view.*
class AddLaunchersAdapter(activity: Activity, val allLaunchers: ArrayList<AppLauncher>, val shownLaunchers: ArrayList<AppLauncher>) : class AddLaunchersAdapter(activity: Activity, val allLaunchers: ArrayList<AppLauncher>, val shownLaunchers: ArrayList<AppLauncher>) :
RecyclerView.Adapter<AddLaunchersAdapter.ViewHolder>() { RecyclerView.Adapter<AddLaunchersAdapter.ViewHolder>() {
private var layoutInflater = activity.layoutInflater
private var textColor = activity.getProperTextColor() private var textColor = activity.getProperTextColor()
private var adjustedPrimaryColor = activity.getProperPrimaryColor() private var adjustedPrimaryColor = activity.getProperPrimaryColor()
private var selectedKeys = HashSet<Int>() private var selectedKeys = HashSet<Int>()
@ -42,8 +41,7 @@ class AddLaunchersAdapter(activity: Activity, val allLaunchers: ArrayList<AppLau
} }
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val view = LayoutInflater.from(parent.context).inflate(R.layout.item_add_launcher, parent, false) return ViewHolder(ItemAddLauncherBinding.inflate(layoutInflater, parent, false).root)
return ViewHolder(view)
} }
override fun getItemCount() = allLaunchers.size override fun getItemCount() = allLaunchers.size
@ -53,16 +51,16 @@ class AddLaunchersAdapter(activity: Activity, val allLaunchers: ArrayList<AppLau
inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) { inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
fun bindView(launcher: AppLauncher): View { fun bindView(launcher: AppLauncher): View {
val isSelected = isKeySelected(launcher.packageName.hashCode()) val isSelected = isKeySelected(launcher.packageName.hashCode())
itemView.apply { ItemAddLauncherBinding.bind(itemView).apply {
launcher_checkbox.apply { launcherCheckbox.apply {
isChecked = isSelected isChecked = isSelected
text = launcher.title text = launcher.title
setColors(textColor, adjustedPrimaryColor, 0) setColors(textColor, adjustedPrimaryColor, 0)
} }
launcher_icon.setImageDrawable(launcher.drawable!!) launcherIcon.setImageDrawable(launcher.drawable!!)
setOnClickListener { viewClicked(launcher) } root.setOnClickListener { viewClicked(launcher) }
setOnLongClickListener { viewClicked(launcher); true } root.setOnLongClickListener { viewClicked(launcher); true }
} }
return itemView return itemView

View File

@ -1,15 +1,18 @@
package com.simplemobiletools.applauncher.adapters package com.simplemobiletools.applauncher.adapters
import android.view.Menu import android.view.*
import android.view.MotionEvent import android.widget.FrameLayout
import android.view.View import android.widget.ImageView
import android.view.ViewGroup import android.widget.TextView
import androidx.recyclerview.widget.ItemTouchHelper import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import androidx.viewbinding.ViewBinding
import com.qtalk.recyclerviewfastscroller.RecyclerViewFastScroller import com.qtalk.recyclerviewfastscroller.RecyclerViewFastScroller
import com.simplemobiletools.applauncher.LauncherAdapterUpdateListener import com.simplemobiletools.applauncher.LauncherAdapterUpdateListener
import com.simplemobiletools.applauncher.R import com.simplemobiletools.applauncher.R
import com.simplemobiletools.applauncher.activities.SimpleActivity import com.simplemobiletools.applauncher.activities.SimpleActivity
import com.simplemobiletools.applauncher.databinding.ItemLauncherLabelBinding
import com.simplemobiletools.applauncher.databinding.ItemLauncherNoLabelBinding
import com.simplemobiletools.applauncher.dialogs.EditDialog import com.simplemobiletools.applauncher.dialogs.EditDialog
import com.simplemobiletools.applauncher.extensions.config import com.simplemobiletools.applauncher.extensions.config
import com.simplemobiletools.applauncher.extensions.dbHelper import com.simplemobiletools.applauncher.extensions.dbHelper
@ -23,7 +26,6 @@ import com.simplemobiletools.commons.interfaces.ItemMoveCallback
import com.simplemobiletools.commons.interfaces.ItemTouchHelperContract import com.simplemobiletools.commons.interfaces.ItemTouchHelperContract
import com.simplemobiletools.commons.interfaces.StartReorderDragListener import com.simplemobiletools.commons.interfaces.StartReorderDragListener
import com.simplemobiletools.commons.views.MyRecyclerView import com.simplemobiletools.commons.views.MyRecyclerView
import kotlinx.android.synthetic.main.item_launcher_label.view.*
import java.util.* import java.util.*
class LaunchersAdapter( class LaunchersAdapter(
@ -72,19 +74,15 @@ class LaunchersAdapter(
} }
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val layoutId = if (activity.config.showAppName) { val binding = Binding.getByAppConfig(activity.config.showAppName).inflate(layoutInflater, parent, false)
R.layout.item_launcher_label
} else {
R.layout.item_launcher_no_label
}
return createViewHolder(layoutId, parent) return createViewHolder(binding.root)
} }
override fun onBindViewHolder(holder: ViewHolder, position: Int) { override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val launcher = launchers[position] val launcher = launchers[position]
holder.bindView(launcher, true, true) { itemView, adapterPosition -> holder.bindView(launcher, true, true) { itemView, adapterPosition ->
setupView(itemView, launcher, holder) setupView(Binding.getByAppConfig(activity.config.showAppName).bind(itemView), launcher, holder)
} }
bindViewHolder(holder) bindViewHolder(holder)
} }
@ -185,14 +183,14 @@ class LaunchersAdapter(
} }
} }
private fun setupView(view: View, launcher: AppLauncher, holder: ViewHolder) { private fun setupView(binding: ItemViewBinding, launcher: AppLauncher, holder: ViewHolder) {
view.apply { binding.apply {
val isSelected = selectedKeys.contains(launcher.packageName.hashCode()) val isSelected = selectedKeys.contains(launcher.packageName.hashCode())
launcher_check?.beInvisibleIf(!isSelected) launcherCheck?.beInvisibleIf(!isSelected)
launcher_label?.text = launcher.title launcherLabel?.text = launcher.title
launcher_label?.setTextColor(textColor) launcherLabel?.setTextColor(textColor)
launcher_label?.beVisibleIf(activity.config.showAppName) launcherLabel?.beVisibleIf(activity.config.showAppName)
launcher_icon.setImageDrawable(launcher.drawable!!) launcherIcon.setImageDrawable(launcher.drawable!!)
val bottomPadding = if (activity.config.showAppName) { val bottomPadding = if (activity.config.showAppName) {
0 0
@ -200,11 +198,11 @@ class LaunchersAdapter(
iconPadding iconPadding
} }
launcher_icon.setPadding(iconPadding, iconPadding, iconPadding, bottomPadding) launcherIcon.setPadding(iconPadding, iconPadding, iconPadding, bottomPadding)
launcher_drag_handle.beVisibleIf(isChangingOrder) launcherDragHandle.beVisibleIf(isChangingOrder)
if (isChangingOrder) { if (isChangingOrder) {
launcher_drag_handle.applyColorFilter(textColor) launcherDragHandle.applyColorFilter(textColor)
launcher_drag_handle.setOnTouchListener { v, event -> launcherDragHandle.setOnTouchListener { v, event ->
if (event.action == MotionEvent.ACTION_DOWN) { if (event.action == MotionEvent.ACTION_DOWN) {
startReorderDragListener.requestDrag(holder) startReorderDragListener.requestDrag(holder)
} }
@ -213,7 +211,7 @@ class LaunchersAdapter(
} }
if (isSelected) { if (isSelected) {
launcher_check?.background?.applyColorFilter(properPrimaryColor) launcherCheck?.background?.applyColorFilter(properPrimaryColor)
} }
} }
} }
@ -238,4 +236,64 @@ class LaunchersAdapter(
override fun onRowSelected(myViewHolder: ViewHolder?) {} override fun onRowSelected(myViewHolder: ViewHolder?) {}
override fun onChange(position: Int) = launchers.getOrNull(position)?.getBubbleText() ?: "" 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
}
} }

View File

@ -1,15 +1,14 @@
package com.simplemobiletools.applauncher.dialogs package com.simplemobiletools.applauncher.dialogs
import android.app.Activity import android.app.Activity
import android.view.ViewGroup
import com.simplemobiletools.applauncher.R import com.simplemobiletools.applauncher.R
import com.simplemobiletools.applauncher.adapters.AddLaunchersAdapter import com.simplemobiletools.applauncher.adapters.AddLaunchersAdapter
import com.simplemobiletools.applauncher.databinding.DialogAddLaunchersBinding
import com.simplemobiletools.applauncher.extensions.dbHelper import com.simplemobiletools.applauncher.extensions.dbHelper
import com.simplemobiletools.applauncher.models.AppLauncher import com.simplemobiletools.applauncher.models.AppLauncher
import com.simplemobiletools.commons.extensions.areSystemAnimationsEnabled import com.simplemobiletools.commons.extensions.areSystemAnimationsEnabled
import com.simplemobiletools.commons.extensions.getAlertDialogBuilder import com.simplemobiletools.commons.extensions.getAlertDialogBuilder
import com.simplemobiletools.commons.extensions.setupDialogStuff import com.simplemobiletools.commons.extensions.setupDialogStuff
import kotlinx.android.synthetic.main.dialog_add_launchers.view.*
class AddLaunchersDialog( class AddLaunchersDialog(
val activity: Activity, val activity: Activity,
@ -17,20 +16,21 @@ class AddLaunchersDialog(
val shownLaunchers: ArrayList<AppLauncher>, val shownLaunchers: ArrayList<AppLauncher>,
val callback: () -> Unit val callback: () -> Unit
) { ) {
private var view = (activity.layoutInflater.inflate(R.layout.dialog_add_launchers, null) as ViewGroup)
private var adapter: AddLaunchersAdapter? = null private var adapter: AddLaunchersAdapter? = null
init { init {
val binding = DialogAddLaunchersBinding.inflate(activity.layoutInflater)
activity.getAlertDialogBuilder() activity.getAlertDialogBuilder()
.setPositiveButton(R.string.ok) { dialogInterface, i -> confirmSelection() } .setPositiveButton(R.string.ok) { dialogInterface, i -> confirmSelection() }
.setNegativeButton(R.string.cancel, null) .setNegativeButton(R.string.cancel, null)
.apply { .apply {
activity.setupDialogStuff(view, this) { activity.setupDialogStuff(binding.root, this) {
adapter = AddLaunchersAdapter(activity, allLaunchers, shownLaunchers) adapter = AddLaunchersAdapter(activity, allLaunchers, shownLaunchers)
view.add_launchers_holder.adapter = adapter binding.addLaunchersHolder.adapter = adapter
if (activity.areSystemAnimationsEnabled) { if (activity.areSystemAnimationsEnabled) {
view.add_launchers_holder.scheduleLayoutAnimation() binding.addLaunchersHolder.scheduleLayoutAnimation()
} }
} }
} }

View File

@ -1,6 +1,7 @@
package com.simplemobiletools.applauncher.dialogs package com.simplemobiletools.applauncher.dialogs
import com.simplemobiletools.applauncher.R import com.simplemobiletools.applauncher.R
import com.simplemobiletools.applauncher.databinding.DialogChangeSortingBinding
import com.simplemobiletools.applauncher.extensions.config import com.simplemobiletools.applauncher.extensions.config
import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.extensions.beGoneIf 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_CUSTOM
import com.simplemobiletools.commons.helpers.SORT_BY_TITLE import com.simplemobiletools.commons.helpers.SORT_BY_TITLE
import com.simplemobiletools.commons.helpers.SORT_DESCENDING 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) { class ChangeSortingDialog(val activity: BaseSimpleActivity, private val callback: () -> Unit) {
private var currSorting = 0 private var currSorting = 0
private var config = activity.config 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 { init {
activity.getAlertDialogBuilder() activity.getAlertDialogBuilder()
.setPositiveButton(R.string.ok) { dialog, which -> dialogConfirmed() } .setPositiveButton(R.string.ok) { dialog, which -> dialogConfirmed() }
.setNegativeButton(R.string.cancel, null) .setNegativeButton(R.string.cancel, null)
.apply { .apply {
activity.setupDialogStuff(view, this, R.string.sort_by) activity.setupDialogStuff(binding.root, this, R.string.sort_by)
} }
currSorting = config.sorting currSorting = config.sorting
@ -30,38 +30,38 @@ class ChangeSortingDialog(val activity: BaseSimpleActivity, private val callback
} }
private fun setupSortRadio() { private fun setupSortRadio() {
val sortingRadio = view.sorting_dialog_radio_sorting binding.apply {
sortingRadio.setOnCheckedChangeListener { group, checkedId -> sortingDialogRadioSorting.setOnCheckedChangeListener { group, checkedId ->
val isCustomSorting = checkedId == sortingRadio.sorting_dialog_radio_custom.id val isCustomSorting = checkedId == sortingDialogRadioCustom.id
view.sorting_dialog_radio_order.beGoneIf(isCustomSorting) sortingDialogRadioOrder.beGoneIf(isCustomSorting)
view.sorting_dialog_divider.beGoneIf(isCustomSorting) sortingDialogDivider.beGoneIf(isCustomSorting)
}
} }
val sortBtn = when { val sortBtn = when {
currSorting and SORT_BY_TITLE != 0 -> sortingRadio.sorting_dialog_radio_title currSorting and SORT_BY_TITLE != 0 -> binding.sortingDialogRadioTitle
else -> sortingRadio.sorting_dialog_radio_custom else -> binding.sortingDialogRadioCustom
} }
sortBtn.isChecked = true sortBtn.isChecked = true
} }
private fun setupOrderRadio() { private fun setupOrderRadio() {
val orderRadio = view.sorting_dialog_radio_order var orderBtn = binding.sortingDialogRadioAscending
var orderBtn = orderRadio.sorting_dialog_radio_ascending
if (currSorting and SORT_DESCENDING != 0) { if (currSorting and SORT_DESCENDING != 0) {
orderBtn = orderRadio.sorting_dialog_radio_descending orderBtn = binding.sortingDialogRadioDescending
} }
orderBtn.isChecked = true orderBtn.isChecked = true
} }
private fun dialogConfirmed() { private fun dialogConfirmed() {
val sortingRadio = view.sorting_dialog_radio_sorting val sortingRadio = binding.sortingDialogRadioSorting
var sorting = when (sortingRadio.checkedRadioButtonId) { var sorting = when (sortingRadio.checkedRadioButtonId) {
R.id.sorting_dialog_radio_title -> SORT_BY_TITLE R.id.sorting_dialog_radio_title -> SORT_BY_TITLE
else -> SORT_BY_CUSTOM 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 sorting = sorting or SORT_DESCENDING
} }

View File

@ -2,27 +2,26 @@ package com.simplemobiletools.applauncher.dialogs
import android.app.Activity import android.app.Activity
import android.app.AlertDialog import android.app.AlertDialog
import android.view.ViewGroup
import com.simplemobiletools.applauncher.R import com.simplemobiletools.applauncher.R
import com.simplemobiletools.applauncher.databinding.DialogEditLauncherBinding
import com.simplemobiletools.applauncher.extensions.dbHelper import com.simplemobiletools.applauncher.extensions.dbHelper
import com.simplemobiletools.applauncher.models.AppLauncher import com.simplemobiletools.applauncher.models.AppLauncher
import com.simplemobiletools.commons.extensions.* 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) { class EditDialog(val activity: Activity, val appLauncher: AppLauncher, val callback: () -> Unit) {
init { init {
val view = (activity.layoutInflater.inflate(R.layout.dialog_edit_launcher, null) as ViewGroup) val binding = DialogEditLauncherBinding.inflate(activity.layoutInflater)
view.edit_launcher_edittext.setText(appLauncher.title)
binding.editLauncherEdittext.setText(appLauncher.title)
activity.getAlertDialogBuilder() activity.getAlertDialogBuilder()
.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.rename) { alertDialog -> activity.setupDialogStuff(binding.root, this, R.string.rename) { alertDialog ->
alertDialog.showKeyboard(view.edit_launcher_edittext) alertDialog.showKeyboard(binding.editLauncherEdittext)
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener { alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
val newName = view.edit_launcher_edittext.value val newName = binding.editLauncherEdittext.value
if (!newName.isEmpty()) { if (!newName.isEmpty()) {
if (activity.dbHelper.updateLauncherName(appLauncher.id, newName)) { if (activity.dbHelper.updateLauncherName(appLauncher.id, newName)) {
callback() callback()