Skip to content

Commit ae9c180

Browse files
author
Martin Dinh
committed
Merge branch '21-replace-pwa-actions-with-js-handlers' into 'master'
Resolve "Replace PWA actions with JS handlers" Closes #21 See merge request pace/mobile/android/pace-cloud-sdk!34
2 parents 51e8541 + d0398ac commit ae9c180

File tree

16 files changed

+531
-920
lines changed

16 files changed

+531
-920
lines changed

library/src/main/java/cloud/pace/sdk/PACECloudSDK.kt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,11 @@ package cloud.pace.sdk
33
import android.content.Context
44
import cloud.pace.sdk.api.API
55
import cloud.pace.sdk.appkit.AppKit
6-
import cloud.pace.sdk.appkit.persistence.SharedPreferencesModel
7-
import cloud.pace.sdk.utils.CloudSDKKoinComponent
86
import cloud.pace.sdk.utils.Configuration
97
import cloud.pace.sdk.utils.KoinConfig
10-
import org.koin.core.inject
118

12-
object PACECloudSDK : CloudSDKKoinComponent {
9+
object PACECloudSDK {
1310

14-
private val sharedPreferencesModel: SharedPreferencesModel by inject()
1511
internal lateinit var configuration: Configuration
1612
var additionalQueryParams: Map<String, String> = mapOf()
1713

@@ -28,7 +24,6 @@ object PACECloudSDK : CloudSDKKoinComponent {
2824
AppKit.locationAccuracy = configuration.locationAccuracy
2925
KoinConfig.setupCloudSDK(context, configuration.environment, configuration.apiKey)
3026
AppKit.updateUserAgent()
31-
sharedPreferencesModel.deleteAllAppStates()
3227
}
3328

3429
/**

library/src/main/java/cloud/pace/sdk/appkit/app/AppActivity.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import android.content.Intent
44
import android.os.Bundle
55
import androidx.appcompat.app.AppCompatActivity
66
import cloud.pace.sdk.R
7-
import cloud.pace.sdk.appkit.app.webview.AppWebViewClient
87
import cloud.pace.sdk.appkit.communication.AppEventManager
98
import cloud.pace.sdk.appkit.communication.AppModel
109
import cloud.pace.sdk.utils.CloudSDKKoinComponent
@@ -62,7 +61,7 @@ class AppActivity : AppCompatActivity(), CloudSDKKoinComponent {
6261
val appLinkAction = intent.action
6362
val appLinkData = intent.data
6463
if (Intent.ACTION_VIEW == appLinkAction) {
65-
appLinkData?.getQueryParameter(AppWebViewClient.TO)?.let { finalRedirect ->
64+
appLinkData?.getQueryParameter(TO)?.let { finalRedirect ->
6665
eventManager.onReceivedRedirect(finalRedirect)
6766
}
6867
}
@@ -72,5 +71,6 @@ class AppActivity : AppCompatActivity(), CloudSDKKoinComponent {
7271
const val APP_URL = "APP_URL"
7372
const val BACK_TO_FINISH = "BACK_TO_FINISH"
7473
const val AUTO_CLOSE = "AUTO_CLOSE"
74+
const val TO = "to"
7575
}
7676
}

library/src/main/java/cloud/pace/sdk/appkit/app/AppFragment.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import android.view.ViewGroup
88
import androidx.browser.customtabs.CustomTabsIntent
99
import androidx.fragment.app.Fragment
1010
import cloud.pace.sdk.R
11-
import cloud.pace.sdk.appkit.app.webview.AppWebViewClient
1211
import cloud.pace.sdk.utils.CloudSDKKoinComponent
1312
import kotlinx.android.synthetic.main.fragment_app.*
1413
import org.koin.android.viewmodel.ext.android.viewModel
@@ -25,7 +24,7 @@ class AppFragment : Fragment(), CloudSDKKoinComponent {
2524
super.onViewCreated(view, savedInstanceState)
2625

2726
val url = activity?.intent?.extras?.getString(AppActivity.APP_URL)
28-
?: activity?.intent?.data?.getQueryParameter(AppWebViewClient.TO)
27+
?: activity?.intent?.data?.getQueryParameter(AppActivity.TO)
2928
?: throw RuntimeException("Missing app URL")
3029

3130
val autoClose = activity?.intent?.extras?.getBoolean(AppActivity.AUTO_CLOSE) ?: true

library/src/main/java/cloud/pace/sdk/appkit/app/api/UriManager.kt

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import java.util.regex.Pattern
88
interface UriManager {
99

1010
fun getStartUrls(baseUrl: String, manifestUrl: String, sdkStartUrl: String?, references: List<String>?): Map<String?, String>
11-
fun getURI(baseUrl: String, parameters: Map<String, String>): String
1211
fun buildUrl(baseUrl: String, path: String): String
1312
}
1413

@@ -51,14 +50,6 @@ class UriManagerImpl : UriManager {
5150
return baseUri.appendPath(path).build().toString()
5251
}
5352

54-
override fun getURI(baseUrl: String, parameters: Map<String, String>): String {
55-
val uriBuilder = Uri.parse(baseUrl).buildUpon()
56-
for (parameter in parameters) {
57-
uriBuilder.appendQueryParameter(parameter.key, parameter.value)
58-
}
59-
return uriBuilder.build().toString()
60-
}
61-
6253
companion object {
6354
const val PARAM_REFERENCES = "REFERENCES"
6455
const val PARAM_R = "r"

library/src/main/java/cloud/pace/sdk/appkit/app/drawer/AppDrawerViewModel.kt

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import java.net.URL
1414

1515
abstract class AppDrawerViewModel : ViewModel() {
1616

17+
abstract val url: LiveData<String>
1718
abstract val title: LiveData<String>
1819
abstract val subtitle: LiveData<String?>
1920
abstract val background: LiveData<Int>
@@ -29,6 +30,7 @@ abstract class AppDrawerViewModel : ViewModel() {
2930

3031
class AppDrawerViewModelImpl(private val eventManager: AppEventManager) : AppDrawerViewModel() {
3132

33+
override val url = MutableLiveData<String>()
3234
override val title = MutableLiveData<String>()
3335
override val subtitle = MutableLiveData<String?>()
3436
override val background = MutableLiveData<Int>()
@@ -37,19 +39,15 @@ class AppDrawerViewModelImpl(private val eventManager: AppEventManager) : AppDra
3739
override val logo = MutableLiveData<Bitmap>()
3840
override val closeEvent = MutableLiveData<Event<Unit>>()
3941

40-
private var url: String? = null
41-
private var initialTitle: String? = null
42-
private var initialSubtitle: String? = null
43-
4442
private val invalidAppsObserver = Observer<List<String>> {
45-
if (it.contains(url)) {
43+
if (it.contains(url.value)) {
4644
closeEvent.value = Event(Unit)
4745
}
4846
}
4947

5048
private val disabledHostObserver = Observer<String> {
5149
try {
52-
val host = URL(url).host
50+
val host = URL(url.value).host
5351
if (it == host) {
5452
closeEvent.value = Event(Unit)
5553
}
@@ -58,17 +56,8 @@ class AppDrawerViewModelImpl(private val eventManager: AppEventManager) : AppDra
5856
}
5957
}
6058

61-
private val buttonChangedObserver = Observer<AppEventManager.AppDrawerInfo> {
62-
if (url != it.url) return@Observer
63-
64-
title.value = it.title ?: initialTitle
65-
subtitle.value = it.subtitle ?: initialSubtitle
66-
}
67-
6859
override fun init(app: App, darkBackground: Boolean) {
69-
url = app.url
70-
initialTitle = app.name
71-
initialSubtitle = app.description
60+
url.value = app.url
7261
title.value = app.name
7362
subtitle.value = app.description
7463

@@ -111,13 +100,11 @@ class AppDrawerViewModelImpl(private val eventManager: AppEventManager) : AppDra
111100

112101
override fun onCreate() {
113102
eventManager.invalidApps.observeForever(invalidAppsObserver)
114-
eventManager.appDrawerInfo.observeForever(buttonChangedObserver)
115103
eventManager.disabledHost.observeForever(disabledHostObserver)
116104
}
117105

118106
override fun onDestroy() {
119107
eventManager.invalidApps.removeObserver(invalidAppsObserver)
120-
eventManager.appDrawerInfo.removeObserver(buttonChangedObserver)
121108
eventManager.disabledHost.removeObserver(disabledHostObserver)
122109
}
123110
}

0 commit comments

Comments
 (0)