Skip to content

Commit

Permalink
Add toolip about swipe actions in library (#98)
Browse files Browse the repository at this point in the history
* Also reorganise Italian strings
---------
Signed-off-by: starry-shivam <[email protected]>
  • Loading branch information
starry-shivam authored Dec 16, 2023
1 parent ece3bb7 commit c4d9a47
Show file tree
Hide file tree
Showing 16 changed files with 203 additions and 81 deletions.
17 changes: 17 additions & 0 deletions .idea/appInsightsSettings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ dependencies {
implementation "com.mikepenz:aboutlibraries-core:10.5.2"
implementation "com.mikepenz:aboutlibraries-compose:10.5.2"
// Swipe actions.
implementation "me.saket.swipe:swipe:1.0.0"
implementation "me.saket.swipe:swipe:1.2.0"
// Crash Handler.
implementation 'cat.ereza:customactivityoncrash:2.4.0'
// Kotlin reflect API.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class HomeViewModel @Inject constructor(
* this: {"detail": "Invalid page."}. Hence the [BookSet] attributes become
* null in this case and can cause crashes.
*/
val books = if (bookSet.books != null) {
@Suppress("SENSELESS_COMPARISON") val books = if (bookSet.books != null) {
bookSet.books.filter { it.formats.applicationepubzip != null } as ArrayList<Book>
} else {
ArrayList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,15 @@ import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.SnackbarDuration
import androidx.compose.material3.SnackbarHost
import androidx.compose.material3.SnackbarHostState
import androidx.compose.material3.SnackbarResult
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.material3.surfaceColorAtElevation
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.runtime.mutableStateOf
Expand Down Expand Up @@ -104,13 +109,18 @@ import java.io.File
fun LibraryScreen(navController: NavController) {
val viewModel: LibraryViewModel = hiltViewModel()
val state = viewModel.allItems.observeAsState(listOf()).value

val context = LocalContext.current
val settingsViewModel = (context.getActivity() as MainActivity).settingsViewModel

val snackBarHostState = remember { SnackbarHostState() }

Scaffold(
snackbarHost = { SnackbarHost(snackBarHostState) },
modifier = Modifier
.fillMaxSize()
.background(MaterialTheme.colorScheme.background),
.background(MaterialTheme.colorScheme.background)
.padding(bottom = 70.dp),
topBar = {
CustomTopAppBar(
headerText = stringResource(id = R.string.library_header),
Expand All @@ -123,7 +133,6 @@ fun LibraryScreen(navController: NavController) {
modifier = Modifier
.fillMaxSize()
.background(MaterialTheme.colorScheme.background)
.padding(bottom = 70.dp)
) {
if (state.isEmpty()) {
NoLibraryItemAnimation()
Expand Down Expand Up @@ -211,7 +220,7 @@ fun LibraryScreen(navController: NavController) {
context.getString(R.string.error).toToast(context)
}
}) {
Text(stringResource(id = R.string.dialog_confirm_button))
Text(stringResource(id = R.string.confirm))
}
}, dismissButton = {
TextButton(onClick = {
Expand All @@ -227,6 +236,24 @@ fun LibraryScreen(navController: NavController) {
}
}
}

// Show tooltip for library screen.
LaunchedEffect(key1 = true) {
if (viewModel.shouldShowLibraryTooltip()) {
val result = snackBarHostState.showSnackbar(
message = context.getString(R.string.library_tooltip),
actionLabel = context.getString(R.string.got_it),
duration = SnackbarDuration.Indefinite
)

when (result) {
SnackbarResult.ActionPerformed -> {
viewModel.libraryTooltipDismissed()
}
SnackbarResult.Dismissed -> {}
}
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,12 @@ class LibraryViewModel @Inject constructor(
fun getInternalReaderSetting() = preferenceUtil.getBoolean(
PreferenceUtil.INTERNAL_READER_BOOL, true
)

fun shouldShowLibraryTooltip() = preferenceUtil.getBoolean(
PreferenceUtil.SHOW_LIBRARY_TOOLTIP_BOOL, true
)

fun libraryTooltipDismissed() = preferenceUtil.putBoolean(
PreferenceUtil.SHOW_LIBRARY_TOOLTIP_BOOL, false
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import androidx.activity.compose.setContent
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.Crossfade
import androidx.compose.animation.animateContentSize
import androidx.compose.animation.expandVertically
import androidx.compose.animation.fadeIn
Expand Down Expand Up @@ -82,6 +83,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.SideEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
Expand Down Expand Up @@ -252,7 +254,7 @@ class ReaderActivity : AppCompatActivity(), ReaderClickListener {
setContent {
MyneTheme(settingsViewModel = settingsViewModel) {
TransparentSystemBars()
val textSizeValue = remember { mutableStateOf(viewModel.getFontSize()) }
val textSizeValue = remember { mutableIntStateOf(viewModel.getFontSize()) }
val readerFontFamily = remember { mutableStateOf(viewModel.getFontFamily()) }
ReaderScreen(
viewModel = viewModel,
Expand Down Expand Up @@ -491,18 +493,23 @@ class ReaderActivity : AppCompatActivity(), ReaderClickListener {
)
}
},
content = {
if (viewModel.state.isLoading) {
Box(
modifier = Modifier
.fillMaxSize()
.padding(bottom = 65.dp),
contentAlignment = Alignment.Center
) {
CircularProgressIndicator(color = MaterialTheme.colorScheme.primary)
content = { paddingValues ->
Crossfade(
targetState = viewModel.state.isLoading,
label = "reader content loading cross fade"
) { loading ->
if (loading) {
Box(
modifier = Modifier
.fillMaxSize()
.padding(bottom = 65.dp),
contentAlignment = Alignment.Center
) {
CircularProgressIndicator(color = MaterialTheme.colorScheme.primary)
}
} else {
readerContent(paddingValues)
}
} else {
readerContent(it)
}
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ fun GeneralOptionsUI(viewModel: SettingsViewModel) {
}
}
}) {
Text(stringResource(id = R.string.dialog_confirm_button))
Text(stringResource(id = R.string.confirm))
}
}, dismissButton = {
TextButton(onClick = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ fun WelcomeScreen(navController: NavController) {
}
}
}) {
Text(stringResource(id = R.string.dialog_confirm_button))
Text(stringResource(id = R.string.confirm))
}
}, dismissButton = {
TextButton(onClick = {
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/com/starry/myne/utils/Preferencesutils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ class PreferenceUtil(context: Context) {
const val READER_FONT_SIZE_INT = "reader_font_size"
const val READER_FONT_STYLE_STR = "reader_font_style"
const val PREFERRED_BOOK_LANG_STR = "preferred_book_language"

// Temporary preference keys
const val SHOW_LIBRARY_TOOLTIP_BOOL = "show_library_tooltip"
}

private var prefs: SharedPreferences
Expand Down
7 changes: 6 additions & 1 deletion app/src/main/res/values-ar/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
<!-- Others Strings -->
<string name="not_applicable">غير معروف</string>
<string name="woops">اووبس!!</string>
<string name="dialog_confirm_button">تأكيد</string>
<string name="confirm">تأكيد</string>
<string name="cancel">الغاء</string>
<string name="ok">OK</string>
<string name="got_it">Got it</string>
<string name="storage_perm_error">امنح اذن التخزين من فضلك</string>
<string name="no_app_to_handle_epub">لا يوجد اى تطبيق لفتح ملف epub</string>
<string name="network_error">أُووبس! فشل الاتصال بالخادم.</string>
Expand All @@ -17,6 +19,9 @@
<string name="navigation_library">المكتبة</string>
<string name="navigation_settings">الاعدادات</string>

<!-- ToolTips -->
<string name="library_tooltip">TIP! Swipe library items left or right to share or view book details.</string>

<!-- Welcome Screen -->
<string name="welcome_screen_text">شكرًا لك على تثبيت Myne!\nالرجاء تحديد قارئ الكتب الإلكترونية المفضل لديك للحصول على السرعة.</string>
<string name="welcome_screen_button">البدء</string>
Expand Down
7 changes: 6 additions & 1 deletion app/src/main/res/values-cs/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
<!-- Others Strings -->
<string name="not_applicable">N/A</string>
<string name="woops">"Jejda!"</string>
<string name="dialog_confirm_button">Potvrdit</string>
<string name="confirm">Potvrdit</string>
<string name="cancel">Zrušit</string>
<string name="ok">OK</string>
<string name="got_it">Got it</string>
<string name="storage_perm_error">Udělte prosím přístup k úložišti!</string>
<string name="no_app_to_handle_epub">Nepodařilo se najít aplikaci, která by dokázala otevřít soubor epub.</string>
<string name="network_error">Oops! Failed to connect with the server.</string>
Expand All @@ -16,6 +18,9 @@
<string name="navigation_library">Knihovna</string>
<string name="navigation_settings">Nastavení</string>

<!-- ToolTips -->
<string name="library_tooltip">TIP! Swipe library items left or right to share or view book details.</string>

<!-- Welcome Screen -->
<string name="welcome_screen_text">ThankYou for installing Myne!\nPlease Select your preferred e-book reader to get on speed.</string>
<string name="welcome_screen_button">Get Started</string>
Expand Down
7 changes: 6 additions & 1 deletion app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
<!-- Others Strings -->
<string name="not_applicable">N/A</string>
<string name="woops">"¡Ups!"</string>
<string name="dialog_confirm_button">Confirmar</string>
<string name="confirm">Confirmar</string>
<string name="cancel">Cancelar</string>
<string name="ok">OK</string>
<string name="got_it">Got it</string>
<string name="storage_perm_error">Por favor, acepte el permiso de almacenamiento</string>
<string name="no_app_to_handle_epub">No se ha podido encontrar ninguna aplicación para abrir el fichero epub.</string>
<string name="network_error">Oops! Failed to connect with the server.</string>
Expand All @@ -17,6 +19,9 @@
<string name="navigation_library">Biblioteca</string>
<string name="navigation_settings">Ajustes</string>

<!-- ToolTips -->
<string name="library_tooltip">TIP! Swipe library items left or right to share or view book details.</string>

<!-- Welcome Screen -->
<string name="welcome_screen_text">ThankYou for installing Myne!\nPlease Select your preferred e-book reader to get on speed.</string>
<string name="welcome_screen_button">Get Started</string>
Expand Down
Loading

0 comments on commit c4d9a47

Please sign in to comment.