From d2497c7217e7203c3a583ee94ed26a7760d7ecac Mon Sep 17 00:00:00 2001 From: Ryan Harg Date: Wed, 21 Jul 2021 09:11:07 +0200 Subject: [PATCH] Remove build warnings --- app/src/main/java/audio/funkwhale/ffa/FFA.kt | 31 ++++++++++--------- .../ffa/activities/DownloadsActivity.kt | 5 +-- .../funkwhale/ffa/activities/MainActivity.kt | 5 +-- .../ffa/activities/SearchActivity.kt | 6 ++-- .../ffa/activities/SettingsActivity.kt | 3 +- .../ffa/activities/SplashActivity.kt | 3 +- .../ffa/playback/MediaControlsManager.kt | 2 +- .../funkwhale/ffa/playback/PinService.kt | 26 ++++++++-------- .../funkwhale/ffa/playback/PlayerService.kt | 24 +++++++------- .../funkwhale/ffa/playback/QueueManager.kt | 4 +-- .../ffa/repositories/FavoritesRepository.kt | 2 +- .../ffa/repositories/SearchRepository.kt | 2 +- .../ffa/repositories/TracksRepository.kt | 4 +-- .../java/audio/funkwhale/ffa/utils/Bus.kt | 17 +++++----- 14 files changed, 70 insertions(+), 64 deletions(-) diff --git a/app/src/main/java/audio/funkwhale/ffa/FFA.kt b/app/src/main/java/audio/funkwhale/ffa/FFA.kt index 95f7bc5..93eebb0 100644 --- a/app/src/main/java/audio/funkwhale/ffa/FFA.kt +++ b/app/src/main/java/audio/funkwhale/ffa/FFA.kt @@ -2,6 +2,9 @@ package audio.funkwhale.ffa import android.app.Application import androidx.appcompat.app.AppCompatDelegate +import audio.funkwhale.ffa.playback.MediaSession +import audio.funkwhale.ffa.playback.QueueManager +import audio.funkwhale.ffa.utils.* import com.google.android.exoplayer2.database.ExoDatabaseProvider import com.google.android.exoplayer2.offline.DefaultDownloadIndex import com.google.android.exoplayer2.offline.DefaultDownloaderFactory @@ -13,17 +16,14 @@ import com.google.android.exoplayer2.upstream.cache.SimpleCache import com.preference.PowerPreference import kotlinx.coroutines.channels.BroadcastChannel import kotlinx.coroutines.channels.ConflatedBroadcastChannel -import audio.funkwhale.ffa.playback.MediaSession -import audio.funkwhale.ffa.playback.QueueManager -import audio.funkwhale.ffa.utils.* import java.text.SimpleDateFormat import java.util.* class FFA : Application() { companion object { - private var instance: audio.funkwhale.ffa.FFA = audio.funkwhale.ffa.FFA() + private var instance: FFA = FFA() - fun get(): audio.funkwhale.ffa.FFA = audio.funkwhale.ffa.FFA.Companion.instance + fun get(): FFA = instance } var defaultExceptionHandler: Thread.UncaughtExceptionHandler? = null @@ -70,7 +70,7 @@ class FFA : Application() { Thread.setDefaultUncaughtExceptionHandler(CrashReportHandler()) - audio.funkwhale.ffa.FFA.Companion.instance = this + FFA.Companion.instance = this when (PowerPreference.getDefaultFile().getString("night_mode")) { "on" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES) @@ -94,19 +94,20 @@ class FFA : Application() { val now = Date(Date().time - (5 * 60 * 1000)) val formatter = SimpleDateFormat("MM-dd kk:mm:ss.000", Locale.US) - Runtime.getRuntime().exec(listOf("logcat", "-d", "-T", formatter.format(now)).toTypedArray()).also { - it.inputStream.bufferedReader().also { reader -> - val builder = StringBuilder() + Runtime.getRuntime().exec(listOf("logcat", "-d", "-T", formatter.format(now)).toTypedArray()) + .also { + it.inputStream.bufferedReader().also { reader -> + val builder = StringBuilder() - while (true) { - builder.appendln(reader.readLine() ?: break) - } + while (true) { + builder.appendLine(reader.readLine() ?: break) + } - builder.appendln(e.toString()) + builder.appendLine(e.toString()) - Cache.set(this@FFA, "crashdump", builder.toString().toByteArray()) + Cache.set(this@FFA, "crashdump", builder.toString().toByteArray()) + } } - } defaultExceptionHandler?.uncaughtException(t, e) } diff --git a/app/src/main/java/audio/funkwhale/ffa/activities/DownloadsActivity.kt b/app/src/main/java/audio/funkwhale/ffa/activities/DownloadsActivity.kt index 308a6a5..49312af 100644 --- a/app/src/main/java/audio/funkwhale/ffa/activities/DownloadsActivity.kt +++ b/app/src/main/java/audio/funkwhale/ffa/activities/DownloadsActivity.kt @@ -4,6 +4,7 @@ import android.os.Bundle import androidx.appcompat.app.AppCompatActivity import androidx.lifecycle.lifecycleScope import androidx.recyclerview.widget.LinearLayoutManager +import audio.funkwhale.ffa.FFA import audio.funkwhale.ffa.adapters.DownloadsAdapter import audio.funkwhale.ffa.databinding.ActivityDownloadsBinding import audio.funkwhale.ffa.utils.Event @@ -62,7 +63,7 @@ class DownloadsActivity : AppCompatActivity() { private fun refresh() { lifecycleScope.launch(Main) { - val cursor = audio.funkwhale.ffa.FFA.get().exoDownloadManager.downloadIndex.getDownloads() + val cursor = FFA.get().exoDownloadManager.downloadIndex.getDownloads() adapter.downloads.clear() @@ -98,7 +99,7 @@ class DownloadsActivity : AppCompatActivity() { } private suspend fun refreshProgress() { - val cursor = audio.funkwhale.ffa.FFA.get().exoDownloadManager.downloadIndex.getDownloads() + val cursor = FFA.get().exoDownloadManager.downloadIndex.getDownloads() while (cursor.moveToNext()) { val download = cursor.download diff --git a/app/src/main/java/audio/funkwhale/ffa/activities/MainActivity.kt b/app/src/main/java/audio/funkwhale/ffa/activities/MainActivity.kt index 8d152f1..bfb2cf9 100644 --- a/app/src/main/java/audio/funkwhale/ffa/activities/MainActivity.kt +++ b/app/src/main/java/audio/funkwhale/ffa/activities/MainActivity.kt @@ -21,6 +21,7 @@ import androidx.fragment.app.Fragment import androidx.fragment.app.FragmentManager import androidx.lifecycle.Lifecycle import androidx.lifecycle.lifecycleScope +import audio.funkwhale.ffa.FFA import audio.funkwhale.ffa.R import audio.funkwhale.ffa.databinding.ActivityMainBinding import audio.funkwhale.ffa.fragments.* @@ -259,7 +260,7 @@ class MainActivity : AppCompatActivity() { if (resultCode == ResultCode.LOGOUT.code) { Intent(this, LoginActivity::class.java).apply { - audio.funkwhale.ffa.FFA.get().deleteAllData() + FFA.get().deleteAllData() flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP @@ -298,7 +299,7 @@ class MainActivity : AppCompatActivity() { EventBus.get().collect { message -> when (message) { is Event.LogOut -> { - audio.funkwhale.ffa.FFA.get().deleteAllData() + FFA.get().deleteAllData() startActivity(Intent(this@MainActivity, LoginActivity::class.java).apply { flags = Intent.FLAG_ACTIVITY_NO_HISTORY diff --git a/app/src/main/java/audio/funkwhale/ffa/activities/SearchActivity.kt b/app/src/main/java/audio/funkwhale/ffa/activities/SearchActivity.kt index 4d10772..b865427 100644 --- a/app/src/main/java/audio/funkwhale/ffa/activities/SearchActivity.kt +++ b/app/src/main/java/audio/funkwhale/ffa/activities/SearchActivity.kt @@ -89,9 +89,9 @@ class SearchActivity : AppCompatActivity() { val query = URLEncoder.encode(it, "UTF-8") - artistsRepository.query = query.toLowerCase(Locale.ROOT) - albumsRepository.query = query.toLowerCase(Locale.ROOT) - tracksRepository.query = query.toLowerCase(Locale.ROOT) + artistsRepository.query = query.lowercase(Locale.ROOT) + albumsRepository.query = query.lowercase(Locale.ROOT) + tracksRepository.query = query.lowercase(Locale.ROOT) binding.searchSpinner.visibility = View.VISIBLE binding.searchEmpty.visibility = View.GONE diff --git a/app/src/main/java/audio/funkwhale/ffa/activities/SettingsActivity.kt b/app/src/main/java/audio/funkwhale/ffa/activities/SettingsActivity.kt index 458ed2e..21f4081 100644 --- a/app/src/main/java/audio/funkwhale/ffa/activities/SettingsActivity.kt +++ b/app/src/main/java/audio/funkwhale/ffa/activities/SettingsActivity.kt @@ -14,6 +14,7 @@ import androidx.preference.ListPreference import androidx.preference.Preference import androidx.preference.PreferenceFragmentCompat import androidx.preference.SeekBarPreference +import audio.funkwhale.ffa.FFA import audio.funkwhale.ffa.R import audio.funkwhale.ffa.databinding.ActivitySettingsBinding import audio.funkwhale.ffa.utils.Cache @@ -97,7 +98,7 @@ class SettingsFragment : .setPositiveButton(android.R.string.yes) { _, _ -> CommandBus.send(Command.ClearQueue) - audio.funkwhale.ffa.FFA.get().deleteAllData() + FFA.get().deleteAllData() activity?.setResult(MainActivity.ResultCode.LOGOUT.code) activity?.finish() diff --git a/app/src/main/java/audio/funkwhale/ffa/activities/SplashActivity.kt b/app/src/main/java/audio/funkwhale/ffa/activities/SplashActivity.kt index 41cff2d..aa62427 100644 --- a/app/src/main/java/audio/funkwhale/ffa/activities/SplashActivity.kt +++ b/app/src/main/java/audio/funkwhale/ffa/activities/SplashActivity.kt @@ -4,6 +4,7 @@ import android.content.Context import android.content.Intent import android.os.Bundle import androidx.appcompat.app.AppCompatActivity +import audio.funkwhale.ffa.FFA import audio.funkwhale.ffa.utils.AppContext import audio.funkwhale.ffa.utils.Settings @@ -21,7 +22,7 @@ class SplashActivity : AppCompatActivity() { } false -> Intent(this@SplashActivity, LoginActivity::class.java).apply { - audio.funkwhale.ffa.FFA.get().deleteAllData() + FFA.get().deleteAllData() flags = Intent.FLAG_ACTIVITY_NO_ANIMATION diff --git a/app/src/main/java/audio/funkwhale/ffa/playback/MediaControlsManager.kt b/app/src/main/java/audio/funkwhale/ffa/playback/MediaControlsManager.kt index 377865a..78dee61 100644 --- a/app/src/main/java/audio/funkwhale/ffa/playback/MediaControlsManager.kt +++ b/app/src/main/java/audio/funkwhale/ffa/playback/MediaControlsManager.kt @@ -99,7 +99,7 @@ class MediaControlsManager(val context: Service, private val scope: CoroutineSco } } - audio.funkwhale.ffa.FFA.get().mediaSession.connector.invalidateMediaSessionMetadata() + FFA.get().mediaSession.connector.invalidateMediaSessionMetadata() } } } diff --git a/app/src/main/java/audio/funkwhale/ffa/playback/PinService.kt b/app/src/main/java/audio/funkwhale/ffa/playback/PinService.kt index 9dbe031..1c901c4 100644 --- a/app/src/main/java/audio/funkwhale/ffa/playback/PinService.kt +++ b/app/src/main/java/audio/funkwhale/ffa/playback/PinService.kt @@ -4,6 +4,17 @@ import android.app.Notification import android.content.Context import android.content.Intent import android.net.Uri +import audio.funkwhale.ffa.FFA +import audio.funkwhale.ffa.R +import audio.funkwhale.ffa.utils.AppContext +import audio.funkwhale.ffa.utils.DownloadInfo +import audio.funkwhale.ffa.utils.Event +import audio.funkwhale.ffa.utils.EventBus +import audio.funkwhale.ffa.utils.Request +import audio.funkwhale.ffa.utils.RequestBus +import audio.funkwhale.ffa.utils.Response +import audio.funkwhale.ffa.utils.Track +import audio.funkwhale.ffa.utils.mustNormalizeUrl import com.google.android.exoplayer2.offline.Download import com.google.android.exoplayer2.offline.DownloadManager import com.google.android.exoplayer2.offline.DownloadRequest @@ -16,17 +27,6 @@ import kotlinx.coroutines.Dispatchers.Main import kotlinx.coroutines.Job import kotlinx.coroutines.flow.collect import kotlinx.coroutines.launch -import audio.funkwhale.ffa.FFA -import audio.funkwhale.ffa.R -import audio.funkwhale.ffa.utils.AppContext -import audio.funkwhale.ffa.utils.DownloadInfo -import audio.funkwhale.ffa.utils.Event -import audio.funkwhale.ffa.utils.EventBus -import audio.funkwhale.ffa.utils.Request -import audio.funkwhale.ffa.utils.RequestBus -import audio.funkwhale.ffa.utils.Response -import audio.funkwhale.ffa.utils.Track -import audio.funkwhale.ffa.utils.mustNormalizeUrl import java.util.Collections class PinService : DownloadService(AppContext.NOTIFICATION_DOWNLOADS) { @@ -66,7 +66,7 @@ class PinService : DownloadService(AppContext.NOTIFICATION_DOWNLOADS) { scope.launch(Main) { RequestBus.get().collect { request -> when (request) { - is Request.GetDownloads -> request.channel?.offer(Response.Downloads(getDownloads())) + is Request.GetDownloads -> request.channel?.trySend(Response.Downloads(getDownloads()))?.isSuccess } } } @@ -74,7 +74,7 @@ class PinService : DownloadService(AppContext.NOTIFICATION_DOWNLOADS) { return super.onStartCommand(intent, flags, startId) } - override fun getDownloadManager() = audio.funkwhale.ffa.FFA.get().exoDownloadManager.apply { + override fun getDownloadManager() = FFA.get().exoDownloadManager.apply { addListener(DownloadListener()) } diff --git a/app/src/main/java/audio/funkwhale/ffa/playback/PlayerService.kt b/app/src/main/java/audio/funkwhale/ffa/playback/PlayerService.kt index 84861e7..8d5c77c 100644 --- a/app/src/main/java/audio/funkwhale/ffa/playback/PlayerService.kt +++ b/app/src/main/java/audio/funkwhale/ffa/playback/PlayerService.kt @@ -15,6 +15,9 @@ import android.support.v4.media.MediaMetadataCompat import android.view.KeyEvent import androidx.core.app.NotificationManagerCompat import androidx.media.session.MediaButtonReceiver +import audio.funkwhale.ffa.FFA +import audio.funkwhale.ffa.R +import audio.funkwhale.ffa.utils.* import com.google.android.exoplayer2.C import com.google.android.exoplayer2.ExoPlaybackException import com.google.android.exoplayer2.Player @@ -26,9 +29,6 @@ import kotlinx.coroutines.* import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.Main import kotlinx.coroutines.flow.collect -import audio.funkwhale.ffa.FFA -import audio.funkwhale.ffa.R -import audio.funkwhale.ffa.utils.* class PlayerService : Service() { companion object { @@ -63,12 +63,12 @@ class PlayerService : Service() { when (key.keyCode) { KeyEvent.KEYCODE_MEDIA_PLAY, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE -> { if (hasAudioFocus(true)) MediaButtonReceiver.handleIntent( - audio.funkwhale.ffa.FFA.get().mediaSession.session, + FFA.get().mediaSession.session, intent ) Unit } - else -> MediaButtonReceiver.handleIntent(audio.funkwhale.ffa.FFA.get().mediaSession.session, intent) + else -> MediaButtonReceiver.handleIntent(FFA.get().mediaSession.session, intent) } } } @@ -108,7 +108,7 @@ class PlayerService : Service() { } } - mediaControlsManager = MediaControlsManager(this, scope, audio.funkwhale.ffa.FFA.get().mediaSession.session) + mediaControlsManager = MediaControlsManager(this, scope, FFA.get().mediaSession.session) player = SimpleExoPlayer.Builder(this).build().apply { playWhenReady = false @@ -118,9 +118,9 @@ class PlayerService : Service() { } } - audio.funkwhale.ffa.FFA.get().mediaSession.active = true + FFA.get().mediaSession.active = true - audio.funkwhale.ffa.FFA.get().mediaSession.connector.apply { + FFA.get().mediaSession.connector.apply { setPlayer(player) setMediaMetadataProvider { @@ -216,9 +216,9 @@ class PlayerService : Service() { scope.launch(Main) { RequestBus.get().collect { request -> when (request) { - is Request.GetCurrentTrack -> request.channel?.offer(Response.CurrentTrack(queue.current())) - is Request.GetState -> request.channel?.offer(Response.State(player.playWhenReady)) - is Request.GetQueue -> request.channel?.offer(Response.Queue(queue.get())) + is Request.GetCurrentTrack -> request.channel?.trySend(Response.CurrentTrack(queue.current()))?.isSuccess + is Request.GetState -> request.channel?.trySend(Response.State(player.playWhenReady))?.isSuccess + is Request.GetQueue -> request.channel?.trySend(Response.Queue(queue.get()))?.isSuccess } } } @@ -271,7 +271,7 @@ class PlayerService : Service() { setPlaybackState(false) player.release() - audio.funkwhale.ffa.FFA.get().mediaSession.active = false + FFA.get().mediaSession.active = false super.onDestroy() } diff --git a/app/src/main/java/audio/funkwhale/ffa/playback/QueueManager.kt b/app/src/main/java/audio/funkwhale/ffa/playback/QueueManager.kt index b08d36b..16f0dc9 100644 --- a/app/src/main/java/audio/funkwhale/ffa/playback/QueueManager.kt +++ b/app/src/main/java/audio/funkwhale/ffa/playback/QueueManager.kt @@ -30,10 +30,10 @@ class QueueManager(val context: Context) { } } - val playbackCache = CacheDataSourceFactory(audio.funkwhale.ffa.FFA.get().exoCache, http) + val playbackCache = CacheDataSourceFactory(FFA.get().exoCache, http) return CacheDataSourceFactory( - audio.funkwhale.ffa.FFA.get().exoDownloadCache, + FFA.get().exoDownloadCache, playbackCache, FileDataSource.Factory(), null, diff --git a/app/src/main/java/audio/funkwhale/ffa/repositories/FavoritesRepository.kt b/app/src/main/java/audio/funkwhale/ffa/repositories/FavoritesRepository.kt index dfefb44..577c1e1 100644 --- a/app/src/main/java/audio/funkwhale/ffa/repositories/FavoritesRepository.kt +++ b/app/src/main/java/audio/funkwhale/ffa/repositories/FavoritesRepository.kt @@ -32,7 +32,7 @@ class FavoritesRepository(override val context: Context?) : Repository maybeNormalizeUrl(upload.listen_url)?.let { url -> - track.cached = audio.funkwhale.ffa.FFA.get().exoCache.isCached(url, 0, upload.duration * 1000L) + track.cached = FFA.get().exoCache.isCached(url, 0, upload.duration * 1000L) } } diff --git a/app/src/main/java/audio/funkwhale/ffa/repositories/SearchRepository.kt b/app/src/main/java/audio/funkwhale/ffa/repositories/SearchRepository.kt index 1b95516..9a98822 100644 --- a/app/src/main/java/audio/funkwhale/ffa/repositories/SearchRepository.kt +++ b/app/src/main/java/audio/funkwhale/ffa/repositories/SearchRepository.kt @@ -33,7 +33,7 @@ class TracksSearchRepository(override val context: Context?, var query: String) track.bestUpload()?.let { upload -> val url = mustNormalizeUrl(upload.listen_url) - track.cached = audio.funkwhale.ffa.FFA.get().exoCache.isCached(url, 0, upload.duration * 1000L) + track.cached = FFA.get().exoCache.isCached(url, 0, upload.duration * 1000L) } track diff --git a/app/src/main/java/audio/funkwhale/ffa/repositories/TracksRepository.kt b/app/src/main/java/audio/funkwhale/ffa/repositories/TracksRepository.kt index 6314916..6f9b857 100644 --- a/app/src/main/java/audio/funkwhale/ffa/repositories/TracksRepository.kt +++ b/app/src/main/java/audio/funkwhale/ffa/repositories/TracksRepository.kt @@ -20,7 +20,7 @@ class TracksRepository(override val context: Context?, albumId: Int) : Repositor companion object { fun getDownloadedIds(): List? { - val cursor = audio.funkwhale.ffa.FFA.get().exoDownloadManager.downloadIndex.getDownloads() + val cursor = FFA.get().exoDownloadManager.downloadIndex.getDownloads() val ids: MutableList = mutableListOf() while (cursor.moveToNext()) { @@ -52,7 +52,7 @@ class TracksRepository(override val context: Context?, albumId: Int) : Repositor track.bestUpload()?.let { upload -> val url = mustNormalizeUrl(upload.listen_url) - track.cached = audio.funkwhale.ffa.FFA.get().exoCache.isCached(url, 0, upload.duration * 1000L) + track.cached = FFA.get().exoCache.isCached(url, 0, upload.duration * 1000L) } track diff --git a/app/src/main/java/audio/funkwhale/ffa/utils/Bus.kt b/app/src/main/java/audio/funkwhale/ffa/utils/Bus.kt index 1254b07..791df86 100644 --- a/app/src/main/java/audio/funkwhale/ffa/utils/Bus.kt +++ b/app/src/main/java/audio/funkwhale/ffa/utils/Bus.kt @@ -1,5 +1,6 @@ package audio.funkwhale.ffa.utils +import audio.funkwhale.ffa.FFA import com.google.android.exoplayer2.offline.Download import com.google.android.exoplayer2.offline.DownloadCursor import kotlinx.coroutines.Dispatchers.IO @@ -70,21 +71,21 @@ sealed class Response { object EventBus { fun send(event: Event) { GlobalScope.launch(IO) { - audio.funkwhale.ffa.FFA.get().eventBus.offer(event) + FFA.get().eventBus.trySend(event).isSuccess } } - fun get() = audio.funkwhale.ffa.FFA.get().eventBus.asFlow() + fun get() = FFA.get().eventBus.asFlow() } object CommandBus { fun send(command: Command) { GlobalScope.launch(IO) { - audio.funkwhale.ffa.FFA.get().commandBus.offer(command) + FFA.get().commandBus.trySend(command).isSuccess } } - fun get() = audio.funkwhale.ffa.FFA.get().commandBus.asFlow() + fun get() = FFA.get().commandBus.asFlow() } object RequestBus { @@ -93,22 +94,22 @@ object RequestBus { GlobalScope.launch(IO) { request.channel = it - audio.funkwhale.ffa.FFA.get().requestBus.offer(request) + FFA.get().requestBus.trySend(request).isSuccess } } } - fun get() = audio.funkwhale.ffa.FFA.get().requestBus.asFlow() + fun get() = FFA.get().requestBus.asFlow() } object ProgressBus { fun send(current: Int, duration: Int, percent: Int) { GlobalScope.launch(IO) { - audio.funkwhale.ffa.FFA.get().progressBus.send(Triple(current, duration, percent)) + FFA.get().progressBus.send(Triple(current, duration, percent)) } } - fun get() = audio.funkwhale.ffa.FFA.get().progressBus.asFlow().conflate() + fun get() = FFA.get().progressBus.asFlow().conflate() } suspend inline fun Channel.wait(): T? {