Skip to content

Commit

Permalink
refactor: use dot getters and setters (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
merlinpaypal committed Oct 18, 2023
1 parent 4b33504 commit 84316bb
Show file tree
Hide file tree
Showing 17 changed files with 442 additions and 406 deletions.
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.

1 change: 1 addition & 0 deletions .idea/gradle.xml

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

1 change: 0 additions & 1 deletion .idea/misc.xml

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

10 changes: 5 additions & 5 deletions demo/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ dependencies {
implementation platform('org.jetbrains.kotlin:kotlin-bom:1.9.0')
implementation platform('androidx.compose:compose-bom:2023.09.00')
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.6.2'
implementation 'androidx.activity:activity-compose:1.7.2'
implementation 'androidx.compose.ui:ui:1.5.1'
implementation 'androidx.compose.ui:ui-graphics:1.5.1'
implementation 'androidx.compose.ui:ui-tooling-preview:1.5.1'
implementation 'androidx.activity:activity-compose:1.8.0'
implementation 'androidx.compose.ui:ui:1.5.2'
implementation 'androidx.compose.ui:ui-graphics:1.5.2'
implementation 'androidx.compose.ui:ui-tooling-preview:1.5.2'
implementation 'androidx.compose.material3:material3:1.1.2'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.appcompat:appcompat:1.6.1'
Expand All @@ -79,5 +79,5 @@ dependencies {
androidTestImplementation platform('androidx.compose:compose-bom:2023.09.00')
androidTestImplementation 'androidx.compose.ui:ui-test-junit4:1.5.1'
debugImplementation 'androidx.compose.ui:ui-tooling:1.5.1'
debugImplementation 'androidx.compose.ui:ui-test-manifest:1.5.1'
debugImplementation 'androidx.compose.ui:ui-test-manifest:1.5.2'
}
108 changes: 60 additions & 48 deletions demo/src/main/java/com/paypal/messagesdemo/XmlActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ import androidx.appcompat.app.AppCompatActivity
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.PayPalMessageEventsCallbacks
import com.paypal.messages.config.message.PayPalMessageStyle
import com.paypal.messages.config.message.PayPalMessageViewState
import com.paypal.messages.config.message.PayPalMessageViewStateCallbacks
import com.paypal.messages.config.message.style.PayPalMessageAlign
import com.paypal.messages.config.message.style.PayPalMessageColor
import com.paypal.messages.config.message.style.PayPalMessageLogoType
Expand All @@ -36,7 +38,7 @@ class XmlActivity : AppCompatActivity() {
val payPalMessage = binding.payPalMessage
val progressBar = binding.progressBar

val editedClientId: EditText? = findViewById<EditText>(R.id.clientId)
val editedClientId: EditText? = findViewById(R.id.clientId)

val logoTypeRadioGroup = findViewById<RadioGroup>(R.id.logoTypeRadioGroup)
logoTypeRadioGroup.setOnCheckedChangeListener { _, checkedId ->
Expand Down Expand Up @@ -96,8 +98,7 @@ class XmlActivity : AppCompatActivity() {
offerType = PayPalMessageOfferType.PAYPAL_CREDIT_NO_INTEREST
}

payPalMessage.setOfferType(offerType = offerType)

payPalMessage.offerType = offerType
}

shortTerm.setOnCheckedChangeListener { _, isChecked ->
Expand All @@ -116,8 +117,6 @@ class XmlActivity : AppCompatActivity() {
val amount = findViewById<EditText>(R.id.amount)
val buyerCountry = findViewById<EditText>(R.id.buyerCountry)
val stageTag = findViewById<EditText>(R.id.stageTag)


val ignoreCache = findViewById<SwitchMaterial>(R.id.ignoreCache)
val devTouchpoint = findViewById<SwitchMaterial>(R.id.devTouchpoint)

Expand All @@ -127,21 +126,21 @@ class XmlActivity : AppCompatActivity() {
Api.ignoreCache = ignoreCache.isChecked

if ( editedClientId?.text.toString().isNotBlank() ) {
payPalMessage.setClientId(editedClientId?.text.toString())
payPalMessage.clientId = editedClientId?.text.toString()
} else {
payPalMessage.setClientId("")
payPalMessage.clientId = ""
}

if ( amount?.text.toString().isNotBlank() ) {
payPalMessage.setAmount(amount?.text.toString().toDouble())
payPalMessage.amount = amount?.text.toString().toDouble()
} else {
payPalMessage.setAmount(null)
payPalMessage.amount = null
}

if ( buyerCountry?.text.toString().isNotBlank() ) {
payPalMessage.setBuyerCountry(buyerCountry?.text.toString())
payPalMessage.buyerCountry = buyerCountry?.text.toString()
} else {
payPalMessage.setBuyerCountry("US")
payPalMessage.buyerCountry = "US"
}

if ( color === PayPalMessageColor.WHITE ) {
Expand All @@ -156,7 +155,7 @@ class XmlActivity : AppCompatActivity() {
Api.stageTag = null
}

payPalMessage.setStyle(PayPalMessageStyle(textAlign = alignment, color = color, logoType = logoType))
payPalMessage.style = PayPalMessageStyle(textAlign = alignment, color = color, logoType = logoType)
payPalMessage.refresh()
}

Expand All @@ -178,42 +177,55 @@ class XmlActivity : AppCompatActivity() {

// Request message based on options
val submitButton = findViewById<Button>(R.id.submit)
submitButton.setOnClickListener {
updateMessageData()
}

// TODO add example of adding MessageView here instead of in XML
payPalMessage.setViewStates(
PayPalMessageViewState(
onLoading = {
Log.d(TAG, "onLoading")
progressBar.visibility = View.VISIBLE
resetButton.isEnabled = false
submitButton.isEnabled = false
Toast.makeText(this, "Loading Content...", Toast.LENGTH_SHORT).show()
},
onError = {
Log.d(TAG, "onError")
progressBar.visibility = View.INVISIBLE
runOnUiThread {
resetButton.isEnabled = true
submitButton.isEnabled = true
Toast.makeText(this, it.javaClass.toString() + ":" + it.message + ":" + it.paypalDebugId, Toast.LENGTH_LONG).show()
}
it.message?.let { it1 -> Log.d("XmlActivity Error", it1) }
it.paypalDebugId?.let { it1 -> Log.d("XmlActivity Error", it1) }
},
onSuccess = {
Log.d(TAG, "onSuccess")
progressBar.visibility = View.INVISIBLE
runOnUiThread {
resetButton.isEnabled = true
submitButton.isEnabled = true
Toast.makeText(this, "Success Getting Content", Toast.LENGTH_SHORT).show()
}
},
),
submitButton.setOnClickListener { updateMessageData() }

payPalMessage.viewStateCallbacks = PayPalMessageViewStateCallbacks(
onLoading = {
Log.d(TAG, "onLoading")
progressBar.visibility = View.VISIBLE
resetButton.isEnabled = false
submitButton.isEnabled = false
Toast.makeText(this, "Loading Content...", Toast.LENGTH_SHORT).show()
},
onError = {
Log.d(TAG, "onError")
progressBar.visibility = View.INVISIBLE
runOnUiThread {
resetButton.isEnabled = true
submitButton.isEnabled = true
Toast.makeText(this, it.javaClass.toString() + ":" + it.message + ":" + it.paypalDebugId, Toast.LENGTH_LONG).show()
}
it.message?.let { it1 -> Log.d("XmlActivity Error", it1) }
it.paypalDebugId?.let { it1 -> Log.d("XmlActivity Error", it1) }
},
onSuccess = {
Log.d(TAG, "onSuccess")
progressBar.visibility = View.INVISIBLE
runOnUiThread {
resetButton.isEnabled = true
submitButton.isEnabled = true
Toast.makeText(this, "Success Getting Content", Toast.LENGTH_SHORT).show()
}
},
)
}

/**
* Prevents unused warnings inside of PayPalMessageView and PayPalMessageConfig
*/
@Suppress("unused")
fun useUnusedFunctions() {
binding = ActivityMessageBinding.inflate(layoutInflater)
setContentView(binding.root)

val message = binding.payPalMessage
val config = PayPalMessageConfig()
config.setGlobalAnalytics("", "")
message.config = config

message.placement = ""
message.logoType = PayPalMessageLogoType.INLINE
message.alignment = PayPalMessageAlign.CENTER
message.eventsCallbacks = PayPalMessageEventsCallbacks()
}
}
128 changes: 128 additions & 0 deletions jacoco.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
apply plugin: 'jacoco'

jacoco {
toolVersion = "0.8.7"
}

project.afterEvaluate {
if (android.hasProperty("applicationVariants")) {
android.applicationVariants.all { variant ->
createVariantCoverage(variant)
}
}
else if (android.hasProperty("libraryVariants")) {
android.libraryVariants.all { variant ->
createVariantCoverage(variant)
}
}
}

ext.excludes = [
'**/databinding/*Binding.*',
'**/R.class',
'**/R$*.class',
'**/BuildConfig.*',
'**/Manifest*.*',
'**/*Test*.*',
'android/**/*.*',
// butterKnife
'**/*$ViewInjector*.*',
'**/*$ViewBinder*.*',
'**/Lambda$*.class',
'**/Lambda.class',
'**/*Lambda.class',
'**/*Lambda*.class',
'**/*_MembersInjector.class',
'**/Dagger*Component*.*',
'**/*Module_*Factory.class',
'**/di/module/*',
'**/*_Factory*.*',
'**/*Module*.*',
'**/*Dagger*.*',
'**/*Hilt*.*',
// kotlin
'**/*MapperImpl*.*',
'**/*$ViewInjector*.*',
'**/*$ViewBinder*.*',
'**/BuildConfig.*',
'**/*Component*.*',
'**/*BR*.*',
'**/Manifest*.*',
'**/*$Lambda$*.*',
'**/*Companion*.*',
'**/*Module*.*',
'**/*Dagger*.*',
'**/*Hilt*.*',
'**/*MembersInjector*.*',
'**/*_MembersInjector.class',
'**/*_Factory*.*',
'**/*_Provide*Factory*.*',
'**/*Extensions*.*'
]

def createVariantCoverage(variant) {
def variantName = variant.name
def testTaskName = "test${variantName.capitalize()}UnitTest"

// Add unit test coverage tasks
tasks.create(name: "${testTaskName}Coverage", type: JacocoReport, dependsOn: "$testTaskName") {
group = "Reporting"
description = "Generate Jacoco coverage reports for the ${variantName.capitalize()} build."

reports {
html.enabled = true
}

def javaClasses = fileTree(dir: variant.javaCompileProvider.get().destinationDir, excludes: project.excludes)
def kotlinClasses = fileTree(dir: "${buildDir}/tmp/kotlin-classes/${variantName}", excludes: project.excludes)
getClassDirectories().setFrom(files([javaClasses, kotlinClasses]))

getSourceDirectories().setFrom(files([
"$project.projectDir/library/src/main/java",
"$project.projectDir/library/src/${variantName}/java",
"$project.projectDir/library/src/main/kotlin",
"$project.projectDir/library/src/${variantName}/kotlin"
]))

getExecutionData().setFrom(files("${project.buildDir}/outputs/unit_test_code_coverage/${variantName}UnitTest/${testTaskName}.exec"))

doLast {
def m = new File("${project.buildDir}/reports/jacoco/${testTaskName}Coverage/html/index.html")
.text =~ /Total[^%]*>(\d?\d?\d?%)/
if (m) {
println "Test coverage: ${m[0][1]}"
}
}
}

// Add unit test coverage verification tasks
tasks.create(name: "${testTaskName}CoverageVerification", type: JacocoCoverageVerification, dependsOn: "${testTaskName}Coverage") {
group = "Reporting"
description = "Verifies Jacoco coverage for the ${variantName.capitalize()} build."
violationRules {
rule {
limit {
minimum = 0
}
}
rule {
element = 'BUNDLE'
limit {
counter = 'LINE'
value = 'COVEREDRATIO'
minimum = 0.30
}
}
}
def javaClasses = fileTree(dir: variant.javaCompileProvider.get().destinationDir, excludes: project.excludes)
def kotlinClasses = fileTree(dir: "${buildDir}/tmp/kotlin-classes/${variantName}", excludes: project.excludes)
getClassDirectories().setFrom(files([javaClasses, kotlinClasses]))
getSourceDirectories().setFrom(files([
"$project.projectDir/library/src/main/java",
"$project.projectDir/library/src/${variantName}/java",
"$project.projectDir/library/src/main/kotlin",
"$project.projectDir/library/src/${variantName}/kotlin"
]))
getExecutionData().setFrom(files("${project.buildDir}/outputs/unit_test_code_coverage/${variantName}UnitTest/${testTaskName}.exec"))
}
}

0 comments on commit 84316bb

Please sign in to comment.