Skip to content

Commit 4b8fe6d

Browse files
authored
Merge pull request #4130 from kiwix/Issue#4106
Fixed: Downloads were not automatically starting showing progress when reopening the app(If downloads paused due to any network error).
2 parents 0db479a + 1f55d95 commit 4b8fe6d

File tree

17 files changed

+571
-1024
lines changed

17 files changed

+571
-1024
lines changed

app/src/main/AndroidManifest.xml

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
android:name="android.permission.NEARBY_WIFI_DEVICES"
1313
android:usesPermissionFlags="neverForLocation"
1414
tools:targetApi="s" />
15+
<!-- Device with versions >= Pie need this permission -->
16+
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
17+
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />
1518

1619
<application
1720
android:name=".KiwixApp"

app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/OnlineLibraryFragment.kt

+4
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ class OnlineLibraryFragment : BaseFragment(), FragmentActivityExtensions {
148148
},
149149
{
150150
context?.let { context ->
151+
if (isNotConnected) {
152+
noInternetSnackbar()
153+
return@let
154+
}
151155
downloader.pauseResumeDownload(
152156
it.downloadId,
153157
it.downloadState.toReadableState(context).contains(getString(string.paused_state))

core/src/main/AndroidManifest.xml

+5-12
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,8 @@
1313
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
1414

1515
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
16-
<uses-permission
17-
android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" />
18-
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>
19-
<!-- Device with versions >= Pie need this permission -->
20-
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
21-
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />
16+
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
17+
2218
<queries>
2319
<intent>
2420
<action android:name="android.intent.action.TTS_SERVICE" />
@@ -52,8 +48,8 @@
5248

5349
<application
5450
android:allowBackup="true"
51+
android:dataExtractionRules="@xml/data_extraction_rules"
5552
android:fullBackupContent="@xml/backup_rules"
56-
android:dataExtractionRules = "@xml/data_extraction_rules"
5753
android:hardwareAccelerated="true"
5854
android:largeHeap="true"
5955
android:requestLegacyExternalStorage="true"
@@ -80,9 +76,9 @@
8076
android:name="androidx.core.content.FileProvider"
8177
android:authorities="${applicationId}.fileprovider"
8278
android:exported="false"
79+
android:grantUriPermissions="true"
8380
tools:node="merge"
84-
tools:overrideLibrary="com.squareup.picasso.picasso"
85-
android:grantUriPermissions="true">
81+
tools:overrideLibrary="com.squareup.picasso.picasso">
8682
<meta-data
8783
android:name="android.support.FILE_PROVIDER_PATHS"
8884
android:resource="@xml/provider_paths" />
@@ -92,8 +88,5 @@
9288
android:name=".error.DiagnosticReportActivity"
9389
android:exported="false" />
9490
<service android:name=".read_aloud.ReadAloudService" />
95-
<service
96-
android:name=".downloader.downloadManager.DownloadMonitorService"
97-
android:foregroundServiceType="dataSync" />
9891
</application>
9992
</manifest>

core/src/main/java/org/kiwix/kiwixmobile/core/dao/DownloadRoomDao.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ abstract class DownloadRoomDao {
113113
sharedPreferenceUtil: SharedPreferenceUtil
114114
) {
115115
if (doesNotAlreadyExist(book)) {
116-
val downloadRequest = DownloadRequest(url)
116+
val downloadRequest = DownloadRequest(url, book.title)
117117
saveDownload(
118118
DownloadRoomEntity(
119119
url,

core/src/main/java/org/kiwix/kiwixmobile/core/dao/entities/DownloadRoomEntity.kt

+4-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ data class DownloadRoomEntity(
5454
val size: String,
5555
val name: String?,
5656
val favIcon: String,
57-
val tags: String? = null
57+
val tags: String? = null,
58+
var pausedByUser: Boolean = false
5859
) {
5960
constructor(downloadUrl: String, downloadId: Long, book: Book, file: String?) : this(
6061
file = file,
@@ -99,7 +100,8 @@ data class DownloadRoomEntity(
99100
totalSizeOfDownload = download.totalSizeOfDownload,
100101
status = download.state,
101102
error = download.error,
102-
progress = download.progress
103+
progress = download.progress,
104+
pausedByUser = download.pausedByUser
103105
)
104106
}
105107

core/src/main/java/org/kiwix/kiwixmobile/core/data/KiwixRoomDatabase.kt

+17-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ import org.kiwix.kiwixmobile.core.dao.entities.ZimSourceRoomConverter
4444
NotesRoomEntity::class,
4545
DownloadRoomEntity::class
4646
],
47-
version = 5,
47+
version = 6,
4848
exportSchema = false
4949
)
5050
@TypeConverters(HistoryRoomDaoCoverts::class, ZimSourceRoomConverter::class)
@@ -62,7 +62,13 @@ abstract class KiwixRoomDatabase : RoomDatabase() {
6262
?: Room.databaseBuilder(context, KiwixRoomDatabase::class.java, "KiwixRoom.db")
6363
// We have already database name called kiwix.db in order to avoid complexity we named
6464
// as kiwixRoom.db
65-
.addMigrations(MIGRATION_1_2, MIGRATION_2_3, MIGRATION_3_4, MIGRATION_4_5)
65+
.addMigrations(
66+
MIGRATION_1_2,
67+
MIGRATION_2_3,
68+
MIGRATION_3_4,
69+
MIGRATION_4_5,
70+
MIGRATION_5_6
71+
)
6672
.build().also { db = it }
6773
}
6874
}
@@ -202,6 +208,15 @@ abstract class KiwixRoomDatabase : RoomDatabase() {
202208
}
203209
}
204210

211+
@Suppress("MagicNumber")
212+
private val MIGRATION_5_6 = object : Migration(5, 6) {
213+
override fun migrate(database: SupportSQLiteDatabase) {
214+
database.execSQL(
215+
"ALTER TABLE DownloadRoomEntity ADD COLUMN pausedByUser INTEGER NOT NULL DEFAULT 0"
216+
)
217+
}
218+
}
219+
205220
fun destroyInstance() {
206221
db = null
207222
}

core/src/main/java/org/kiwix/kiwixmobile/core/di/components/CoreServiceComponent.kt

-2
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,12 @@ import dagger.BindsInstance
2323
import dagger.Subcomponent
2424
import org.kiwix.kiwixmobile.core.di.CoreServiceScope
2525
import org.kiwix.kiwixmobile.core.di.modules.CoreServiceModule
26-
import org.kiwix.kiwixmobile.core.downloader.downloadManager.DownloadMonitorService
2726
import org.kiwix.kiwixmobile.core.read_aloud.ReadAloudService
2827

2928
@Subcomponent(modules = [CoreServiceModule::class])
3029
@CoreServiceScope
3130
interface CoreServiceComponent {
3231
fun inject(readAloudService: ReadAloudService)
33-
fun inject(downloadMonitorService: DownloadMonitorService)
3432

3533
@Subcomponent.Builder
3634
interface Builder {

core/src/main/java/org/kiwix/kiwixmobile/core/di/modules/DownloaderModule.kt

-10
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
package org.kiwix.kiwixmobile.core.di.modules
1919

2020
import android.app.DownloadManager
21-
import android.app.NotificationManager
22-
import android.content.Context
2321
import dagger.Module
2422
import dagger.Provides
2523
import org.kiwix.kiwixmobile.core.dao.DownloadRoomDao
@@ -30,7 +28,6 @@ import org.kiwix.kiwixmobile.core.downloader.DownloaderImpl
3028
import org.kiwix.kiwixmobile.core.downloader.downloadManager.DownloadManagerBroadcastReceiver
3129
import org.kiwix.kiwixmobile.core.downloader.downloadManager.DownloadManagerMonitor
3230
import org.kiwix.kiwixmobile.core.downloader.downloadManager.DownloadManagerRequester
33-
import org.kiwix.kiwixmobile.core.downloader.downloadManager.DownloadNotificationManager
3431
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
3532
import javax.inject.Singleton
3633

@@ -69,11 +66,4 @@ object DownloaderModule {
6966
fun providesDownloadManagerBroadcastReceiver(
7067
callback: DownloadManagerBroadcastReceiver.Callback
7168
): DownloadManagerBroadcastReceiver = DownloadManagerBroadcastReceiver(callback)
72-
73-
@Provides
74-
@Singleton
75-
fun providesDownloadNotificationManager(
76-
context: Context,
77-
notificationManager: NotificationManager
78-
): DownloadNotificationManager = DownloadNotificationManager(context, notificationManager)
7969
}

0 commit comments

Comments
 (0)