From 5ffc2046bfdafd5bb080b085eef54bd12a1a1141 Mon Sep 17 00:00:00 2001 From: angrezichatterbox Date: Sun, 25 Aug 2024 19:19:15 +0530 Subject: [PATCH] feat:Migrated from Kotlin Synthetics to Jetpack View-Binding feat:Migrated from Kotlin Synthetics to Jetpack View-Binding --- app/build.gradle | 10 ++-- .../java/be/scri/activities/AboutActivity.kt | 10 +++- .../java/be/scri/activities/MainActivity.kt | 23 +++---- .../be/scri/activities/SettingsActivity.kt | 22 +++++-- .../be/scri/dialogs/AppSideloadedDialog.kt | 10 ++-- .../dialogs/ConfirmationAdvancedDialog.kt | 7 ++- .../be/scri/dialogs/ConfirmationDialog.kt | 8 ++- .../dialogs/CustomIntervalPickerDialog.kt | 53 ++++++++-------- .../java/be/scri/dialogs/RadioGroupDialog.kt | 11 ++-- .../be/scri/dialogs/WritePermissionDialog.kt | 29 ++++----- .../main/java/be/scri/extensions/Activity.kt | 24 +++++--- .../be/scri/services/SimpleKeyboardIME.kt | 11 ++-- .../main/java/be/scri/views/MyKeyboardView.kt | 60 ++++++++++++++----- .../BottomActionMenuItemPopup.kt | 18 +++--- app/src/main/res/layout/activity_settings.xml | 3 +- gradle.properties | 1 - 16 files changed, 183 insertions(+), 117 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 7b420aa3..fc8f17ce 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,6 +1,5 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' -apply plugin: 'kotlin-android-extensions' apply plugin: 'kotlin-kapt' def keystorePropertiesFile = rootProject.file("keystore.properties") @@ -11,9 +10,12 @@ if (keystorePropertiesFile.exists()) { android { compileSdk 34 + buildFeatures { viewBinding = true + buildConfig true } + defaultConfig { applicationId "be.scri" minSdk 26 @@ -58,12 +60,13 @@ android { sourceSets { main.java.srcDirs += 'src/main/kotlin' } + lint { abortOnError false checkReleaseBuilds false } - namespace 'be.scri' + namespace 'be.scri' } dependencies { @@ -98,7 +101,6 @@ dependencies { annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0' } - task moveFromi18n { def locales = ['de','es','sv','en-US'] @@ -125,5 +127,3 @@ task moveFromi18n { tasks.named('preBuild').configure { dependsOn tasks.named('moveFromi18n') } - - diff --git a/app/src/main/java/be/scri/activities/AboutActivity.kt b/app/src/main/java/be/scri/activities/AboutActivity.kt index e01c11ea..d8670efb 100644 --- a/app/src/main/java/be/scri/activities/AboutActivity.kt +++ b/app/src/main/java/be/scri/activities/AboutActivity.kt @@ -9,8 +9,8 @@ import android.view.MotionEvent import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import com.google.android.material.bottomnavigation.BottomNavigationView -import kotlinx.android.synthetic.main.activity_about.* import be.scri.R +import be.scri.databinding.ActivityAboutBinding import be.scri.extensions.* import be.scri.helpers.* import be.scri.models.ItemsViewModel @@ -27,6 +27,8 @@ class AboutActivity : BaseSimpleActivity(), GestureDetector.OnGestureListener{ private val SWIPE_THRESHOLD = 100 private val SWIPE_VELOCITY_THRESHOLD = 100 + private lateinit var binding: ActivityAboutBinding + private lateinit var gestureDetector: GestureDetector private val swipeThreshold = 100 private val swipeVelocityThreshold = 100 @@ -38,7 +40,9 @@ class AboutActivity : BaseSimpleActivity(), GestureDetector.OnGestureListener{ override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - setContentView(R.layout.activity_about) + binding = ActivityAboutBinding.inflate(layoutInflater) + val view = binding.root + setContentView(view) gestureDetector = GestureDetector(this) setupRecyclerViews() appName = intent.getStringExtra(APP_NAME) ?: "" @@ -142,7 +146,7 @@ class AboutActivity : BaseSimpleActivity(), GestureDetector.OnGestureListener{ override fun onResume() { super.onResume() - updateTextColors(about_scrollview) + updateTextColors(binding.aboutScrollview) } override fun onCreateOptionsMenu(menu: Menu): Boolean { diff --git a/app/src/main/java/be/scri/activities/MainActivity.kt b/app/src/main/java/be/scri/activities/MainActivity.kt index 8b191d71..9e9301fa 100644 --- a/app/src/main/java/be/scri/activities/MainActivity.kt +++ b/app/src/main/java/be/scri/activities/MainActivity.kt @@ -7,17 +7,14 @@ import android.graphics.drawable.LayerDrawable import android.graphics.drawable.RippleDrawable import android.os.Bundle import android.provider.Settings -import android.util.Log import android.view.GestureDetector -import android.view.Menu -import android.view.MenuItem import android.view.MotionEvent import android.view.inputmethod.InputMethodManager import androidx.appcompat.app.AppCompatDelegate import com.google.android.material.bottomnavigation.BottomNavigationView -import kotlinx.android.synthetic.main.activity_main.* import be.scri.BuildConfig import be.scri.R +import be.scri.databinding.ActivityMainBinding import be.scri.dialogs.ConfirmationAdvancedDialog import be.scri.extensions.* import be.scri.helpers.LICENSE_GSON @@ -28,11 +25,14 @@ class MainActivity : SimpleActivity(), GestureDetector.OnGestureListener { private lateinit var gestureDetector: GestureDetector private val swipeThreshold = 100 private val swipeVelocityThreshold = 100 + private lateinit var binding: ActivityMainBinding override fun onCreate(savedInstanceState: Bundle?) { + binding = ActivityMainBinding.inflate(layoutInflater) applyUserDarkModePreference() + val view = binding.root + setContentView(view) super.onCreate(savedInstanceState) - setContentView(R.layout.activity_main) appLaunched(BuildConfig.APPLICATION_ID) gestureDetector = GestureDetector(this) @@ -60,7 +60,7 @@ class MainActivity : SimpleActivity(), GestureDetector.OnGestureListener { false }) - scribe_key.setOnClickListener { + binding.scribeKey.setOnClickListener { (getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager).showInputMethodPicker() } } @@ -75,6 +75,9 @@ class MainActivity : SimpleActivity(), GestureDetector.OnGestureListener { if (isUserDarkMode) AppCompatDelegate.MODE_NIGHT_YES else AppCompatDelegate.MODE_NIGHT_NO ) + if (isUserDarkMode != (currentNightMode == Configuration.UI_MODE_NIGHT_YES)) { + recreate() + } } override fun onTouchEvent(event: MotionEvent): Boolean { @@ -100,9 +103,9 @@ class MainActivity : SimpleActivity(), GestureDetector.OnGestureListener { } } - updateTextColors(main_holder) + updateTextColors(binding.mainHolder) updateChangeKeyboardColor() - main_holder.setBackgroundColor(getProperBackgroundColor()) + binding.mainHolder.setBackgroundColor(getProperBackgroundColor()) } @@ -120,8 +123,8 @@ class MainActivity : SimpleActivity(), GestureDetector.OnGestureListener { private fun updateChangeKeyboardColor() { val applyBackground = resources.getDrawable(R.drawable.button_background_rounded, theme) as RippleDrawable (applyBackground as LayerDrawable).findDrawableByLayerId(R.id.button_background_holder).applyColorFilter(getProperPrimaryColor()) - change_keyboard.background = applyBackground - change_keyboard.setTextColor(getProperPrimaryColor().getContrastColor()) + binding.changeKeyboard.background = applyBackground + binding.changeKeyboard.setTextColor(getProperPrimaryColor().getContrastColor()) } private fun isKeyboardEnabled(): Boolean { diff --git a/app/src/main/java/be/scri/activities/SettingsActivity.kt b/app/src/main/java/be/scri/activities/SettingsActivity.kt index 7f26779e..e3447b0a 100644 --- a/app/src/main/java/be/scri/activities/SettingsActivity.kt +++ b/app/src/main/java/be/scri/activities/SettingsActivity.kt @@ -23,7 +23,6 @@ import be.scri.helpers.CustomAdapter import be.scri.models.SwitchItem import be.scri.models.TextItem import com.google.android.material.bottomnavigation.BottomNavigationView -import kotlinx.android.synthetic.main.activity_settings.settings_scrollview import kotlin.math.abs @@ -34,7 +33,6 @@ class SettingsActivity : SimpleActivity(), GestureDetector.OnGestureListener { private val swipeVelocityThreshold = 100 private lateinit var binding: ActivitySettingsBinding - override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivitySettingsBinding.inflate(layoutInflater) @@ -48,8 +46,7 @@ class SettingsActivity : SimpleActivity(), GestureDetector.OnGestureListener { val enabledInputMethods = imm.enabledInputMethodList for(inputMethod in enabledInputMethods) { if (inputMethod.packageName == "be.scri.debug") { - binding.btnInstall.visibility = View.INVISIBLE - binding.selectLanguage.visibility = View.VISIBLE + setupItemVisibility() } } binding.btnInstall.setOnClickListener { @@ -123,6 +120,13 @@ class SettingsActivity : SimpleActivity(), GestureDetector.OnGestureListener { } private fun setupRecyclerView2() { + val imm = getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager + val enabledInputMethods = imm.enabledInputMethodList + for(inputMethod in enabledInputMethods) { + if (inputMethod.packageName == "be.scri.debug") { + setupItemVisibility() + } + } val recyclerView = binding.recyclerView2 val adapter = CustomAdapter(getRecyclerViewElements(),this) recyclerView.layoutManager = LinearLayoutManager(this) @@ -188,7 +192,7 @@ class SettingsActivity : SimpleActivity(), GestureDetector.OnGestureListener { editor.putBoolean("dark_mode", false) editor.apply() AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO) - + recreate() } private fun darkMode(){ @@ -197,6 +201,7 @@ class SettingsActivity : SimpleActivity(), GestureDetector.OnGestureListener { editor.putBoolean("dark_mode", true) editor.apply() AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES) + recreate() } private fun enableVibrateOnKeypress() { @@ -232,9 +237,14 @@ class SettingsActivity : SimpleActivity(), GestureDetector.OnGestureListener { } + private fun setupItemVisibility() { + binding.btnInstall.visibility = View.INVISIBLE + binding.selectLanguage.visibility = View.VISIBLE + } override fun onResume() { super.onResume() - updateTextColors(settings_scrollview) + setupRecyclerView2() + updateTextColors(binding.settingsScrollview) } override fun onCreateOptionsMenu(menu: Menu): Boolean { diff --git a/app/src/main/java/be/scri/dialogs/AppSideloadedDialog.kt b/app/src/main/java/be/scri/dialogs/AppSideloadedDialog.kt index c3e0466f..9450b560 100644 --- a/app/src/main/java/be/scri/dialogs/AppSideloadedDialog.kt +++ b/app/src/main/java/be/scri/dialogs/AppSideloadedDialog.kt @@ -4,8 +4,8 @@ import android.app.Activity import android.text.Html import android.text.method.LinkMovementMethod import androidx.appcompat.app.AlertDialog -import kotlinx.android.synthetic.main.dialog_textview.view.* import be.scri.R +import be.scri.databinding.DialogTextviewBinding import be.scri.extensions.getStringsPackageName import be.scri.extensions.launchViewIntent import be.scri.extensions.setupDialogStuff @@ -13,14 +13,16 @@ import be.scri.extensions.setupDialogStuff class AppSideloadedDialog(val activity: Activity, val callback: () -> Unit) { private var dialog: AlertDialog private val url = "https://play.google.com/store/apps/details?id=${activity.getStringsPackageName()}" + private var binding: DialogTextviewBinding = DialogTextviewBinding.inflate(activity.layoutInflater) init { - val view = activity.layoutInflater.inflate(R.layout.dialog_textview, null).apply { + val view = binding.root.apply { val text = String.format(activity.getString(R.string.sideloaded_app), url) - text_view.text = Html.fromHtml(text) - text_view.movementMethod = LinkMovementMethod.getInstance() + binding.textView.text = Html.fromHtml(text) + binding.textView.movementMethod = LinkMovementMethod.getInstance() } + dialog = AlertDialog.Builder(activity) .setNegativeButton(R.string.cancel) { dialog, which -> negativePressed() } .setPositiveButton(R.string.download, null) diff --git a/app/src/main/java/be/scri/dialogs/ConfirmationAdvancedDialog.kt b/app/src/main/java/be/scri/dialogs/ConfirmationAdvancedDialog.kt index 4aa475cc..444c5349 100644 --- a/app/src/main/java/be/scri/dialogs/ConfirmationAdvancedDialog.kt +++ b/app/src/main/java/be/scri/dialogs/ConfirmationAdvancedDialog.kt @@ -2,8 +2,8 @@ package be.scri.dialogs import android.app.Activity import androidx.appcompat.app.AlertDialog -import kotlinx.android.synthetic.main.dialog_message.view.* import be.scri.R +import be.scri.databinding.DialogMessageBinding import be.scri.extensions.setupDialogStuff // similar fo ConfirmationDialog, but has a callback for negative button too @@ -16,10 +16,11 @@ class ConfirmationAdvancedDialog( val callback: (result: Boolean) -> Unit ) { var dialog: AlertDialog + private var binding: DialogMessageBinding = DialogMessageBinding.inflate(activity.layoutInflater) init { - val view = activity.layoutInflater.inflate(R.layout.dialog_message, null) - view.message.text = + val view = binding.root + binding.message.text = if (message.isEmpty()) activity.resources.getString(messageId) else message val builder = AlertDialog.Builder(activity) diff --git a/app/src/main/java/be/scri/dialogs/ConfirmationDialog.kt b/app/src/main/java/be/scri/dialogs/ConfirmationDialog.kt index fa71370e..dca18714 100644 --- a/app/src/main/java/be/scri/dialogs/ConfirmationDialog.kt +++ b/app/src/main/java/be/scri/dialogs/ConfirmationDialog.kt @@ -2,8 +2,8 @@ package be.scri.dialogs import android.app.Activity import androidx.appcompat.app.AlertDialog -import kotlinx.android.synthetic.main.dialog_message.view.* import be.scri.R +import be.scri.databinding.DialogMessageBinding import be.scri.extensions.setupDialogStuff /** @@ -21,10 +21,12 @@ class ConfirmationDialog( negative: Int = R.string.no, val cancelOnTouchOutside: Boolean = true, val callback: () -> Unit ) { var dialog: AlertDialog + private var binding: DialogMessageBinding = DialogMessageBinding.inflate(activity.layoutInflater) + init { - val view = activity.layoutInflater.inflate(R.layout.dialog_message, null) - view.message.text = if (message.isEmpty()) activity.resources.getString(messageId) else message + val view = binding.root + binding.message.text = if (message.isEmpty()) activity.resources.getString(messageId) else message val builder = AlertDialog.Builder(activity) .setPositiveButton(positive) { dialog, which -> dialogConfirmed() } diff --git a/app/src/main/java/be/scri/dialogs/CustomIntervalPickerDialog.kt b/app/src/main/java/be/scri/dialogs/CustomIntervalPickerDialog.kt index 298c315a..bc552a6d 100644 --- a/app/src/main/java/be/scri/dialogs/CustomIntervalPickerDialog.kt +++ b/app/src/main/java/be/scri/dialogs/CustomIntervalPickerDialog.kt @@ -1,10 +1,9 @@ package be.scri.dialogs import android.app.Activity -import android.view.ViewGroup import androidx.appcompat.app.AlertDialog -import kotlinx.android.synthetic.main.dialog_custom_interval_picker.view.* import be.scri.R +import be.scri.databinding.DialogCustomIntervalPickerBinding import be.scri.extensions.* import be.scri.helpers.DAY_SECONDS import be.scri.helpers.HOUR_SECONDS @@ -12,28 +11,34 @@ import be.scri.helpers.MINUTE_SECONDS class CustomIntervalPickerDialog(val activity: Activity, val selectedSeconds: Int = 0, val showSeconds: Boolean = false, val callback: (minutes: Int) -> Unit) { var dialog: AlertDialog - var view = (activity.layoutInflater.inflate(R.layout.dialog_custom_interval_picker, null) as ViewGroup) + private var binding: DialogCustomIntervalPickerBinding = DialogCustomIntervalPickerBinding.inflate(activity.layoutInflater) + var view = binding.root init { view.apply { - dialog_radio_seconds.beVisibleIf(showSeconds) - when { - selectedSeconds == 0 -> dialog_radio_view.check(R.id.dialog_radio_minutes) - selectedSeconds % DAY_SECONDS == 0 -> { - dialog_radio_view.check(R.id.dialog_radio_days) - dialog_custom_interval_value.setText((selectedSeconds / DAY_SECONDS).toString()) - } - selectedSeconds % HOUR_SECONDS == 0 -> { - dialog_radio_view.check(R.id.dialog_radio_hours) - dialog_custom_interval_value.setText((selectedSeconds / HOUR_SECONDS).toString()) - } - selectedSeconds % MINUTE_SECONDS == 0 -> { - dialog_radio_view.check(R.id.dialog_radio_minutes) - dialog_custom_interval_value.setText((selectedSeconds / MINUTE_SECONDS).toString()) - } - else -> { - dialog_radio_view.check(R.id.dialog_radio_seconds) - dialog_custom_interval_value.setText(selectedSeconds.toString()) + binding.apply { + dialogRadioSeconds.beVisibleIf(showSeconds) + when { + selectedSeconds == 0 -> dialogRadioView.check(R.id.dialog_radio_minutes) + selectedSeconds % DAY_SECONDS == 0 -> { + dialogRadioView.check(R.id.dialog_radio_days) + dialogCustomIntervalValue.setText((selectedSeconds / DAY_SECONDS).toString()) + } + + selectedSeconds % HOUR_SECONDS == 0 -> { + dialogRadioView.check(R.id.dialog_radio_hours) + dialogCustomIntervalValue.setText((selectedSeconds / HOUR_SECONDS).toString()) + } + + selectedSeconds % MINUTE_SECONDS == 0 -> { + dialogRadioView.check(R.id.dialog_radio_minutes) + dialogCustomIntervalValue.setText((selectedSeconds / MINUTE_SECONDS).toString()) + } + + else -> { + dialogRadioView.check(R.id.dialog_radio_seconds) + dialogCustomIntervalValue.setText(selectedSeconds.toString()) + } } } } @@ -43,14 +48,14 @@ class CustomIntervalPickerDialog(val activity: Activity, val selectedSeconds: In .setNegativeButton(R.string.cancel, null) .create().apply { activity.setupDialogStuff(view, this) { - showKeyboard(view.dialog_custom_interval_value) + showKeyboard(binding.dialogCustomIntervalValue) } } } private fun confirmReminder() { - val value = view.dialog_custom_interval_value.value - val multiplier = getMultiplier(view.dialog_radio_view.checkedRadioButtonId) + val value = binding.dialogCustomIntervalValue.value + val multiplier = getMultiplier(binding.dialogRadioView.checkedRadioButtonId) val minutes = Integer.valueOf(if (value.isEmpty()) "0" else value) callback(minutes * multiplier) activity.hideKeyboard() diff --git a/app/src/main/java/be/scri/dialogs/RadioGroupDialog.kt b/app/src/main/java/be/scri/dialogs/RadioGroupDialog.kt index 5fc9362e..8a0fd816 100644 --- a/app/src/main/java/be/scri/dialogs/RadioGroupDialog.kt +++ b/app/src/main/java/be/scri/dialogs/RadioGroupDialog.kt @@ -6,8 +6,8 @@ import android.view.ViewGroup import android.widget.RadioButton import android.widget.RadioGroup import androidx.appcompat.app.AlertDialog -import kotlinx.android.synthetic.main.dialog_radio_group.view.* import be.scri.R +import be.scri.databinding.DialogRadioGroupBinding import be.scri.extensions.onGlobalLayout import be.scri.extensions.setupDialogStuff import be.scri.models.RadioItem @@ -20,9 +20,10 @@ class RadioGroupDialog( private var wasInit = false private var selectedItemId = -1 + private var binding: DialogRadioGroupBinding = DialogRadioGroupBinding.inflate(activity.layoutInflater) init { - val view = activity.layoutInflater.inflate(R.layout.dialog_radio_group, null) - view.dialog_radio_group.apply { + val view = binding.root + binding.dialogRadioGroup.apply { for (i in 0 until items.size) { val radioButton = (activity.layoutInflater.inflate(R.layout.radio_button, null) as RadioButton).apply { text = items[i].title @@ -51,9 +52,9 @@ class RadioGroupDialog( } if (selectedItemId != -1) { - view.dialog_radio_holder.apply { + binding.dialogRadioHolder.apply { onGlobalLayout { - scrollY = view.dialog_radio_group.findViewById(selectedItemId).bottom - height + scrollY = binding.dialogRadioGroup.findViewById(selectedItemId).bottom - height } } } diff --git a/app/src/main/java/be/scri/dialogs/WritePermissionDialog.kt b/app/src/main/java/be/scri/dialogs/WritePermissionDialog.kt index 54b9e83f..963c427e 100644 --- a/app/src/main/java/be/scri/dialogs/WritePermissionDialog.kt +++ b/app/src/main/java/be/scri/dialogs/WritePermissionDialog.kt @@ -5,10 +5,10 @@ import android.text.Html import androidx.appcompat.app.AlertDialog import com.bumptech.glide.Glide import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions -import kotlinx.android.synthetic.main.dialog_write_permission.view.* -import kotlinx.android.synthetic.main.dialog_write_permission_otg.view.* import be.scri.R import be.scri.activities.BaseSimpleActivity +import be.scri.databinding.DialogWritePermissionBinding +import be.scri.databinding.DialogWritePermissionOtgBinding import be.scri.extensions.humanizePath import be.scri.extensions.setupDialogStuff @@ -19,39 +19,40 @@ class WritePermissionDialog(activity: Activity, val mode: Mode, val callback: () data class OpenDocumentTreeSDK30(val path: String) : Mode() object CreateDocumentSDK30 : Mode() } + private lateinit var otgBinding: DialogWritePermissionOtgBinding + private lateinit var binding: DialogWritePermissionBinding var dialog: AlertDialog init { - val layout = if (mode == Mode.SdCard) R.layout.dialog_write_permission else R.layout.dialog_write_permission_otg - val view = activity.layoutInflater.inflate(layout, null) + val view = if (mode == Mode.SdCard) binding.root else otgBinding.root val glide = Glide.with(activity) val crossFade = DrawableTransitionOptions.withCrossFade() when (mode) { Mode.Otg -> { - view.write_permissions_dialog_otg_text.setText(R.string.confirm_usb_storage_access_text) - glide.load(R.drawable.img_write_storage_otg).transition(crossFade).into(view.write_permissions_dialog_otg_image) + otgBinding.writePermissionsDialogOtgText.setText(R.string.confirm_usb_storage_access_text) + glide.load(R.drawable.img_write_storage_otg).transition(crossFade).into(otgBinding.writePermissionsDialogOtgImage) } Mode.SdCard -> { - glide.load(R.drawable.img_write_storage).transition(crossFade).into(view.write_permissions_dialog_image) - glide.load(R.drawable.img_write_storage_sd).transition(crossFade).into(view.write_permissions_dialog_image_sd) + glide.load(R.drawable.img_write_storage).transition(crossFade).into(binding.writePermissionsDialogImage) + glide.load(R.drawable.img_write_storage_sd).transition(crossFade).into(binding.writePermissionsDialogImageSd) } is Mode.OpenDocumentTreeSDK30 -> { val humanizedPath = activity.humanizePath(mode.path) - view.write_permissions_dialog_otg_text.text = + otgBinding.writePermissionsDialogOtgText.text = Html.fromHtml(activity.getString(R.string.confirm_storage_access_android_text_specific, humanizedPath)) - glide.load(R.drawable.img_write_storage_sdk_30).transition(crossFade).into(view.write_permissions_dialog_otg_image) + glide.load(R.drawable.img_write_storage_sdk_30).transition(crossFade).into(otgBinding.writePermissionsDialogOtgImage) - view.write_permissions_dialog_otg_image.setOnClickListener { + otgBinding.writePermissionsDialogOtgImage.setOnClickListener { dialogConfirmed() } } Mode.CreateDocumentSDK30 -> { - view.write_permissions_dialog_otg_text.text = Html.fromHtml(activity.getString(R.string.confirm_create_doc_for_new_folder_text)) - glide.load(R.drawable.img_write_storage_create_doc_sdk_30).transition(crossFade).into(view.write_permissions_dialog_otg_image) + otgBinding.writePermissionsDialogOtgText.text = Html.fromHtml(activity.getString(R.string.confirm_create_doc_for_new_folder_text)) + glide.load(R.drawable.img_write_storage_create_doc_sdk_30).transition(crossFade).into(otgBinding.writePermissionsDialogOtgImage) - view.write_permissions_dialog_otg_image.setOnClickListener { + otgBinding.writePermissionsDialogOtgImage.setOnClickListener { dialogConfirmed() } } diff --git a/app/src/main/java/be/scri/extensions/Activity.kt b/app/src/main/java/be/scri/extensions/Activity.kt index a637523b..56bfe7c5 100644 --- a/app/src/main/java/be/scri/extensions/Activity.kt +++ b/app/src/main/java/be/scri/extensions/Activity.kt @@ -35,9 +35,9 @@ import androidx.biometric.auth.AuthPromptHost import androidx.biometric.auth.Class2BiometricAuthPrompt import androidx.documentfile.provider.DocumentFile import androidx.fragment.app.FragmentActivity -import kotlinx.android.synthetic.main.dialog_title.view.* import be.scri.R import be.scri.activities.BaseSimpleActivity +import be.scri.databinding.DialogTitleBinding import be.scri.dialogs.* import be.scri.dialogs.WritePermissionDialog.Mode import be.scri.helpers.* @@ -49,6 +49,11 @@ import java.io.FileOutputStream import java.io.OutputStream import java.util.* + +private lateinit var binding: DialogTitleBinding + + + fun AppCompatActivity.updateActionBarTitle(text: String, color: Int = getProperStatusBarColor()) { val colorToUse = if (baseConfig.isUsingSystemTheme) { getProperTextColor() @@ -1327,7 +1332,7 @@ fun Activity.setupDialogStuff( if (isDestroyed || isFinishing) { return } - + binding = DialogTitleBinding.inflate(layoutInflater) val textColor = getProperTextColor() val backgroundColor = getProperBackgroundColor() val primaryColor = getProperPrimaryColor() @@ -1337,16 +1342,19 @@ fun Activity.setupDialogStuff( view.setColors(textColor, primaryColor, backgroundColor) } + var title: TextView? = null if (titleId != 0 || titleText.isNotEmpty()) { title = layoutInflater.inflate(R.layout.dialog_title, null) as TextView - title.dialog_title_textview.apply { - if (titleText.isNotEmpty()) { - text = titleText - } else { - setText(titleId) + binding.apply { + dialogTitleTextview.apply { + if (titleText.isNotEmpty()) { + text = titleText + } else { + setText(titleId) + } + setTextColor(textColor) } - setTextColor(textColor) } } diff --git a/app/src/main/java/be/scri/services/SimpleKeyboardIME.kt b/app/src/main/java/be/scri/services/SimpleKeyboardIME.kt index 812fcb2a..50432c91 100644 --- a/app/src/main/java/be/scri/services/SimpleKeyboardIME.kt +++ b/app/src/main/java/be/scri/services/SimpleKeyboardIME.kt @@ -7,7 +7,6 @@ import android.text.InputType.TYPE_CLASS_NUMBER import android.text.InputType.TYPE_CLASS_PHONE import android.text.InputType.TYPE_MASK_CLASS import android.text.TextUtils -import android.util.Log import android.view.KeyEvent import android.view.View import android.view.inputmethod.EditorInfo @@ -15,8 +14,8 @@ import android.view.inputmethod.EditorInfo.IME_ACTION_NONE import android.view.inputmethod.EditorInfo.IME_FLAG_NO_ENTER_ACTION import android.view.inputmethod.EditorInfo.IME_MASK_ACTION import android.view.inputmethod.ExtractedTextRequest -import kotlinx.android.synthetic.main.keyboard_view_keyboard.view.* import be.scri.R +import be.scri.databinding.KeyboardViewKeyboardBinding import be.scri.helpers.* import be.scri.views.MyKeyboardView @@ -38,6 +37,7 @@ abstract class SimpleKeyboardIME : InputMethodService(), MyKeyboardView.OnKeyboa private var enterKeyType = IME_ACTION_NONE private var switchToLetters = false private var hasTextBeforeCursor = false + private lateinit var binding: KeyboardViewKeyboardBinding override fun onInitializeInterface() { super.onInitializeInterface() @@ -62,10 +62,11 @@ abstract class SimpleKeyboardIME : InputMethodService(), MyKeyboardView.OnKeyboa } override fun onCreateInputView(): View { - val keyboardHolder = layoutInflater.inflate(R.layout.keyboard_view_keyboard, null) - keyboardView = keyboardHolder.keyboard_view as MyKeyboardView + binding = KeyboardViewKeyboardBinding.inflate(layoutInflater) + val keyboardHolder = binding.root + keyboardView = binding.keyboardView keyboardView!!.setKeyboard(keyboard!!) - keyboardView!!.setKeyboardHolder(keyboardHolder.keyboard_holder) + keyboardView!!.setKeyboardHolder(binding.keyboardHolder) keyboardView!!.mOnKeyboardActionListener = this return keyboardHolder!! } diff --git a/app/src/main/java/be/scri/views/MyKeyboardView.kt b/app/src/main/java/be/scri/views/MyKeyboardView.kt index db32b60e..25f4b57d 100644 --- a/app/src/main/java/be/scri/views/MyKeyboardView.kt +++ b/app/src/main/java/be/scri/views/MyKeyboardView.kt @@ -19,10 +19,10 @@ import android.view.accessibility.AccessibilityEvent import android.view.accessibility.AccessibilityManager import android.widget.PopupWindow import android.widget.TextView -import kotlinx.android.synthetic.main.keyboard_popup_keyboard.view.* -import kotlinx.android.synthetic.main.keyboard_view_keyboard.view.* import be.scri.R import be.scri.activities.SettingsActivity +import be.scri.databinding.KeyboardPopupKeyboardBinding +import be.scri.databinding.KeyboardViewKeyboardBinding import be.scri.extensions.* import be.scri.helpers.* import be.scri.helpers.MyKeyboard.Companion.KEYCODE_DELETE @@ -184,6 +184,23 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut } + private var _popupBinding: KeyboardPopupKeyboardBinding? = null + private val popupBinding: KeyboardPopupKeyboardBinding + get() { + if (_popupBinding == null) { + _popupBinding = KeyboardPopupKeyboardBinding.inflate(LayoutInflater.from(context)) + } + return _popupBinding!! + } + + private var _keyboardBinding: KeyboardViewKeyboardBinding? = null + private val keyboardBinding: KeyboardViewKeyboardBinding + get() { + if (_keyboardBinding == null) { + _keyboardBinding = KeyboardViewKeyboardBinding.inflate(LayoutInflater.from(context)) + } + return _keyboardBinding!! + } init { val attributes = context.obtainStyledAttributes(attrs, R.styleable.MyKeyboardView, 0, defStyleRes) val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater @@ -283,7 +300,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut mBackgroundColor } - if (changedView == mini_keyboard_view) { + if (changedView == _popupBinding?.miniKeyboardView) { val previewBackground = background as LayerDrawable previewBackground.findDrawableByLayerId(R.id.button_background_shape).applyColorFilter(miniKeyboardBackgroundColor) previewBackground.findDrawableByLayerId(R.id.button_background_stroke).applyColorFilter(strokeColor) @@ -294,11 +311,13 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut val wasDarkened = mBackgroundColor != mBackgroundColor.darkenColor() mToolbarHolder?.apply { - top_keyboard_divider.beGoneIf(wasDarkened) - top_keyboard_divider.background = ColorDrawable(strokeColor) + _keyboardBinding?.apply { + topKeyboardDivider.beGoneIf(wasDarkened) + topKeyboardDivider.background = ColorDrawable(strokeColor) - background = ColorDrawable(toolbarColor) - settings_cog.applyColorFilter(mTextColor) + background = ColorDrawable(toolbarColor) + settingsCog.applyColorFilter(mTextColor) + } } } } @@ -329,15 +348,24 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut /** Sets the top row above the keyboard containing Scribe command buttons **/ fun setKeyboardHolder(keyboardHolder: View) { - mToolbarHolder = keyboardHolder.command_field - - mToolbarHolder!!.apply { - settings_cog.setOnLongClickListener { context.toast(R.string.settings); true; } - settings_cog.setOnClickListener { - vibrateIfNeeded() - Intent(context, SettingsActivity::class.java).apply { - addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - context.startActivity(this) + mToolbarHolder = _keyboardBinding?.commandField + + mToolbarHolder?.let { toolbarHolder -> + _keyboardBinding?.let { binding -> + binding.settingsCog?.apply { + setOnLongClickListener { + context?.toast(R.string.settings) + true + } + setOnClickListener { + context?.let { ctx -> + vibrateIfNeeded() + Intent(ctx, SettingsActivity::class.java).apply { + addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + ctx.startActivity(this) + } + } + } } } } diff --git a/app/src/main/java/be/scri/views/bottomactionmenu/BottomActionMenuItemPopup.kt b/app/src/main/java/be/scri/views/bottomactionmenu/BottomActionMenuItemPopup.kt index 06b24a19..4c48dfe5 100644 --- a/app/src/main/java/be/scri/views/bottomactionmenu/BottomActionMenuItemPopup.kt +++ b/app/src/main/java/be/scri/views/bottomactionmenu/BottomActionMenuItemPopup.kt @@ -11,8 +11,8 @@ import android.widget.ListView import android.widget.PopupWindow import androidx.core.content.ContextCompat import androidx.core.widget.PopupWindowCompat -import kotlinx.android.synthetic.main.item_action_mode_popup.view.* import be.scri.R +import be.scri.databinding.ItemActionModePopupBinding import be.scri.extensions.applyColorFilter import be.scri.extensions.windowManager import be.scri.helpers.isRPlus @@ -32,34 +32,33 @@ class BottomActionMenuItemPopup( private val popupPaddingStart: Int private val popupPaddingEnd: Int private val popupPaddingTop: Int + private lateinit var binding: ItemActionModePopupBinding val isShowing: Boolean get() = popup.isShowing private val popupListAdapter = object : ArrayAdapter(context, R.layout.item_action_mode_popup, items) { override fun getView(position: Int, convertView: View?, parent: ViewGroup): View { - var view = convertView - if (view == null) { - view = LayoutInflater.from(context).inflate(R.layout.item_action_mode_popup, parent, false) - } + val binding = ItemActionModePopupBinding.inflate(LayoutInflater.from(context), parent, false) val item = items[position] - view!!.cab_item.text = item.title + binding.cabItem.text = item.title if (item.icon != View.NO_ID) { val icon = ContextCompat.getDrawable(context, item.icon) icon?.applyColorFilter(Color.WHITE) - view.cab_item.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null) + binding.cabItem.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null) } - view.setOnClickListener { + binding.root.setOnClickListener { onSelect.invoke(item) popup.dismiss() } - return view + return binding.root } } + init { popup.isFocusable = true popupMinWidth = context.resources.getDimensionPixelSize(R.dimen.cab_popup_menu_min_width) @@ -67,6 +66,7 @@ class BottomActionMenuItemPopup( popupPaddingEnd = context.resources.getDimensionPixelSize(R.dimen.smaller_margin) popupPaddingTop = context.resources.getDimensionPixelSize(R.dimen.smaller_margin) popupPaddingBottom = context.resources.getDimensionPixelSize(R.dimen.smaller_margin) + binding = ItemActionModePopupBinding.inflate(LayoutInflater.from(context)) } fun show(anchorView: View) { diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml index 247018b4..ce212d0a 100644 --- a/app/src/main/res/layout/activity_settings.xml +++ b/app/src/main/res/layout/activity_settings.xml @@ -57,7 +57,8 @@ android:text="@string/app.settings.installedKeyboards" android:textColor="@color/app_text_color" android:textSize="20sp" - android:textStyle="bold" /> + android:textStyle="bold" + android:visibility="invisible" />