Skip to content
Closed
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
29 changes: 28 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
import java.util.Properties
import java.io.FileInputStream

plugins {
id("com.android.application")
kotlin("android")
alias(libs.plugins.compose.compiler)
id("com.mikepenz.aboutlibraries.plugin")
}

val props = Properties().apply {
runCatching {
load(FileInputStream(rootProject.file("local.properties")))
}
}


android {
namespace = "com.readrops.app"
Expand All @@ -21,7 +30,10 @@ android {
isMinifyEnabled = true
isShrinkResources = true

proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}

debug {
Expand All @@ -41,6 +53,21 @@ android {
applicationIdSuffix = ".beta"
signingConfig = signingConfigs.getByName("debug")
}

configureEach {
val shouldSource = name == "debug" || name == "beta"
listOf(
"url" to "https://",
"login" to "",
"password" to ""
).forEach { (k, v) ->
resValue(
"string",
"debug.${k}",
if (shouldSource) props.getProperty("debug.$k", v) else v
)
}
}
Comment on lines +56 to +70
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an improvement to easier login during development. Please tell me if it need a separate PR.

}

buildFeatures {
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/com/readrops/app/AppModule.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.readrops.app

import android.content.Context
import androidx.compose.ui.platform.LocalContext
import androidx.core.app.NotificationManagerCompat
import androidx.datastore.core.handlers.ReplaceFileCorruptionHandler
import androidx.datastore.preferences.SharedPreferencesMigration
Expand Down Expand Up @@ -64,7 +65,7 @@ val appModule = module {
}

factory { (accountType: Account, mode: AccountCredentialsScreenMode) ->
AccountCredentialsScreenModel(accountType, mode, get())
AccountCredentialsScreenModel(accountType, mode, get(), context = get())
}

factory { (account: Account) -> NotificationsScreenModel(account, get(), get(), get()) }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.readrops.app.account.credentials

import android.content.Context
import android.content.SharedPreferences
import android.util.Patterns
import cafe.adriel.voyager.core.model.StateScreenModel
Expand All @@ -16,14 +17,22 @@ import kotlinx.coroutines.launch
import org.koin.core.component.KoinComponent
import org.koin.core.component.get
import org.koin.core.parameter.parametersOf
import com.readrops.app.R


class AccountCredentialsScreenModel(
private val account: Account,
private val mode: AccountCredentialsScreenMode,
private val database: Database,
private val dispatcher: CoroutineDispatcher = Dispatchers.IO
) : StateScreenModel<AccountCredentialsState>(AccountCredentialsState()), KoinComponent {

private val dispatcher: CoroutineDispatcher = Dispatchers.IO,
context: Context,
) : StateScreenModel<AccountCredentialsState>(
AccountCredentialsState(
url = context.getString(R.string.debug_url),
login = context.getString(R.string.debug_login),
password = context.getString(R.string.debug_password),
)
), KoinComponent {
init {
if (mode == AccountCredentialsScreenMode.EDIT_CREDENTIALS) {
mutableState.update {
Expand All @@ -35,7 +44,9 @@ class AccountCredentialsScreenModel(
)
}
} else {
mutableState.update { it.copy(name = account.name!!) }
mutableState.update {
it.copy(name = account.name!!)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,75 +3,40 @@ package com.readrops.app.repositories
import com.readrops.db.Database
import com.readrops.db.entities.Feed
import com.readrops.db.entities.Folder
import com.readrops.db.entities.OpenIn
import com.readrops.db.entities.FoldersWithFeedAndUnreadCount
import com.readrops.db.entities.unbox
import com.readrops.db.filters.MainFilter
import com.readrops.db.queries.FeedUnreadCountQueryBuilder
import com.readrops.db.queries.FoldersAndFeedsQueryBuilder
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.map
import kotlin.collections.map

class GetFoldersWithFeeds(
private val database: Database,
) {

@Deprecated("Use GetFoldersWithFeeds#get2")
fun get(
accountId: Int,
mainFilter: MainFilter,
useSeparateState: Boolean,
hideReadFeeds: Boolean = false
): Flow<Map<Folder?, List<Feed>>> {
val foldersAndFeedsQuery = FoldersAndFeedsQueryBuilder.build(accountId, hideReadFeeds)
val unreadItemsCountQuery = FeedUnreadCountQueryBuilder.build(accountId, mainFilter, useSeparateState)

return combine(
flow = database.folderDao().selectFoldersAndFeeds(foldersAndFeedsQuery),
flow2 = database.itemDao().selectFeedUnreadItemsCount(unreadItemsCountQuery)
) { folders, itemCounts ->
val foldersWithFeeds = folders.groupBy(
keySelector = {
if (it.folderId != null) {
Folder(
id = it.folderId!!,
name = it.folderName,
remoteId = it.folderRemoteId,
accountId = it.accountId
)
} else {
null
}
},
valueTransform = {
Feed(
id = it.feedId,
name = it.feedName,
iconUrl = it.feedIcon,
color = it.feedColor,
imageUrl = it.feedImage,
url = it.feedUrl,
siteUrl = it.feedSiteUrl,
description = it.feedDescription,
isNotificationEnabled = it.feedNotificationsEnabled,
openIn = if (it.feedOpenIn != null) {
it.feedOpenIn!!
} else {
OpenIn.LOCAL_VIEW
},
remoteId = it.feedRemoteId,
unreadCount = itemCounts[it.feedId] ?: 0
)
}
).mapValues { listEntry ->
// Empty folder case
if (listEntry.value.any { it.id == 0 }) {
listOf()
} else {
listEntry.value
return database.folderDao().selectFolders2(accountId).map { foldersAndFeeds ->
foldersAndFeeds.associate { folderAndFeeds ->
var unreadCount = 0
val resultFeeds = folderAndFeeds.feeds.map {
unreadCount += it.unreadCount
it.feed.copy(unreadCount = it.unreadCount)
}
folderAndFeeds.folder?.copy(unreadCount = unreadCount) to resultFeeds
}

foldersWithFeeds.toSortedMap(nullsLast(Folder::compareTo))
}
}
fun get2(
accountId: Int,
mainFilter: MainFilter,
hideReadFeeds: Boolean = false
): Flow<FoldersWithFeedAndUnreadCount> = database.folderDao().selectFolders2(accountId).map {
it.unbox()
}

fun getNewItemsUnreadCount(accountId: Int, useSeparateState: Boolean): Flow<Int> =
if (useSeparateState) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.readrops.app.timelime

import android.content.Context
import android.content.Intent
import android.util.Log
import androidx.compose.runtime.Stable
import androidx.paging.Pager
import androidx.paging.PagingConfig
Expand Down Expand Up @@ -101,17 +102,17 @@ class TimelineScreenModel(

preferences.hideReadFeeds.flow
.flatMapLatest { hideReadFeeds ->
getFoldersWithFeeds.get(
getFoldersWithFeeds.get2(
accountId = account.id,
mainFilter = filters.mainFilter,
useSeparateState = account.config.useSeparateState,
hideReadFeeds = hideReadFeeds
)
}
.collect { foldersAndFeeds ->
_timelineState.update {
it.copy(
foldersAndFeeds = foldersAndFeeds
unreadNewItemsCount = foldersAndFeeds.totalUnreadCount,
foldersAndFeeds = foldersAndFeeds.foldersAndFeeds
)
}
}
Expand Down
Loading