Skip to content

Commit

Permalink
feat: debounce config updates (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
merlinpaypal committed Feb 26, 2024
1 parent acfc3ff commit 7d0a043
Show file tree
Hide file tree
Showing 16 changed files with 276 additions and 460 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,14 @@ jobs:
api-level: 23
target: google_apis
arch: x86_64
script: ./gradlew connectedCheck --info
script: ./gradlew connectedCheck --info | tee connectedCheck.log
continue-on-error: true

- name: Show Test XML
run: |
cat library/build/outputs/androidTest-results/connected/*.xml
mkdir -p library/build/outputs/androidTest-results/connected/logs
grep -E '(SUCCESS|FAILED|failed)' connectedCheck.log > library/build/outputs/androidTest-results/connected/logs/connectedCheck.xml
cat library/build/outputs/androidTest-results/connected/**/*.xml
echo ""
error_count=$(grep "<failure>" library/build/outputs/androidTest-results/connected/*.xml | wc -l | awk '{$1=$1};1')
error_count=$(grep -E '(FAILED|failed|failure)' library/build/outputs/androidTest-results/connected/**/*.xml | wc -l | awk '{$1=$1};1')
if [[ "$error_count" -ne "0" ]]; then echo "Tests failed. See above"; exit 1; fi
1 change: 1 addition & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

85 changes: 1 addition & 84 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 0 additions & 20 deletions .idea/gradle.xml

This file was deleted.

6 changes: 2 additions & 4 deletions demo/src/main/java/com/paypal/messagesdemo/JetpackActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class JetpackActivity : ComponentActivity() {
backgroundColor = if (messageColor === PayPalMessageColor.WHITE) Color.Black else Color.White
messageView.color = messageColor
messageView.logoType = messageLogo
messageView.alignment = messageAlignment
messageView.textAlign = messageAlignment

messageView.offerType = when (offerType) {
offerGroupOptions[0] -> PayPalMessageOfferType.PAY_LATER_SHORT_TERM
Expand All @@ -159,8 +159,6 @@ class JetpackActivity : ComponentActivity() {
Api.stageTag = stageTag
Api.ignoreCache = ignoreCache
Api.devTouchpoint = devTouchpoint

messageView.refresh()
}

fun resetButton() {
Expand All @@ -169,7 +167,7 @@ class JetpackActivity : ComponentActivity() {
messageAlignment = alignmentGroupOptions[0]

offerType = null
messageView.data.offerType = null
messageView.offerType = null

amount = ""
buyerCountry = ""
Expand Down
40 changes: 21 additions & 19 deletions demo/src/main/java/com/paypal/messagesdemo/XmlActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import com.paypal.messages.config.PayPalEnvironment
import com.paypal.messages.config.PayPalMessageOfferType
import com.paypal.messages.config.message.PayPalMessageConfig
import com.paypal.messages.config.message.PayPalMessageData
import com.paypal.messages.config.message.PayPalMessageEventsCallbacks
import com.paypal.messages.config.message.PayPalMessageStyle
import com.paypal.messages.config.message.PayPalMessageViewStateCallbacks
import com.paypal.messages.config.message.style.PayPalMessageAlign
import com.paypal.messages.config.message.style.PayPalMessageColor
Expand All @@ -25,9 +23,9 @@ import com.paypal.messagesdemo.databinding.ActivityMessageBinding
class XmlActivity : AppCompatActivity() {
private lateinit var binding: ActivityMessageBinding
private val TAG = "XmlActivity"
private var logoType: PayPalMessageLogoType = PayPalMessageLogoType.PRIMARY
private var color: PayPalMessageColor = PayPalMessageColor.BLACK
private var alignment: PayPalMessageAlign = PayPalMessageAlign.LEFT
private var logoType: PayPalMessageLogoType = PayPalMessageLogoType.PRIMARY
private var textAlign: PayPalMessageAlign = PayPalMessageAlign.LEFT
private var offerType: PayPalMessageOfferType? = null
private val environment = PayPalEnvironment.SANDBOX

Expand Down Expand Up @@ -106,7 +104,7 @@ class XmlActivity : AppCompatActivity() {

val alignmentRadioGroup = binding.alignmentRadioGroup
alignmentRadioGroup.setOnCheckedChangeListener { _, checkedId ->
alignment = when (checkedId) {
textAlign = when (checkedId) {
R.id.styleLeft -> PayPalMessageAlign.LEFT
R.id.styleCenter -> PayPalMessageAlign.CENTER
R.id.styleRight -> PayPalMessageAlign.RIGHT
Expand Down Expand Up @@ -153,14 +151,15 @@ class XmlActivity : AppCompatActivity() {
payPalMessage.setBackgroundColor(backgroundColor.hashCode())

// TODO: verify/fix offer type not working as expected
payPalMessage.data = PayPalMessageData(
clientId, amount = amount, buyerCountry = buyerCountry, offerType = offerType,
environment = environment,
)
payPalMessage.style = PayPalMessageStyle(
textAlign = alignment, color = color, logoType = logoType,
)
payPalMessage.refresh()
payPalMessage.clientID = clientId
payPalMessage.amount = amount
payPalMessage.buyerCountry = buyerCountry
payPalMessage.offerType = offerType
payPalMessage.environment = environment

payPalMessage.color = color
payPalMessage.logoType = logoType
payPalMessage.textAlign = textAlign
}

// Restore default options and reset UI
Expand Down Expand Up @@ -192,15 +191,18 @@ class XmlActivity : AppCompatActivity() {

val config = PayPalMessageConfig(data = PayPalMessageData(clientID = "someClientID"))
val message = PayPalMessageView(context = this, config = config)
message.getConfig()
message.setConfig(config)
config.setGlobalAnalytics("", "")
message.config = config
message.clientID = ""
message.buyerCountry = ""
message.merchantID = ""
message.partnerAttributionID = ""
message.placement = ""
message.logoType = PayPalMessageLogoType.INLINE
message.alignment = PayPalMessageAlign.CENTER
message.eventsCallbacks = PayPalMessageEventsCallbacks()
message.viewStateCallbacks = PayPalMessageViewStateCallbacks()
message.onClick = {}
message.onApply = {}
message.onLoading = {}
message.onSuccess = {}
message.onError = {}
EnvVars.getClientId(PayPalEnvironment.STAGE)
}
}
17 changes: 15 additions & 2 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ android {
targetSdkVersion modules.androidTargetVersion

versionCode modules.sdkVersionCode
versionName modules.sdkVersionName
versionName modules.sdkVersionName
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
testInstrumentationRunnerArguments clearPackageData: 'true'
consumerProguardFiles 'consumer-rules.pro'
Expand Down Expand Up @@ -64,6 +64,19 @@ android {
}
}

tasks.register('addPreCommitGitHookOnBuild') {
group 'git'
if (! project.file('../.git/hooks/pre-commit').exists()) {
println("⚈ ⚈ ⚈ Running Add Pre Commit Git Hook Script on Build ⚈ ⚈ ⚈")
exec {
commandLine("cp", "../scripts/pre-commit", "../.git/hooks")
}
println("✅ Added Pre Commit Git Hook Script.")
}
}

preBuild.doFirst { addPreCommitGitHookOnBuild }

tasks.withType(Test) {
useJUnitPlatform()
}
Expand Down Expand Up @@ -130,7 +143,7 @@ dependencies {
}

project.ext.name = "paypal-messages"
project.ext.version = modules.sdkVersionName
project.ext.version = modules.sdkVersionName
project.ext.pom_name = "PayPal Messages"
project.ext.pom_desc = "The PayPal Android SDK Messages Module: Promote offers to your customers such as Pay Later and PayPal Credit."

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import com.paypal.messages.config.message.PayPalMessageViewStateCallbacks
import com.paypal.messages.config.modal.ModalCloseButton
import com.paypal.messages.io.ApiMessageData
import com.paypal.messages.io.ApiResult
import org.junit.Assert.assertNull
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.runner.RunWith
Expand Down Expand Up @@ -82,12 +82,14 @@ class PayPalMessageViewTest {

payPalMessageView.onActionCompleted(ApiResult.Success(response))

val emptyFunction = fun () {}

config.data.amount = 200.00
config.viewStateCallbacks = PayPalMessageViewStateCallbacks(onLoading = fun () { "NOT_NULL" })
config.eventsCallbacks = PayPalMessageEventsCallbacks(onClick = fun () { "NOT_NULL" })
config.viewStateCallbacks = PayPalMessageViewStateCallbacks(onLoading = emptyFunction)
config.eventsCallbacks = PayPalMessageEventsCallbacks(onClick = emptyFunction)

assertTrue(payPalMessageView.config.data.amount!!.equals(100.00))
assertNull(payPalMessageView.config.viewStateCallbacks?.onLoading)
assertNull(payPalMessageView.config.eventsCallbacks?.onClick)
assertTrue(payPalMessageView.getConfig().data.amount!!.equals(100.00))
assertFalse(payPalMessageView.getConfig().viewStateCallbacks?.onLoading == emptyFunction)
assertFalse(payPalMessageView.getConfig().eventsCallbacks?.onClick == emptyFunction)
}
}

0 comments on commit 7d0a043

Please sign in to comment.