Skip to content

Commit

Permalink
MBL-1908 && MBL-1911: Migration to Apollo3 (#2182)
Browse files Browse the repository at this point in the history
  • Loading branch information
Arkariang authored Dec 2, 2024
1 parent 6996126 commit 91785ea
Show file tree
Hide file tree
Showing 87 changed files with 1,696 additions and 1,781 deletions.
24 changes: 15 additions & 9 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ buildscript {

dependencies {
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.9'
classpath 'com.apollographql.apollo:apollo-gradle-plugin:2.5.14'
classpath 'com.apollographql.apollo3:apollo-gradle-plugin:3.8.5'
classpath 'com.karumi:shot:5.13.0'
}
}
Expand All @@ -23,10 +23,11 @@ apply plugin: 'com.google.firebase.crashlytics'
apply plugin: 'com.google.firebase.firebase-perf'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-parcelize'
apply plugin: 'com.apollographql.apollo'
apply plugin: 'com.apollographql.apollo3'
apply plugin: 'jacoco'
apply from: 'quality.gradle'
apply from: "$project.rootDir/jacoco.gradle"
def apolloVersion = '3.8.5'

def externalPrivateVersion = new File(project.rootDir.path + "/app/external_version_code.txt").text.trim().toInteger()
def externalPublicVersion = new File(project.rootDir.path + "/app/external_version_name.txt").text.trim()
Expand Down Expand Up @@ -182,12 +183,12 @@ android {
}

apollo {
customTypeMapping = [
"Date" : "java.util.Date",
"Email": "java.lang.String",
"ISO8601DateTime" : "org.joda.time.DateTime",
"DateTime" : "org.joda.time.DateTime"
]
service("service") {
packageName.set("com.kickstarter") // -> Every generated files/classes by apollo will now live under the directory "com.kickstarter.*"
mapScalar("Date", "java.util.Date")
mapScalar("ISO8601DateTime", "org.joda.time.DateTime")
mapScalar("DateTime", "org.joda.time.DateTime")
}
}

repositories {
Expand Down Expand Up @@ -219,7 +220,12 @@ dependencies {

implementation 'com.android.support.constraint:constraint-layout:2.0.4'
implementation("androidx.core:core-splashscreen:1.0.1")
implementation 'com.apollographql.apollo:apollo-runtime:2.5.14'

implementation "com.apollographql.apollo3:apollo-adapters:$apolloVersion"
implementation "com.apollographql.apollo3:apollo-runtime:$apolloVersion"
// RxJava2 support
implementation "com.apollographql.apollo3:apollo-rx2-support:$apolloVersion"

implementation 'com.facebook.android:facebook-android-sdk:16.0.0'
implementation("com.google.android.play:review-ktx:2.0.1")
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
Expand Down
2 changes: 1 addition & 1 deletion app/internal_version_code.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2014150921
2014150925
2 changes: 1 addition & 1 deletion app/internal_version_name.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.26.2
3.28.0
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.kickstarter.screenshoot.testing.di

import android.app.Application
import androidx.annotation.NonNull
import com.apollographql.apollo.ApolloClient
import com.apollographql.apollo3.ApolloClient
import com.google.gson.Gson
import com.kickstarter.ApplicationModule
import com.kickstarter.libs.ApiEndpoint
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.kickstarter;

import com.apollographql.apollo.ApolloClient;
import com.apollographql.apollo3.ApolloClient;
import com.google.gson.Gson;
import com.kickstarter.libs.ApiEndpoint;
import com.kickstarter.libs.InternalToolsType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import android.content.SharedPreferences;

import com.apollographql.apollo.ApolloClient;
import com.apollographql.apollo3.ApolloClient;
import com.google.gson.Gson;
import com.kickstarter.libs.ApiEndpoint;
import com.kickstarter.libs.InternalTools;
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/graphql/checkout.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ mutation CompleteOnSessionCheckout($checkoutId: ID!, $paymentIntentClientSecret:
}
}

mutation completeOrder($projectId: ID!, $stripePaymentMethodId: String, $paymentSourceId: String, $paymentSourceReusable: Boolean, $paymentMethodTypes: [String!]) {
completeOrder(input:{stripePaymentMethodId: $stripePaymentMethodId, paymentSourceId: $paymentSourceId, paymentSourceReusable: $paymentSourceReusable, paymentMethodTypes: $paymentMethodTypes }) {
mutation completeOrder($orderId: ID!, $stripePaymentMethodId: String, $paymentSourceId: String, $paymentSourceReusable: Boolean, $paymentMethodTypes: [String!]) {
completeOrder(input:{orderId: $orderId, stripePaymentMethodId: $stripePaymentMethodId, paymentSourceId: $paymentSourceId, paymentSourceReusable: $paymentSourceReusable, paymentMethodTypes: $paymentMethodTypes }) {
status
clientSecret
}
Expand Down
12 changes: 6 additions & 6 deletions app/src/main/graphql/thirdPartyEvents.graphql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
mutation triggerThirdPartyEvent ($triggerThirdPartyEventInput: TriggerThirdPartyEventInput!) {
triggerThirdPartyEvent(input: $triggerThirdPartyEventInput) {
message
success
}
}
#mutation triggerThirdPartyEvent ($triggerThirdPartyEventInput: TriggerThirdPartyEventInput!) {
# triggerThirdPartyEvent(input: $triggerThirdPartyEventInput) {
# message
# success
# }
#}
17 changes: 8 additions & 9 deletions app/src/main/java/com/kickstarter/ApplicationModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
import android.content.res.AssetManager;
import android.content.res.Resources;

import com.apollographql.apollo.ApolloClient;
import com.apollographql.apollo3.ApolloClient;
import com.apollographql.apollo3.network.http.DefaultHttpEngine;
import com.google.firebase.analytics.FirebaseAnalytics;
import com.google.gson.FieldNamingPolicy;
import com.google.gson.Gson;
Expand Down Expand Up @@ -42,7 +43,6 @@
import com.kickstarter.libs.graphql.DateAdapter;
import com.kickstarter.libs.graphql.DateTimeAdapter;
import com.kickstarter.libs.graphql.Iso8601DateTimeAdapter;
import com.kickstarter.libs.graphql.EmailAdapter;
import com.kickstarter.libs.keystore.EncryptionEngine;
import com.kickstarter.libs.preferences.BooleanPreference;
import com.kickstarter.libs.preferences.BooleanPreferenceType;
Expand Down Expand Up @@ -72,6 +72,7 @@
import com.kickstarter.services.interceptors.GraphQLInterceptor;
import com.kickstarter.services.interceptors.KSRequestInterceptor;
import com.kickstarter.services.interceptors.WebRequestInterceptor;
import com.kickstarter.type.Date;
import com.kickstarter.ui.SharedPreferenceKey;
import com.stripe.android.PaymentConfiguration;
import com.stripe.android.Stripe;
Expand All @@ -97,7 +98,6 @@
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
import type.CustomType;

@Module
public class ApplicationModule {
Expand Down Expand Up @@ -200,13 +200,12 @@ static ApolloClient provideApolloClient(final @NonNull Build build, final @NonNu

final OkHttpClient okHttpClient = builder.build();

return ApolloClient.builder()
.addCustomTypeAdapter(CustomType.DATE, new DateAdapter())
.addCustomTypeAdapter(CustomType.EMAIL, new EmailAdapter())
.addCustomTypeAdapter(CustomType.ISO8601DATETIME, new Iso8601DateTimeAdapter())
.addCustomTypeAdapter(CustomType.DATETIME, new DateTimeAdapter())
return new ApolloClient.Builder()
.serverUrl(webEndpoint + "/graph")
.okHttpClient(okHttpClient)
.addCustomScalarAdapter(Date.Companion.getType(), new DateAdapter())
.addCustomScalarAdapter(com.kickstarter.type.DateTime.Companion.getType(), new DateTimeAdapter())
.addCustomScalarAdapter(com.kickstarter.type.ISO8601DateTime.Companion.getType(), new Iso8601DateTimeAdapter())
.httpEngine(new DefaultHttpEngine(okHttpClient))
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package com.kickstarter.features.pledgedprojectsoverview.data

import android.os.Parcelable
import com.kickstarter.features.pledgedprojectsoverview.ui.PPOCardViewType
import com.kickstarter.type.CurrencyCode
import kotlinx.parcelize.Parcelize
import type.CurrencyCode

@Parcelize
class PPOCard private constructor(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.kickstarter.features.pledgedprojectsoverview.data

import com.kickstarter.features.pledgedprojectsoverview.ui.PPOCardViewType
import type.CurrencyCode
import com.kickstarter.type.CurrencyCode

class PPOCardFactory private constructor() {
companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ fun PledgedProjectsOverviewScreen(
onProjectPledgeSummaryClick = { onProjectPledgeSummaryClick(it.backingDetailsUrl() ?: "") },
projectName = it.projectName(),
pledgeAmount = it.amount?.toDoubleOrNull()?.let { amount ->
RewardViewUtils.formatCurrency(amount, it.currencyCode?.rawValue(), it.currencySymbol)
RewardViewUtils.formatCurrency(amount, it.currencyCode?.rawValue, it.currencySymbol)
},
imageUrl = it.imageUrl(),
flags = it.flags,
Expand Down
22 changes: 12 additions & 10 deletions app/src/main/java/com/kickstarter/libs/graphql/DateAdapter.kt
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
package com.kickstarter.libs.graphql

import com.apollographql.apollo.api.CustomTypeAdapter
import com.apollographql.apollo.api.CustomTypeValue
import com.apollographql.apollo3.api.Adapter
import com.apollographql.apollo3.api.CustomScalarAdapters
import com.apollographql.apollo3.api.json.JsonReader
import com.apollographql.apollo3.api.json.JsonWriter
import java.text.ParseException
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale

class DateAdapter : CustomTypeAdapter<Date> {
class DateAdapter : Adapter<Date> {

private val DATE_FORMAT = SimpleDateFormat("yyyy-MM-dd", Locale.getDefault())

override fun encode(value: Date): CustomTypeValue<*> {
return CustomTypeValue.GraphQLString(DATE_FORMAT.format(value))
}

override fun decode(value: CustomTypeValue<*>): Date {
try {
return DATE_FORMAT.parse(value.value.toString())
override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): Date {
return try {
reader.nextString()?.let { DATE_FORMAT.parse(it) } ?: Date()
} catch (exception: ParseException) {
throw RuntimeException(exception)
}
}

override fun toJson(writer: JsonWriter, customScalarAdapters: CustomScalarAdapters, value: Date) {
writer.value(DATE_FORMAT.format(value))
}
}
28 changes: 18 additions & 10 deletions app/src/main/java/com/kickstarter/libs/graphql/DateTimeAdapter.kt
Original file line number Diff line number Diff line change
@@ -1,22 +1,30 @@
package com.kickstarter.libs.graphql

import com.apollographql.apollo.api.CustomTypeAdapter
import com.apollographql.apollo.api.CustomTypeValue
import com.apollographql.apollo3.api.Adapter
import com.apollographql.apollo3.api.CustomScalarAdapters
import com.apollographql.apollo3.api.json.JsonReader
import com.apollographql.apollo3.api.json.JsonWriter
import org.joda.time.DateTime
import org.joda.time.DateTimeZone
import java.text.ParseException

class DateTimeAdapter : CustomTypeAdapter<DateTime> {

override fun encode(value: DateTime): CustomTypeValue<*> {
return CustomTypeValue.GraphQLNumber(value.toString().toLong() / 1000L)
}
class DateTimeAdapter : Adapter<DateTime> {

override fun decode(value: CustomTypeValue<*>): DateTime {
override fun fromJson(
reader: JsonReader,
customScalarAdapters: CustomScalarAdapters
): DateTime {
try {
return DateTime(java.lang.Long.valueOf(value.value.toString().toLong() * 1000L), DateTimeZone.UTC)
return DateTime(java.lang.Long.valueOf(reader.nextString()!!.toLong() * 1000L), DateTimeZone.UTC)
} catch (exception: ParseException) {
throw RuntimeException(exception)
}
}

override fun toJson(
writer: JsonWriter,
customScalarAdapters: CustomScalarAdapters,
value: DateTime
) {
writer.value(value.toString().toLong() / 1000L)
}
}
14 changes: 0 additions & 14 deletions app/src/main/java/com/kickstarter/libs/graphql/EmailAdapter.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
package com.kickstarter.libs.graphql

import com.apollographql.apollo.api.CustomTypeAdapter
import com.apollographql.apollo.api.CustomTypeValue
import com.apollographql.apollo3.api.Adapter
import com.apollographql.apollo3.api.CustomScalarAdapters
import com.apollographql.apollo3.api.json.JsonReader
import com.apollographql.apollo3.api.json.JsonWriter
import org.joda.time.DateTime
import java.text.ParseException

class Iso8601DateTimeAdapter : CustomTypeAdapter<DateTime> {
class Iso8601DateTimeAdapter : Adapter<DateTime> {

override fun encode(value: DateTime): CustomTypeValue<*> {
return CustomTypeValue.GraphQLString(value.toString())
}

override fun decode(value: CustomTypeValue<*>): DateTime {
override fun fromJson(
reader: JsonReader,
customScalarAdapters: CustomScalarAdapters
): DateTime {
try {
return DateTime.parse(value.value.toString())
return DateTime.parse(reader.nextString())
} catch (exception: ParseException) {
throw RuntimeException(exception)
}
}

override fun toJson(
writer: JsonWriter,
customScalarAdapters: CustomScalarAdapters,
value: DateTime
) {
writer.value(value.toString())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ object AnalyticEventsUtils {
checkoutData.id()?.let { put("id", it.toString()) }
put(
"payment_type",
checkoutData.paymentType().rawValue().lowercase(Locale.getDefault())
checkoutData.paymentType().rawValue.lowercase(Locale.getDefault())
)
put("amount_total_usd", checkoutData.totalAmount(project.staticUsdRate()).round())
put("shipping_amount", checkoutData.shippingAmount())
Expand All @@ -73,7 +73,7 @@ object AnalyticEventsUtils {
checkoutData.id()?.let { put("id", it.toString()) }
put(
"payment_type",
checkoutData.paymentType().rawValue().lowercase(Locale.getDefault())
checkoutData.paymentType().rawValue.lowercase(Locale.getDefault())
)
put("amount_total_usd", checkoutData.totalAmount(project.staticUsdRate()).round())
put("shipping_amount", checkoutData.shippingAmount())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.kickstarter.libs.utils

import com.kickstarter.models.Reward
import com.kickstarter.type.CreditCardPaymentType
import com.kickstarter.ui.data.CheckoutData
import type.CreditCardPaymentType

/**
* Total count of selected add-ons (including multiple quantities of a single add-on)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import com.kickstarter.libs.utils.ListUtils
import com.kickstarter.models.Category
import com.kickstarter.models.User
import com.kickstarter.services.DiscoveryParams
import com.kickstarter.type.ProjectSort
import com.kickstarter.ui.adapters.data.NavigationDrawerData
import type.ProjectSort
import java.util.TreeMap

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import com.kickstarter.models.Urls
import com.kickstarter.models.User
import com.kickstarter.models.Web
import com.kickstarter.services.DiscoveryParams
import com.kickstarter.type.CreditCardTypes
import io.reactivex.Observable
import org.joda.time.DateTime
import org.joda.time.Duration
import type.CreditCardTypes
import kotlin.math.floor

/**
Expand Down Expand Up @@ -61,7 +61,7 @@ fun Project.showLatePledgeFlow() = this.isInPostCampaignPledgingPhase() ?: false
*
* @return boolean that represents if the card type is available
*/
fun Project.acceptedCardType(cardType: CreditCardTypes?) = this.availableCardTypes()?.contains(cardType?.rawValue()) ?: false
fun Project.acceptedCardType(cardType: CreditCardTypes?) = this.availableCardTypes()?.contains(cardType?.rawValue) ?: false

/**
* Combines each project in the list with the discovery param
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.kickstarter.mock.factories

import com.kickstarter.type.CreditCardPaymentType
import com.kickstarter.ui.data.CheckoutData
import type.CreditCardPaymentType

object CheckoutDataFactory {
@JvmStatic
Expand Down
Loading

0 comments on commit 91785ea

Please sign in to comment.