mirror of
https://github.com/openflocon/Flocon.git
synced 2026-05-19 15:25:34 +00:00
Fix dashboard selection key
This commit is contained in:
parent
61e70a9cae
commit
e0aea704b2
4 changed files with 46 additions and 20 deletions
|
|
@ -7,11 +7,13 @@ import kotlinx.coroutines.flow.Flow
|
|||
|
||||
interface DeviceDashboardsDataSource {
|
||||
|
||||
fun observeSelectedDeviceDashboard(deviceIdAndPackageName: DeviceIdAndPackageNameDomainModel): Flow<DashboardId?>
|
||||
fun observeSelectedDeviceDashboard(
|
||||
deviceIdAndPackageName: DeviceIdAndPackageNameDomainModel
|
||||
): Flow<DashboardId?>
|
||||
|
||||
fun selectDeviceDashboard(
|
||||
deviceIdAndPackageName: DeviceIdAndPackageNameDomainModel,
|
||||
dashboardId: DashboardId,
|
||||
deviceIdAndPackageName: DeviceIdAndPackageNameDomainModel,
|
||||
)
|
||||
|
||||
fun deleteDashboard(
|
||||
|
|
|
|||
|
|
@ -114,18 +114,20 @@ class DashboardRepositoryImpl(
|
|||
}
|
||||
|
||||
override suspend fun selectDeviceDashboard(
|
||||
deviceIdAndPackageName: DeviceIdAndPackageNameDomainModel,
|
||||
dashboardId: DashboardId
|
||||
dashboardId: DashboardId,
|
||||
deviceIdAndPackageName: DeviceIdAndPackageNameDomainModel
|
||||
) {
|
||||
withContext(dispatcherProvider.data) {
|
||||
deviceDashboardsDataSource.selectDeviceDashboard(
|
||||
deviceIdAndPackageName = deviceIdAndPackageName,
|
||||
dashboardId = dashboardId,
|
||||
deviceIdAndPackageName = deviceIdAndPackageName,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override fun observeSelectedDeviceDashboard(deviceIdAndPackageName: DeviceIdAndPackageNameDomainModel): Flow<DashboardId?> = deviceDashboardsDataSource.observeSelectedDeviceDashboard(
|
||||
override fun observeSelectedDeviceDashboard(
|
||||
deviceIdAndPackageName: DeviceIdAndPackageNameDomainModel
|
||||
): Flow<DashboardId?> = deviceDashboardsDataSource.observeSelectedDeviceDashboard(
|
||||
deviceIdAndPackageName = deviceIdAndPackageName,
|
||||
).flowOn(dispatcherProvider.data)
|
||||
|
||||
|
|
|
|||
|
|
@ -11,31 +11,47 @@ import kotlinx.coroutines.flow.map
|
|||
import kotlinx.coroutines.flow.update
|
||||
|
||||
class DeviceDashboardsDataSourceInMemory : DeviceDashboardsDataSource {
|
||||
private val selectedDeviceDashboards = MutableStateFlow<Map<DeviceIdAndPackageNameDomainModel, DashboardId?>>(emptyMap())
|
||||
private val selectedDeviceDashboards = MutableStateFlow<Map<String, DashboardId?>>(emptyMap())
|
||||
private val selectedDashboardArrangements = MutableStateFlow<Map<String, DashboardArrangementDomainModel>>(emptyMap())
|
||||
|
||||
override fun observeSelectedDeviceDashboard(deviceIdAndPackageName: DeviceIdAndPackageNameDomainModel): Flow<DashboardId?> = selectedDeviceDashboards
|
||||
.map { it[deviceIdAndPackageName] }
|
||||
override fun observeSelectedDeviceDashboard(
|
||||
deviceIdAndPackageName: DeviceIdAndPackageNameDomainModel
|
||||
): Flow<DashboardId?> = selectedDeviceDashboards
|
||||
.map {
|
||||
val dashboardKey = getSelectedDashboardKey(deviceIdAndPackageName)
|
||||
it[dashboardKey]
|
||||
}
|
||||
.distinctUntilChanged()
|
||||
|
||||
override fun selectDeviceDashboard(deviceIdAndPackageName: DeviceIdAndPackageNameDomainModel, dashboardId: DashboardId) {
|
||||
override fun selectDeviceDashboard(
|
||||
dashboardId: DashboardId,
|
||||
deviceIdAndPackageName: DeviceIdAndPackageNameDomainModel
|
||||
) {
|
||||
val dashboardKey = getSelectedDashboardKey(deviceIdAndPackageName)
|
||||
selectedDeviceDashboards.update {
|
||||
it + (deviceIdAndPackageName to dashboardId)
|
||||
it + (dashboardKey to dashboardId)
|
||||
}
|
||||
}
|
||||
|
||||
override fun deleteDashboard(dashboardId: DashboardId, deviceIdAndPackageName: DeviceIdAndPackageNameDomainModel) {
|
||||
override fun deleteDashboard(
|
||||
dashboardId: DashboardId,
|
||||
deviceIdAndPackageName: DeviceIdAndPackageNameDomainModel
|
||||
) {
|
||||
val dashboardKey = getSelectedDashboardKey(deviceIdAndPackageName)
|
||||
selectedDeviceDashboards.update {
|
||||
if (it[deviceIdAndPackageName] == dashboardId) {
|
||||
it - deviceIdAndPackageName
|
||||
if (it[dashboardKey] == dashboardId) {
|
||||
it - dashboardKey
|
||||
} else it
|
||||
}
|
||||
}
|
||||
|
||||
override fun observeDashboardArrangement(dashboardId: DashboardId, deviceIdAndPackageName: DeviceIdAndPackageNameDomainModel): Flow<DashboardArrangementDomainModel> = selectedDashboardArrangements
|
||||
override fun observeDashboardArrangement(
|
||||
dashboardId: DashboardId,
|
||||
deviceIdAndPackageName: DeviceIdAndPackageNameDomainModel
|
||||
): Flow<DashboardArrangementDomainModel> = selectedDashboardArrangements
|
||||
.map {
|
||||
val dashboardKey = getDashboardArrangementKey(dashboardId, deviceIdAndPackageName)
|
||||
it[dashboardKey] ?: DashboardArrangementDomainModel.Adaptive
|
||||
val dashboardArrangementKey = getDashboardArrangementKey(dashboardId, deviceIdAndPackageName)
|
||||
it[dashboardArrangementKey] ?: DashboardArrangementDomainModel.Adaptive
|
||||
}
|
||||
.distinctUntilChanged()
|
||||
|
||||
|
|
@ -44,12 +60,18 @@ class DeviceDashboardsDataSourceInMemory : DeviceDashboardsDataSource {
|
|||
deviceIdAndPackageName: DeviceIdAndPackageNameDomainModel,
|
||||
arrangement: DashboardArrangementDomainModel
|
||||
) {
|
||||
val dashboardKey = getDashboardArrangementKey(dashboardId, deviceIdAndPackageName)
|
||||
val dashboardArrangementKey = getDashboardArrangementKey(dashboardId, deviceIdAndPackageName)
|
||||
selectedDashboardArrangements.update {
|
||||
it + (dashboardKey to arrangement)
|
||||
it + (dashboardArrangementKey to arrangement)
|
||||
}
|
||||
}
|
||||
|
||||
private fun getSelectedDashboardKey(
|
||||
deviceIdAndPackageName: DeviceIdAndPackageNameDomainModel
|
||||
): String {
|
||||
return deviceIdAndPackageName.packageName
|
||||
}
|
||||
|
||||
private fun getDashboardArrangementKey(
|
||||
dashboardId: DashboardId,
|
||||
deviceIdAndPackageName: DeviceIdAndPackageNameDomainModel
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import kotlinx.coroutines.flow.Flow
|
|||
interface DashboardRepository {
|
||||
fun observeDashboard(deviceIdAndPackageName: DeviceIdAndPackageNameDomainModel, dashboardId: DashboardId): Flow<DashboardDomainModel?>
|
||||
|
||||
suspend fun selectDeviceDashboard(deviceIdAndPackageName: DeviceIdAndPackageNameDomainModel, dashboardId: DashboardId)
|
||||
suspend fun selectDeviceDashboard(dashboardId: DashboardId, deviceIdAndPackageName: DeviceIdAndPackageNameDomainModel)
|
||||
fun observeSelectedDeviceDashboard(deviceIdAndPackageName: DeviceIdAndPackageNameDomainModel): Flow<DashboardId?>
|
||||
fun observeDeviceDashboards(deviceIdAndPackageName: DeviceIdAndPackageNameDomainModel): Flow<List<DashboardId>>
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue