Skip to content

Commit

Permalink
Cleanup code and fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxr1998 committed Sep 4, 2023
1 parent ffb3b09 commit 574d4ea
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 13 deletions.
6 changes: 3 additions & 3 deletions app/src/main/java/org/jellyfin/mobile/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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() }

Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/org/jellyfin/mobile/events/ActivityEvent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<PermissionRequestHelper>()
val code = helper.getRequestCode()
Expand Down
4 changes: 1 addition & 3 deletions app/src/main/java/org/jellyfin/mobile/utils/SystemUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -145,7 +144,6 @@ fun Context.createMediaNotificationChannel(notificationManager: NotificationMana
}
}

@Suppress("DEPRECATION")
fun Context.getDownloadsPaths(): List<String> = ArrayList<String>().apply {
for (directory in getExternalFilesDirs(null)) {
// Ignore currently unavailable shared storage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 574d4ea

Please sign in to comment.