Browse Source

Merge branch 'housekeeping/remove-warnings' into 'develop'

Remove build warnings

See merge request funkwhale/funkwhale-android!42
enhancement/speed-up-pipelines
Ryan Harg 3 years ago
parent
commit
5bf8e8ed15
  1. 31
      app/src/main/java/audio/funkwhale/ffa/FFA.kt
  2. 5
      app/src/main/java/audio/funkwhale/ffa/activities/DownloadsActivity.kt
  3. 5
      app/src/main/java/audio/funkwhale/ffa/activities/MainActivity.kt
  4. 6
      app/src/main/java/audio/funkwhale/ffa/activities/SearchActivity.kt
  5. 3
      app/src/main/java/audio/funkwhale/ffa/activities/SettingsActivity.kt
  6. 3
      app/src/main/java/audio/funkwhale/ffa/activities/SplashActivity.kt
  7. 2
      app/src/main/java/audio/funkwhale/ffa/playback/MediaControlsManager.kt
  8. 26
      app/src/main/java/audio/funkwhale/ffa/playback/PinService.kt
  9. 24
      app/src/main/java/audio/funkwhale/ffa/playback/PlayerService.kt
  10. 4
      app/src/main/java/audio/funkwhale/ffa/playback/QueueManager.kt
  11. 2
      app/src/main/java/audio/funkwhale/ffa/repositories/FavoritesRepository.kt
  12. 2
      app/src/main/java/audio/funkwhale/ffa/repositories/SearchRepository.kt
  13. 4
      app/src/main/java/audio/funkwhale/ffa/repositories/TracksRepository.kt
  14. 17
      app/src/main/java/audio/funkwhale/ffa/utils/Bus.kt

31
app/src/main/java/audio/funkwhale/ffa/FFA.kt

@ -2,6 +2,9 @@ package audio.funkwhale.ffa @@ -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 @@ -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() { @@ -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() { @@ -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)
}

5
app/src/main/java/audio/funkwhale/ffa/activities/DownloadsActivity.kt

@ -4,6 +4,7 @@ import android.os.Bundle @@ -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() { @@ -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() { @@ -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

5
app/src/main/java/audio/funkwhale/ffa/activities/MainActivity.kt

@ -21,6 +21,7 @@ import androidx.fragment.app.Fragment @@ -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() { @@ -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() { @@ -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

6
app/src/main/java/audio/funkwhale/ffa/activities/SearchActivity.kt

@ -89,9 +89,9 @@ class SearchActivity : AppCompatActivity() { @@ -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

3
app/src/main/java/audio/funkwhale/ffa/activities/SettingsActivity.kt

@ -14,6 +14,7 @@ import androidx.preference.ListPreference @@ -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 : @@ -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()

3
app/src/main/java/audio/funkwhale/ffa/activities/SplashActivity.kt

@ -4,6 +4,7 @@ import android.content.Context @@ -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() { @@ -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

2
app/src/main/java/audio/funkwhale/ffa/playback/MediaControlsManager.kt

@ -99,7 +99,7 @@ class MediaControlsManager(val context: Service, private val scope: CoroutineSco @@ -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()
}
}
}

26
app/src/main/java/audio/funkwhale/ffa/playback/PinService.kt

@ -4,6 +4,17 @@ import android.app.Notification @@ -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 @@ -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) { @@ -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) { @@ -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())
}

24
app/src/main/java/audio/funkwhale/ffa/playback/PlayerService.kt

@ -15,6 +15,9 @@ import android.support.v4.media.MediaMetadataCompat @@ -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.* @@ -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() { @@ -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() { @@ -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() { @@ -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() { @@ -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() { @@ -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()
}

4
app/src/main/java/audio/funkwhale/ffa/playback/QueueManager.kt

@ -30,10 +30,10 @@ class QueueManager(val context: Context) { @@ -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,

2
app/src/main/java/audio/funkwhale/ffa/repositories/FavoritesRepository.kt

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

2
app/src/main/java/audio/funkwhale/ffa/repositories/SearchRepository.kt

@ -33,7 +33,7 @@ class TracksSearchRepository(override val context: Context?, var query: String) @@ -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

4
app/src/main/java/audio/funkwhale/ffa/repositories/TracksRepository.kt

@ -20,7 +20,7 @@ class TracksRepository(override val context: Context?, albumId: Int) : Repositor @@ -20,7 +20,7 @@ class TracksRepository(override val context: Context?, albumId: Int) : Repositor
companion object {
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()
while (cursor.moveToNext()) {
@ -52,7 +52,7 @@ class TracksRepository(override val context: Context?, albumId: Int) : Repositor @@ -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

17
app/src/main/java/audio/funkwhale/ffa/utils/Bus.kt

@ -1,5 +1,6 @@ @@ -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 { @@ -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 { @@ -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 <reified T> Channel<Response>.wait(): T? {

Loading…
Cancel
Save