Skip to content

Commit 79762d9

Browse files
authored
font scale setting screen (#6453)
1 parent cdbc197 commit 79762d9

38 files changed

+1195
-221
lines changed

changelog.d/5687.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Adds settings screen to change app font scale or enable using system setting
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<selector xmlns:android="http://schemas.android.com/apk/res/android">
3+
<item android:color="@color/color_primary_alpha25" android:state_checked="true" android:state_enabled="false" />
4+
<item android:color="?colorPrimary" android:state_checked="true" android:state_enabled="true" />
5+
<item android:color="?vctr_content_quaternary"/>
6+
</selector>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<selector xmlns:android="http://schemas.android.com/apk/res/android">
3+
<item android:color="?vctr_content_quaternary" android:state_enabled="false" />
4+
<item android:color="?vctr_content_primary"/>
5+
</selector>

vector/src/androidTest/java/im/vector/app/ui/robot/settings/SettingsPreferencesRobot.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ import androidx.test.espresso.matcher.ViewMatchers.withText
2121
import com.adevinta.android.barista.interaction.BaristaClickInteractions.clickOn
2222
import com.adevinta.android.barista.interaction.BaristaDialogInteractions.clickDialogNegativeButton
2323
import im.vector.app.R
24+
import im.vector.app.espresso.tools.waitUntilActivityVisible
2425
import im.vector.app.espresso.tools.waitUntilViewVisible
26+
import im.vector.app.features.settings.font.FontScaleSettingActivity
2527

2628
class SettingsPreferencesRobot {
2729

@@ -32,6 +34,8 @@ class SettingsPreferencesRobot {
3234
clickOn(R.string.settings_theme)
3335
clickDialogNegativeButton()
3436
clickOn(R.string.font_size)
35-
clickDialogNegativeButton()
37+
waitUntilActivityVisible<FontScaleSettingActivity> {
38+
pressBack()
39+
}
3640
}
3741
}

vector/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@
347347
<activity android:name=".features.poll.create.CreatePollActivity" />
348348
<activity android:name=".features.location.LocationSharingActivity" />
349349
<activity android:name=".features.location.live.map.LocationLiveMapViewActivity" />
350+
<activity android:name=".features.settings.font.FontScaleSettingActivity"/>
350351

351352
<!-- Services -->
352353

vector/src/main/java/im/vector/app/core/di/FragmentModule.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ import im.vector.app.features.settings.devtools.GossipingEventsPaperTrailFragmen
162162
import im.vector.app.features.settings.devtools.IncomingKeyRequestListFragment
163163
import im.vector.app.features.settings.devtools.KeyRequestsFragment
164164
import im.vector.app.features.settings.devtools.OutgoingKeyRequestListFragment
165+
import im.vector.app.features.settings.font.FontScaleSettingFragment
165166
import im.vector.app.features.settings.homeserver.HomeserverSettingsFragment
166167
import im.vector.app.features.settings.ignored.VectorSettingsIgnoredUsersFragment
167168
import im.vector.app.features.settings.legals.LegalsFragment
@@ -586,6 +587,11 @@ interface FragmentModule {
586587
@FragmentKey(HomeserverSettingsFragment::class)
587588
fun bindHomeserverSettingsFragment(fragment: HomeserverSettingsFragment): Fragment
588589

590+
@Binds
591+
@IntoMap
592+
@FragmentKey(FontScaleSettingFragment::class)
593+
fun bindFontScaleSettingFragment(fragment: FontScaleSettingFragment): Fragment
594+
589595
@Binds
590596
@IntoMap
591597
@FragmentKey(VectorSettingsPinFragment::class)

vector/src/main/java/im/vector/app/core/di/MavericksViewModelModule.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ import im.vector.app.features.settings.devtools.AccountDataViewModel
9090
import im.vector.app.features.settings.devtools.GossipingEventsPaperTrailViewModel
9191
import im.vector.app.features.settings.devtools.KeyRequestListViewModel
9292
import im.vector.app.features.settings.devtools.KeyRequestViewModel
93+
import im.vector.app.features.settings.font.FontScaleSettingViewModel
9394
import im.vector.app.features.settings.homeserver.HomeserverSettingsViewModel
9495
import im.vector.app.features.settings.ignored.IgnoredUsersViewModel
9596
import im.vector.app.features.settings.legals.LegalsViewModel
@@ -606,4 +607,9 @@ interface MavericksViewModelModule {
606607
@IntoMap
607608
@MavericksViewModelKey(LocationLiveMapViewModel::class)
608609
fun locationLiveMapViewModelFactory(factory: LocationLiveMapViewModel.Factory): MavericksAssistedViewModelFactory<*, *>
610+
611+
@Binds
612+
@IntoMap
613+
@MavericksViewModelKey(FontScaleSettingViewModel::class)
614+
fun fontScaleSettingViewModelFactory(factory: FontScaleSettingViewModel.Factory): MavericksAssistedViewModelFactory<*, *>
609615
}

vector/src/main/java/im/vector/app/core/di/NamedGlobalScope.kt renamed to vector/src/main/java/im/vector/app/core/di/Qualifiers.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
1716
package im.vector.app.core.di
1817

1918
import javax.inject.Qualifier
2019

20+
@Qualifier
21+
@Retention(AnnotationRetention.RUNTIME)
22+
annotation class DefaultPreferences
23+
2124
@Qualifier
2225
@Retention(AnnotationRetention.RUNTIME)
2326
annotation class NamedGlobalScope

vector/src/main/java/im/vector/app/core/di/SingletonModule.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import android.content.Context
2121
import android.content.Context.MODE_PRIVATE
2222
import android.content.SharedPreferences
2323
import android.content.res.Resources
24+
import androidx.preference.PreferenceManager
2425
import com.google.i18n.phonenumbers.PhoneNumberUtil
2526
import dagger.Binds
2627
import dagger.Module
@@ -37,6 +38,8 @@ import im.vector.app.core.error.ErrorFormatter
3738
import im.vector.app.core.resources.BuildMeta
3839
import im.vector.app.core.time.Clock
3940
import im.vector.app.core.time.DefaultClock
41+
import im.vector.app.core.utils.AndroidSystemSettingsProvider
42+
import im.vector.app.core.utils.SystemSettingsProvider
4043
import im.vector.app.features.analytics.AnalyticsConfig
4144
import im.vector.app.features.analytics.AnalyticsTracker
4245
import im.vector.app.features.analytics.VectorAnalytics
@@ -48,6 +51,8 @@ import im.vector.app.features.navigation.Navigator
4851
import im.vector.app.features.pin.PinCodeStore
4952
import im.vector.app.features.pin.SharedPrefPinCodeStore
5053
import im.vector.app.features.room.VectorRoomDisplayNameFallbackProvider
54+
import im.vector.app.features.settings.FontScalePreferences
55+
import im.vector.app.features.settings.FontScalePreferencesImpl
5156
import im.vector.app.features.settings.VectorPreferences
5257
import im.vector.app.features.ui.SharedPreferencesUiStateRepository
5358
import im.vector.app.features.ui.UiStateRepository
@@ -97,6 +102,12 @@ abstract class VectorBindModule {
97102

98103
@Binds
99104
abstract fun bindEmojiSpanify(emojiCompatWrapper: EmojiCompatWrapper): EmojiSpanify
105+
106+
@Binds
107+
abstract fun bindFontScale(fontScale: FontScalePreferencesImpl): FontScalePreferences
108+
109+
@Binds
110+
abstract fun bindSystemSettingsProvide(provider: AndroidSystemSettingsProvider): SystemSettingsProvider
100111
}
101112

102113
@InstallIn(SingletonComponent::class)
@@ -200,4 +211,11 @@ object VectorStaticModule {
200211
@Provides
201212
@Singleton
202213
fun providesBuildMeta() = BuildMeta()
214+
215+
@Provides
216+
@Singleton
217+
@DefaultPreferences
218+
fun providesDefaultSharedPreferences(context: Context): SharedPreferences {
219+
return PreferenceManager.getDefaultSharedPreferences(context.applicationContext)
220+
}
203221
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright (c) 2022 New Vector Ltd
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package im.vector.app.core.epoxy
18+
19+
import android.util.TypedValue
20+
import android.widget.CompoundButton
21+
import android.widget.RadioButton
22+
import android.widget.TextView
23+
import com.airbnb.epoxy.EpoxyAttribute
24+
import com.airbnb.epoxy.EpoxyModelClass
25+
import im.vector.app.R
26+
import im.vector.app.features.settings.FontScaleValue
27+
28+
@EpoxyModelClass
29+
abstract class FontScaleItem : VectorEpoxyModel<FontScaleItem.Holder>(R.layout.item_font_scale) {
30+
31+
companion object {
32+
const val MINIMAL_TEXT_SIZE_DP = 10f
33+
}
34+
35+
@EpoxyAttribute var fontScale: FontScaleValue? = null
36+
@EpoxyAttribute var selected: Boolean = true
37+
@EpoxyAttribute var enabled: Boolean = true
38+
39+
@EpoxyAttribute(EpoxyAttribute.Option.DoNotHash)
40+
var checkChangeListener: CompoundButton.OnCheckedChangeListener? = null
41+
42+
override fun bind(holder: Holder) {
43+
super.bind(holder)
44+
val context = holder.view.context
45+
holder.textView.text = fontScale?.let {
46+
context.resources.getString(it.nameResId)
47+
}
48+
val index = fontScale?.index ?: 0
49+
holder.textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, MINIMAL_TEXT_SIZE_DP + index * 2)
50+
holder.textView.isEnabled = enabled
51+
holder.button.isChecked = selected
52+
holder.button.isEnabled = enabled
53+
holder.button.isClickable = enabled
54+
holder.view.onClick {
55+
holder.button.performClick()
56+
}
57+
holder.button.setOnCheckedChangeListener(checkChangeListener)
58+
}
59+
60+
class Holder : VectorEpoxyHolder() {
61+
val button by bind<RadioButton>(R.id.font_scale_radio_button)
62+
val textView by bind<TextView>(R.id.font_scale_text)
63+
}
64+
}

0 commit comments

Comments
 (0)