Merge pull request #1857 from medici/bugs/amc-loader
Fix loader issue in AMC app
This commit is contained in:
@@ -28,15 +28,11 @@ abstract class BaseActivity<D : ViewDataBinding, V : BaseViewModel> : AppCompatA
|
||||
private val progressDialog by lazy { CustomProgressDialog(this) }
|
||||
|
||||
fun showProgress() {
|
||||
currentFocus?.clearFocus()
|
||||
hideProgress()
|
||||
progressDialog.show()
|
||||
}
|
||||
|
||||
fun hideProgress() {
|
||||
currentFocus?.clearFocus()
|
||||
progressDialog.hide()
|
||||
progressDialog.cancel()
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
|
||||
@@ -6,6 +6,8 @@ import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.liveData
|
||||
import com.navi.amc.investorapp.retrofit.ApiErrorHandler
|
||||
import com.navi.amc.investorapp.util.orFalse
|
||||
import com.navi.amc.investorapp.util.orTrue
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
|
||||
|
||||
@@ -17,16 +19,17 @@ abstract class BaseViewModel : ViewModel() {
|
||||
private val _error = MutableLiveData<String>()
|
||||
val error: LiveData<String> = _error
|
||||
|
||||
private val _updateHomeData = MutableLiveData<Boolean>()
|
||||
val updateHomeData: LiveData<Boolean> = _updateHomeData
|
||||
|
||||
|
||||
fun showProgress() {
|
||||
_progress.value = true
|
||||
if (!progress.value.orFalse()) {
|
||||
_progress.value = true
|
||||
}
|
||||
}
|
||||
|
||||
fun hideProgress() {
|
||||
_progress.value = false
|
||||
if (progress.value.orTrue()) {
|
||||
_progress.value = false
|
||||
}
|
||||
}
|
||||
|
||||
fun hideProgressAndShowError(it: Exception) {
|
||||
|
||||
@@ -212,8 +212,6 @@ class SellMyFundActivity : BaseActivity<ActivitySellMyFundBinding, SellMyFundVie
|
||||
}
|
||||
}
|
||||
|
||||
private val progressDialog by lazy { CustomProgressDialog(this) }
|
||||
|
||||
private fun inItLiveDataObserver() {
|
||||
viewModel.onCLick.observe(this, {
|
||||
when (it.id) {
|
||||
@@ -359,13 +357,6 @@ class SellMyFundActivity : BaseActivity<ActivitySellMyFundBinding, SellMyFundVie
|
||||
}
|
||||
}
|
||||
})
|
||||
viewModel.loader.observe(this, Observer {
|
||||
if (it) {
|
||||
progressDialog.show()
|
||||
} else {
|
||||
progressDialog.hide()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun disableUI() {
|
||||
|
||||
@@ -43,9 +43,6 @@ class SellMyFundViewModel : BaseViewModel() {
|
||||
var isin: String = ""
|
||||
var accessToken = ""
|
||||
|
||||
private val _loader = MutableLiveData<Boolean>()
|
||||
val loader: LiveData<Boolean> = _loader
|
||||
|
||||
var otp1: ObservableField<String> = ObservableField("")
|
||||
var otp2: ObservableField<String> = ObservableField("")
|
||||
var otp3: ObservableField<String> = ObservableField("")
|
||||
@@ -58,33 +55,31 @@ class SellMyFundViewModel : BaseViewModel() {
|
||||
}
|
||||
|
||||
fun fundRedeemApi() {
|
||||
_loader.value = true
|
||||
showProgress()
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
ApiUtils.fundRedeemApi(folioNumber, isin, accessToken, {
|
||||
_responseRedeem.setValue(it)
|
||||
_loader.value = false
|
||||
hideProgress()
|
||||
}, {
|
||||
_loader.value = false
|
||||
hideProgressAndShowError(it)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fun sendOTP(mobileVerificationResponse: MobileVerificationResponse) {
|
||||
_loader.value = true
|
||||
showProgress()
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
ApiUtils.initiateMobileVerification(mobileVerificationResponse, {
|
||||
_responseOTP.value = it
|
||||
_loader.value = false
|
||||
hideProgress()
|
||||
}) {
|
||||
_loader.value = false
|
||||
hideProgressAndShowError(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun otpVerify(transactionId: String?) {
|
||||
_loader.value = true
|
||||
showProgress()
|
||||
val userData = OTPBeam(
|
||||
transactionId = transactionId,
|
||||
otp = getEnteredOtp()
|
||||
@@ -93,20 +88,18 @@ class SellMyFundViewModel : BaseViewModel() {
|
||||
ApiUtils.redeemOtpVerification(userData, {
|
||||
_response.value = it
|
||||
}, {
|
||||
_loader.value = false
|
||||
hideProgressAndShowError(it)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fun reSendOTPApi(mobileVerificationResponse: MobileVerificationResponse) {
|
||||
_loader.value = true
|
||||
showProgress()
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
ApiUtils.initiateMobileVerification(mobileVerificationResponse, {
|
||||
_responseOTPResend.value = it
|
||||
_loader.value = false
|
||||
hideProgress()
|
||||
}) {
|
||||
_loader.value = false
|
||||
hideProgressAndShowError(it)
|
||||
}
|
||||
}
|
||||
@@ -122,9 +115,8 @@ class SellMyFundViewModel : BaseViewModel() {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
ApiUtils.createRedeemOrder(userData, accessToken, {
|
||||
_responseRedeemOrder.value = it
|
||||
_loader.value = false
|
||||
hideProgress()
|
||||
}, {
|
||||
_loader.value = false
|
||||
hideProgressAndShowError(it)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -52,6 +52,7 @@ class BuyingFlowSIPViewModel : BaseViewModel() {
|
||||
|
||||
|
||||
fun createLumpSumOrderApi() {
|
||||
showProgress()
|
||||
val userData = SipLumpsumResponse(
|
||||
amount = investmentamount.getString().removeComma().toDouble(),
|
||||
scheme = scheme,
|
||||
@@ -60,15 +61,15 @@ class BuyingFlowSIPViewModel : BaseViewModel() {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
ApiUtils.createLumpsumOrder(userData, {
|
||||
_orderResponse.value = it
|
||||
hideProgress()
|
||||
}) {
|
||||
hideProgressAndShowError(it)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun createSipOrderApi() {
|
||||
showProgress()
|
||||
val userData = ResponseSipBeam(
|
||||
sip_day = dayofinvestment.getString().toInt(),
|
||||
amount = investmentamount.getString().removeComma().toDouble(),
|
||||
@@ -77,14 +78,13 @@ class BuyingFlowSIPViewModel : BaseViewModel() {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
ApiUtils.createSipOrder(userData, accessToken, {
|
||||
_sipOrderResponse.value = it
|
||||
hideProgress()
|
||||
}) {
|
||||
hideProgressAndShowError(it)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun getBankDetailsApi() {
|
||||
showProgress()
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
@@ -94,7 +94,6 @@ class BuyingFlowSIPViewModel : BaseViewModel() {
|
||||
}) {
|
||||
hideProgressAndShowError(it)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,8 +107,6 @@ class BuyingFlowSIPViewModel : BaseViewModel() {
|
||||
}, {
|
||||
hideProgressAndShowError(it)
|
||||
})
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -51,9 +51,6 @@ class BuyingflowSIPActivity : BaseActivity<ActivityBuyingflowSipBinding, BuyingF
|
||||
private val isIn: String?
|
||||
get() = intent.getStringExtra(EXTRA_ID)
|
||||
|
||||
|
||||
private val progressDialog by lazy { CustomProgressDialog(this) }
|
||||
|
||||
override val layoutRes: Int
|
||||
get() = R.layout.activity_buyingflow_sip
|
||||
|
||||
@@ -268,7 +265,6 @@ class BuyingflowSIPActivity : BaseActivity<ActivityBuyingflowSipBinding, BuyingF
|
||||
|
||||
R.id.btnSelectBank -> {
|
||||
if (checkInternetSnackBar(this, binding.root)) {
|
||||
progressDialog.show()
|
||||
if (typeOfInvestment == "sip") {
|
||||
if (isValid()) {
|
||||
viewModel.createSipOrderApi()
|
||||
@@ -309,7 +305,6 @@ class BuyingflowSIPActivity : BaseActivity<ActivityBuyingflowSipBinding, BuyingF
|
||||
putExtra(EXTRA_ID, its.order_id.toString())
|
||||
putExtra(EXTRA_MESSAGE, fundType)
|
||||
})
|
||||
progressDialog.hide()
|
||||
}
|
||||
})
|
||||
// SIP order
|
||||
@@ -326,7 +321,6 @@ class BuyingflowSIPActivity : BaseActivity<ActivityBuyingflowSipBinding, BuyingF
|
||||
putExtra(EXTRA_ID, its.firstOrderId.toString())
|
||||
putExtra(EXTRA_MESSAGE, fundType)
|
||||
})
|
||||
progressDialog.hide()
|
||||
}
|
||||
})
|
||||
viewModel.naviFundsResponse.observe(this, {
|
||||
|
||||
Reference in New Issue
Block a user