Skip to content

Commit

Permalink
Add long running task support
Browse files Browse the repository at this point in the history
Signed-off-by: alperozturk <[email protected]>
  • Loading branch information
alperozturk96 committed Jan 10, 2024
1 parent 252d7de commit abbf79b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
6 changes: 6 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,12 @@
android:exported="false"
android:configChanges="orientation|screenLayout|screenSize|keyboardHidden"
android:theme="@style/Theme.ownCloud.Media" />
<service
android:name="androidx.work.impl.foreground.SystemForegroundService"
android:directBootAware="false"
android:enabled="@bool/enable_system_foreground_service_default"
android:exported="false"
android:foregroundServiceType="dataSync" />
<service
android:name=".authentication.AccountAuthenticatorService"
android:exported="false">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class DownloadNotificationManager(
@Suppress("MagicNumber")
fun showCompleteNotification(text: String) {
Handler(Looper.getMainLooper()).postDelayed({
updateNotificationText(null,text, true)
updateNotificationText(null, text, true)
dismissNotification()
}, 3000)
}
Expand Down Expand Up @@ -156,4 +156,12 @@ class DownloadNotificationManager(
)
)
}

fun getId(): Int {
return id
}

fun getNotification(): Notification {
return notificationBuilder.build()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ import com.nextcloud.client.account.UserAccountManager
import com.nextcloud.java.util.Optional
import com.nextcloud.model.WorkerState
import com.nextcloud.model.WorkerStateLiveData
import com.nextcloud.utils.ForegroundServiceHelper
import com.owncloud.android.R
import com.owncloud.android.datamodel.FileDataStorageManager
import com.owncloud.android.datamodel.ForegroundServiceType
import com.owncloud.android.datamodel.OCFile
import com.owncloud.android.files.services.IndexedForest
import com.owncloud.android.lib.common.OwnCloudAccount
Expand Down Expand Up @@ -123,6 +125,14 @@ class FileDownloadWorker(

addAccountUpdateListener()

setForegroundAsync(
ForegroundServiceHelper.createWorkerForegroundInfo(
notificationManager.getId(),
notificationManager.getNotification(),
ForegroundServiceType.DataSync
)
)

requestDownloads.forEach {
downloadFile(it)
}
Expand Down

0 comments on commit abbf79b

Please sign in to comment.