Created
July 24, 2020 17:27
-
-
Save biodunalfet/06467d5372af4befb1e935ca397e21ed to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.hf.fichaya.ui.main | |
import androidx.lifecycle.MutableLiveData | |
import androidx.lifecycle.ViewModel | |
import com.hf.fichaya.data.di.DIContainer | |
import com.hf.fichaya.data.local.LocalDataSource | |
import com.hf.fichaya.data.remote.response.UserData | |
class MainFragmentViewModel( | |
val local: LocalDataSource = DIContainer.localDataSource | |
) : ViewModel() { | |
val viewState: MutableLiveData<ViewState> = MutableLiveData<ViewState>() | |
init { | |
generateViewState() | |
} | |
private fun generateViewState() { | |
val userData: UserData = local.getUserData()!! | |
viewState.value = ViewState( | |
getVerifiedMessage = "Hey ${userData.firstName} get verified", | |
ratings = userData.ratingScore, | |
fullName = userData.fullName, | |
balance = NAIRA + (userData.balance ?: "0.0") | |
) | |
} | |
fun onViewResumed() { | |
refreshUserData() | |
} | |
private fun refreshUserData() { | |
// TODO get latest user data from network and update the local | |
// after updating, call #generateViewState() | |
} | |
data class ViewState( | |
val getVerifiedMessage: String, | |
val ratings: String, | |
val fullName: String, | |
val balance: String | |
) | |
} | |
const val NAIRA = "₦" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment