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
interface EditProfileContract { | |
interface view { | |
fun setProgress(show: Boolean) | |
fun showEmptyFirstNameError() | |
fun showEmptyLastNameError() | |
} |
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
viewModel.getState().observe(this, Observer { handleState(it) }) | |
private fun handleState(state: EditProfileState?) { | |
if (state?.isCityDialogShown == true) { | |
showCitySelectionDialog() | |
return | |
} | |
if (state?.isGenderDialogShown == true) { | |
showGenderSelectionDialog() | |
return |
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
private val state = MutableLiveData<EditProfileState>() | |
fun getState(): LiveData<EditProfileState> { | |
return state | |
} | |
fun setProgressIndicator(isProgressIndicatorShown: Boolean) { | |
state.value?.isProgressIndicatorShown = isProgressIndicatorShown | |
} |
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
data class EditProfileState( | |
var isProgressIndicatorShown: Boolean = false, | |
var isCityDialogShown: Boolean = false, | |
var isGenderDialogShown: Boolean = false) |
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
viewModel.getStatus().observe(this, Observer { handleStatus(it) }) | |
private fun handleStatus(status: Status?) { | |
when (status) { | |
Status.EMPTY_FIRST_NAME -> Toast.makeText(activity, "Please enter your first name!", Toast.LENGTH_SHORT).show() | |
Status.EMPTY_LAST_NAME -> Toast.makeText(activity, "Please enter your last name", Toast.LENGTH_SHORT).show() | |
Status.EMPTY_CITY -> Toast.makeText(activity, "Please choose your home city", Toast.LENGTH_SHORT).show() | |
Status.INVALID_URI -> Toast.makeText(activity, "Unable to load the photo", Toast.LENGTH_SHORT).show() | |
Status.SUCCESS -> { | |
startActivity(HomeFragment.newIntent(activity)) |
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
enum class Status { | |
SUCCESS, | |
ERROR, | |
NO_NETWORK, | |
EMPTY_FIRST_NAME, | |
EMPTY_LAST_NAME, | |
EMPTY_CITY, | |
INVALID_URI | |
} |
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
private val status = SingleLiveEvent<Status>() | |
fun getStatus(): LiveData<Status> { | |
return status | |
} | |
fun handleImage(intent: Intent?) { | |
intent?.data?.let { | |
avatar.value = it.toString() | |
} ?: run { status.value = Status.INVALID_URI } |