Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate from JetPack Navigation to Compose Navigation #218

Merged
merged 31 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
0aa6160
Bump compile sdk and target sdk version to 34 and add navigation-comp…
sshropshire Nov 20, 2023
56d1f7a
Rename DemoActivity to main activity.
sshropshire Nov 20, 2023
4a4cf23
Rename DemoApplication to MainApplication.
sshropshire Nov 20, 2023
90b36e5
Remove Jetpack Navigation configuration from MainActivity.
sshropshire Nov 20, 2023
8893c88
Add compose navigation view.
sshropshire Nov 20, 2023
9bf5212
Add hilt navigation compose to project.
sshropshire Nov 20, 2023
6c9d2a7
Migrate test card approve order to Jetpack navigation compose.
sshropshire Nov 21, 2023
f013484
Remove ApproveOrderFragment.
sshropshire Nov 21, 2023
4c84553
Remove features fragment from project.
sshropshire Nov 21, 2023
e29e064
Add Card Vault destination to project.
sshropshire Nov 21, 2023
8a32081
Remove VaultCardFragment from project.
sshropshire Nov 21, 2023
ec25bfd
Add PayPalWebView and remove PayPalWebFragment.
sshropshire Nov 21, 2023
5c0fa4c
Add PayPalButtons view to compose navigation configuration.
sshropshire Nov 21, 2023
d1c87fa
Add PayPal Native flow to jetpack compose navigation configuration.
sshropshire Nov 21, 2023
1d1689e
Remove SelectCardFragment.
sshropshire Nov 21, 2023
9372529
Add onNewIntent override to MainActivity.
sshropshire Nov 21, 2023
a3c633c
Remove action bar.
sshropshire Nov 21, 2023
b404764
Add app bar to project.
sshropshire Nov 21, 2023
54f5fcd
Update title text based on current back stack entry destination.
sshropshire Nov 21, 2023
b79d10c
Conditionally add back button to app bar.
sshropshire Nov 21, 2023
c695de8
Revert build.gradle androidTargetVersion to 30.
sshropshire Nov 21, 2023
90a6f06
Clean up lint errors and unused imports.
sshropshire Nov 27, 2023
cc27fc0
Suppress long method lint error in Demo app until we find a better wa…
sshropshire Nov 27, 2023
4abdd24
Make code more DRY and extract NavDestinationChangeDisposableEffect.
sshropshire Nov 27, 2023
4ce593c
Fix lint errors.
sshropshire Nov 27, 2023
df70469
Fix package naming.
sshropshire Nov 27, 2023
c552ca4
Cleanup Android lint errors and remove unecessary resource files.
sshropshire Nov 27, 2023
92502d9
Remove old Jetpack navigation dependencies that are no longer used.
sshropshire Nov 27, 2023
857b81d
Add links to Jetpack compose sample repo maintained by Google.
sshropshire Nov 27, 2023
1b94367
Remove log statement.
sshropshire Nov 27, 2023
b83b79a
Cleanup unused import.
sshropshire Nov 27, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading