-
-
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.
* Parse published date in local delegate * Add article_statuses table
- Loading branch information
Showing
28 changed files
with
477 additions
and
137 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
54 changes: 42 additions & 12 deletions
54
app/src/main/java/com/jocmp/basilreader/ui/articles/ArticleList.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,45 +1,75 @@ | ||
package com.jocmp.basilreader.ui.articles | ||
|
||
import androidx.compose.foundation.clickable | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.lazy.LazyColumn | ||
import androidx.compose.material.ExperimentalMaterialApi | ||
import androidx.compose.material.pullrefresh.PullRefreshIndicator | ||
import androidx.compose.material.pullrefresh.pullRefresh | ||
import androidx.compose.material.pullrefresh.rememberPullRefreshState | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.rememberCoroutineScope | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.unit.dp | ||
import androidx.compose.ui.unit.sp | ||
import androidx.paging.Pager | ||
import androidx.paging.compose.collectAsLazyPagingItems | ||
import com.jocmp.basil.Article | ||
import kotlinx.coroutines.launch | ||
import java.time.format.DateTimeFormatter | ||
|
||
@OptIn(ExperimentalMaterialApi::class) | ||
@Composable | ||
fun ArticleList( | ||
pager: Pager<Int, Article>, | ||
onRefresh: suspend () -> Unit, | ||
onSelect: suspend (articleID: String) -> Unit, | ||
) { | ||
val composableScope = rememberCoroutineScope() | ||
val lazyPagingItems = pager.flow.collectAsLazyPagingItems() | ||
|
||
LazyColumn(Modifier.fillMaxWidth()) { | ||
items(count = lazyPagingItems.itemCount) { index -> | ||
val item = lazyPagingItems[index] | ||
Column( | ||
modifier = Modifier | ||
.padding(8.dp) | ||
.clickable { | ||
item?.let { | ||
composableScope.launch { | ||
onSelect(it.id) | ||
val refreshScope = rememberCoroutineScope() | ||
val (refreshing, setRefreshing) = remember { mutableStateOf(false) } | ||
|
||
fun refresh() = refreshScope.launch { | ||
setRefreshing(true) | ||
onRefresh() | ||
setRefreshing(false) | ||
} | ||
|
||
val state = rememberPullRefreshState(refreshing, ::refresh) | ||
|
||
Box(Modifier.pullRefresh(state)) { | ||
|
||
LazyColumn(Modifier.fillMaxWidth()) { | ||
items(count = lazyPagingItems.itemCount) { index -> | ||
val item = lazyPagingItems[index] | ||
Column( | ||
modifier = Modifier | ||
.padding(8.dp) | ||
.clickable { | ||
item?.let { | ||
composableScope.launch { | ||
onSelect(it.id) | ||
} | ||
} | ||
} | ||
) { | ||
item?.let { article -> | ||
Text(article.title, fontSize = 20.sp) | ||
Text(article.arrivedAt.format(DateTimeFormatter.BASIC_ISO_DATE)) | ||
} | ||
) { | ||
Text(item?.title ?: "No title", fontSize = 20.sp) | ||
} | ||
} | ||
} | ||
|
||
PullRefreshIndicator(refreshing, state, Modifier.align(Alignment.TopCenter)) | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.jocmp.basil | ||
|
||
import androidx.paging.Pager | ||
import androidx.paging.PagingConfig | ||
import com.jocmp.basil.persistence.ArticlePagerFactory | ||
|
||
fun Account.buildPager( | ||
filter: Filter = Filter.Articles(status = Filter.Status.ALL) | ||
): Pager<Int, Article> { | ||
val pagerFactory = ArticlePagerFactory( | ||
database = database, | ||
filter = filter | ||
) | ||
|
||
return Pager( | ||
config = PagingConfig(pageSize = 10), | ||
pagingSourceFactory = { pagerFactory.find() } | ||
) | ||
} |
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 was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.jocmp.basil | ||
|
||
sealed class Filter(val status: Status) { | ||
enum class Status(value: String) { | ||
ALL("all"), | ||
READ("read"), | ||
STARRED("starred") | ||
} | ||
|
||
class Articles(status: Status) : Filter(status) | ||
|
||
class Feeds(val feed: Feed, status: Status) : Filter(status) | ||
|
||
class Folders(val folder: Folder, status: Status) : Filter(status) | ||
} |
Oops, something went wrong.