Remove build warnings

housekeeping/remove-warnings
Ryan Harg 2021-07-21 09:11:07 +02:00 zatwierdzone przez Ryan Harg
rodzic b1913f3ca5
commit d2497c7217
14 zmienionych plików z 71 dodań i 65 usunięć

Wyświetl plik

@ -2,6 +2,9 @@ package audio.funkwhale.ffa
import android.app.Application import android.app.Application
import androidx.appcompat.app.AppCompatDelegate 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.database.ExoDatabaseProvider
import com.google.android.exoplayer2.offline.DefaultDownloadIndex import com.google.android.exoplayer2.offline.DefaultDownloadIndex
import com.google.android.exoplayer2.offline.DefaultDownloaderFactory import com.google.android.exoplayer2.offline.DefaultDownloaderFactory
@ -13,17 +16,14 @@ import com.google.android.exoplayer2.upstream.cache.SimpleCache
import com.preference.PowerPreference import com.preference.PowerPreference
import kotlinx.coroutines.channels.BroadcastChannel import kotlinx.coroutines.channels.BroadcastChannel
import kotlinx.coroutines.channels.ConflatedBroadcastChannel 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.text.SimpleDateFormat
import java.util.* import java.util.*
class FFA : Application() { class FFA : Application() {
companion object { 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 var defaultExceptionHandler: Thread.UncaughtExceptionHandler? = null
@ -70,7 +70,7 @@ class FFA : Application() {
Thread.setDefaultUncaughtExceptionHandler(CrashReportHandler()) Thread.setDefaultUncaughtExceptionHandler(CrashReportHandler())
audio.funkwhale.ffa.FFA.Companion.instance = this FFA.Companion.instance = this
when (PowerPreference.getDefaultFile().getString("night_mode")) { when (PowerPreference.getDefaultFile().getString("night_mode")) {
"on" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES) "on" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
@ -94,19 +94,20 @@ class FFA : Application() {
val now = Date(Date().time - (5 * 60 * 1000)) val now = Date(Date().time - (5 * 60 * 1000))
val formatter = SimpleDateFormat("MM-dd kk:mm:ss.000", Locale.US) val formatter = SimpleDateFormat("MM-dd kk:mm:ss.000", Locale.US)
Runtime.getRuntime().exec(listOf("logcat", "-d", "-T", formatter.format(now)).toTypedArray()).also { Runtime.getRuntime().exec(listOf("logcat", "-d", "-T", formatter.format(now)).toTypedArray())
it.inputStream.bufferedReader().also { reader -> .also {
val builder = StringBuilder() it.inputStream.bufferedReader().also { reader ->
val builder = StringBuilder()
while (true) { while (true) {
builder.appendln(reader.readLine() ?: break) builder.appendLine(reader.readLine() ?: break)
}
builder.appendLine(e.toString())
Cache.set(this@FFA, "crashdump", builder.toString().toByteArray())
} }
builder.appendln(e.toString())
Cache.set(this@FFA, "crashdump", builder.toString().toByteArray())
} }
}
defaultExceptionHandler?.uncaughtException(t, e) defaultExceptionHandler?.uncaughtException(t, e)
} }

Wyświetl plik

@ -4,6 +4,7 @@ import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import audio.funkwhale.ffa.FFA
import audio.funkwhale.ffa.adapters.DownloadsAdapter import audio.funkwhale.ffa.adapters.DownloadsAdapter
import audio.funkwhale.ffa.databinding.ActivityDownloadsBinding import audio.funkwhale.ffa.databinding.ActivityDownloadsBinding
import audio.funkwhale.ffa.utils.Event import audio.funkwhale.ffa.utils.Event
@ -62,7 +63,7 @@ class DownloadsActivity : AppCompatActivity() {
private fun refresh() { private fun refresh() {
lifecycleScope.launch(Main) { lifecycleScope.launch(Main) {
val cursor = audio.funkwhale.ffa.FFA.get().exoDownloadManager.downloadIndex.getDownloads() val cursor = FFA.get().exoDownloadManager.downloadIndex.getDownloads()
adapter.downloads.clear() adapter.downloads.clear()
@ -98,7 +99,7 @@ class DownloadsActivity : AppCompatActivity() {
} }
private suspend fun refreshProgress() { private suspend fun refreshProgress() {
val cursor = audio.funkwhale.ffa.FFA.get().exoDownloadManager.downloadIndex.getDownloads() val cursor = FFA.get().exoDownloadManager.downloadIndex.getDownloads()
while (cursor.moveToNext()) { while (cursor.moveToNext()) {
val download = cursor.download val download = cursor.download

Wyświetl plik

@ -21,6 +21,7 @@ import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager import androidx.fragment.app.FragmentManager
import androidx.lifecycle.Lifecycle import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import audio.funkwhale.ffa.FFA
import audio.funkwhale.ffa.R import audio.funkwhale.ffa.R
import audio.funkwhale.ffa.databinding.ActivityMainBinding import audio.funkwhale.ffa.databinding.ActivityMainBinding
import audio.funkwhale.ffa.fragments.* import audio.funkwhale.ffa.fragments.*
@ -259,7 +260,7 @@ class MainActivity : AppCompatActivity() {
if (resultCode == ResultCode.LOGOUT.code) { if (resultCode == ResultCode.LOGOUT.code) {
Intent(this, LoginActivity::class.java).apply { Intent(this, LoginActivity::class.java).apply {
audio.funkwhale.ffa.FFA.get().deleteAllData() FFA.get().deleteAllData()
flags = flags =
Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP 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 -> EventBus.get().collect { message ->
when (message) { when (message) {
is Event.LogOut -> { is Event.LogOut -> {
audio.funkwhale.ffa.FFA.get().deleteAllData() FFA.get().deleteAllData()
startActivity(Intent(this@MainActivity, LoginActivity::class.java).apply { startActivity(Intent(this@MainActivity, LoginActivity::class.java).apply {
flags = Intent.FLAG_ACTIVITY_NO_HISTORY flags = Intent.FLAG_ACTIVITY_NO_HISTORY

Wyświetl plik

@ -89,9 +89,9 @@ class SearchActivity : AppCompatActivity() {
val query = URLEncoder.encode(it, "UTF-8") val query = URLEncoder.encode(it, "UTF-8")
artistsRepository.query = query.toLowerCase(Locale.ROOT) artistsRepository.query = query.lowercase(Locale.ROOT)
albumsRepository.query = query.toLowerCase(Locale.ROOT) albumsRepository.query = query.lowercase(Locale.ROOT)
tracksRepository.query = query.toLowerCase(Locale.ROOT) tracksRepository.query = query.lowercase(Locale.ROOT)
binding.searchSpinner.visibility = View.VISIBLE binding.searchSpinner.visibility = View.VISIBLE
binding.searchEmpty.visibility = View.GONE binding.searchEmpty.visibility = View.GONE

Wyświetl plik

@ -14,6 +14,7 @@ import androidx.preference.ListPreference
import androidx.preference.Preference import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat import androidx.preference.PreferenceFragmentCompat
import androidx.preference.SeekBarPreference import androidx.preference.SeekBarPreference
import audio.funkwhale.ffa.FFA
import audio.funkwhale.ffa.R import audio.funkwhale.ffa.R
import audio.funkwhale.ffa.databinding.ActivitySettingsBinding import audio.funkwhale.ffa.databinding.ActivitySettingsBinding
import audio.funkwhale.ffa.utils.Cache import audio.funkwhale.ffa.utils.Cache
@ -97,7 +98,7 @@ class SettingsFragment :
.setPositiveButton(android.R.string.yes) { _, _ -> .setPositiveButton(android.R.string.yes) { _, _ ->
CommandBus.send(Command.ClearQueue) CommandBus.send(Command.ClearQueue)
audio.funkwhale.ffa.FFA.get().deleteAllData() FFA.get().deleteAllData()
activity?.setResult(MainActivity.ResultCode.LOGOUT.code) activity?.setResult(MainActivity.ResultCode.LOGOUT.code)
activity?.finish() activity?.finish()

Wyświetl plik

@ -4,6 +4,7 @@ import android.content.Context
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import audio.funkwhale.ffa.FFA
import audio.funkwhale.ffa.utils.AppContext import audio.funkwhale.ffa.utils.AppContext
import audio.funkwhale.ffa.utils.Settings import audio.funkwhale.ffa.utils.Settings
@ -21,7 +22,7 @@ class SplashActivity : AppCompatActivity() {
} }
false -> Intent(this@SplashActivity, LoginActivity::class.java).apply { false -> Intent(this@SplashActivity, LoginActivity::class.java).apply {
audio.funkwhale.ffa.FFA.get().deleteAllData() FFA.get().deleteAllData()
flags = Intent.FLAG_ACTIVITY_NO_ANIMATION flags = Intent.FLAG_ACTIVITY_NO_ANIMATION

Wyświetl plik

@ -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()
} }
} }
} }

Wyświetl plik

@ -4,6 +4,17 @@ import android.app.Notification
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.net.Uri 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.Download
import com.google.android.exoplayer2.offline.DownloadManager import com.google.android.exoplayer2.offline.DownloadManager
import com.google.android.exoplayer2.offline.DownloadRequest import com.google.android.exoplayer2.offline.DownloadRequest
@ -16,17 +27,6 @@ import kotlinx.coroutines.Dispatchers.Main
import kotlinx.coroutines.Job import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.collect import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch 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 import java.util.Collections
class PinService : DownloadService(AppContext.NOTIFICATION_DOWNLOADS) { class PinService : DownloadService(AppContext.NOTIFICATION_DOWNLOADS) {
@ -66,7 +66,7 @@ class PinService : DownloadService(AppContext.NOTIFICATION_DOWNLOADS) {
scope.launch(Main) { scope.launch(Main) {
RequestBus.get().collect { request -> RequestBus.get().collect { request ->
when (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) 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()) addListener(DownloadListener())
} }

Wyświetl plik

@ -15,6 +15,9 @@ import android.support.v4.media.MediaMetadataCompat
import android.view.KeyEvent import android.view.KeyEvent
import androidx.core.app.NotificationManagerCompat import androidx.core.app.NotificationManagerCompat
import androidx.media.session.MediaButtonReceiver 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.C
import com.google.android.exoplayer2.ExoPlaybackException import com.google.android.exoplayer2.ExoPlaybackException
import com.google.android.exoplayer2.Player import com.google.android.exoplayer2.Player
@ -26,9 +29,6 @@ import kotlinx.coroutines.*
import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.Dispatchers.Main import kotlinx.coroutines.Dispatchers.Main
import kotlinx.coroutines.flow.collect import kotlinx.coroutines.flow.collect
import audio.funkwhale.ffa.FFA
import audio.funkwhale.ffa.R
import audio.funkwhale.ffa.utils.*
class PlayerService : Service() { class PlayerService : Service() {
companion object { companion object {
@ -63,12 +63,12 @@ class PlayerService : Service() {
when (key.keyCode) { when (key.keyCode) {
KeyEvent.KEYCODE_MEDIA_PLAY, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE -> { KeyEvent.KEYCODE_MEDIA_PLAY, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE -> {
if (hasAudioFocus(true)) MediaButtonReceiver.handleIntent( if (hasAudioFocus(true)) MediaButtonReceiver.handleIntent(
audio.funkwhale.ffa.FFA.get().mediaSession.session, FFA.get().mediaSession.session,
intent intent
) )
Unit 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 { player = SimpleExoPlayer.Builder(this).build().apply {
playWhenReady = false 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) setPlayer(player)
setMediaMetadataProvider { setMediaMetadataProvider {
@ -216,9 +216,9 @@ class PlayerService : Service() {
scope.launch(Main) { scope.launch(Main) {
RequestBus.get().collect { request -> RequestBus.get().collect { request ->
when (request) { when (request) {
is Request.GetCurrentTrack -> request.channel?.offer(Response.CurrentTrack(queue.current())) is Request.GetCurrentTrack -> request.channel?.trySend(Response.CurrentTrack(queue.current()))?.isSuccess
is Request.GetState -> request.channel?.offer(Response.State(player.playWhenReady)) is Request.GetState -> request.channel?.trySend(Response.State(player.playWhenReady))?.isSuccess
is Request.GetQueue -> request.channel?.offer(Response.Queue(queue.get())) is Request.GetQueue -> request.channel?.trySend(Response.Queue(queue.get()))?.isSuccess
} }
} }
} }
@ -271,7 +271,7 @@ class PlayerService : Service() {
setPlaybackState(false) setPlaybackState(false)
player.release() player.release()
audio.funkwhale.ffa.FFA.get().mediaSession.active = false FFA.get().mediaSession.active = false
super.onDestroy() super.onDestroy()
} }

Wyświetl plik

@ -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( return CacheDataSourceFactory(
audio.funkwhale.ffa.FFA.get().exoDownloadCache, FFA.get().exoDownloadCache,
playbackCache, playbackCache,
FileDataSource.Factory(), FileDataSource.Factory(),
null, null,

Wyświetl plik

@ -32,7 +32,7 @@ class FavoritesRepository(override val context: Context?) : Repository<Track, Tr
track.bestUpload()?.let { upload -> track.bestUpload()?.let { upload ->
maybeNormalizeUrl(upload.listen_url)?.let { url -> 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)
} }
} }

Wyświetl plik

@ -33,7 +33,7 @@ class TracksSearchRepository(override val context: Context?, var query: String)
track.bestUpload()?.let { upload -> track.bestUpload()?.let { upload ->
val url = mustNormalizeUrl(upload.listen_url) 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 track

Wyświetl plik

@ -20,7 +20,7 @@ class TracksRepository(override val context: Context?, albumId: Int) : Repositor
companion object { companion object {
fun getDownloadedIds(): List<Int>? { fun getDownloadedIds(): List<Int>? {
val cursor = audio.funkwhale.ffa.FFA.get().exoDownloadManager.downloadIndex.getDownloads() val cursor = FFA.get().exoDownloadManager.downloadIndex.getDownloads()
val ids: MutableList<Int> = mutableListOf() val ids: MutableList<Int> = mutableListOf()
while (cursor.moveToNext()) { while (cursor.moveToNext()) {
@ -52,7 +52,7 @@ class TracksRepository(override val context: Context?, albumId: Int) : Repositor
track.bestUpload()?.let { upload -> track.bestUpload()?.let { upload ->
val url = mustNormalizeUrl(upload.listen_url) 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 track

Wyświetl plik

@ -1,5 +1,6 @@
package audio.funkwhale.ffa.utils package audio.funkwhale.ffa.utils
import audio.funkwhale.ffa.FFA
import com.google.android.exoplayer2.offline.Download import com.google.android.exoplayer2.offline.Download
import com.google.android.exoplayer2.offline.DownloadCursor import com.google.android.exoplayer2.offline.DownloadCursor
import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.IO
@ -70,21 +71,21 @@ sealed class Response {
object EventBus { object EventBus {
fun send(event: Event) { fun send(event: Event) {
GlobalScope.launch(IO) { 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 { object CommandBus {
fun send(command: Command) { fun send(command: Command) {
GlobalScope.launch(IO) { 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 { object RequestBus {
@ -93,22 +94,22 @@ object RequestBus {
GlobalScope.launch(IO) { GlobalScope.launch(IO) {
request.channel = it 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 { object ProgressBus {
fun send(current: Int, duration: Int, percent: Int) { fun send(current: Int, duration: Int, percent: Int) {
GlobalScope.launch(IO) { 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 <reified T> Channel<Response>.wait(): T? { suspend inline fun <reified T> Channel<Response>.wait(): T? {