Skip to content

Commit

Permalink
Remove confusing RTL options
Browse files Browse the repository at this point in the history
  • Loading branch information
DianQK committed May 9, 2023
1 parent 32b88f6 commit 8fb6da7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.core.edit
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
import org.dianqk.ruslin.R
import org.dianqk.ruslin.data.DataStoreKeys
import org.dianqk.ruslin.data.dataStore

sealed class TextDirectionPreference(val value: Int) {
object Ltr : TextDirectionPreference(1)
object Rtl : TextDirectionPreference(2)
object Content : TextDirectionPreference(3)
object ContentOrLtr : TextDirectionPreference(4)
object ContentOrRtl : TextDirectionPreference(5)
object Auto : TextDirectionPreference(3)

fun put(context: Context, scope: CoroutineScope) {
scope.launch {
Expand All @@ -24,33 +23,31 @@ sealed class TextDirectionPreference(val value: Int) {
}
}

fun toDesc(context: Context): String = getTextDirection().toString()
fun toDesc(context: Context): String = when (this) {
Ltr -> context.getString(R.string.ltr)
Rtl -> context.getString(R.string.rtl)
Auto -> context.getString(R.string.auto)
}

fun getTextDirection(): TextDirection = when (this) {
Ltr -> TextDirection.Ltr
Rtl -> TextDirection.Rtl
Content -> TextDirection.Content
ContentOrLtr -> TextDirection.ContentOrLtr
ContentOrRtl -> TextDirection.ContentOrRtl
Auto -> TextDirection.Content
}

companion object {
val default = Ltr
val values = listOf(
Ltr,
Rtl,
Content,
ContentOrLtr,
ContentOrRtl,
Auto
)

fun fromPreferences(preferences: Preferences): TextDirectionPreference =
when (preferences[DataStoreKeys.TextDirection.key]) {
1 -> Ltr
2 -> Rtl
3 -> Content
4 -> ContentOrLtr
5 -> ContentOrRtl
3 -> Auto
else -> default
}
}
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,5 @@
<string name="other">其他</string>
<string name="content_text_direction">内容文本方向</string>
<string name="content_text_direction_desc">笔记、标题等文本方向</string>
<string name="auto">自动</string>
</resources>
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,7 @@
<string name="other">Other</string>
<string name="content_text_direction">Content Text Direction</string>
<string name="content_text_direction_desc">Text direction of notes, titles, etc.</string>
<string name="rtl" translatable="false">RTL</string>
<string name="ltr" translatable="false">LTR</string>
<string name="auto">Auto</string>
</resources>

0 comments on commit 8fb6da7

Please sign in to comment.