Skip to content

Commit

Permalink
commit 2 : migrated KYCLevel3Fragment to compose
Browse files Browse the repository at this point in the history
  • Loading branch information
AdityaKumdale authored and therajanmaurya committed Apr 14, 2024
1 parent 02109c2 commit be9d758
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package org.mifos.mobilewallet.mifospay.kyc.presenter

import androidx.lifecycle.ViewModel
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import org.mifos.mobilewallet.core.base.UseCaseHandler
import org.mifos.mobilewallet.mifospay.data.local.LocalRepository
import javax.inject.Inject
Expand All @@ -11,5 +13,16 @@ class KYCLevel3ViewModel @Inject constructor(
private val mUseCaseHandler: UseCaseHandler,
private val mLocalRepository: LocalRepository
) : ViewModel() {
private val _kyc3uiState =
MutableStateFlow<KYCLevel3UiState>(KYCLevel3UiState.Loading)
val kyc3uiState: StateFlow<KYCLevel3UiState> = _kyc3uiState

//Todo: Implement KYCLevel3ViewModel flow

}

sealed interface KYCLevel3UiState {
data object Loading : KYCLevel3UiState
data object Success : KYCLevel3UiState
data object Error : KYCLevel3UiState
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,30 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import butterknife.ButterKnife
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.platform.ViewCompositionStrategy
import dagger.hilt.android.AndroidEntryPoint
import org.mifos.mobilewallet.mifospay.R
import org.mifos.mobilewallet.mifospay.base.BaseFragment
import org.mifos.mobilewallet.mifospay.kyc.KYCContract
import org.mifos.mobilewallet.mifospay.kyc.KYCContract.KYCLevel3View
import org.mifos.mobilewallet.mifospay.kyc.presenter.KYCLevel3Presenter
import javax.inject.Inject
import org.mifos.mobilewallet.mifospay.theme.MifosTheme

/**
* Created by ankur on 17/May/2018
*/
@AndroidEntryPoint
class KYCLevel3Fragment : BaseFragment(), KYCLevel3View {
@JvmField
@Inject
var mPresenter: KYCLevel3Presenter? = null
var mKYCLevel3Presenter: KYCContract.KYCLevel3Presenter? = null
class KYCLevel3Fragment : BaseFragment() {

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
val rootView = inflater.inflate(R.layout.fragment_kyc_lvl3, container, false)
ButterKnife.bind(this, rootView)
mPresenter!!.attachView(this)
//setToolbarTitle(Constants.KYC_REGISTRATION_LEVEL_3);
return rootView
): View {
return ComposeView(requireContext()).apply {
setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)
setContent {
MifosTheme {
KYCLevel3Screen()
}
}
}
}

companion object {
Expand All @@ -43,8 +39,4 @@ class KYCLevel3Fragment : BaseFragment(), KYCLevel3View {
return fragment
}
}

override fun setPresenter(presenter: KYCContract.KYCLevel3Presenter?) {
mKYCLevel3Presenter = presenter
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,52 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import org.mifos.mobilewallet.mifospay.R
import org.mifos.mobilewallet.mifospay.designsystem.component.MfOverlayLoadingWheel
import org.mifos.mobilewallet.mifospay.designsystem.component.MifosOutlinedTextField
import org.mifos.mobilewallet.mifospay.kyc.presenter.KYCLevel3UiState
import org.mifos.mobilewallet.mifospay.kyc.presenter.KYCLevel3ViewModel
import org.mifos.mobilewallet.mifospay.theme.MifosTheme

@Composable
fun KYCLevel3Screen(
viewModel: KYCLevel3ViewModel = hiltViewModel()
){
val kyc3uiState by viewModel.kyc3uiState.collectAsStateWithLifecycle()

KYCLevel3Screen(
uiState = kyc3uiState
)
}

@Composable
fun KYCLevel3Screen(
uiState: KYCLevel3UiState
){

Kyc3Form(
modifier = Modifier
)

when (uiState) {
KYCLevel3UiState.Loading -> {
MfOverlayLoadingWheel(stringResource(id = R.string.submitting))
}

KYCLevel3UiState.Error -> {
//Todo : Implement Error state
}

KYCLevel3UiState.Success -> {
//Todo : Implement Success state
}
}
}

@Composable
fun Kyc3Form(
modifier: Modifier
) {
var panIdValue by rememberSaveable { mutableStateOf("") }
Expand All @@ -31,7 +71,7 @@ fun KYCLevel3Screen(
modifier = Modifier
.fillMaxSize()
.padding(20.dp),
verticalArrangement = Arrangement.spacedBy(20.dp)
verticalArrangement = Arrangement.spacedBy(10.dp)
) {

MifosOutlinedTextField(
Expand Down Expand Up @@ -60,6 +100,6 @@ fun KYCLevel3Screen(
@Composable
fun KYCLevel3ScreenPreview() {
MifosTheme {
KYCLevel3Screen(modifier = Modifier)
Kyc3Form(modifier = Modifier)
}
}

0 comments on commit be9d758

Please sign in to comment.