Skip to content

Commit

Permalink
Merge pull request #412 from skedgo/feature/20495-server-booking-erro…
Browse files Browse the repository at this point in the history
…rs-handling

[20495] Handle outbound and return trip booking failures from server DRT. Revisit and revamp certain logics within the DRT feature.
  • Loading branch information
MichaelReyes authored Feb 29, 2024
2 parents e106bcc + c236468 commit 2b1ecdd
Show file tree
Hide file tree
Showing 23 changed files with 168 additions and 29 deletions.
4 changes: 4 additions & 0 deletions CommonCoreLegacy/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ android {
release {
consumerProguardFile 'proguard-rules.pro'
}
staging {
debuggable true
}
}

lintOptions {
Expand Down Expand Up @@ -71,6 +74,7 @@ dependencies {
implementation 'com.github.skedgo:commons-collections:v1.0'

debugImplementation project(':TripKitDomain')
stagingImplementation project(':TripKitDomain')
releaseImplementation project(':TripKitDomain')

implementation libs.kotlin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

import android.util.DisplayMetrics;

import com.skedgo.tripkit.configuration.Server;
import com.skedgo.tripkit.configuration.ServerManager;
import com.skedgo.tripkit.routing.ModeInfo;
import com.skedgo.tripkit.common.model.TransportMode;

public final class TransportModeUtils {
public static final String ICON_URL_TEMPLATE = Server.ApiTripGo.getValue() + "modeicons/android/%s/ic_transport_%s.png";
public static final String ICON_URL_TEMPLATE = ServerManager.INSTANCE.getConfiguration().getApiTripGoUrl() + "modeicons/android/%s/ic_transport_%s.png";

private TransportModeUtils() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,6 @@ val TripSegment.noActionAlerts
val TripSegment.actionAlert
get() =
alerts?.firstOrNull { it.alertAction() != null }

val TripSegment?.bookingHasConfirmation
get() = this?.booking?.confirmation?.status() != null
15 changes: 15 additions & 0 deletions TripKitAndroid/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ android {
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
staging {
debuggable true
}
}

packagingOptions {
// To avoid conflicts with ASL.
// We don't utilize ServiceLoader, so this is unneeded.
Expand Down Expand Up @@ -113,14 +119,23 @@ dependencies {
testImplementation libs.mockk

debugApi project(':CommonCoreLegacy')
stagingApi project(':CommonCoreLegacy')
releaseApi project(':CommonCoreLegacy')

debugApi project(':TripKitDomain')
stagingApi project(':TripKitDomain')
releaseApi project(':TripKitDomain')

debugApi project(':TripKitDomainLegacy')
stagingApi project(':TripKitDomainLegacy')
releaseApi project(':TripKitDomainLegacy')

debugApi project(':TripKitData')
stagingApi project(':TripKitData')
releaseApi project(':TripKitData')

debugApi project(':sqliteutils')
stagingApi project(':sqliteutils')
releaseApi project(':sqliteutils')
//api project(':SnapshotTaker') Uncomment when using in TripGo-v5

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ package com.skedgo.tripkit

import android.content.Context
import android.content.SharedPreferences
import android.webkit.URLUtil
import com.google.gson.Gson
import com.haroldadmin.cnradapter.NetworkResponseAdapterFactory
import com.skedgo.tripkit.configuration.AppVersionNameRepository
import com.skedgo.tripkit.configuration.GetAppVersion
import com.skedgo.tripkit.configuration.Server
import com.skedgo.tripkit.data.HttpClientCustomDataStore
import com.skedgo.tripkit.configuration.ServerManager
import com.skedgo.tripkit.data.regions.RegionService
import com.skedgo.tripkit.regionrouting.RegionRoutingRepository
import com.skedgo.tripkit.regionrouting.RegionRoutingApi
Expand Down Expand Up @@ -107,7 +105,7 @@ open class HttpClientModule(
@Provides
open fun retrofitBuilder(gson: Gson): Retrofit.Builder {
return Retrofit.Builder()
.baseUrl(Server.ApiTripGo.value)
.baseUrl(ServerManager.configuration.apiTripGoUrl)
.addCallAdapterFactory(NetworkResponseAdapterFactory())
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.addConverterFactory(GsonConverterFactory.create(gson))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.skedgo.tripkit.common.util.LowercaseEnumTypeAdapterFactory;
import com.skedgo.tripkit.bookingproviders.BookingResolver;
import com.skedgo.tripkit.bookingproviders.BookingResolverImpl;
import com.skedgo.tripkit.configuration.ServerManager;
import com.skedgo.tripkit.data.regions.RegionService;
import com.skedgo.tripkit.data.tsp.GsonAdaptersRegionInfo;
import com.skedgo.tripkit.tsp.GsonAdaptersRegionInfoBody;
Expand Down Expand Up @@ -43,7 +44,6 @@
import com.skedgo.tripkit.a2brouting.RouteService;
import com.skedgo.TripKit;
import com.skedgo.tripkit.configuration.AppVersionNameRepository;
import com.skedgo.tripkit.configuration.Server;

@Module
public class MainModule {
Expand All @@ -63,7 +63,7 @@ Configs configs() {
@Provides
RegionsApi getRegionsApi(OkHttpClient httpClient) {
return new Retrofit.Builder()
.baseUrl(Server.ApiTripGo.getValue())
.baseUrl(ServerManager.INSTANCE.getConfiguration().getApiTripGoUrl())
.addConverterFactory(GsonConverterFactory.create(Gsons.createForRegion()))
.addCallAdapterFactory(RxJava2CallAdapterFactory.createWithScheduler(Schedulers.io()))
.client(httpClient)
Expand Down Expand Up @@ -167,7 +167,7 @@ BookingResolver getBookingResolver() {
LocationInfoApi getLocationInfoApi(Gson gson, OkHttpClient httpClient) {
return new Retrofit.Builder()
/* This base url is ignored as the api relies on @Url. */
.baseUrl(Server.ApiTripGo.getValue())
.baseUrl(ServerManager.INSTANCE.getConfiguration().getApiTripGoUrl())
.addCallAdapterFactory(RxJava2CallAdapterFactory.createWithScheduler(Schedulers.io()))
.addConverterFactory(GsonConverterFactory.create(gson))
.client(httpClient)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import retrofit2.Retrofit
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
import retrofit2.converter.gson.GsonConverterFactory
import io.reactivex.schedulers.Schedulers
import com.skedgo.tripkit.configuration.Server
import com.skedgo.tripkit.configuration.ServerManager
import java.util.concurrent.TimeUnit

@Module
Expand All @@ -22,7 +22,7 @@ class A2bRoutingDataModule {
return Retrofit.Builder()
.addCallAdapterFactory(RxJava2CallAdapterFactory.createWithScheduler(Schedulers.io()))
.addConverterFactory(GsonConverterFactory.create(gson))
.baseUrl(Server.ApiTripGo.value)
.baseUrl(ServerManager.configuration.apiTripGoUrl)
.client(client)
.build()
.create(A2bRoutingApi::class.java)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import io.reactivex.schedulers.Schedulers
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
import com.skedgo.tripkit.configuration.Server
import com.skedgo.tripkit.configuration.ServerManager

/**
* @suppress
Expand All @@ -27,7 +27,7 @@ class AnalyticsDataModule {
private fun reportingApi(gson: Gson, httpClient: OkHttpClient): MarkTripAsPlannedApi
= Retrofit.Builder()
/* This base url is ignored as the api relies on @Url. */
.baseUrl(Server.ApiTripGo.value)
.baseUrl(ServerManager.configuration.apiTripGoUrl)
.addCallAdapterFactory(RxJava2CallAdapterFactory.createWithScheduler(Schedulers.io()))
.addConverterFactory(GsonConverterFactory.create(gson))
.client(httpClient)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
package com.skedgo.tripkit.tsp;

import com.google.gson.Gson;
import com.skedgo.tripkit.configuration.ServerManager;

import dagger.Module;
import dagger.Provides;
import io.reactivex.schedulers.Schedulers;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
import com.skedgo.tripkit.configuration.Server;

@Module
public class TspModule {
@Provides RegionInfoApi regionInfoApi(
Gson gson,
okhttp3.OkHttpClient httpClient) {
return new Retrofit.Builder()
.baseUrl(Server.ApiTripGo.getValue())
.baseUrl(ServerManager.INSTANCE.getConfiguration().getApiTripGoUrl())
.client(httpClient)
.addConverterFactory(GsonConverterFactory.create(gson))
.addCallAdapterFactory(RxJava2CallAdapterFactory.createWithScheduler(Schedulers.io()))
Expand Down
14 changes: 14 additions & 0 deletions TripKitData/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ android {
}
}

buildTypes {
staging {
debuggable true
}
}

lintOptions {
// Changing to warning because of https://github.com/square/okio/issues/58.
warning "InvalidPackage"
Expand Down Expand Up @@ -59,12 +65,19 @@ dependencies {
implementation 'com.github.skedgo:commons-collections:v1.0'

debugImplementation project(":CommonCoreLegacy")
stagingImplementation project(":CommonCoreLegacy")
releaseImplementation project(":CommonCoreLegacy")

debugImplementation project(":TripKitDomain")
stagingImplementation project(":TripKitDomain")
releaseImplementation project(":TripKitDomain")

debugImplementation project(":TripKitDomainLegacy")
stagingImplementation project(":TripKitDomainLegacy")
releaseImplementation project(":TripKitDomainLegacy")

debugApi project(":route-persistence")
stagingApi project(":route-persistence")
releaseApi project(":route-persistence")

implementation libs.dagger
Expand Down Expand Up @@ -115,6 +128,7 @@ dependencies {
compileOnly 'com.github.pengrad:jdk9-deps:1.0'

debugApi project(':sqliteutils')
stagingApi project(':sqliteutils')
releaseApi project(':sqliteutils')
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import android.content.Context
import android.content.SharedPreferences
import com.skedgo.tripkit.account.domain.UserKeyRepository
import com.skedgo.tripkit.account.domain.UserTokenRepository
import com.skedgo.tripkit.configuration.Server
import com.skedgo.tripkit.configuration.ServerManager
import dagger.Module
import dagger.Provides
import io.reactivex.schedulers.Schedulers
Expand All @@ -26,15 +26,15 @@ class AccountDataModule {
httpClient: OkHttpClient, @Named(UserTokenPreferences) prefs: SharedPreferences
): UserTokenRepository {
val silentLoginApi = Retrofit.Builder()
.baseUrl(Server.ApiTripGo.value)
.baseUrl(ServerManager.configuration.apiTripGoUrl)
.addCallAdapterFactory(RxJava2CallAdapterFactory.createWithScheduler(Schedulers.io()))
.addConverterFactory(GsonConverterFactory.create())
.client(httpClient)
.build()
.create(SilentLoginApi::class.java)

val accountApi = Retrofit.Builder()
.baseUrl(Server.ApiTripGo.value)
.baseUrl(ServerManager.configuration.apiTripGoUrl)
.addCallAdapterFactory(RxJava2CallAdapterFactory.createWithScheduler(Schedulers.io()))
.addConverterFactory(GsonConverterFactory.create())
.client(httpClient)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,46 @@
package com.skedgo.tripkit.configuration

enum class Server(val value: String) {
enum class DefaultServer(val value: String) {
ApiTripGo("https://api.tripgo.com/v1/"),
// ApiTripGo("https://galaxies.skedgo.com/lab/beta/satapp/"),
// BigBang("https://bigbang.buzzhives.com/satapp/")
// BigBang("https://api-beta.tripgo.com/v1/")
BigBang("https://galaxies.skedgo.com/lab/beta/satapp/")
}

open class ServerConfiguration(
var apiTripGoUrl: String = DefaultServer.ApiTripGo.value,
var bigBangUrl: String = DefaultServer.BigBang.value
)

/**
* Singleton object that manages server configurations for the application.
*
* This manager allows for setting and retrieving server URLs throughout the application.
* It provides a centralized point of configuration, making it easy to adjust server URLs
* for different environments (e.g., development, staging, production) or build variants.
*
* Usage:
* - Access default server URLs via `ServerManager.configuration`.
* - Customize server URLs using `ServerManager.customizeConfiguration(...)`.
*
* Example:
* ```
* // Accessing default URLs
* val defaultApiUrl = ServerManager.configuration.apiTripGoUrl
* val defaultBigBangUrl = ServerManager.configuration.bigBangUrl
*
* // Customizing URLs
* ServerManager.customizeConfiguration(apiTripGoUrl = "https://api.newtripgo.com/v2/", bigBangUrl = "https://new.bigbang.url/")
* ```
*
* Note: Customizations to the server URLs should ideally be done during application initialization
* to ensure consistent use of the URLs throughout the application lifecycle.
*/
object ServerManager {

var configuration: ServerConfiguration = ServerConfiguration()

fun setCustomConfiguration(apiTripGoUrl: String? = null, bigBangUrl: String? = null) {
apiTripGoUrl?.let { configuration.apiTripGoUrl = it }
bigBangUrl?.let { configuration.bigBangUrl = it }
}

}
10 changes: 10 additions & 0 deletions TripKitDomainLegacy/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ android {
targetSdkVersion versions.targetSdkVersion
}

buildTypes {
staging {
debuggable true
}
}

lintOptions {
// Changing to warning because of https://github.com/square/okio/issues/58.
warning 'InvalidPackage'
Expand All @@ -39,9 +45,13 @@ android {
}

dependencies {

debugImplementation project(":TripKitDomain")
stagingImplementation project(":TripKitDomain")
releaseImplementation project(":TripKitDomain")

debugImplementation project(':CommonCoreLegacy')
stagingImplementation project(':CommonCoreLegacy')
releaseImplementation project(':CommonCoreLegacy')

implementation libs.dagger
Expand Down
3 changes: 3 additions & 0 deletions TripKitSamples/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ dependencies {

implementation libs.bindingCollectionAdapterRecyclerView
debugImplementation project(':TripKitAndroid')
stagingImplementation project(':TripKitAndroid')
releaseImplementation project(':TripKitAndroid')

debugImplementation project(':rxlifecyclecomponents')
stagingImplementation project(':rxlifecyclecomponents')
releaseImplementation project(':rxlifecyclecomponents')
}
9 changes: 9 additions & 0 deletions ValidBookingCountData/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ android {
targetSdkVersion versions.targetSdkVersion
}

buildTypes {
staging {
debuggable true
}
}

lintOptions {
// Changing to warning because of https://github.com/square/okio/issues/58.
warning 'InvalidPackage'
Expand Down Expand Up @@ -60,8 +66,11 @@ dependencies {

implementation libs.kotlin
debugImplementation project(':TripKitDomain')
stagingImplementation project(':TripKitDomain')
releaseImplementation project(':TripKitDomain')

debugImplementation project(':ValidBookingCountDomain')
stagingImplementation project(':ValidBookingCountDomain')
releaseImplementation project(':ValidBookingCountDomain')

implementation libs.javaxAnnotation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import retrofit2.Retrofit
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
import retrofit2.converter.gson.GsonConverterFactory
import io.reactivex.schedulers.Schedulers
import com.skedgo.tripkit.configuration.Server
import com.skedgo.tripkit.configuration.ServerManager
import com.skedgo.tripkit.validbookingcount.domain.ValidBookingCountRepository

@Module
Expand All @@ -19,7 +19,7 @@ class ValidBookingCountDataModule {
): ValidBookingCountRepository {
val api = Retrofit.Builder()
.client(httpClient)
.baseUrl(Server.ApiTripGo.value)
.baseUrl(ServerManager.configuration.apiTripGoUrl)
.addCallAdapterFactory(RxJava2CallAdapterFactory.createWithScheduler(Schedulers.io()))
.addConverterFactory(GsonConverterFactory.create())
.build()
Expand Down
Loading

0 comments on commit 2b1ecdd

Please sign in to comment.