diff --git a/app/src/main/java/org/jellyfin/mobile/MainActivity.kt b/app/src/main/java/org/jellyfin/mobile/MainActivity.kt index fa0cbd6c18..8c36e64625 100644 --- a/app/src/main/java/org/jellyfin/mobile/MainActivity.kt +++ b/app/src/main/java/org/jellyfin/mobile/MainActivity.kt @@ -97,9 +97,6 @@ class MainActivity : AppCompatActivity() { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) - // Bind player service - bindService(Intent(this, RemotePlayerService::class.java), serviceConnection, Service.BIND_AUTO_CREATE) - // Check WebView support if (!isWebViewSupported()) { AlertDialog.Builder(this).apply { @@ -120,6 +117,9 @@ class MainActivity : AppCompatActivity() { return } + // Bind player service + bindService(Intent(this, RemotePlayerService::class.java), serviceConnection, Service.BIND_AUTO_CREATE) + // Subscribe to activity events with(activityEventHandler) { subscribe() } diff --git a/app/src/main/java/org/jellyfin/mobile/events/ActivityEvent.kt b/app/src/main/java/org/jellyfin/mobile/events/ActivityEvent.kt index afec2b9aff..e5a9ec5ca0 100644 --- a/app/src/main/java/org/jellyfin/mobile/events/ActivityEvent.kt +++ b/app/src/main/java/org/jellyfin/mobile/events/ActivityEvent.kt @@ -11,7 +11,7 @@ sealed class ActivityEvent { class DownloadFile(val uri: Uri, val title: String, val filename: String) : ActivityEvent() class CastMessage(val action: String, val args: JSONArray) : ActivityEvent() data object RequestBluetoothPermission : ActivityEvent() - object OpenSettings : ActivityEvent() - object SelectServer : ActivityEvent() - object ExitApp : ActivityEvent() + data object OpenSettings : ActivityEvent() + data object SelectServer : ActivityEvent() + data object ExitApp : ActivityEvent() } diff --git a/app/src/main/java/org/jellyfin/mobile/events/ActivityEventHandler.kt b/app/src/main/java/org/jellyfin/mobile/events/ActivityEventHandler.kt index 84b30a892e..d15c3a609b 100644 --- a/app/src/main/java/org/jellyfin/mobile/events/ActivityEventHandler.kt +++ b/app/src/main/java/org/jellyfin/mobile/events/ActivityEventHandler.kt @@ -41,7 +41,7 @@ class ActivityEventHandler( } } - private suspend fun MainActivity.handleEvent(event: ActivityEvent) { + private fun MainActivity.handleEvent(event: ActivityEvent) { when (event) { is ActivityEvent.ChangeFullscreen -> { val fullscreenHelper = PlayerFullscreenHelper(window) @@ -72,7 +72,9 @@ class ActivityEventHandler( } } is ActivityEvent.DownloadFile -> { - with(event) { requestDownload(uri, title, filename) } + lifecycleScope.launch { + with(event) { requestDownload(uri, title, filename) } + } } is ActivityEvent.CastMessage -> { val action = event.action diff --git a/app/src/main/java/org/jellyfin/mobile/utils/PermissionRequestHelper.kt b/app/src/main/java/org/jellyfin/mobile/utils/PermissionRequestHelper.kt index 9fb43301a7..1a5a4d67cc 100644 --- a/app/src/main/java/org/jellyfin/mobile/utils/PermissionRequestHelper.kt +++ b/app/src/main/java/org/jellyfin/mobile/utils/PermissionRequestHelper.kt @@ -45,7 +45,7 @@ fun Activity.requestPermission(vararg permissions: String, callback: PermissionR } if (skipRequest) { - callback(permissions.map { Pair(it, PackageManager.PERMISSION_GRANTED) }.toMap()) + callback(permissions.associateWith { PackageManager.PERMISSION_GRANTED }) } else { val helper = getKoin().get() val code = helper.getRequestCode() diff --git a/app/src/main/java/org/jellyfin/mobile/utils/SystemUtils.kt b/app/src/main/java/org/jellyfin/mobile/utils/SystemUtils.kt index bd52463d3d..f3b0c33011 100644 --- a/app/src/main/java/org/jellyfin/mobile/utils/SystemUtils.kt +++ b/app/src/main/java/org/jellyfin/mobile/utils/SystemUtils.kt @@ -17,7 +17,6 @@ import android.os.Environment import android.os.PowerManager import android.provider.Settings import android.provider.Settings.System.ACCELEROMETER_ROTATION -import androidx.appcompat.app.AppCompatActivity import androidx.coordinatorlayout.widget.CoordinatorLayout import androidx.core.content.getSystemService import com.google.android.material.snackbar.Snackbar @@ -37,7 +36,7 @@ import kotlin.coroutines.suspendCoroutine fun WebViewFragment.requestNoBatteryOptimizations(rootView: CoordinatorLayout) { if (AndroidVersion.isAtLeastM) { - val powerManager: PowerManager = requireContext().getSystemService(AppCompatActivity.POWER_SERVICE) as PowerManager + val powerManager: PowerManager = requireContext().getSystemService(Activity.POWER_SERVICE) as PowerManager if ( !appPreferences.ignoreBatteryOptimizations && !powerManager.isIgnoringBatteryOptimizations(BuildConfig.APPLICATION_ID) @@ -145,7 +144,6 @@ fun Context.createMediaNotificationChannel(notificationManager: NotificationMana } } -@Suppress("DEPRECATION") fun Context.getDownloadsPaths(): List = ArrayList().apply { for (directory in getExternalFilesDirs(null)) { // Ignore currently unavailable shared storage diff --git a/app/src/main/java/org/jellyfin/mobile/webapp/RemotePlayerService.kt b/app/src/main/java/org/jellyfin/mobile/webapp/RemotePlayerService.kt index 895ace8f86..5f0f5dbf09 100644 --- a/app/src/main/java/org/jellyfin/mobile/webapp/RemotePlayerService.kt +++ b/app/src/main/java/org/jellyfin/mobile/webapp/RemotePlayerService.kt @@ -166,7 +166,9 @@ class RemotePlayerService : Service(), CoroutineScope { } private fun handleIntent(intent: Intent?) { - if (intent == null || intent.action == null) return + if (intent?.action == null) { + return + } val action = intent.action if (action == Constants.ACTION_REPORT) { notify(intent)