-
Notifications
You must be signed in to change notification settings - Fork 603
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Survey-Question-Logic-Implemented #2262
base: master
Are you sure you want to change the base?
Changes from all commits
24a3491
496965c
32c3911
1198dd9
47c919b
a73616c
39a35e3
22d7fbe
2b325d7
e27ea7b
e2a34eb
fdcb983
e7f6b86
70a1f4a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* Copyright 2025 Mifos Initiative | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
* | ||
* See https://github.com/openMF/android-client/blob/master/LICENSE.md | ||
*/ | ||
package com.mifos.core.data.repository | ||
|
||
import com.mifos.core.objects.survey.Survey | ||
import rx.Observable | ||
|
||
interface SurveyQuestionRepository { | ||
|
||
fun getSurvey(surveyId: Int): Observable<Survey> | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright 2025 Mifos Initiative | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
* | ||
* See https://github.com/openMF/android-client/blob/master/LICENSE.md | ||
*/ | ||
package com.mifos.core.data.repositoryImp | ||
|
||
import com.mifos.core.data.repository.SurveyQuestionRepository | ||
import com.mifos.core.network.datamanager.DataManagerSurveys | ||
import com.mifos.core.objects.survey.Survey | ||
import rx.Observable | ||
import javax.inject.Inject | ||
|
||
class SurveyQuestionRepositoryImp @Inject constructor(private val dataManagerSurveys: DataManagerSurveys) : | ||
SurveyQuestionRepository { | ||
|
||
override fun getSurvey(surveyId: Int): Observable<Survey> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here! |
||
return dataManagerSurveys.getSurvey(surveyId) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* Copyright 2024 Mifos Initiative | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
* | ||
* See https://github.com/openMF/android-client/blob/master/LICENSE.md | ||
*/ | ||
package com.mifos.feature.client.clientSurveyQuestion | ||
|
||
import com.mifos.core.objects.survey.Survey | ||
|
||
sealed class SurveyQuestionUiState { | ||
|
||
data object ShowProgressbar : SurveyQuestionUiState() | ||
|
||
data class ShowFetchingError(val message: Int) : SurveyQuestionUiState() | ||
|
||
data class ShowQuestions(val ques: Survey) : SurveyQuestionUiState() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Copyright 2024 Mifos Initiative | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
* | ||
* See https://github.com/openMF/android-client/blob/master/LICENSE.md | ||
*/ | ||
package com.mifos.feature.client.clientSurveyQuestion | ||
|
||
import androidx.lifecycle.SavedStateHandle | ||
import androidx.lifecycle.ViewModel | ||
import com.mifos.core.common.utils.Constants | ||
import com.mifos.core.data.repository.SurveyQuestionRepository | ||
import com.mifos.core.objects.survey.Survey | ||
import com.mifos.feature.client.R | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.StateFlow | ||
import rx.Subscriber | ||
import rx.android.schedulers.AndroidSchedulers | ||
import rx.schedulers.Schedulers | ||
import javax.inject.Inject | ||
|
||
@HiltViewModel | ||
class SurveyQuestionViewModel @Inject constructor( | ||
private val surveyQuestionRepository: SurveyQuestionRepository, | ||
private val savedStateHandle: SavedStateHandle, | ||
) : ViewModel() { | ||
val surveyId = savedStateHandle.getStateFlow(key = Constants.CLIENT_ID, initialValue = 0) | ||
private val _surveyQuestionUiState = | ||
MutableStateFlow<SurveyQuestionUiState>(SurveyQuestionUiState.ShowProgressbar) | ||
val surveyQuestionUiState: StateFlow<SurveyQuestionUiState> get() = _surveyQuestionUiState | ||
|
||
init { | ||
loadSurvey(surveyId.value) | ||
} | ||
|
||
private lateinit var mSyncSurvey: Survey | ||
|
||
fun loadSurvey(surveyId: Int) { | ||
_surveyQuestionUiState.value = SurveyQuestionUiState.ShowProgressbar | ||
|
||
surveyQuestionRepository.getSurvey(surveyId) | ||
.observeOn(AndroidSchedulers.mainThread()) | ||
.subscribeOn(Schedulers.io()) | ||
.subscribe(object : Subscriber<Survey>() { | ||
override fun onCompleted() { | ||
_surveyQuestionUiState.value = SurveyQuestionUiState.ShowQuestions(ques = mSyncSurvey) | ||
} | ||
override fun onError(e: Throwable) { | ||
_surveyQuestionUiState.value = | ||
SurveyQuestionUiState.ShowFetchingError(R.string.feature_client_failed_to_fetch_survey_questions) | ||
} | ||
|
||
override fun onNext(survey: Survey) { | ||
mSyncSurvey = survey | ||
} | ||
}) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,7 +45,9 @@ sealed class ClientScreens(val route: String) { | |
fun argument(clientId: Int) = "client_survey_list_screen/$clientId" | ||
} | ||
|
||
data object ClientSurveyQuestionScreen : ClientScreens("client_survey_question_screen") | ||
data object ClientSurveyQuestionScreen : ClientScreens("client_survey_question_screen/{${Constants.CLIENT_ID}}") { | ||
fun argument(surveyId: Int) = "client_survey_question_screen/$surveyId" | ||
} | ||
Comment on lines
+48
to
+50
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. client ID? shouldn't this be survey_id !? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nahi bhai, I think clientid is correct??? We are taking the survey for that particular client right?? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Darkeye14 Correct me if I am wrong, but on line 49 we are passing surveyId right?? Even in the ViewModel, we are retrieving that value and storing it in the surveyId variable. however on line 48, it says Client_ID Shouldn’t both be the same!?! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yea in my opinion both should be the same.. either survey_id or client_id depending on what we are passing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nahi bhai, i think this is correct!! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh... my apologies. I didn't see we are using 2 view models here. @sujalagrawal2 its correct |
||
|
||
data object CreateClientScreen : ClientScreens("create_client_screen/{${Constants.CLIENT_ID}}") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@itsPronay bhai, what do you say about using Flow instead of Observables???
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yea bhai, we can use that. but it shouldn't be an issue now i guess, since we are using Observable in the whole project.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ha bhai