Hide top row of favorites in favorites widget if it is directly below the clock widget favorites part
This commit is contained in:
parent
6424bf7b92
commit
824ae9bba2
@ -16,7 +16,7 @@ import org.koin.core.component.inject
|
|||||||
abstract class FavoritesVM : ViewModel(), KoinComponent {
|
abstract class FavoritesVM : ViewModel(), KoinComponent {
|
||||||
|
|
||||||
private val favoritesRepository: FavoritesRepository by inject()
|
private val favoritesRepository: FavoritesRepository by inject()
|
||||||
private val widgetRepository: WidgetRepository by inject()
|
internal val widgetRepository: WidgetRepository by inject()
|
||||||
private val customAttributesRepository: CustomAttributesRepository by inject()
|
private val customAttributesRepository: CustomAttributesRepository by inject()
|
||||||
internal val dataStore: LauncherDataStore by inject()
|
internal val dataStore: LauncherDataStore by inject()
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ abstract class FavoritesVM : ViewModel(), KoinComponent {
|
|||||||
it.filterIsInstance<Tag>()
|
it.filterIsInstance<Tag>()
|
||||||
}
|
}
|
||||||
|
|
||||||
val favorites: Flow<List<SavableSearchable>> = selectedTag.flatMapLatest { tag ->
|
open val favorites: Flow<List<SavableSearchable>> = selectedTag.flatMapLatest { tag ->
|
||||||
if (tag == null) {
|
if (tag == null) {
|
||||||
val columns = dataStore.data.map { it.grid.columnCount }
|
val columns = dataStore.data.map { it.grid.columnCount }
|
||||||
val excludeCalendar = widgetRepository.isCalendarWidgetEnabled()
|
val excludeCalendar = widgetRepository.isCalendarWidgetEnabled()
|
||||||
|
|||||||
@ -1,17 +1,37 @@
|
|||||||
package de.mm20.launcher2.ui.launcher.widgets.favorites
|
package de.mm20.launcher2.ui.launcher.widgets.favorites
|
||||||
|
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
|
import de.mm20.launcher2.preferences.Settings.ClockWidgetSettings.ClockWidgetLayout
|
||||||
import de.mm20.launcher2.ui.common.FavoritesVM
|
import de.mm20.launcher2.ui.common.FavoritesVM
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.SharingStarted
|
import kotlinx.coroutines.flow.SharingStarted
|
||||||
|
import kotlinx.coroutines.flow.combine
|
||||||
import kotlinx.coroutines.flow.map
|
import kotlinx.coroutines.flow.map
|
||||||
import kotlinx.coroutines.flow.shareIn
|
import kotlinx.coroutines.flow.shareIn
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
class FavoritesWidgetVM: FavoritesVM() {
|
class FavoritesWidgetVM : FavoritesVM() {
|
||||||
|
|
||||||
override val tagsExpanded: Flow<Boolean> = dataStore.data.map { it.ui.widgetTagsMultiline }
|
override val tagsExpanded: Flow<Boolean> = dataStore.data.map { it.ui.widgetTagsMultiline }
|
||||||
.shareIn(viewModelScope, SharingStarted.Lazily)
|
.shareIn(viewModelScope, SharingStarted.Lazily)
|
||||||
|
|
||||||
|
private val isTopWidget = widgetRepository.isFavoritesWidgetFirst()
|
||||||
|
private val clockWidgetFavSlots = dataStore.data.combine(isTopWidget) { data, isTop ->
|
||||||
|
if (!isTop) 0
|
||||||
|
else {
|
||||||
|
if (data.clockWidget.layout == ClockWidgetLayout.Horizontal) data.grid.columnCount - 2
|
||||||
|
else data.grid.columnCount
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override val favorites = super.favorites.combine(clockWidgetFavSlots) { favs, slots ->
|
||||||
|
if (selectedTag.value == null) {
|
||||||
|
favs.subList(slots, favs.size)
|
||||||
|
} else {
|
||||||
|
favs
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun setTagsExpanded(expanded: Boolean) {
|
override fun setTagsExpanded(expanded: Boolean) {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
dataStore.updateData {
|
dataStore.updateData {
|
||||||
|
|||||||
@ -36,4 +36,7 @@ interface WidgetDao {
|
|||||||
|
|
||||||
@Query("SELECT EXISTS(SELECT 1 FROM Widget WHERE type = :type AND data = :data)")
|
@Query("SELECT EXISTS(SELECT 1 FROM Widget WHERE type = :type AND data = :data)")
|
||||||
fun exists(type: String, data: String) : Flow<Boolean>
|
fun exists(type: String, data: String) : Flow<Boolean>
|
||||||
|
|
||||||
|
@Query("SELECT * FROM Widget ORDER BY position ASC LIMIT 1")
|
||||||
|
fun getFirst() : Flow<WidgetEntity?>
|
||||||
}
|
}
|
||||||
@ -24,6 +24,8 @@ interface WidgetRepository {
|
|||||||
fun isCalendarWidgetEnabled(): Flow<Boolean>
|
fun isCalendarWidgetEnabled(): Flow<Boolean>
|
||||||
fun isFavoritesWidgetEnabled(): Flow<Boolean>
|
fun isFavoritesWidgetEnabled(): Flow<Boolean>
|
||||||
|
|
||||||
|
fun isFavoritesWidgetFirst(): Flow<Boolean>
|
||||||
|
|
||||||
suspend fun export(toDir: File)
|
suspend fun export(toDir: File)
|
||||||
suspend fun import(fromDir: File)
|
suspend fun import(fromDir: File)
|
||||||
}
|
}
|
||||||
@ -105,6 +107,10 @@ internal class WidgetRepositoryImpl(
|
|||||||
return database.widgetDao().exists("internal", "favorites")
|
return database.widgetDao().exists("internal", "favorites")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun isFavoritesWidgetFirst(): Flow<Boolean> {
|
||||||
|
return database.widgetDao().getFirst().map { it?.type == "internal" && it.data == "favorites" }
|
||||||
|
}
|
||||||
|
|
||||||
override suspend fun export(toDir: File) = withContext(Dispatchers.IO) {
|
override suspend fun export(toDir: File) = withContext(Dispatchers.IO) {
|
||||||
val dao = database.backupDao()
|
val dao = database.backupDao()
|
||||||
var page = 0
|
var page = 0
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user