Skip to content

Commit 17009b3

Browse files
committed
Bumped Kotlin Coroutine to 1.3.7 and removed workaround when downlading translations / SN
1 parent 22dbfdc commit 17009b3

File tree

11 files changed

+27
-40
lines changed

11 files changed

+27
-40
lines changed

app/src/main/kotlin/me/xizzhu/android/joshua/core/repository/StrongNumberRepository.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,6 @@ class StrongNumberRepository(private val localStrongNumberStorage: LocalStrongNu
6767
Log.i(TAG, "Strong number saved to database")
6868
val installFinished = elapsedRealtime()
6969

70-
offer(101)
71-
7270
Analytics.track(Analytics.EVENT_DOWNLOAD_STRONG_NUMBER, mapOf(
7371
Pair(Analytics.PARAM_DOWNLOAD_TIME, downloadFinished - start),
7472
Pair(Analytics.PARAM_INSTALL_TIME, installFinished - downloadFinished)

app/src/main/kotlin/me/xizzhu/android/joshua/core/repository/TranslationRepository.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,6 @@ class TranslationRepository(private val localTranslationStorage: LocalTranslatio
168168
return@synchronized Pair(available, downloaded)
169169
}
170170
notifyTranslationsUpdated(available, downloaded)
171-
172-
offer(101)
173171
}
174172

175173
@VisibleForTesting

app/src/main/kotlin/me/xizzhu/android/joshua/reading/ReadingViewModel.kt

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -276,14 +276,7 @@ class ReadingViewModel(
276276

277277
suspend fun readStrongNumber(verseIndex: VerseIndex): List<StrongNumber> = strongNumberManager.readStrongNumber(verseIndex)
278278

279-
fun downloadStrongNumber(): Flow<Int> =
280-
strongNumberManager.download()
281-
.map { progress ->
282-
// Ideally, we should use onCompletion() to handle this. However, it doesn't
283-
// distinguish between a successful completion and a cancellation.
284-
// See https://github.com/Kotlin/kotlinx.coroutines/issues/1693
285-
if (progress <= 100) progress else -1
286-
}
279+
fun downloadStrongNumber(): Flow<Int> = strongNumberManager.download()
287280

288281
fun startTracking() {
289282
readingProgressManager.startTracking()

app/src/main/kotlin/me/xizzhu/android/joshua/reading/detail/VerseDetailPresenter.kt

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,6 @@ class VerseDetailPresenter(
119119
downloadStrongNumberJob = viewModel.downloadStrongNumber()
120120
.onEach { progress ->
121121
when (progress) {
122-
-1 -> {
123-
activity.toast(R.string.toast_downloaded)
124-
verseDetail?.let {
125-
verseDetail = it.copy(strongNumberItems = viewModel.readStrongNumber(it.verseIndex).toStrongNumberItems())
126-
viewHolder.verseDetailViewLayout.setVerseDetail(verseDetail!!)
127-
}
128-
}
129122
in 0 until 100 -> {
130123
downloadStrongNumberDialog?.setProgress(progress)
131124
}
@@ -140,10 +133,18 @@ class VerseDetailPresenter(
140133
Log.e(tag, "Failed to download Strong's numberrs", e)
141134
activity.dialog(true, R.string.dialog_download_error,
142135
DialogInterface.OnClickListener { _, _ -> downloadStrongNumber() })
143-
}.onCompletion {
136+
}.onCompletion { e ->
144137
downloadStrongNumberDialog?.dismiss()
145138
downloadStrongNumberDialog = null
146139
downloadStrongNumberJob = null
140+
141+
if (e == null) {
142+
activity.toast(R.string.toast_downloaded)
143+
verseDetail?.let {
144+
verseDetail = it.copy(strongNumberItems = viewModel.readStrongNumber(it.verseIndex).toStrongNumberItems())
145+
viewHolder.verseDetailViewLayout.setVerseDetail(verseDetail!!)
146+
}
147+
}
147148
}.launchIn(coroutineScope)
148149
}
149150

app/src/main/kotlin/me/xizzhu/android/joshua/translations/TranslationListPresenter.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,6 @@ class TranslationListPresenter(
162162
downloadingJob = viewModel.downloadTranslation(translationToDownload)
163163
.onEach { progress ->
164164
when (progress) {
165-
-1 -> {
166-
activity.toast(R.string.toast_downloaded)
167-
loadTranslationList(false)
168-
}
169165
in 0 until 100 -> {
170166
downloadTranslationDialog?.setProgress(progress)
171167
}
@@ -180,10 +176,15 @@ class TranslationListPresenter(
180176
Log.e(tag, "Failed to download translation", e)
181177
activity.dialog(true, R.string.dialog_download_error,
182178
DialogInterface.OnClickListener { _, _ -> downloadTranslation(translationToDownload) })
183-
}.onCompletion {
179+
}.onCompletion { e ->
184180
downloadTranslationDialog?.dismiss()
185181
downloadTranslationDialog = null
186182
downloadingJob = null
183+
184+
if (e == null) {
185+
activity.toast(R.string.toast_downloaded)
186+
loadTranslationList(false)
187+
}
187188
}.launchIn(coroutineScope)
188189
}
189190

app/src/main/kotlin/me/xizzhu/android/joshua/translations/TranslationsViewModel.kt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,6 @@ class TranslationsViewModel(private val bibleReadingManager: BibleReadingManager
4545

4646
fun downloadTranslation(translationToDownload: TranslationInfo): Flow<Int> =
4747
translationManager.downloadTranslation(translationToDownload)
48-
.map { progress ->
49-
// Ideally, we should use onCompletion() to handle this. However, it doesn't
50-
// distinguish between a successful completion and a cancellation.
51-
// See https://github.com/Kotlin/kotlinx.coroutines/issues/1693
52-
if (progress <= 100) progress else -1
53-
}
5448

5549
fun removeTranslation(translationToRemove: TranslationInfo): Flow<Unit> = flow {
5650
emit(translationManager.removeTranslation(translationToRemove))

app/src/test/kotlin/me/xizzhu/android/joshua/core/repository/StrongNumberRepositoryTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ class StrongNumberRepositoryTest : BaseUnitTest() {
5656
var called = false
5757
strongNumberRepository.download(versesDownloadProgress, wordsDownloadProgress)
5858
.collect {
59-
assertTrue(it in (0..101))
60-
if (it == 101) called = true
59+
assertTrue(it in (0..100))
60+
if (it == 100) called = true
6161
}
6262
assertTrue(called)
6363
assertTrue(versesDownloadProgress.isClosedForSend && versesDownloadProgress.isClosedForReceive)

app/src/test/kotlin/me/xizzhu/android/joshua/core/repository/TranslationRepositoryTest.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package me.xizzhu.android.joshua.core.repository
1919
import kotlinx.coroutines.channels.Channel
2020
import kotlinx.coroutines.channels.consumeEach
2121
import kotlinx.coroutines.flow.first
22+
import kotlinx.coroutines.flow.toList
2223
import kotlinx.coroutines.launch
2324
import kotlinx.coroutines.test.runBlockingTest
2425
import me.xizzhu.android.joshua.core.TranslationInfo
@@ -234,7 +235,7 @@ class TranslationRepositoryTest : BaseUnitTest() {
234235
assertTrue(translationRepository.downloadedTranslations().first().isEmpty())
235236
assertEquals(setOf(MockContents.cuvTranslationInfo, MockContents.kjvTranslationInfo), translationRepository.availableTranslations().first().toSet())
236237

237-
assertEquals(101, translationRepository.downloadTranslation(MockContents.kjvTranslationInfo).first { it == 101 })
238+
assertTrue(translationRepository.downloadTranslation(MockContents.kjvTranslationInfo).toList().isEmpty())
238239
assertEquals(listOf(MockContents.cuvTranslationInfo), translationRepository.availableTranslations().first())
239240
assertEquals(listOf(MockContents.kjvDownloadedTranslationInfo), translationRepository.downloadedTranslations().first())
240241
}

app/src/test/kotlin/me/xizzhu/android/joshua/translations/TranslationsViewModelTest.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@ import kotlin.test.assertEquals
3232
class TranslationsViewModelTest : BaseUnitTest() {
3333
@Mock
3434
private lateinit var bibleReadingManager: BibleReadingManager
35+
3536
@Mock
3637
private lateinit var translationManager: TranslationManager
38+
3739
@Mock
3840
private lateinit var settingsManager: SettingsManager
3941

@@ -104,11 +106,10 @@ class TranslationsViewModelTest : BaseUnitTest() {
104106
fun testDownloadTranslation() = testDispatcher.runBlockingTest {
105107
`when`(bibleReadingManager.currentTranslation()).thenReturn(flowOf(""))
106108
val translationToDownload = MockContents.kjvTranslationInfo
107-
val progress = 89
108-
`when`(translationManager.downloadTranslation(translationToDownload)).thenReturn(flowOf(progress, 101))
109+
val progress = listOf(64, 89, 100)
110+
`when`(translationManager.downloadTranslation(translationToDownload)).thenReturn(progress.asFlow())
109111

110-
assertEquals(listOf(progress, -1),
111-
translationsViewModel.downloadTranslation(translationToDownload).toList())
112+
assertEquals(progress, translationsViewModel.downloadTranslation(translationToDownload).toList())
112113
verify(translationManager, times(1)).downloadTranslation(translationToDownload)
113114
}
114115

buildSrc/src/main/kotlin/Configurations.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ object Versions {
4949
object Kotlin {
5050
const val jvmTarget = "1.8"
5151
const val core = "1.3.72"
52-
const val coroutines = "1.3.5"
52+
const val coroutines = "1.3.7"
5353
}
5454

5555
object AndroidX {

docs/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ CHANGELOG
1515
- No longer needs ViewData
1616
- Updated dependencies:
1717
- Kotlin JVM target to 1.8
18-
- Kotlin to 1.3.72, Coroutine to 1.3.5
18+
- Kotlin to 1.3.72, Coroutine to 1.3.7
1919
- Gradle to 6.4.1
2020
- Android Gradle plugin to 3.6.3
2121
- Android build tools to 29.0.3

0 commit comments

Comments
 (0)