8000 Bump retrofit and remove retrofitCoroutinesAdapter dependency (#1001) · wertgit/Android@17cfcb2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 17cfcb2

Browse files
authored
Bump retrofit and remove retrofitCoroutinesAdapter dependency (duckduckgo#1001)
* Bump kotlin and coroutine libraries * Bump retrofit version Remove retrofit-coroutine adapter library (deprecated: https://github.com/JakeWharton/retrofit2-kotlin-coroutines-adapter#kotlin-coroutine-adapter-deprecated) Adapt code to introduce suspend operator * bump coroutines version! * remove unnecessary annotations * Fixes compilation error due to DuplicateRelativeFileException * fix failing test related to withTimeoutOrNull (Job has not completed yet)
1 parent 559ac56 commit 17cfcb2

File tree

10 files changed

+58
-55
lines changed

10 files changed

+58
-55
lines changed

app/build.gradle

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,13 @@ ext {
110110
legacySupport = "1.0.0"
111111
coreTesting = "2.1.0"
112112
testRunner = "1.3.0"
113-
coroutines = "1.3.5"
114-
retrofitCoroutinesAdapter = "0.9.2"
113+
coroutines = "1.4.2"
115114
webkit = "1.3.0"
116115
referrerLibrary = "1.1.2"
117116

118117
junit = "4.12"
119118
dagger = "2.27"
120-
retrofit = "2.8.1"
119+
retrofit = "2.9.0"
121120
ankoVersion = "0.10.4"
122121
glide = "4.11.0"
123122
lottieVersion = "3.4.0"
@@ -141,7 +140,12 @@ dependencies {
141140

142141
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
143142
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines"
144-
androidTestImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutines"
143+
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines"
144+
androidTestImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutines") {
145+
// https://github.com/Kotlin/kotlinx.coroutines/issues/2023
146+
// conflicts with mockito due to direct inclusion of byte buddy
147+
exclude group: "org.jetbrains.kotlinx", module: "kotlinx-coroutines-debug"
148+
}
145149

146150
implementation "androidx.appcompat:appcompat:$androidX"
147151
implementation "com.google.android.material:material:$materialDesign"
@@ -154,7 +158,6 @@ dependencies {
154158
implementation "com.squareup.retrofit2:converter-moshi:$retrofit"
155159
implementation "com.squareup.retrofit2:adapter-rxjava2:$retrofit"
156160
implementation "com.squareup.retrofit2:converter-scalars:$retrofit"
157-
implementation "com.jakewharton.retrofit:retrofit2-kotlin-coroutines-adapter:$retrofitCoroutinesAdapter"
158161
implementation "io.reactivex.rxjava2:rxjava:$rxJava"
159162
implementation "io.reactivex.rxjava2:rxandroid:$rxAndroid"
160163
implementation "com.jakewharton.timber:timber:$timber"

app/src/androidTest/java/com/duckduckgo/app/cta/ui/CtaViewModelTest.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -616,14 +616,13 @@ class CtaViewModelTest {
616616
givenOnboardingActive()
617617
db.tabsDao().insertTab(TabEntity(tabId = "0", position = 0))
618618
db.dismissedCtaDao().insert(DismissedCta(CtaId.DAX_DIALOG_TRACKERS_FOUND))
619+
db.tabsDao().insertTab(TabEntity(tabId = "1", position = 1))
620+
619621
val collector = launch {
620622
testee.showFireButtonPulseAnimation.collect {
621-
values.add(it)
623+
assertFalse(it)
622624
}
623625
}
624-
db.tabsDao().insertTab(TabEntity(tabId = "1", position = 1))
625-
626-
assertEquals(listOf(true, false), values)
627626
collector.cancel()
628627
}
629628

app/src/androidTest/java/com/duckduckgo/app/launch/LaunchViewModelTest.kt

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,11 @@ import com.duckduckgo.app.launch.LaunchViewModel.Command.Home
2323
import com.duckduckgo.app.launch.LaunchViewModel.Command.Onboarding
2424
import com.duckduckgo.app.onboarding.store.AppStage
2525
import com.duckduckgo.app.onboarding.store.UserStageStore
26-
import com.duckduckgo.app.referral.AppInstallationReferrerStateListener
27-
import com.duckduckgo.app.referral.ParsedReferrerResult
26+
import com.duckduckgo.app.referral.StubAppReferrerFoundStateListener
2827
import com.nhaarman.mockitokotlin2.mock
2928
import com.nhaarman.mockitokotlin2.verify
3029
import com.nhaarman.mockitokotlin2.whenever
3130
import kotlinx.coroutines.ExperimentalCoroutinesApi
32-
import kotlinx.coroutines.delay
3331
import kotlinx.coroutines.test.runBlockingTest
3432
import org.junit.After
3533
import org.junit.Rule
@@ -115,15 +113,4 @@ class LaunchViewModelTest {
115113
testee.determineViewToShow()
116114
verify(mockCommandObserver).onChanged(any(Home::class.java))
117115
}
118-
119-
class StubAppReferrerFoundStateListener(private val referrer: String, private val mockDelayMs: Long = 0) : AppInstallationReferrerStateListener {
120-
override suspend fun waitForReferrerCode(): ParsedReferrerResult {
121-
if (mockDelayMs > 0) delay(mockDelayMs)
122-
123-
return ParsedReferrerResult.CampaignReferrerFound(referrer)
124-
}
125-
126-
override fun initialiseReferralRetrieval() {
127-
}
128-
}
129116
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright (c) 2021 DuckDuckGo
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.duckduckgo.app.referral
18+
19+
import kotlinx.coroutines.delay
20+
21+
class StubAppReferrerFoundStateListener(private val referrer: String, private val mockDelayMs: Long = 0) : AppInstallationReferrerStateListener {
22+
override suspend fun waitForReferrerCode(): ParsedReferrerResult {
23+
if (mockDelayMs > 0) delay(mockDelayMs)
24+
25+
return ParsedReferrerResult.CampaignReferrerFound(referrer)
26+
}
27+
28+
override fun initialiseReferralRetrieval() {
29+
}
30+
}

app/src/androidTest/java/com/duckduckgo/app/statistics/AtbInitializerTest.kt

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,15 @@
1717
package com.duckduckgo.app.statistics
1818

1919
import com.duckduckgo.app.referral.AppInstallationReferrerStateListener
20-
import com.duckduckgo.app.referral.ParsedReferrerResult
20+
import com.duckduckgo.app.referral.StubAppReferrerFoundStateListener
2121
import com.duckduckgo.app.statistics.api.StatisticsUpdater
2222
import com.duckduckgo.app.statistics.store.StatisticsDataStore
2323
import com.nhaarman.mockitokotlin2.mock
2424
import com.nhaarman.mockitokotlin2.verify
2525
import com.nhaarman.mockitokotlin2.whenever
2626
import kotlinx.coroutines.ExperimentalCoroutinesApi
27-
import kotlinx.coroutines.delay
2827
import kotlinx.coroutines.test.runBlockingTest
29-
import org.junit.Before
3028
import org.junit.Test
31-
import org.mockito.stubbing.Answer
3229

3330
@ExperimentalCoroutinesApi
3431
class AtbInitializerTest {
@@ -37,17 +34,13 @@ class AtbInitializerTest {
3734

3835
private val statisticsDataStore: StatisticsDataStore = mock()
3936
private val statisticsUpdater: StatisticsUpdater = mock()
40-
private val appReferrerStateListener: AppInstallationReferrerStateListener = mock()
41-
42-
@Before
43-
fun setup() {
44-
testee = AtbInitializer(statisticsDataStore, statisticsUpdater, appReferrerStateListener)
45-
}
37+
private lateinit var appReferrerStateListener: AppInstallationReferrerStateListener
4638

4739
@Test
4840
fun whenReferrerInformationInstantlyAvailableThenAtbInitialized() = runBlockingTest {
4941
whenever(statisticsDataStore.hasInstallationStatistics).thenReturn(false)
50-
whenever(appReferrerStateListener.waitForReferrerCode()).thenAnswer(referrerAnswer(0))
42+
appReferrerStateListener = StubAppReferrerFoundStateListener(referrer = "xx")
43+
testee = AtbInitializer(statisticsDataStore, statisticsUpdater, appReferrerStateListener)
5144

5245
testee.initializeAfterReferrerAvailable()
5346

@@ -57,7 +50,8 @@ class AtbInitializerTest {
5750
@Test
5851
fun whenReferrerInformationQuicklyAvailableThenAtbInitialized() = runBlockingTest {
5952
whenever(statisticsDataStore.hasInstallationStatistics).thenReturn(false)
60-
whenever(appReferrerStateListener.waitForReferrerCode()).thenAnswer(referrerAnswer(1000))
53+
appReferrerStateListener = StubAppReferrerFoundStateListener(referrer = "xx", mockDelayMs = 1000L)
54+
testee = AtbInitializer(statisticsDataStore, statisticsUpdater, appReferrerStateListener)
6155

6256
testee.initializeAfterReferrerAvailable()
6357

@@ -67,7 +61,8 @@ class AtbInitializerTest {
6761
@Test
6862
fun whenReferrerInformationTimesOutThenAtbInitialized() = runBlockingTest {
6963
whenever(statisticsDataStore.hasInstallationStatistics).thenReturn(false)
70-
whenever(appReferrerStateListener.waitForReferrerCode()).thenAnswer(referrerAnswer(Long.MAX_VALUE))
64+
appReferrerStateListener = StubAppReferrerFoundStateListener(referrer = "xx", mockDelayMs = Long.MAX_VALUE)
65+
testee = AtbInitializer(statisticsDataStore, statisticsUpdater, appReferrerStateListener)
7166

7267
testee.initializeAfterReferrerAvailable()
7368

@@ -77,17 +72,14 @@ class AtbInitializerTest {
7772
@Test
7873
fun whenAlreadyInitializedThenRefreshCalled() = runBlockingTest {
7974
configureAlreadyInitialized()
75+
testee = AtbInitializer(statisticsDataStore, statisticsUpdater, appReferrerStateListener)
76+
8077
testee.initializeAfterReferrerAvailable()
8178
verify(statisticsUpdater).refreshAppRetentionAtb()
8279
}
8380

84-
private suspend fun configureAlreadyInitialized() {
81+
private fun configureAlreadyInitialized() {
8582
whenever(statisticsDataStore.hasInstallationStatistics).thenReturn(true)
86-
whenever(appReferrerStateListener.waitForReferrerCode()).thenAnswer(referrerAnswer(0))
87-
}
88-
89-
private suspend fun referrerAnswer(delayMs: Long): Answer<ParsedReferrerResult> {
90-
delay(delayMs)
91-
return Answer { ParsedReferrerResult.CampaignReferrerFound("") }
83+
appReferrerStateListener = StubAppReferrerFoundStateListener(referrer = "xx")
9284
}
9385
}

app/src/main/java/com/duckduckgo/app/browser/BrowserTabViewModel.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,6 @@ class BrowserTabViewModel(
331331
browserViewState.value = currentBrowserViewState().copy(isFireproofWebsite = isFireproofWebsite())
332332
}
333333

334-
@ExperimentalCoroutinesApi
335334
private val fireButtonAnimation = Observer<Boolean> { shouldShowAnimation ->
336335
Timber.i("shouldShowAnimation $shouldShowAnimation")
337336
if (currentBrowserViewState().fireButton is FireButton.Visible) {
@@ -343,7 +342,6 @@ class BrowserTabViewModel(
343342
}
344343
}
345344

346-
@ExperimentalCoroutinesApi
347345
private fun registerAndScheduleDismissAction() {
348346
viewModelScope.launch(dispatchers.io()) {
349347
val fireButtonHighlightedEvent = userEventsStore.getUserEvent(UserEventKey.FIRE_BUTTON_HIGHLIGHTED)

app/src/main/java/com/duckduckgo/app/cta/ui/CtaViewModel.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ class CtaViewModel @Inject constructor(
100100
)
101101
}
102102

103-
@ExperimentalCoroutinesApi
104103
suspend fun dismissPulseAnimation() {
105104
withContext(dispatchers.io()) {
106105
dismissedCtaDao.insert(DismissedCta(CtaId.DAX_FIRE_BUTTON))
@@ -357,7 +356,6 @@ class CtaViewModel @Inject constructor(
357356
}
358357
}
359358

360-
@ExperimentalCoroutinesApi
361359
private fun forceStopFireButtonPulseAnimationFlow() = tabRepository.flowTabs.distinctUntilChanged()
362360
.map { tabs ->
363361
if (tabs.size >= MAX_TABS_OPEN_FIRE_EDUCATION) return@map true
@@ -378,7 +376,6 @@ class CtaViewModel @Inject constructor(
378376
}
379377
}.shouldShowPulseAnimation()
380378

381-
@ExperimentalCoroutinesApi
382379
private fun Flow<Pair<List<DismissedCta>, Boolean>>.shouldShowPulseAnimation(): Flow<Boolean> {
383380
return this.map { (dismissedCtaDao, forceStopAnimation) ->
384381
withContext(dispatchers.io()) {

app/src/main/java/com/duckduckgo/app/di/NetworkModule.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ import com.duckduckgo.app.surrogates.api.ResourceSurrogateListService
4040
import com.duckduckgo.app.survey.api.SurveyService
4141
import com.duckduckgo.app.trackerdetection.api.TrackerListService
4242
import com.duckduckgo.app.trackerdetection.db.TdsMetadataDao
43-
import com.jakewharton.retrofit2.adapter.kotlin.coroutines.CoroutineCallAdapterFactory
4443
import com.squareup.moshi.Moshi
4544
import dagger.Module
4645
import dagger.Provides
@@ -91,7 +90,6 @@ class NetworkModule {
9190
.client(okHttpClient)
9291
.addConverterFactory(ScalarsConverterFactory.create())
9392
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
94-
.addCallAdapterFactory(CoroutineCallAdapterFactory())
9593
.addConverterFactory(MoshiConverterFactory.create(moshi))
9694
.build()
9795
}

app/src/main/java/com/duckduckgo/app/feedback/api/FeedbackService.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package com.duckduckgo.app.feedback.api
1818

19-
import retrofit2.Call
2019
import retrofit2.http.Field
2120
import retrofit2.http.FormUrlEncoded
2221
import retrofit2.http.POST
@@ -25,7 +24,7 @@ interface FeedbackService {
2524

2625
@FormUrlEncoded
2726
@POST("/feedback.js?type=app-feedback")
28-
fun submitFeedback(
27+
suspend fun submitFeedback(
2928
@Field("reason") reason: String = REASON_GENERAL,
3029
@Field("rating") rating: String,
3130
@Field("category") category: String?,
@@ -38,7 +37,7 @@ interface FeedbackService {
3837
@Field("manufacturer") manufacturer: String,
3938
@Field("model") model: String,
4039
@Field("atb") atb: String
41-
): Call<Void>
40+
)
4241

4342
companion object {
4443
const val REASON_GENERAL = "general"

app/src/main/java/com/duckduckgo/app/feedback/api/FeedbackSubmitter.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class FireAndForgetFeedbackSubmitter(
112112
pixel.fire(pixelName)
113113
}
114114

115-
private fun submitFeedback(
115+
private suspend fun submitFeedback(
116116
openEnded: String,
117117
rating: String,
118118
category: String? = null,
@@ -132,7 +132,7 @@ class FireAndForgetFeedbackSubmitter(
132132
model = Build.MODEL,
133133
api = Build.VERSION.SDK_INT,
134134
atb = atbWithVariant()
135-
).execute()
135+
)
136136
}
137137

138138
private fun categoryFromMainReason(mainReason: MainReason): String {

0 commit comments

Comments
 (0)
0