Skip to content

Commit

Permalink
Merge pull request #360 from gini/PIA-4595-extract-feedback-from-cleanup
Browse files Browse the repository at this point in the history
Pia 4595 extract feedback from cleanup
  • Loading branch information
abolfazlimahdi authored Oct 31, 2023
2 parents 8ffd440 + a32ba46 commit b7fd984
Show file tree
Hide file tree
Showing 8 changed files with 263 additions and 181 deletions.
1 change: 1 addition & 0 deletions RELEASE-ORDER.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ Release order for :bank-sdk:sdk 3.6.0:
3. :capture-sdk:sdk 3.6.0
4. :capture-sdk:default-network 3.6.0
5. :bank-sdk:sdk 3.6.0

Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import java.util.*

@OptIn(ExperimentalCoroutinesApi::class)
@RunWith(AndroidJUnit4::class)
class ExtractionFeedbackIntegrationTest {
class TransferSummaryIntegrationTest {

private lateinit var giniBankAPI: GiniBankAPI
private val moshi = Moshi.Builder().build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import com.google.android.material.textfield.TextInputLayout
import dagger.hilt.android.AndroidEntryPoint
import net.gini.android.bank.sdk.GiniBank
import net.gini.android.bank.sdk.exampleapp.R
import net.gini.android.bank.sdk.exampleapp.core.di.GiniCaptureNetworkServiceDebugDisabled
import net.gini.android.bank.sdk.exampleapp.core.di.GiniCaptureNetworkServiceDebugEnabled
import net.gini.android.bank.sdk.exampleapp.databinding.ActivityExtractionsBinding
import net.gini.android.capture.Amount
import net.gini.android.capture.AmountCurrency
Expand All @@ -31,7 +31,7 @@ import javax.inject.Inject
/**
* Displays the Pay5 extractions: paymentRecipient, iban, bic, amount and paymentReference.
*
* A menu item is added to send feedback.
* A menu item is added to send transfer summary.
*/

@AndroidEntryPoint
Expand All @@ -40,12 +40,20 @@ class ExtractionsActivity : AppCompatActivity(), ExtractionsAdapter.ExtractionsA

private var mExtractions: MutableMap<String, GiniCaptureSpecificExtraction> = hashMapOf()
private lateinit var mExtractionsAdapter: ExtractionsAdapter
@Inject @GiniCaptureNetworkServiceDebugDisabled

@Inject
@GiniCaptureNetworkServiceDebugEnabled
lateinit var defaultNetworkService: GiniCaptureDefaultNetworkService

// {extraction name} to it's {entity name}
private val editableSpecificExtractions = hashMapOf("paymentRecipient" to "companyname", "paymentReference" to "reference",
"paymentPurpose" to "text", "iban" to "iban", "bic" to "bic", "amountToPay" to "amount")
private val editableSpecificExtractions = hashMapOf(
"paymentRecipient" to "companyname",
"paymentReference" to "reference",
"paymentPurpose" to "text",
"iban" to "iban",
"bic" to "bic",
"amountToPay" to "amount"
)

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand All @@ -68,8 +76,8 @@ class ExtractionsActivity : AppCompatActivity(), ExtractionsAdapter.ExtractionsA
}

override fun onOptionsItemSelected(item: MenuItem): Boolean = when (item.itemId) {
R.id.feedback -> {
sendFeedbackAndClose(binding)
R.id.transfer_summary -> {
sendTransferSummaryAndClose(binding)
true
}

Expand Down Expand Up @@ -98,26 +106,32 @@ class ExtractionsActivity : AppCompatActivity(), ExtractionsAdapter.ExtractionsA
editableSpecificExtractions.forEach {
if (!mExtractions.containsKey(it.key)) {
mExtractions[it.key] = GiniCaptureSpecificExtraction(
it.key, "",
it.value, null, emptyList())
it.key, "", it.value, null, emptyList()
)
}
}

adapter = ExtractionsAdapter(getSortedExtractions(mExtractions), this@ExtractionsActivity, editableSpecificExtractions.keys.toList()).also {
adapter = ExtractionsAdapter(
getSortedExtractions(mExtractions),
this@ExtractionsActivity,
editableSpecificExtractions.keys.toList()
).also {
mExtractionsAdapter = it
}
setOnTouchListener { _, _ ->
performClick()
val inputMethodManager = getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager
val inputMethodManager =
getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager
inputMethodManager.hideSoftInputFromWindow(windowToken, 0)
}
}
}

private fun <T> getSortedExtractions(extractions: Map<String, T>): List<T> = extractions.toSortedMap().values.toList()
private fun <T> getSortedExtractions(extractions: Map<String, T>): List<T> =
extractions.toSortedMap().values.toList()

private fun sendFeedbackAndClose(binding: ActivityExtractionsBinding) {
// Feedback should be sent only for the user visible fields. Non-visible fields should be filtered out.
private fun sendTransferSummaryAndClose(binding: ActivityExtractionsBinding) {
// Transfer summary should be sent only for the user visible fields. Non-visible fields should be filtered out.
// In a real application the user input should be used as the new value.

var amount = mExtractions["amountToPay"]?.value ?: ""
Expand All @@ -131,10 +145,14 @@ class ExtractionsActivity : AppCompatActivity(), ExtractionsAdapter.ExtractionsA
amount = Amount.EMPTY.amountToPay()
}

GiniBank.releaseCapture(applicationContext, paymentRecipient, paymentReference, paymentPurpose, iban, bic, Amount(
BigDecimal(amount.removeSuffix(":EUR")), AmountCurrency.EUR)
GiniBank.sendTransferSummary(
paymentRecipient, paymentReference, paymentPurpose, iban, bic, Amount(
BigDecimal(amount.removeSuffix(":EUR")), AmountCurrency.EUR
)
)

GiniBank.releaseCapture(applicationContext)

finish()
}

Expand All @@ -151,25 +169,30 @@ class ExtractionsActivity : AppCompatActivity(), ExtractionsAdapter.ExtractionsA
companion object {
const val EXTRA_IN_EXTRACTIONS = "EXTRA_IN_EXTRACTIONS"

fun getStartIntent(context: Context, extractionsBundle: Map<String, GiniCaptureSpecificExtraction>): Intent =
Intent(context, ExtractionsActivity::class.java).apply {
putExtra(EXTRA_IN_EXTRACTIONS, Bundle().apply {
extractionsBundle.map { putParcelable(it.key, it.value) }
})
}
fun getStartIntent(
context: Context, extractionsBundle: Map<String, GiniCaptureSpecificExtraction>
): Intent = Intent(context, ExtractionsActivity::class.java).apply {
putExtra(EXTRA_IN_EXTRACTIONS, Bundle().apply {
extractionsBundle.map { putParcelable(it.key, it.value) }
})
}
}
}

private class ExtractionsAdapter(var extractions: List<GiniCaptureSpecificExtraction>,
var listener: ExtractionsAdapterInterface? = null,
val editableSpecificExtractions: List<String>) : RecyclerView.Adapter<ExtractionsViewHolder>() {
private class ExtractionsAdapter(
var extractions: List<GiniCaptureSpecificExtraction>,
var listener: ExtractionsAdapterInterface? = null,
val editableSpecificExtractions: List<String>
) : RecyclerView.Adapter<ExtractionsViewHolder>() {

interface ExtractionsAdapterInterface {
fun valueChanged(key: String, value: String)
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ExtractionsViewHolder {
val holder = ExtractionsViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.item_extraction, parent, false))
val holder = ExtractionsViewHolder(
LayoutInflater.from(parent.context).inflate(R.layout.item_extraction, parent, false)
)
holder.mTextValue.addTextChangedListener {
listener?.valueChanged(holder.mTextInputLayout.hint.toString(), it.toString())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/feedback"
android:id="@+id/transfer_summary"
android:title="@string/menu_item_feedback"
app:showAsAction="always" />
<item
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import net.gini.android.capture.Document
import net.gini.android.capture.GiniCaptureError
import net.gini.android.capture.internal.util.MimeType
import net.gini.android.capture.network.*
import org.junit.After
import org.junit.Assert
import org.junit.Before
import org.junit.Test
Expand All @@ -41,7 +40,7 @@ import kotlin.coroutines.resumeWithException
*/

@RunWith(AndroidJUnit4::class)
class ExtractionFeedbackIntegrationTest {
class TransferSummaryIntegrationTest {

private lateinit var networkService: GiniCaptureDefaultNetworkService
private lateinit var giniBankAPI: GiniBankAPI
Expand Down Expand Up @@ -103,12 +102,12 @@ class ExtractionFeedbackIntegrationTest {
// 3. Assuming the user saw the following extractions:
// amountToPay, iban, bic, paymentPurpose and paymentRecipient

// When releasing capture we need to provide the values the user has used for
// Before releasing capture we need to provide the values the user has used for
// creating the transaction.
// Supposing the user changed the amountToPay from "995.00:EUR" to "950.00:EUR"
// we need to pass in the changed value. For the other extractions we can pass in
// the original values since the user did not edit them.
GiniBank.releaseCapture(getApplicationContext(),
GiniBank.sendTransferSummary(
result.specificExtractions["paymentRecipient"]!!.value,
"", // Payment reference was not shown to the user and can be left empty
result.specificExtractions["paymentPurpose"]!!.value,
Expand All @@ -117,6 +116,10 @@ class ExtractionFeedbackIntegrationTest {
Amount(BigDecimal("950.00"), AmountCurrency.EUR)
)

// Now we can release capture
GiniBank.releaseCapture(getApplicationContext()
)

// Wait a little for the feedback sending to complete
delay(2_000)

Expand Down
Loading

0 comments on commit b7fd984

Please sign in to comment.