-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use swipe library instead of horizontal pager
- Loading branch information
Showing
25 changed files
with
487 additions
and
248 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 4 additions & 1 deletion
5
app/src/main/java/com/capyreader/app/ui/articles/LocalArticleLookup.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
package com.capyreader.app.ui.articles | ||
|
||
import androidx.compose.runtime.compositionLocalOf | ||
import com.jocmp.capy.ArticlePages | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.emptyFlow | ||
|
||
val LocalArticleLookup = compositionLocalOf { ArticleLookup() } | ||
|
||
data class ArticleLookup( | ||
val findIndex: (articleID: String) -> Int = { -1 } | ||
val findArticlePages: (articleID: String) -> Flow<ArticlePages?> = { emptyFlow() } | ||
) |
52 changes: 52 additions & 0 deletions
52
app/src/main/java/com/capyreader/app/ui/articles/detail/ArticlePagination.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.capyreader.app.ui.articles.detail | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.remember | ||
import androidx.lifecycle.compose.collectAsStateWithLifecycle | ||
import com.capyreader.app.ui.articles.LocalArticleLookup | ||
import com.jocmp.capy.Article | ||
import com.jocmp.capy.ArticlePages | ||
|
||
data class ArticlePagination( | ||
val pages: ArticlePages, | ||
val onSelectArticle: (index: Int, id: String) -> Unit, | ||
) { | ||
val hasPrevious = pages.previous > -1 | ||
val hasNext = pages.next > -1 | ||
val index = pages.current | ||
|
||
fun selectPrevious() { | ||
selectArticle(pages.previous, pages.previousID) | ||
} | ||
|
||
fun selectNext() { | ||
selectArticle(pages.next, pages.nextID) | ||
} | ||
|
||
private fun selectArticle(index: Int, id: String?) { | ||
if (index > -1 && index < pages.size && id != null) { | ||
onSelectArticle(index, id) | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
fun rememberArticlePagination( | ||
article: Article, | ||
onSelectArticle: (index: Int, id: String) -> Unit, | ||
): ArticlePagination { | ||
val lookup = LocalArticleLookup.current | ||
val pages by remember(article.id) { | ||
lookup.findArticlePages(article.id) | ||
}.collectAsStateWithLifecycle(null) | ||
|
||
return remember(pages, onSelectArticle) { | ||
val pagesWithDefault = pages ?: ArticlePages(current = -2, size = 0) | ||
|
||
ArticlePagination( | ||
pagesWithDefault, | ||
onSelectArticle, | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.