🚀 Screen Orientation option
* Added "Screen orientation" option, that lets user set specific orientation for Reader * Put in "System" subcategory, which contains all settings related to system
This commit is contained in:
parent
47d322fed7
commit
8599594372
13 changed files with 169 additions and 7 deletions
|
|
@ -440,7 +440,7 @@ private fun provideAboutBadges() = listOf(
|
|||
private fun provideFonts() = listOf(
|
||||
FontWithName(
|
||||
"default",
|
||||
UIText.StringResource(R.string.default_font),
|
||||
UIText.StringResource(R.string.default_string),
|
||||
FontFamily.Default
|
||||
),
|
||||
FontWithName(
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ object DataStoreConstants {
|
|||
val PERCEPTION_EXPANDER_THICKNESS = intPreferencesKey("perception_expander_thickness")
|
||||
val CHECK_FOR_TEXT_UPDATE = booleanPreferencesKey("check_for_text_update")
|
||||
val CHECK_FOR_TEXT_UPDATE_TOAST = booleanPreferencesKey("check_for_text_update_toast")
|
||||
val SCREEN_ORIENTATION = stringPreferencesKey("screen_orientation")
|
||||
|
||||
// Browse settings
|
||||
val BROWSE_FILES_STRUCTURE = stringPreferencesKey("browse_files_structure")
|
||||
|
|
|
|||
|
|
@ -42,4 +42,5 @@ sealed class MainEvent {
|
|||
data class OnChangePerceptionExpanderThickness(val thickness: Int) : MainEvent()
|
||||
data class OnChangeCheckForTextUpdate(val bool: Boolean) : MainEvent()
|
||||
data class OnChangeCheckForTextUpdateToast(val bool: Boolean) : MainEvent()
|
||||
data class OnChangeScreenOrientation(val orientation: String) : MainEvent()
|
||||
}
|
||||
|
|
@ -16,7 +16,9 @@ import ua.acclorite.book_story.presentation.screens.settings.nested.browse.data.
|
|||
import ua.acclorite.book_story.presentation.screens.settings.nested.browse.data.toBrowseLayout
|
||||
import ua.acclorite.book_story.presentation.screens.settings.nested.browse.data.toBrowseSortOrder
|
||||
import ua.acclorite.book_story.presentation.screens.settings.nested.browse.data.toFilesStructure
|
||||
import ua.acclorite.book_story.presentation.screens.settings.nested.reader.data.ReaderScreenOrientation
|
||||
import ua.acclorite.book_story.presentation.screens.settings.nested.reader.data.ReaderTextAlignment
|
||||
import ua.acclorite.book_story.presentation.screens.settings.nested.reader.data.toReaderScreenOrientation
|
||||
import ua.acclorite.book_story.presentation.screens.settings.nested.reader.data.toTextAlignment
|
||||
import ua.acclorite.book_story.presentation.ui.DarkTheme
|
||||
import ua.acclorite.book_story.presentation.ui.PureDark
|
||||
|
|
@ -79,6 +81,9 @@ data class MainState(
|
|||
val perceptionExpanderThickness: Int = provideDefaultValue { 4 },
|
||||
val checkForTextUpdate: Boolean = provideDefaultValue { true },
|
||||
val checkForTextUpdateToast: Boolean = provideDefaultValue { true },
|
||||
val screenOrientation: ReaderScreenOrientation = provideDefaultValue {
|
||||
ReaderScreenOrientation.DEFAULT
|
||||
},
|
||||
|
||||
// Browse Settings
|
||||
val browseFilesStructure: BrowseFilesStructure = provideDefaultValue {
|
||||
|
|
@ -264,6 +269,10 @@ data class MainState(
|
|||
checkForTextUpdateToast = provideValue(
|
||||
CHECK_FOR_TEXT_UPDATE_TOAST
|
||||
) { checkForTextUpdateToast },
|
||||
|
||||
screenOrientation = provideValue(
|
||||
SCREEN_ORIENTATION, convert = { toReaderScreenOrientation() }
|
||||
) { screenOrientation },
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ import ua.acclorite.book_story.presentation.screens.settings.data.SettingsViewMo
|
|||
import ua.acclorite.book_story.presentation.screens.settings.nested.browse.data.toBrowseLayout
|
||||
import ua.acclorite.book_story.presentation.screens.settings.nested.browse.data.toBrowseSortOrder
|
||||
import ua.acclorite.book_story.presentation.screens.settings.nested.browse.data.toFilesStructure
|
||||
import ua.acclorite.book_story.presentation.screens.settings.nested.reader.data.toReaderScreenOrientation
|
||||
import ua.acclorite.book_story.presentation.screens.settings.nested.reader.data.toTextAlignment
|
||||
import ua.acclorite.book_story.presentation.ui.toDarkTheme
|
||||
import ua.acclorite.book_story.presentation.ui.toPureDark
|
||||
|
|
@ -530,6 +531,20 @@ class MainViewModel @Inject constructor(
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
is MainEvent.OnChangeScreenOrientation -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
setDatastore.execute(
|
||||
DataStoreConstants.SCREEN_ORIENTATION,
|
||||
event.orientation
|
||||
)
|
||||
updateStateWithSavedHandle {
|
||||
it.copy(
|
||||
screenOrientation = event.orientation.toReaderScreenOrientation()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package ua.acclorite.book_story.presentation.screens.reader
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.pm.ActivityInfo
|
||||
import android.os.Build
|
||||
import android.view.WindowManager
|
||||
import androidx.activity.ComponentActivity
|
||||
|
|
@ -174,6 +175,12 @@ fun ReaderScreenRoot(screen: Screen.Reader) {
|
|||
}
|
||||
viewModel.onUpdateCurrentChapter()
|
||||
}
|
||||
DisposableEffect(mainState.value.screenOrientation) {
|
||||
context.requestedOrientation = mainState.value.screenOrientation.code
|
||||
onDispose {
|
||||
context.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
|
||||
}
|
||||
}
|
||||
|
||||
ReaderScreen(lazyListState = lazyListState)
|
||||
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ import ua.acclorite.book_story.presentation.screens.settings.nested.reader.compo
|
|||
import ua.acclorite.book_story.presentation.screens.settings.nested.reader.components.subcategories.MiscSubcategory
|
||||
import ua.acclorite.book_story.presentation.screens.settings.nested.reader.components.subcategories.PaddingSubcategory
|
||||
import ua.acclorite.book_story.presentation.screens.settings.nested.reader.components.subcategories.ReadingSpeedSubcategory
|
||||
import ua.acclorite.book_story.presentation.screens.settings.nested.reader.components.subcategories.SystemSubcategory
|
||||
import ua.acclorite.book_story.presentation.screens.settings.nested.reader.components.subcategories.TextSubcategory
|
||||
import ua.acclorite.book_story.presentation.screens.settings.nested.reader.components.subcategories.TranslatorSubcategory
|
||||
|
||||
|
|
@ -94,6 +95,11 @@ fun ReaderSettingsBottomSheet() {
|
|||
topPadding = 22.dp,
|
||||
bottomPadding = 0.dp
|
||||
)
|
||||
SystemSubcategory(
|
||||
titleColor = { MaterialTheme.colorScheme.onSurface },
|
||||
topPadding = 22.dp,
|
||||
bottomPadding = 0.dp
|
||||
)
|
||||
ReadingSpeedSubcategory(
|
||||
titleColor = { MaterialTheme.colorScheme.onSurface },
|
||||
topPadding = 22.dp,
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import ua.acclorite.book_story.presentation.screens.settings.nested.reader.compo
|
|||
import ua.acclorite.book_story.presentation.screens.settings.nested.reader.components.subcategories.MiscSubcategory
|
||||
import ua.acclorite.book_story.presentation.screens.settings.nested.reader.components.subcategories.PaddingSubcategory
|
||||
import ua.acclorite.book_story.presentation.screens.settings.nested.reader.components.subcategories.ReadingSpeedSubcategory
|
||||
import ua.acclorite.book_story.presentation.screens.settings.nested.reader.components.subcategories.SystemSubcategory
|
||||
import ua.acclorite.book_story.presentation.screens.settings.nested.reader.components.subcategories.TextSubcategory
|
||||
import ua.acclorite.book_story.presentation.screens.settings.nested.reader.components.subcategories.TranslatorSubcategory
|
||||
|
||||
|
|
@ -44,6 +45,11 @@ fun LazyListScope.ReaderSettingsCategory(
|
|||
topPadding = 22.dp,
|
||||
bottomPadding = 0.dp
|
||||
)
|
||||
SystemSubcategory(
|
||||
titleColor = titleColor,
|
||||
topPadding = 22.dp,
|
||||
bottomPadding = 0.dp
|
||||
)
|
||||
ReadingSpeedSubcategory(
|
||||
titleColor = titleColor,
|
||||
topPadding = 22.dp,
|
||||
|
|
|
|||
|
|
@ -0,0 +1,47 @@
|
|||
package ua.acclorite.book_story.presentation.screens.settings.nested.reader.components.settings
|
||||
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import ua.acclorite.book_story.R
|
||||
import ua.acclorite.book_story.domain.model.ButtonItem
|
||||
import ua.acclorite.book_story.presentation.core.components.LocalMainViewModel
|
||||
import ua.acclorite.book_story.presentation.data.MainEvent
|
||||
import ua.acclorite.book_story.presentation.screens.settings.components.ChipsWithTitle
|
||||
import ua.acclorite.book_story.presentation.screens.settings.nested.reader.data.ReaderScreenOrientation
|
||||
|
||||
/**
|
||||
* Screen Orientation setting.
|
||||
* Changes Reader's screen orientation.
|
||||
*/
|
||||
@Composable
|
||||
fun ScreenOrientationSetting() {
|
||||
val state = LocalMainViewModel.current.state
|
||||
val onMainEvent = LocalMainViewModel.current.onEvent
|
||||
|
||||
ChipsWithTitle(
|
||||
title = stringResource(id = R.string.screen_orientation_option),
|
||||
chips = ReaderScreenOrientation.entries.map {
|
||||
ButtonItem(
|
||||
id = it.toString(),
|
||||
title = when (it.code) {
|
||||
ReaderScreenOrientation.FREE.code -> stringResource(id = R.string.screen_orientation_free)
|
||||
ReaderScreenOrientation.PORTRAIT.code -> stringResource(id = R.string.screen_orientation_portrait)
|
||||
ReaderScreenOrientation.LANDSCAPE.code -> stringResource(id = R.string.screen_orientation_landscape)
|
||||
ReaderScreenOrientation.LOCKED_PORTRAIT.code -> stringResource(id = R.string.screen_orientation_locked_portrait)
|
||||
ReaderScreenOrientation.LOCKED_LANDSCAPE.code -> stringResource(id = R.string.screen_orientation_locked_landscape)
|
||||
else -> stringResource(id = R.string.default_string)
|
||||
},
|
||||
textStyle = MaterialTheme.typography.labelLarge,
|
||||
selected = it == state.value.screenOrientation
|
||||
)
|
||||
},
|
||||
onClick = {
|
||||
onMainEvent(
|
||||
MainEvent.OnChangeScreenOrientation(
|
||||
it.id
|
||||
)
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
@file:Suppress("FunctionName")
|
||||
|
||||
package ua.acclorite.book_story.presentation.screens.settings.nested.reader.components.subcategories
|
||||
|
||||
import androidx.compose.foundation.lazy.LazyListScope
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import ua.acclorite.book_story.R
|
||||
import ua.acclorite.book_story.presentation.screens.settings.components.SettingsSubcategory
|
||||
import ua.acclorite.book_story.presentation.screens.settings.nested.reader.components.settings.ScreenOrientationSetting
|
||||
|
||||
/**
|
||||
* System subcategory.
|
||||
* Contains all settings that are related to system (e.g. screen orientation).
|
||||
*/
|
||||
fun LazyListScope.SystemSubcategory(
|
||||
titleColor: @Composable () -> Color = { MaterialTheme.colorScheme.primary },
|
||||
title: @Composable () -> String = { stringResource(id = R.string.system_reader_settings) },
|
||||
showTitle: Boolean = true,
|
||||
showDivider: Boolean = true,
|
||||
topPadding: Dp,
|
||||
bottomPadding: Dp
|
||||
) {
|
||||
SettingsSubcategory(
|
||||
titleColor = titleColor,
|
||||
title = title,
|
||||
showTitle = showTitle,
|
||||
showDivider = showDivider,
|
||||
topPadding = topPadding,
|
||||
bottomPadding = bottomPadding
|
||||
) {
|
||||
item {
|
||||
ScreenOrientationSetting()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
package ua.acclorite.book_story.presentation.screens.settings.nested.reader.data
|
||||
|
||||
import android.content.pm.ActivityInfo
|
||||
|
||||
enum class ReaderScreenOrientation(val code: Int) {
|
||||
DEFAULT(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED),
|
||||
FREE(ActivityInfo.SCREEN_ORIENTATION_USER),
|
||||
PORTRAIT(ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT),
|
||||
LANDSCAPE(ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE),
|
||||
LOCKED_PORTRAIT(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT),
|
||||
LOCKED_LANDSCAPE(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE),
|
||||
}
|
||||
|
||||
fun String.toReaderScreenOrientation(): ReaderScreenOrientation {
|
||||
return ReaderScreenOrientation.valueOf(this)
|
||||
}
|
||||
|
|
@ -1,5 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<!-- Basic Strings -->
|
||||
<string name="default_string">За замовчуванням</string>
|
||||
|
||||
<!-- Notifications -->
|
||||
<string name="updates_notification_channel">Нові оновлення</string>
|
||||
|
|
@ -210,6 +212,7 @@
|
|||
<string name="padding_reader_settings">Відступи</string>
|
||||
<string name="misc_reader_settings">Інше</string>
|
||||
<string name="reading_speed_reader_settings">Швидкість читання</string>
|
||||
<string name="system_reader_settings">Система</string>
|
||||
<string name="theme_appearance_settings">Налаштування теми</string>
|
||||
<string name="colors_appearance_settings">Кольори</string>
|
||||
<string name="general_browse_settings">Головні</string>
|
||||
|
|
@ -263,6 +266,7 @@
|
|||
<string name="check_for_text_update_option">Перевіряти на оновлення тексту</string>
|
||||
<string name="check_for_text_update_option_desc">Автоматично перевіряти чи є оновлення тексту</string>
|
||||
<string name="check_for_text_update_toast_option">Показувати повідомлення \"текст актуальний\"</string>
|
||||
<string name="screen_orientation_option">Орієнтація екрана</string>
|
||||
|
||||
<!-- Browse -->
|
||||
<string name="browse_files_structure_option">Структура файлів</string>
|
||||
|
|
@ -323,6 +327,13 @@
|
|||
<string name="text_alignment_center">Центр</string>
|
||||
<string name="text_alignment_end">Кінець</string>
|
||||
|
||||
<!-- Screen Orientation properties -->
|
||||
<string name="screen_orientation_free">Вільно</string>
|
||||
<string name="screen_orientation_portrait">Портрет</string>
|
||||
<string name="screen_orientation_landscape">Альбом</string>
|
||||
<string name="screen_orientation_locked_portrait">Заблокований портрет</string>
|
||||
<string name="screen_orientation_locked_landscape">Заблокований альбом</string>
|
||||
|
||||
<!-- Themes -->
|
||||
<string name="dynamic_theme">Меркурій</string>
|
||||
<string name="blue_theme">Нептун</string>
|
||||
|
|
@ -565,9 +576,6 @@
|
|||
Бажаєте дізнатися, як користуватися застосунком, прочитавши екран Допомоги?
|
||||
</string>
|
||||
|
||||
<!-- Font families -->
|
||||
<string name="default_font">За замовчуванням</string>
|
||||
|
||||
<!-- History -->
|
||||
<string name="today">Сьогодні</string>
|
||||
<string name="yesterday">Вчора</string>
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
<!-- Basic Strings -->
|
||||
<string name="app_version" translatable="false">1.2.0</string>
|
||||
<string name="app_name" translatable="false">Book\'s Story</string>
|
||||
<string name="default_string">Default</string>
|
||||
|
||||
<!-- Notifications -->
|
||||
<string name="updates_notification_channel">New updates</string>
|
||||
|
|
@ -212,6 +213,7 @@
|
|||
<string name="padding_reader_settings">Padding</string>
|
||||
<string name="misc_reader_settings">Misc</string>
|
||||
<string name="reading_speed_reader_settings">Reading speed</string>
|
||||
<string name="system_reader_settings">System</string>
|
||||
<string name="theme_appearance_settings">Theme preferences</string>
|
||||
<string name="colors_appearance_settings">Colors</string>
|
||||
<string name="general_browse_settings">General</string>
|
||||
|
|
@ -265,6 +267,7 @@
|
|||
<string name="check_for_text_update_option">Check for text update</string>
|
||||
<string name="check_for_text_update_option_desc">Automatically check whether there is text update</string>
|
||||
<string name="check_for_text_update_toast_option">Show \"text is up-to-date\" toast</string>
|
||||
<string name="screen_orientation_option">Screen orientation</string>
|
||||
|
||||
<!-- Browse -->
|
||||
<string name="browse_files_structure_option">Files structure</string>
|
||||
|
|
@ -325,6 +328,13 @@
|
|||
<string name="text_alignment_center">Center</string>
|
||||
<string name="text_alignment_end">End</string>
|
||||
|
||||
<!-- Screen Orientation properties -->
|
||||
<string name="screen_orientation_free">Free</string>
|
||||
<string name="screen_orientation_portrait">Portrait</string>
|
||||
<string name="screen_orientation_landscape">Landscape</string>
|
||||
<string name="screen_orientation_locked_portrait">Locked portrait</string>
|
||||
<string name="screen_orientation_locked_landscape">Locked landscape</string>
|
||||
|
||||
<!-- Themes -->
|
||||
<string name="dynamic_theme">Mercury</string>
|
||||
<string name="blue_theme">Neptune</string>
|
||||
|
|
@ -566,9 +576,6 @@
|
|||
Would you like to learn how to use the app by reading Help screen?
|
||||
</string>
|
||||
|
||||
<!-- Font families -->
|
||||
<string name="default_font">Default</string>
|
||||
|
||||
<!-- History -->
|
||||
<string name="today">Today</string>
|
||||
<string name="yesterday">Yesterday</string>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue