-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
KMP: use compose gradle injected dep versions, locker viewmodel, watc…
…hfaces list
- Loading branch information
Showing
14 changed files
with
243 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
.../src/commonMain/kotlin/io/rebble/cobble/shared/ui/view/home/locker/LockerWatchfaceItem.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package io.rebble.cobble.shared.ui.view.home.locker | ||
|
||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.size | ||
import androidx.compose.material3.Surface | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.unit.dp | ||
import androidx.lifecycle.viewmodel.compose.viewModel | ||
import io.rebble.cobble.shared.database.entity.SyncedLockerEntry | ||
import io.rebble.cobble.shared.database.entity.SyncedLockerEntryWithPlatforms | ||
import io.rebble.cobble.shared.ui.common.RebbleIcons | ||
import io.rebble.cobble.shared.ui.viewmodel.LockerWatchfaceItemViewModel | ||
|
||
@Composable | ||
fun LockerWatchfaceItem(entry: SyncedLockerEntryWithPlatforms) { | ||
val viewModel: LockerWatchfaceItemViewModel = viewModel { LockerWatchfaceItemViewModel(entry) } | ||
Surface(tonalElevation = 1.dp) { | ||
Column(modifier = Modifier.fillMaxWidth()) { | ||
Box(modifier = Modifier.size(width = 92.dp, height = if (viewModel.circleWatchface) 92.dp else 108.dp)) { RebbleIcons.unknownApp() } | ||
Text(viewModel.title) | ||
Text(viewModel.developerName) | ||
} | ||
} | ||
} |
24 changes: 22 additions & 2 deletions
24
.../src/commonMain/kotlin/io/rebble/cobble/shared/ui/view/home/locker/LockerWatchfaceList.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,29 @@ | ||
package io.rebble.cobble.shared.ui.view.home.locker | ||
|
||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.lazy.grid.GridCells | ||
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid | ||
import androidx.compose.foundation.rememberScrollState | ||
import androidx.compose.foundation.verticalScroll | ||
import androidx.compose.material3.Surface | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.collectAsState | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.ui.Modifier | ||
import io.rebble.cobble.shared.ui.viewmodel.LockerViewModel | ||
|
||
@Composable | ||
fun LockerWatchfaceList() { | ||
Text("Watchface list") | ||
fun LockerWatchfaceList(viewModel: LockerViewModel) { | ||
val entriesState: LockerViewModel.LockerEntriesState by viewModel.entriesState.collectAsState() | ||
val entries = ((entriesState as? LockerViewModel.LockerEntriesState.Loaded)?.entries ?: emptyList()).filter { it.entry.type == "watchface" } | ||
|
||
LazyVerticalGrid( | ||
columns = GridCells.Fixed(2), | ||
modifier = Modifier.verticalScroll(rememberScrollState()) | ||
) { | ||
items(entries.size) { i -> | ||
LockerWatchfaceItem(entries[i]) | ||
} | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
android/shared/src/commonMain/kotlin/io/rebble/cobble/shared/ui/viewmodel/LockerViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package io.rebble.cobble.shared.ui.viewmodel | ||
|
||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import io.rebble.cobble.shared.database.dao.LockerDao | ||
import io.rebble.cobble.shared.database.entity.SyncedLockerEntryWithPlatforms | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.IO | ||
import kotlinx.coroutines.Job | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.asStateFlow | ||
import kotlinx.coroutines.launch | ||
import kotlinx.coroutines.sync.Mutex | ||
import kotlinx.coroutines.sync.withLock | ||
|
||
class LockerViewModel(private val lockerDao: LockerDao): ViewModel() { | ||
open class LockerEntriesState { | ||
object Loading : LockerEntriesState() | ||
data class Loaded(val entries: List<SyncedLockerEntryWithPlatforms>) : LockerEntriesState() | ||
} | ||
|
||
private val _entriesState: MutableStateFlow<LockerEntriesState> = MutableStateFlow(LockerEntriesState.Loading) | ||
val entriesState = _entriesState.asStateFlow() | ||
private var mutex = Mutex() | ||
private var lastJob: Job? = null | ||
|
||
init { | ||
viewModelScope.launch(Dispatchers.IO) { | ||
_entriesState.value = LockerEntriesState.Loaded(lockerDao.getAllEntries()) | ||
} | ||
} | ||
|
||
suspend fun updateOrder(entries: List<SyncedLockerEntryWithPlatforms>) { | ||
lastJob?.cancel() | ||
lastJob = viewModelScope.launch(Dispatchers.IO) { | ||
mutex.withLock { | ||
entries.forEachIndexed { i, e -> | ||
lockerDao.updateOrder(e.entry.id, i+1) | ||
} | ||
} | ||
} | ||
_entriesState.value = LockerEntriesState.Loaded(entries) | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...rc/commonMain/kotlin/io/rebble/cobble/shared/ui/viewmodel/LockerWatchfaceItemViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package io.rebble.cobble.shared.ui.viewmodel | ||
|
||
import androidx.lifecycle.ViewModel | ||
import io.rebble.cobble.shared.database.entity.SyncedLockerEntry | ||
import io.rebble.cobble.shared.database.entity.SyncedLockerEntryWithPlatforms | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.asStateFlow | ||
import org.jetbrains.skia.Image | ||
|
||
class LockerWatchfaceItemViewModel(val entry: SyncedLockerEntryWithPlatforms): ViewModel() { | ||
open class ImageState { | ||
object Loading : ImageState() | ||
data class Loaded(val image: Image) : ImageState() | ||
} | ||
private var _imageState = MutableStateFlow(ImageState.Loading) | ||
val imageState = _imageState.asStateFlow() | ||
|
||
val title: String | ||
get() = entry.entry.title | ||
|
||
val developerName: String | ||
get() = entry.entry.developerName | ||
|
||
val circleWatchface: Boolean | ||
get() = entry.platforms.any { it.name == "chalk" } && entry.platforms.size == 1 //TODO: also display when chalk connected | ||
|
||
init { | ||
//TODO: Load image | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.