Exclude tags in clock widget favorites part

This commit is contained in:
MM20 2022-09-24 19:37:03 +02:00
parent 5d8bbbd19e
commit 21bdbb2f0a
No known key found for this signature in database
GPG Key ID: 0B61A8F2DEAFA389
2 changed files with 5 additions and 61 deletions

View File

@ -18,13 +18,6 @@ import org.koin.core.component.KoinComponent
import java.io.File
interface FavoritesRepository {
@Deprecated("Use getFavorites(java.util.List<java.lang.String>, java.util.List<java.lang.String>, boolean, boolean, boolean, java.lang.Integer) instead.")
fun getFavorites(
columns: Int,
maxRows: Int? = null,
excludeCalendarEvents: Boolean = false
): Flow<List<Searchable>>
/**
* Get favorites
* @param includeTypes Include only items of these types. Cannot be used together with excludeTypes.
@ -101,57 +94,6 @@ internal class FavoritesRepositoryImpl(
private val scope = CoroutineScope(Job() + Dispatchers.Default)
override fun getFavorites(
columns: Int,
maxRows: Int?,
excludeCalendarEvents: Boolean
): Flow<List<Searchable>> =
channelFlow {
withContext(Dispatchers.IO) {
val dao = database.searchDao()
val pinnedFavorites =
if (excludeCalendarEvents) {
dao.getFavoritesWithoutTypes(
excludeTypes = listOf("calendar"),
manuallySorted = true,
automaticallySorted = true,
frequentlyUsed = false,
limit = columns * (maxRows ?: 20)
)
} else {
dao.getFavorites(
manuallySorted = true,
automaticallySorted = true,
frequentlyUsed = false,
limit = columns * (maxRows ?: 20)
)
}.map {
it.mapNotNull {
val item = fromDatabaseEntity(it).searchable
return@mapNotNull item
}
}
pinnedFavorites.collectLatest { pinned ->
var favCount = (pinned.size.toDouble() / columns).ceilToInt() * columns
if (pinned.size < columns) favCount += columns
val autoFavs = dao.getFavorites(
manuallySorted = false,
automaticallySorted = false,
frequentlyUsed = true,
limit = favCount.coerceAtMost((maxRows ?: 20) * columns) - pinned.size
).first().mapNotNull {
val item = fromDatabaseEntity(it).searchable
if (item == null) {
dao.deleteByKey(it.key)
}
return@mapNotNull item
}
send(pinned + autoFavs)
}
}
}
override fun getFavorites(
includeTypes: List<String>?,
excludeTypes: List<String>?,

View File

@ -47,9 +47,11 @@ class FavoritesPartProvider : PartProvider, KoinComponent {
val favorites by remember(columns, excludeCalendar, layout) {
favoritesRepository.getFavorites(
columns = columns,
maxRows = 1,
excludeCalendarEvents = excludeCalendar
excludeTypes = if (excludeCalendar) listOf("calendar", "tag") else listOf("tag"),
manuallySorted = true,
automaticallySorted = true,
frequentlyUsed = true,
limit = columns
)
}.collectAsState(emptyList())