mirror of
https://github.com/nextcloud/android.git
synced 2024-11-28 02:17:43 +03:00
Simplify code complexity
Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
parent
39231af670
commit
b2e0e76605
2 changed files with 21 additions and 9 deletions
|
@ -23,7 +23,6 @@ package com.nextcloud.utils
|
|||
|
||||
import android.app.Notification
|
||||
import android.app.Service
|
||||
import android.content.pm.ServiceInfo
|
||||
import android.os.Build
|
||||
import androidx.core.app.ServiceCompat
|
||||
import com.owncloud.android.datamodel.ForegroundServiceType
|
||||
|
@ -36,17 +35,11 @@ object ForegroundServiceHelper {
|
|||
foregroundServiceType: ForegroundServiceType
|
||||
) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
val foregroundServiceTypeId: Int = if (foregroundServiceType == ForegroundServiceType.DataSync) {
|
||||
ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC
|
||||
} else {
|
||||
ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK
|
||||
}
|
||||
|
||||
ServiceCompat.startForeground(
|
||||
service,
|
||||
id,
|
||||
notification,
|
||||
foregroundServiceTypeId
|
||||
foregroundServiceType.getId()
|
||||
)
|
||||
} else {
|
||||
service.startForeground(id, notification)
|
||||
|
|
|
@ -21,6 +21,25 @@
|
|||
|
||||
package com.owncloud.android.datamodel
|
||||
|
||||
import android.content.pm.ServiceInfo
|
||||
import android.os.Build
|
||||
import androidx.annotation.RequiresApi
|
||||
|
||||
/**
|
||||
* Enum to specify the type of foreground service.
|
||||
* Use this enum when starting a foreground service to indicate its purpose.
|
||||
* Note: Foreground service type is not available for older Android versions.
|
||||
* This wrapper is designed for compatibility on those versions.
|
||||
*/
|
||||
enum class ForegroundServiceType {
|
||||
DataSync, MediaPlayback
|
||||
DataSync, MediaPlayback;
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.Q)
|
||||
fun getId(): Int {
|
||||
return if (this == DataSync) {
|
||||
ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC
|
||||
} else {
|
||||
ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue