diff --git a/demo/build.gradle b/demo/build.gradle index eb282d35..ba320754 100644 --- a/demo/build.gradle +++ b/demo/build.gradle @@ -71,8 +71,9 @@ dependencies { implementation 'androidx.constraintlayout:constraintlayout:2.1.4' implementation 'androidx.appcompat:appcompat:1.6.1' implementation project(':library') + implementation 'com.google.android.material:material:1.10.0' - testImplementation 'junit:junit:4.13.2' + testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.5' androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' androidTestImplementation platform('androidx.compose:compose-bom:2023.09.00') diff --git a/demo/src/main/java/com/paypal/messagesdemo/XmlActivity.kt b/demo/src/main/java/com/paypal/messagesdemo/XmlActivity.kt index 7b4362bd..95875bab 100644 --- a/demo/src/main/java/com/paypal/messagesdemo/XmlActivity.kt +++ b/demo/src/main/java/com/paypal/messagesdemo/XmlActivity.kt @@ -3,24 +3,30 @@ package com.paypal.messagesdemo import android.os.Bundle import android.util.Log import android.view.View +import android.widget.Button +import android.widget.EditText +import android.widget.RadioGroup import android.widget.Toast +import android.widget.ToggleButton import androidx.appcompat.app.AppCompatActivity -import com.paypal.messages.PayPalMessageView +import androidx.compose.ui.graphics.Color +import com.google.android.material.switchmaterial.SwitchMaterial 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.PayPalMessageEvents import com.paypal.messages.config.message.PayPalMessageStyle import com.paypal.messages.config.message.PayPalMessageViewState import com.paypal.messages.config.message.style.PayPalMessageAlign import com.paypal.messages.config.message.style.PayPalMessageColor import com.paypal.messages.config.message.style.PayPalMessageLogoType +import com.paypal.messages.io.Api import com.paypal.messagesdemo.databinding.ActivityMessageBinding -import com.paypal.messages.config.PayPalEnvironment as Environment 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 offerType: PayPalMessageOfferType? = null override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -29,23 +35,169 @@ class XmlActivity : AppCompatActivity() { val payPalMessage = binding.payPalMessage val progressBar = binding.progressBar - val reloadButton = binding.reloadButton - // TODO add example of adding MessageView here instead of in XML + val editedClientId: EditText? = findViewById(R.id.clientId) + + val logoTypeRadioGroup = findViewById(R.id.logoTypeRadioGroup) + logoTypeRadioGroup.setOnCheckedChangeListener { _, checkedId -> + logoType = when (checkedId) { + R.id.stylePrimary -> PayPalMessageLogoType.PRIMARY + R.id.styleInline -> PayPalMessageLogoType.INLINE + R.id.styleAlternative -> PayPalMessageLogoType.ALTERNATIVE + R.id.styleNone -> PayPalMessageLogoType.NONE + else -> PayPalMessageLogoType.PRIMARY + } + } + + val colorRadioGroup = findViewById(R.id.colorRadioGroup) + colorRadioGroup.setOnCheckedChangeListener { _, checkedId -> + color = when (checkedId) { + R.id.styleBlack -> PayPalMessageColor.BLACK + R.id.styleWhite -> PayPalMessageColor.WHITE + R.id.styleMonochrome -> PayPalMessageColor.MONOCHROME + R.id.styleGrayscale -> PayPalMessageColor.GRAYSCALE + else -> PayPalMessageColor.BLACK + } + } + + val alignmentRadioGroup = findViewById(R.id.alignmentRadioGroup) + alignmentRadioGroup.setOnCheckedChangeListener { _, checkedId -> + alignment = when (checkedId) { + R.id.styleLeft -> PayPalMessageAlign.LEFT + R.id.styleCenter -> PayPalMessageAlign.CENTER + R.id.styleRight -> PayPalMessageAlign.RIGHT + else -> PayPalMessageAlign.LEFT + } + } + + val shortTerm = findViewById(R.id.shortTerm) + val longTerm = findViewById(R.id.longTerm) + val payIn1 = findViewById(R.id.payIn1) + val credit = findViewById(R.id.credit) + + fun updateOfferUi (offerName: PayPalMessageOfferType?, isChecked: Boolean) { + shortTerm.isChecked = false + longTerm.isChecked = false + payIn1.isChecked = false + credit.isChecked = false + offerType = null + + if ( offerName == PayPalMessageOfferType.PAY_LATER_SHORT_TERM && isChecked) { + shortTerm.isChecked = true + offerType = PayPalMessageOfferType.PAY_LATER_SHORT_TERM + } else if ( offerName == PayPalMessageOfferType.PAY_LATER_LONG_TERM && isChecked) { + longTerm.isChecked = true + offerType = PayPalMessageOfferType.PAY_LATER_LONG_TERM + } else if ( offerName == PayPalMessageOfferType.PAY_LATER_PAY_IN_1 && isChecked) { + payIn1.isChecked = true + offerType = PayPalMessageOfferType.PAY_LATER_PAY_IN_1 + } else if ( offerName == PayPalMessageOfferType.PAYPAL_CREDIT_NO_INTEREST && isChecked) { + credit.isChecked = true + offerType = PayPalMessageOfferType.PAYPAL_CREDIT_NO_INTEREST + } + + payPalMessage.setOfferType(offerType = offerType) + + } + + shortTerm.setOnCheckedChangeListener { _, isChecked -> + updateOfferUi(PayPalMessageOfferType.PAY_LATER_SHORT_TERM, isChecked) + } + longTerm.setOnCheckedChangeListener { _, isChecked -> + updateOfferUi(PayPalMessageOfferType.PAY_LATER_LONG_TERM, isChecked) + } + payIn1.setOnCheckedChangeListener { _, isChecked -> + updateOfferUi(PayPalMessageOfferType.PAY_LATER_PAY_IN_1, isChecked) + } + credit.setOnCheckedChangeListener { _, isChecked -> + updateOfferUi(PayPalMessageOfferType.PAYPAL_CREDIT_NO_INTEREST, isChecked) + } + + val amount = findViewById(R.id.amount) + val buyerCountry = findViewById(R.id.buyerCountry) + val stageTag = findViewById(R.id.stageTag) + + + val ignoreCache = findViewById(R.id.ignoreCache) + val devTouchpoint = findViewById(R.id.devTouchpoint) + + // Get the data from the selected options + fun updateMessageData() { + Api.devTouchpoint = devTouchpoint.isChecked + Api.ignoreCache = ignoreCache.isChecked + + if ( editedClientId?.text.toString().isNotBlank() ) { + payPalMessage.setClientId(editedClientId?.text.toString()) + } else { + payPalMessage.setClientId("") + } + + if ( amount?.text.toString().isNotBlank() ) { + payPalMessage.setAmount(amount?.text.toString().toDouble()) + } else { + payPalMessage.setAmount(null) + } + if ( buyerCountry?.text.toString().isNotBlank() ) { + payPalMessage.setBuyerCountry(buyerCountry?.text.toString()) + } else { + payPalMessage.setBuyerCountry("US") + } + + if ( color === PayPalMessageColor.WHITE ) { + payPalMessage.setBackgroundColor(Color.Black.hashCode()) + } else { + payPalMessage.setBackgroundColor(Color.White.hashCode()) + } + + if ( stageTag?.text.toString().isNotBlank() ) { + Api.stageTag = stageTag?.text.toString() + } else { + Api.stageTag = null + } + + payPalMessage.setStyle(PayPalMessageStyle(textAlign = alignment, color = color, logoType = logoType)) + payPalMessage.refresh() + } + + // Restore default options + val resetButton = findViewById