Skip to content

Commit

Permalink
Fix reader menu not appearing due to text selection
Browse files Browse the repository at this point in the history
And some other improvements

Signed-off-by: starry-shivam <[email protected]>
  • Loading branch information
starry-shivam committed Dec 16, 2023
1 parent 2f20b02 commit e4b06a1
Show file tree
Hide file tree
Showing 23 changed files with 84 additions and 99 deletions.
4 changes: 2 additions & 2 deletions app/src/main/java/com/starry/myne/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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())

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/starry/myne/MainViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/starry/myne/di/MainModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/starry/myne/repo/BookRepository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
13 changes: 7 additions & 6 deletions app/src/main/java/com/starry/myne/ui/navigation/Screens.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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<Book> =
bookSet.books.filter { it.formats.applicationepubzip != null } as ArrayList<Book>

// 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<Book>
} else {
ArrayList()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -78,40 +79,39 @@ 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)
}
}
}
}
}

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 {
return allChapters.size
}

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")
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ 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
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
Expand Down
Loading

0 comments on commit e4b06a1

Please sign in to comment.