Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed: Downloads were not automatically starting showing progress when reopening the app(If downloads paused due to any network error). #4130

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
android:name="android.permission.NEARBY_WIFI_DEVICES"
android:usesPermissionFlags="neverForLocation"
tools:targetApi="s" />
<!-- Device with versions >= Pie need this permission -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />

<application
android:name=".KiwixApp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@
},
{
context?.let { context ->
if (isNotConnected) {
noInternetSnackbar()
return@let

Check warning on line 153 in app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/OnlineLibraryFragment.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/OnlineLibraryFragment.kt#L152-L153

Added lines #L152 - L153 were not covered by tests
}
downloader.pauseResumeDownload(
it.downloadId,
it.downloadState.toReadableState(context).contains(getString(string.paused_state))
Expand Down
17 changes: 5 additions & 12 deletions core/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,8 @@
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission
android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" />
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>
<!-- Device with versions >= Pie need this permission -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />

<queries>
<intent>
<action android:name="android.intent.action.TTS_SERVICE" />
Expand Down Expand Up @@ -52,8 +48,8 @@

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:dataExtractionRules = "@xml/data_extraction_rules"
android:hardwareAccelerated="true"
android:largeHeap="true"
android:requestLegacyExternalStorage="true"
Expand All @@ -80,9 +76,9 @@
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.fileprovider"
android:exported="false"
android:grantUriPermissions="true"
tools:node="merge"
tools:overrideLibrary="com.squareup.picasso.picasso"
android:grantUriPermissions="true">
tools:overrideLibrary="com.squareup.picasso.picasso">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths" />
Expand All @@ -92,8 +88,5 @@
android:name=".error.DiagnosticReportActivity"
android:exported="false" />
<service android:name=".read_aloud.ReadAloudService" />
<service
android:name=".downloader.downloadManager.DownloadMonitorService"
android:foregroundServiceType="dataSync" />
</application>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ abstract class DownloadRoomDao {
sharedPreferenceUtil: SharedPreferenceUtil
) {
if (doesNotAlreadyExist(book)) {
val downloadRequest = DownloadRequest(url)
val downloadRequest = DownloadRequest(url, book.title)
saveDownload(
DownloadRoomEntity(
url,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ data class DownloadRoomEntity(
val size: String,
val name: String?,
val favIcon: String,
val tags: String? = null
val tags: String? = null,
var pausedByUser: Boolean = false
) {
constructor(downloadUrl: String, downloadId: Long, book: Book, file: String?) : this(
file = file,
Expand Down Expand Up @@ -99,7 +100,8 @@ data class DownloadRoomEntity(
totalSizeOfDownload = download.totalSizeOfDownload,
status = download.state,
error = download.error,
progress = download.progress
progress = download.progress,
pausedByUser = download.pausedByUser
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
NotesRoomEntity::class,
DownloadRoomEntity::class
],
version = 5,
version = 6,
exportSchema = false
)
@TypeConverters(HistoryRoomDaoCoverts::class, ZimSourceRoomConverter::class)
Expand All @@ -62,7 +62,13 @@
?: Room.databaseBuilder(context, KiwixRoomDatabase::class.java, "KiwixRoom.db")
// We have already database name called kiwix.db in order to avoid complexity we named
// as kiwixRoom.db
.addMigrations(MIGRATION_1_2, MIGRATION_2_3, MIGRATION_3_4, MIGRATION_4_5)
.addMigrations(
MIGRATION_1_2,
MIGRATION_2_3,
MIGRATION_3_4,
MIGRATION_4_5,
MIGRATION_5_6
)
.build().also { db = it }
}
}
Expand Down Expand Up @@ -202,6 +208,15 @@
}
}

@Suppress("MagicNumber")
private val MIGRATION_5_6 = object : Migration(5, 6) {
override fun migrate(database: SupportSQLiteDatabase) {
database.execSQL(
"ALTER TABLE DownloadRoomEntity ADD COLUMN pausedByUser INTEGER NOT NULL DEFAULT 0"

Check warning on line 215 in core/src/main/java/org/kiwix/kiwixmobile/core/data/KiwixRoomDatabase.kt

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/org/kiwix/kiwixmobile/core/data/KiwixRoomDatabase.kt#L214-L215

Added lines #L214 - L215 were not covered by tests
)
}

Check warning on line 217 in core/src/main/java/org/kiwix/kiwixmobile/core/data/KiwixRoomDatabase.kt

View check run for this annotation

Codecov / codecov/patch

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

Added line #L217 was not covered by tests
}

fun destroyInstance() {
db = null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,12 @@ import dagger.BindsInstance
import dagger.Subcomponent
import org.kiwix.kiwixmobile.core.di.CoreServiceScope
import org.kiwix.kiwixmobile.core.di.modules.CoreServiceModule
import org.kiwix.kiwixmobile.core.downloader.downloadManager.DownloadMonitorService
import org.kiwix.kiwixmobile.core.read_aloud.ReadAloudService

@Subcomponent(modules = [CoreServiceModule::class])
@CoreServiceScope
interface CoreServiceComponent {
fun inject(readAloudService: ReadAloudService)
fun inject(downloadMonitorService: DownloadMonitorService)

@Subcomponent.Builder
interface Builder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
package org.kiwix.kiwixmobile.core.di.modules

import android.app.DownloadManager
import android.app.NotificationManager
import android.content.Context
import dagger.Module
import dagger.Provides
import org.kiwix.kiwixmobile.core.dao.DownloadRoomDao
Expand All @@ -30,7 +28,6 @@ import org.kiwix.kiwixmobile.core.downloader.DownloaderImpl
import org.kiwix.kiwixmobile.core.downloader.downloadManager.DownloadManagerBroadcastReceiver
import org.kiwix.kiwixmobile.core.downloader.downloadManager.DownloadManagerMonitor
import org.kiwix.kiwixmobile.core.downloader.downloadManager.DownloadManagerRequester
import org.kiwix.kiwixmobile.core.downloader.downloadManager.DownloadNotificationManager
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
import javax.inject.Singleton

Expand Down Expand Up @@ -69,11 +66,4 @@ object DownloaderModule {
fun providesDownloadManagerBroadcastReceiver(
callback: DownloadManagerBroadcastReceiver.Callback
): DownloadManagerBroadcastReceiver = DownloadManagerBroadcastReceiver(callback)

@Provides
@Singleton
fun providesDownloadNotificationManager(
context: Context,
notificationManager: NotificationManager
): DownloadNotificationManager = DownloadNotificationManager(context, notificationManager)
}
Loading
Loading