Skip to content
Closed
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
84 changes: 40 additions & 44 deletions app/src/main/java/com/demonlab/lune/tools/MusicService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ import com.google.common.util.concurrent.ListenableFuture
import com.google.common.util.concurrent.SettableFuture

@OptIn(UnstableApi::class, ExperimentalCoroutinesApi::class)
@Suppress("DEPRECATION")
class MusicService : MediaLibraryService() {
override fun onGetSession(controllerInfo: MediaSession.ControllerInfo): MediaLibrarySession? {
ensureMediaSession()
Expand Down Expand Up @@ -309,12 +308,20 @@ class MusicService : MediaLibraryService() {
.build().also { audioFocusRequest = it }
audioManager.requestAudioFocus(request)
} else {
@Suppress("DEPRECATION")
audioManager.requestAudioFocus(
audioFocusListener,
AudioManager.STREAM_MUSIC,
AudioManager.AUDIOFOCUS_GAIN
)
runCatching {
val method = AudioManager::class.java.getMethod(
"requestAudioFocus",
AudioManager.OnAudioFocusChangeListener::class.java,
Int::class.javaPrimitiveType,
Int::class.javaPrimitiveType
)
method.invoke(
audioManager,
audioFocusListener,
AudioManager.STREAM_MUSIC,
AudioManager.AUDIOFOCUS_GAIN
) as? Int
}.getOrNull() ?: AudioManager.AUDIOFOCUS_REQUEST_FAILED
}

return when (result) {
Expand Down Expand Up @@ -342,8 +349,13 @@ class MusicService : MediaLibraryService() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
audioFocusRequest?.let { audioManager.abandonAudioFocusRequest(it) }
} else {
@Suppress("DEPRECATION")
audioManager.abandonAudioFocus(audioFocusListener)
runCatching {
val method = AudioManager::class.java.getMethod(
"abandonAudioFocus",
AudioManager.OnAudioFocusChangeListener::class.java
)
method.invoke(audioManager, audioFocusListener)
}
}
}

Expand Down Expand Up @@ -474,12 +486,7 @@ class MusicService : MediaLibraryService() {
pm.updatePlayingState(false)
pm.savePlaybackState(wasPlaying = false)
stopWidgetUpdateTimer()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
stopForeground(STOP_FOREGROUND_REMOVE)
} else {
@Suppress("DEPRECATION")
stopForeground(true)
}
stopForeground(STOP_FOREGROUND_REMOVE)
try {
val notificationManager = getSystemService(NotificationManager::class.java)
notificationManager?.cancel(1)
Expand Down Expand Up @@ -523,12 +530,7 @@ class MusicService : MediaLibraryService() {
pm.updatePlayingState(false)
pm.savePlaybackState(wasPlaying = false)
stopWidgetUpdateTimer()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
stopForeground(STOP_FOREGROUND_REMOVE)
} else {
@Suppress("DEPRECATION")
stopForeground(true)
}
stopForeground(STOP_FOREGROUND_REMOVE)
try {
val notificationManager = getSystemService(NotificationManager::class.java)
notificationManager?.cancel(1)
Expand Down Expand Up @@ -788,12 +790,11 @@ class MusicService : MediaLibraryService() {
controllerInfo: MediaSession.ControllerInfo,
intent: Intent
): Boolean {
val keyEvent = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT, KeyEvent::class.java)
} else {
@Suppress("DEPRECATION")
intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT)
}
val keyEvent = androidx.core.content.IntentCompat.getParcelableExtra(
intent,
Intent.EXTRA_KEY_EVENT,
KeyEvent::class.java
)
if (keyEvent != null && handleMediaKeyEvent(keyEvent)) {
return true
}
Expand Down Expand Up @@ -1445,12 +1446,7 @@ class MusicService : MediaLibraryService() {
isNotificationDismissed = true
abandonAudioFocus()
releaseWakeLock()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
stopForeground(android.app.Service.STOP_FOREGROUND_REMOVE)
} else {
@Suppress("DEPRECATION")
stopForeground(true)
}
stopForeground(STOP_FOREGROUND_REMOVE)
try {
val notificationManager = getSystemService(NotificationManager::class.java)
notificationManager?.cancel(1)
Expand Down Expand Up @@ -1623,12 +1619,7 @@ class MusicService : MediaLibraryService() {
pauseTimeoutJob = serviceScope.launch {
delay(PAUSE_TIMEOUT_MS)
isNotificationDismissed = true
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
stopForeground(android.app.Service.STOP_FOREGROUND_REMOVE)
} else {
@Suppress("DEPRECATION")
stopForeground(true)
}
stopForeground(STOP_FOREGROUND_REMOVE)
try {
val notificationManager = getSystemService(NotificationManager::class.java)
notificationManager?.cancel(1)
Expand Down Expand Up @@ -1811,11 +1802,16 @@ class MusicService : MediaLibraryService() {
}

try {
val musicDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC)
val globalLyrics = File(musicDir, "Lyrics")
if (globalLyrics.isDirectory) {
possibleLrcFiles.add(File(globalLyrics, "$baseName.lrc"))
possibleLrcFiles.add(File(globalLyrics, "$baseName.LRC"))
val musicDir = runCatching {
Environment::class.java.getMethod("getExternalStoragePublicDirectory", String::class.java)
.invoke(null, Environment.DIRECTORY_MUSIC) as? File
}.getOrNull()
if (musicDir != null) {
val globalLyrics = File(musicDir, "Lyrics")
if (globalLyrics.isDirectory) {
possibleLrcFiles.add(File(globalLyrics, "$baseName.lrc"))
possibleLrcFiles.add(File(globalLyrics, "$baseName.LRC"))
}
}
} catch (_: Exception) {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ class CustomizationActivity : ComponentActivity() {
}

@OptIn(ExperimentalMaterial3Api::class)
@Suppress("DEPRECATION")
@Composable
fun CustomizationScreen(
onBack: () -> Unit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ class EqualizerActivity : ComponentActivity() {
}

@OptIn(ExperimentalMaterial3Api::class)
@Suppress("DEPRECATION")
@Composable
fun EqualizerScreen(onBack: () -> Unit) {
val context = LocalContext.current
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,35 +70,25 @@ data class StorageInfo(val name: String, val path: String, val isPrimary: Boolea

fun getStorageVolumes(context: android.content.Context): List<StorageInfo> {
val volumes = mutableListOf<StorageInfo>()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
val storageManager = context.getSystemService(android.content.Context.STORAGE_SERVICE) as StorageManager
for (volume in storageManager.storageVolumes) {
val dir = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
volume.directory
} else {
@Suppress("DEPRECATION")
if (volume.isPrimary) {
android.os.Environment.getExternalStorageDirectory()
} else {
try {
val method = volume.javaClass.getMethod("getPath")
File(method.invoke(volume) as String)
} catch (_: Exception) { null }
}
}
dir?.let {
val name = volume.getDescription(context)
volumes.add(StorageInfo(name, it.absolutePath, volume.isPrimary))
val storageManager = context.getSystemService(android.content.Context.STORAGE_SERVICE) as StorageManager
for (volume in storageManager.storageVolumes) {
val dir = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
volume.directory
} else {
try {
val method = volume.javaClass.getMethod("getPath")
File(method.invoke(volume) as String)
} catch (_: Exception) {
runCatching {
val method = android.os.Environment::class.java.getMethod("getExternalStorageDirectory")
method.invoke(null) as? File
}.getOrNull()
}
}
} else {
@Suppress("DEPRECATION")
val primary = android.os.Environment.getExternalStorageDirectory()
volumes.add(StorageInfo(
context.getString(if (primary.exists()) R.string.internal_storage else R.string.sd_card),
primary.absolutePath,
true
))
dir?.let {
val name = volume.getDescription(context)
volumes.add(StorageInfo(name, it.absolutePath, volume.isPrimary))
}
}
return volumes
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ class WidgetCustomizationActivity : ComponentActivity() {
}

@OptIn(ExperimentalMaterial3Api::class)
@Suppress("DEPRECATION")
@Composable
fun WidgetCustomizationScreen(
onBack: () -> Unit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,13 @@ fun AppBlurBackdrop(
ctx = ctx.baseContext
}
val targetWindow = dialogWindow ?: activity?.window
@Suppress("DEPRECATION")
targetWindow?.let { window ->
window.navigationBarColor = android.graphics.Color.TRANSPARENT
if (Build.VERSION.SDK_INT < 35) {
runCatching {
window.javaClass.getMethod("setNavigationBarColor", Int::class.javaPrimitiveType)
.invoke(window, android.graphics.Color.TRANSPARENT)
}
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
window.isNavigationBarContrastEnforced = false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.demonlab.lune.ui.lyrics

import android.content.ClipboardManager
import android.content.Context
import android.os.Build
import android.os.Vibrator
import android.widget.Toast
import androidx.activity.compose.rememberLauncherForActivityResult
Expand Down Expand Up @@ -34,7 +35,6 @@ import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.LocalView
import androidx.compose.ui.window.DialogWindowProvider
import android.view.WindowManager
import androidx.compose.foundation.horizontalScroll
import androidx.compose.foundation.rememberScrollState
import coil.compose.AsyncImage
Expand Down Expand Up @@ -237,8 +237,10 @@ fun LyricsEditorSheet(
var parent = view.parent
while (parent != null) {
if (parent is DialogWindowProvider) {
@Suppress("DEPRECATION")
parent.window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE)
androidx.core.view.WindowCompat.setDecorFitsSystemWindows(parent.window, false)
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
parent.window.setSoftInputMode(0x10)
}
break
}
parent = parent.parent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import android.content.Intent
import android.content.pm.PackageManager
import android.content.res.Configuration
import android.os.Build
import android.os.VibrationEffect
import android.os.Vibrator
import androidx.core.content.ContextCompat
import androidx.compose.animation.*
Expand Down Expand Up @@ -124,6 +123,7 @@ import com.demonlab.lune.ui.sheets.VisualizerSettingsBottomSheet
import com.demonlab.lune.ui.theme.getControlsPrimaryColor
import com.demonlab.lune.ui.utils.MaterialExpressiveScallopShape
import com.demonlab.lune.ui.utils.bounceClick
import com.demonlab.lune.ui.utils.triggerLightVibration
import com.demonlab.lune.ui.utils.formatDuration
import com.demonlab.lune.ui.utils.songSwipeGestures
import com.demonlab.lune.ui.viewmodels.MusicViewModel
Expand Down Expand Up @@ -2964,14 +2964,7 @@ fun MiniPlayerMinimized(

if (clampedOffset <= -50f && !hasVibrated) {
hasVibrated = true
vibrator?.let {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
it.vibrate(VibrationEffect.createOneShot(28, VibrationEffect.DEFAULT_AMPLITUDE))
} else {
@Suppress("DEPRECATION")
it.vibrate(28)
}
}
vibrator?.triggerLightVibration()
}

coroutineScope.launch {
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/java/com/demonlab/lune/ui/sheets/BottomSheets.kt
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,6 @@ fun SortBottomSheet(
}

@OptIn(ExperimentalMaterial3Api::class)
@Suppress("DEPRECATION")
@Composable
fun EqBottomSheet(
playbackManager: PlaybackManager,
Expand Down Expand Up @@ -1787,7 +1786,6 @@ fun EditSongBottomSheet(
}
}

@Suppress("DEPRECATION")
@Composable
fun CustomSleepTimerDialog(
currentMinutes: Int,
Expand Down
8 changes: 6 additions & 2 deletions app/src/main/java/com/demonlab/lune/ui/theme/Theme.kt
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,13 @@ fun LuneTheme(
ctx = ctx.baseContext
}
val window = dialogWindow ?: activity?.window
@Suppress("DEPRECATION")
window?.let { win ->
win.navigationBarColor = android.graphics.Color.TRANSPARENT
if (Build.VERSION.SDK_INT < 35) {
runCatching {
win.javaClass.getMethod("setNavigationBarColor", Int::class.javaPrimitiveType)
.invoke(win, android.graphics.Color.TRANSPARENT)
}
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
win.isNavigationBarContrastEnforced = false
}
Expand Down
8 changes: 6 additions & 2 deletions app/src/main/java/com/demonlab/lune/ui/utils/Extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,13 @@ import kotlin.math.sin
fun Vibrator.triggerLightVibration() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
this.vibrate(VibrationEffect.createPredefined(VibrationEffect.EFFECT_TICK))
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
this.vibrate(VibrationEffect.createOneShot(20, VibrationEffect.DEFAULT_AMPLITUDE))
} else {
@Suppress("DEPRECATION")
this.vibrate(20)
runCatching {
val method = Vibrator::class.java.getMethod("vibrate", Long::class.javaPrimitiveType)
method.invoke(this, 20L)
}
}
}

Expand Down
Loading