Skip to content

Commit

Permalink
Merge pull request #17 from Enoch02/dev
Browse files Browse the repository at this point in the history
refactor: moved some ui elements into their own composable
  • Loading branch information
Enoch02 authored Nov 11, 2024
2 parents 12f6dd8 + 330e1e6 commit ece9ef6
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 46 deletions.
4 changes: 2 additions & 2 deletions .idea/deploymentTargetSelector.xml

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

Original file line number Diff line number Diff line change
Expand Up @@ -216,13 +216,13 @@ fun LiteraryLincApp(navController: NavController) {
}
},
content = { paddingValues ->
RequestNotificationPermission()

Crossfade(
targetState = currentScreen,
content = {
when (it) {
TopLevelDestination.BOOK_LIST -> {
RequestNotificationPermission()

BookListSortOptionsAlert(
showBookListSortOptions = showBookListSortOptions,
currentBookListSorting = currentBookListSorting,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,40 @@ import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Button
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.enoch02.viewer.LLDocumentActivity
import com.composables.core.ScrollArea
import com.composables.core.Thumb
import com.composables.core.ThumbVisibility
import com.composables.core.VerticalScrollbar
import com.composables.core.rememberScrollAreaState
import com.enoch02.database.model.ReaderFilter
import com.enoch02.database.model.ReaderSorting
import com.enoch02.reader.components.NoDocumentView
import com.enoch02.reader.components.ReaderListItem
import com.enoch02.viewer.LLDocumentActivity
import kotlinx.coroutines.launch
import kotlin.time.Duration.Companion.seconds

@OptIn(ExperimentalFoundationApi::class)
Expand All @@ -55,6 +53,7 @@ fun ReaderListScreen(
val context = LocalContext.current
val arrangedDocs by viewModel.documentsState.collectAsStateWithLifecycle()
val covers by viewModel.covers.collectAsState(initial = emptyMap())
val scope = rememberCoroutineScope()

LaunchedEffect(sorting, filter) {
viewModel.updateFilter(filter)
Expand All @@ -72,39 +71,9 @@ fun ReaderListScreen(

is DocumentsState.Loaded -> {
if (docList.documents.isEmpty()) {
Column(
modifier = Modifier.fillMaxSize(),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally,
content = {
when (filter) {
ReaderFilter.READING -> {
Text(text = stringResource(R.string.nothing_to_continue))
}

ReaderFilter.FAVORITES -> {
Text(text = stringResource(R.string.no_favorite_docs))
}

ReaderFilter.COMPLETED -> {
Text(text = stringResource(R.string.no_completed_docs))
}

ReaderFilter.ALL -> {
Text(text = stringResource(R.string.no_doc_found))
Button(
onClick = onScanForDocs,
content = {
Text(text = stringResource(R.string.scan_for_new_docs))
}
)
}

ReaderFilter.NO_FILE -> {
Text(text = stringResource(R.string.no_doc_found))
}
}
}
NoDocumentView(
filter = filter,
onScanForDocs = onScanForDocs
)
} else {
val listState = rememberLazyListState()
Expand All @@ -129,6 +98,9 @@ fun ReaderListScreen(
documentInBookList = inBookList,
cover = covers[document.cover],
onClick = {
scope.launch {
listState.animateScrollToItem(0)
}
viewModel.createBookListEntry(document)

val intent =
Expand All @@ -138,9 +110,7 @@ fun ReaderListScreen(
data = document.contentUri
putExtra("id", document.id)
}

context.startActivity(intent)
listState.requestScrollToItem(0)
},
onAddToFavoritesClicked = {
viewModel.toggleFavoriteStatus(document)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.enoch02.reader.components

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.Button
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import com.enoch02.database.model.ReaderFilter
import com.enoch02.reader.R

@Composable
fun NoDocumentView(
modifier: Modifier = Modifier,
filter: ReaderFilter,
onScanForDocs: () -> Unit
) {
Column(
modifier = modifier.fillMaxSize(),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally,
content = {
when (filter) {
ReaderFilter.READING -> {
Text(text = stringResource(R.string.nothing_to_continue))
}

ReaderFilter.FAVORITES -> {
Text(text = stringResource(R.string.no_favorite_docs))
}

ReaderFilter.COMPLETED -> {
Text(text = stringResource(R.string.no_completed_docs))
}

ReaderFilter.ALL -> {
Text(text = stringResource(R.string.no_doc_found))
Button(
onClick = onScanForDocs,
content = {
Text(text = stringResource(R.string.scan_for_new_docs))
}
)
}

ReaderFilter.NO_FILE -> {
Text(text = stringResource(R.string.no_doc_found))
}
}
}
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ fun ReaderListItem(
modifier = modifier
.height(IntrinsicSize.Min)
.clickable {
onClick()
onClick()
}
)

Expand Down

0 comments on commit ece9ef6

Please sign in to comment.