Browse Source

Fix existing linting problems

housekeeping/mavenCentral
Ryan Harg 3 years ago
parent
commit
ef3387dee0
No known key found for this signature in database
GPG Key ID: 89106F3A84E6958C
  1. 6
      app/build.gradle.kts
  2. 9
      app/src/main/java/audio/funkwhale/ffa/FFA.kt
  3. 6
      app/src/main/java/audio/funkwhale/ffa/activities/DownloadsActivity.kt
  4. 3
      app/src/main/java/audio/funkwhale/ffa/activities/LicencesActivity.kt
  5. 5
      app/src/main/java/audio/funkwhale/ffa/activities/LoginActivity.kt
  6. 49
      app/src/main/java/audio/funkwhale/ffa/activities/MainActivity.kt
  7. 15
      app/src/main/java/audio/funkwhale/ffa/activities/SearchActivity.kt
  8. 6
      app/src/main/java/audio/funkwhale/ffa/activities/SettingsActivity.kt
  9. 4
      app/src/main/java/audio/funkwhale/ffa/activities/SplashActivity.kt
  10. 11
      app/src/main/java/audio/funkwhale/ffa/adapters/BrowseTabsAdapter.kt
  11. 2
      app/src/main/java/audio/funkwhale/ffa/adapters/DownloadsAdapter.kt
  12. 2
      app/src/main/java/audio/funkwhale/ffa/adapters/FavoritesAdapter.kt
  13. 4
      app/src/main/java/audio/funkwhale/ffa/adapters/PlaylistTracksAdapter.kt
  14. 11
      app/src/main/java/audio/funkwhale/ffa/adapters/RadiosAdapter.kt
  15. 41
      app/src/main/java/audio/funkwhale/ffa/adapters/SearchAdapter.kt
  16. 2
      app/src/main/java/audio/funkwhale/ffa/adapters/TracksAdapter.kt
  17. 10
      app/src/main/java/audio/funkwhale/ffa/fragments/AddToPlaylistDialog.kt
  18. 7
      app/src/main/java/audio/funkwhale/ffa/fragments/AlbumsFragment.kt
  19. 2
      app/src/main/java/audio/funkwhale/ffa/fragments/AlbumsGridFragment.kt
  20. 5
      app/src/main/java/audio/funkwhale/ffa/fragments/FFAFragment.kt
  21. 10
      app/src/main/java/audio/funkwhale/ffa/fragments/FavoritesFragment.kt
  22. 10
      app/src/main/java/audio/funkwhale/ffa/fragments/PlaylistTracksFragment.kt
  23. 2
      app/src/main/java/audio/funkwhale/ffa/fragments/PlaylistsFragment.kt
  24. 2
      app/src/main/java/audio/funkwhale/ffa/fragments/RadiosFragment.kt
  25. 19
      app/src/main/java/audio/funkwhale/ffa/fragments/TracksFragment.kt
  26. 8
      app/src/main/java/audio/funkwhale/ffa/playback/CacheDataSourceFactoryProvider.kt
  27. 2
      app/src/main/java/audio/funkwhale/ffa/playback/MediaControlsManager.kt
  28. 6
      app/src/main/java/audio/funkwhale/ffa/playback/MediaSession.kt
  29. 8
      app/src/main/java/audio/funkwhale/ffa/playback/OAuth2Datasource.kt
  30. 10
      app/src/main/java/audio/funkwhale/ffa/playback/PinService.kt
  31. 30
      app/src/main/java/audio/funkwhale/ffa/playback/PlayerService.kt
  32. 14
      app/src/main/java/audio/funkwhale/ffa/playback/QueueManager.kt
  33. 11
      app/src/main/java/audio/funkwhale/ffa/playback/RadioPlayer.kt
  34. 15
      app/src/main/java/audio/funkwhale/ffa/repositories/FavoritesRepository.kt
  35. 9
      app/src/main/java/audio/funkwhale/ffa/repositories/HttpUpstream.kt
  36. 6
      app/src/main/java/audio/funkwhale/ffa/repositories/PlaylistsRepository.kt
  37. 10
      app/src/main/java/audio/funkwhale/ffa/repositories/Repository.kt
  38. 13
      app/src/main/java/audio/funkwhale/ffa/repositories/SearchRepository.kt
  39. 2
      app/src/main/java/audio/funkwhale/ffa/utils/Extensions.kt
  40. 17
      app/src/main/java/audio/funkwhale/ffa/utils/OAuth.kt
  41. 5
      app/src/test/java/audio/funkwhale/ffa/activities/SplashActivityTest.kt

6
app/build.gradle.kts

@ -241,13 +241,15 @@ project.afterEvaluate { @@ -241,13 +241,15 @@ project.afterEvaluate {
sourceDirectories.setFrom(files(listOf(mainSrc)))
classDirectories.setFrom(files(listOf(debugTree)))
executionData.setFrom(fileTree(project.buildDir) {
executionData.setFrom(
fileTree(project.buildDir) {
setIncludes(
listOf(
"outputs/unit_test_code_coverage/debugUnitTest/*.exec",
"outputs/code_coverage/debugAndroidTest/connected/**/*.ec"
)
)
})
}
)
}
}

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

@ -5,13 +5,18 @@ import android.content.Context @@ -5,13 +5,18 @@ import android.content.Context
import androidx.appcompat.app.AppCompatDelegate
import audio.funkwhale.ffa.koin.authModule
import audio.funkwhale.ffa.koin.exoplayerModule
import audio.funkwhale.ffa.utils.*
import audio.funkwhale.ffa.utils.AppContext
import audio.funkwhale.ffa.utils.Command
import audio.funkwhale.ffa.utils.Event
import audio.funkwhale.ffa.utils.FFACache
import audio.funkwhale.ffa.utils.Request
import com.preference.PowerPreference
import kotlinx.coroutines.channels.BroadcastChannel
import kotlinx.coroutines.channels.ConflatedBroadcastChannel
import org.koin.core.context.startKoin
import java.text.SimpleDateFormat
import java.util.*
import java.util.Date
import java.util.Locale
class FFA : Application() {

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

@ -73,9 +73,9 @@ class DownloadsActivity : AppCompatActivity() { @@ -73,9 +73,9 @@ class DownloadsActivity : AppCompatActivity() {
val download = cursor.download
download.getMetadata()?.let { info ->
adapter.downloads.add(info.apply {
this.download = download
})
adapter.downloads.add(
info.apply { this.download = download }
)
}
}

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

@ -90,7 +90,8 @@ class LicencesActivity : AppCompatActivity() { @@ -90,7 +90,8 @@ class LicencesActivity : AppCompatActivity() {
holder.licence.text = item.licence
}
inner class ViewHolder(binding: RowLicenceBinding) : RecyclerView.ViewHolder(binding.root),
inner class ViewHolder(binding: RowLicenceBinding) :
RecyclerView.ViewHolder(binding.root),
View.OnClickListener {
val name = binding.name
val licence = binding.licence

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

@ -11,7 +11,10 @@ import androidx.lifecycle.lifecycleScope @@ -11,7 +11,10 @@ import androidx.lifecycle.lifecycleScope
import audio.funkwhale.ffa.R
import audio.funkwhale.ffa.databinding.ActivityLoginBinding
import audio.funkwhale.ffa.fragments.LoginDialog
import audio.funkwhale.ffa.utils.*
import audio.funkwhale.ffa.utils.AppContext
import audio.funkwhale.ffa.utils.FuelResult
import audio.funkwhale.ffa.utils.OAuth
import audio.funkwhale.ffa.utils.Userinfo
import com.github.kittinunf.fuel.Fuel
import com.github.kittinunf.fuel.coroutines.awaitObjectResponseResult
import com.github.kittinunf.fuel.gson.gsonDeserializerOf

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

@ -9,7 +9,11 @@ import android.graphics.Bitmap @@ -9,7 +9,11 @@ import android.graphics.Bitmap
import android.os.Build
import android.os.Bundle
import android.util.DisplayMetrics
import android.view.*
import android.view.Gravity
import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import android.view.animation.AccelerateDecelerateInterpolator
import android.widget.SeekBar
import androidx.appcompat.app.AppCompatActivity
@ -24,7 +28,13 @@ import androidx.lifecycle.lifecycleScope @@ -24,7 +28,13 @@ 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.*
import audio.funkwhale.ffa.fragments.AddToPlaylistDialog
import audio.funkwhale.ffa.fragments.AlbumsFragment
import audio.funkwhale.ffa.fragments.ArtistsFragment
import audio.funkwhale.ffa.fragments.BrowseFragment
import audio.funkwhale.ffa.fragments.LandscapeQueueFragment
import audio.funkwhale.ffa.fragments.QueueFragment
import audio.funkwhale.ffa.fragments.TrackInfoDetailsFragment
import audio.funkwhale.ffa.model.Track
import audio.funkwhale.ffa.playback.MediaControlsManager
import audio.funkwhale.ffa.playback.PinService
@ -32,7 +42,25 @@ import audio.funkwhale.ffa.playback.PlayerService @@ -32,7 +42,25 @@ import audio.funkwhale.ffa.playback.PlayerService
import audio.funkwhale.ffa.repositories.FavoritedRepository
import audio.funkwhale.ffa.repositories.FavoritesRepository
import audio.funkwhale.ffa.repositories.Repository
import audio.funkwhale.ffa.utils.*
import audio.funkwhale.ffa.utils.AppContext
import audio.funkwhale.ffa.utils.Command
import audio.funkwhale.ffa.utils.CommandBus
import audio.funkwhale.ffa.utils.Event
import audio.funkwhale.ffa.utils.EventBus
import audio.funkwhale.ffa.utils.FFACache
import audio.funkwhale.ffa.utils.OAuth
import audio.funkwhale.ffa.utils.ProgressBus
import audio.funkwhale.ffa.utils.Settings
import audio.funkwhale.ffa.utils.Userinfo
import audio.funkwhale.ffa.utils.authorize
import audio.funkwhale.ffa.utils.log
import audio.funkwhale.ffa.utils.logError
import audio.funkwhale.ffa.utils.maybeLoad
import audio.funkwhale.ffa.utils.maybeNormalizeUrl
import audio.funkwhale.ffa.utils.mustNormalizeUrl
import audio.funkwhale.ffa.utils.onApi
import audio.funkwhale.ffa.utils.toast
import audio.funkwhale.ffa.utils.untilNetwork
import audio.funkwhale.ffa.views.DisableableFrameLayout
import com.github.kittinunf.fuel.Fuel
import com.github.kittinunf.fuel.coroutines.awaitStringResponse
@ -303,9 +331,11 @@ class MainActivity : AppCompatActivity() { @@ -303,9 +331,11 @@ class MainActivity : AppCompatActivity() {
when (message) {
is Event.LogOut -> {
FFA.get().deleteAllData(this@MainActivity)
startActivity(Intent(this@MainActivity, LoginActivity::class.java).apply {
startActivity(
Intent(this@MainActivity, LoginActivity::class.java).apply {
flags = Intent.FLAG_ACTIVITY_NO_HISTORY
})
}
)
finish()
}
@ -385,12 +415,15 @@ class MainActivity : AppCompatActivity() { @@ -385,12 +415,15 @@ class MainActivity : AppCompatActivity() {
PlayerService::class.java
).apply {
putExtra(PlayerService.INITIAL_COMMAND_KEY, command.command.toString())
})
}
)
},
{
startService(Intent(this@MainActivity, PlayerService::class.java).apply {
startService(
Intent(this@MainActivity, PlayerService::class.java).apply {
putExtra(PlayerService.INITIAL_COMMAND_KEY, command.command.toString())
})
}
)
}
)
}

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

@ -13,15 +13,24 @@ import audio.funkwhale.ffa.fragments.AlbumsFragment @@ -13,15 +13,24 @@ import audio.funkwhale.ffa.fragments.AlbumsFragment
import audio.funkwhale.ffa.fragments.ArtistsFragment
import audio.funkwhale.ffa.model.Album
import audio.funkwhale.ffa.model.Artist
import audio.funkwhale.ffa.repositories.*
import audio.funkwhale.ffa.utils.*
import audio.funkwhale.ffa.repositories.AlbumsSearchRepository
import audio.funkwhale.ffa.repositories.ArtistsSearchRepository
import audio.funkwhale.ffa.repositories.FavoritesRepository
import audio.funkwhale.ffa.repositories.Repository
import audio.funkwhale.ffa.repositories.TracksSearchRepository
import audio.funkwhale.ffa.utils.Command
import audio.funkwhale.ffa.utils.CommandBus
import audio.funkwhale.ffa.utils.Event
import audio.funkwhale.ffa.utils.EventBus
import audio.funkwhale.ffa.utils.getMetadata
import audio.funkwhale.ffa.utils.untilNetwork
import com.google.android.exoplayer2.offline.Download
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.net.URLEncoder
import java.util.*
import java.util.Locale
class SearchActivity : AppCompatActivity() {
private lateinit var adapter: SearchAdapter

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

@ -1,6 +1,10 @@ @@ -1,6 +1,10 @@
package audio.funkwhale.ffa.activities
import android.content.*
import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.content.Intent
import android.content.SharedPreferences
import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AlertDialog

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

@ -6,7 +6,9 @@ import android.os.Bundle @@ -6,7 +6,9 @@ import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import audio.funkwhale.ffa.FFA
import audio.funkwhale.ffa.utils.*
import audio.funkwhale.ffa.utils.AppContext
import audio.funkwhale.ffa.utils.OAuth
import audio.funkwhale.ffa.utils.Settings
import org.koin.java.KoinJavaComponent.inject
class SplashActivity : AppCompatActivity() {

11
app/src/main/java/audio/funkwhale/ffa/adapters/BrowseTabsAdapter.kt

@ -4,9 +4,14 @@ import androidx.fragment.app.Fragment @@ -4,9 +4,14 @@ import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentPagerAdapter
import audio.funkwhale.ffa.R
import audio.funkwhale.ffa.fragments.*
class BrowseTabsAdapter(val context: Fragment, manager: FragmentManager) : FragmentPagerAdapter(manager, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) {
import audio.funkwhale.ffa.fragments.AlbumsGridFragment
import audio.funkwhale.ffa.fragments.ArtistsFragment
import audio.funkwhale.ffa.fragments.FavoritesFragment
import audio.funkwhale.ffa.fragments.PlaylistsFragment
import audio.funkwhale.ffa.fragments.RadiosFragment
class BrowseTabsAdapter(val context: Fragment, manager: FragmentManager) :
FragmentPagerAdapter(manager, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) {
var tabs = mutableListOf<Fragment>()
override fun getCount() = 5

2
app/src/main/java/audio/funkwhale/ffa/adapters/DownloadsAdapter.kt

@ -8,9 +8,9 @@ import android.view.ViewGroup @@ -8,9 +8,9 @@ import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import audio.funkwhale.ffa.R
import audio.funkwhale.ffa.databinding.RowDownloadBinding
import audio.funkwhale.ffa.playback.PinService
import audio.funkwhale.ffa.model.DownloadInfo
import audio.funkwhale.ffa.model.Track
import audio.funkwhale.ffa.playback.PinService
import com.google.android.exoplayer2.offline.Download
import com.google.android.exoplayer2.offline.DownloadService

2
app/src/main/java/audio/funkwhale/ffa/adapters/FavoritesAdapter.kt

@ -13,9 +13,9 @@ import androidx.recyclerview.widget.RecyclerView @@ -13,9 +13,9 @@ import androidx.recyclerview.widget.RecyclerView
import audio.funkwhale.ffa.R
import audio.funkwhale.ffa.databinding.RowTrackBinding
import audio.funkwhale.ffa.fragments.FFAAdapter
import audio.funkwhale.ffa.model.Track
import audio.funkwhale.ffa.utils.Command
import audio.funkwhale.ffa.utils.CommandBus
import audio.funkwhale.ffa.model.Track
import audio.funkwhale.ffa.utils.maybeLoad
import audio.funkwhale.ffa.utils.maybeNormalizeUrl
import audio.funkwhale.ffa.utils.toast

4
app/src/main/java/audio/funkwhale/ffa/adapters/PlaylistTracksAdapter.kt

@ -16,10 +16,10 @@ import androidx.recyclerview.widget.RecyclerView @@ -16,10 +16,10 @@ import androidx.recyclerview.widget.RecyclerView
import audio.funkwhale.ffa.R
import audio.funkwhale.ffa.databinding.RowTrackBinding
import audio.funkwhale.ffa.fragments.FFAAdapter
import audio.funkwhale.ffa.utils.Command
import audio.funkwhale.ffa.utils.CommandBus
import audio.funkwhale.ffa.model.PlaylistTrack
import audio.funkwhale.ffa.model.Track
import audio.funkwhale.ffa.utils.Command
import audio.funkwhale.ffa.utils.CommandBus
import audio.funkwhale.ffa.utils.maybeLoad
import audio.funkwhale.ffa.utils.maybeNormalizeUrl
import audio.funkwhale.ffa.utils.toast

11
app/src/main/java/audio/funkwhale/ffa/adapters/RadiosAdapter.kt

@ -9,10 +9,10 @@ import audio.funkwhale.ffa.R @@ -9,10 +9,10 @@ import audio.funkwhale.ffa.R
import audio.funkwhale.ffa.databinding.RowRadioBinding
import audio.funkwhale.ffa.databinding.RowRadioHeaderBinding
import audio.funkwhale.ffa.fragments.FFAAdapter
import audio.funkwhale.ffa.model.Radio
import audio.funkwhale.ffa.utils.AppContext
import audio.funkwhale.ffa.utils.Event
import audio.funkwhale.ffa.utils.EventBus
import audio.funkwhale.ffa.model.Radio
import audio.funkwhale.ffa.views.LoadingImageView
import com.preference.PowerPreference
import kotlinx.coroutines.CoroutineScope
@ -42,8 +42,10 @@ class RadiosAdapter( @@ -42,8 +42,10 @@ class RadiosAdapter(
private val instanceRadios: List<Radio> by lazy {
context?.let {
return@lazy when (val username =
PowerPreference.getFileByName(AppContext.PREFS_CREDENTIALS).getString("actor_username")) {
return@lazy when (
val username =
PowerPreference.getFileByName(AppContext.PREFS_CREDENTIALS).getString("actor_username")
) {
"" -> listOf(
Radio(
0,
@ -133,7 +135,8 @@ class RadiosAdapter( @@ -133,7 +135,8 @@ class RadiosAdapter(
context?.let {
when (position) {
0 -> holder.label.text = context.getString(R.string.radio_instance_radios)
instanceRadios.size + 1 -> holder.label.text =
instanceRadios.size + 1 ->
holder.label.text =
context.getString(R.string.radio_user_radios)
}
}

41
app/src/main/java/audio/funkwhale/ffa/adapters/SearchAdapter.kt

@ -17,9 +17,9 @@ import audio.funkwhale.ffa.databinding.RowSearchHeaderBinding @@ -17,9 +17,9 @@ import audio.funkwhale.ffa.databinding.RowSearchHeaderBinding
import audio.funkwhale.ffa.databinding.RowTrackBinding
import audio.funkwhale.ffa.model.Album
import audio.funkwhale.ffa.model.Artist
import audio.funkwhale.ffa.model.Track
import audio.funkwhale.ffa.utils.Command
import audio.funkwhale.ffa.utils.CommandBus
import audio.funkwhale.ffa.model.Track
import audio.funkwhale.ffa.utils.maybeLoad
import audio.funkwhale.ffa.utils.maybeNormalizeUrl
import audio.funkwhale.ffa.utils.onApi
@ -73,20 +73,19 @@ class SearchAdapter( @@ -73,20 +73,19 @@ class SearchAdapter(
ResultType.Artist.ordinal -> artists[position].id.toLong()
ResultType.Artist.ordinal -> albums[position - artists.size - 2].id.toLong()
ResultType.Track.ordinal -> tracks[position - artists.size - albums.size - sectionCount].id.toLong()
ResultType.Track.ordinal ->
tracks[position - artists.size - albums.size - sectionCount].id.toLong()
else -> 0
}
}
override fun getItemViewType(position: Int): Int {
if (position == 0) return ResultType.Header.ordinal // Artists header
if (position == (artists.size + 1)) return ResultType.Header.ordinal // Albums header
if (position == (artists.size + albums.size + 2)) return ResultType.Header.ordinal // Tracks header
if (position <= artists.size) return ResultType.Artist.ordinal
if (position <= artists.size + albums.size + 2) return ResultType.Album.ordinal
return ResultType.Track.ordinal
override fun getItemViewType(position: Int): Int = when {
position == 0 ||
position == (artists.size + 1) ||
position == (artists.size + albums.size + 2) -> ResultType.Header.ordinal
position <= artists.size -> ResultType.Artist.ordinal
position <= artists.size + albums.size + 2 -> ResultType.Album.ordinal
else -> ResultType.Track.ordinal
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
@ -205,7 +204,8 @@ class SearchAdapter( @@ -205,7 +204,8 @@ class SearchAdapter(
Typeface.create(searchHeaderViewHolder?.title?.typeface, Typeface.NORMAL)
rowTrackViewHolder?.artist?.typeface =
Typeface.create(rowTrackViewHolder?.artist?.typeface, Typeface.NORMAL)
})
}
)
searchHeaderViewHolder?.title?.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0)
@ -235,8 +235,12 @@ class SearchAdapter( @@ -235,8 +235,12 @@ class SearchAdapter(
}
when (track.favorite) {
true -> rowTrackViewHolder?.favorite?.setColorFilter(context.getColor(R.color.colorFavorite))
false -> rowTrackViewHolder?.favorite?.setColorFilter(context.getColor(R.color.colorSelected))
true -> rowTrackViewHolder?.favorite?.setColorFilter(
context.getColor(R.color.colorFavorite)
)
false -> rowTrackViewHolder?.favorite?.setColorFilter(
context.getColor(R.color.colorSelected)
)
}
rowTrackViewHolder?.favorite?.setOnClickListener {
@ -269,7 +273,10 @@ class SearchAdapter( @@ -269,7 +273,10 @@ class SearchAdapter(
if (track.downloaded) {
rowTrackViewHolder?.title?.compoundDrawables?.forEach {
it?.colorFilter =
PorterDuffColorFilter(context.getColor(R.color.downloaded), PorterDuff.Mode.SRC_IN)
PorterDuffColorFilter(
context.getColor(R.color.downloaded),
PorterDuff.Mode.SRC_IN
)
}
}
@ -288,7 +295,9 @@ class SearchAdapter( @@ -288,7 +295,9 @@ class SearchAdapter(
R.id.track_add_to_queue -> CommandBus.send(Command.AddToQueue(listOf(track)))
R.id.track_play_next -> CommandBus.send(Command.PlayNext(track))
R.id.track_pin -> CommandBus.send(Command.PinTrack(track))
R.id.track_add_to_playlist -> CommandBus.send(Command.AddToPlaylist(listOf(track)))
R.id.track_add_to_playlist -> CommandBus.send(
Command.AddToPlaylist(listOf(track))
)
R.id.queue_remove -> CommandBus.send(Command.RemoveFromQueue(track))
}

2
app/src/main/java/audio/funkwhale/ffa/adapters/TracksAdapter.kt

@ -18,9 +18,9 @@ import androidx.recyclerview.widget.RecyclerView @@ -18,9 +18,9 @@ import androidx.recyclerview.widget.RecyclerView
import audio.funkwhale.ffa.R
import audio.funkwhale.ffa.databinding.RowTrackBinding
import audio.funkwhale.ffa.fragments.FFAAdapter
import audio.funkwhale.ffa.model.Track
import audio.funkwhale.ffa.utils.Command
import audio.funkwhale.ffa.utils.CommandBus
import audio.funkwhale.ffa.model.Track
import audio.funkwhale.ffa.utils.maybeLoad
import audio.funkwhale.ffa.utils.maybeNormalizeUrl
import audio.funkwhale.ffa.utils.toast

10
app/src/main/java/audio/funkwhale/ffa/fragments/AddToPlaylistDialog.kt

@ -14,7 +14,8 @@ import audio.funkwhale.ffa.databinding.DialogAddToPlaylistBinding @@ -14,7 +14,8 @@ import audio.funkwhale.ffa.databinding.DialogAddToPlaylistBinding
import audio.funkwhale.ffa.model.Playlist
import audio.funkwhale.ffa.model.Track
import audio.funkwhale.ffa.repositories.ManagementPlaylistsRepository
import audio.funkwhale.ffa.utils.*
import audio.funkwhale.ffa.utils.FFACache
import audio.funkwhale.ffa.utils.untilNetwork
import com.google.gson.Gson
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers.IO
@ -80,7 +81,9 @@ object AddToPlaylistDialog { @@ -80,7 +81,9 @@ object AddToPlaylistDialog {
}
val adapter =
PlaylistsAdapter(layoutInflater, activity, object : PlaylistsAdapter.OnPlaylistClickListener {
PlaylistsAdapter(
layoutInflater, activity,
object : PlaylistsAdapter.OnPlaylistClickListener {
override fun onClick(holder: View?, playlist: Playlist) {
repository.add(playlist.id, tracks)
@ -92,7 +95,8 @@ object AddToPlaylistDialog { @@ -92,7 +95,8 @@ object AddToPlaylistDialog {
dialog.dismiss()
}
})
}
)
binding.playlists.layoutManager = LinearLayoutManager(activity)
binding.playlists.adapter = adapter

7
app/src/main/java/audio/funkwhale/ffa/fragments/AlbumsFragment.kt

@ -25,7 +25,12 @@ import audio.funkwhale.ffa.model.Artist @@ -25,7 +25,12 @@ import audio.funkwhale.ffa.model.Artist
import audio.funkwhale.ffa.repositories.AlbumsRepository
import audio.funkwhale.ffa.repositories.ArtistTracksRepository
import audio.funkwhale.ffa.repositories.Repository
import audio.funkwhale.ffa.utils.*
import audio.funkwhale.ffa.utils.AppContext
import audio.funkwhale.ffa.utils.Command
import audio.funkwhale.ffa.utils.CommandBus
import audio.funkwhale.ffa.utils.maybeLoad
import audio.funkwhale.ffa.utils.maybeNormalizeUrl
import audio.funkwhale.ffa.utils.onViewPager
import com.squareup.picasso.Picasso
import jp.wasabeef.picasso.transformations.RoundedCornersTransformation
import kotlinx.coroutines.Dispatchers.IO

2
app/src/main/java/audio/funkwhale/ffa/fragments/AlbumsGridFragment.kt

@ -13,8 +13,8 @@ import audio.funkwhale.ffa.R @@ -13,8 +13,8 @@ import audio.funkwhale.ffa.R
import audio.funkwhale.ffa.activities.MainActivity
import audio.funkwhale.ffa.adapters.AlbumsGridAdapter
import audio.funkwhale.ffa.databinding.FragmentAlbumsGridBinding
import audio.funkwhale.ffa.repositories.AlbumsRepository
import audio.funkwhale.ffa.model.Album
import audio.funkwhale.ffa.repositories.AlbumsRepository
import audio.funkwhale.ffa.utils.AppContext
class AlbumsGridFragment : FFAFragment<Album, AlbumsGridAdapter>() {

5
app/src/main/java/audio/funkwhale/ffa/fragments/FFAFragment.kt

@ -10,7 +10,10 @@ import androidx.recyclerview.widget.SimpleItemAnimator @@ -10,7 +10,10 @@ import androidx.recyclerview.widget.SimpleItemAnimator
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import audio.funkwhale.ffa.repositories.HttpUpstream
import audio.funkwhale.ffa.repositories.Repository
import audio.funkwhale.ffa.utils.*
import audio.funkwhale.ffa.utils.Event
import audio.funkwhale.ffa.utils.EventBus
import audio.funkwhale.ffa.utils.FFACache
import audio.funkwhale.ffa.utils.untilNetwork
import com.google.gson.Gson
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.Dispatchers.Main

10
app/src/main/java/audio/funkwhale/ffa/fragments/FavoritesFragment.kt

@ -11,7 +11,15 @@ import audio.funkwhale.ffa.databinding.FragmentFavoritesBinding @@ -11,7 +11,15 @@ import audio.funkwhale.ffa.databinding.FragmentFavoritesBinding
import audio.funkwhale.ffa.model.Track
import audio.funkwhale.ffa.repositories.FavoritesRepository
import audio.funkwhale.ffa.repositories.TracksRepository
import audio.funkwhale.ffa.utils.*
import audio.funkwhale.ffa.utils.Command
import audio.funkwhale.ffa.utils.CommandBus
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.getMetadata
import audio.funkwhale.ffa.utils.wait
import com.google.android.exoplayer2.offline.Download
import com.google.android.exoplayer2.offline.DownloadManager
import kotlinx.coroutines.Dispatchers.IO

10
app/src/main/java/audio/funkwhale/ffa/fragments/PlaylistTracksFragment.kt

@ -18,7 +18,15 @@ import audio.funkwhale.ffa.model.Track @@ -18,7 +18,15 @@ import audio.funkwhale.ffa.model.Track
import audio.funkwhale.ffa.repositories.FavoritesRepository
import audio.funkwhale.ffa.repositories.ManagementPlaylistsRepository
import audio.funkwhale.ffa.repositories.PlaylistTracksRepository
import audio.funkwhale.ffa.utils.*
import audio.funkwhale.ffa.utils.Command
import audio.funkwhale.ffa.utils.CommandBus
import audio.funkwhale.ffa.utils.Request
import audio.funkwhale.ffa.utils.RequestBus
import audio.funkwhale.ffa.utils.Response
import audio.funkwhale.ffa.utils.maybeLoad
import audio.funkwhale.ffa.utils.maybeNormalizeUrl
import audio.funkwhale.ffa.utils.toast
import audio.funkwhale.ffa.utils.wait
import com.squareup.picasso.Picasso
import jp.wasabeef.picasso.transformations.RoundedCornersTransformation
import kotlinx.coroutines.Dispatchers.Main

2
app/src/main/java/audio/funkwhale/ffa/fragments/PlaylistsFragment.kt

@ -12,9 +12,9 @@ import audio.funkwhale.ffa.R @@ -12,9 +12,9 @@ import audio.funkwhale.ffa.R
import audio.funkwhale.ffa.activities.MainActivity
import audio.funkwhale.ffa.adapters.PlaylistsAdapter
import audio.funkwhale.ffa.databinding.FragmentPlaylistsBinding
import audio.funkwhale.ffa.model.Playlist
import audio.funkwhale.ffa.repositories.PlaylistsRepository
import audio.funkwhale.ffa.utils.AppContext
import audio.funkwhale.ffa.model.Playlist
class PlaylistsFragment : FFAFragment<Playlist, PlaylistsAdapter>() {

2
app/src/main/java/audio/funkwhale/ffa/fragments/RadiosFragment.kt

@ -9,12 +9,12 @@ import androidx.lifecycle.lifecycleScope @@ -9,12 +9,12 @@ import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.RecyclerView
import audio.funkwhale.ffa.adapters.RadiosAdapter
import audio.funkwhale.ffa.databinding.FragmentRadiosBinding
import audio.funkwhale.ffa.model.Radio
import audio.funkwhale.ffa.repositories.RadiosRepository
import audio.funkwhale.ffa.utils.Command
import audio.funkwhale.ffa.utils.CommandBus
import audio.funkwhale.ffa.utils.Event
import audio.funkwhale.ffa.utils.EventBus
import audio.funkwhale.ffa.model.Radio
import kotlinx.coroutines.Dispatchers.Main
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch

19
app/src/main/java/audio/funkwhale/ffa/fragments/TracksFragment.kt

@ -19,7 +19,18 @@ import audio.funkwhale.ffa.model.Track @@ -19,7 +19,18 @@ import audio.funkwhale.ffa.model.Track
import audio.funkwhale.ffa.repositories.FavoritedRepository
import audio.funkwhale.ffa.repositories.FavoritesRepository
import audio.funkwhale.ffa.repositories.TracksRepository
import audio.funkwhale.ffa.utils.*
import audio.funkwhale.ffa.utils.Command
import audio.funkwhale.ffa.utils.CommandBus
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.getMetadata
import audio.funkwhale.ffa.utils.maybeLoad
import audio.funkwhale.ffa.utils.maybeNormalizeUrl
import audio.funkwhale.ffa.utils.toast
import audio.funkwhale.ffa.utils.wait
import com.google.android.exoplayer2.offline.Download
import com.google.android.exoplayer2.offline.DownloadManager
import com.preference.PowerPreference
@ -199,8 +210,10 @@ class TracksFragment : FFAFragment<Track, TracksAdapter>() { @@ -199,8 +210,10 @@ class TracksFragment : FFAFragment<Track, TracksAdapter>() {
setOnMenuItemClickListener {
when (it.itemId) {
R.id.play_secondary -> when (PowerPreference.getDefaultFile()
.getString("play_order")) {
R.id.play_secondary -> when (
PowerPreference.getDefaultFile()
.getString("play_order")
) {
"in_order" -> CommandBus.send(Command.ReplaceQueue(adapter.data.shuffled()))
else -> CommandBus.send(Command.ReplaceQueue(adapter.data))
}

8
app/src/main/java/audio/funkwhale/ffa/playback/CacheDataSourceFactoryProvider.kt

@ -5,7 +5,7 @@ import audio.funkwhale.ffa.R @@ -5,7 +5,7 @@ import audio.funkwhale.ffa.R
import audio.funkwhale.ffa.utils.OAuth
import audio.funkwhale.ffa.utils.Settings
import com.google.android.exoplayer2.upstream.DataSource
import com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory
import com.google.android.exoplayer2.upstream.DefaultHttpDataSource
import com.google.android.exoplayer2.upstream.FileDataSource
import com.google.android.exoplayer2.upstream.cache.Cache
import com.google.android.exoplayer2.upstream.cache.CacheDataSource
@ -33,9 +33,9 @@ class CacheDataSourceFactoryProvider( @@ -33,9 +33,9 @@ class CacheDataSourceFactoryProvider(
}
private fun createDatasourceFactory(context: Context, oAuth: OAuth): DataSource.Factory {
val http = DefaultHttpDataSourceFactory(
Util.getUserAgent(context, context.getString(R.string.app_name))
)
val http = DefaultHttpDataSource.Factory().apply {
setUserAgent(Util.getUserAgent(context, context.getString(R.string.app_name)))
}
return if (!Settings.isAnonymous()) {
OAuth2DatasourceFactory(context, http, oAuth)
} else {

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

@ -12,8 +12,8 @@ import androidx.media.app.NotificationCompat.MediaStyle @@ -12,8 +12,8 @@ import androidx.media.app.NotificationCompat.MediaStyle
import androidx.media.session.MediaButtonReceiver
import audio.funkwhale.ffa.R
import audio.funkwhale.ffa.activities.MainActivity
import audio.funkwhale.ffa.utils.AppContext
import audio.funkwhale.ffa.model.Track
import audio.funkwhale.ffa.utils.AppContext
import audio.funkwhale.ffa.utils.maybeNormalizeUrl
import com.squareup.picasso.Picasso
import kotlinx.coroutines.CoroutineScope

6
app/src/main/java/audio/funkwhale/ffa/playback/MediaSession.kt

@ -44,11 +44,13 @@ class MediaSession(private val context: Context) { @@ -44,11 +44,13 @@ class MediaSession(private val context: Context) {
it.setMediaButtonEventHandler { _, _, intent ->
if (!active) {
context.startService(Intent(context, PlayerService::class.java).apply {
context.startService(
Intent(context, PlayerService::class.java).apply {
action = intent.action
intent.extras?.let { extras -> putExtras(extras) }
})
}
)
return@setMediaButtonEventHandler true
}

8
app/src/main/java/audio/funkwhale/ffa/playback/OAuth2Datasource.kt

@ -3,7 +3,11 @@ package audio.funkwhale.ffa.playback @@ -3,7 +3,11 @@ package audio.funkwhale.ffa.playback
import android.content.Context
import android.net.Uri
import audio.funkwhale.ffa.utils.OAuth
import com.google.android.exoplayer2.upstream.*
import com.google.android.exoplayer2.upstream.DataSource
import com.google.android.exoplayer2.upstream.DataSpec
import com.google.android.exoplayer2.upstream.DefaultHttpDataSource
import com.google.android.exoplayer2.upstream.HttpDataSource
import com.google.android.exoplayer2.upstream.TransferListener
class OAuthDatasource(
private val context: Context,
@ -38,7 +42,7 @@ class OAuthDatasource( @@ -38,7 +42,7 @@ class OAuthDatasource(
class OAuth2DatasourceFactory(
private val context: Context,
private val http: DefaultHttpDataSourceFactory,
private val http: DefaultHttpDataSource.Factory,
private val oauth: OAuth
) : DataSource.Factory {

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

@ -7,7 +7,13 @@ import androidx.core.net.toUri @@ -7,7 +7,13 @@ import androidx.core.net.toUri
import audio.funkwhale.ffa.R
import audio.funkwhale.ffa.model.DownloadInfo
import audio.funkwhale.ffa.model.Track
import audio.funkwhale.ffa.utils.*
import audio.funkwhale.ffa.utils.AppContext
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.mustNormalizeUrl
import com.google.android.exoplayer2.offline.Download
import com.google.android.exoplayer2.offline.DownloadManager
import com.google.android.exoplayer2.offline.DownloadRequest
@ -21,7 +27,7 @@ import kotlinx.coroutines.Job @@ -21,7 +27,7 @@ import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch
import org.koin.java.KoinJavaComponent
import java.util.*
import java.util.Collections
class PinService : DownloadService(AppContext.NOTIFICATION_DOWNLOADS) {

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

@ -17,7 +17,19 @@ import androidx.core.app.NotificationManagerCompat @@ -17,7 +17,19 @@ import androidx.core.app.NotificationManagerCompat
import androidx.media.session.MediaButtonReceiver
import audio.funkwhale.ffa.R
import audio.funkwhale.ffa.model.Track
import audio.funkwhale.ffa.utils.*
import audio.funkwhale.ffa.utils.Command
import audio.funkwhale.ffa.utils.CommandBus
import audio.funkwhale.ffa.utils.Event
import audio.funkwhale.ffa.utils.EventBus
import audio.funkwhale.ffa.utils.FFACache
import audio.funkwhale.ffa.utils.HeadphonesUnpluggedReceiver
import audio.funkwhale.ffa.utils.ProgressBus
import audio.funkwhale.ffa.utils.Request
import audio.funkwhale.ffa.utils.RequestBus
import audio.funkwhale.ffa.utils.Response
import audio.funkwhale.ffa.utils.log
import audio.funkwhale.ffa.utils.maybeNormalizeUrl
import audio.funkwhale.ffa.utils.onApi
import com.google.android.exoplayer2.C
import com.google.android.exoplayer2.ExoPlaybackException
import com.google.android.exoplayer2.Player
@ -25,10 +37,15 @@ import com.google.android.exoplayer2.SimpleExoPlayer @@ -25,10 +37,15 @@ import com.google.android.exoplayer2.SimpleExoPlayer
import com.google.android.exoplayer2.source.TrackGroupArray
import com.google.android.exoplayer2.trackselection.TrackSelectionArray
import com.squareup.picasso.Picasso
import kotlinx.coroutines.*
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.Dispatchers.Main
import kotlinx.coroutines.Job
import kotlinx.coroutines.cancel
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import org.koin.java.KoinJavaComponent.inject
class PlayerService : Service() {
@ -97,7 +114,8 @@ class PlayerService : Service() { @@ -97,7 +114,8 @@ class PlayerService : Service() {
Build.VERSION_CODES.O.onApi {
audioFocusRequest = AudioFocusRequest.Builder(AudioManager.AUDIOFOCUS_GAIN).run {
setAudioAttributes(AudioAttributes.Builder().run {
setAudioAttributes(
AudioAttributes.Builder().run {
setUsage(AudioAttributes.USAGE_MEDIA)
setContentType(AudioAttributes.CONTENT_TYPE_MUSIC)
@ -105,7 +123,8 @@ class PlayerService : Service() { @@ -105,7 +123,8 @@ class PlayerService : Service() {
setOnAudioFocusChangeListener(audioFocusChangeListener)
build()
})
}
)
build()
}
@ -268,7 +287,8 @@ class PlayerService : Service() { @@ -268,7 +287,8 @@ class PlayerService : Service() {
{
@Suppress("DEPRECATION")
audioManager.abandonAudioFocus(audioFocusChangeListener)
})
}
)
player.removeListener(playerEventListener)
setPlaybackState(false)

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

@ -4,7 +4,13 @@ import android.content.Context @@ -4,7 +4,13 @@ import android.content.Context
import android.net.Uri
import audio.funkwhale.ffa.model.QueueCache
import audio.funkwhale.ffa.model.Track
import audio.funkwhale.ffa.utils.*
import audio.funkwhale.ffa.utils.Command
import audio.funkwhale.ffa.utils.CommandBus
import audio.funkwhale.ffa.utils.Event
import audio.funkwhale.ffa.utils.EventBus
import audio.funkwhale.ffa.utils.FFACache
import audio.funkwhale.ffa.utils.log
import audio.funkwhale.ffa.utils.mustNormalizeUrl
import com.github.kittinunf.fuel.gson.gsonDeserializerOf
import com.google.android.exoplayer2.source.ConcatenatingMediaSource
import com.google.android.exoplayer2.source.ProgressiveMediaSource
@ -28,12 +34,14 @@ class QueueManager(val context: Context) { @@ -28,12 +34,14 @@ class QueueManager(val context: Context) {
val factory = cacheDataSourceFactoryProvider.create(context)
dataSources.addMediaSources(metadata.map { track ->
dataSources.addMediaSources(
metadata.map { track ->
val url = mustNormalizeUrl(track.bestUpload()?.listen_url ?: "")
ProgressiveMediaSource.Factory(factory).setTag(track.title)
.createMediaSource(Uri.parse(url))
})
}
)
}
}

11
app/src/main/java/audio/funkwhale/ffa/playback/RadioPlayer.kt

@ -6,7 +6,16 @@ import audio.funkwhale.ffa.model.Radio @@ -6,7 +6,16 @@ import audio.funkwhale.ffa.model.Radio
import audio.funkwhale.ffa.model.Track
import audio.funkwhale.ffa.repositories.FavoritedRepository
import audio.funkwhale.ffa.repositories.Repository
import audio.funkwhale.ffa.utils.*
import audio.funkwhale.ffa.utils.Command
import audio.funkwhale.ffa.utils.CommandBus
import audio.funkwhale.ffa.utils.Event
import audio.funkwhale.ffa.utils.EventBus
import audio.funkwhale.ffa.utils.FFACache
import audio.funkwhale.ffa.utils.OAuth
import audio.funkwhale.ffa.utils.authorize
import audio.funkwhale.ffa.utils.logError
import audio.funkwhale.ffa.utils.mustNormalizeUrl
import audio.funkwhale.ffa.utils.toast
import com.github.kittinunf.fuel.Fuel
import com.github.kittinunf.fuel.coroutines.awaitObjectResponseResult
import com.github.kittinunf.fuel.coroutines.awaitObjectResult

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

@ -1,8 +1,19 @@ @@ -1,8 +1,19 @@
package audio.funkwhale.ffa.repositories
import android.content.Context
import audio.funkwhale.ffa.model.*
import audio.funkwhale.ffa.utils.*
import audio.funkwhale.ffa.model.FFAResponse
import audio.funkwhale.ffa.model.FavoritedCache
import audio.funkwhale.ffa.model.FavoritedResponse
import audio.funkwhale.ffa.model.Track
import audio.funkwhale.ffa.model.TracksCache
import audio.funkwhale.ffa.model.TracksResponse
import audio.funkwhale.ffa.utils.FFACache
import audio.funkwhale.ffa.utils.OAuth
import audio.funkwhale.ffa.utils.Settings
import audio.funkwhale.ffa.utils.authorize
import audio.funkwhale.ffa.utils.maybeNormalizeUrl
import audio.funkwhale.ffa.utils.mustNormalizeUrl
import audio.funkwhale.ffa.utils.untilNetwork
import com.github.kittinunf.fuel.Fuel
import com.github.kittinunf.fuel.coroutines.awaitByteArrayResponseResult
import com.github.kittinunf.fuel.gson.gsonDeserializerOf

9
app/src/main/java/audio/funkwhale/ffa/repositories/HttpUpstream.kt

@ -4,7 +4,14 @@ import android.content.Context @@ -4,7 +4,14 @@ import android.content.Context
import android.net.Uri
import android.util.Log
import audio.funkwhale.ffa.model.FFAResponse
import audio.funkwhale.ffa.utils.*
import audio.funkwhale.ffa.utils.AppContext
import audio.funkwhale.ffa.utils.Event
import audio.funkwhale.ffa.utils.EventBus
import audio.funkwhale.ffa.utils.OAuth
import audio.funkwhale.ffa.utils.RefreshError
import audio.funkwhale.ffa.utils.Settings
import audio.funkwhale.ffa.utils.authorize
import audio.funkwhale.ffa.utils.mustNormalizeUrl
import com.github.kittinunf.fuel.Fuel
import com.github.kittinunf.fuel.core.FuelError
import com.github.kittinunf.fuel.core.ResponseDeserializable

6
app/src/main/java/audio/funkwhale/ffa/repositories/PlaylistsRepository.kt

@ -1,7 +1,11 @@ @@ -1,7 +1,11 @@
package audio.funkwhale.ffa.repositories
import android.content.Context
import audio.funkwhale.ffa.model.*
import audio.funkwhale.ffa.model.FFAResponse
import audio.funkwhale.ffa.model.Playlist
import audio.funkwhale.ffa.model.PlaylistsCache
import audio.funkwhale.ffa.model.PlaylistsResponse
import audio.funkwhale.ffa.model.Track
import audio.funkwhale.ffa.utils.OAuth
import audio.funkwhale.ffa.utils.Settings
import audio.funkwhale.ffa.utils.authorize

10
app/src/main/java/audio/funkwhale/ffa/repositories/Repository.kt

@ -1,13 +1,17 @@ @@ -1,13 +1,17 @@
package audio.funkwhale.ffa.repositories
import android.content.Context
import audio.funkwhale.ffa.utils.AppContext
import audio.funkwhale.ffa.model.CacheItem
import audio.funkwhale.ffa.utils.AppContext
import audio.funkwhale.ffa.utils.FFACache
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.map
import java.io.BufferedReader
import kotlin.math.ceil
@ -59,7 +63,7 @@ abstract class Repository<D : Any, C : CacheItem<D>> { @@ -59,7 +63,7 @@ abstract class Repository<D : Any, C : CacheItem<D>> {
}
}.flowOn(IO)
private fun fromNetwork(size: Int) = flow {
private fun fromNetwork(size: Int): Flow<Response<D>> = flow {
upstream
.fetch(size)
.map { response ->

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

@ -1,8 +1,17 @@ @@ -1,8 +1,17 @@
package audio.funkwhale.ffa.repositories
import android.content.Context
import audio.funkwhale.ffa.model.*
import audio.funkwhale.ffa.utils.*
import audio.funkwhale.ffa.model.Album
import audio.funkwhale.ffa.model.AlbumsCache
import audio.funkwhale.ffa.model.AlbumsResponse
import audio.funkwhale.ffa.model.Artist
import audio.funkwhale.ffa.model.ArtistsCache
import audio.funkwhale.ffa.model.ArtistsResponse
import audio.funkwhale.ffa.model.Track
import audio.funkwhale.ffa.model.TracksCache
import audio.funkwhale.ffa.model.TracksResponse
import audio.funkwhale.ffa.utils.OAuth
import audio.funkwhale.ffa.utils.mustNormalizeUrl
import com.github.kittinunf.fuel.gson.gsonDeserializerOf
import com.google.android.exoplayer2.offline.DownloadManager
import com.google.android.exoplayer2.upstream.cache.Cache

2
app/src/main/java/audio/funkwhale/ffa/utils/Extensions.kt

@ -23,7 +23,7 @@ import kotlinx.coroutines.launch @@ -23,7 +23,7 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import net.openid.appauth.ClientSecretPost
import java.text.SimpleDateFormat
import java.util.*
import java.util.Date
import kotlin.coroutines.CoroutineContext
inline fun <D> Flow<Repository.Response<D>>.untilNetwork(

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

@ -13,7 +13,16 @@ import com.github.kittinunf.fuel.gson.jsonBody @@ -13,7 +13,16 @@ import com.github.kittinunf.fuel.gson.jsonBody
import com.github.kittinunf.result.Result
import com.preference.PowerPreference
import kotlinx.coroutines.runBlocking
import net.openid.appauth.*
import net.openid.appauth.AuthState
import net.openid.appauth.AuthorizationException
import net.openid.appauth.AuthorizationRequest
import net.openid.appauth.AuthorizationResponse
import net.openid.appauth.AuthorizationService
import net.openid.appauth.AuthorizationServiceConfiguration
import net.openid.appauth.ClientSecretPost
import net.openid.appauth.RegistrationRequest
import net.openid.appauth.RegistrationResponse
import net.openid.appauth.ResponseTypeValues
fun AuthState.save() {
PowerPreference.getFileByName(AppContext.PREFS_CREDENTIALS).apply {
@ -56,11 +65,13 @@ class OAuth(private val authorizationServiceFactory: AuthorizationServiceFactory @@ -56,11 +65,13 @@ class OAuth(private val authorizationServiceFactory: AuthorizationServiceFactory
fun isAuthorized(context: Context): Boolean {
val state = tryState()
return (if (state != null) {
return (
if (state != null) {
state.validAuthorization() || refreshAccessToken(state, context)
} else {
false
}).also {
}
).also {
it.logInfo("isAuthorized()")
}
}

5
app/src/test/java/audio/funkwhale/ffa/activities/SplashActivityTest.kt

@ -8,7 +8,10 @@ import audio.funkwhale.ffa.KoinTestApp @@ -8,7 +8,10 @@ import audio.funkwhale.ffa.KoinTestApp
import audio.funkwhale.ffa.utils.OAuth
import com.preference.PowerPreference
import com.preference.Preference
import io.mockk.*
import io.mockk.every
import io.mockk.mockk
import io.mockk.mockkStatic
import io.mockk.verify
import org.junit.After
import org.junit.Test
import org.junit.runner.RunWith

Loading…
Cancel
Save