migrate activities kotlin synthetic to viewbinding

This commit is contained in:
fatih ergin 2023-08-15 23:53:43 +03:00
parent bcf0676fc7
commit 8e2e41c086
2 changed files with 41 additions and 31 deletions

View File

@ -7,35 +7,36 @@ import com.simplemobiletools.commons.models.FAQItem
import com.simplemobiletools.commons.models.Release import com.simplemobiletools.commons.models.Release
import com.simplemobiletools.thankyou.BuildConfig import com.simplemobiletools.thankyou.BuildConfig
import com.simplemobiletools.thankyou.R import com.simplemobiletools.thankyou.R
import kotlinx.android.synthetic.main.activity_main.* import com.simplemobiletools.thankyou.databinding.ActivityMainBinding
class MainActivity : SimpleActivity() { class MainActivity : SimpleActivity() {
private val binding by viewBinding(ActivityMainBinding::inflate)
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)
refreshMenuItems() refreshMenuItems()
setupOptionsMenu() setupOptionsMenu()
checkWhatsNewDialog() checkWhatsNewDialog()
updateMaterialActivityViews(main_coordinator, activity_main, useTransparentNavigation = true, useTopSearchMenu = false) updateMaterialActivityViews(binding.mainCoordinator, binding.activityMain, useTransparentNavigation = true, useTopSearchMenu = false)
} }
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
updateTextColors(activity_main) updateTextColors(binding.activityMain)
setupToolbar(main_toolbar, statusBarColor = getProperBackgroundColor()) setupToolbar(binding.mainToolbar, statusBarColor = getProperBackgroundColor())
} }
private fun refreshMenuItems() { private fun refreshMenuItems() {
main_toolbar.menu.apply { binding.mainToolbar.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_toolbar.setOnMenuItemClickListener { menuItem -> binding.mainToolbar.setOnMenuItemClickListener { menuItem ->
when (menuItem.itemId) { when (menuItem.itemId) {
R.id.more_apps_from_us -> launchMoreAppsFromUsIntent() R.id.more_apps_from_us -> launchMoreAppsFromUsIntent()
R.id.settings -> launchSettings() R.id.settings -> launchSettings()

View File

@ -7,63 +7,72 @@ import com.simplemobiletools.commons.helpers.NavigationIcon
import com.simplemobiletools.commons.helpers.isTiramisuPlus import com.simplemobiletools.commons.helpers.isTiramisuPlus
import com.simplemobiletools.thankyou.BuildConfig import com.simplemobiletools.thankyou.BuildConfig
import com.simplemobiletools.thankyou.R import com.simplemobiletools.thankyou.R
import com.simplemobiletools.thankyou.databinding.ActivitySettingsBinding
import com.simplemobiletools.thankyou.extensions.config import com.simplemobiletools.thankyou.extensions.config
import kotlinx.android.synthetic.main.activity_settings.* import java.util.Locale
import java.util.*
class SettingsActivity : SimpleActivity() { class SettingsActivity : SimpleActivity() {
private val binding by viewBinding(ActivitySettingsBinding::inflate)
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)
setupCustomizeColors() setupCustomizeColors()
setupUseEnglish() setupUseEnglish()
setupLanguage() setupLanguage()
setupHideLauncherIcon() setupHideLauncherIcon()
updateTextColors(settings_nested_scrollview) updateTextColors(binding.settingsNestedScrollview)
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 setupCustomizeColors() { private fun setupCustomizeColors() {
settings_color_customization_holder.setOnClickListener { binding.settingsColorCustomizationHolder.setOnClickListener {
startCustomizationActivity() startCustomizationActivity()
} }
} }
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()
System.exit(0) config.useEnglish = settingsUseEnglish.isChecked
System.exit(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 setupHideLauncherIcon() { private fun setupHideLauncherIcon() {
settings_hide_launcher_icon.isChecked = config.hideLauncherIcon binding.settingsHideLauncherIcon.isChecked = config.hideLauncherIcon
settings_hide_launcher_icon_holder.setOnClickListener { binding.settingsHideLauncherIconHolder.setOnClickListener {
if (config.hideLauncherIcon) { if (config.hideLauncherIcon) {
toggleHideLauncherIcon() toggleHideLauncherIcon()
} else { } else {
@ -75,8 +84,8 @@ class SettingsActivity : SimpleActivity() {
} }
private fun toggleHideLauncherIcon() { private fun toggleHideLauncherIcon() {
settings_hide_launcher_icon.toggle() binding.settingsHideLauncherIcon.toggle()
config.hideLauncherIcon = settings_hide_launcher_icon.isChecked config.hideLauncherIcon = binding.settingsHideLauncherIcon.isChecked
val appId = BuildConfig.APPLICATION_ID val appId = BuildConfig.APPLICATION_ID
getAppIconColors().forEachIndexed { index, color -> getAppIconColors().forEachIndexed { index, color ->