Skip to content

Commit f5d862e

Browse files
committed
Fix app not updating in background
Closes #38
1 parent 78606af commit f5d862e

File tree

4 files changed

+19
-9
lines changed

4 files changed

+19
-9
lines changed

app/src/main/java/com/melonhead/mangadexfollower/App.kt

+5-2
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,11 @@ class App: Application() {
5454
appContext.isInForeground = true
5555
appEventsRepository.postEvent(AppLifecycleEvent.AppForegrounded)
5656
Clog.i("Creating background task")
57-
val refreshWorkRequest = PeriodicWorkRequestBuilder<RefreshWorker>(15.minutes.toJavaDuration()).build()
58-
WorkManager.getInstance(this@App).enqueueUniquePeriodicWork("refresh-task", ExistingPeriodicWorkPolicy.KEEP, refreshWorkRequest)
57+
val refreshWorkRequest = PeriodicWorkRequestBuilder<RefreshWorker>(
58+
repeatInterval = 30.minutes.toJavaDuration(),
59+
flexTimeInterval = 15.minutes.toJavaDuration()
60+
).build()
61+
WorkManager.getInstance(this@App).enqueueUniquePeriodicWork("refresh-task", ExistingPeriodicWorkPolicy.UPDATE, refreshWorkRequest)
5962
}
6063

6164
override fun onStop(owner: LifecycleOwner) {

feature-authentication/src/main/java/com/melonhead/feature_authentication/di/FeatureAuthenticationModule.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ val FeatureAuthenticationModule = module {
2424
includes(DataAuthenticationModule)
2525
includes(DataUserModule)
2626

27-
single<AuthRepository> { AuthRepositoryImpl(get(), get(), get(), get(), get(), get(), get(), get()) }
27+
single<AuthRepository>(createdAtStart = true) { AuthRepositoryImpl(get(), get(), get(), get(), get(), get(), get(), get()) }
2828
single<LoginScreenResolver>(createdAtStart = true) { LoginScreenResolver() }
2929
}

lib-chapter-cache/src/main/java/com/melonhead/lib_chapter_cache/ChapterCache.kt

+6-5
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,14 @@ internal class ChapterCacheImpl(
9595
val downloadJob = async {
9696
try {
9797
val result = httpClient.downloadFile(pageFile, page)
98-
if (!result) {
98+
if (result) {
99+
Clog.i("Finished downloading page $i for ${mangaForChapter.chosenTitle} chapter $chapterTitle - $page")
100+
true
101+
} else {
99102
pageFile.delete()
100-
Clog.w("Error downloading page $i for ${mangaForChapter.chosenTitle} chapter ${chapter.chapterTitle} - $page")
101-
return@async false
103+
Clog.w("Failed to download page $i for ${mangaForChapter.chosenTitle} chapter ${chapter.chapterTitle} - $page")
104+
false
102105
}
103-
Clog.i("Finished downloading page $i for ${mangaForChapter.chosenTitle} chapter $chapterTitle - $page")
104-
true
105106
} catch (e: Exception) {
106107
Clog.w("Error downloading page $i for ${mangaForChapter.chosenTitle} chapter ${chapter.chapterTitle} - $page")
107108
Clog.e("Error downloading page", e)

lib-networking/src/main/java/com/melonhead/lib_networking/extensions/HttpClientExtensions.kt

+7-1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ suspend fun HttpClient.downloadFile(outputFile: File, url: String): Boolean {
6868
outputFile.appendBytes(bytes)
6969
}
7070
}
71-
return@execute httpResponse.contentLength() == outputFile.length()
71+
val sourceLength = httpResponse.contentLength()
72+
val fileLength = outputFile.length()
73+
if (sourceLength != fileLength) {
74+
Clog.w("Downloaded file size and source file size don't match. Source = $sourceLength, file = $fileLength")
75+
return@execute false
76+
}
77+
return@execute true
7278
}
7379
}

0 commit comments

Comments
 (0)