Skip to content

Commit

Permalink
Merge pull request #67 from TinkoffCreditSystems/2.5.0
Browse files Browse the repository at this point in the history
Android 12 support
  • Loading branch information
IlnarH authored Nov 12, 2021
2 parents 08f95f9 + 794bd6d commit e94931f
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 40 deletions.
7 changes: 7 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 2.5.0

#### Fixed
#### Changes
Android 12 support
#### Additions

## 2.4.3

#### Fixed
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION_NAME=2.4.3
VERSION_NAME=2.5.0
VERSION_CODE=15
GROUP=ru.tinkoff.acquiring

Expand Down
8 changes: 4 additions & 4 deletions gradle/versions.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ ext {
isRelease = project.hasProperty('release')
versionName = isRelease ? VERSION_NAME : "$VERSION_NAME-SNAPSHOT"

compileSdk = 29
minSdk = 19
targetSdk = 29
compileSdk = 31
minSdk = 21
targetSdk = 31
buildTools = '29.0.2'

kotlinVersion = '1.3.72'
Expand All @@ -16,7 +16,7 @@ ext {
lifecycleExtensionsVersion = '2.2.0'
cardIoVersion = '5.5.1'
gsonVersion = '2.8.6'
coreNfcVersion = '3.3.17'
coreNfcVersion = '1.0.2'
coroutinesVersion = '1.3.7'
googleWalletVersion = '18.0.0'
}
4 changes: 4 additions & 0 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ android {
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
Expand Down
3 changes: 2 additions & 1 deletion sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
<activity
android:name=".ui.MainActivity"
android:alwaysRetainTaskState="true"
android:clearTaskOnLaunch="false">
android:clearTaskOnLaunch="false"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,15 @@ object PaymentNotificationManager {
PaymentNotificationIntentService::class.java).apply {
action = ACTION_SELECT_PRICE + buttonPriceId
}
val flags = when {
Build.VERSION.SDK_INT < Build.VERSION_CODES.S -> PendingIntent.FLAG_UPDATE_CURRENT
else -> PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE
}
notificationLayout.setOnClickPendingIntent(buttonId, PendingIntent.getService(
activity,
0,
selectPriceIntent,
PendingIntent.FLAG_UPDATE_CURRENT))
flags))
}

val googlePayIntent = getGooglePayIntent(activity,
Expand Down
2 changes: 1 addition & 1 deletion ui/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "androidx.appcompat:appcompat:$appCompatVersion"
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycleExtensionsVersion"
implementation "ru.tinkoff.core:core-nfc:$coreNfcVersion"
implementation "ru.tinkoff.core.components.nfc:nfc:$coreNfcVersion"

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutinesVersion"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package ru.tinkoff.acquiring.sdk.cardscanners.ui

import android.app.Activity
import android.app.AlertDialog
import android.content.Intent
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
Expand All @@ -27,23 +28,36 @@ import android.view.WindowManager
import android.widget.Button
import android.widget.LinearLayout
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import ru.tinkoff.acquiring.sdk.R
import ru.tinkoff.acquiring.sdk.cardscanners.models.AsdkScannedCardData
import ru.tinkoff.acquiring.sdk.localization.AsdkLocalization
import ru.tinkoff.core.nfc.BaseNfcActivity
import ru.tinkoff.core.nfc.ImperfectAlgorithmException
import ru.tinkoff.core.nfc.MalformedDataException
import ru.tinkoff.core.components.nfc.NfcHelper
import ru.tinkoff.core.components.nfc.NfcUtils

/**
* @author Mariya Chernyadieva
*/
internal class AsdkNfcScanActivity : BaseNfcActivity() {
internal class AsdkNfcScanActivity : AppCompatActivity() {

private lateinit var nfcHelper: NfcHelper

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.acq_activity_nfc)

nfcHelper = NfcHelper.createAndRegisterObserver(this, object : NfcHelper.Callback {
override fun onResult(bundle: Bundle) =
onResult(bundle.getString(NfcHelper.CARD_NUMBER)!!, bundle.getString(NfcHelper.EXPIRY_DATE)!!)

override fun onException(p0: java.lang.Exception?) = onException()

override fun onNfcNotSupported() = onException()

override fun onNfcDisabled() = showDialog()
})

window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
setupTranslucentStatusBar()

Expand All @@ -57,7 +71,7 @@ internal class AsdkNfcScanActivity : BaseNfcActivity() {
applyBackgroundColor()
}

override fun onResult(cardNumber: String, expireDate: String) {
private fun onResult(cardNumber: String, expireDate: String) {
val card = AsdkScannedCardData(cardNumber, expireDate, "")
val intent = Intent()
intent.putExtra(EXTRA_CARD, card)
Expand All @@ -70,26 +84,6 @@ internal class AsdkNfcScanActivity : BaseNfcActivity() {
super.onBackPressed()
}

override fun onException(exception: Exception) {
onException()
}

override fun onClarifiedException(ex: MalformedDataException) {
onException()
}

override fun onClarifiedException(ex: ImperfectAlgorithmException) {
onException()
}

override fun getNfcDisabledDialogMessage(): String {
return AsdkLocalization.resources.nfcDialogDisableTitle ?: getString(R.string.acq_nfc_need_enable)
}

override fun getNfcDisabledDialogTitle(): String {
return AsdkLocalization.resources.nfcDialogDisableMessage ?: getString(R.string.acq_nfc_is_disable)
}

private fun setupTranslucentStatusBar() {
if (Build.VERSION.SDK_INT in 19..20) {
window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
Expand All @@ -115,11 +109,23 @@ internal class AsdkNfcScanActivity : BaseNfcActivity() {
finish()
}

private fun showDialog() {
AlertDialog.Builder(this)
.setTitle(AsdkLocalization.resources.nfcDialogDisableMessage ?: getString(R.string.acq_nfc_is_disable))
.setMessage(AsdkLocalization.resources.nfcDialogDisableMessage ?: getString(R.string.acq_nfc_is_disable))
.setPositiveButton(android.R.string.ok) { _, _ ->
NfcUtils.openNfcSettingsForResult(this, REQUEST_CODE_SETTINGS)
}.setNegativeButton(android.R.string.cancel) { _, _ -> finish() }
.show()
}

companion object {

const val EXTRA_CARD = "card_extra"
const val RESULT_ERROR = 256

const val REQUEST_CODE_SETTINGS = 0

private const val ALPHA_MASK = -0x33000001
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import android.app.Activity
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.os.Build
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.NotificationManagerCompat
Expand Down Expand Up @@ -99,19 +100,27 @@ internal class NotificationPaymentActivity : AppCompatActivity() {
}

if (requestCode != null && context is Activity) {
val flags = when {
Build.VERSION.SDK_INT < Build.VERSION_CODES.S -> PendingIntent.FLAG_UPDATE_CURRENT
else -> PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE
}
val resultPendingIntent = context.createPendingResult(requestCode,
intent,
PendingIntent.FLAG_UPDATE_CURRENT)
flags)
intent.putExtra(EXTRA_PENDING_INTENT, resultPendingIntent)
}

val preferences = context.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE)
var pendingIntentCode = preferences.getInt(PREF_INTENT_COUNTER_KEY, START_COUNTER_VALUE)

val flags = when {
Build.VERSION.SDK_INT < Build.VERSION_CODES.S -> PendingIntent.FLAG_UPDATE_CURRENT
else -> PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE
}
val pendingIntent = PendingIntent.getActivity(context,
pendingIntentCode,
intent,
PendingIntent.FLAG_UPDATE_CURRENT)
flags)

pendingIntentCode = if (pendingIntentCode == Int.MAX_VALUE) START_COUNTER_VALUE else pendingIntentCode + 1
preferences.edit().putInt(PREF_INTENT_COUNTER_KEY, pendingIntentCode).apply()
Expand All @@ -129,7 +138,7 @@ internal class NotificationPaymentActivity : AppCompatActivity() {
dialogMessage = it.getString(STATE_DIALOG_MESSAGE, "")
}

paymentOptions = intent.getParcelableExtra(EXTRA_PAYMENT_OPTIONS) as PaymentOptions
paymentOptions = intent.getParcelableExtra<PaymentOptions>(EXTRA_PAYMENT_OPTIONS) as PaymentOptions
resultIntent = intent.getParcelableExtra(EXTRA_PENDING_INTENT) as PendingIntent?

AsdkLocalization.init(this, paymentOptions.features.localizationSource)
Expand All @@ -139,7 +148,9 @@ internal class NotificationPaymentActivity : AppCompatActivity() {
ViewModelProviderFactory(paymentOptions.features.handleErrorsInSdk,
sdk))[NotificationPaymentViewModel::class.java]

sendBroadcast(Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS))
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) {
sendBroadcast(Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS))
}

if (savedInstanceState == null) {
initPaymentScreen()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@

package ru.tinkoff.acquiring.sdk.ui.activities

import android.annotation.SuppressLint
import android.content.Intent
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.view.View
import androidx.lifecycle.Observer
Expand Down Expand Up @@ -170,11 +172,12 @@ internal class PaymentActivity : TransparentActivity() {
}
}

@SuppressLint("QueryPermissionsNeeded")
private fun openBankChooser(deepLink: String, banks: Set<Any?>?) {
var intent = Intent(Intent.ACTION_VIEW)
intent.data = Uri.parse(deepLink)

if (!banks.isNullOrEmpty()) {
if (!banks.isNullOrEmpty() && Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
val activities = packageManager.queryIntentActivities(intent, 0)
val supportedBanks = activities.filter { banks.contains(it.activityInfo.packageName) }
.map { it.activityInfo.packageName }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ internal class ThreeDsActivity : BaseAcquiringActivity() {
val dataBase64 = Base64.encodeToString(threeDsMethodData.toString().toByteArray(), Base64.DEFAULT).trim()
val params = "threeDSMethodData=${URLEncoder.encode(dataBase64, "UTF-8")}"

hiddenWebView.postUrl(response.threeDsMethodUrl, params.toByteArray())
hiddenWebView.postUrl(response.threeDsMethodUrl!!, params.toByteArray())
threeDSCompInd = THREE_DS_CALLED_FLAG
}

Expand Down Expand Up @@ -181,7 +181,7 @@ internal class ThreeDsActivity : BaseAcquiringActivity() {
"&TermUrl=${URLEncoder.encode(termUrl, "UTF-8")}"
}

wvThreeDs.postUrl(url, params.toByteArray())
wvThreeDs.postUrl(url!!, params.toByteArray())
}

private fun prepareCreqParams(): String {
Expand Down

0 comments on commit e94931f

Please sign in to comment.