Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate From Kotlin Synthetics to Jetpack Binding #69

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -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")
Expand All @@ -11,9 +10,12 @@ if (keystorePropertiesFile.exists()) {

android {
compileSdk 34

buildFeatures {
viewBinding = true
buildConfig true
}

defaultConfig {
applicationId "be.scri"
minSdk 26
Expand Down Expand Up @@ -58,12 +60,13 @@ android {
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}

lint {
abortOnError false
checkReleaseBuilds false
}
namespace 'be.scri'

namespace 'be.scri'
}

dependencies {
Expand Down Expand Up @@ -98,7 +101,6 @@ dependencies {
annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'
}


task moveFromi18n {
def locales = ['de','es','sv','en-US']

Expand All @@ -125,5 +127,3 @@ task moveFromi18n {
tasks.named('preBuild').configure {
dependsOn tasks.named('moveFromi18n')
}


10 changes: 7 additions & 3 deletions app/src/main/java/be/scri/activities/AboutActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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) ?: ""
Expand Down Expand Up @@ -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 {
Expand Down
23 changes: 13 additions & 10 deletions app/src/main/java/be/scri/activities/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand Down Expand Up @@ -60,7 +60,7 @@ class MainActivity : SimpleActivity(), GestureDetector.OnGestureListener {
false
})

scribe_key.setOnClickListener {
binding.scribeKey.setOnClickListener {
(getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager).showInputMethodPicker()
}
}
Expand All @@ -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 {
Expand All @@ -100,9 +103,9 @@ class MainActivity : SimpleActivity(), GestureDetector.OnGestureListener {
}
}

updateTextColors(main_holder)
updateTextColors(binding.mainHolder)
updateChangeKeyboardColor()
main_holder.setBackgroundColor(getProperBackgroundColor())
binding.mainHolder.setBackgroundColor(getProperBackgroundColor())
}


Expand All @@ -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 {
Expand Down
22 changes: 16 additions & 6 deletions app/src/main/java/be/scri/activities/SettingsActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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)
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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(){
Expand All @@ -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() {
Expand Down Expand Up @@ -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 {
Expand Down
10 changes: 6 additions & 4 deletions app/src/main/java/be/scri/dialogs/AppSideloadedDialog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,25 @@ 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

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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
8 changes: 5 additions & 3 deletions app/src/main/java/be/scri/dialogs/ConfirmationDialog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand All @@ -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() }
Expand Down
Loading
Loading