Skip to content

Commit 815b800

Browse files
committed
Implement right-to-left support
1 parent e7b06bd commit 815b800

File tree

28 files changed

+88
-5
lines changed

28 files changed

+88
-5
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
android:icon="@mipmap/ic_launcher"
4343
android:label="${appName}"
4444
android:theme="@style/Theme.Notepad"
45+
android:supportsRtl="true"
4546
tools:ignore="AppLinkUrlError">
4647

4748
<activity-alias

app/src/main/java/com/farmerbb/notepad/data/PreferenceManager.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ class PreferenceManager private constructor(
8989
val showDate get() = Prefs.ShowDate.asFlow
9090
val directEdit get() = Prefs.DirectEdit.asFlow
9191
val markdown get() = Prefs.Markdown.asFlow
92+
val rtlSupport get() = Prefs.RtlSupport.asFlow
9293
val firstRunComplete get() = Prefs.FirstRun.mapToFlow(::toBoolean)
9394
val firstViewComplete get() = Prefs.FirstLoad.mapToFlow(::toBoolean)
9495
val showDoubleTapMessage get() = Prefs.ShowDoubleTapMessage.asFlow

app/src/main/java/com/farmerbb/notepad/model/Prefs.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ object PrefKeys {
2929
val ShowDate = booleanPreferencesKey("show_date")
3030
val DirectEdit = booleanPreferencesKey("direct_edit")
3131
val Markdown = booleanPreferencesKey("markdown")
32+
val RtlSupport = booleanPreferencesKey("rtl_support")
3233
val ShowDoubleTapMessage = booleanPreferencesKey("show_double_tap_message")
3334
val FirstRun = intPreferencesKey("first-run")
3435
val FirstLoad = intPreferencesKey("first-load")
@@ -75,6 +76,11 @@ object Prefs {
7576
defaultValue = false
7677
)
7778

79+
object RtlSupport: PreferenceRequest<Boolean>(
80+
key = PrefKeys.RtlSupport,
81+
defaultValue = false
82+
)
83+
7884
object ShowDoubleTapMessage: PreferenceRequest<Boolean>(
7985
key = PrefKeys.ShowDoubleTapMessage,
8086
defaultValue = true

app/src/main/java/com/farmerbb/notepad/ui/components/IconButtons.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import androidx.compose.material.Icon
1919
import androidx.compose.material.IconButton
2020
import androidx.compose.material.icons.Icons
2121
import androidx.compose.material.icons.filled.ArrowBack
22+
import androidx.compose.material.icons.filled.ArrowForward
2223
import androidx.compose.material.icons.filled.Delete
2324
import androidx.compose.material.icons.filled.Edit
2425
import androidx.compose.material.icons.filled.MoreVert
@@ -28,14 +29,21 @@ import androidx.compose.material.icons.filled.SdCard
2829
import androidx.compose.material.icons.filled.SelectAll
2930
import androidx.compose.runtime.Composable
3031
import androidx.compose.ui.graphics.Color
32+
import androidx.compose.ui.platform.LocalLayoutDirection
3133
import androidx.compose.ui.res.stringResource
34+
import androidx.compose.ui.unit.LayoutDirection
3235
import com.farmerbb.notepad.R
3336

3437
@Composable
3538
fun BackButton(onClick: () -> Unit = {}) {
39+
val imageVector = when(LocalLayoutDirection.current) {
40+
LayoutDirection.Rtl -> Icons.Filled.ArrowForward
41+
else -> Icons.Filled.ArrowBack
42+
}
43+
3644
IconButton(onClick = onClick) {
3745
Icon(
38-
imageVector = Icons.Filled.ArrowBack,
46+
imageVector = imageVector,
3947
contentDescription = null,
4048
tint = Color.White
4149
)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/* Copyright 2022 Braden Farmer
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
package com.farmerbb.notepad.ui.components
17+
18+
import androidx.compose.material.MaterialTheme
19+
import androidx.compose.runtime.Composable
20+
import androidx.compose.runtime.CompositionLocalProvider
21+
import androidx.compose.ui.platform.LocalLayoutDirection
22+
import androidx.compose.ui.unit.LayoutDirection
23+
24+
@Composable
25+
fun NotepadTheme(
26+
rtlSupport: Boolean,
27+
content: @Composable () -> Unit
28+
) {
29+
val layoutDirection = when(rtlSupport) {
30+
true -> LayoutDirection.Rtl
31+
false -> LayoutDirection.Ltr
32+
}
33+
34+
MaterialTheme {
35+
CompositionLocalProvider(
36+
LocalLayoutDirection provides layoutDirection,
37+
content = content
38+
)
39+
}
40+
}

app/src/main/java/com/farmerbb/notepad/ui/routes/AppSettings.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@ fun NotepadPreferenceScreen(
117117
title = stringResource(id = R.string.pref_title_markdown),
118118
singleLineTitle = false,
119119
enabled = !directEdit
120+
),
121+
SwitchPreference(
122+
request = Prefs.RtlSupport,
123+
title = stringResource(id = R.string.rtl_support),
124+
singleLineTitle = false
120125
)
121126
),
122127
contentPadding = PaddingValues(8.dp),

app/src/main/java/com/farmerbb/notepad/ui/routes/NotepadComposeApp.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ import androidx.compose.foundation.layout.width
3737
import androidx.compose.material.Divider
3838
import androidx.compose.material.FloatingActionButton
3939
import androidx.compose.material.Icon
40-
import androidx.compose.material.MaterialTheme
4140
import androidx.compose.material.Scaffold
4241
import androidx.compose.material.TopAppBar
4342
import androidx.compose.material.icons.Icons
@@ -84,6 +83,7 @@ import com.farmerbb.notepad.ui.components.FirstViewDialog
8483
import com.farmerbb.notepad.ui.components.MultiSelectButton
8584
import com.farmerbb.notepad.ui.components.NoteListMenu
8685
import com.farmerbb.notepad.ui.components.NoteViewEditMenu
86+
import com.farmerbb.notepad.ui.components.NotepadTheme
8787
import com.farmerbb.notepad.ui.components.SaveButton
8888
import com.farmerbb.notepad.ui.components.SaveDialog
8989
import com.farmerbb.notepad.ui.components.SelectAllButton
@@ -104,6 +104,7 @@ fun NotepadComposeAppRoute() {
104104
val configuration = LocalConfiguration.current
105105

106106
val isLightTheme by vm.prefs.isLightTheme.collectAsState()
107+
val rtlSupport by vm.prefs.rtlSupport.collectAsState()
107108
val draftId by vm.savedDraftId.collectAsState()
108109

109110
LaunchedEffect(Unit) {
@@ -112,7 +113,7 @@ fun NotepadComposeAppRoute() {
112113

113114
if (draftId == null) return
114115

115-
MaterialTheme {
116+
NotepadTheme(rtlSupport) {
116117
NotepadComposeApp(
117118
vm = vm,
118119
isMultiPane = configuration.screenWidthDp >= 600,

app/src/main/java/com/farmerbb/notepad/ui/routes/StandaloneEditor.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.farmerbb.notepad.ui.routes
22

33
import androidx.activity.compose.BackHandler
4-
import androidx.compose.material.MaterialTheme
54
import androidx.compose.material.Scaffold
65
import androidx.compose.material.TopAppBar
76
import androidx.compose.runtime.Composable
@@ -20,6 +19,7 @@ import com.farmerbb.notepad.ui.components.AppBarText
2019
import com.farmerbb.notepad.ui.components.BackButton
2120
import com.farmerbb.notepad.ui.components.DeleteButton
2221
import com.farmerbb.notepad.ui.components.DeleteDialog
22+
import com.farmerbb.notepad.ui.components.NotepadTheme
2323
import com.farmerbb.notepad.ui.components.SaveButton
2424
import com.farmerbb.notepad.ui.components.SaveDialog
2525
import com.farmerbb.notepad.ui.components.StandaloneEditorMenu
@@ -36,8 +36,9 @@ fun StandaloneEditorRoute(
3636
val vm: NotepadViewModel = getViewModel()
3737
val systemUiController = rememberSystemUiController()
3838
val isLightTheme by vm.prefs.isLightTheme.collectAsState()
39+
val rtlSupport by vm.prefs.rtlSupport.collectAsState()
3940

40-
MaterialTheme {
41+
NotepadTheme(rtlSupport) {
4142
StandaloneEditor(
4243
vm = vm,
4344
initialText = initialText,

app/src/main/res/values-ar/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,5 @@
5656
<string name="no_notes_to_export">لم تُحَدَّد ملاحظاتٌ لتصديرها</string>
5757
<string name="no_notes_to_delete">لم تُحَدَّد ملاحظاتٌ لحذفها</string>
5858
<string name="check_for_updates">تحقّق من التحديثات</string>
59+
<string name="rtl_support">Right-to-left support</string>
5960
</resources>

app/src/main/res/values-bn/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
<string name="no_notes_to_export">এক্সপোর্ট করার জন্য কোন নোট নির্বাচন করা হয়নি</string>
7575
<string name="no_notes_to_delete">মুছে ফেলার জন্য কোন নোট নির্বাচন করা হয়নি</string>
7676
<string name="check_for_updates">হালনাগাদ আছে কি না দেখুন</string>
77+
<string name="rtl_support">Right-to-left support</string>
7778

7879
<string-array name="sort_by_list">
7980
<item>তারিখ (একদম নতুন)</item>

0 commit comments

Comments
 (0)