-
Notifications
You must be signed in to change notification settings - Fork 743
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
38 changed files
with
1,195 additions
and
221 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Adds settings screen to change app font scale or enable using system setting |
6 changes: 6 additions & 0 deletions
6
library/ui-styles/src/main/res/color/radio_button_tint_selector.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<selector xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<item android:color="@color/color_primary_alpha25" android:state_checked="true" android:state_enabled="false" /> | ||
<item android:color="?colorPrimary" android:state_checked="true" android:state_enabled="true" /> | ||
<item android:color="?vctr_content_quaternary"/> | ||
</selector> |
5 changes: 5 additions & 0 deletions
5
library/ui-styles/src/main/res/color/vector_content_primary_tint_selector.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<selector xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<item android:color="?vctr_content_quaternary" android:state_enabled="false" /> | ||
<item android:color="?vctr_content_primary"/> | ||
</selector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
vector/src/main/java/im/vector/app/core/epoxy/FontScaleItem.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright (c) 2022 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. | ||
*/ | ||
|
||
package im.vector.app.core.epoxy | ||
|
||
import android.util.TypedValue | ||
import android.widget.CompoundButton | ||
import android.widget.RadioButton | ||
import android.widget.TextView | ||
import com.airbnb.epoxy.EpoxyAttribute | ||
import com.airbnb.epoxy.EpoxyModelClass | ||
import im.vector.app.R | ||
import im.vector.app.features.settings.FontScaleValue | ||
|
||
@EpoxyModelClass | ||
abstract class FontScaleItem : VectorEpoxyModel<FontScaleItem.Holder>(R.layout.item_font_scale) { | ||
|
||
companion object { | ||
const val MINIMAL_TEXT_SIZE_DP = 10f | ||
} | ||
|
||
@EpoxyAttribute var fontScale: FontScaleValue? = null | ||
@EpoxyAttribute var selected: Boolean = true | ||
@EpoxyAttribute var enabled: Boolean = true | ||
|
||
@EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) | ||
var checkChangeListener: CompoundButton.OnCheckedChangeListener? = null | ||
|
||
override fun bind(holder: Holder) { | ||
super.bind(holder) | ||
val context = holder.view.context | ||
holder.textView.text = fontScale?.let { | ||
context.resources.getString(it.nameResId) | ||
} | ||
val index = fontScale?.index ?: 0 | ||
holder.textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, MINIMAL_TEXT_SIZE_DP + index * 2) | ||
holder.textView.isEnabled = enabled | ||
holder.button.isChecked = selected | ||
holder.button.isEnabled = enabled | ||
holder.button.isClickable = enabled | ||
holder.view.onClick { | ||
holder.button.performClick() | ||
} | ||
holder.button.setOnCheckedChangeListener(checkChangeListener) | ||
} | ||
|
||
class Holder : VectorEpoxyHolder() { | ||
val button by bind<RadioButton>(R.id.font_scale_radio_button) | ||
val textView by bind<TextView>(R.id.font_scale_text) | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
vector/src/main/java/im/vector/app/core/epoxy/FontScaleSectionItem.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright (c) 2022 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. | ||
*/ | ||
|
||
package im.vector.app.core.epoxy | ||
|
||
import android.widget.TextView | ||
import com.airbnb.epoxy.EpoxyAttribute | ||
import com.airbnb.epoxy.EpoxyModelClass | ||
import im.vector.app.R | ||
|
||
@EpoxyModelClass | ||
abstract class FontScaleSectionItem : VectorEpoxyModel<FontScaleSectionItem.Holder>(R.layout.item_font_scale_section) { | ||
|
||
@EpoxyAttribute var sectionName: String = "" | ||
|
||
override fun bind(holder: Holder) { | ||
super.bind(holder) | ||
holder.textView.text = sectionName | ||
} | ||
|
||
class Holder : VectorEpoxyHolder() { | ||
val textView by bind<TextView>(R.id.font_scale_section_name) | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
vector/src/main/java/im/vector/app/core/epoxy/FontScaleUseSystemSettingsItem.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright (c) 2022 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. | ||
*/ | ||
|
||
package im.vector.app.core.epoxy | ||
|
||
import android.widget.CheckBox | ||
import android.widget.CompoundButton | ||
import com.airbnb.epoxy.EpoxyAttribute | ||
import com.airbnb.epoxy.EpoxyModelClass | ||
import im.vector.app.R | ||
|
||
@EpoxyModelClass | ||
abstract class FontScaleUseSystemSettingsItem : VectorEpoxyModel<FontScaleUseSystemSettingsItem.Holder>(R.layout.item_font_scale_system) { | ||
|
||
@EpoxyAttribute var useSystemSettings: Boolean = true | ||
|
||
@EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) | ||
var checkChangeListener: CompoundButton.OnCheckedChangeListener? = null | ||
|
||
override fun bind(holder: Holder) { | ||
super.bind(holder) | ||
holder.checkBox.isChecked = useSystemSettings | ||
holder.checkBox.setOnCheckedChangeListener(checkChangeListener) | ||
holder.view.onClick { | ||
holder.checkBox.performClick() | ||
} | ||
} | ||
|
||
class Holder : VectorEpoxyHolder() { | ||
val checkBox by bind<CheckBox>(R.id.font_scale_use_system_checkbox) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
vector/src/main/java/im/vector/app/core/utils/SystemSettingsProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright (c) 2022 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. | ||
*/ | ||
|
||
package im.vector.app.core.utils | ||
|
||
import android.content.Context | ||
import android.provider.Settings | ||
import javax.inject.Inject | ||
|
||
/** | ||
* A helper to get system settings. | ||
*/ | ||
interface SystemSettingsProvider { | ||
|
||
/** | ||
* @return system setting for font scale | ||
*/ | ||
fun getSystemFontScale(): Float | ||
} | ||
|
||
class AndroidSystemSettingsProvider @Inject constructor( | ||
private val context: Context, | ||
) : SystemSettingsProvider { | ||
|
||
override fun getSystemFontScale(): Float { | ||
return Settings.System.getFloat(context.contentResolver, Settings.System.FONT_SCALE) | ||
} | ||
} |
Oops, something went wrong.