Skip to content

Commit

Permalink
New settings menu 'Appearance'
Browse files Browse the repository at this point in the history
  • Loading branch information
cintek committed Jan 20, 2023
1 parent 99eb443 commit 8d7481a
Show file tree
Hide file tree
Showing 12 changed files with 167 additions and 78 deletions.
1 change: 1 addition & 0 deletions changelog.d/7889.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
New settings "Appearance"
1 change: 1 addition & 0 deletions library/ui-strings/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1724,6 +1724,7 @@

<!-- Settings -->
<string name="settings_general_title">General</string>
<string name="settings_appearance_title">Appearance</string>
<string name="settings_preferences">Preferences</string>
<string name="settings_security_and_privacy">Security &amp; Privacy</string>
<string name="settings_push_rules">Push Rules</string>
Expand Down
1 change: 1 addition & 0 deletions vector-config/src/main/res/values/config-settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<!-- Level 0: Root -->

<bool name="settings_root_general_visible">true</bool>
<bool name="settings_root_appearance_visible">true</bool>
<bool name="settings_root_notification_visible">true</bool>
<bool name="settings_root_preferences_visible">true</bool>
<bool name="settings_root_voice_video_visible">true</bool>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,11 @@ data class MobileScreen(
*/
Settings,

/**
* The appearance settings screen.
*/
SettingsAppearance,

/**
* The advanced settings screen (developer mode, rageshake, push
* notification rules).
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* Copyright 2019 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

@file:Suppress("UNUSED_VARIABLE", "UNUSED_ANONYMOUS_PARAMETER", "UNUSED_PARAMETER")

package im.vector.app.features.settings

import android.content.Intent
import android.os.Bundle
import androidx.preference.Preference
import dagger.hilt.android.AndroidEntryPoint
import im.vector.app.R
import im.vector.app.core.extensions.restart
import im.vector.app.core.preference.VectorListPreference
import im.vector.app.core.preference.VectorPreference
import im.vector.app.features.VectorFeatures
import im.vector.app.features.analytics.plan.MobileScreen
import im.vector.app.features.settings.font.FontScaleSettingActivity
import im.vector.app.features.themes.ThemeUtils
import javax.inject.Inject

@AndroidEntryPoint
class VectorSettingsAppearanceFragment :
VectorSettingsBaseFragment() {

@Inject lateinit var vectorPreferences: VectorPreferences
@Inject lateinit var vectorFeatures: VectorFeatures
@Inject lateinit var fontScalePreferences: FontScalePreferences

override var titleRes = R.string.settings_appearance_title
override val preferenceXmlRes = R.xml.vector_settings_appearance

private val textSizePreference by lazy {
findPreference<VectorPreference>(VectorPreferences.SETTINGS_INTERFACE_TEXT_SIZE_KEY)!!
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
analyticsScreenName = MobileScreen.ScreenName.SettingsAppearance
}

override fun bindPref() {
// user interface preferences
setUserInterfacePreferences()

// Themes
findPreference<VectorListPreference>(ThemeUtils.APPLICATION_THEME_KEY)!!
.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, newValue ->
if (newValue is String) {
ThemeUtils.setApplicationTheme(requireContext().applicationContext, newValue)
// Restart the Activity
activity?.restart()
true
} else {
false
}
}
}

override fun onResume() {
super.onResume()
}

override fun onPause() {
super.onPause()
}

// ==============================================================================================================
// user interface management
// ==============================================================================================================

private fun setUserInterfacePreferences() {
// Text size
textSizePreference.summary = getString(fontScalePreferences.getResolvedFontScaleValue().nameResId)

textSizePreference.onPreferenceClickListener = Preference.OnPreferenceClickListener {
startActivity(Intent(activity, FontScaleSettingActivity::class.java))
true
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class VectorSettingsGeneralFragment :
override val preferenceXmlRes = R.xml.vector_settings_general

private lateinit var galleryOrCameraDialogHelper: GalleryOrCameraDialogHelper
@Inject lateinit var vectorLocale: VectorLocale

private val mUserSettingsCategory by lazy {
findPreference<PreferenceCategory>(VectorPreferences.SETTINGS_USER_SETTINGS_PREFERENCE_KEY)!!
Expand All @@ -98,6 +99,9 @@ class VectorSettingsGeneralFragment :
private val mPasswordPreference by lazy {
findPreference<VectorPreference>(VectorPreferences.SETTINGS_CHANGE_PASSWORD_PREFERENCE_KEY)!!
}
private val selectedLanguagePreference by lazy {
findPreference<VectorPreference>(VectorPreferences.SETTINGS_INTERFACE_LANGUAGE_PREFERENCE_KEY)!!
}
private val mIdentityServerPreference by lazy {
findPreference<VectorPreference>(VectorPreferences.SETTINGS_IDENTITY_SERVER_PREFERENCE_KEY)!!
}
Expand Down Expand Up @@ -161,6 +165,9 @@ class VectorSettingsGeneralFragment :
}

override fun bindPref() {
// user interface preferences
setUserInterfacePreferences()

// Avatar
mUserAvatarPreference.let {
it.onPreferenceClickListener = Preference.OnPreferenceClickListener {
Expand Down Expand Up @@ -498,4 +505,9 @@ class VectorSettingsGeneralFragment :
}
}
}

private fun setUserInterfacePreferences() {
// Selected language
selectedLanguagePreference.summary = vectorLocale.localeToLocalisedString(vectorLocale.applicationLocale)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,19 @@
package im.vector.app.features.settings

import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.lifecycle.lifecycleScope
import androidx.preference.Preference
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import dagger.hilt.android.AndroidEntryPoint
import im.vector.app.R
import im.vector.app.core.dialogs.PhotoOrVideoDialog
import im.vector.app.core.extensions.restart
import im.vector.app.core.preference.VectorListPreference
import im.vector.app.core.preference.VectorPreference
import im.vector.app.core.preference.VectorSwitchPreference
import im.vector.app.features.MainActivity
import im.vector.app.features.MainActivityArgs
import im.vector.app.features.VectorFeatures
import im.vector.app.features.analytics.plan.MobileScreen
import im.vector.app.features.settings.font.FontScaleSettingActivity
import im.vector.app.features.themes.ThemeUtils
import kotlinx.coroutines.launch
import org.matrix.android.sdk.api.session.presence.model.PresenceEnum
import javax.inject.Inject
Expand All @@ -44,19 +39,12 @@ class VectorSettingsPreferencesFragment :
VectorSettingsBaseFragment() {

@Inject lateinit var vectorPreferences: VectorPreferences
@Inject lateinit var fontScalePreferences: FontScalePreferences
@Inject lateinit var vectorFeatures: VectorFeatures
@Inject lateinit var vectorLocale: VectorLocale

override var titleRes = R.string.settings_preferences
override val preferenceXmlRes = R.xml.vector_settings_preferences

private val selectedLanguagePreference by lazy {
findPreference<VectorPreference>(VectorPreferences.SETTINGS_INTERFACE_LANGUAGE_PREFERENCE_KEY)!!
}
private val textSizePreference by lazy {
findPreference<VectorPreference>(VectorPreferences.SETTINGS_INTERFACE_TEXT_SIZE_KEY)!!
}
private val takePhotoOrVideoPreference by lazy {
findPreference<VectorPreference>("SETTINGS_INTERFACE_TAKE_PHOTO_VIDEO")!!
}
Expand All @@ -67,22 +55,6 @@ class VectorSettingsPreferencesFragment :
}

override fun bindPref() {
// user interface preferences
setUserInterfacePreferences()

// Themes
findPreference<VectorListPreference>(ThemeUtils.APPLICATION_THEME_KEY)!!
.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, newValue ->
if (newValue is String) {
ThemeUtils.setApplicationTheme(requireContext().applicationContext, newValue)
// Restart the Activity
activity?.restart()
true
} else {
false
}
}

findPreference<VectorSwitchPreference>(VectorPreferences.SETTINGS_PRESENCE_USER_ALWAYS_APPEARS_OFFLINE)!!.let { pref ->
pref.isChecked = vectorPreferences.userAlwaysAppearsOffline()
pref.setOnPreferenceChangeListener { _, newValue ->
Expand Down Expand Up @@ -192,21 +164,4 @@ class VectorSettingsPreferencesFragment :
}
)
}

// ==============================================================================================================
// user interface management
// ==============================================================================================================

private fun setUserInterfacePreferences() {
// Selected language
selectedLanguagePreference.summary = vectorLocale.localeToLocalisedString(vectorLocale.applicationLocale)

// Text size
textSizePreference.summary = getString(fontScalePreferences.getResolvedFontScaleValue().nameResId)

textSizePreference.onPreferenceClickListener = Preference.OnPreferenceClickListener {
startActivity(Intent(activity, FontScaleSettingActivity::class.java))
true
}
}
}
4 changes: 4 additions & 0 deletions vector/src/main/res/drawable/ic_settings_root_appearance.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<vector android:height="25dp" android:viewportHeight="18"
android:viewportWidth="18" android:width="25dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#000000" android:fillType="evenOdd" android:pathData="M16.296,6.95C17.281,8.163 17.302,9.849 16.33,11.071C14.95,12.806 12.514,15 9.024,15C5.533,15 3.098,12.806 1.718,11.071C0.745,9.849 0.766,8.163 1.751,6.95C3.163,5.212 5.628,3 9.024,3C12.42,3 14.884,5.212 16.296,6.95ZM13,9C13,11.209 11.209,13 9,13C6.791,13 5,11.209 5,9C5,6.791 6.791,5 9,5C11.209,5 13,6.791 13,9ZM9,11C10.105,11 11,10.105 11,9C11,7.895 10.105,7 9,7C7.895,7 7,7.895 7,9C7,10.105 7.895,11 9,11Z"/>
</vector>
37 changes: 37 additions & 0 deletions vector/src/main/res/xml/vector_settings_appearance.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">

<im.vector.app.core.preference.VectorPreferenceCategory
android:key="SETTINGS_USER_INTERFACE_KEY"
android:title="@string/settings_user_interface">

<im.vector.app.core.preference.VectorListPreference
android:defaultValue="system"
android:entries="@array/theme_entries"
android:entryValues="@array/theme_values"
android:key="APPLICATION_THEME_KEY"
android:summary="%s"
android:title="@string/settings_theme"
app:iconSpaceReserved="false" />

<im.vector.app.core.preference.VectorPreference
android:dialogTitle="@string/font_size"
android:key="SETTINGS_INTERFACE_TEXT_SIZE_KEY"
android:persistent="false"
android:title="@string/font_size" />

</im.vector.app.core.preference.VectorPreferenceCategory>

<im.vector.app.core.preference.VectorPreferenceCategory android:title="@string/settings_category_timeline">

<im.vector.app.core.preference.VectorSwitchPreference
android:defaultValue="@bool/settings_interface_bubble_default"
android:key="SETTINGS_INTERFACE_BUBBLE_KEY"
android:title="@string/message_bubbles"
app:isPreferenceVisible="@bool/settings_interface_bubble_visible" />

</im.vector.app.core.preference.VectorPreferenceCategory>

</androidx.preference.PreferenceScreen>
6 changes: 6 additions & 0 deletions vector/src/main/res/xml/vector_settings_general.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@
android:title="@string/settings_emails_and_phone_numbers_title"
app:fragment="im.vector.app.features.settings.threepids.ThreePidsSettingsFragment" />

<im.vector.app.core.preference.VectorPreference
android:key="SETTINGS_INTERFACE_LANGUAGE_PREFERENCE_KEY"
android:persistent="false"
android:title="@string/settings_interface_language"
app:fragment="im.vector.app.features.settings.locale.LocalePickerFragment" />

<im.vector.app.core.preference.VectorPreference
android:key="SETTINGS_DISCOVERY_PREFERENCE_KEY"
android:persistent="false"
Expand Down
33 changes: 0 additions & 33 deletions vector/src/main/res/xml/vector_settings_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,6 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">

<im.vector.app.core.preference.VectorPreferenceCategory
android:key="SETTINGS_USER_INTERFACE_KEY"
android:title="@string/settings_user_interface">

<im.vector.app.core.preference.VectorPreference
android:key="SETTINGS_INTERFACE_LANGUAGE_PREFERENCE_KEY"
android:persistent="false"
android:title="@string/settings_interface_language"
app:fragment="im.vector.app.features.settings.locale.LocalePickerFragment" />

<im.vector.app.core.preference.VectorListPreference
android:defaultValue="system"
android:entries="@array/theme_entries"
android:entryValues="@array/theme_values"
android:key="APPLICATION_THEME_KEY"
android:summary="%s"
android:title="@string/settings_theme"
app:iconSpaceReserved="false" />

<im.vector.app.core.preference.VectorPreference
android:dialogTitle="@string/font_size"
android:key="SETTINGS_INTERFACE_TEXT_SIZE_KEY"
android:persistent="false"
android:title="@string/font_size" />

</im.vector.app.core.preference.VectorPreferenceCategory>

<im.vector.app.core.preference.VectorPreferenceCategory
android:title="@string/spaces"
android:key="SETTINGS_PREF_SPACE_CATEGORY">
Expand Down Expand Up @@ -78,12 +51,6 @@

<im.vector.app.core.preference.VectorPreferenceCategory android:title="@string/settings_category_timeline">

<im.vector.app.core.preference.VectorSwitchPreference
android:defaultValue="@bool/settings_interface_bubble_default"
android:key="SETTINGS_INTERFACE_BUBBLE_KEY"
android:title="@string/message_bubbles"
app:isPreferenceVisible="@bool/settings_interface_bubble_visible" />

<im.vector.app.core.preference.VectorSwitchPreference
android:defaultValue="@bool/settings_timeline_show_live_sender_info_default"
app:isPreferenceVisible="@bool/settings_timeline_show_live_sender_info_visible"
Expand Down
6 changes: 6 additions & 0 deletions vector/src/main/res/xml/vector_settings_root.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
app:fragment="im.vector.app.features.settings.VectorSettingsGeneralFragment"
app:isPreferenceVisible="@bool/settings_root_general_visible" />

<im.vector.app.core.preference.VectorPreference
android:icon="@drawable/ic_settings_root_appearance"
android:title="@string/settings_appearance_title"
app:fragment="im.vector.app.features.settings.VectorSettingsAppearanceFragment"
app:isPreferenceVisible="@bool/settings_root_appearance_visible" />

<im.vector.app.core.preference.VectorPreference
android:icon="@drawable/ic_settings_root_notification"
android:title="@string/settings_notifications"
Expand Down

0 comments on commit 8d7481a

Please sign in to comment.