Exclude tags in clock widget favorites part
This commit is contained in:
parent
5d8bbbd19e
commit
21bdbb2f0a
@ -18,13 +18,6 @@ import org.koin.core.component.KoinComponent
|
|||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
interface FavoritesRepository {
|
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
|
* Get favorites
|
||||||
* @param includeTypes Include only items of these types. Cannot be used together with excludeTypes.
|
* @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)
|
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(
|
override fun getFavorites(
|
||||||
includeTypes: List<String>?,
|
includeTypes: List<String>?,
|
||||||
excludeTypes: List<String>?,
|
excludeTypes: List<String>?,
|
||||||
|
|||||||
@ -47,9 +47,11 @@ class FavoritesPartProvider : PartProvider, KoinComponent {
|
|||||||
|
|
||||||
val favorites by remember(columns, excludeCalendar, layout) {
|
val favorites by remember(columns, excludeCalendar, layout) {
|
||||||
favoritesRepository.getFavorites(
|
favoritesRepository.getFavorites(
|
||||||
columns = columns,
|
excludeTypes = if (excludeCalendar) listOf("calendar", "tag") else listOf("tag"),
|
||||||
maxRows = 1,
|
manuallySorted = true,
|
||||||
excludeCalendarEvents = excludeCalendar
|
automaticallySorted = true,
|
||||||
|
frequentlyUsed = true,
|
||||||
|
limit = columns
|
||||||
)
|
)
|
||||||
}.collectAsState(emptyList())
|
}.collectAsState(emptyList())
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user