3d354b664dc8
feat: D8 feedback HTTP submission — FeedbackRepository (OkHttp, mirrors browser payload; endpoint TODO) + Sending/Sent/Error states + retry in SettingsCardBodies (v2.1.34)
- time
- 2026-06-09 04:43 UTC · 5 months ago
- machine
- koh2
- agent
- claude-opus-4-8
- session
- peach remaining gaps
- parent
- 16237ac7d53f
↓ peach-android-3d354b66.tar.gzatlas at this save
files changed6 files
app/drafts/D8/FeedbackRepository.kt+0 −65app/drafts/D8/FeedbackState.kt+0 −12app/src/main/java/com/peachpasswords/feedback/FeedbackRepository.kt+65 −0app/src/main/java/com/peachpasswords/feedback/FeedbackState.kt+12 −0app/src/main/java/com/peachpasswords/ui/settings/SettingsCardBodies.kt+52 −6app/src/main/java/com/peachpasswords/ui/settings/SettingsViewModel.kt+24 −0app/drafts/D8/FeedbackRepository.kt+0 −65
@@ -1,65 +0,0 @@1-package com.peachpasswords.feedback2-3-import com.peachpasswords.BuildConfig4-import kotlinx.coroutines.Dispatchers5-import kotlinx.coroutines.withContext6-import okhttp3.MediaType.Companion.toMediaType7-import okhttp3.OkHttpClient8-import okhttp3.Request9-import okhttp3.RequestBody.Companion.toRequestBody10-import org.json.JSONObject11-import javax.inject.Inject12-import javax.inject.Singleton13-14-/**15- * Submits user feedback to the Peach feedback endpoint. Payload shape mirrors16- * the browser extension's `SUBMIT_FEEDBACK` handler exactly17- * (`src/background/messages.ts`): a JSON body of18- * `{ category, message, version, browser, source }`, POSTed as19- * `application/json`.20- *21- * As in the browser, [FEEDBACK_ENDPOINT] is empty by default: when unset the22- * submission is a no-op that reports success, so the UI flow works end-to-end23- * without a live backend. The orchestrator fills in the real URL once it exists24- * (see INTEGRATION.md). The `source` discriminator is `"peach-android"` here25- * (the browser sends `"peach-extension"`).26- */27-@Singleton28-class FeedbackRepository @Inject constructor() {29-30- private val client: OkHttpClient by lazy { OkHttpClient() }31-32- suspend fun submit(type: String, message: String) {33- if (message.isBlank()) throw IllegalArgumentException("message_empty")34-35- // No-op success when no endpoint is configured (matches browser behaviour).36- if (FEEDBACK_ENDPOINT.isBlank()) return37-38- withContext(Dispatchers.IO) {39- val payload = JSONObject().apply {40- put("category", type)41- put("message", message)42- put("version", BuildConfig.VERSION_NAME)43- put("browser", "android")44- put("source", "peach-android")45- }46- val body = payload.toString().toRequestBody(JSON)47- val request = Request.Builder()48- .url(FEEDBACK_ENDPOINT)49- .post(body)50- .build()51- client.newCall(request).execute().use { res ->52- if (!res.isSuccessful) throw java.io.IOException("HTTP ${res.code}")53- }54- }55- }56-57- companion object {58- // TODO(orchestrator): set to the real Peach feedback endpoint when it59- // exists. The browser source ships this empty (FEEDBACK_ENDPOINT = "")60- // and treats empty as a no-op success. Keep that contract.61- const val FEEDBACK_ENDPOINT: String = ""62-63- private val JSON = "application/json; charset=utf-8".toMediaType()64- }65-}app/drafts/D8/FeedbackState.kt+0 −12
@@ -1,12 +0,0 @@1-package com.peachpasswords.feedback2-3-/**4- * UI state for a feedback submission. Mirrors the browser extension's three5- * outcomes (no-op success, success, error) plus an in-flight state.6- */7-sealed interface FeedbackState {8- object Idle : FeedbackState9- object Sending : FeedbackState10- object Sent : FeedbackState11- data class Error(val message: String) : FeedbackState12-}app/src/main/java/com/peachpasswords/feedback/FeedbackRepository.kt+65 −0
@@ -0,0 +1,65 @@1+package com.peachpasswords.feedback2+3+import com.peachpasswords.BuildConfig4+import kotlinx.coroutines.Dispatchers5+import kotlinx.coroutines.withContext6+import okhttp3.MediaType.Companion.toMediaType7+import okhttp3.OkHttpClient8+import okhttp3.Request9+import okhttp3.RequestBody.Companion.toRequestBody10+import org.json.JSONObject11+import javax.inject.Inject12+import javax.inject.Singleton13+14+/**15+ * Submits user feedback to the Peach feedback endpoint. Payload shape mirrors16+ * the browser extension's `SUBMIT_FEEDBACK` handler exactly17+ * (`src/background/messages.ts`): a JSON body of18+ * `{ category, message, version, browser, source }`, POSTed as19+ * `application/json`.20+ *21+ * As in the browser, [FEEDBACK_ENDPOINT] is empty by default: when unset the22+ * submission is a no-op that reports success, so the UI flow works end-to-end23+ * without a live backend. The orchestrator fills in the real URL once it exists24+ * (see INTEGRATION.md). The `source` discriminator is `"peach-android"` here25+ * (the browser sends `"peach-extension"`).26+ */27+@Singleton28+class FeedbackRepository @Inject constructor() {29+30+ private val client: OkHttpClient by lazy { OkHttpClient() }31+32+ suspend fun submit(type: String, message: String) {33+ if (message.isBlank()) throw IllegalArgumentException("message_empty")34+35+ // No-op success when no endpoint is configured (matches browser behaviour).36+ if (FEEDBACK_ENDPOINT.isBlank()) return37+38+ withContext(Dispatchers.IO) {39+ val payload = JSONObject().apply {40+ put("category", type)41+ put("message", message)42+ put("version", BuildConfig.VERSION_NAME)43+ put("browser", "android")44+ put("source", "peach-android")45+ }46+ val body = payload.toString().toRequestBody(JSON)47+ val request = Request.Builder()48+ .url(FEEDBACK_ENDPOINT)49+ .post(body)50+ .build()51+ client.newCall(request).execute().use { res ->52+ if (!res.isSuccessful) throw java.io.IOException("HTTP ${res.code}")53+ }54+ }55+ }56+57+ companion object {58+ // TODO(orchestrator): set to the real Peach feedback endpoint when it59+ // exists. The browser source ships this empty (FEEDBACK_ENDPOINT = "")60+ // and treats empty as a no-op success. Keep that contract.61+ const val FEEDBACK_ENDPOINT: String = ""62+63+ private val JSON = "application/json; charset=utf-8".toMediaType()64+ }65+}app/src/main/java/com/peachpasswords/feedback/FeedbackState.kt+12 −0
@@ -0,0 +1,12 @@1+package com.peachpasswords.feedback2+3+/**4+ * UI state for a feedback submission. Mirrors the browser extension's three5+ * outcomes (no-op success, success, error) plus an in-flight state.6+ */7+sealed interface FeedbackState {8+ object Idle : FeedbackState9+ object Sending : FeedbackState10+ object Sent : FeedbackState11+ data class Error(val message: String) : FeedbackState12+}app/src/main/java/com/peachpasswords/ui/settings/SettingsCardBodies.kt+52 −6
@@ -24,8 +24,13 @@2424 import androidx.compose.foundation.shape.RoundedCornerShape2525 import androidx.compose.foundation.text.BasicTextField2626 import androidx.compose.runtime.Composable27+import androidx.compose.material3.CircularProgressIndicator28+import androidx.compose.runtime.DisposableEffect2729 import androidx.compose.runtime.collectAsState2830 import androidx.compose.runtime.getValue31+import com.peachpasswords.feedback.FeedbackState32+import com.peachpasswords.ui.theme.LocalPeachAccent33+import com.peachpasswords.ui.theme.PeachColors2934 import androidx.compose.runtime.mutableStateOf3035 import androidx.compose.runtime.remember3136 import androidx.compose.runtime.rememberCoroutineScope@@ -75,7 +80,7 @@7580 CardId.Sync -> SyncBody(fg, onNavigate)7681 CardId.Shortcuts -> ShortcutsBody(fg)7782 CardId.Pro -> ProBody(fg, vm)78- CardId.Feedback -> FeedbackBody(fg)83+ CardId.Feedback -> FeedbackBody(fg, vm)7984 }8085 }8186 @@ -580,13 +585,16 @@580585 581586 @OptIn(ExperimentalLayoutApi::class)582587 @Composable583-private fun FeedbackBody(fg: Color) {588+private fun FeedbackBody(fg: Color, vm: SettingsViewModel) {584589 val categories = listOf("Bug report", "Feature request", "Question", "Other")585590 var category by remember { mutableStateOf(categories[0]) }586591 var message by remember { mutableStateOf("") }587- var sent by remember { mutableStateOf(false) }592+ val state by vm.feedbackState.collectAsState()588593 589- if (sent) {594+ // Reset transient state when the card leaves composition so reopening starts fresh.595+ DisposableEffect(Unit) { onDispose { vm.resetFeedback() } }596+597+ if (state is FeedbackState.Sent) {590598 Box(591599 Modifier.fillMaxWidth().clip(RoundedCornerShape(10.dp)).background(fg.copy(alpha = 0.08f))592600 .border(1.dp, fg.copy(alpha = 0.32f), RoundedCornerShape(10.dp)).padding(16.dp),@@ -599,10 +607,12 @@599607 return600608 }601609 610+ val sending = state is FeedbackState.Sending611+602612 Text("Help us improve Peach. Every report goes directly to our inbox.", color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 12.sp, lineHeight = 17.sp)603613 SubLabel("TYPE", fg)604614 FlowRow(horizontalArrangement = Arrangement.spacedBy(6.dp), verticalArrangement = Arrangement.spacedBy(6.dp)) {605- categories.forEach { cat -> Pill(cat, category == cat, fg) { category = cat } }615+ categories.forEach { cat -> Pill(cat, category == cat, fg) { if (!sending) category = cat } }606616 }607617 SubLabel("MESSAGE", fg)608618 Box(@@ -613,11 +623,47 @@613623 if (message.isEmpty()) Text("Describe the issue or idea...", color = fg.copy(alpha = 0.42f), fontFamily = PeachType.Body, fontSize = 12.sp)614624 BasicTextField(615625 value = message, onValueChange = { message = it },626+ enabled = !sending,616627 textStyle = TextStyle(color = fg, fontFamily = PeachType.Body, fontSize = 12.sp),617628 cursorBrush = SolidColor(fg), modifier = Modifier.fillMaxWidth(),618629 )619630 }620631 Spacer(Modifier.height(8.dp))621- SubtleButton("Send", fg) { if (message.isNotBlank()) sent = true }632+633+ Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(10.dp)) {634+ val canSend = !sending && message.isNotBlank()635+ Box(636+ Modifier.clip(RoundedCornerShape(8.dp))637+ .border(1.dp, fg.copy(alpha = if (canSend) 0.28f else 0.14f), RoundedCornerShape(8.dp))638+ .background(fg.copy(alpha = if (canSend) 0.08f else 0.04f))639+ .clickable(enabled = canSend) { vm.sendFeedback(category, message) }640+ .padding(horizontal = 12.dp, vertical = 6.dp),641+ ) {642+ Text(643+ if (state is FeedbackState.Error) "Retry" else "Send",644+ color = fg.copy(alpha = if (canSend) 1f else 0.4f),645+ fontFamily = PeachType.Mono, fontSize = 11.sp,646+ )647+ }648+ if (sending) {649+ CircularProgressIndicator(650+ color = LocalPeachAccent.current,651+ strokeWidth = 2.dp,652+ modifier = Modifier.size(16.dp),653+ )654+ }655+ }656+657+ (state as? FeedbackState.Error)?.let { err ->658+ Text(659+ err.message,660+ modifier = Modifier.padding(top = 8.dp),661+ color = PeachColors.Breach,662+ fontFamily = PeachType.Mono,663+ fontSize = 11.sp,664+ lineHeight = 15.sp,665+ )666+ }667+622668 Hint("Sent anonymously · no account required", fg)623669 }app/src/main/java/com/peachpasswords/ui/settings/SettingsViewModel.kt+24 −0
@@ -5,6 +5,8 @@55 import androidx.fragment.app.FragmentActivity66 import androidx.lifecycle.ViewModel77 import androidx.lifecycle.viewModelScope8+import com.peachpasswords.feedback.FeedbackRepository9+import com.peachpasswords.feedback.FeedbackState810 import com.peachpasswords.license.LicenseRepository911 import com.peachpasswords.ui.lock.BiometricKeyStore1012 import com.peachpasswords.ui.lock.Biometrics@@ -23,8 +25,30 @@2325 class SettingsViewModel @Inject constructor(2426 private val vault: VaultRepository,2527 private val license: LicenseRepository,28+ private val feedback: FeedbackRepository,2629 @ApplicationContext private val appContext: Context,2730 ) : ViewModel() {31+32+ private val _feedbackState = MutableStateFlow<FeedbackState>(FeedbackState.Idle)33+ val feedbackState: StateFlow<FeedbackState> = _feedbackState.asStateFlow()34+35+ fun sendFeedback(type: String, message: String) {36+ if (_feedbackState.value is FeedbackState.Sending) return37+ _feedbackState.value = FeedbackState.Sending38+ viewModelScope.launch {39+ _feedbackState.value = try {40+ feedback.submit(type, message)41+ FeedbackState.Sent42+ } catch (e: Exception) {43+ FeedbackState.Error("Couldn't send feedback — check your connection")44+ }45+ }46+ }47+48+ /** Reset to Idle when the Feedback card leaves the screen. */49+ fun resetFeedback() {50+ _feedbackState.value = FeedbackState.Idle51+ }2852 val entries: StateFlow<List<com.peachpasswords.vault.VaultEntry>> = vault.entries2953 val settings: StateFlow<VaultSettings> = vault.settings3054