From ef3387dee0033bd75e3bc64de74c1d4564e6cacb Mon Sep 17 00:00:00 2001 From: Ryan Harg Date: Thu, 9 Sep 2021 09:56:15 +0200 Subject: [PATCH] Fix existing linting problems --- app/build.gradle.kts | 16 +- app/src/main/java/audio/funkwhale/ffa/FFA.kt | 9 +- .../ffa/activities/DownloadsActivity.kt | 6 +- .../ffa/activities/LicencesActivity.kt | 3 +- .../funkwhale/ffa/activities/LoginActivity.kt | 5 +- .../funkwhale/ffa/activities/MainActivity.kt | 69 +++++-- .../ffa/activities/SearchActivity.kt | 93 +++++---- .../ffa/activities/SettingsActivity.kt | 6 +- .../ffa/activities/SplashActivity.kt | 4 +- .../ffa/adapters/BrowseTabsAdapter.kt | 11 +- .../ffa/adapters/DownloadsAdapter.kt | 2 +- .../ffa/adapters/FavoritesAdapter.kt | 2 +- .../ffa/adapters/PlaylistTracksAdapter.kt | 4 +- .../funkwhale/ffa/adapters/RadiosAdapter.kt | 13 +- .../funkwhale/ffa/adapters/SearchAdapter.kt | 179 +++++++++--------- .../funkwhale/ffa/adapters/TracksAdapter.kt | 2 +- .../ffa/fragments/AddToPlaylistDialog.kt | 26 +-- .../funkwhale/ffa/fragments/AlbumsFragment.kt | 7 +- .../ffa/fragments/AlbumsGridFragment.kt | 2 +- .../funkwhale/ffa/fragments/FFAFragment.kt | 5 +- .../ffa/fragments/FavoritesFragment.kt | 10 +- .../ffa/fragments/PlaylistTracksFragment.kt | 10 +- .../ffa/fragments/PlaylistsFragment.kt | 2 +- .../funkwhale/ffa/fragments/RadiosFragment.kt | 2 +- .../funkwhale/ffa/fragments/TracksFragment.kt | 19 +- .../java/audio/funkwhale/ffa/koin/Modules.kt | 2 +- .../funkwhale/ffa/model/AlbumsResponse.kt | 2 +- .../java/audio/funkwhale/ffa/model/Artist.kt | 2 +- .../funkwhale/ffa/model/ArtistsResponse.kt | 2 +- .../audio/funkwhale/ffa/model/CacheItem.kt | 2 +- .../audio/funkwhale/ffa/model/CoverUrls.kt | 2 +- .../java/audio/funkwhale/ffa/model/Covers.kt | 2 +- .../audio/funkwhale/ffa/model/DownloadInfo.kt | 2 +- .../audio/funkwhale/ffa/model/FFAResponse.kt | 2 +- .../audio/funkwhale/ffa/model/Favorited.kt | 2 +- .../funkwhale/ffa/model/FavoritedResponse.kt | 2 +- .../audio/funkwhale/ffa/model/Playlist.kt | 2 +- .../funkwhale/ffa/model/PlaylistTrack.kt | 2 +- .../ffa/model/PlaylistTracksResponse.kt | 2 +- .../funkwhale/ffa/model/PlaylistsResponse.kt | 2 +- .../java/audio/funkwhale/ffa/model/Radio.kt | 2 +- .../funkwhale/ffa/model/RadiosResponse.kt | 2 +- .../audio/funkwhale/ffa/model/SearchResult.kt | 2 +- .../java/audio/funkwhale/ffa/model/Track.kt | 2 +- .../funkwhale/ffa/model/TracksResponse.kt | 2 +- .../CacheDataSourceFactoryProvider.kt | 10 +- .../ffa/playback/MediaControlsManager.kt | 2 +- .../funkwhale/ffa/playback/MediaSession.kt | 10 +- .../ffa/playback/OAuth2Datasource.kt | 8 +- .../funkwhale/ffa/playback/PinService.kt | 10 +- .../funkwhale/ffa/playback/PlayerService.kt | 42 ++-- .../funkwhale/ffa/playback/QueueManager.kt | 20 +- .../funkwhale/ffa/playback/RadioPlayer.kt | 11 +- .../ffa/repositories/FavoritesRepository.kt | 15 +- .../ffa/repositories/HttpUpstream.kt | 9 +- .../ffa/repositories/PlaylistsRepository.kt | 6 +- .../funkwhale/ffa/repositories/Repository.kt | 10 +- .../ffa/repositories/SearchRepository.kt | 13 +- .../audio/funkwhale/ffa/utils/Extensions.kt | 4 +- .../audio/funkwhale/ffa/utils/FuelResult.kt | 2 +- .../java/audio/funkwhale/ffa/utils/OAuth.kt | 23 ++- .../test/java/audio/funkwhale/ffa/FFATest.kt | 2 +- .../java/audio/funkwhale/ffa/KoinTestApp.kt | 2 +- .../ffa/activities/SplashActivityTest.kt | 5 +- 64 files changed, 483 insertions(+), 268 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 22fd8e5..24b5dbc 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -241,13 +241,15 @@ project.afterEvaluate { sourceDirectories.setFrom(files(listOf(mainSrc))) classDirectories.setFrom(files(listOf(debugTree))) - executionData.setFrom(fileTree(project.buildDir) { - setIncludes( - listOf( - "outputs/unit_test_code_coverage/debugUnitTest/*.exec", - "outputs/code_coverage/debugAndroidTest/connected/**/*.ec" + executionData.setFrom( + fileTree(project.buildDir) { + setIncludes( + listOf( + "outputs/unit_test_code_coverage/debugUnitTest/*.exec", + "outputs/code_coverage/debugAndroidTest/connected/**/*.ec" + ) ) - ) - }) + } + ) } } diff --git a/app/src/main/java/audio/funkwhale/ffa/FFA.kt b/app/src/main/java/audio/funkwhale/ffa/FFA.kt index e0002a6..e529940 100644 --- a/app/src/main/java/audio/funkwhale/ffa/FFA.kt +++ b/app/src/main/java/audio/funkwhale/ffa/FFA.kt @@ -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() { 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 31711a3..c5a3408 100644 --- a/app/src/main/java/audio/funkwhale/ffa/activities/DownloadsActivity.kt +++ b/app/src/main/java/audio/funkwhale/ffa/activities/DownloadsActivity.kt @@ -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 } + ) } } diff --git a/app/src/main/java/audio/funkwhale/ffa/activities/LicencesActivity.kt b/app/src/main/java/audio/funkwhale/ffa/activities/LicencesActivity.kt index 71d088c..3de5e50 100644 --- a/app/src/main/java/audio/funkwhale/ffa/activities/LicencesActivity.kt +++ b/app/src/main/java/audio/funkwhale/ffa/activities/LicencesActivity.kt @@ -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 diff --git a/app/src/main/java/audio/funkwhale/ffa/activities/LoginActivity.kt b/app/src/main/java/audio/funkwhale/ffa/activities/LoginActivity.kt index 2b78bb9..862e3cc 100644 --- a/app/src/main/java/audio/funkwhale/ffa/activities/LoginActivity.kt +++ b/app/src/main/java/audio/funkwhale/ffa/activities/LoginActivity.kt @@ -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 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 ccddeae..fc01c5b 100644 --- a/app/src/main/java/audio/funkwhale/ffa/activities/MainActivity.kt +++ b/app/src/main/java/audio/funkwhale/ffa/activities/MainActivity.kt @@ -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 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 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 @@ -132,17 +160,17 @@ class MainActivity : AppCompatActivity() { } binding.nowPlayingContainer?.nowPlayingDetailsProgress?.setOnSeekBarChangeListener(object : - SeekBar.OnSeekBarChangeListener { - override fun onStopTrackingTouch(view: SeekBar?) {} + SeekBar.OnSeekBarChangeListener { + override fun onStopTrackingTouch(view: SeekBar?) {} - override fun onStartTrackingTouch(view: SeekBar?) {} + override fun onStartTrackingTouch(view: SeekBar?) {} - override fun onProgressChanged(view: SeekBar?, progress: Int, fromUser: Boolean) { - if (fromUser) { - CommandBus.send(Command.Seek(progress)) + override fun onProgressChanged(view: SeekBar?, progress: Int, fromUser: Boolean) { + if (fromUser) { + CommandBus.send(Command.Seek(progress)) + } } - } - }) + }) landscapeQueue?.let { supportFragmentManager.beginTransaction() @@ -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 { - flags = Intent.FLAG_ACTIVITY_NO_HISTORY - }) + startActivity( + Intent(this@MainActivity, LoginActivity::class.java).apply { + flags = Intent.FLAG_ACTIVITY_NO_HISTORY + } + ) finish() } @@ -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 { - putExtra(PlayerService.INITIAL_COMMAND_KEY, command.command.toString()) - }) + startService( + Intent(this@MainActivity, PlayerService::class.java).apply { + putExtra(PlayerService.INITIAL_COMMAND_KEY, command.command.toString()) + } + ) } ) } 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 0a530bc..b5b574c 100644 --- a/app/src/main/java/audio/funkwhale/ffa/activities/SearchActivity.kt +++ b/app/src/main/java/audio/funkwhale/ffa/activities/SearchActivity.kt @@ -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 @@ -82,58 +91,58 @@ class SearchActivity : AppCompatActivity() { favoritesRepository = FavoritesRepository(this@SearchActivity) binding.search.setOnQueryTextListener(object : - androidx.appcompat.widget.SearchView.OnQueryTextListener { - override fun onQueryTextSubmit(rawQuery: String?): Boolean { - binding.search.clearFocus() + androidx.appcompat.widget.SearchView.OnQueryTextListener { + override fun onQueryTextSubmit(rawQuery: String?): Boolean { + binding.search.clearFocus() - rawQuery?.let { - done = 0 + rawQuery?.let { + done = 0 - val query = URLEncoder.encode(it, "UTF-8") + val query = URLEncoder.encode(it, "UTF-8") - artistsRepository.query = query.lowercase(Locale.ROOT) - albumsRepository.query = query.lowercase(Locale.ROOT) - tracksRepository.query = query.lowercase(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 - binding.searchNoResults.visibility = View.GONE + binding.searchSpinner.visibility = View.VISIBLE + binding.searchEmpty.visibility = View.GONE + binding.searchNoResults.visibility = View.GONE - adapter.artists.clear() - adapter.albums.clear() - adapter.tracks.clear() - adapter.notifyDataSetChanged() + adapter.artists.clear() + adapter.albums.clear() + adapter.tracks.clear() + adapter.notifyDataSetChanged() - artistsRepository.fetch(Repository.Origin.Network.origin) - .untilNetwork(lifecycleScope) { artists, _, _, _ -> - done++ + artistsRepository.fetch(Repository.Origin.Network.origin) + .untilNetwork(lifecycleScope) { artists, _, _, _ -> + done++ - adapter.artists.addAll(artists) - refresh() - } + adapter.artists.addAll(artists) + refresh() + } - albumsRepository.fetch(Repository.Origin.Network.origin) - .untilNetwork(lifecycleScope) { albums, _, _, _ -> - done++ + albumsRepository.fetch(Repository.Origin.Network.origin) + .untilNetwork(lifecycleScope) { albums, _, _, _ -> + done++ - adapter.albums.addAll(albums) - refresh() - } + adapter.albums.addAll(albums) + refresh() + } - tracksRepository.fetch(Repository.Origin.Network.origin) - .untilNetwork(lifecycleScope) { tracks, _, _, _ -> - done++ + tracksRepository.fetch(Repository.Origin.Network.origin) + .untilNetwork(lifecycleScope) { tracks, _, _, _ -> + done++ - adapter.tracks.addAll(tracks) - refresh() - } - } + adapter.tracks.addAll(tracks) + refresh() + } + } - return true - } + return true + } - override fun onQueryTextChange(newText: String?) = true - }) + override fun onQueryTextChange(newText: String?) = true + }) } private fun refresh() { 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 caa7a87..38886ec 100644 --- a/app/src/main/java/audio/funkwhale/ffa/activities/SettingsActivity.kt +++ b/app/src/main/java/audio/funkwhale/ffa/activities/SettingsActivity.kt @@ -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 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 865463d..bce7f49 100644 --- a/app/src/main/java/audio/funkwhale/ffa/activities/SplashActivity.kt +++ b/app/src/main/java/audio/funkwhale/ffa/activities/SplashActivity.kt @@ -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() { diff --git a/app/src/main/java/audio/funkwhale/ffa/adapters/BrowseTabsAdapter.kt b/app/src/main/java/audio/funkwhale/ffa/adapters/BrowseTabsAdapter.kt index 359578f..272f24f 100644 --- a/app/src/main/java/audio/funkwhale/ffa/adapters/BrowseTabsAdapter.kt +++ b/app/src/main/java/audio/funkwhale/ffa/adapters/BrowseTabsAdapter.kt @@ -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() override fun getCount() = 5 diff --git a/app/src/main/java/audio/funkwhale/ffa/adapters/DownloadsAdapter.kt b/app/src/main/java/audio/funkwhale/ffa/adapters/DownloadsAdapter.kt index c700328..17631cb 100644 --- a/app/src/main/java/audio/funkwhale/ffa/adapters/DownloadsAdapter.kt +++ b/app/src/main/java/audio/funkwhale/ffa/adapters/DownloadsAdapter.kt @@ -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 diff --git a/app/src/main/java/audio/funkwhale/ffa/adapters/FavoritesAdapter.kt b/app/src/main/java/audio/funkwhale/ffa/adapters/FavoritesAdapter.kt index 2a84024..66ea97a 100644 --- a/app/src/main/java/audio/funkwhale/ffa/adapters/FavoritesAdapter.kt +++ b/app/src/main/java/audio/funkwhale/ffa/adapters/FavoritesAdapter.kt @@ -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 diff --git a/app/src/main/java/audio/funkwhale/ffa/adapters/PlaylistTracksAdapter.kt b/app/src/main/java/audio/funkwhale/ffa/adapters/PlaylistTracksAdapter.kt index 734e850..70693df 100644 --- a/app/src/main/java/audio/funkwhale/ffa/adapters/PlaylistTracksAdapter.kt +++ b/app/src/main/java/audio/funkwhale/ffa/adapters/PlaylistTracksAdapter.kt @@ -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 diff --git a/app/src/main/java/audio/funkwhale/ffa/adapters/RadiosAdapter.kt b/app/src/main/java/audio/funkwhale/ffa/adapters/RadiosAdapter.kt index 12b88b1..8d57fa2 100644 --- a/app/src/main/java/audio/funkwhale/ffa/adapters/RadiosAdapter.kt +++ b/app/src/main/java/audio/funkwhale/ffa/adapters/RadiosAdapter.kt @@ -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( private val instanceRadios: List 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,8 +135,9 @@ class RadiosAdapter( context?.let { when (position) { 0 -> holder.label.text = context.getString(R.string.radio_instance_radios) - instanceRadios.size + 1 -> holder.label.text = - context.getString(R.string.radio_user_radios) + instanceRadios.size + 1 -> + holder.label.text = + context.getString(R.string.radio_user_radios) } } } diff --git a/app/src/main/java/audio/funkwhale/ffa/adapters/SearchAdapter.kt b/app/src/main/java/audio/funkwhale/ffa/adapters/SearchAdapter.kt index df860b9..f5b2b97 100644 --- a/app/src/main/java/audio/funkwhale/ffa/adapters/SearchAdapter.kt +++ b/app/src/main/java/audio/funkwhale/ffa/adapters/SearchAdapter.kt @@ -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( 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,102 +204,112 @@ 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) when (resultType) { - ResultType.Artist.ordinal -> { - rowTrackViewHolder?.title?.setCompoundDrawablesWithIntrinsicBounds( - 0, 0, 0, 0 - ) - } - ResultType.Album.ordinal -> { - rowTrackViewHolder?.title?.setCompoundDrawablesWithIntrinsicBounds( - 0, 0, 0, 0 - ) - } - ResultType.Track.ordinal -> { - (item as? Track)?.let { track -> - context?.let { context -> - if (track == currentTrack || track.current) { - searchHeaderViewHolder?.title?.setTypeface( - searchHeaderViewHolder.title.typeface, - Typeface.BOLD - ) - rowTrackViewHolder?.artist?.setTypeface( - rowTrackViewHolder.artist.typeface, - Typeface.BOLD - ) - } + ResultType.Artist.ordinal -> { + rowTrackViewHolder?.title?.setCompoundDrawablesWithIntrinsicBounds( + 0, 0, 0, 0 + ) + } + ResultType.Album.ordinal -> { + rowTrackViewHolder?.title?.setCompoundDrawablesWithIntrinsicBounds( + 0, 0, 0, 0 + ) + } + ResultType.Track.ordinal -> { + (item as? Track)?.let { track -> + context?.let { context -> + if (track == currentTrack || track.current) { + searchHeaderViewHolder?.title?.setTypeface( + searchHeaderViewHolder.title.typeface, + Typeface.BOLD + ) + rowTrackViewHolder?.artist?.setTypeface( + rowTrackViewHolder.artist.typeface, + Typeface.BOLD + ) + } - when (track.favorite) { - true -> rowTrackViewHolder?.favorite?.setColorFilter(context.getColor(R.color.colorFavorite)) - false -> rowTrackViewHolder?.favorite?.setColorFilter(context.getColor(R.color.colorSelected)) - } + when (track.favorite) { + true -> rowTrackViewHolder?.favorite?.setColorFilter( + context.getColor(R.color.colorFavorite) + ) + false -> rowTrackViewHolder?.favorite?.setColorFilter( + context.getColor(R.color.colorSelected) + ) + } - rowTrackViewHolder?.favorite?.setOnClickListener { - favoriteListener?.let { - favoriteListener.onToggleFavorite(track.id, !track.favorite) + rowTrackViewHolder?.favorite?.setOnClickListener { + favoriteListener?.let { + favoriteListener.onToggleFavorite(track.id, !track.favorite) - tracks[position - artists.size - albums.size - sectionCount].favorite = - !track.favorite + tracks[position - artists.size - albums.size - sectionCount].favorite = + !track.favorite - notifyItemChanged(position) - } + notifyItemChanged(position) } + } - when (track.cached || track.downloaded) { - true -> rowTrackViewHolder?.title?.setCompoundDrawablesWithIntrinsicBounds( - R.drawable.downloaded, 0, 0, 0 - ) - false -> rowTrackViewHolder?.title?.setCompoundDrawablesWithIntrinsicBounds( - 0, 0, 0, 0 - ) - } + when (track.cached || track.downloaded) { + true -> rowTrackViewHolder?.title?.setCompoundDrawablesWithIntrinsicBounds( + R.drawable.downloaded, 0, 0, 0 + ) + false -> rowTrackViewHolder?.title?.setCompoundDrawablesWithIntrinsicBounds( + 0, 0, 0, 0 + ) + } - if (track.cached && !track.downloaded) { - rowTrackViewHolder?.title?.compoundDrawables?.forEach { - it?.colorFilter = - PorterDuffColorFilter(context.getColor(R.color.cached), PorterDuff.Mode.SRC_IN) - } + if (track.cached && !track.downloaded) { + rowTrackViewHolder?.title?.compoundDrawables?.forEach { + it?.colorFilter = + PorterDuffColorFilter(context.getColor(R.color.cached), PorterDuff.Mode.SRC_IN) } + } - if (track.downloaded) { - rowTrackViewHolder?.title?.compoundDrawables?.forEach { - it?.colorFilter = - PorterDuffColorFilter(context.getColor(R.color.downloaded), PorterDuff.Mode.SRC_IN) - } + if (track.downloaded) { + rowTrackViewHolder?.title?.compoundDrawables?.forEach { + it?.colorFilter = + PorterDuffColorFilter( + context.getColor(R.color.downloaded), + PorterDuff.Mode.SRC_IN + ) } + } - rowTrackViewHolder?.actions?.setOnClickListener { - PopupMenu( - context, - rowTrackViewHolder.actions, - Gravity.START, - R.attr.actionOverflowMenuStyle, - 0 - ).apply { - inflate(R.menu.row_track) - - setOnMenuItemClickListener { - when (it.itemId) { - 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.queue_remove -> CommandBus.send(Command.RemoveFromQueue(track)) - } - - true + rowTrackViewHolder?.actions?.setOnClickListener { + PopupMenu( + context, + rowTrackViewHolder.actions, + Gravity.START, + R.attr.actionOverflowMenuStyle, + 0 + ).apply { + inflate(R.menu.row_track) + + setOnMenuItemClickListener { + when (it.itemId) { + 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.queue_remove -> CommandBus.send(Command.RemoveFromQueue(track)) } - show() + true } + + show() } } } } + } } } diff --git a/app/src/main/java/audio/funkwhale/ffa/adapters/TracksAdapter.kt b/app/src/main/java/audio/funkwhale/ffa/adapters/TracksAdapter.kt index c661460..049df34 100644 --- a/app/src/main/java/audio/funkwhale/ffa/adapters/TracksAdapter.kt +++ b/app/src/main/java/audio/funkwhale/ffa/adapters/TracksAdapter.kt @@ -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 diff --git a/app/src/main/java/audio/funkwhale/ffa/fragments/AddToPlaylistDialog.kt b/app/src/main/java/audio/funkwhale/ffa/fragments/AddToPlaylistDialog.kt index 4498e5d..2c01cbb 100644 --- a/app/src/main/java/audio/funkwhale/ffa/fragments/AddToPlaylistDialog.kt +++ b/app/src/main/java/audio/funkwhale/ffa/fragments/AddToPlaylistDialog.kt @@ -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,19 +81,22 @@ object AddToPlaylistDialog { } val adapter = - PlaylistsAdapter(layoutInflater, activity, object : PlaylistsAdapter.OnPlaylistClickListener { - override fun onClick(holder: View?, playlist: Playlist) { - repository.add(playlist.id, tracks) + PlaylistsAdapter( + layoutInflater, activity, + object : PlaylistsAdapter.OnPlaylistClickListener { + override fun onClick(holder: View?, playlist: Playlist) { + repository.add(playlist.id, tracks) - Toast.makeText( - activity, - activity.getString(R.string.playlist_added_to, playlist.name), - Toast.LENGTH_SHORT - ).show() + Toast.makeText( + activity, + activity.getString(R.string.playlist_added_to, playlist.name), + Toast.LENGTH_SHORT + ).show() - dialog.dismiss() + dialog.dismiss() + } } - }) + ) binding.playlists.layoutManager = LinearLayoutManager(activity) binding.playlists.adapter = adapter diff --git a/app/src/main/java/audio/funkwhale/ffa/fragments/AlbumsFragment.kt b/app/src/main/java/audio/funkwhale/ffa/fragments/AlbumsFragment.kt index a6a2116..c671179 100644 --- a/app/src/main/java/audio/funkwhale/ffa/fragments/AlbumsFragment.kt +++ b/app/src/main/java/audio/funkwhale/ffa/fragments/AlbumsFragment.kt @@ -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 diff --git a/app/src/main/java/audio/funkwhale/ffa/fragments/AlbumsGridFragment.kt b/app/src/main/java/audio/funkwhale/ffa/fragments/AlbumsGridFragment.kt index 263ad64..4259e88 100644 --- a/app/src/main/java/audio/funkwhale/ffa/fragments/AlbumsGridFragment.kt +++ b/app/src/main/java/audio/funkwhale/ffa/fragments/AlbumsGridFragment.kt @@ -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() { diff --git a/app/src/main/java/audio/funkwhale/ffa/fragments/FFAFragment.kt b/app/src/main/java/audio/funkwhale/ffa/fragments/FFAFragment.kt index e79faaa..c2c1840 100644 --- a/app/src/main/java/audio/funkwhale/ffa/fragments/FFAFragment.kt +++ b/app/src/main/java/audio/funkwhale/ffa/fragments/FFAFragment.kt @@ -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 diff --git a/app/src/main/java/audio/funkwhale/ffa/fragments/FavoritesFragment.kt b/app/src/main/java/audio/funkwhale/ffa/fragments/FavoritesFragment.kt index 1a4d27f..38d65fc 100644 --- a/app/src/main/java/audio/funkwhale/ffa/fragments/FavoritesFragment.kt +++ b/app/src/main/java/audio/funkwhale/ffa/fragments/FavoritesFragment.kt @@ -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 diff --git a/app/src/main/java/audio/funkwhale/ffa/fragments/PlaylistTracksFragment.kt b/app/src/main/java/audio/funkwhale/ffa/fragments/PlaylistTracksFragment.kt index 5e26b81..1b3ac64 100644 --- a/app/src/main/java/audio/funkwhale/ffa/fragments/PlaylistTracksFragment.kt +++ b/app/src/main/java/audio/funkwhale/ffa/fragments/PlaylistTracksFragment.kt @@ -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 diff --git a/app/src/main/java/audio/funkwhale/ffa/fragments/PlaylistsFragment.kt b/app/src/main/java/audio/funkwhale/ffa/fragments/PlaylistsFragment.kt index 83875c5..25cff0d 100644 --- a/app/src/main/java/audio/funkwhale/ffa/fragments/PlaylistsFragment.kt +++ b/app/src/main/java/audio/funkwhale/ffa/fragments/PlaylistsFragment.kt @@ -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() { diff --git a/app/src/main/java/audio/funkwhale/ffa/fragments/RadiosFragment.kt b/app/src/main/java/audio/funkwhale/ffa/fragments/RadiosFragment.kt index d57d625..cf9c764 100644 --- a/app/src/main/java/audio/funkwhale/ffa/fragments/RadiosFragment.kt +++ b/app/src/main/java/audio/funkwhale/ffa/fragments/RadiosFragment.kt @@ -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 diff --git a/app/src/main/java/audio/funkwhale/ffa/fragments/TracksFragment.kt b/app/src/main/java/audio/funkwhale/ffa/fragments/TracksFragment.kt index ce64521..c8be2af 100644 --- a/app/src/main/java/audio/funkwhale/ffa/fragments/TracksFragment.kt +++ b/app/src/main/java/audio/funkwhale/ffa/fragments/TracksFragment.kt @@ -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() { 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)) } diff --git a/app/src/main/java/audio/funkwhale/ffa/koin/Modules.kt b/app/src/main/java/audio/funkwhale/ffa/koin/Modules.kt index 3f9c3de..d06ac33 100644 --- a/app/src/main/java/audio/funkwhale/ffa/koin/Modules.kt +++ b/app/src/main/java/audio/funkwhale/ffa/koin/Modules.kt @@ -64,4 +64,4 @@ fun exoplayerModule(context: Context) = module { fun authModule() = module { single { OAuth(get()) } single { AuthorizationServiceFactory() } -} \ No newline at end of file +} diff --git a/app/src/main/java/audio/funkwhale/ffa/model/AlbumsResponse.kt b/app/src/main/java/audio/funkwhale/ffa/model/AlbumsResponse.kt index 98aa991..8f3203f 100644 --- a/app/src/main/java/audio/funkwhale/ffa/model/AlbumsResponse.kt +++ b/app/src/main/java/audio/funkwhale/ffa/model/AlbumsResponse.kt @@ -6,4 +6,4 @@ data class AlbumsResponse( val results: AlbumList ) : FFAResponse() { override fun getData() = results -} \ No newline at end of file +} diff --git a/app/src/main/java/audio/funkwhale/ffa/model/Artist.kt b/app/src/main/java/audio/funkwhale/ffa/model/Artist.kt index 2a74b6d..7e779a7 100644 --- a/app/src/main/java/audio/funkwhale/ffa/model/Artist.kt +++ b/app/src/main/java/audio/funkwhale/ffa/model/Artist.kt @@ -13,4 +13,4 @@ data class Artist( override fun cover(): String? = albums?.getOrNull(0)?.cover?.urls?.original override fun title() = name override fun subtitle() = "Artist" -} \ No newline at end of file +} diff --git a/app/src/main/java/audio/funkwhale/ffa/model/ArtistsResponse.kt b/app/src/main/java/audio/funkwhale/ffa/model/ArtistsResponse.kt index d59b793..c504700 100644 --- a/app/src/main/java/audio/funkwhale/ffa/model/ArtistsResponse.kt +++ b/app/src/main/java/audio/funkwhale/ffa/model/ArtistsResponse.kt @@ -6,4 +6,4 @@ data class ArtistsResponse( val results: List ) : FFAResponse() { override fun getData() = results -} \ No newline at end of file +} diff --git a/app/src/main/java/audio/funkwhale/ffa/model/CacheItem.kt b/app/src/main/java/audio/funkwhale/ffa/model/CacheItem.kt index 616bb87..a1296db 100644 --- a/app/src/main/java/audio/funkwhale/ffa/model/CacheItem.kt +++ b/app/src/main/java/audio/funkwhale/ffa/model/CacheItem.kt @@ -9,4 +9,4 @@ class PlaylistsCache(data: List) : CacheItem(data) class PlaylistTracksCache(data: List) : CacheItem(data) class RadiosCache(data: List) : CacheItem(data) class FavoritedCache(data: List) : CacheItem(data) -class QueueCache(data: List) : CacheItem(data) \ No newline at end of file +class QueueCache(data: List) : CacheItem(data) diff --git a/app/src/main/java/audio/funkwhale/ffa/model/CoverUrls.kt b/app/src/main/java/audio/funkwhale/ffa/model/CoverUrls.kt index 6c935be..8efb18c 100644 --- a/app/src/main/java/audio/funkwhale/ffa/model/CoverUrls.kt +++ b/app/src/main/java/audio/funkwhale/ffa/model/CoverUrls.kt @@ -1,3 +1,3 @@ package audio.funkwhale.ffa.model -data class CoverUrls(val original: String) \ No newline at end of file +data class CoverUrls(val original: String) diff --git a/app/src/main/java/audio/funkwhale/ffa/model/Covers.kt b/app/src/main/java/audio/funkwhale/ffa/model/Covers.kt index 86b9880..5271778 100644 --- a/app/src/main/java/audio/funkwhale/ffa/model/Covers.kt +++ b/app/src/main/java/audio/funkwhale/ffa/model/Covers.kt @@ -1,3 +1,3 @@ package audio.funkwhale.ffa.model -data class Covers(val urls: CoverUrls) \ No newline at end of file +data class Covers(val urls: CoverUrls) diff --git a/app/src/main/java/audio/funkwhale/ffa/model/DownloadInfo.kt b/app/src/main/java/audio/funkwhale/ffa/model/DownloadInfo.kt index 47d5e0a..383f2ea 100644 --- a/app/src/main/java/audio/funkwhale/ffa/model/DownloadInfo.kt +++ b/app/src/main/java/audio/funkwhale/ffa/model/DownloadInfo.kt @@ -8,4 +8,4 @@ data class DownloadInfo( val title: String, val artist: String, var download: Download? -) \ No newline at end of file +) diff --git a/app/src/main/java/audio/funkwhale/ffa/model/FFAResponse.kt b/app/src/main/java/audio/funkwhale/ffa/model/FFAResponse.kt index 289fa29..781e50c 100644 --- a/app/src/main/java/audio/funkwhale/ffa/model/FFAResponse.kt +++ b/app/src/main/java/audio/funkwhale/ffa/model/FFAResponse.kt @@ -5,4 +5,4 @@ abstract class FFAResponse { abstract val next: String? abstract fun getData(): List -} \ No newline at end of file +} diff --git a/app/src/main/java/audio/funkwhale/ffa/model/Favorited.kt b/app/src/main/java/audio/funkwhale/ffa/model/Favorited.kt index facfd2f..33d02bc 100644 --- a/app/src/main/java/audio/funkwhale/ffa/model/Favorited.kt +++ b/app/src/main/java/audio/funkwhale/ffa/model/Favorited.kt @@ -1,3 +1,3 @@ package audio.funkwhale.ffa.model -data class Favorited(val track: Int) \ No newline at end of file +data class Favorited(val track: Int) diff --git a/app/src/main/java/audio/funkwhale/ffa/model/FavoritedResponse.kt b/app/src/main/java/audio/funkwhale/ffa/model/FavoritedResponse.kt index ab8ae62..75588b5 100644 --- a/app/src/main/java/audio/funkwhale/ffa/model/FavoritedResponse.kt +++ b/app/src/main/java/audio/funkwhale/ffa/model/FavoritedResponse.kt @@ -6,4 +6,4 @@ data class FavoritedResponse( val results: List ) : FFAResponse() { override fun getData() = results.map { it.track } -} \ No newline at end of file +} diff --git a/app/src/main/java/audio/funkwhale/ffa/model/Playlist.kt b/app/src/main/java/audio/funkwhale/ffa/model/Playlist.kt index 7bf432a..725a3ba 100644 --- a/app/src/main/java/audio/funkwhale/ffa/model/Playlist.kt +++ b/app/src/main/java/audio/funkwhale/ffa/model/Playlist.kt @@ -6,4 +6,4 @@ data class Playlist( val album_covers: List, val tracks_count: Int, val duration: Int -) \ No newline at end of file +) diff --git a/app/src/main/java/audio/funkwhale/ffa/model/PlaylistTrack.kt b/app/src/main/java/audio/funkwhale/ffa/model/PlaylistTrack.kt index 4948f57..f1db14b 100644 --- a/app/src/main/java/audio/funkwhale/ffa/model/PlaylistTrack.kt +++ b/app/src/main/java/audio/funkwhale/ffa/model/PlaylistTrack.kt @@ -1,3 +1,3 @@ package audio.funkwhale.ffa.model -data class PlaylistTrack(val track: Track) \ No newline at end of file +data class PlaylistTrack(val track: Track) diff --git a/app/src/main/java/audio/funkwhale/ffa/model/PlaylistTracksResponse.kt b/app/src/main/java/audio/funkwhale/ffa/model/PlaylistTracksResponse.kt index ecfddae..e3d7e57 100644 --- a/app/src/main/java/audio/funkwhale/ffa/model/PlaylistTracksResponse.kt +++ b/app/src/main/java/audio/funkwhale/ffa/model/PlaylistTracksResponse.kt @@ -6,4 +6,4 @@ data class PlaylistTracksResponse( val results: List ) : FFAResponse() { override fun getData() = results -} \ No newline at end of file +} diff --git a/app/src/main/java/audio/funkwhale/ffa/model/PlaylistsResponse.kt b/app/src/main/java/audio/funkwhale/ffa/model/PlaylistsResponse.kt index 623ddb2..6ccc766 100644 --- a/app/src/main/java/audio/funkwhale/ffa/model/PlaylistsResponse.kt +++ b/app/src/main/java/audio/funkwhale/ffa/model/PlaylistsResponse.kt @@ -6,4 +6,4 @@ data class PlaylistsResponse( val results: List ) : FFAResponse() { override fun getData() = results -} \ No newline at end of file +} diff --git a/app/src/main/java/audio/funkwhale/ffa/model/Radio.kt b/app/src/main/java/audio/funkwhale/ffa/model/Radio.kt index b8d7135..a23230b 100644 --- a/app/src/main/java/audio/funkwhale/ffa/model/Radio.kt +++ b/app/src/main/java/audio/funkwhale/ffa/model/Radio.kt @@ -6,4 +6,4 @@ data class Radio( val name: String, val description: String, var related_object_id: String? = null -) \ No newline at end of file +) diff --git a/app/src/main/java/audio/funkwhale/ffa/model/RadiosResponse.kt b/app/src/main/java/audio/funkwhale/ffa/model/RadiosResponse.kt index f2f6d9e..b1935b5 100644 --- a/app/src/main/java/audio/funkwhale/ffa/model/RadiosResponse.kt +++ b/app/src/main/java/audio/funkwhale/ffa/model/RadiosResponse.kt @@ -6,4 +6,4 @@ data class RadiosResponse( val results: List ) : FFAResponse() { override fun getData() = results -} \ No newline at end of file +} diff --git a/app/src/main/java/audio/funkwhale/ffa/model/SearchResult.kt b/app/src/main/java/audio/funkwhale/ffa/model/SearchResult.kt index e512576..16c4951 100644 --- a/app/src/main/java/audio/funkwhale/ffa/model/SearchResult.kt +++ b/app/src/main/java/audio/funkwhale/ffa/model/SearchResult.kt @@ -4,4 +4,4 @@ interface SearchResult { fun cover(): String? fun title(): String fun subtitle(): String -} \ No newline at end of file +} diff --git a/app/src/main/java/audio/funkwhale/ffa/model/Track.kt b/app/src/main/java/audio/funkwhale/ffa/model/Track.kt index a7ea228..e29761e 100644 --- a/app/src/main/java/audio/funkwhale/ffa/model/Track.kt +++ b/app/src/main/java/audio/funkwhale/ffa/model/Track.kt @@ -61,4 +61,4 @@ data class Track( override fun subtitle() = artist.name val formatted: String get() = "$id $artist ($album): $title" -} \ No newline at end of file +} diff --git a/app/src/main/java/audio/funkwhale/ffa/model/TracksResponse.kt b/app/src/main/java/audio/funkwhale/ffa/model/TracksResponse.kt index 21cc942..c13026d 100644 --- a/app/src/main/java/audio/funkwhale/ffa/model/TracksResponse.kt +++ b/app/src/main/java/audio/funkwhale/ffa/model/TracksResponse.kt @@ -6,4 +6,4 @@ data class TracksResponse( val results: List ) : FFAResponse() { override fun getData() = results -} \ No newline at end of file +} diff --git a/app/src/main/java/audio/funkwhale/ffa/playback/CacheDataSourceFactoryProvider.kt b/app/src/main/java/audio/funkwhale/ffa/playback/CacheDataSourceFactoryProvider.kt index 8dd33ec..bc99b06 100644 --- a/app/src/main/java/audio/funkwhale/ffa/playback/CacheDataSourceFactoryProvider.kt +++ b/app/src/main/java/audio/funkwhale/ffa/playback/CacheDataSourceFactoryProvider.kt @@ -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,13 +33,13 @@ 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 { http } } -} \ No newline at end of file +} 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 7fe2a5b..36b5302 100644 --- a/app/src/main/java/audio/funkwhale/ffa/playback/MediaControlsManager.kt +++ b/app/src/main/java/audio/funkwhale/ffa/playback/MediaControlsManager.kt @@ -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 diff --git a/app/src/main/java/audio/funkwhale/ffa/playback/MediaSession.kt b/app/src/main/java/audio/funkwhale/ffa/playback/MediaSession.kt index 34ce450..9b3a4eb 100644 --- a/app/src/main/java/audio/funkwhale/ffa/playback/MediaSession.kt +++ b/app/src/main/java/audio/funkwhale/ffa/playback/MediaSession.kt @@ -44,11 +44,13 @@ class MediaSession(private val context: Context) { it.setMediaButtonEventHandler { _, _, intent -> if (!active) { - context.startService(Intent(context, PlayerService::class.java).apply { - action = intent.action + context.startService( + Intent(context, PlayerService::class.java).apply { + action = intent.action - intent.extras?.let { extras -> putExtras(extras) } - }) + intent.extras?.let { extras -> putExtras(extras) } + } + ) return@setMediaButtonEventHandler true } diff --git a/app/src/main/java/audio/funkwhale/ffa/playback/OAuth2Datasource.kt b/app/src/main/java/audio/funkwhale/ffa/playback/OAuth2Datasource.kt index e53f0dd..c2aecbc 100644 --- a/app/src/main/java/audio/funkwhale/ffa/playback/OAuth2Datasource.kt +++ b/app/src/main/java/audio/funkwhale/ffa/playback/OAuth2Datasource.kt @@ -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( class OAuth2DatasourceFactory( private val context: Context, - private val http: DefaultHttpDataSourceFactory, + private val http: DefaultHttpDataSource.Factory, private val oauth: OAuth ) : DataSource.Factory { 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 587c7c1..fd91bec 100644 --- a/app/src/main/java/audio/funkwhale/ffa/playback/PinService.kt +++ b/app/src/main/java/audio/funkwhale/ffa/playback/PinService.kt @@ -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 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) { 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 3731c1b..ab8b556 100644 --- a/app/src/main/java/audio/funkwhale/ffa/playback/PlayerService.kt +++ b/app/src/main/java/audio/funkwhale/ffa/playback/PlayerService.kt @@ -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 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,15 +114,17 @@ class PlayerService : Service() { Build.VERSION_CODES.O.onApi { audioFocusRequest = AudioFocusRequest.Builder(AudioManager.AUDIOFOCUS_GAIN).run { - setAudioAttributes(AudioAttributes.Builder().run { - setUsage(AudioAttributes.USAGE_MEDIA) - setContentType(AudioAttributes.CONTENT_TYPE_MUSIC) + setAudioAttributes( + AudioAttributes.Builder().run { + setUsage(AudioAttributes.USAGE_MEDIA) + setContentType(AudioAttributes.CONTENT_TYPE_MUSIC) - setAcceptsDelayedFocusGain(true) - setOnAudioFocusChangeListener(audioFocusChangeListener) + setAcceptsDelayedFocusGain(true) + setOnAudioFocusChangeListener(audioFocusChangeListener) - build() - }) + build() + } + ) build() } @@ -268,7 +287,8 @@ class PlayerService : Service() { { @Suppress("DEPRECATION") audioManager.abandonAudioFocus(audioFocusChangeListener) - }) + } + ) player.removeListener(playerEventListener) setPlaybackState(false) @@ -461,7 +481,7 @@ class PlayerService : Service() { } if (queue.get().isNotEmpty() && queue.current() == queue.get() - .last() && radioPlayer.isActive() + .last() && radioPlayer.isActive() ) { scope.launch(IO) { if (radioPlayer.lock.tryAcquire()) { 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 f716701..211928d 100644 --- a/app/src/main/java/audio/funkwhale/ffa/playback/QueueManager.kt +++ b/app/src/main/java/audio/funkwhale/ffa/playback/QueueManager.kt @@ -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) { val factory = cacheDataSourceFactoryProvider.create(context) - dataSources.addMediaSources(metadata.map { track -> - val url = mustNormalizeUrl(track.bestUpload()?.listen_url ?: "") + dataSources.addMediaSources( + metadata.map { track -> + val url = mustNormalizeUrl(track.bestUpload()?.listen_url ?: "") - ProgressiveMediaSource.Factory(factory).setTag(track.title) - .createMediaSource(Uri.parse(url)) - }) + ProgressiveMediaSource.Factory(factory).setTag(track.title) + .createMediaSource(Uri.parse(url)) + } + ) } } diff --git a/app/src/main/java/audio/funkwhale/ffa/playback/RadioPlayer.kt b/app/src/main/java/audio/funkwhale/ffa/playback/RadioPlayer.kt index 8f299da..b9f3ce4 100644 --- a/app/src/main/java/audio/funkwhale/ffa/playback/RadioPlayer.kt +++ b/app/src/main/java/audio/funkwhale/ffa/playback/RadioPlayer.kt @@ -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 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 ca7a04d..46cc2a2 100644 --- a/app/src/main/java/audio/funkwhale/ffa/repositories/FavoritesRepository.kt +++ b/app/src/main/java/audio/funkwhale/ffa/repositories/FavoritesRepository.kt @@ -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 diff --git a/app/src/main/java/audio/funkwhale/ffa/repositories/HttpUpstream.kt b/app/src/main/java/audio/funkwhale/ffa/repositories/HttpUpstream.kt index bbf71cb..8f44802 100644 --- a/app/src/main/java/audio/funkwhale/ffa/repositories/HttpUpstream.kt +++ b/app/src/main/java/audio/funkwhale/ffa/repositories/HttpUpstream.kt @@ -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 diff --git a/app/src/main/java/audio/funkwhale/ffa/repositories/PlaylistsRepository.kt b/app/src/main/java/audio/funkwhale/ffa/repositories/PlaylistsRepository.kt index 752d60f..daf119a 100644 --- a/app/src/main/java/audio/funkwhale/ffa/repositories/PlaylistsRepository.kt +++ b/app/src/main/java/audio/funkwhale/ffa/repositories/PlaylistsRepository.kt @@ -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 diff --git a/app/src/main/java/audio/funkwhale/ffa/repositories/Repository.kt b/app/src/main/java/audio/funkwhale/ffa/repositories/Repository.kt index bef2f27..6ff56dd 100644 --- a/app/src/main/java/audio/funkwhale/ffa/repositories/Repository.kt +++ b/app/src/main/java/audio/funkwhale/ffa/repositories/Repository.kt @@ -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> { } }.flowOn(IO) - private fun fromNetwork(size: Int) = flow { + private fun fromNetwork(size: Int): Flow> = flow { upstream .fetch(size) .map { response -> 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 cd27c73..e473c42 100644 --- a/app/src/main/java/audio/funkwhale/ffa/repositories/SearchRepository.kt +++ b/app/src/main/java/audio/funkwhale/ffa/repositories/SearchRepository.kt @@ -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 diff --git a/app/src/main/java/audio/funkwhale/ffa/utils/Extensions.kt b/app/src/main/java/audio/funkwhale/ffa/utils/Extensions.kt index 70d5d11..0a250a5 100644 --- a/app/src/main/java/audio/funkwhale/ffa/utils/Extensions.kt +++ b/app/src/main/java/audio/funkwhale/ffa/utils/Extensions.kt @@ -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 Flow>.untilNetwork( @@ -106,4 +106,4 @@ val ISO_8601_DATE_TIME_FORMAT = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ") fun Date.format(): String { return ISO_8601_DATE_TIME_FORMAT.format(this) -} \ No newline at end of file +} diff --git a/app/src/main/java/audio/funkwhale/ffa/utils/FuelResult.kt b/app/src/main/java/audio/funkwhale/ffa/utils/FuelResult.kt index 3429eb1..db74aac 100644 --- a/app/src/main/java/audio/funkwhale/ffa/utils/FuelResult.kt +++ b/app/src/main/java/audio/funkwhale/ffa/utils/FuelResult.kt @@ -19,4 +19,4 @@ data class FuelResult(val httpStatus: Int? = null, val message: String? = null) return FuelResult() } } -} \ No newline at end of file +} diff --git a/app/src/main/java/audio/funkwhale/ffa/utils/OAuth.kt b/app/src/main/java/audio/funkwhale/ffa/utils/OAuth.kt index c0c7c79..5164358 100644 --- a/app/src/main/java/audio/funkwhale/ffa/utils/OAuth.kt +++ b/app/src/main/java/audio/funkwhale/ffa/utils/OAuth.kt @@ -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 fun isAuthorized(context: Context): Boolean { val state = tryState() - return (if (state != null) { - state.validAuthorization() || refreshAccessToken(state, context) - } else { - false - }).also { + return ( + if (state != null) { + state.validAuthorization() || refreshAccessToken(state, context) + } else { + false + } + ).also { it.logInfo("isAuthorized()") } } diff --git a/app/src/test/java/audio/funkwhale/ffa/FFATest.kt b/app/src/test/java/audio/funkwhale/ffa/FFATest.kt index f6d8786..071342e 100644 --- a/app/src/test/java/audio/funkwhale/ffa/FFATest.kt +++ b/app/src/test/java/audio/funkwhale/ffa/FFATest.kt @@ -58,4 +58,4 @@ class FFATest { expectThat(picassoCache.exists()).isFalse() } -} \ No newline at end of file +} diff --git a/app/src/test/java/audio/funkwhale/ffa/KoinTestApp.kt b/app/src/test/java/audio/funkwhale/ffa/KoinTestApp.kt index 1acf927..a1dae10 100644 --- a/app/src/test/java/audio/funkwhale/ffa/KoinTestApp.kt +++ b/app/src/test/java/audio/funkwhale/ffa/KoinTestApp.kt @@ -24,4 +24,4 @@ class KoinTestApp : Application() { block() unloadKoinModules(module) } -} \ No newline at end of file +} diff --git a/app/src/test/java/audio/funkwhale/ffa/activities/SplashActivityTest.kt b/app/src/test/java/audio/funkwhale/ffa/activities/SplashActivityTest.kt index 868a4cd..2864d6c 100644 --- a/app/src/test/java/audio/funkwhale/ffa/activities/SplashActivityTest.kt +++ b/app/src/test/java/audio/funkwhale/ffa/activities/SplashActivityTest.kt @@ -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