Conversation
d3b8208 to
213d348
Compare
213d348 to
49c436a
Compare
There was a problem hiding this comment.
Pull request overview
Refactors the profile “Properties” flow to split the previous Design-based implementation into a Compose @Composable screen backed by a dedicated ViewModel (refs #119).
Changes:
- Added
PropertiesViewModelto own UI state/events, validation, saving, and commit progress reporting. - Reworked
PropertiesScreeninto a composable route that binds toPropertiesViewModelviacollectAsStateWithLifecycle. - Simplified
PropertiesActivityto a ComposesetContenthost forPropertiesScreenand navigation callbacks.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| app/src/main/kotlin/com/github/kr328/clash/profile/vm/PropertiesViewModel.kt | New ViewModel providing state/events, autosave-on-stop, and commit/progress handling for the Properties UI. |
| app/src/main/kotlin/com/github/kr328/clash/profile/ui/PropertiesScreen.kt | Moves from Design to pure Compose; binds UI to PropertiesViewModel and forwards navigation/events. |
| app/src/main/kotlin/com/github/kr328/clash/profile/PropertiesActivity.kt | Converts to a lightweight Compose host activity wiring navigation callbacks and result handling. |
Comments suppressed due to low confidence (1)
app/src/main/kotlin/com/github/kr328/clash/profile/ui/PropertiesScreen.kt:148
ModelProgressBarStateis mutated directly during composition viawith(progressBarState) { ... }. Since its fields aremutableStateOf, writing them during composition can cause unnecessary recompositions and is inconsistent with existing patterns (e.g.LogcatScreenupdates the progress state inside aLaunchedEffect). Consider moving these assignments intoLaunchedEffect(progressState).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| val profile = uiState.value.profile ?: return | ||
| viewModelScope.launch { | ||
| runCatching { | ||
| withProfile { patch(profile.uuid, profile.name, profile.source, profile.interval) } |
There was a problem hiding this comment.
onStop() auto-saves via patch(...) when there are unsaved changes, but the ViewModel never updates originalProfile / hasUnsavedChanges after a successful patch. This means the UI can continue to think there are unsaved changes and will re-patch on every subsequent stop. Consider updating originalProfile (and resetting hasUnsavedChanges) after the patch succeeds.
| withProfile { patch(profile.uuid, profile.name, profile.source, profile.interval) } | |
| withProfile { patch(profile.uuid, profile.name, profile.source, profile.interval) } | |
| }.onSuccess { | |
| uiState.update { state -> state.copy(originalProfile = profile.copy()) } |
| @OptIn(DelicateCoroutinesApi::class) | ||
| override fun onCleared() { | ||
| rootUuid?.let { uuid -> | ||
| GlobalScope.launch(Dispatchers.IO) { | ||
| try { | ||
| withProfile { release(uuid) } | ||
| } catch (e: Exception) { | ||
| // ignore | ||
| } | ||
| } |
There was a problem hiding this comment.
GlobalScope.launch in onCleared() is the only GlobalScope usage in the app module and opts into DelicateCoroutinesApi. Prefer using the app-wide com.github.kr328.clash.common.Global scope (used elsewhere, e.g. Remote.kt) or another structured application scope so this work is still cancellable/traceable.
| canceled = true | ||
| eventState.value = EventState.Finish(true) | ||
| } catch (e: Exception) { | ||
| eventState.value = EventState.ShowMessage(e.message ?: "Unknown error") |
There was a problem hiding this comment.
The fallback error message uses a hard-coded string ("Unknown error"). The rest of the app uses the localized R.string.unknown (e.g. NewProfileViewModel.kt). Consider switching to that resource (or another localized string) for consistency and translation coverage.
| eventState.value = EventState.ShowMessage(e.message ?: "Unknown error") | |
| eventState.value = | |
| EventState.ShowMessage( | |
| e.message ?: getApplication<Application>().getString(R.string.unknown), | |
| ) |
Agent-Logs-Url: https://github.com/Goooler/MihomoForAndroid/sessions/d0627b29-1c66-489f-b1c5-f651fcae1870 Co-authored-by: Goooler <10363352+Goooler@users.noreply.github.com>
Refs #119.