Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get articles to appear on refresh #74

Merged
merged 3 commits into from
Feb 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .idea/androidTestResultsUserPreferences.xml

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

5 changes: 2 additions & 3 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,12 @@ dependencies {
implementation("androidx.webkit:webkit:1.10.0")
implementation("androidx.work:work-runtime-ktx:2.9.0")
implementation("app.cash.sqldelight:android-driver:$sqldelightVersion")
implementation("io.coil-kt:coil:2.5.0")
implementation("io.coil-kt:coil-compose:2.5.0")
implementation("com.github.bumptech.glide:compose:1.0.0-beta01")
implementation("io.insert-koin:koin-android")
implementation("io.insert-koin:koin-androidx-compose")
implementation("io.insert-koin:koin-androidx-workmanager")
implementation("io.insert-koin:koin-core")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.8.0")
implementation(libs.androidx.preferences)
implementation(libs.kotlinx.coroutines.core)
implementation(libs.kotlinx.serialization.json)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,5 @@ fun AccountSettingsScreen(
viewModel.removeAccount()
goBack()
},
exportOPML = {
context.exportOPML(account = viewModel.account)
},
importOPML = {
picker.launch("text/xml")
}
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ fun AccountSettingsView(
refreshInterval: RefreshInterval,
updateRefreshInterval: (interval: RefreshInterval) -> Unit,
removeAccount: () -> Unit,
exportOPML: () -> Unit,
importOPML: () -> Unit,
) {
val scope = rememberCoroutineScope()
val snackbarHostState = remember { SnackbarHostState() }
Expand Down Expand Up @@ -64,16 +62,6 @@ fun AccountSettingsView(
updateRefreshInterval = updateRefreshInterval,
)

Button(
onClick = importOPML,
) {
Text(stringResource(R.string.account_settings_import))
}
Button(
onClick = exportOPML
) {
Text(stringResource(R.string.account_settings_export))
}
Button(onClick = { setRemoveDialogOpen(true) }) {
Text(stringResource(R.string.account_settings_delete_account_button))
}
Expand Down Expand Up @@ -112,8 +100,6 @@ fun AccountSettingsViewPreview() {
AccountSettingsView(
defaultDisplayName = "Feedbin",
removeAccount = {},
exportOPML = {},
importOPML = {},
refreshInterval = RefreshInterval.EVERY_HOUR,
updateRefreshInterval = {}
)
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.jocmp.basilreader.ui.articles

import android.app.DownloadManager.Query
import android.util.Log
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.derivedStateOf
Expand All @@ -20,8 +21,15 @@ import com.jocmp.basil.Feed
import com.jocmp.basil.Folder
import com.jocmp.basil.buildPager
import com.jocmp.basil.countAll
import com.jocmp.basil.persistence.AllFeeds
import com.jocmp.basilreader.common.AppPreferences
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.flow.transform
import kotlinx.coroutines.launch

private const val TAG = "AccountViewModel"
Expand All @@ -30,10 +38,7 @@ class AccountViewModel(
private val accountManager: AccountManager,
private val appPreferences: AppPreferences,
) : ViewModel() {
private val _account: MutableState<Account> = mutableStateOf(
accountManager.findByID(appPreferences.accountID.get())!!,
policy = neverEqualPolicy()
)
private val _account = accountManager.findByID(appPreferences.accountID.get())!!

private val _counts = mutableStateOf<Map<String, Long>>(mapOf())

Expand All @@ -47,18 +52,16 @@ class AccountViewModel(
get() = _articles.value

private val account: Account
get() = _account.value

val folders: List<Folder>
get() = account.folders.map(::copyFolderCounts).withPositiveCount(filterStatus)
get() = _account

private val articleState = mutableStateOf(account.findArticle(appPreferences.articleID.get()))

val statusCount: Long
get() = _counts.value.values.sum()

val feeds: List<Feed>
get() = account.feeds.map(::copyFeedCounts).withPositiveCount(filterStatus)
val folders = account.folders

val feeds = account.feeds

val article: Article?
get() = articleState.value
Expand Down Expand Up @@ -99,15 +102,13 @@ class AccountViewModel(
viewModelScope.launch {
account.removeFeed(feedID = feedID)
resetToDefaultFilter()
_account.value = account
}
}

fun removeFolder(folderTitle: String) {
viewModelScope.launch {
account.removeFolder(title = folderTitle)
resetToDefaultFilter()
_account.value = account
}
}

Expand Down Expand Up @@ -191,9 +192,7 @@ class AccountViewModel(
}

fun reload() {
_account.value = accountManager.findByID(appPreferences.accountID.get())!!
refreshCounts()
Log.d(TAG, "ArticleScreen: folders=${folders.size}; feeds=${feeds.size}")
}

private fun resetToDefaultFilter() {
Expand Down Expand Up @@ -230,7 +229,7 @@ class AccountViewModel(
}

private fun refreshCounts() {
_counts.value = _account.value.countAll(status = filterStatus)
_counts.value = _account.countAll(status = filterStatus)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fun AddFeedScreen(

Column {
AddFeedView(
folders = viewModel.folders,
folders = emptyList(),// viewModel.folders,
onSubmit = { entry ->
viewModel.addFeed(
entry,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.jocmp.basilreader.ui.articles

import androidx.compose.animation.Crossfade
import androidx.compose.animation.core.tween
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
Expand All @@ -14,33 +15,35 @@ import androidx.compose.material3.Scaffold
import androidx.compose.material3.TopAppBar
import androidx.compose.material3.adaptive.ExperimentalMaterial3AdaptiveApi
import androidx.compose.material3.adaptive.ListDetailPaneScaffoldRole
import androidx.compose.material3.adaptive.ThreePaneScaffoldDestinationItem
import androidx.compose.material3.adaptive.calculateListDetailPaneScaffoldState
import androidx.compose.material3.adaptive.rememberListDetailPaneScaffoldNavigator
import androidx.compose.material3.pulltorefresh.PullToRefreshContainer
import androidx.compose.material3.pulltorefresh.rememberPullToRefreshState
import androidx.compose.material3.rememberDrawerState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.tooling.preview.Preview
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.paging.PagingData
import com.jocmp.basil.Article
import com.jocmp.basil.ArticleFilter
import com.jocmp.basil.ArticleStatus
import com.jocmp.basil.Feed
import com.jocmp.basil.Folder
import com.jocmp.basil.persistence.AllFeeds
import com.jocmp.basilreader.ui.components.rememberSaveableWebViewState
import com.jocmp.basilreader.ui.components.rememberWebViewNavigator
import com.jocmp.basilreader.ui.fixtures.FeedPreviewFixture
import com.jocmp.basilreader.ui.fixtures.FolderPreviewFixture
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.emptyFlow
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.launch

@OptIn(
Expand Down Expand Up @@ -172,7 +175,7 @@ fun ArticleLayout(
) {
ArticleList(
articles = it,
selectedArticleKey = article?.key,
selectedArticleKey = article?.id,
onSelect = { articleID ->
onSelectArticle(articleID) {
coroutineScope.launch {
Expand Down
20 changes: 8 additions & 12 deletions app/src/main/java/com/jocmp/basilreader/ui/articles/ArticleList.kt
Original file line number Diff line number Diff line change
@@ -1,26 +1,16 @@
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.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.paging.PagingData
import androidx.paging.compose.collectAsLazyPagingItems
import androidx.paging.compose.itemKey
import com.jocmp.basil.Article
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.launch
import java.time.format.DateTimeFormatter

@Composable
fun ArticleList(
Expand All @@ -42,15 +32,21 @@ fun ArticleList(
) {
items(
count = lazyPagingItems.itemCount,
key = lazyPagingItems.itemKey { it.key }
key = lazyPagingItems.itemKey { it.id },
) { index ->
val item = lazyPagingItems[index] ?: return@items

ArticleRow(
article = item,
selected = selectedArticleKey == item.key,
selected = selectedArticleKey == item.id,
onSelect = { selectArticle(it) },
)
}
}
}

private fun String.orNullIfBlank(): String? {
return ifBlank {
null
}
}
Loading
Loading