Skip to content

Commit

Permalink
Migrate from JetPack Navigation to Compose Navigation (#218)
Browse files Browse the repository at this point in the history
* Bump compile sdk and target sdk version to 34 and add navigation-compose dependency to demo app.

* Rename DemoActivity to main activity.

* Rename DemoApplication to MainApplication.

* Remove Jetpack Navigation configuration from MainActivity.

* Add compose navigation view.

* Add hilt navigation compose to project.

* Migrate test card approve order to Jetpack navigation compose.

* Remove ApproveOrderFragment.

* Remove features fragment from project.

* Add Card Vault destination to project.

* Remove VaultCardFragment from project.

* Add PayPalWebView and remove PayPalWebFragment.

* Add PayPalButtons view to compose navigation configuration.

* Add PayPal Native flow to jetpack compose navigation configuration.

* Remove SelectCardFragment.

* Add onNewIntent override to MainActivity.

* Remove action bar.

* Add app bar to project.

* Update title text based on current back stack entry destination.

* Conditionally add back button to app bar.

* Revert build.gradle androidTargetVersion to 30.

* Clean up lint errors and unused imports.

* Suppress long method lint error in Demo app until we find a better way to reduce line count of this composable.

* Make code more DRY and extract NavDestinationChangeDisposableEffect.

* Fix lint errors.

* Fix package naming.

* Cleanup Android lint errors and remove unecessary resource files.

* Remove old Jetpack navigation dependencies that are no longer used.

* Add links to Jetpack compose sample repo maintained by Google.

* Remove log statement.

* Cleanup unused import.
  • Loading branch information
sshropshire authored Nov 30, 2023
1 parent 0ab3d4b commit 227eed9
Show file tree
Hide file tree
Showing 34 changed files with 484 additions and 664 deletions.
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.

15 changes: 8 additions & 7 deletions Demo/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'androidx.navigation.safeargs.kotlin'
id 'kotlin-kapt'
id 'dagger.hilt.android.plugin'
id 'kotlin-parcelize'
Expand All @@ -11,12 +10,12 @@ plugins {
def paypalProperties = loadPropertiesFromFile("paypal.properties")

android {
compileSdkVersion 33
compileSdkVersion 34

defaultConfig {
applicationId "com.paypal.android"
minSdkVersion 21
targetSdkVersion 33
targetSdkVersion 34
versionCode modules.demoAppVersionCode
versionName modules.sdkVersionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand Down Expand Up @@ -117,7 +116,7 @@ dependencies {
implementation deps.fragmentKtx

// TODO: remove dependency when we don't relay on nxo models anymore
implementation (deps.nativeCheckout) {
implementation(deps.nativeCheckout) {
exclude module: 'data-collector'
}

Expand All @@ -138,8 +137,6 @@ dependencies {
implementation deps.lifecycleViewModelCompose
implementation deps.lifecycleRuntimeCompose

implementation deps.navigationFragment
implementation deps.navigationUI
implementation deps.preference

implementation deps.retrofit
Expand All @@ -149,6 +146,9 @@ dependencies {
implementation deps.hilt
kapt deps.hiltKapt

implementation deps.navigationCompose
implementation deps.hiltNavigationCompose

testImplementation deps.junit

androidTestImplementation deps.androidxJUnit
Expand All @@ -171,6 +171,7 @@ def loadPropertiesFromFile(filePath) {
def result = new Properties()
try {
result.load(new FileInputStream(rootProject.file(filePath)))
} catch (e) { /* ignored */ }
} catch (e) { /* ignored */
}
return result
}
2 changes: 1 addition & 1 deletion Demo/src/androidTest/java/com/paypal/android/CardTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import org.junit.runner.RunWith
class CardTest {

@get:Rule
val composeTestRule = createAndroidComposeRule<DemoActivity>()
val composeTestRule = createAndroidComposeRule<MainActivity>()

@Test
fun approveOrder() {
Expand Down
4 changes: 2 additions & 2 deletions Demo/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
android:supportsRtl="true"
android:theme="@style/Theme.AndroidSDK"
android:networkSecurityConfig="@xml/network_security_config"
android:name=".DemoApplication"
android:name=".MainApplication"
tools:ignore="MediaCapabilities,UnusedAttribute">
<activity
android:name=".DemoActivity"
android:name=".MainActivity"
android:exported="true"
android:launchMode="singleTop">
<intent-filter>
Expand Down
48 changes: 0 additions & 48 deletions Demo/src/main/java/com/paypal/android/DemoActivity.kt

This file was deleted.

28 changes: 28 additions & 0 deletions Demo/src/main/java/com/paypal/android/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.paypal.android

import android.content.Intent
import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.material3.ExperimentalMaterial3Api
import com.paypal.android.ui.DemoApp
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class MainActivity : AppCompatActivity() {

@ExperimentalMaterial3Api
@ExperimentalFoundationApi
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
DemoApp()
}
}

override fun onNewIntent(newIntent: Intent) {
super.onNewIntent(newIntent)
intent = newIntent
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ import android.app.Application
import dagger.hilt.android.HiltAndroidApp

@HiltAndroidApp
class DemoApplication : Application()
class MainApplication : Application()
192 changes: 191 additions & 1 deletion Demo/src/main/java/com/paypal/android/models/TestCard.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,201 @@ package com.paypal.android.models
import android.os.Parcelable
import com.paypal.android.cardpayments.Card
import com.paypal.android.ui.approveorder.CardFormatter
import com.paypal.android.ui.selectcard.SelectCardViewModel.Companion.validExpirationYear
import kotlinx.parcelize.IgnoredOnParcel
import kotlinx.parcelize.Parcelize

@Parcelize
data class TestCard(val name: String, val card: Card) : Parcelable {
data class TestCard(val id: String, val name: String, val card: Card) : Parcelable {

companion object {
val VISA_VAULT_WITH_PURCHASE_NO_3DS = TestCard(
id = "vault_with_purchase_no_3DS",
name = "🇺🇸 Vault with Purchase (no 3DS)",
card = Card(
number = "4000000000000002",
expirationMonth = "01",
expirationYear = validExpirationYear,
securityCode = "123"
),
)

val VISA_NO_3DS_1 = TestCard(
id = "visa_no_3DS_1",
name = "Visa",
card = Card(
number = "4111111111111111",
expirationMonth = "01",
expirationYear = validExpirationYear,
securityCode = "123"
)
)

val VISA_NO_3DS_2 = TestCard(
id = "visa_no_3DS_2",
name = "New Visa",
card = Card(
number = "4032035809742661",
expirationMonth = "09",
expirationYear = validExpirationYear,
securityCode = "655"
)
)

val VISA_3DS_SUCCESSFUL_AUTH = TestCard(
id = "visa_3DS_successful_auth",
name = "3DS Successful Auth",
card = Card(
number = "4000000000000002",
expirationMonth = "01",
expirationYear = validExpirationYear,
securityCode = "123"
),
)

val VISA_3DS_FAILED_SIGNATURE = TestCard(
id = "visa_3DS_failed_signature",
name = "3DS Failed Signature",
card = Card(
number = "4000000000000010",
expirationMonth = "01",
expirationYear = validExpirationYear,
securityCode = "123"
),
)

val VISA_3DS_FAILED_AUTHENTICATION = TestCard(
id = "visa_3DS_failed_authentication",
name = "3DS Failed Authentication",
card = Card(
number = "4000000000000028",
expirationMonth = "01",
expirationYear = validExpirationYear,
securityCode = "123"
),
)

val VISA_3DS_PASSIVE_AUTHENTICATION = TestCard(
id = "visa_3DS_passive_authentication",
name = "3DS Passive Authentication",
card = Card(
number = "4000000000000101",
expirationMonth = "01",
expirationYear = validExpirationYear,
securityCode = "123"
),
)

val VISA_3DS_TRANSACTION_TIMEOUT = TestCard(
id = "visa_3DS_transaction_timeout",
name = "3DS Transaction Timeout",
card = Card(
number = "4000000000000044",
expirationMonth = "01",
expirationYear = validExpirationYear,
securityCode = "123"
),
)

val VISA_3DS_NOT_ENROLLED = TestCard(
id = "visa_3DS_not_enrolled",
name = "3DS Not Enrolled",
card = Card(
number = "4000000000000051",
expirationMonth = "01",
expirationYear = validExpirationYear,
securityCode = "123"
),
)

val VISA_3DS_AUTH_SYSTEM_UNAVAILABLE = TestCard(
id = "visa_3DS_auth_system_unavailable",
name = "3DS Auth System Unavailable",
card = Card(
number = "4000000000000069",
expirationMonth = "01",
expirationYear = validExpirationYear,
securityCode = "123"
),
)

val VISA_3DS_AUTH_ERROR = TestCard(
id = "visa_3DS_auth_error",
name = "3DS Auth Error",
card = Card(
number = "4000000000000093",
expirationMonth = "01",
expirationYear = validExpirationYear,
securityCode = "123"
),
)

val VISA_3DS_AUTH_UNAVAILABLE = TestCard(
id = "visa_3DS_auth_unavailable",
name = "3DS Auth Unavailable",
card = Card(
number = "4000000000000036",
expirationMonth = "01",
expirationYear = validExpirationYear,
securityCode = "123"
),
)

val VISA_3DS_MERCHANT_BYPASSED_AUTH = TestCard(
id = "visa_3DS_merchant_bypassed_auth",
name = "3DS Merchant Bypassed Auth",
card = Card(
number = "4000990000000004",
expirationMonth = "01",
expirationYear = validExpirationYear,
securityCode = "123"
),
)

val VISA_3DS_MERCHANT_INACTIVE = TestCard(
id = "visa_3DS_merchant_inactive",
name = "3DS Merchant Inactive",
card = Card(
number = "4000000000000077",
expirationMonth = "01",
expirationYear = validExpirationYear,
securityCode = "123"
),
)

val VISA_3DS_CMPI_LOOKUP_ERROR = TestCard(
id = "visa_3DS_cmpi_lookup_error",
name = "3DS cmpi_lookup Error",
card = Card(
number = "4000000000000085",
expirationMonth = "01",
expirationYear = validExpirationYear,
securityCode = "123"
),
)

private val testCardMapById = mapOf(
VISA_VAULT_WITH_PURCHASE_NO_3DS.id to VISA_VAULT_WITH_PURCHASE_NO_3DS,
VISA_NO_3DS_1.id to VISA_NO_3DS_1,
VISA_NO_3DS_2.id to VISA_NO_3DS_2,
VISA_3DS_SUCCESSFUL_AUTH.id to VISA_3DS_SUCCESSFUL_AUTH,
VISA_3DS_FAILED_SIGNATURE.id to VISA_3DS_FAILED_SIGNATURE,
VISA_3DS_FAILED_AUTHENTICATION.id to VISA_3DS_FAILED_AUTHENTICATION,
VISA_3DS_PASSIVE_AUTHENTICATION.id to VISA_3DS_PASSIVE_AUTHENTICATION,
VISA_3DS_TRANSACTION_TIMEOUT.id to VISA_3DS_TRANSACTION_TIMEOUT,
VISA_3DS_NOT_ENROLLED.id to VISA_3DS_NOT_ENROLLED,
VISA_3DS_AUTH_SYSTEM_UNAVAILABLE.id to VISA_3DS_AUTH_SYSTEM_UNAVAILABLE,
VISA_3DS_AUTH_ERROR.id to VISA_3DS_AUTH_ERROR,
VISA_3DS_AUTH_UNAVAILABLE.id to VISA_3DS_AUTH_UNAVAILABLE,
VISA_3DS_MERCHANT_BYPASSED_AUTH.id to VISA_3DS_MERCHANT_BYPASSED_AUTH,
VISA_3DS_MERCHANT_INACTIVE.id to VISA_3DS_MERCHANT_INACTIVE,
VISA_3DS_CMPI_LOOKUP_ERROR.id to VISA_3DS_CMPI_LOOKUP_ERROR,
)

fun byId(testCardId: String): TestCard? {
return testCardMapById[testCardId]
}
}

@IgnoredOnParcel
val formattedCardNumber: String = CardFormatter.formatCardNumber(card.number)
Expand Down
Loading

0 comments on commit 227eed9

Please sign in to comment.