From 153fd8f346bade4d2aa52151614483aab0b03dd5 Mon Sep 17 00:00:00 2001 From: starry-shivam Date: Fri, 15 Dec 2023 14:02:38 +0530 Subject: [PATCH 1/3] Remove depreceiated stuff from navigation graph And cleanup duplicate code Signed-off-by: starry-shivam --- app/build.gradle | 2 +- .../java/com/starry/myne/MainViewModel.kt | 1 + .../com/starry/myne/ui/navigation/NavGraph.kt | 285 +++++------------- .../starry/myne/ui/screens/main/MainScreen.kt | 4 +- 4 files changed, 82 insertions(+), 210 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 373b9d92..f5ef00cc 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -85,6 +85,7 @@ dependencies { implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.6.2' implementation 'androidx.activity:activity-compose:1.8.2' implementation "androidx.lifecycle:lifecycle-viewmodel-compose:2.6.2" + implementation "androidx.navigation:navigation-compose:2.7.6" // Jetpack compose. implementation "androidx.compose.ui:ui" implementation "androidx.compose.ui:ui-tooling-preview" @@ -94,7 +95,6 @@ dependencies { implementation "androidx.compose.material3:material3" // Accompanist compose. implementation "com.google.accompanist:accompanist-systemuicontroller:0.28.0" - implementation "com.google.accompanist:accompanist-navigation-animation:0.33.1-alpha" // Recycler View for reader. implementation "androidx.recyclerview:recyclerview:1.3.2" // Material theme for main activity. diff --git a/app/src/main/java/com/starry/myne/MainViewModel.kt b/app/src/main/java/com/starry/myne/MainViewModel.kt index e8785bce..2475942f 100644 --- a/app/src/main/java/com/starry/myne/MainViewModel.kt +++ b/app/src/main/java/com/starry/myne/MainViewModel.kt @@ -42,6 +42,7 @@ class MainViewModel @Inject constructor(private val welcomeDataStore: WelcomeDat init { viewModelScope.launch { + // Check if user has completed onboarding. welcomeDataStore.readOnBoardingState().collect { completed -> if (completed) { _startDestination.value = BottomBarScreen.Home.route diff --git a/app/src/main/java/com/starry/myne/ui/navigation/NavGraph.kt b/app/src/main/java/com/starry/myne/ui/navigation/NavGraph.kt index 30376841..94e220b3 100644 --- a/app/src/main/java/com/starry/myne/ui/navigation/NavGraph.kt +++ b/app/src/main/java/com/starry/myne/ui/navigation/NavGraph.kt @@ -32,10 +32,10 @@ import androidx.compose.ui.ExperimentalComposeUiApi import androidx.compose.ui.Modifier import androidx.navigation.NavHostController import androidx.navigation.NavType +import androidx.navigation.compose.NavHost +import androidx.navigation.compose.composable import androidx.navigation.navArgument import coil.annotation.ExperimentalCoilApi -import com.google.accompanist.navigation.animation.AnimatedNavHost -import com.google.accompanist.navigation.animation.composable import com.starry.myne.others.NetworkObserver import com.starry.myne.ui.screens.categories.composables.CategoriesScreen import com.starry.myne.ui.screens.categories.composables.CategoryDetailScreen @@ -48,6 +48,34 @@ import com.starry.myne.ui.screens.settings.composables.OSLScreen import com.starry.myne.ui.screens.settings.composables.SettingsScreen import com.starry.myne.ui.screens.welcome.composables.WelcomeScreen + +private const val NAVIGATION_ANIM_DURATION = 300 +private const val FADEIN_ANIM_DURATION = 400 + +private fun enterTransition() = slideInHorizontally( + initialOffsetX = { NAVIGATION_ANIM_DURATION }, animationSpec = tween( + durationMillis = NAVIGATION_ANIM_DURATION, easing = FastOutSlowInEasing + ) +) + fadeIn(animationSpec = tween(NAVIGATION_ANIM_DURATION)) + +private fun exitTransition() = slideOutHorizontally( + targetOffsetX = { -NAVIGATION_ANIM_DURATION }, animationSpec = tween( + durationMillis = NAVIGATION_ANIM_DURATION, easing = FastOutSlowInEasing + ) +) + fadeOut(animationSpec = tween(NAVIGATION_ANIM_DURATION)) + +private fun popEnterTransition() = slideInHorizontally( + initialOffsetX = { -NAVIGATION_ANIM_DURATION }, animationSpec = tween( + durationMillis = NAVIGATION_ANIM_DURATION, easing = FastOutSlowInEasing + ) +) + fadeIn(animationSpec = tween(NAVIGATION_ANIM_DURATION)) + +private fun popExitTransition() = slideOutHorizontally( + targetOffsetX = { NAVIGATION_ANIM_DURATION }, animationSpec = tween( + durationMillis = NAVIGATION_ANIM_DURATION, easing = FastOutSlowInEasing + ) +) + fadeOut(animationSpec = tween(NAVIGATION_ANIM_DURATION)) + @ExperimentalAnimationApi @ExperimentalMaterialApi @ExperimentalCoilApi @@ -59,7 +87,7 @@ fun NavGraph( navController: NavHostController, networkStatus: NetworkObserver.Status, ) { - AnimatedNavHost( + NavHost( navController = navController, startDestination = startDestination, modifier = Modifier.background(MaterialTheme.colorScheme.background) @@ -68,49 +96,26 @@ fun NavGraph( /** Welcome Screen */ composable( route = Screens.WelcomeScreen.route, - exitTransition = { - slideOutHorizontally( - targetOffsetX = { -300 }, animationSpec = tween( - durationMillis = 300, easing = FastOutSlowInEasing - ) - ) + fadeOut(animationSpec = tween(300)) - }, - popEnterTransition = { - slideInHorizontally( - initialOffsetX = { -300 }, animationSpec = tween( - durationMillis = 300, easing = FastOutSlowInEasing - ) - ) + fadeIn(animationSpec = tween(300)) - - }, + exitTransition = { exitTransition() }, + popEnterTransition = { popEnterTransition() }, ) { WelcomeScreen(navController = navController) } /** Home Screen */ - composable( - route = BottomBarScreen.Home.route, - enterTransition = { fadeIn(animationSpec = tween(400)) }, + composable(route = BottomBarScreen.Home.route, + enterTransition = { fadeIn(animationSpec = tween(FADEIN_ANIM_DURATION)) }, exitTransition = { if (initialState.destination.route == Screens.BookDetailScreen.route) { - slideOutHorizontally( - targetOffsetX = { -300 }, animationSpec = tween( - durationMillis = 300, easing = FastOutSlowInEasing - ) - ) + fadeOut(animationSpec = tween(300)) - } else fadeOut(animationSpec = tween(400)) + exitTransition() + } else fadeOut(animationSpec = tween(FADEIN_ANIM_DURATION)) }, popEnterTransition = { if (targetState.destination.route == Screens.BookDetailScreen.route) { - slideInHorizontally( - initialOffsetX = { -300 }, animationSpec = tween( - durationMillis = 300, easing = FastOutSlowInEasing - ) - ) + fadeIn(animationSpec = tween(300)) - } else fadeIn(animationSpec = tween(400)) + popEnterTransition() + } else fadeIn(animationSpec = tween(FADEIN_ANIM_DURATION)) }, - popExitTransition = { fadeOut(animationSpec = tween(400)) } - ) { + popExitTransition = { fadeOut(animationSpec = tween(FADEIN_ANIM_DURATION)) }) { HomeScreen(navController, networkStatus) } @@ -122,65 +127,29 @@ fun NavGraph( type = NavType.StringType }, ), - enterTransition = { - slideInHorizontally( - initialOffsetX = { 300 }, animationSpec = tween( - durationMillis = 300, easing = FastOutSlowInEasing - ) - ) + fadeIn(animationSpec = tween(300)) - }, - exitTransition = { - slideOutHorizontally( - targetOffsetX = { -300 }, animationSpec = tween( - durationMillis = 300, easing = FastOutSlowInEasing - ) - ) + fadeOut(animationSpec = tween(300)) - - }, - popEnterTransition = { - slideInHorizontally( - initialOffsetX = { -300 }, animationSpec = tween( - durationMillis = 300, easing = FastOutSlowInEasing - ) - ) + fadeIn(animationSpec = tween(300)) - - }, - popExitTransition = { - slideOutHorizontally( - targetOffsetX = { 300 }, animationSpec = tween( - durationMillis = 300, easing = FastOutSlowInEasing - ) - ) + fadeOut(animationSpec = tween(300)) - }, + enterTransition = { enterTransition() }, + exitTransition = { exitTransition() }, + popEnterTransition = { popEnterTransition() }, + popExitTransition = { popExitTransition() }, ) { backStackEntry -> val bookId = backStackEntry.arguments!!.getString(BOOK_ID_ARG_KEY)!! BookDetailScreen(bookId, navController) } /** Categories Screen */ - composable( - route = BottomBarScreen.Categories.route, - enterTransition = { fadeIn(animationSpec = tween(400)) }, + composable(route = BottomBarScreen.Categories.route, + enterTransition = { fadeIn(animationSpec = tween(FADEIN_ANIM_DURATION)) }, exitTransition = { if (initialState.destination.route == Screens.CategoryDetailScreen.route) { - slideOutHorizontally( - targetOffsetX = { -300 }, animationSpec = tween( - durationMillis = 300, easing = FastOutSlowInEasing - ) - ) + fadeOut(animationSpec = tween(300)) - } else fadeOut(animationSpec = tween(400)) + exitTransition() + } else fadeOut(animationSpec = tween(FADEIN_ANIM_DURATION)) }, popEnterTransition = { if (targetState.destination.route == Screens.CategoryDetailScreen.route) { - slideInHorizontally( - initialOffsetX = { -300 }, animationSpec = tween( - durationMillis = 300, easing = FastOutSlowInEasing - ) - ) + fadeIn(animationSpec = tween(300)) - } else fadeIn(animationSpec = tween(400)) + popEnterTransition() + } else fadeIn(animationSpec = tween(FADEIN_ANIM_DURATION)) }, - popExitTransition = { fadeOut(animationSpec = tween(400)) } - ) { + popExitTransition = { fadeOut(animationSpec = tween(FADEIN_ANIM_DURATION)) }) { CategoriesScreen(navController) } @@ -190,65 +159,29 @@ fun NavGraph( arguments = listOf(navArgument(CATEGORY_DETAIL_ARG_KEY) { type = NavType.StringType }), - enterTransition = { - slideInHorizontally( - initialOffsetX = { 300 }, animationSpec = tween( - durationMillis = 300, easing = FastOutSlowInEasing - ) - ) + fadeIn(animationSpec = tween(300)) - }, - exitTransition = { - slideOutHorizontally( - targetOffsetX = { -300 }, animationSpec = tween( - durationMillis = 300, easing = FastOutSlowInEasing - ) - ) + fadeOut(animationSpec = tween(300)) - - }, - popEnterTransition = { - slideInHorizontally( - initialOffsetX = { -300 }, animationSpec = tween( - durationMillis = 300, easing = FastOutSlowInEasing - ) - ) + fadeIn(animationSpec = tween(300)) - - }, - popExitTransition = { - slideOutHorizontally( - targetOffsetX = { 300 }, animationSpec = tween( - durationMillis = 300, easing = FastOutSlowInEasing - ) - ) + fadeOut(animationSpec = tween(300)) - }, + enterTransition = { enterTransition() }, + exitTransition = { exitTransition() }, + popEnterTransition = { popEnterTransition() }, + popExitTransition = { popExitTransition() }, ) { backStackEntry -> val category = backStackEntry.arguments!!.getString(CATEGORY_DETAIL_ARG_KEY)!! CategoryDetailScreen(category, navController, networkStatus) } /** Library Screen */ - composable( - route = BottomBarScreen.Library.route, - enterTransition = { fadeIn(animationSpec = tween(400)) }, + composable(route = BottomBarScreen.Library.route, + enterTransition = { fadeIn(animationSpec = tween(FADEIN_ANIM_DURATION)) }, exitTransition = { if (initialState.destination.route == Screens.BookDetailScreen.route) { - slideOutHorizontally( - targetOffsetX = { -300 }, animationSpec = tween( - durationMillis = 300, easing = FastOutSlowInEasing - ) - ) + fadeOut(animationSpec = tween(300)) - } else fadeOut(animationSpec = tween(400)) + exitTransition() + } else fadeOut(animationSpec = tween(FADEIN_ANIM_DURATION)) }, popEnterTransition = { if (targetState.destination.route == BottomBarScreen.Library.route) { - slideInHorizontally( - initialOffsetX = { -300 }, animationSpec = tween( - durationMillis = 300, easing = FastOutSlowInEasing - ) - ) + fadeIn(animationSpec = tween(300)) - } else fadeIn(animationSpec = tween(400)) + popEnterTransition() + } else fadeIn(animationSpec = tween(FADEIN_ANIM_DURATION)) }, - popExitTransition = { fadeOut(animationSpec = tween(400)) } - ) { + popExitTransition = { fadeOut(animationSpec = tween(FADEIN_ANIM_DURATION)) }) { LibraryScreen(navController) } @@ -260,89 +193,39 @@ fun NavGraph( ) { type = NavType.StringType }), - enterTransition = { - slideInHorizontally( - initialOffsetX = { 300 }, animationSpec = tween( - durationMillis = 300, easing = FastOutSlowInEasing - ) - ) + fadeIn(animationSpec = tween(300)) - }, - exitTransition = { - slideOutHorizontally( - targetOffsetX = { -300 }, animationSpec = tween( - durationMillis = 300, easing = FastOutSlowInEasing - ) - ) + fadeOut(animationSpec = tween(300)) - - }, - popEnterTransition = { - slideInHorizontally( - initialOffsetX = { -300 }, animationSpec = tween( - durationMillis = 300, easing = FastOutSlowInEasing - ) - ) + fadeIn(animationSpec = tween(300)) - - }, - popExitTransition = { - slideOutHorizontally( - targetOffsetX = { 300 }, animationSpec = tween( - durationMillis = 300, easing = FastOutSlowInEasing - ) - ) + fadeOut(animationSpec = tween(300)) - }, + enterTransition = { enterTransition() }, + exitTransition = { exitTransition() }, + popEnterTransition = { popEnterTransition() }, + popExitTransition = { popExitTransition() }, ) { backStackEntry -> val bookId = backStackEntry.arguments!!.getString(BOOK_ID_ARG_KEY)!! ReaderDetailScreen( - bookId = bookId, - navController = navController, - networkStatus = networkStatus + bookId = bookId, navController = navController, networkStatus = networkStatus ) } /** Settings Screen */ - composable( - route = BottomBarScreen.Settings.route, - enterTransition = { fadeIn(animationSpec = tween(400)) }, + composable(route = BottomBarScreen.Settings.route, + enterTransition = { fadeIn(animationSpec = tween(FADEIN_ANIM_DURATION)) }, exitTransition = { if (initialState.destination.route == Screens.OSLScreen.route || initialState.destination.route == Screens.AboutScreen.route) { - slideOutHorizontally( - targetOffsetX = { -300 }, animationSpec = tween( - durationMillis = 300, easing = FastOutSlowInEasing - ) - ) + fadeOut(animationSpec = tween(300)) - } else fadeOut(animationSpec = tween(400)) + exitTransition() + } else fadeOut(animationSpec = tween(FADEIN_ANIM_DURATION)) }, popEnterTransition = { if (initialState.destination.route == Screens.OSLScreen.route || initialState.destination.route == Screens.AboutScreen.route) { - slideInHorizontally( - initialOffsetX = { -300 }, animationSpec = tween( - durationMillis = 300, easing = FastOutSlowInEasing - ) - ) + fadeIn(animationSpec = tween(300)) - } else fadeIn(animationSpec = tween(400)) + popEnterTransition() + } else fadeIn(animationSpec = tween(FADEIN_ANIM_DURATION)) }, - popExitTransition = { fadeOut(animationSpec = tween(400)) } - ) { + popExitTransition = { fadeOut(animationSpec = tween(FADEIN_ANIM_DURATION)) }) { SettingsScreen(navController) } /** Open Source Licenses Screen */ composable( route = Screens.OSLScreen.route, - enterTransition = { - slideInHorizontally( - initialOffsetX = { 300 }, animationSpec = tween( - durationMillis = 300, easing = FastOutSlowInEasing - ) - ) + fadeIn(animationSpec = tween(300)) - }, - popExitTransition = { - slideOutHorizontally( - targetOffsetX = { 300 }, animationSpec = tween( - durationMillis = 300, easing = FastOutSlowInEasing - ) - ) + fadeOut(animationSpec = tween(300)) - }, + enterTransition = { enterTransition() }, + popExitTransition = { popExitTransition() }, ) { OSLScreen(navController = navController) } @@ -350,20 +233,8 @@ fun NavGraph( /** About Screen */ composable( route = Screens.AboutScreen.route, - enterTransition = { - slideInHorizontally( - initialOffsetX = { 300 }, animationSpec = tween( - durationMillis = 300, easing = FastOutSlowInEasing - ) - ) + fadeIn(animationSpec = tween(300)) - }, - popExitTransition = { - slideOutHorizontally( - targetOffsetX = { 300 }, animationSpec = tween( - durationMillis = 300, easing = FastOutSlowInEasing - ) - ) + fadeOut(animationSpec = tween(300)) - }, + enterTransition = { enterTransition() }, + popExitTransition = { popExitTransition() }, ) { AboutScreen(navController = navController) } diff --git a/app/src/main/java/com/starry/myne/ui/screens/main/MainScreen.kt b/app/src/main/java/com/starry/myne/ui/screens/main/MainScreen.kt index 4cfc258f..73543fa2 100644 --- a/app/src/main/java/com/starry/myne/ui/screens/main/MainScreen.kt +++ b/app/src/main/java/com/starry/myne/ui/screens/main/MainScreen.kt @@ -46,8 +46,8 @@ import androidx.compose.ui.unit.dp import androidx.navigation.NavGraph.Companion.findStartDestination import androidx.navigation.NavHostController import androidx.navigation.compose.currentBackStackEntryAsState +import androidx.navigation.compose.rememberNavController import coil.annotation.ExperimentalCoilApi -import com.google.accompanist.navigation.animation.rememberAnimatedNavController import com.google.accompanist.systemuicontroller.SystemUiController import com.google.accompanist.systemuicontroller.rememberSystemUiController import com.starry.myne.others.NetworkObserver @@ -69,7 +69,7 @@ fun MainScreen( networkStatus: NetworkObserver.Status, settingsViewModel: SettingsViewModel, ) { - val navController = rememberAnimatedNavController() + val navController = rememberNavController() val systemUiController = rememberSystemUiController() systemUiController.setStatusBarColor( From 2f20b02d1edab03cab6feac0b88a379e939ca66b Mon Sep 17 00:00:00 2001 From: starry-shivam Date: Fri, 15 Dec 2023 15:11:44 +0530 Subject: [PATCH 2/3] Remove 'others' package and move items in utils Signed-off-by: starry-shivam --- .../main/java/com/starry/myne/MainActivity.kt | 2 +- .../java/com/starry/myne/MainViewModel.kt | 2 +- .../com/starry/myne/database/MyneDatabase.kt | 2 +- .../java/com/starry/myne/di/MainModule.kt | 4 ++-- .../com/starry/myne/repo/BookRepository.kt | 24 +++++++------------ .../com/starry/myne/ui/navigation/NavGraph.kt | 2 +- .../composables/CategoryDetailScreen.kt | 6 ++--- .../viewmodels/CategoryViewModel.kt | 11 +++++++-- .../detail/composables/BookDetailScreen.kt | 2 +- .../detail/viewmodels/BookDetailViewModel.kt | 4 ++-- .../ui/screens/home/composables/HomeScreen.kt | 6 ++--- .../screens/home/viewmodels/HomeViewModel.kt | 13 +++++++--- .../starry/myne/ui/screens/main/MainScreen.kt | 2 +- .../reader/composables/ReaderDetailScreen.kt | 2 +- .../viewmodels/ReaderDetailViewModel.kt | 2 +- .../settings/composables/AboutScreen.kt | 2 +- .../welcome/viewmodels}/WelcomeDataStore.kt | 2 +- .../welcome/viewmodels/WelcomeViewModel.kt | 1 - .../myne/{others => utils}/Constants.kt | 2 +- .../java/com/starry/myne/utils/Extensions.kt | 18 ++++++++++++++ .../myne/{others => utils}/NetworkObserver.kt | 2 +- .../myne/{others => utils}/Paginator.kt | 2 +- .../myne/utils/{ => book}/BookDownloader.kt | 4 ++-- .../{others => utils/book}/BookLanguage.kt | 2 +- .../starry/myne/utils/{ => book}/BookUtils.kt | 2 +- .../java/com/starry/myne/BookUtilsTest.kt | 2 +- .../java/com/starry/myne/PaginatorTest.kt | 2 +- 27 files changed, 75 insertions(+), 50 deletions(-) rename app/src/main/java/com/starry/myne/{others => ui/screens/welcome/viewmodels}/WelcomeDataStore.kt (97%) rename app/src/main/java/com/starry/myne/{others => utils}/Constants.kt (96%) rename app/src/main/java/com/starry/myne/{others => utils}/NetworkObserver.kt (98%) rename app/src/main/java/com/starry/myne/{others => utils}/Paginator.kt (98%) rename app/src/main/java/com/starry/myne/utils/{ => book}/BookDownloader.kt (98%) rename app/src/main/java/com/starry/myne/{others => utils/book}/BookLanguage.kt (97%) rename app/src/main/java/com/starry/myne/utils/{ => book}/BookUtils.kt (98%) diff --git a/app/src/main/java/com/starry/myne/MainActivity.kt b/app/src/main/java/com/starry/myne/MainActivity.kt index 9388c4d8..76a4bfb6 100644 --- a/app/src/main/java/com/starry/myne/MainActivity.kt +++ b/app/src/main/java/com/starry/myne/MainActivity.kt @@ -38,7 +38,7 @@ import androidx.core.app.ActivityCompat import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen import androidx.lifecycle.ViewModelProvider import coil.annotation.ExperimentalCoilApi -import com.starry.myne.others.NetworkObserver +import com.starry.myne.utils.NetworkObserver import com.starry.myne.ui.screens.main.MainScreen import com.starry.myne.ui.screens.settings.viewmodels.SettingsViewModel import com.starry.myne.ui.screens.settings.viewmodels.ThemeMode diff --git a/app/src/main/java/com/starry/myne/MainViewModel.kt b/app/src/main/java/com/starry/myne/MainViewModel.kt index 2475942f..c6f7a2d7 100644 --- a/app/src/main/java/com/starry/myne/MainViewModel.kt +++ b/app/src/main/java/com/starry/myne/MainViewModel.kt @@ -22,7 +22,7 @@ import androidx.compose.runtime.State import androidx.compose.runtime.mutableStateOf import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope -import com.starry.myne.others.WelcomeDataStore +import com.starry.myne.ui.screens.welcome.viewmodels.WelcomeDataStore import com.starry.myne.ui.navigation.BottomBarScreen import com.starry.myne.ui.navigation.Screens import dagger.hilt.android.lifecycle.HiltViewModel diff --git a/app/src/main/java/com/starry/myne/database/MyneDatabase.kt b/app/src/main/java/com/starry/myne/database/MyneDatabase.kt index 7d123756..2a2adb4b 100644 --- a/app/src/main/java/com/starry/myne/database/MyneDatabase.kt +++ b/app/src/main/java/com/starry/myne/database/MyneDatabase.kt @@ -25,7 +25,7 @@ import com.starry.myne.database.library.LibraryDao import com.starry.myne.database.library.LibraryItem import com.starry.myne.database.reader.ReaderDao import com.starry.myne.database.reader.ReaderItem -import com.starry.myne.others.Constants +import com.starry.myne.utils.Constants @Database( entities = [LibraryItem::class, ReaderItem::class], diff --git a/app/src/main/java/com/starry/myne/di/MainModule.kt b/app/src/main/java/com/starry/myne/di/MainModule.kt index 0c9de2b5..e8f9c9d5 100644 --- a/app/src/main/java/com/starry/myne/di/MainModule.kt +++ b/app/src/main/java/com/starry/myne/di/MainModule.kt @@ -19,9 +19,9 @@ package com.starry.myne.di import android.content.Context import com.starry.myne.database.MyneDatabase -import com.starry.myne.others.WelcomeDataStore +import com.starry.myne.ui.screens.welcome.viewmodels.WelcomeDataStore import com.starry.myne.repo.BookRepository -import com.starry.myne.utils.BookDownloader +import com.starry.myne.utils.book.BookDownloader import com.starry.myne.utils.PreferenceUtil import dagger.Module import dagger.Provides diff --git a/app/src/main/java/com/starry/myne/repo/BookRepository.kt b/app/src/main/java/com/starry/myne/repo/BookRepository.kt index 38596304..e7f63ecd 100644 --- a/app/src/main/java/com/starry/myne/repo/BookRepository.kt +++ b/app/src/main/java/com/starry/myne/repo/BookRepository.kt @@ -17,7 +17,7 @@ limitations under the License. package com.starry.myne.repo import com.google.gson.Gson -import com.starry.myne.others.BookLanguage +import com.starry.myne.utils.book.BookLanguage import com.starry.myne.repo.models.BookSet import com.starry.myne.repo.models.ExtraInfo import kotlinx.coroutines.Dispatchers @@ -43,9 +43,11 @@ class BookRepository { private val googleBooksUrl = "https://www.googleapis.com/books/v1/volumes" private val googleApiKey = "AIzaSyBCaXx-U0sbEpGVPWylSggC4RaR4gCGkVE" - - private val okHttpClient = OkHttpClient.Builder().connectTimeout(60, TimeUnit.SECONDS) - .writeTimeout(60, TimeUnit.SECONDS).readTimeout(100, TimeUnit.SECONDS).build() + private val okHttpClient = OkHttpClient.Builder() + .connectTimeout(60, TimeUnit.SECONDS) + .writeTimeout(60, TimeUnit.SECONDS) + .readTimeout(100, TimeUnit.SECONDS) + .build() private val gsonClient = Gson() @@ -102,9 +104,7 @@ class BookRepository { response.use { continuation.resume( Result.success( - gsonClient.fromJson( - response.body!!.string(), BookSet::class.java - ) + gsonClient.fromJson(response.body!!.string(), BookSet::class.java) ) ) } @@ -124,9 +124,7 @@ class BookRepository { override fun onResponse(call: Call, response: Response) { response.use { - continuation.resume( - parseExtraInfoJson(response.body!!.string()) - ) + continuation.resume(parseExtraInfoJson(response.body!!.string())) } } }) @@ -175,11 +173,7 @@ class BookRepository { } override fun onResponse(call: Call, response: Response) { - response.use { - continuation.resume( - response.body!!.string() - ) - } + response.use { continuation.resume(response.body!!.string()) } } }) } diff --git a/app/src/main/java/com/starry/myne/ui/navigation/NavGraph.kt b/app/src/main/java/com/starry/myne/ui/navigation/NavGraph.kt index 94e220b3..47f2fd1d 100644 --- a/app/src/main/java/com/starry/myne/ui/navigation/NavGraph.kt +++ b/app/src/main/java/com/starry/myne/ui/navigation/NavGraph.kt @@ -36,7 +36,7 @@ import androidx.navigation.compose.NavHost import androidx.navigation.compose.composable import androidx.navigation.navArgument import coil.annotation.ExperimentalCoilApi -import com.starry.myne.others.NetworkObserver +import com.starry.myne.utils.NetworkObserver import com.starry.myne.ui.screens.categories.composables.CategoriesScreen import com.starry.myne.ui.screens.categories.composables.CategoryDetailScreen import com.starry.myne.ui.screens.detail.composables.BookDetailScreen diff --git a/app/src/main/java/com/starry/myne/ui/screens/categories/composables/CategoryDetailScreen.kt b/app/src/main/java/com/starry/myne/ui/screens/categories/composables/CategoryDetailScreen.kt index 687400d6..c7d7d7a6 100644 --- a/app/src/main/java/com/starry/myne/ui/screens/categories/composables/CategoryDetailScreen.kt +++ b/app/src/main/java/com/starry/myne/ui/screens/categories/composables/CategoryDetailScreen.kt @@ -55,8 +55,8 @@ import androidx.hilt.navigation.compose.hiltViewModel import androidx.navigation.NavController import coil.annotation.ExperimentalCoilApi import com.starry.myne.R -import com.starry.myne.others.BookLanguage -import com.starry.myne.others.NetworkObserver +import com.starry.myne.utils.book.BookLanguage +import com.starry.myne.utils.NetworkObserver import com.starry.myne.ui.common.BookItemCard import com.starry.myne.ui.common.CustomTopAppBar import com.starry.myne.ui.common.NoBooksAvailable @@ -66,7 +66,7 @@ import com.starry.myne.ui.screens.categories.viewmodels.CategoryViewModel import com.starry.myne.ui.screens.home.composables.LanguageItem import com.starry.myne.ui.screens.other.NetworkError import com.starry.myne.ui.theme.pacificoFont -import com.starry.myne.utils.BookUtils +import com.starry.myne.utils.book.BookUtils import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.launch import java.util.Locale diff --git a/app/src/main/java/com/starry/myne/ui/screens/categories/viewmodels/CategoryViewModel.kt b/app/src/main/java/com/starry/myne/ui/screens/categories/viewmodels/CategoryViewModel.kt index ed25c130..05e04a6e 100644 --- a/app/src/main/java/com/starry/myne/ui/screens/categories/viewmodels/CategoryViewModel.kt +++ b/app/src/main/java/com/starry/myne/ui/screens/categories/viewmodels/CategoryViewModel.kt @@ -24,8 +24,8 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.setValue import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope -import com.starry.myne.others.BookLanguage -import com.starry.myne.others.Paginator +import com.starry.myne.utils.book.BookLanguage +import com.starry.myne.utils.Paginator import com.starry.myne.repo.BookRepository import com.starry.myne.repo.models.Book import com.starry.myne.repo.models.BookSet @@ -100,6 +100,13 @@ class CategoryViewModel @Inject constructor( state = state.copy(error = it?.localizedMessage ?: "unknown-error") }, onSuccess = { bookSet, newPage -> + /** + * usually bookSet.books is not nullable and API simply returns empty list + * when browsing books all books (i.e. without passing language parameter) + * however, when browsing by language it returns a response which looks like + * this: {"detail": "Invalid page."}. Hence the [BookSet] attributes become + * null in this case and can cause crashes. + */ /** * usually bookSet.books is not nullable and API simply returns empty list * when browsing books all books (i.e. without passing language parameter) diff --git a/app/src/main/java/com/starry/myne/ui/screens/detail/composables/BookDetailScreen.kt b/app/src/main/java/com/starry/myne/ui/screens/detail/composables/BookDetailScreen.kt index 56a69b14..d40e47e2 100644 --- a/app/src/main/java/com/starry/myne/ui/screens/detail/composables/BookDetailScreen.kt +++ b/app/src/main/java/com/starry/myne/ui/screens/detail/composables/BookDetailScreen.kt @@ -102,7 +102,7 @@ import com.starry.myne.ui.screens.other.NetworkError import com.starry.myne.ui.screens.settings.viewmodels.ThemeMode import com.starry.myne.ui.theme.figeronaFont import com.starry.myne.ui.theme.pacificoFont -import com.starry.myne.utils.BookUtils +import com.starry.myne.utils.book.BookUtils import com.starry.myne.utils.Utils import com.starry.myne.utils.getActivity import kotlinx.coroutines.Dispatchers diff --git a/app/src/main/java/com/starry/myne/ui/screens/detail/viewmodels/BookDetailViewModel.kt b/app/src/main/java/com/starry/myne/ui/screens/detail/viewmodels/BookDetailViewModel.kt index 531e0214..f91579ab 100644 --- a/app/src/main/java/com/starry/myne/ui/screens/detail/viewmodels/BookDetailViewModel.kt +++ b/app/src/main/java/com/starry/myne/ui/screens/detail/viewmodels/BookDetailViewModel.kt @@ -34,8 +34,8 @@ import com.starry.myne.repo.BookRepository import com.starry.myne.repo.models.Book import com.starry.myne.repo.models.BookSet import com.starry.myne.repo.models.ExtraInfo -import com.starry.myne.utils.BookDownloader -import com.starry.myne.utils.BookUtils +import com.starry.myne.utils.book.BookDownloader +import com.starry.myne.utils.book.BookUtils import com.starry.myne.utils.PreferenceUtil import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.Dispatchers diff --git a/app/src/main/java/com/starry/myne/ui/screens/home/composables/HomeScreen.kt b/app/src/main/java/com/starry/myne/ui/screens/home/composables/HomeScreen.kt index e41c9532..a3911dca 100644 --- a/app/src/main/java/com/starry/myne/ui/screens/home/composables/HomeScreen.kt +++ b/app/src/main/java/com/starry/myne/ui/screens/home/composables/HomeScreen.kt @@ -90,8 +90,8 @@ import androidx.navigation.NavController import androidx.navigation.compose.rememberNavController import coil.annotation.ExperimentalCoilApi import com.starry.myne.R -import com.starry.myne.others.BookLanguage -import com.starry.myne.others.NetworkObserver +import com.starry.myne.utils.book.BookLanguage +import com.starry.myne.utils.NetworkObserver import com.starry.myne.ui.common.BookItemCard import com.starry.myne.ui.common.ProgressDots import com.starry.myne.ui.navigation.Screens @@ -100,7 +100,7 @@ import com.starry.myne.ui.screens.home.viewmodels.UserAction import com.starry.myne.ui.screens.other.NetworkError import com.starry.myne.ui.theme.figeronaFont import com.starry.myne.ui.theme.pacificoFont -import com.starry.myne.utils.BookUtils +import com.starry.myne.utils.book.BookUtils import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.launch diff --git a/app/src/main/java/com/starry/myne/ui/screens/home/viewmodels/HomeViewModel.kt b/app/src/main/java/com/starry/myne/ui/screens/home/viewmodels/HomeViewModel.kt index cd134ef2..3facd196 100644 --- a/app/src/main/java/com/starry/myne/ui/screens/home/viewmodels/HomeViewModel.kt +++ b/app/src/main/java/com/starry/myne/ui/screens/home/viewmodels/HomeViewModel.kt @@ -23,9 +23,9 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.setValue import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope -import com.starry.myne.others.BookLanguage -import com.starry.myne.others.NetworkObserver -import com.starry.myne.others.Paginator +import com.starry.myne.utils.book.BookLanguage +import com.starry.myne.utils.NetworkObserver +import com.starry.myne.utils.Paginator import com.starry.myne.repo.BookRepository import com.starry.myne.repo.models.Book import com.starry.myne.repo.models.BookSet @@ -89,6 +89,13 @@ class HomeViewModel @Inject constructor( }, onError = { allBooksState = allBooksState.copy(error = it?.localizedMessage ?: "unknown-error") }, onSuccess = { bookSet, newPage -> + /** + * usually bookSet.books is not nullable and API simply returns empty list + * when browsing books all books (i.e. without passing language parameter) + * however, when browsing by language it returns a response which looks like + * this: {"detail": "Invalid page."}. Hence the [BookSet] attributes become + * null in this case and can cause crashes. + */ /** * usually bookSet.books is not nullable and API simply returns empty list * when browsing books all books (i.e. without passing language parameter) diff --git a/app/src/main/java/com/starry/myne/ui/screens/main/MainScreen.kt b/app/src/main/java/com/starry/myne/ui/screens/main/MainScreen.kt index 73543fa2..b75fe7e1 100644 --- a/app/src/main/java/com/starry/myne/ui/screens/main/MainScreen.kt +++ b/app/src/main/java/com/starry/myne/ui/screens/main/MainScreen.kt @@ -50,7 +50,7 @@ import androidx.navigation.compose.rememberNavController import coil.annotation.ExperimentalCoilApi import com.google.accompanist.systemuicontroller.SystemUiController import com.google.accompanist.systemuicontroller.rememberSystemUiController -import com.starry.myne.others.NetworkObserver +import com.starry.myne.utils.NetworkObserver import com.starry.myne.ui.navigation.BottomBarScreen import com.starry.myne.ui.navigation.NavGraph import com.starry.myne.ui.screens.settings.viewmodels.SettingsViewModel diff --git a/app/src/main/java/com/starry/myne/ui/screens/reader/composables/ReaderDetailScreen.kt b/app/src/main/java/com/starry/myne/ui/screens/reader/composables/ReaderDetailScreen.kt index 57ad5ca1..f0a157fa 100644 --- a/app/src/main/java/com/starry/myne/ui/screens/reader/composables/ReaderDetailScreen.kt +++ b/app/src/main/java/com/starry/myne/ui/screens/reader/composables/ReaderDetailScreen.kt @@ -80,7 +80,7 @@ import coil.compose.AsyncImage import coil.request.ImageRequest import com.starry.myne.MainActivity import com.starry.myne.R -import com.starry.myne.others.NetworkObserver +import com.starry.myne.utils.NetworkObserver import com.starry.myne.ui.common.CustomTopAppBar import com.starry.myne.ui.common.ProgressDots import com.starry.myne.ui.common.simpleVerticalScrollbar diff --git a/app/src/main/java/com/starry/myne/ui/screens/reader/viewmodels/ReaderDetailViewModel.kt b/app/src/main/java/com/starry/myne/ui/screens/reader/viewmodels/ReaderDetailViewModel.kt index 98770c7b..b8591dc3 100644 --- a/app/src/main/java/com/starry/myne/ui/screens/reader/viewmodels/ReaderDetailViewModel.kt +++ b/app/src/main/java/com/starry/myne/ui/screens/reader/viewmodels/ReaderDetailViewModel.kt @@ -27,7 +27,7 @@ import com.starry.myne.database.reader.ReaderDao import com.starry.myne.database.reader.ReaderItem import com.starry.myne.epub.createEpubBook import com.starry.myne.epub.models.EpubBook -import com.starry.myne.others.NetworkObserver +import com.starry.myne.utils.NetworkObserver import com.starry.myne.repo.BookRepository import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.Dispatchers diff --git a/app/src/main/java/com/starry/myne/ui/screens/settings/composables/AboutScreen.kt b/app/src/main/java/com/starry/myne/ui/screens/settings/composables/AboutScreen.kt index 49942aa5..116cb8be 100644 --- a/app/src/main/java/com/starry/myne/ui/screens/settings/composables/AboutScreen.kt +++ b/app/src/main/java/com/starry/myne/ui/screens/settings/composables/AboutScreen.kt @@ -62,7 +62,7 @@ import coil.compose.AsyncImage import coil.request.ImageRequest import com.starry.myne.BuildConfig import com.starry.myne.R -import com.starry.myne.others.Constants +import com.starry.myne.utils.Constants import com.starry.myne.ui.common.CustomTopAppBar import com.starry.myne.ui.theme.figeronaFont diff --git a/app/src/main/java/com/starry/myne/others/WelcomeDataStore.kt b/app/src/main/java/com/starry/myne/ui/screens/welcome/viewmodels/WelcomeDataStore.kt similarity index 97% rename from app/src/main/java/com/starry/myne/others/WelcomeDataStore.kt rename to app/src/main/java/com/starry/myne/ui/screens/welcome/viewmodels/WelcomeDataStore.kt index 815c718e..f782046a 100644 --- a/app/src/main/java/com/starry/myne/others/WelcomeDataStore.kt +++ b/app/src/main/java/com/starry/myne/ui/screens/welcome/viewmodels/WelcomeDataStore.kt @@ -15,7 +15,7 @@ limitations under the License. */ -package com.starry.myne.others +package com.starry.myne.ui.screens.welcome.viewmodels import android.content.Context import androidx.datastore.core.DataStore diff --git a/app/src/main/java/com/starry/myne/ui/screens/welcome/viewmodels/WelcomeViewModel.kt b/app/src/main/java/com/starry/myne/ui/screens/welcome/viewmodels/WelcomeViewModel.kt index a1162598..d7a616ea 100644 --- a/app/src/main/java/com/starry/myne/ui/screens/welcome/viewmodels/WelcomeViewModel.kt +++ b/app/src/main/java/com/starry/myne/ui/screens/welcome/viewmodels/WelcomeViewModel.kt @@ -19,7 +19,6 @@ package com.starry.myne.ui.screens.welcome.viewmodels import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope -import com.starry.myne.others.WelcomeDataStore import com.starry.myne.utils.PreferenceUtil import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.Dispatchers diff --git a/app/src/main/java/com/starry/myne/others/Constants.kt b/app/src/main/java/com/starry/myne/utils/Constants.kt similarity index 96% rename from app/src/main/java/com/starry/myne/others/Constants.kt rename to app/src/main/java/com/starry/myne/utils/Constants.kt index f113ec1e..2a83fc5b 100644 --- a/app/src/main/java/com/starry/myne/others/Constants.kt +++ b/app/src/main/java/com/starry/myne/utils/Constants.kt @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package com.starry.myne.others +package com.starry.myne.utils object Constants { const val DOWNLOAD_DIR = "MyneEbooks" diff --git a/app/src/main/java/com/starry/myne/utils/Extensions.kt b/app/src/main/java/com/starry/myne/utils/Extensions.kt index a4e40856..9a455322 100644 --- a/app/src/main/java/com/starry/myne/utils/Extensions.kt +++ b/app/src/main/java/com/starry/myne/utils/Extensions.kt @@ -20,6 +20,11 @@ import android.content.Context import android.content.ContextWrapper import android.widget.Toast import androidx.appcompat.app.AppCompatActivity +import androidx.compose.foundation.gestures.awaitEachGesture +import androidx.compose.foundation.gestures.awaitFirstDown +import androidx.compose.foundation.gestures.waitForUpOrCancellation +import androidx.compose.ui.geometry.Offset +import androidx.compose.ui.input.pointer.PointerInputScope fun Context.getActivity(): AppCompatActivity? = when (this) { is AppCompatActivity -> this @@ -29,4 +34,17 @@ fun Context.getActivity(): AppCompatActivity? = when (this) { fun String.toToast(context: Context, length: Int = Toast.LENGTH_SHORT) { Toast.makeText(context, this, length).show() +} + +suspend fun PointerInputScope.detectTapGestureIfMatch( + onTap: (Offset) -> Boolean, +) { + awaitEachGesture { + awaitFirstDown() + + val up = waitForUpOrCancellation() + if (up != null && onTap(up.position)) { + up.consume() + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/starry/myne/others/NetworkObserver.kt b/app/src/main/java/com/starry/myne/utils/NetworkObserver.kt similarity index 98% rename from app/src/main/java/com/starry/myne/others/NetworkObserver.kt rename to app/src/main/java/com/starry/myne/utils/NetworkObserver.kt index 64ca5ca7..12f938d0 100644 --- a/app/src/main/java/com/starry/myne/others/NetworkObserver.kt +++ b/app/src/main/java/com/starry/myne/utils/NetworkObserver.kt @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package com.starry.myne.others +package com.starry.myne.utils import android.content.Context import android.net.ConnectivityManager diff --git a/app/src/main/java/com/starry/myne/others/Paginator.kt b/app/src/main/java/com/starry/myne/utils/Paginator.kt similarity index 98% rename from app/src/main/java/com/starry/myne/others/Paginator.kt rename to app/src/main/java/com/starry/myne/utils/Paginator.kt index e7f35b2d..fe6f00f8 100644 --- a/app/src/main/java/com/starry/myne/others/Paginator.kt +++ b/app/src/main/java/com/starry/myne/utils/Paginator.kt @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package com.starry.myne.others +package com.starry.myne.utils class Paginator( private val initialPage: Page, diff --git a/app/src/main/java/com/starry/myne/utils/BookDownloader.kt b/app/src/main/java/com/starry/myne/utils/book/BookDownloader.kt similarity index 98% rename from app/src/main/java/com/starry/myne/utils/BookDownloader.kt rename to app/src/main/java/com/starry/myne/utils/book/BookDownloader.kt index e262f6bf..979d5429 100644 --- a/app/src/main/java/com/starry/myne/utils/BookDownloader.kt +++ b/app/src/main/java/com/starry/myne/utils/book/BookDownloader.kt @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package com.starry.myne.utils +package com.starry.myne.utils.book import android.annotation.SuppressLint import android.app.DownloadManager @@ -22,7 +22,7 @@ import android.content.Context import android.database.Cursor import android.net.Uri import android.os.Environment -import com.starry.myne.others.Constants +import com.starry.myne.utils.Constants import com.starry.myne.repo.models.Book import kotlinx.coroutines.* import kotlinx.coroutines.flow.MutableStateFlow diff --git a/app/src/main/java/com/starry/myne/others/BookLanguage.kt b/app/src/main/java/com/starry/myne/utils/book/BookLanguage.kt similarity index 97% rename from app/src/main/java/com/starry/myne/others/BookLanguage.kt rename to app/src/main/java/com/starry/myne/utils/book/BookLanguage.kt index ea6725ef..51a5e816 100644 --- a/app/src/main/java/com/starry/myne/others/BookLanguage.kt +++ b/app/src/main/java/com/starry/myne/utils/book/BookLanguage.kt @@ -1,4 +1,4 @@ -package com.starry.myne.others +package com.starry.myne.utils.book import androidx.annotation.Keep diff --git a/app/src/main/java/com/starry/myne/utils/BookUtils.kt b/app/src/main/java/com/starry/myne/utils/book/BookUtils.kt similarity index 98% rename from app/src/main/java/com/starry/myne/utils/BookUtils.kt rename to app/src/main/java/com/starry/myne/utils/book/BookUtils.kt index 412b2d5c..42df5bf6 100644 --- a/app/src/main/java/com/starry/myne/utils/BookUtils.kt +++ b/app/src/main/java/com/starry/myne/utils/book/BookUtils.kt @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package com.starry.myne.utils +package com.starry.myne.utils.book import com.starry.myne.repo.models.Author import java.util.Locale diff --git a/app/src/test/java/com/starry/myne/BookUtilsTest.kt b/app/src/test/java/com/starry/myne/BookUtilsTest.kt index e0730948..7f5d206e 100644 --- a/app/src/test/java/com/starry/myne/BookUtilsTest.kt +++ b/app/src/test/java/com/starry/myne/BookUtilsTest.kt @@ -2,7 +2,7 @@ package com.starry.myne import com.google.common.truth.Truth.assertThat import com.starry.myne.repo.models.Author -import com.starry.myne.utils.BookUtils +import com.starry.myne.utils.book.BookUtils import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.test.runTest import org.junit.Test diff --git a/app/src/test/java/com/starry/myne/PaginatorTest.kt b/app/src/test/java/com/starry/myne/PaginatorTest.kt index dd2d0022..a9439db9 100644 --- a/app/src/test/java/com/starry/myne/PaginatorTest.kt +++ b/app/src/test/java/com/starry/myne/PaginatorTest.kt @@ -2,7 +2,7 @@ package com.starry.myne import com.google.common.truth.Truth.assertThat -import com.starry.myne.others.Paginator +import com.starry.myne.utils.Paginator import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.test.runTest import org.junit.Before From e4b06a196ae0620fe6318dc885d951c47440f3eb Mon Sep 17 00:00:00 2001 From: starry-shivam Date: Sat, 16 Dec 2023 12:46:33 +0530 Subject: [PATCH 3/3] Fix reader menu not appearing due to text selection And some other improvements Signed-off-by: starry-shivam --- .../main/java/com/starry/myne/MainActivity.kt | 4 +-- .../java/com/starry/myne/MainViewModel.kt | 2 +- .../myne/database/library/LibraryDao.kt | 6 +++- .../starry/myne/database/reader/ReaderDao.kt | 5 ++- .../java/com/starry/myne/di/MainModule.kt | 4 +-- .../com/starry/myne/repo/BookRepository.kt | 2 +- .../myne/ui/navigation/BottomBarScreen.kt | 8 ++--- .../com/starry/myne/ui/navigation/NavGraph.kt | 2 +- .../com/starry/myne/ui/navigation/Screens.kt | 13 +++---- .../composables/CategoryDetailScreen.kt | 4 +-- .../viewmodels/CategoryViewModel.kt | 4 +-- .../detail/composables/BookDetailScreen.kt | 2 +- .../detail/viewmodels/BookDetailViewModel.kt | 2 +- .../ui/screens/home/composables/HomeScreen.kt | 4 +-- .../screens/home/viewmodels/HomeViewModel.kt | 31 ++++------------ .../starry/myne/ui/screens/main/MainScreen.kt | 2 +- .../reader/adapters/ReaderRVAdapter.kt | 20 ++++++----- .../reader/composables/ReaderDetailScreen.kt | 2 +- .../viewmodels/ReaderDetailViewModel.kt | 2 +- .../settings/composables/AboutScreen.kt | 2 +- .../java/com/starry/myne/utils/Extensions.kt | 24 +++++-------- .../starry/myne/utils/book/BookDownloader.kt | 2 +- .../starry/myne/utils/book/BookLanguage.kt | 36 +++++++++---------- 23 files changed, 84 insertions(+), 99 deletions(-) diff --git a/app/src/main/java/com/starry/myne/MainActivity.kt b/app/src/main/java/com/starry/myne/MainActivity.kt index 76a4bfb6..30d5fe06 100644 --- a/app/src/main/java/com/starry/myne/MainActivity.kt +++ b/app/src/main/java/com/starry/myne/MainActivity.kt @@ -38,11 +38,11 @@ import androidx.core.app.ActivityCompat import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen import androidx.lifecycle.ViewModelProvider import coil.annotation.ExperimentalCoilApi -import com.starry.myne.utils.NetworkObserver import com.starry.myne.ui.screens.main.MainScreen import com.starry.myne.ui.screens.settings.viewmodels.SettingsViewModel import com.starry.myne.ui.screens.settings.viewmodels.ThemeMode import com.starry.myne.ui.theme.MyneTheme +import com.starry.myne.utils.NetworkObserver import dagger.hilt.android.AndroidEntryPoint @ExperimentalMaterialApi @@ -64,7 +64,7 @@ class MainActivity : AppCompatActivity() { settingsViewModel = ViewModelProvider(this)[SettingsViewModel::class.java] mainViewModel = ViewModelProvider(this)[MainViewModel::class.java] - ThemeMode.entries.find { it.ordinal == settingsViewModel.getThemeValue()} + ThemeMode.entries.find { it.ordinal == settingsViewModel.getThemeValue() } ?.let { settingsViewModel.setTheme(it) } settingsViewModel.setMaterialYou(settingsViewModel.getMaterialYouValue()) diff --git a/app/src/main/java/com/starry/myne/MainViewModel.kt b/app/src/main/java/com/starry/myne/MainViewModel.kt index c6f7a2d7..a34a9f84 100644 --- a/app/src/main/java/com/starry/myne/MainViewModel.kt +++ b/app/src/main/java/com/starry/myne/MainViewModel.kt @@ -22,9 +22,9 @@ import androidx.compose.runtime.State import androidx.compose.runtime.mutableStateOf import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope -import com.starry.myne.ui.screens.welcome.viewmodels.WelcomeDataStore import com.starry.myne.ui.navigation.BottomBarScreen import com.starry.myne.ui.navigation.Screens +import com.starry.myne.ui.screens.welcome.viewmodels.WelcomeDataStore import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.delay import kotlinx.coroutines.launch diff --git a/app/src/main/java/com/starry/myne/database/library/LibraryDao.kt b/app/src/main/java/com/starry/myne/database/library/LibraryDao.kt index b9684a40..b6ad40d1 100644 --- a/app/src/main/java/com/starry/myne/database/library/LibraryDao.kt +++ b/app/src/main/java/com/starry/myne/database/library/LibraryDao.kt @@ -17,7 +17,11 @@ limitations under the License. package com.starry.myne.database.library import androidx.lifecycle.LiveData -import androidx.room.* +import androidx.room.Dao +import androidx.room.Delete +import androidx.room.Insert +import androidx.room.OnConflictStrategy +import androidx.room.Query @Dao interface LibraryDao { diff --git a/app/src/main/java/com/starry/myne/database/reader/ReaderDao.kt b/app/src/main/java/com/starry/myne/database/reader/ReaderDao.kt index 535d1654..13cf66da 100644 --- a/app/src/main/java/com/starry/myne/database/reader/ReaderDao.kt +++ b/app/src/main/java/com/starry/myne/database/reader/ReaderDao.kt @@ -17,7 +17,10 @@ limitations under the License. package com.starry.myne.database.reader -import androidx.room.* +import androidx.room.Dao +import androidx.room.Insert +import androidx.room.OnConflictStrategy +import androidx.room.Query @Dao interface ReaderDao { diff --git a/app/src/main/java/com/starry/myne/di/MainModule.kt b/app/src/main/java/com/starry/myne/di/MainModule.kt index e8f9c9d5..775e12f6 100644 --- a/app/src/main/java/com/starry/myne/di/MainModule.kt +++ b/app/src/main/java/com/starry/myne/di/MainModule.kt @@ -19,10 +19,10 @@ package com.starry.myne.di import android.content.Context import com.starry.myne.database.MyneDatabase -import com.starry.myne.ui.screens.welcome.viewmodels.WelcomeDataStore import com.starry.myne.repo.BookRepository -import com.starry.myne.utils.book.BookDownloader +import com.starry.myne.ui.screens.welcome.viewmodels.WelcomeDataStore import com.starry.myne.utils.PreferenceUtil +import com.starry.myne.utils.book.BookDownloader import dagger.Module import dagger.Provides import dagger.hilt.InstallIn diff --git a/app/src/main/java/com/starry/myne/repo/BookRepository.kt b/app/src/main/java/com/starry/myne/repo/BookRepository.kt index e7f63ecd..f09998d4 100644 --- a/app/src/main/java/com/starry/myne/repo/BookRepository.kt +++ b/app/src/main/java/com/starry/myne/repo/BookRepository.kt @@ -17,9 +17,9 @@ limitations under the License. package com.starry.myne.repo import com.google.gson.Gson -import com.starry.myne.utils.book.BookLanguage import com.starry.myne.repo.models.BookSet import com.starry.myne.repo.models.ExtraInfo +import com.starry.myne.utils.book.BookLanguage import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import okhttp3.Call diff --git a/app/src/main/java/com/starry/myne/ui/navigation/BottomBarScreen.kt b/app/src/main/java/com/starry/myne/ui/navigation/BottomBarScreen.kt index d4a4d8ee..16c63792 100644 --- a/app/src/main/java/com/starry/myne/ui/navigation/BottomBarScreen.kt +++ b/app/src/main/java/com/starry/myne/ui/navigation/BottomBarScreen.kt @@ -23,25 +23,25 @@ sealed class BottomBarScreen( val title: Int, val icon: Int ) { - object Home : BottomBarScreen( + data object Home : BottomBarScreen( route = "home", title = R.string.navigation_home, icon = R.drawable.ic_nav_home ) - object Categories : BottomBarScreen( + data object Categories : BottomBarScreen( route = "categories", title = R.string.navigation_categories, icon = R.drawable.ic_nav_categories ) - object Library : BottomBarScreen( + data object Library : BottomBarScreen( route = "library", title = R.string.navigation_library, icon = R.drawable.ic_nav_library ) - object Settings : BottomBarScreen( + data object Settings : BottomBarScreen( route = "settings", title = R.string.navigation_settings, icon = R.drawable.ic_nav_settings diff --git a/app/src/main/java/com/starry/myne/ui/navigation/NavGraph.kt b/app/src/main/java/com/starry/myne/ui/navigation/NavGraph.kt index 47f2fd1d..6517e8bc 100644 --- a/app/src/main/java/com/starry/myne/ui/navigation/NavGraph.kt +++ b/app/src/main/java/com/starry/myne/ui/navigation/NavGraph.kt @@ -36,7 +36,6 @@ import androidx.navigation.compose.NavHost import androidx.navigation.compose.composable import androidx.navigation.navArgument import coil.annotation.ExperimentalCoilApi -import com.starry.myne.utils.NetworkObserver import com.starry.myne.ui.screens.categories.composables.CategoriesScreen import com.starry.myne.ui.screens.categories.composables.CategoryDetailScreen import com.starry.myne.ui.screens.detail.composables.BookDetailScreen @@ -47,6 +46,7 @@ import com.starry.myne.ui.screens.settings.composables.AboutScreen import com.starry.myne.ui.screens.settings.composables.OSLScreen import com.starry.myne.ui.screens.settings.composables.SettingsScreen import com.starry.myne.ui.screens.welcome.composables.WelcomeScreen +import com.starry.myne.utils.NetworkObserver private const val NAVIGATION_ANIM_DURATION = 300 diff --git a/app/src/main/java/com/starry/myne/ui/navigation/Screens.kt b/app/src/main/java/com/starry/myne/ui/navigation/Screens.kt index 722a7480..3d6c2e52 100644 --- a/app/src/main/java/com/starry/myne/ui/navigation/Screens.kt +++ b/app/src/main/java/com/starry/myne/ui/navigation/Screens.kt @@ -21,27 +21,28 @@ const val CATEGORY_DETAIL_ARG_KEY = "category" sealed class Screens(val route: String) { - object BookDetailScreen : Screens("book_detail_screen/{$BOOK_ID_ARG_KEY}") { + data object BookDetailScreen : Screens("book_detail_screen/{$BOOK_ID_ARG_KEY}") { fun withBookId(id: String): String { return this.route.replace("{$BOOK_ID_ARG_KEY}", id) } } - object CategoryDetailScreen : Screens("category_detail_screen/{$CATEGORY_DETAIL_ARG_KEY}") { + data object CategoryDetailScreen : + Screens("category_detail_screen/{$CATEGORY_DETAIL_ARG_KEY}") { fun withCategory(category: String): String { return this.route.replace("{$CATEGORY_DETAIL_ARG_KEY}", category) } } - object ReaderDetailScreen : Screens("reader_detail_screen/{$BOOK_ID_ARG_KEY}") { + data object ReaderDetailScreen : Screens("reader_detail_screen/{$BOOK_ID_ARG_KEY}") { fun withBookId(id: String): String { return this.route.replace("{$BOOK_ID_ARG_KEY}", id) } } - object WelcomeScreen : Screens("welcome_screen") + data object WelcomeScreen : Screens("welcome_screen") - object OSLScreen : Screens("osl_screen") + data object OSLScreen : Screens("osl_screen") - object AboutScreen : Screens("about_screen") + data object AboutScreen : Screens("about_screen") } diff --git a/app/src/main/java/com/starry/myne/ui/screens/categories/composables/CategoryDetailScreen.kt b/app/src/main/java/com/starry/myne/ui/screens/categories/composables/CategoryDetailScreen.kt index c7d7d7a6..4b7ad2ae 100644 --- a/app/src/main/java/com/starry/myne/ui/screens/categories/composables/CategoryDetailScreen.kt +++ b/app/src/main/java/com/starry/myne/ui/screens/categories/composables/CategoryDetailScreen.kt @@ -55,8 +55,6 @@ import androidx.hilt.navigation.compose.hiltViewModel import androidx.navigation.NavController import coil.annotation.ExperimentalCoilApi import com.starry.myne.R -import com.starry.myne.utils.book.BookLanguage -import com.starry.myne.utils.NetworkObserver import com.starry.myne.ui.common.BookItemCard import com.starry.myne.ui.common.CustomTopAppBar import com.starry.myne.ui.common.NoBooksAvailable @@ -66,6 +64,8 @@ import com.starry.myne.ui.screens.categories.viewmodels.CategoryViewModel import com.starry.myne.ui.screens.home.composables.LanguageItem import com.starry.myne.ui.screens.other.NetworkError import com.starry.myne.ui.theme.pacificoFont +import com.starry.myne.utils.NetworkObserver +import com.starry.myne.utils.book.BookLanguage import com.starry.myne.utils.book.BookUtils import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.launch diff --git a/app/src/main/java/com/starry/myne/ui/screens/categories/viewmodels/CategoryViewModel.kt b/app/src/main/java/com/starry/myne/ui/screens/categories/viewmodels/CategoryViewModel.kt index 05e04a6e..884b729a 100644 --- a/app/src/main/java/com/starry/myne/ui/screens/categories/viewmodels/CategoryViewModel.kt +++ b/app/src/main/java/com/starry/myne/ui/screens/categories/viewmodels/CategoryViewModel.kt @@ -24,12 +24,12 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.setValue import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope -import com.starry.myne.utils.book.BookLanguage -import com.starry.myne.utils.Paginator import com.starry.myne.repo.BookRepository import com.starry.myne.repo.models.Book import com.starry.myne.repo.models.BookSet +import com.starry.myne.utils.Paginator import com.starry.myne.utils.PreferenceUtil +import com.starry.myne.utils.book.BookLanguage import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.launch import javax.inject.Inject diff --git a/app/src/main/java/com/starry/myne/ui/screens/detail/composables/BookDetailScreen.kt b/app/src/main/java/com/starry/myne/ui/screens/detail/composables/BookDetailScreen.kt index d40e47e2..cd56ba42 100644 --- a/app/src/main/java/com/starry/myne/ui/screens/detail/composables/BookDetailScreen.kt +++ b/app/src/main/java/com/starry/myne/ui/screens/detail/composables/BookDetailScreen.kt @@ -102,8 +102,8 @@ import com.starry.myne.ui.screens.other.NetworkError import com.starry.myne.ui.screens.settings.viewmodels.ThemeMode import com.starry.myne.ui.theme.figeronaFont import com.starry.myne.ui.theme.pacificoFont -import com.starry.myne.utils.book.BookUtils import com.starry.myne.utils.Utils +import com.starry.myne.utils.book.BookUtils import com.starry.myne.utils.getActivity import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch diff --git a/app/src/main/java/com/starry/myne/ui/screens/detail/viewmodels/BookDetailViewModel.kt b/app/src/main/java/com/starry/myne/ui/screens/detail/viewmodels/BookDetailViewModel.kt index f91579ab..e902b35d 100644 --- a/app/src/main/java/com/starry/myne/ui/screens/detail/viewmodels/BookDetailViewModel.kt +++ b/app/src/main/java/com/starry/myne/ui/screens/detail/viewmodels/BookDetailViewModel.kt @@ -34,9 +34,9 @@ import com.starry.myne.repo.BookRepository import com.starry.myne.repo.models.Book import com.starry.myne.repo.models.BookSet import com.starry.myne.repo.models.ExtraInfo +import com.starry.myne.utils.PreferenceUtil import com.starry.myne.utils.book.BookDownloader import com.starry.myne.utils.book.BookUtils -import com.starry.myne.utils.PreferenceUtil import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch diff --git a/app/src/main/java/com/starry/myne/ui/screens/home/composables/HomeScreen.kt b/app/src/main/java/com/starry/myne/ui/screens/home/composables/HomeScreen.kt index a3911dca..dafb6494 100644 --- a/app/src/main/java/com/starry/myne/ui/screens/home/composables/HomeScreen.kt +++ b/app/src/main/java/com/starry/myne/ui/screens/home/composables/HomeScreen.kt @@ -90,8 +90,6 @@ import androidx.navigation.NavController import androidx.navigation.compose.rememberNavController import coil.annotation.ExperimentalCoilApi import com.starry.myne.R -import com.starry.myne.utils.book.BookLanguage -import com.starry.myne.utils.NetworkObserver import com.starry.myne.ui.common.BookItemCard import com.starry.myne.ui.common.ProgressDots import com.starry.myne.ui.navigation.Screens @@ -100,6 +98,8 @@ import com.starry.myne.ui.screens.home.viewmodels.UserAction import com.starry.myne.ui.screens.other.NetworkError import com.starry.myne.ui.theme.figeronaFont import com.starry.myne.ui.theme.pacificoFont +import com.starry.myne.utils.NetworkObserver +import com.starry.myne.utils.book.BookLanguage import com.starry.myne.utils.book.BookUtils import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.launch diff --git a/app/src/main/java/com/starry/myne/ui/screens/home/viewmodels/HomeViewModel.kt b/app/src/main/java/com/starry/myne/ui/screens/home/viewmodels/HomeViewModel.kt index 3facd196..57978cee 100644 --- a/app/src/main/java/com/starry/myne/ui/screens/home/viewmodels/HomeViewModel.kt +++ b/app/src/main/java/com/starry/myne/ui/screens/home/viewmodels/HomeViewModel.kt @@ -23,13 +23,13 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.setValue import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope -import com.starry.myne.utils.book.BookLanguage -import com.starry.myne.utils.NetworkObserver -import com.starry.myne.utils.Paginator import com.starry.myne.repo.BookRepository import com.starry.myne.repo.models.Book import com.starry.myne.repo.models.BookSet +import com.starry.myne.utils.NetworkObserver +import com.starry.myne.utils.Paginator import com.starry.myne.utils.PreferenceUtil +import com.starry.myne.utils.book.BookLanguage import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.Job import kotlinx.coroutines.delay @@ -53,8 +53,8 @@ data class TopBarState( ) sealed class UserAction { - object SearchIconClicked : UserAction() - object CloseIconClicked : UserAction() + data object SearchIconClicked : UserAction() + data object CloseIconClicked : UserAction() data class TextFieldInput( val text: String, val networkStatus: NetworkObserver.Status @@ -89,13 +89,6 @@ class HomeViewModel @Inject constructor( }, onError = { allBooksState = allBooksState.copy(error = it?.localizedMessage ?: "unknown-error") }, onSuccess = { bookSet, newPage -> - /** - * usually bookSet.books is not nullable and API simply returns empty list - * when browsing books all books (i.e. without passing language parameter) - * however, when browsing by language it returns a response which looks like - * this: {"detail": "Invalid page."}. Hence the [BookSet] attributes become - * null in this case and can cause crashes. - */ /** * usually bookSet.books is not nullable and API simply returns empty list * when browsing books all books (i.e. without passing language parameter) @@ -104,19 +97,7 @@ class HomeViewModel @Inject constructor( * null in this case and can cause crashes. */ val books = if (bookSet.books != null) { - val books: ArrayList = - bookSet.books.filter { it.formats.applicationepubzip != null } as ArrayList - - // pls ignore (this line doesn't exists)... - if (setOf( - BookLanguage.English, - BookLanguage.AllBooks - ).contains(language.value) && allBooksState.page == 1L - ) { - books.removeAt(0) - } - // returning value - books + bookSet.books.filter { it.formats.applicationepubzip != null } as ArrayList } else { ArrayList() } diff --git a/app/src/main/java/com/starry/myne/ui/screens/main/MainScreen.kt b/app/src/main/java/com/starry/myne/ui/screens/main/MainScreen.kt index b75fe7e1..c1b33710 100644 --- a/app/src/main/java/com/starry/myne/ui/screens/main/MainScreen.kt +++ b/app/src/main/java/com/starry/myne/ui/screens/main/MainScreen.kt @@ -50,12 +50,12 @@ import androidx.navigation.compose.rememberNavController import coil.annotation.ExperimentalCoilApi import com.google.accompanist.systemuicontroller.SystemUiController import com.google.accompanist.systemuicontroller.rememberSystemUiController -import com.starry.myne.utils.NetworkObserver import com.starry.myne.ui.navigation.BottomBarScreen import com.starry.myne.ui.navigation.NavGraph import com.starry.myne.ui.screens.settings.viewmodels.SettingsViewModel import com.starry.myne.ui.screens.settings.viewmodels.ThemeMode import com.starry.myne.ui.theme.figeronaFont +import com.starry.myne.utils.NetworkObserver @SuppressLint("UnusedMaterial3ScaffoldPaddingParameter") @ExperimentalAnimationApi 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 64b6b2f2..03fd6b5f 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 @@ -51,6 +51,7 @@ import com.starry.myne.epub.models.EpubChapter import com.starry.myne.ui.screens.reader.activities.ReaderActivity import com.starry.myne.ui.screens.reader.viewmodels.ReaderViewModel import com.starry.myne.ui.theme.MyneTheme +import com.starry.myne.utils.noRippleClickable @ExperimentalMaterialApi @ExperimentalMaterial3Api @@ -78,13 +79,13 @@ class ReaderRVAdapter( set(value) = differ.submitList(value) inner class ReaderComposeViewHolder(view: View) : RecyclerView.ViewHolder(view) { - val composeView: ComposeView = view.findViewById(R.id.ReaderRVItem) - fun bind(position: Int) { + private val composeView: ComposeView = view.findViewById(R.id.ReaderRVItem) + fun bind(position: Int, onClick: () -> Unit) { val chapter = allChapters[position] composeView.setContent { MyneTheme(settingsViewModel = activity.settingsViewModel) { SelectionContainer { - ReaderItem(chapter = chapter, viewModel = viewModel) + ReaderItem(chapter = chapter, viewModel = viewModel, onClick = onClick) } } } @@ -92,11 +93,9 @@ class ReaderRVAdapter( } override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ReaderComposeViewHolder { - val viewHolder = ReaderComposeViewHolder( + return ReaderComposeViewHolder( LayoutInflater.from(parent.context).inflate(R.layout.reader_item, parent, false) ) - viewHolder.composeView.setOnClickListener { clickListener.onReaderClick() } - return viewHolder } override fun getItemCount(): Int { @@ -104,14 +103,15 @@ class ReaderRVAdapter( } override fun onBindViewHolder(holder: ReaderComposeViewHolder, position: Int) { - holder.bind(position) + holder.bind(position, onClick = { clickListener.onReaderClick() }) } } @Composable private fun ReaderItem( chapter: EpubChapter, - viewModel: ReaderViewModel + viewModel: ReaderViewModel, + onClick: () -> Unit ) { val paragraphs = chapter.body .splitToSequence("\n\n") @@ -120,7 +120,9 @@ private fun ReaderItem( val epubBook = viewModel.state.epubBook - Column(modifier = Modifier.fillMaxWidth()) { + Column(modifier = Modifier + .fillMaxWidth() + .noRippleClickable { onClick() }) { Text( modifier = Modifier.padding(start = 12.dp, end = 4.dp, top = 10.dp), text = chapter.title, diff --git a/app/src/main/java/com/starry/myne/ui/screens/reader/composables/ReaderDetailScreen.kt b/app/src/main/java/com/starry/myne/ui/screens/reader/composables/ReaderDetailScreen.kt index f0a157fa..c5584412 100644 --- a/app/src/main/java/com/starry/myne/ui/screens/reader/composables/ReaderDetailScreen.kt +++ b/app/src/main/java/com/starry/myne/ui/screens/reader/composables/ReaderDetailScreen.kt @@ -80,7 +80,6 @@ import coil.compose.AsyncImage import coil.request.ImageRequest import com.starry.myne.MainActivity import com.starry.myne.R -import com.starry.myne.utils.NetworkObserver import com.starry.myne.ui.common.CustomTopAppBar import com.starry.myne.ui.common.ProgressDots import com.starry.myne.ui.common.simpleVerticalScrollbar @@ -88,6 +87,7 @@ import com.starry.myne.ui.screens.reader.activities.ReaderActivity import com.starry.myne.ui.screens.reader.viewmodels.ReaderDetailViewModel import com.starry.myne.ui.screens.settings.viewmodels.ThemeMode import com.starry.myne.ui.theme.figeronaFont +import com.starry.myne.utils.NetworkObserver import com.starry.myne.utils.getActivity @ExperimentalCoilApi diff --git a/app/src/main/java/com/starry/myne/ui/screens/reader/viewmodels/ReaderDetailViewModel.kt b/app/src/main/java/com/starry/myne/ui/screens/reader/viewmodels/ReaderDetailViewModel.kt index b8591dc3..b90a474a 100644 --- a/app/src/main/java/com/starry/myne/ui/screens/reader/viewmodels/ReaderDetailViewModel.kt +++ b/app/src/main/java/com/starry/myne/ui/screens/reader/viewmodels/ReaderDetailViewModel.kt @@ -27,8 +27,8 @@ import com.starry.myne.database.reader.ReaderDao import com.starry.myne.database.reader.ReaderItem import com.starry.myne.epub.createEpubBook import com.starry.myne.epub.models.EpubBook -import com.starry.myne.utils.NetworkObserver import com.starry.myne.repo.BookRepository +import com.starry.myne.utils.NetworkObserver import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch diff --git a/app/src/main/java/com/starry/myne/ui/screens/settings/composables/AboutScreen.kt b/app/src/main/java/com/starry/myne/ui/screens/settings/composables/AboutScreen.kt index 116cb8be..24609c96 100644 --- a/app/src/main/java/com/starry/myne/ui/screens/settings/composables/AboutScreen.kt +++ b/app/src/main/java/com/starry/myne/ui/screens/settings/composables/AboutScreen.kt @@ -62,9 +62,9 @@ import coil.compose.AsyncImage import coil.request.ImageRequest import com.starry.myne.BuildConfig import com.starry.myne.R -import com.starry.myne.utils.Constants import com.starry.myne.ui.common.CustomTopAppBar import com.starry.myne.ui.theme.figeronaFont +import com.starry.myne.utils.Constants @Composable diff --git a/app/src/main/java/com/starry/myne/utils/Extensions.kt b/app/src/main/java/com/starry/myne/utils/Extensions.kt index 9a455322..7f3eb611 100644 --- a/app/src/main/java/com/starry/myne/utils/Extensions.kt +++ b/app/src/main/java/com/starry/myne/utils/Extensions.kt @@ -20,11 +20,11 @@ import android.content.Context import android.content.ContextWrapper import android.widget.Toast import androidx.appcompat.app.AppCompatActivity -import androidx.compose.foundation.gestures.awaitEachGesture -import androidx.compose.foundation.gestures.awaitFirstDown -import androidx.compose.foundation.gestures.waitForUpOrCancellation -import androidx.compose.ui.geometry.Offset -import androidx.compose.ui.input.pointer.PointerInputScope +import androidx.compose.foundation.clickable +import androidx.compose.foundation.interaction.MutableInteractionSource +import androidx.compose.runtime.remember +import androidx.compose.ui.Modifier +import androidx.compose.ui.composed fun Context.getActivity(): AppCompatActivity? = when (this) { is AppCompatActivity -> this @@ -36,15 +36,9 @@ fun String.toToast(context: Context, length: Int = Toast.LENGTH_SHORT) { Toast.makeText(context, this, length).show() } -suspend fun PointerInputScope.detectTapGestureIfMatch( - onTap: (Offset) -> Boolean, -) { - awaitEachGesture { - awaitFirstDown() - - val up = waitForUpOrCancellation() - if (up != null && onTap(up.position)) { - up.consume() - } +fun Modifier.noRippleClickable(onClick: () -> Unit): Modifier = composed { + clickable(indication = null, + interactionSource = remember { MutableInteractionSource() }) { + onClick() } } \ No newline at end of file diff --git a/app/src/main/java/com/starry/myne/utils/book/BookDownloader.kt b/app/src/main/java/com/starry/myne/utils/book/BookDownloader.kt index 979d5429..c298bf24 100644 --- a/app/src/main/java/com/starry/myne/utils/book/BookDownloader.kt +++ b/app/src/main/java/com/starry/myne/utils/book/BookDownloader.kt @@ -22,8 +22,8 @@ import android.content.Context import android.database.Cursor import android.net.Uri import android.os.Environment -import com.starry.myne.utils.Constants import com.starry.myne.repo.models.Book +import com.starry.myne.utils.Constants import kotlinx.coroutines.* import kotlinx.coroutines.flow.MutableStateFlow diff --git a/app/src/main/java/com/starry/myne/utils/book/BookLanguage.kt b/app/src/main/java/com/starry/myne/utils/book/BookLanguage.kt index 51a5e816..6fb74545 100644 --- a/app/src/main/java/com/starry/myne/utils/book/BookLanguage.kt +++ b/app/src/main/java/com/starry/myne/utils/book/BookLanguage.kt @@ -11,56 +11,56 @@ sealed class BookLanguage(val name: String, val isoCode: String) { } @Keep - object AllBooks : BookLanguage("All Books", "all") + data object AllBooks : BookLanguage("All Books", "all") @Keep - object Chinese : BookLanguage("Chinese", "zh") + data object Chinese : BookLanguage("Chinese", "zh") @Keep - object Danish : BookLanguage("Danish", "da") + data object Danish : BookLanguage("Danish", "da") @Keep - object Dutch : BookLanguage("Dutch", "nl") + data object Dutch : BookLanguage("Dutch", "nl") @Keep - object English : BookLanguage("English", "en") + data object English : BookLanguage("English", "en") @Keep - object Esperanto : BookLanguage("Esperanto", "eo") + data object Esperanto : BookLanguage("Esperanto", "eo") @Keep - object Finnish : BookLanguage("Finnish", "fi") + data object Finnish : BookLanguage("Finnish", "fi") @Keep - object French : BookLanguage("French", "fr") + data object French : BookLanguage("French", "fr") @Keep - object German : BookLanguage("German", "de") + data object German : BookLanguage("German", "de") @Keep - object Greek : BookLanguage("Greek", "el") + data object Greek : BookLanguage("Greek", "el") @Keep - object Hungarian : BookLanguage("Hungarian", "hu") + data object Hungarian : BookLanguage("Hungarian", "hu") @Keep - object Italian : BookLanguage("Italian", "it") + data object Italian : BookLanguage("Italian", "it") @Keep - object Latin : BookLanguage("Latin", "la") + data object Latin : BookLanguage("Latin", "la") @Keep - object Portuguese : BookLanguage("Portuguese", "pt") + data object Portuguese : BookLanguage("Portuguese", "pt") @Keep - object Russian : BookLanguage("Russian", "ru") + data object Russian : BookLanguage("Russian", "ru") @Keep - object Spanish : BookLanguage("Spanish", "es") + data object Spanish : BookLanguage("Spanish", "es") @Keep - object Swedish : BookLanguage("Swedish", "sv") + data object Swedish : BookLanguage("Swedish", "sv") @Keep - object Tagalog : BookLanguage("Tagalog", "tl") + data object Tagalog : BookLanguage("Tagalog", "tl") }