mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-01-17 11:28:06 +00:00
Added main color theme selector in settings
This commit is contained in:
parent
fdafcfd7a4
commit
f048b895b5
15 changed files with 170 additions and 7 deletions
|
|
@ -41,7 +41,6 @@
|
|||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:label="@string/app_name"
|
||||
android:enableOnBackInvokedCallback="true"
|
||||
android:theme="@style/Theme.Linphone"
|
||||
android:localeConfig="@xml/locales_config"
|
||||
tools:targetApi="34">
|
||||
|
||||
|
|
|
|||
|
|
@ -137,6 +137,13 @@ class CorePreferences @UiThread constructor(private val context: Context) {
|
|||
config.setInt("app", "dark_mode", value)
|
||||
}
|
||||
|
||||
@get:WorkerThread @set:WorkerThread
|
||||
var themeMainColor: String
|
||||
get() = config.getString("ui", "theme_main_color", "orange")!!
|
||||
set(value) {
|
||||
config.setString("ui", "theme_main_color", value)
|
||||
}
|
||||
|
||||
@get:WorkerThread @set:WorkerThread
|
||||
var linphoneConfigurationVersion: Int
|
||||
get() = config.getInt("app", "config_version", 50200)
|
||||
|
|
@ -148,6 +155,10 @@ class CorePreferences @UiThread constructor(private val context: Context) {
|
|||
val darkModeAllowed: Boolean
|
||||
get() = config.getBool("ui", "dark_mode_allowed", true)
|
||||
|
||||
@get:WorkerThread
|
||||
val changeMainColorAllowed: Boolean
|
||||
get() = config.getBool("ui", "change_main_color_allowed", true)
|
||||
|
||||
@get:WorkerThread
|
||||
val onlyDisplaySipUriUsername: Boolean
|
||||
get() = config.getBool("ui", "only_display_sip_uri_username", false)
|
||||
|
|
|
|||
|
|
@ -21,9 +21,11 @@ package org.linphone.ui
|
|||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.res.Configuration
|
||||
import android.content.res.Resources
|
||||
import android.os.Bundle
|
||||
import android.view.ViewGroup
|
||||
import androidx.annotation.DrawableRes
|
||||
import androidx.annotation.MainThread
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.view.WindowCompat
|
||||
import androidx.core.view.children
|
||||
|
|
@ -32,12 +34,14 @@ import kotlinx.coroutines.Dispatchers
|
|||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.linphone.LinphoneApplication.Companion.corePreferences
|
||||
import org.linphone.R
|
||||
import org.linphone.compatibility.Compatibility
|
||||
import org.linphone.core.tools.Log
|
||||
import org.linphone.utils.ToastUtils
|
||||
import org.linphone.utils.slideInToastFromTop
|
||||
import org.linphone.utils.slideInToastFromTopForDuration
|
||||
|
||||
@MainThread
|
||||
open class GenericActivity : AppCompatActivity() {
|
||||
companion object {
|
||||
private const val TAG = "[Generic Activity]"
|
||||
|
|
@ -45,6 +49,16 @@ open class GenericActivity : AppCompatActivity() {
|
|||
|
||||
private lateinit var toastsArea: ViewGroup
|
||||
|
||||
override fun getTheme(): Resources.Theme {
|
||||
val mainColor = corePreferences.themeMainColor
|
||||
val theme = super.getTheme()
|
||||
when (mainColor) {
|
||||
"yellow" -> theme.applyStyle(R.style.Theme_LinphoneYellow, true)
|
||||
else -> theme.applyStyle(R.style.Theme_Linphone, true)
|
||||
}
|
||||
return theme
|
||||
}
|
||||
|
||||
@SuppressLint("SourceLockedOrientationActivity")
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
WindowCompat.setDecorFitsSystemWindows(window, true)
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ package org.linphone.ui.call
|
|||
import android.Manifest
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.content.res.Resources
|
||||
import android.os.Bundle
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.annotation.UiThread
|
||||
|
|
@ -39,6 +40,7 @@ import com.google.android.material.bottomsheet.BottomSheetDialogFragment
|
|||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import org.linphone.LinphoneApplication.Companion.coreContext
|
||||
import org.linphone.LinphoneApplication.Companion.corePreferences
|
||||
import org.linphone.R
|
||||
import org.linphone.compatibility.Compatibility
|
||||
import org.linphone.core.tools.Log
|
||||
|
|
@ -94,6 +96,16 @@ class CallActivity : GenericActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
override fun getTheme(): Resources.Theme {
|
||||
val mainColor = corePreferences.themeMainColor
|
||||
val theme = super.getTheme()
|
||||
when (mainColor) {
|
||||
"yellow" -> theme.applyStyle(R.style.Theme_LinphoneInCallYellow, true)
|
||||
else -> theme.applyStyle(R.style.Theme_LinphoneInCall, true)
|
||||
}
|
||||
return theme
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
|
|
|
|||
|
|
@ -75,6 +75,22 @@ class SettingsFragment : GenericFragment() {
|
|||
}
|
||||
}
|
||||
|
||||
private val colorListener = object : AdapterView.OnItemSelectedListener {
|
||||
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
|
||||
val label = viewModel.availableColorsNames[position]
|
||||
val value = viewModel.availableColorsValues[position]
|
||||
Log.i("$TAG Selected color is now [$label] ($value)")
|
||||
// Be carefull not to create an infinite loop
|
||||
if (value != viewModel.color.value.orEmpty()) {
|
||||
viewModel.setColor(value)
|
||||
requireActivity().recreate()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onNothingSelected(parent: AdapterView<*>?) {
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
|
|
@ -169,9 +185,24 @@ class SettingsFragment : GenericFragment() {
|
|||
binding.userInterfaceSettings.themeSpinner.setSelection(
|
||||
viewModel.availableThemesValues.indexOf(theme)
|
||||
)
|
||||
binding.userInterfaceSettings.themeSpinner.onItemSelectedListener = themeListener
|
||||
}
|
||||
|
||||
binding.userInterfaceSettings.themeSpinner.onItemSelectedListener = themeListener
|
||||
// Choose main color
|
||||
val colorAdapter = ArrayAdapter(
|
||||
requireContext(),
|
||||
R.layout.drop_down_item,
|
||||
viewModel.availableColorsNames
|
||||
)
|
||||
colorAdapter.setDropDownViewResource(R.layout.generic_dropdown_cell)
|
||||
binding.userInterfaceSettings.colorSpinner.adapter = colorAdapter
|
||||
|
||||
viewModel.color.observe(viewLifecycleOwner) { color ->
|
||||
binding.userInterfaceSettings.colorSpinner.setSelection(
|
||||
viewModel.availableColorsValues.indexOf(color)
|
||||
)
|
||||
binding.userInterfaceSettings.colorSpinner.onItemSelectedListener = colorListener
|
||||
}
|
||||
|
||||
startPostponedEnterTransition()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -115,6 +115,14 @@ class SettingsViewModel @UiThread constructor() : ViewModel() {
|
|||
)
|
||||
val availableThemesValues = arrayListOf(-1, 0, 1)
|
||||
|
||||
val showColorSelector = MutableLiveData<Boolean>()
|
||||
val color = MutableLiveData<String>()
|
||||
val availableColorsNames = arrayListOf(
|
||||
"Orange",
|
||||
"Yellow"
|
||||
)
|
||||
val availableColorsValues = arrayListOf("orange", "yellow")
|
||||
|
||||
// Advanced settings
|
||||
val keepAliveThirdPartyAccountsService = MutableLiveData<Boolean>()
|
||||
|
||||
|
|
@ -126,6 +134,7 @@ class SettingsViewModel @UiThread constructor() : ViewModel() {
|
|||
showMeetingsSettings.postValue(!corePreferences.disableMeetings)
|
||||
ldapAvailable.postValue(core.ldapAvailable())
|
||||
showThemeSelector.postValue(corePreferences.darkModeAllowed)
|
||||
showColorSelector.postValue(corePreferences.changeMainColorAllowed)
|
||||
}
|
||||
showContactsSettings.value = true
|
||||
|
||||
|
|
@ -160,6 +169,7 @@ class SettingsViewModel @UiThread constructor() : ViewModel() {
|
|||
defaultLayout.postValue(core.defaultConferenceLayout.toInt())
|
||||
|
||||
theme.postValue(corePreferences.darkMode)
|
||||
color.postValue(corePreferences.themeMainColor)
|
||||
|
||||
keepAliveThirdPartyAccountsService.postValue(corePreferences.keepServiceAlive)
|
||||
|
||||
|
|
@ -355,9 +365,18 @@ class SettingsViewModel @UiThread constructor() : ViewModel() {
|
|||
fun setTheme(themeValue: Int) {
|
||||
coreContext.postOnCoreThread {
|
||||
corePreferences.darkMode = themeValue
|
||||
Log.i("$TAG Theme [$theme] saved")
|
||||
theme.postValue(themeValue)
|
||||
Log.i("$TAG Theme [$themeValue] saved")
|
||||
}
|
||||
theme.value = themeValue
|
||||
}
|
||||
|
||||
@UiThread
|
||||
fun setColor(colorName: String) {
|
||||
coreContext.postOnCoreThread {
|
||||
corePreferences.themeMainColor = colorName
|
||||
Log.i("$TAG Color [$colorName] saved")
|
||||
}
|
||||
color.value = colorName
|
||||
}
|
||||
|
||||
@UiThread
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
|
||||
<corners android:radius="48dp" />
|
||||
<solid android:color="@color/orange_main_100_alpha_50"/>
|
||||
<solid android:color="?attr/color_main1_100_alpha_50"/>
|
||||
</shape>
|
||||
|
|
@ -251,7 +251,6 @@
|
|||
android:text="@string/settings_user_interface_title"
|
||||
android:drawableEnd="@{viewModel.expandUserInterface ? @drawable/caret_up : @drawable/caret_down, default=@drawable/caret_up}"
|
||||
android:drawableTint="?attr/color_main2_600"
|
||||
android:visibility="@{viewModel.showThemeSelector ? View.VISIBLE : View.GONE}"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/network_settings"/>
|
||||
|
|
@ -264,7 +263,7 @@
|
|||
android:layout_marginTop="8dp"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:visibility="@{viewModel.showThemeSelector && viewModel.expandUserInterface ? View.VISIBLE : View.GONE}"
|
||||
android:visibility="@{viewModel.expandUserInterface ? View.VISIBLE : View.GONE}"
|
||||
app:layout_constraintTop_toBottomOf="@id/user_interface"
|
||||
bind:viewModel="@{viewModel}"/>
|
||||
|
||||
|
|
|
|||
|
|
@ -16,6 +16,18 @@
|
|||
android:paddingBottom="20dp"
|
||||
android:background="@drawable/shape_squircle_white_background">
|
||||
|
||||
<androidx.constraintlayout.widget.Group
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="@{viewModel.showThemeSelector ? View.VISIBLE : View.GONE}"
|
||||
app:constraint_referenced_ids="theme_spinner, theme_spinner_caret, theme_title" />
|
||||
|
||||
<androidx.constraintlayout.widget.Group
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="@{viewModel.showColorSelector ? View.VISIBLE : View.GONE}"
|
||||
app:constraint_referenced_ids="color_spinner, color_spinner_caret, color_title" />
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
style="@style/settings_title_style"
|
||||
android:id="@+id/theme_title"
|
||||
|
|
@ -57,6 +69,47 @@
|
|||
app:layout_constraintBottom_toBottomOf="@id/theme_spinner"
|
||||
app:layout_constraintEnd_toEndOf="@id/theme_spinner"/>
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
style="@style/settings_title_style"
|
||||
android:id="@+id/color_title"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="20dp"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginEnd="10dp"
|
||||
android:text="@string/settings_user_interface_color_title"
|
||||
android:maxLines="2"
|
||||
android:ellipsize="end"
|
||||
app:layout_constraintTop_toBottomOf="@id/theme_spinner"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"/>
|
||||
|
||||
<androidx.appcompat.widget.AppCompatSpinner
|
||||
style="@style/material_switch_style"
|
||||
android:id="@+id/color_spinner"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="50dp"
|
||||
android:layout_marginEnd="10dp"
|
||||
android:background="@drawable/edit_text_background"
|
||||
android:paddingStart="@dimen/spinner_start_padding"
|
||||
android:paddingEnd="@dimen/spinner_end_padding"
|
||||
android:overlapAnchor="false"
|
||||
android:spinnerMode="dropdown"
|
||||
android:popupBackground="@drawable/shape_squircle_white_background"
|
||||
app:layout_constraintTop_toBottomOf="@id/color_title"
|
||||
app:layout_constraintStart_toStartOf="@id/color_title"
|
||||
app:layout_constraintEnd_toEndOf="@id/color_title" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/color_spinner_caret"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="@dimen/spinner_caret_end_margin"
|
||||
android:src="@drawable/caret_down"
|
||||
app:layout_constraintTop_toTopOf="@id/color_spinner"
|
||||
app:layout_constraintBottom_toBottomOf="@id/color_spinner"
|
||||
app:layout_constraintEnd_toEndOf="@id/color_spinner"/>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
</layout>
|
||||
|
|
@ -258,6 +258,7 @@
|
|||
<string name="settings_user_interface_dark_theme_label">Sombre</string>
|
||||
<string name="settings_user_interface_light_theme_label">Clair</string>
|
||||
<string name="settings_user_interface_auto_theme_label">Auto</string>
|
||||
<string name="settings_user_interface_color_title">Couleur principale</string>
|
||||
|
||||
<string name="settings_advanced_title">Paramètres avancés</string>
|
||||
<string name="settings_advanced_keep_alive_service_title">Garder l\'app en vie via un Service</string>
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
<item name="android:navigationBarColor">@color/black</item>
|
||||
|
||||
<item name="color_main1_100">@color/orange_main_900</item>
|
||||
<item name="color_main1_100_alpha_50">@color/orange_main_100_alpha_50</item>
|
||||
<item name="color_main1_300">@color/orange_main_300</item>
|
||||
<item name="color_main1_500">@color/orange_main_500</item>
|
||||
<item name="color_main1_700">@color/orange_main_700</item>
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@
|
|||
|
||||
<declare-styleable name="LinphoneAppTheme">
|
||||
<attr name="color_main1_100" format="color"/>
|
||||
<attr name="color_main1_100_alpha_50" format="color"/>
|
||||
<attr name="color_main1_300" format="color"/>
|
||||
<attr name="color_main1_500" format="color"/>
|
||||
<attr name="color_main1_700" format="color"/>
|
||||
|
|
|
|||
|
|
@ -66,4 +66,10 @@
|
|||
|
||||
<color name="gradient_start">#FF923F</color>
|
||||
<color name="gradient_progress">#80FFFFFF</color>
|
||||
|
||||
<color name="yellow_main_100">#FFE799</color>
|
||||
<color name="yellow_main_100_alpha_50">#80FFE799</color>
|
||||
<color name="yellow_main_300">#FFDE70</color>
|
||||
<color name="yellow_main_500">#FFD23F</color>
|
||||
<color name="yellow_main_700">#FFCB1F</color>
|
||||
</resources>
|
||||
|
|
@ -293,6 +293,7 @@
|
|||
<string name="settings_user_interface_dark_theme_label">Dark theme</string>
|
||||
<string name="settings_user_interface_light_theme_label">Light theme</string>
|
||||
<string name="settings_user_interface_auto_theme_label">Auto</string>
|
||||
<string name="settings_user_interface_color_title">Main color</string>
|
||||
|
||||
<string name="settings_advanced_title">Advanced settings</string>
|
||||
<string name="settings_advanced_keep_alive_service_title">Keep app alive using Service</string>
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
<item name="android:navigationBarColor">@color/white</item>
|
||||
|
||||
<item name="color_main1_100">@color/orange_main_100</item>
|
||||
<item name="color_main1_100_alpha_50">@color/orange_main_100_alpha_50</item>
|
||||
<item name="color_main1_300">@color/orange_main_300</item>
|
||||
<item name="color_main1_500">@color/orange_main_500</item>
|
||||
<item name="color_main1_700">@color/orange_main_700</item>
|
||||
|
|
@ -56,12 +57,26 @@
|
|||
<item name="color_on_main">@color/white</item>
|
||||
</style>
|
||||
|
||||
<style name="Theme.LinphoneYellow" parent="Theme.Linphone">
|
||||
<item name="android:statusBarColor">@color/yellow_main_500</item>
|
||||
<item name="color_main1_100">@color/yellow_main_100</item>
|
||||
<item name="color_main1_100_alpha_50">@color/yellow_main_100_alpha_50</item>
|
||||
<item name="color_main1_300">@color/yellow_main_300</item>
|
||||
<item name="color_main1_500">@color/yellow_main_500</item>
|
||||
<item name="color_main1_700">@color/yellow_main_700</item>
|
||||
</style>
|
||||
|
||||
<!-- In-call application theme. -->
|
||||
<style name="Theme.LinphoneInCall" parent="Theme.Linphone">
|
||||
<item name="android:navigationBarColor">@color/gray_600</item>
|
||||
<item name="android:windowBackground">@color/black</item>
|
||||
</style>
|
||||
|
||||
<style name="Theme.LinphoneInCallYellow" parent="Theme.LinphoneYellow">
|
||||
<item name="android:navigationBarColor">@color/gray_600</item>
|
||||
<item name="android:windowBackground">@color/black</item>
|
||||
</style>
|
||||
|
||||
<style name="Theme.LinphoneDialog" parent="Theme.Linphone">
|
||||
<item name="android:windowAnimationStyle">@null</item>
|
||||
<item name="android:windowBackground">@color/transparent_color</item>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue