|
@@ -11,6 +11,7 @@ import com.khmer9.yuki.remote.service.ApiService
|
|
import com.khmer9.yuki.remote.service.ConnectivityStates
|
|
import com.khmer9.yuki.remote.service.ConnectivityStates
|
|
import com.khmer9.yuki.remote.service.EventListener
|
|
import com.khmer9.yuki.remote.service.EventListener
|
|
import com.khmer9.yuki.screen.main.ResultMainState
|
|
import com.khmer9.yuki.screen.main.ResultMainState
|
|
|
|
+import com.khmer9.yuki.screen.main.ResultSubState
|
|
import com.khmer9.yuki.screen.report.ReportViewState
|
|
import com.khmer9.yuki.screen.report.ReportViewState
|
|
import com.khmer9.yuki.screen.result.ResultViewState
|
|
import com.khmer9.yuki.screen.result.ResultViewState
|
|
import com.khmer9.yuki.util.PrefHelper
|
|
import com.khmer9.yuki.util.PrefHelper
|
|
@@ -37,6 +38,10 @@ class ShareViewModel(
|
|
private val mainModuleState = MutableLiveData(ResultMainState())
|
|
private val mainModuleState = MutableLiveData(ResultMainState())
|
|
val getMainModuleState: LiveData<ResultMainState> = mainModuleState
|
|
val getMainModuleState: LiveData<ResultMainState> = mainModuleState
|
|
|
|
|
|
|
|
+ //Sub Module Data
|
|
|
|
+ private val subModuleState = MutableLiveData(ResultSubState())
|
|
|
|
+ val getSubModuleState: LiveData<ResultSubState> = subModuleState
|
|
|
|
+
|
|
//Result Screen Live Data
|
|
//Result Screen Live Data
|
|
private val resultState = MutableLiveData<ResultViewState>(ResultViewState())
|
|
private val resultState = MutableLiveData<ResultViewState>(ResultViewState())
|
|
val getResultState: LiveData<ResultViewState> = resultState
|
|
val getResultState: LiveData<ResultViewState> = resultState
|
|
@@ -221,6 +226,37 @@ class ShareViewModel(
|
|
)
|
|
)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ fun remoteSubModule(module_id: String) {
|
|
|
|
+ if (subModuleState.value!!.isProgress) return
|
|
|
|
+ subModuleState.value = prevSubModule().copy(isProgress = true)
|
|
|
|
+
|
|
|
|
+ disposables.add(
|
|
|
|
+ apiService.remoteSubModule(module_id)
|
|
|
|
+ .timeout(60, TimeUnit.SECONDS)
|
|
|
|
+ .subscribeOn(Schedulers.io())
|
|
|
|
+ .observeOn(AndroidSchedulers.mainThread())
|
|
|
|
+ .subscribe({ response ->
|
|
|
|
+ if (response.resultCode == "1") {
|
|
|
|
+ response.data?.let {
|
|
|
|
+ val sortedList = it.sortedWith(compareBy { it.order })
|
|
|
|
+ subModuleState.value = prevSubModule().copy(
|
|
|
|
+ isProgress = false,
|
|
|
|
+ resultList = sortedList,
|
|
|
|
+ error = null
|
|
|
|
+ )
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ subModuleState.value = prevSubModule().copy(isProgress = false, error = "[${response.message.description}]")
|
|
|
|
+ }
|
|
|
|
+ }, {
|
|
|
|
+ val message: String = "ប្រតិបត្តិការមិនជោគជ័យ\n" + it.getErrorCode()
|
|
|
|
+ subModuleState.value = prevSubModule().copy(isProgress = false, error = message)
|
|
|
|
+ })
|
|
|
|
+ )
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ ////////////////////////////////////////////////////////
|
|
|
|
+
|
|
fun remoteResult() {
|
|
fun remoteResult() {
|
|
if (resultState.value!!.isProgress) return
|
|
if (resultState.value!!.isProgress) return
|
|
resultState.value = prevResult().copy(isProgress = true)
|
|
resultState.value = prevResult().copy(isProgress = true)
|
|
@@ -303,6 +339,8 @@ class ShareViewModel(
|
|
|
|
|
|
private fun prevMainModule() = mainModuleState.value!!
|
|
private fun prevMainModule() = mainModuleState.value!!
|
|
|
|
|
|
|
|
+ private fun prevSubModule() = subModuleState.value!!
|
|
|
|
+
|
|
private fun prevResult() = resultState.value!!
|
|
private fun prevResult() = resultState.value!!
|
|
|
|
|
|
private fun prevReport() = reportState.value!!
|
|
private fun prevReport() = reportState.value!!
|