From 188db671996a951c27d99d9c852dea783a60ed7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C9=91rry=20Shiv=C9=91m?= Date: Fri, 10 Nov 2023 13:05:01 +0530 Subject: [PATCH] Add ability to select texts in reader (#95) Signed-off-by: starry-shivam --- app/src/main/java/com/starry/myne/MainActivity.kt | 8 ++------ .../myne/ui/screens/reader/adapters/ReaderRVAdapter.kt | 8 ++++---- .../main/java/com/starry/myne/utils/Preferencesutils.kt | 6 +----- 3 files changed, 7 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/com/starry/myne/MainActivity.kt b/app/src/main/java/com/starry/myne/MainActivity.kt index 3530643f..9388c4d8 100644 --- a/app/src/main/java/com/starry/myne/MainActivity.kt +++ b/app/src/main/java/com/starry/myne/MainActivity.kt @@ -64,12 +64,8 @@ class MainActivity : AppCompatActivity() { settingsViewModel = ViewModelProvider(this)[SettingsViewModel::class.java] mainViewModel = ViewModelProvider(this)[MainViewModel::class.java] - when (settingsViewModel.getThemeValue()) { - ThemeMode.Auto.ordinal -> settingsViewModel.setTheme(ThemeMode.Auto) - ThemeMode.Dark.ordinal -> settingsViewModel.setTheme(ThemeMode.Dark) - ThemeMode.Light.ordinal -> settingsViewModel.setTheme(ThemeMode.Light) - } - + ThemeMode.entries.find { it.ordinal == settingsViewModel.getThemeValue()} + ?.let { settingsViewModel.setTheme(it) } settingsViewModel.setMaterialYou(settingsViewModel.getMaterialYouValue()) // Install splash screen before setting content. diff --git a/app/src/main/java/com/starry/myne/ui/screens/reader/adapters/ReaderRVAdapter.kt b/app/src/main/java/com/starry/myne/ui/screens/reader/adapters/ReaderRVAdapter.kt index a65ff381..64b6b2f2 100644 --- a/app/src/main/java/com/starry/myne/ui/screens/reader/adapters/ReaderRVAdapter.kt +++ b/app/src/main/java/com/starry/myne/ui/screens/reader/adapters/ReaderRVAdapter.kt @@ -25,6 +25,7 @@ import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.text.selection.SelectionContainer import androidx.compose.material.ExperimentalMaterialApi import androidx.compose.material3.Divider import androidx.compose.material3.ExperimentalMaterial3Api @@ -82,10 +83,9 @@ class ReaderRVAdapter( val chapter = allChapters[position] composeView.setContent { MyneTheme(settingsViewModel = activity.settingsViewModel) { - ReaderItem( - chapter = chapter, - viewModel = viewModel - ) + SelectionContainer { + ReaderItem(chapter = chapter, viewModel = viewModel) + } } } } diff --git a/app/src/main/java/com/starry/myne/utils/Preferencesutils.kt b/app/src/main/java/com/starry/myne/utils/Preferencesutils.kt index 7aa7f1e9..8136c17f 100644 --- a/app/src/main/java/com/starry/myne/utils/Preferencesutils.kt +++ b/app/src/main/java/com/starry/myne/utils/Preferencesutils.kt @@ -39,11 +39,7 @@ class PreferenceUtil(context: Context) { prefs = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE) } - fun keyExists(key: String): Boolean { - if (prefs.contains(key)) - return true - return false - } + fun keyExists(key: String): Boolean = prefs.contains(key) fun putString(key: String, value: String) { val prefsEditor = prefs.edit()