adding Settings activity

This commit is contained in:
tibbi 2022-01-15 22:13:41 +01:00
parent de80cb7e23
commit eea7e1c035
5 changed files with 178 additions and 5 deletions

View file

@ -49,6 +49,11 @@
android:label="@string/about" android:label="@string/about"
android:parentActivityName=".activities.MainActivity" /> android:parentActivityName=".activities.MainActivity" />
<activity
android:name="com.simplemobiletools.commons.activities.CustomizationActivity"
android:label="@string/customize_colors"
android:parentActivityName=".activities.SettingsActivity" />
<activity-alias <activity-alias
android:name=".activities.SplashActivity.Red" android:name=".activities.SplashActivity.Red"
android:enabled="false" android:enabled="false"

View file

@ -1,9 +1,13 @@
package com.simplemobiletools.keyboard.activities package com.simplemobiletools.keyboard.activities
import android.os.Bundle import android.os.Bundle
import com.simplemobiletools.commons.extensions.appLaunched import android.view.Menu
import com.simplemobiletools.keyboard.BuildConfig import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.keyboard.R import com.simplemobiletools.keyboard.R
import com.simplemobiletools.keyboard.extensions.config
import kotlinx.android.synthetic.main.activity_settings.*
import java.util.*
import kotlin.system.exitProcess
class SettingsActivity : SimpleActivity() { class SettingsActivity : SimpleActivity() {
@ -11,4 +15,65 @@ class SettingsActivity : SimpleActivity() {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.activity_settings) setContentView(R.layout.activity_settings)
} }
override fun onResume() {
super.onResume()
setupPurchaseThankYou()
setupCustomizeColors()
setupUseEnglish()
updateTextColors(settings_scrollview)
arrayOf(settings_color_customization_label, settings_general_settings_label).forEach {
it.setTextColor(getAdjustedPrimaryColor())
}
arrayOf(settings_color_customization_holder, settings_general_settings_holder).forEach {
it.background.applyColorFilter(baseConfig.backgroundColor.getContrastColor())
}
}
override fun onCreateOptionsMenu(menu: Menu): Boolean {
updateMenuItemColors(menu)
return super.onCreateOptionsMenu(menu)
}
private fun setupPurchaseThankYou() {
settings_purchase_thank_you_holder.beGoneIf(isOrWasThankYouInstalled())
// make sure the corners at ripple fit the stroke rounded corners
if (settings_purchase_thank_you_holder.isGone()) {
settings_use_english_holder.background = resources.getDrawable(R.drawable.ripple_all_corners, theme)
}
settings_purchase_thank_you_holder.setOnClickListener {
handleCustomizeColorsClick()
}
}
private fun setupCustomizeColors() {
settings_customize_colors_label.text = getCustomizeColorsString()
settings_customize_colors_holder.setOnClickListener {
handleCustomizeColorsClick()
}
}
private fun setupUseEnglish() {
settings_use_english_holder.beVisibleIf(config.wasUseEnglishToggled || Locale.getDefault().language != "en")
settings_use_english.isChecked = config.useEnglish
if (settings_use_english_holder.isGone() && settings_purchase_thank_you_holder.isGone()) {
settings_general_settings_label.beGone()
settings_general_settings_holder.beGone()
} else if (settings_use_english_holder.isGone()) {
settings_purchase_thank_you_holder.background = resources.getDrawable(R.drawable.ripple_all_corners, theme)
}
settings_use_english_holder.setOnClickListener {
settings_use_english.toggle()
config.useEnglish = settings_use_english.isChecked
exitProcess(0)
}
}
} }

View file

@ -0,0 +1,6 @@
package com.simplemobiletools.keyboard.extensions
import android.content.Context
import com.simplemobiletools.keyboard.helpers.Config
val Context.config: Config get() = Config.newInstance(applicationContext)

View file

@ -0,0 +1,10 @@
package com.simplemobiletools.keyboard.helpers
import android.content.Context
import com.simplemobiletools.commons.helpers.BaseConfig
class Config(context: Context) : BaseConfig(context) {
companion object {
fun newInstance(context: Context) = Config(context)
}
}

View file

@ -1,6 +1,93 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/settings_scrollview"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="wrap_content">
</androidx.coordinatorlayout.widget.CoordinatorLayout> <LinearLayout
android:id="@+id/settings_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/settings_color_customization_label"
style="@style/SettingsSectionLabelStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/color_customization" />
<LinearLayout
android:id="@+id/settings_color_customization_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/medium_margin"
android:background="@drawable/section_holder_stroke"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/settings_customize_colors_holder"
style="@style/SettingsHolderTextViewOneLinerStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/ripple_all_corners">
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/settings_customize_colors_label"
style="@style/SettingsTextLabelStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/customize_colors" />
</RelativeLayout>
</LinearLayout>
<TextView
android:id="@+id/settings_general_settings_label"
style="@style/SettingsSectionLabelStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/general_settings" />
<LinearLayout
android:id="@+id/settings_general_settings_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/medium_margin"
android:background="@drawable/section_holder_stroke"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/settings_purchase_thank_you_holder"
style="@style/SettingsHolderTextViewOneLinerStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/ripple_top_corners">
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/settings_purchase_thank_you"
style="@style/SettingsTextLabelStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/purchase_simple_thank_you" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/settings_use_english_holder"
style="@style/SettingsHolderCheckboxStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/ripple_bottom_corners">
<com.simplemobiletools.commons.views.MyAppCompatCheckbox
android:id="@+id/settings_use_english"
style="@style/SettingsCheckboxStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/use_english_language" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>