Skip to content

Commit

Permalink
Kotlin conversion: receipt (#1388)
Browse files Browse the repository at this point in the history
  • Loading branch information
rchtgpt committed Jul 12, 2023
1 parent 4075199 commit 6aed303
Show file tree
Hide file tree
Showing 6 changed files with 416 additions and 450 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.mifos.mobilewallet.mifospay.receipt

import okhttp3.ResponseBody
import org.mifos.mobilewallet.core.data.fineract.entity.accounts.savings.TransferDetail
import org.mifos.mobilewallet.core.domain.model.Transaction
import org.mifos.mobilewallet.mifospay.base.BasePresenter
import org.mifos.mobilewallet.mifospay.base.BaseView

/**
* Created by ankur on 06/June/2018
*/
interface ReceiptContract {
interface ReceiptView : BaseView<ReceiptPresenter?> {
fun showSnackbar(message: String?)
fun writeReceiptToPDF(responseBody: ResponseBody?, filename: String?)
fun hideProgressDialog()
fun showTransactionDetail(transaction: Transaction?)
fun showTransferDetail(transferDetail: TransferDetail?)
fun openPassCodeActivity()
}

interface ReceiptPresenter : BasePresenter {
fun downloadReceipt(transactionId: String?)
fun fetchTransaction(transactionId: Long)
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package org.mifos.mobilewallet.mifospay.receipt.presenter

import org.mifos.mobilewallet.core.base.UseCase.UseCaseCallback
import org.mifos.mobilewallet.core.base.UseCaseHandler
import org.mifos.mobilewallet.core.domain.usecase.account.DownloadTransactionReceipt
import org.mifos.mobilewallet.core.domain.usecase.account.FetchAccountTransaction
import org.mifos.mobilewallet.core.domain.usecase.account.FetchAccountTransfer
import org.mifos.mobilewallet.mifospay.base.BaseView
import org.mifos.mobilewallet.mifospay.data.local.PreferencesHelper
import org.mifos.mobilewallet.mifospay.receipt.ReceiptContract
import org.mifos.mobilewallet.mifospay.receipt.ReceiptContract.ReceiptView
import org.mifos.mobilewallet.mifospay.utils.Constants
import javax.inject.Inject

/**
* Created by ankur on 06/June/2018
*/
class ReceiptPresenter @Inject constructor(
private val mUseCaseHandler: UseCaseHandler,
private val preferencesHelper: PreferencesHelper
) : ReceiptContract.ReceiptPresenter {
private lateinit var mDownloadTransactionReceiptUseCase: DownloadTransactionReceipt
private lateinit var mFetchAccountTransfer: FetchAccountTransfer
private lateinit var mFetchAccountTransaction: FetchAccountTransaction
private lateinit var mReceiptView: ReceiptView
override fun attachView(baseView: BaseView<*>?) {
mReceiptView = baseView as ReceiptView
mReceiptView.setPresenter(this)
}

override fun downloadReceipt(transactionId: String?) {
mUseCaseHandler.execute(mDownloadTransactionReceiptUseCase,
DownloadTransactionReceipt.RequestValues(transactionId),
object : UseCaseCallback<DownloadTransactionReceipt.ResponseValue> {
override fun onSuccess(response: DownloadTransactionReceipt.ResponseValue) {
mReceiptView.writeReceiptToPDF(
response.responseBody,
Constants.RECEIPT + transactionId + Constants.PDF
)
}

override fun onError(message: String) {
mReceiptView.showSnackbar(Constants.ERROR_FETCHING_RECEIPT)
}
})
}

override fun fetchTransaction(transactionId: Long) {
val accountId = preferencesHelper.accountId
mUseCaseHandler.execute(mFetchAccountTransaction,
FetchAccountTransaction.RequestValues(accountId, transactionId),
object : UseCaseCallback<FetchAccountTransaction.ResponseValue> {
override fun onSuccess(response: FetchAccountTransaction.ResponseValue) {
mReceiptView.showTransactionDetail(response.transaction)
fetchTransfer(response.transaction.transferId)
}

override fun onError(message: String) {
if (message == Constants.UNAUTHORIZED_ERROR) {
mReceiptView.openPassCodeActivity()
} else {
mReceiptView.hideProgressDialog()
mReceiptView.showSnackbar("Error fetching Transaction")
}
}
}
)
}

fun fetchTransfer(transferId: Long) {
mUseCaseHandler.execute(mFetchAccountTransfer,
FetchAccountTransfer.RequestValues(transferId),
object : UseCaseCallback<FetchAccountTransfer.ResponseValue> {
override fun onSuccess(response: FetchAccountTransfer.ResponseValue) {
mReceiptView.showTransferDetail(response.transferDetail)
}

override fun onError(message: String) {
mReceiptView.hideProgressDialog()
mReceiptView.showSnackbar("Error fetching Account Transfer")
}
})
}
}
Loading

0 comments on commit 6aed303

Please sign in to comment.