Skip to content

Commit 90efb87

Browse files
authored
Simplify playstore reporting (#373)
1 parent 112d2d7 commit 90efb87

File tree

1 file changed

+37
-29
lines changed
  • presentation/src/main/java/com/shifthackz/aisdv1/presentation/screen/report

1 file changed

+37
-29
lines changed

presentation/src/main/java/com/shifthackz/aisdv1/presentation/screen/report/ReportViewModel.kt

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.shifthackz.aisdv1.presentation.screen.report
22

3+
import com.shifthackz.aisdv1.core.common.appbuild.BuildInfoProvider
4+
import com.shifthackz.aisdv1.core.common.appbuild.BuildType
35
import com.shifthackz.aisdv1.core.common.log.errorLog
46
import com.shifthackz.aisdv1.core.common.schedulers.SchedulersProvider
57
import com.shifthackz.aisdv1.core.common.schedulers.subscribeOnMainThread
@@ -25,6 +27,7 @@ class ReportViewModel(
2527
private val base64ToBitmapConverter: Base64ToBitmapConverter,
2628
private val mainRouter: MainRouter,
2729
private val schedulersProvider: SchedulersProvider,
30+
private val buildInfoProvider: BuildInfoProvider,
2831
) : MviRxViewModel<ReportState, ReportIntent, EmptyEffect>() {
2932

3033
override val initialState = ReportState()
@@ -50,35 +53,7 @@ class ReportViewModel(
5053

5154
override fun processIntent(intent: ReportIntent) {
5255
when (intent) {
53-
ReportIntent.Submit -> !sendReportUseCase(
54-
text = currentState.text,
55-
reason = currentState.reason ?: ReportReason.Other,
56-
image = currentState.imageBase64,
57-
)
58-
.doOnSubscribe {
59-
updateState { it.copy(loading = true) }
60-
}
61-
.doFinally {
62-
updateState { it.copy(loading = false) }
63-
}
64-
.subscribeOnMainThread(schedulersProvider)
65-
.subscribeBy(
66-
onError = { t ->
67-
errorLog(t)
68-
updateState {
69-
it.copy(
70-
reportSent = false,
71-
screenModal = Modal.Error(
72-
(t.localizedMessage ?: t.message
73-
?: "Something went wrong").asUiText(),
74-
)
75-
)
76-
}
77-
},
78-
onComplete = {
79-
updateState { it.copy(reportSent = true) }
80-
},
81-
)
56+
ReportIntent.Submit -> submitReport()
8257

8358
is ReportIntent.UpdateReason -> updateState {
8459
it.copy(reason = intent.reason)
@@ -100,4 +75,37 @@ class ReportViewModel(
10075
if (id <= 0) return getLastResultFromCacheUseCase()
10176
return getGenerationResultUseCase(id)
10277
}
78+
79+
private fun submitReport() = !sendReportUseCase(
80+
text = currentState.text,
81+
reason = currentState.reason,
82+
image = currentState.imageBase64,
83+
)
84+
.doOnSubscribe {
85+
updateState { it.copy(loading = true) }
86+
}
87+
.doFinally {
88+
updateState { it.copy(loading = false) }
89+
}
90+
.subscribeOnMainThread(schedulersProvider)
91+
.subscribeBy(
92+
onError = { t ->
93+
errorLog(t)
94+
updateState { state ->
95+
when (buildInfoProvider.type) {
96+
BuildType.PLAY -> state.copy(reportSent = true)
97+
else -> state.copy(
98+
reportSent = false,
99+
screenModal = Modal.Error(
100+
(t.localizedMessage ?: t.message
101+
?: "Something went wrong").asUiText(),
102+
)
103+
)
104+
}
105+
}
106+
},
107+
onComplete = {
108+
updateState { it.copy(reportSent = true) }
109+
},
110+
)
103111
}

0 commit comments

Comments
 (0)