From 94ac0c6b85f13429fb80946e29e1e3b450034754 Mon Sep 17 00:00:00 2001 From: Ryan Harg Date: Sun, 22 Aug 2021 09:48:33 +0200 Subject: [PATCH] Upgrading Android Gradle Plugin - Also moving some model classes --- .../funkwhale/ffa/activities/MainActivity.kt | 1 + .../ffa/activities/SearchActivity.kt | 2 + .../funkwhale/ffa/adapters/AlbumsAdapter.kt | 2 +- .../ffa/adapters/AlbumsGridAdapter.kt | 2 +- .../funkwhale/ffa/adapters/ArtistsAdapter.kt | 2 +- .../ffa/adapters/DownloadsAdapter.kt | 4 +- .../ffa/adapters/FavoritesAdapter.kt | 2 +- .../ffa/adapters/PlaylistTracksAdapter.kt | 4 +- .../ffa/adapters/PlaylistsAdapter.kt | 2 +- .../funkwhale/ffa/adapters/RadiosAdapter.kt | 2 +- .../funkwhale/ffa/adapters/SearchAdapter.kt | 6 +- .../funkwhale/ffa/adapters/TracksAdapter.kt | 2 +- .../ffa/fragments/AddToPlaylistDialog.kt | 2 + .../funkwhale/ffa/fragments/AlbumsFragment.kt | 2 + .../ffa/fragments/AlbumsGridFragment.kt | 2 +- .../ffa/fragments/ArtistsFragment.kt | 2 +- .../ffa/fragments/FavoritesFragment.kt | 1 + .../ffa/fragments/PlaylistTracksFragment.kt | 6 +- .../ffa/fragments/PlaylistsFragment.kt | 2 +- .../funkwhale/ffa/fragments/RadiosFragment.kt | 2 +- .../ffa/fragments/TrackInfoDetailsFragment.kt | 2 +- .../funkwhale/ffa/fragments/TracksFragment.kt | 2 + .../java/audio/funkwhale/ffa/model/Album.kt | 17 ++ .../funkwhale/ffa/model/AlbumsResponse.kt | 9 + .../java/audio/funkwhale/ffa/model/Artist.kt | 16 ++ .../funkwhale/ffa/model/ArtistsResponse.kt | 9 + .../audio/funkwhale/ffa/model/CacheItem.kt | 12 + .../audio/funkwhale/ffa/model/CoverUrls.kt | 3 + .../java/audio/funkwhale/ffa/model/Covers.kt | 3 + .../audio/funkwhale/ffa/model/DownloadInfo.kt | 11 + .../audio/funkwhale/ffa/model/FFAResponse.kt | 8 + .../audio/funkwhale/ffa/model/Favorited.kt | 3 + .../funkwhale/ffa/model/FavoritedResponse.kt | 9 + .../audio/funkwhale/ffa/model/Playlist.kt | 9 + .../funkwhale/ffa/model/PlaylistTrack.kt | 3 + .../ffa/model/PlaylistTracksResponse.kt | 9 + .../funkwhale/ffa/model/PlaylistsResponse.kt | 9 + .../java/audio/funkwhale/ffa/model/Radio.kt | 9 + .../funkwhale/ffa/model/RadiosResponse.kt | 9 + .../audio/funkwhale/ffa/model/SearchResult.kt | 7 + .../java/audio/funkwhale/ffa/model/Track.kt | 64 ++++++ .../funkwhale/ffa/model/TracksResponse.kt | 9 + .../java/audio/funkwhale/ffa/model/User.kt | 5 + .../CacheDataSourceFactoryProvider.kt | 24 +- .../ffa/playback/MediaControlsManager.kt | 2 +- .../funkwhale/ffa/playback/MediaSession.kt | 4 +- .../funkwhale/ffa/playback/PinService.kt | 2 + .../funkwhale/ffa/playback/PlayerService.kt | 2 +- .../funkwhale/ffa/playback/QueueManager.kt | 3 +- .../funkwhale/ffa/playback/RadioPlayer.kt | 2 + .../ffa/repositories/AlbumsRepository.kt | 6 +- .../repositories/ArtistTracksRepository.kt | 8 +- .../ffa/repositories/ArtistsRepository.kt | 8 +- .../ffa/repositories/FavoritesRepository.kt | 5 +- .../ffa/repositories/HttpUpstream.kt | 5 +- .../repositories/PlaylistTracksRepository.kt | 8 +- .../ffa/repositories/PlaylistsRepository.kt | 10 +- .../ffa/repositories/RadiosRepository.kt | 8 +- .../funkwhale/ffa/repositories/Repository.kt | 2 +- .../ffa/repositories/SearchRepository.kt | 1 + .../ffa/repositories/TracksRepository.kt | 10 +- .../java/audio/funkwhale/ffa/utils/Bus.kt | 2 + .../audio/funkwhale/ffa/utils/Extensions.kt | 3 +- .../audio/funkwhale/ffa/utils/FFACache.kt | 3 +- .../java/audio/funkwhale/ffa/utils/Models.kt | 213 ------------------ .../audio/funkwhale/ffa/utils/RefreshError.kt | 1 - .../audio/funkwhale/ffa/utils/Userinfo.kt | 1 + build.gradle.kts | 2 +- buildSrc/src/main/java/Versions.kt | 1 - 69 files changed, 344 insertions(+), 279 deletions(-) create mode 100644 app/src/main/java/audio/funkwhale/ffa/model/Album.kt create mode 100644 app/src/main/java/audio/funkwhale/ffa/model/AlbumsResponse.kt create mode 100644 app/src/main/java/audio/funkwhale/ffa/model/Artist.kt create mode 100644 app/src/main/java/audio/funkwhale/ffa/model/ArtistsResponse.kt create mode 100644 app/src/main/java/audio/funkwhale/ffa/model/CacheItem.kt create mode 100644 app/src/main/java/audio/funkwhale/ffa/model/CoverUrls.kt create mode 100644 app/src/main/java/audio/funkwhale/ffa/model/Covers.kt create mode 100644 app/src/main/java/audio/funkwhale/ffa/model/DownloadInfo.kt create mode 100644 app/src/main/java/audio/funkwhale/ffa/model/FFAResponse.kt create mode 100644 app/src/main/java/audio/funkwhale/ffa/model/Favorited.kt create mode 100644 app/src/main/java/audio/funkwhale/ffa/model/FavoritedResponse.kt create mode 100644 app/src/main/java/audio/funkwhale/ffa/model/Playlist.kt create mode 100644 app/src/main/java/audio/funkwhale/ffa/model/PlaylistTrack.kt create mode 100644 app/src/main/java/audio/funkwhale/ffa/model/PlaylistTracksResponse.kt create mode 100644 app/src/main/java/audio/funkwhale/ffa/model/PlaylistsResponse.kt create mode 100644 app/src/main/java/audio/funkwhale/ffa/model/Radio.kt create mode 100644 app/src/main/java/audio/funkwhale/ffa/model/RadiosResponse.kt create mode 100644 app/src/main/java/audio/funkwhale/ffa/model/SearchResult.kt create mode 100644 app/src/main/java/audio/funkwhale/ffa/model/Track.kt create mode 100644 app/src/main/java/audio/funkwhale/ffa/model/TracksResponse.kt create mode 100644 app/src/main/java/audio/funkwhale/ffa/model/User.kt delete mode 100644 app/src/main/java/audio/funkwhale/ffa/utils/Models.kt 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 5fe32df..737f51e 100644 --- a/app/src/main/java/audio/funkwhale/ffa/activities/MainActivity.kt +++ b/app/src/main/java/audio/funkwhale/ffa/activities/MainActivity.kt @@ -25,6 +25,7 @@ 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.model.Track import audio.funkwhale.ffa.playback.MediaControlsManager import audio.funkwhale.ffa.playback.PinService import audio.funkwhale.ffa.playback.PlayerService 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 b865427..0a530bc 100644 --- a/app/src/main/java/audio/funkwhale/ffa/activities/SearchActivity.kt +++ b/app/src/main/java/audio/funkwhale/ffa/activities/SearchActivity.kt @@ -11,6 +11,8 @@ import audio.funkwhale.ffa.databinding.ActivitySearchBinding import audio.funkwhale.ffa.fragments.AddToPlaylistDialog 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 com.google.android.exoplayer2.offline.Download diff --git a/app/src/main/java/audio/funkwhale/ffa/adapters/AlbumsAdapter.kt b/app/src/main/java/audio/funkwhale/ffa/adapters/AlbumsAdapter.kt index 4904384..839f770 100644 --- a/app/src/main/java/audio/funkwhale/ffa/adapters/AlbumsAdapter.kt +++ b/app/src/main/java/audio/funkwhale/ffa/adapters/AlbumsAdapter.kt @@ -7,7 +7,7 @@ import android.view.ViewGroup import androidx.recyclerview.widget.RecyclerView import audio.funkwhale.ffa.databinding.RowAlbumBinding import audio.funkwhale.ffa.fragments.FFAAdapter -import audio.funkwhale.ffa.utils.Album +import audio.funkwhale.ffa.model.Album import audio.funkwhale.ffa.utils.maybeLoad import audio.funkwhale.ffa.utils.maybeNormalizeUrl import com.squareup.picasso.Picasso diff --git a/app/src/main/java/audio/funkwhale/ffa/adapters/AlbumsGridAdapter.kt b/app/src/main/java/audio/funkwhale/ffa/adapters/AlbumsGridAdapter.kt index 0847e0b..f3bde83 100644 --- a/app/src/main/java/audio/funkwhale/ffa/adapters/AlbumsGridAdapter.kt +++ b/app/src/main/java/audio/funkwhale/ffa/adapters/AlbumsGridAdapter.kt @@ -7,7 +7,7 @@ import androidx.recyclerview.widget.RecyclerView import audio.funkwhale.ffa.R import audio.funkwhale.ffa.databinding.RowAlbumGridBinding import audio.funkwhale.ffa.fragments.FFAAdapter -import audio.funkwhale.ffa.utils.Album +import audio.funkwhale.ffa.model.Album import audio.funkwhale.ffa.utils.maybeLoad import audio.funkwhale.ffa.utils.maybeNormalizeUrl import com.squareup.picasso.Picasso diff --git a/app/src/main/java/audio/funkwhale/ffa/adapters/ArtistsAdapter.kt b/app/src/main/java/audio/funkwhale/ffa/adapters/ArtistsAdapter.kt index 08d67bd..afdfe42 100644 --- a/app/src/main/java/audio/funkwhale/ffa/adapters/ArtistsAdapter.kt +++ b/app/src/main/java/audio/funkwhale/ffa/adapters/ArtistsAdapter.kt @@ -8,7 +8,7 @@ import androidx.recyclerview.widget.RecyclerView import audio.funkwhale.ffa.R import audio.funkwhale.ffa.databinding.RowArtistBinding import audio.funkwhale.ffa.fragments.FFAAdapter -import audio.funkwhale.ffa.utils.Artist +import audio.funkwhale.ffa.model.Artist import audio.funkwhale.ffa.utils.maybeLoad import audio.funkwhale.ffa.utils.maybeNormalizeUrl import com.squareup.picasso.Picasso 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 6cfd35f..c700328 100644 --- a/app/src/main/java/audio/funkwhale/ffa/adapters/DownloadsAdapter.kt +++ b/app/src/main/java/audio/funkwhale/ffa/adapters/DownloadsAdapter.kt @@ -9,8 +9,8 @@ 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.utils.DownloadInfo -import audio.funkwhale.ffa.utils.Track +import audio.funkwhale.ffa.model.DownloadInfo +import audio.funkwhale.ffa.model.Track 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 70155d9..ac9ceda 100644 --- a/app/src/main/java/audio/funkwhale/ffa/adapters/FavoritesAdapter.kt +++ b/app/src/main/java/audio/funkwhale/ffa/adapters/FavoritesAdapter.kt @@ -15,7 +15,7 @@ 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.utils.Track +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 0d6a4de..a51f502 100644 --- a/app/src/main/java/audio/funkwhale/ffa/adapters/PlaylistTracksAdapter.kt +++ b/app/src/main/java/audio/funkwhale/ffa/adapters/PlaylistTracksAdapter.kt @@ -18,8 +18,8 @@ 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.utils.PlaylistTrack -import audio.funkwhale.ffa.utils.Track +import audio.funkwhale.ffa.model.PlaylistTrack +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/PlaylistsAdapter.kt b/app/src/main/java/audio/funkwhale/ffa/adapters/PlaylistsAdapter.kt index 66ea686..b6b29d5 100644 --- a/app/src/main/java/audio/funkwhale/ffa/adapters/PlaylistsAdapter.kt +++ b/app/src/main/java/audio/funkwhale/ffa/adapters/PlaylistsAdapter.kt @@ -9,7 +9,7 @@ import androidx.recyclerview.widget.RecyclerView import audio.funkwhale.ffa.R import audio.funkwhale.ffa.databinding.RowPlaylistBinding import audio.funkwhale.ffa.fragments.FFAAdapter -import audio.funkwhale.ffa.utils.Playlist +import audio.funkwhale.ffa.model.Playlist import audio.funkwhale.ffa.utils.toDurationString import com.squareup.picasso.Picasso import jp.wasabeef.picasso.transformations.RoundedCornersTransformation 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 b4567af..fb24a52 100644 --- a/app/src/main/java/audio/funkwhale/ffa/adapters/RadiosAdapter.kt +++ b/app/src/main/java/audio/funkwhale/ffa/adapters/RadiosAdapter.kt @@ -12,7 +12,7 @@ import audio.funkwhale.ffa.fragments.FFAAdapter import audio.funkwhale.ffa.utils.AppContext import audio.funkwhale.ffa.utils.Event import audio.funkwhale.ffa.utils.EventBus -import audio.funkwhale.ffa.utils.Radio +import audio.funkwhale.ffa.model.Radio import audio.funkwhale.ffa.views.LoadingImageView import com.preference.PowerPreference import kotlinx.coroutines.CoroutineScope 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 f7cd7ee..65181e8 100644 --- a/app/src/main/java/audio/funkwhale/ffa/adapters/SearchAdapter.kt +++ b/app/src/main/java/audio/funkwhale/ffa/adapters/SearchAdapter.kt @@ -15,11 +15,11 @@ import androidx.recyclerview.widget.RecyclerView import audio.funkwhale.ffa.R import audio.funkwhale.ffa.databinding.RowSearchHeaderBinding import audio.funkwhale.ffa.databinding.RowTrackBinding -import audio.funkwhale.ffa.utils.Album -import audio.funkwhale.ffa.utils.Artist +import audio.funkwhale.ffa.model.Album +import audio.funkwhale.ffa.model.Artist import audio.funkwhale.ffa.utils.Command import audio.funkwhale.ffa.utils.CommandBus -import audio.funkwhale.ffa.utils.Track +import audio.funkwhale.ffa.model.Track import audio.funkwhale.ffa.utils.maybeLoad import audio.funkwhale.ffa.utils.maybeNormalizeUrl import audio.funkwhale.ffa.utils.onApi 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 37a9e64..381b05f 100644 --- a/app/src/main/java/audio/funkwhale/ffa/adapters/TracksAdapter.kt +++ b/app/src/main/java/audio/funkwhale/ffa/adapters/TracksAdapter.kt @@ -20,7 +20,7 @@ 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.utils.Track +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 3002e07..4498e5d 100644 --- a/app/src/main/java/audio/funkwhale/ffa/fragments/AddToPlaylistDialog.kt +++ b/app/src/main/java/audio/funkwhale/ffa/fragments/AddToPlaylistDialog.kt @@ -11,6 +11,8 @@ import androidx.recyclerview.widget.LinearLayoutManager import audio.funkwhale.ffa.R import audio.funkwhale.ffa.adapters.PlaylistsAdapter 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 com.google.gson.Gson 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 c5a9e03..a6a2116 100644 --- a/app/src/main/java/audio/funkwhale/ffa/fragments/AlbumsFragment.kt +++ b/app/src/main/java/audio/funkwhale/ffa/fragments/AlbumsFragment.kt @@ -20,6 +20,8 @@ import audio.funkwhale.ffa.R import audio.funkwhale.ffa.activities.MainActivity import audio.funkwhale.ffa.adapters.AlbumsAdapter import audio.funkwhale.ffa.databinding.FragmentAlbumsBinding +import audio.funkwhale.ffa.model.Album +import audio.funkwhale.ffa.model.Artist import audio.funkwhale.ffa.repositories.AlbumsRepository import audio.funkwhale.ffa.repositories.ArtistTracksRepository import audio.funkwhale.ffa.repositories.Repository 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 bfc041f..263ad64 100644 --- a/app/src/main/java/audio/funkwhale/ffa/fragments/AlbumsGridFragment.kt +++ b/app/src/main/java/audio/funkwhale/ffa/fragments/AlbumsGridFragment.kt @@ -14,7 +14,7 @@ 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.utils.Album +import audio.funkwhale.ffa.model.Album import audio.funkwhale.ffa.utils.AppContext class AlbumsGridFragment : FFAFragment() { diff --git a/app/src/main/java/audio/funkwhale/ffa/fragments/ArtistsFragment.kt b/app/src/main/java/audio/funkwhale/ffa/fragments/ArtistsFragment.kt index 75de8a0..c2ef420 100644 --- a/app/src/main/java/audio/funkwhale/ffa/fragments/ArtistsFragment.kt +++ b/app/src/main/java/audio/funkwhale/ffa/fragments/ArtistsFragment.kt @@ -15,9 +15,9 @@ import audio.funkwhale.ffa.R import audio.funkwhale.ffa.activities.MainActivity import audio.funkwhale.ffa.adapters.ArtistsAdapter import audio.funkwhale.ffa.databinding.FragmentArtistsBinding +import audio.funkwhale.ffa.model.Artist import audio.funkwhale.ffa.repositories.ArtistsRepository import audio.funkwhale.ffa.utils.AppContext -import audio.funkwhale.ffa.utils.Artist import audio.funkwhale.ffa.utils.onViewPager class ArtistsFragment : FFAFragment() { 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 12bb8e2..1a4d27f 100644 --- a/app/src/main/java/audio/funkwhale/ffa/fragments/FavoritesFragment.kt +++ b/app/src/main/java/audio/funkwhale/ffa/fragments/FavoritesFragment.kt @@ -8,6 +8,7 @@ import androidx.lifecycle.lifecycleScope import androidx.recyclerview.widget.RecyclerView import audio.funkwhale.ffa.adapters.FavoritesAdapter 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.* 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 594d603..da40ee2 100644 --- a/app/src/main/java/audio/funkwhale/ffa/fragments/PlaylistTracksFragment.kt +++ b/app/src/main/java/audio/funkwhale/ffa/fragments/PlaylistTracksFragment.kt @@ -17,12 +17,12 @@ import audio.funkwhale.ffa.repositories.ManagementPlaylistsRepository import audio.funkwhale.ffa.repositories.PlaylistTracksRepository import audio.funkwhale.ffa.utils.Command import audio.funkwhale.ffa.utils.CommandBus -import audio.funkwhale.ffa.utils.Playlist -import audio.funkwhale.ffa.utils.PlaylistTrack +import audio.funkwhale.ffa.model.Playlist +import audio.funkwhale.ffa.model.PlaylistTrack import audio.funkwhale.ffa.utils.Request import audio.funkwhale.ffa.utils.RequestBus import audio.funkwhale.ffa.utils.Response -import audio.funkwhale.ffa.utils.Track +import audio.funkwhale.ffa.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/PlaylistsFragment.kt b/app/src/main/java/audio/funkwhale/ffa/fragments/PlaylistsFragment.kt index a6b0081..83875c5 100644 --- a/app/src/main/java/audio/funkwhale/ffa/fragments/PlaylistsFragment.kt +++ b/app/src/main/java/audio/funkwhale/ffa/fragments/PlaylistsFragment.kt @@ -14,7 +14,7 @@ import audio.funkwhale.ffa.adapters.PlaylistsAdapter import audio.funkwhale.ffa.databinding.FragmentPlaylistsBinding import audio.funkwhale.ffa.repositories.PlaylistsRepository import audio.funkwhale.ffa.utils.AppContext -import audio.funkwhale.ffa.utils.Playlist +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 cdbb7fb..d57d625 100644 --- a/app/src/main/java/audio/funkwhale/ffa/fragments/RadiosFragment.kt +++ b/app/src/main/java/audio/funkwhale/ffa/fragments/RadiosFragment.kt @@ -14,7 +14,7 @@ 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.Radio +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/TrackInfoDetailsFragment.kt b/app/src/main/java/audio/funkwhale/ffa/fragments/TrackInfoDetailsFragment.kt index bed7e24..998073e 100644 --- a/app/src/main/java/audio/funkwhale/ffa/fragments/TrackInfoDetailsFragment.kt +++ b/app/src/main/java/audio/funkwhale/ffa/fragments/TrackInfoDetailsFragment.kt @@ -12,7 +12,7 @@ import androidx.core.os.bundleOf import androidx.fragment.app.DialogFragment import audio.funkwhale.ffa.R import audio.funkwhale.ffa.databinding.FragmentTrackInfoDetailsBinding -import audio.funkwhale.ffa.utils.Track +import audio.funkwhale.ffa.model.Track import audio.funkwhale.ffa.utils.mustNormalizeUrl import audio.funkwhale.ffa.utils.toDurationString 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 70422f4..ce64521 100644 --- a/app/src/main/java/audio/funkwhale/ffa/fragments/TracksFragment.kt +++ b/app/src/main/java/audio/funkwhale/ffa/fragments/TracksFragment.kt @@ -14,6 +14,8 @@ import androidx.recyclerview.widget.RecyclerView import audio.funkwhale.ffa.R import audio.funkwhale.ffa.adapters.TracksAdapter import audio.funkwhale.ffa.databinding.FragmentTracksBinding +import audio.funkwhale.ffa.model.Album +import audio.funkwhale.ffa.model.Track import audio.funkwhale.ffa.repositories.FavoritedRepository import audio.funkwhale.ffa.repositories.FavoritesRepository import audio.funkwhale.ffa.repositories.TracksRepository diff --git a/app/src/main/java/audio/funkwhale/ffa/model/Album.kt b/app/src/main/java/audio/funkwhale/ffa/model/Album.kt new file mode 100644 index 0000000..cf71c32 --- /dev/null +++ b/app/src/main/java/audio/funkwhale/ffa/model/Album.kt @@ -0,0 +1,17 @@ +package audio.funkwhale.ffa.model + +data class Album( + val id: Int, + val artist: Artist, + val title: String, + val cover: Covers?, + val release_date: String? +) : SearchResult { + data class Artist(val name: String) + + override fun cover() = cover?.urls?.original + override fun title() = title + override fun subtitle() = artist.name +} + +typealias AlbumList = List diff --git a/app/src/main/java/audio/funkwhale/ffa/model/AlbumsResponse.kt b/app/src/main/java/audio/funkwhale/ffa/model/AlbumsResponse.kt new file mode 100644 index 0000000..98aa991 --- /dev/null +++ b/app/src/main/java/audio/funkwhale/ffa/model/AlbumsResponse.kt @@ -0,0 +1,9 @@ +package audio.funkwhale.ffa.model + +data class AlbumsResponse( + override val count: Int, + override val next: String?, + 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 new file mode 100644 index 0000000..2a74b6d --- /dev/null +++ b/app/src/main/java/audio/funkwhale/ffa/model/Artist.kt @@ -0,0 +1,16 @@ +package audio.funkwhale.ffa.model + +data class Artist( + val id: Int, + val name: String, + val albums: List? +) : SearchResult { + data class Album( + val title: String, + val cover: Covers? + ) + + 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 new file mode 100644 index 0000000..d59b793 --- /dev/null +++ b/app/src/main/java/audio/funkwhale/ffa/model/ArtistsResponse.kt @@ -0,0 +1,9 @@ +package audio.funkwhale.ffa.model + +data class ArtistsResponse( + override val count: Int, + override val next: String?, + 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 new file mode 100644 index 0000000..616bb87 --- /dev/null +++ b/app/src/main/java/audio/funkwhale/ffa/model/CacheItem.kt @@ -0,0 +1,12 @@ +package audio.funkwhale.ffa.model + +sealed class CacheItem(val data: List) + +class ArtistsCache(data: List) : CacheItem(data) +class AlbumsCache(data: List) : CacheItem(data) +class TracksCache(data: List) : CacheItem(data) +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 diff --git a/app/src/main/java/audio/funkwhale/ffa/model/CoverUrls.kt b/app/src/main/java/audio/funkwhale/ffa/model/CoverUrls.kt new file mode 100644 index 0000000..6c935be --- /dev/null +++ b/app/src/main/java/audio/funkwhale/ffa/model/CoverUrls.kt @@ -0,0 +1,3 @@ +package audio.funkwhale.ffa.model + +data class CoverUrls(val original: String) \ No newline at end of file diff --git a/app/src/main/java/audio/funkwhale/ffa/model/Covers.kt b/app/src/main/java/audio/funkwhale/ffa/model/Covers.kt new file mode 100644 index 0000000..86b9880 --- /dev/null +++ b/app/src/main/java/audio/funkwhale/ffa/model/Covers.kt @@ -0,0 +1,3 @@ +package audio.funkwhale.ffa.model + +data class Covers(val urls: CoverUrls) \ No newline at end of file diff --git a/app/src/main/java/audio/funkwhale/ffa/model/DownloadInfo.kt b/app/src/main/java/audio/funkwhale/ffa/model/DownloadInfo.kt new file mode 100644 index 0000000..47d5e0a --- /dev/null +++ b/app/src/main/java/audio/funkwhale/ffa/model/DownloadInfo.kt @@ -0,0 +1,11 @@ +package audio.funkwhale.ffa.model + +import com.google.android.exoplayer2.offline.Download + +data class DownloadInfo( + val id: Int, + val contentId: String, + 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 new file mode 100644 index 0000000..289fa29 --- /dev/null +++ b/app/src/main/java/audio/funkwhale/ffa/model/FFAResponse.kt @@ -0,0 +1,8 @@ +package audio.funkwhale.ffa.model + +abstract class FFAResponse { + abstract val count: Int + 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 new file mode 100644 index 0000000..facfd2f --- /dev/null +++ b/app/src/main/java/audio/funkwhale/ffa/model/Favorited.kt @@ -0,0 +1,3 @@ +package audio.funkwhale.ffa.model + +data class Favorited(val track: Int) \ No newline at end of file diff --git a/app/src/main/java/audio/funkwhale/ffa/model/FavoritedResponse.kt b/app/src/main/java/audio/funkwhale/ffa/model/FavoritedResponse.kt new file mode 100644 index 0000000..ab8ae62 --- /dev/null +++ b/app/src/main/java/audio/funkwhale/ffa/model/FavoritedResponse.kt @@ -0,0 +1,9 @@ +package audio.funkwhale.ffa.model + +data class FavoritedResponse( + override val count: Int, + override val next: String?, + 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 new file mode 100644 index 0000000..7bf432a --- /dev/null +++ b/app/src/main/java/audio/funkwhale/ffa/model/Playlist.kt @@ -0,0 +1,9 @@ +package audio.funkwhale.ffa.model + +data class Playlist( + val id: Int, + val name: String, + 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 new file mode 100644 index 0000000..4948f57 --- /dev/null +++ b/app/src/main/java/audio/funkwhale/ffa/model/PlaylistTrack.kt @@ -0,0 +1,3 @@ +package audio.funkwhale.ffa.model + +data class PlaylistTrack(val track: Track) \ No newline at end of file diff --git a/app/src/main/java/audio/funkwhale/ffa/model/PlaylistTracksResponse.kt b/app/src/main/java/audio/funkwhale/ffa/model/PlaylistTracksResponse.kt new file mode 100644 index 0000000..ecfddae --- /dev/null +++ b/app/src/main/java/audio/funkwhale/ffa/model/PlaylistTracksResponse.kt @@ -0,0 +1,9 @@ +package audio.funkwhale.ffa.model + +data class PlaylistTracksResponse( + override val count: Int, + override val next: String?, + 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 new file mode 100644 index 0000000..623ddb2 --- /dev/null +++ b/app/src/main/java/audio/funkwhale/ffa/model/PlaylistsResponse.kt @@ -0,0 +1,9 @@ +package audio.funkwhale.ffa.model + +data class PlaylistsResponse( + override val count: Int, + override val next: String?, + 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 new file mode 100644 index 0000000..b8d7135 --- /dev/null +++ b/app/src/main/java/audio/funkwhale/ffa/model/Radio.kt @@ -0,0 +1,9 @@ +package audio.funkwhale.ffa.model + +data class Radio( + val id: Int, + var radio_type: String, + 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 new file mode 100644 index 0000000..f2f6d9e --- /dev/null +++ b/app/src/main/java/audio/funkwhale/ffa/model/RadiosResponse.kt @@ -0,0 +1,9 @@ +package audio.funkwhale.ffa.model + +data class RadiosResponse( + override val count: Int, + override val next: String?, + 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 new file mode 100644 index 0000000..e512576 --- /dev/null +++ b/app/src/main/java/audio/funkwhale/ffa/model/SearchResult.kt @@ -0,0 +1,7 @@ +package audio.funkwhale.ffa.model + +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 new file mode 100644 index 0000000..a7ea228 --- /dev/null +++ b/app/src/main/java/audio/funkwhale/ffa/model/Track.kt @@ -0,0 +1,64 @@ +package audio.funkwhale.ffa.model + +import com.preference.PowerPreference + +data class Track( + val id: Int = 0, + val title: String, + val artist: Artist, + val album: Album?, + val disc_number: Int = 0, + val position: Int = 0, + val uploads: List = listOf(), + val copyright: String? = null, + val license: String? = null +) : SearchResult { + var current: Boolean = false + var favorite: Boolean = false + var cached: Boolean = false + var downloaded: Boolean = false + + companion object { + + fun fromDownload(download: DownloadInfo): Track = Track( + id = download.id, + title = download.title, + artist = Artist(0, download.artist, listOf()), + album = Album(0, Album.Artist(""), "", Covers(CoverUrls("")), ""), + uploads = listOf(Upload(download.contentId, 0, 0)) + ) + } + + data class Upload( + val listen_url: String, + val duration: Int, + val bitrate: Int + ) + + override fun equals(other: Any?): Boolean { + return when (other) { + is Track -> other.id == id + else -> false + } + } + + override fun hashCode(): Int { + return id + } + + fun bestUpload(): Upload? { + if (uploads.isEmpty()) return null + + return when (PowerPreference.getDefaultFile().getString("media_cache_quality")) { + "quality" -> uploads.maxByOrNull { it.bitrate } ?: uploads[0] + "size" -> uploads.minByOrNull { it.bitrate } ?: uploads[0] + else -> uploads.maxByOrNull { it.bitrate } ?: uploads[0] + } + } + + override fun cover() = album?.cover?.urls?.original + override fun title() = title + 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 new file mode 100644 index 0000000..21cc942 --- /dev/null +++ b/app/src/main/java/audio/funkwhale/ffa/model/TracksResponse.kt @@ -0,0 +1,9 @@ +package audio.funkwhale.ffa.model + +data class TracksResponse( + override val count: Int, + override val next: String?, + 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/User.kt b/app/src/main/java/audio/funkwhale/ffa/model/User.kt new file mode 100644 index 0000000..590f1c5 --- /dev/null +++ b/app/src/main/java/audio/funkwhale/ffa/model/User.kt @@ -0,0 +1,5 @@ +package audio.funkwhale.ffa.model + +data class User( + val full_username: String +) 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 44478f6..74132d2 100644 --- a/app/src/main/java/audio/funkwhale/ffa/playback/CacheDataSourceFactoryProvider.kt +++ b/app/src/main/java/audio/funkwhale/ffa/playback/CacheDataSourceFactoryProvider.kt @@ -13,32 +13,32 @@ import com.google.android.exoplayer2.upstream.cache.CacheDataSourceFactory import com.google.android.exoplayer2.util.Util class CacheDataSourceFactoryProvider( - private val oAuth: OAuth, - private val exoCache: Cache, - private val exoDownloadCache: Cache + private val oAuth: OAuth, + private val exoCache: Cache, + private val exoDownloadCache: Cache ) { fun create(context: Context): CacheDataSourceFactory { val playbackCache = - CacheDataSourceFactory(exoCache, createDatasourceFactory(context, oAuth)) + CacheDataSourceFactory(exoCache, createDatasourceFactory(context, oAuth)) return CacheDataSourceFactory( - exoDownloadCache, - playbackCache, - FileDataSource.Factory(), - null, - CacheDataSource.FLAG_IGNORE_CACHE_ON_ERROR, - null + exoDownloadCache, + playbackCache, + FileDataSource.Factory(), + null, + CacheDataSource.FLAG_IGNORE_CACHE_ON_ERROR, + null ) } private fun createDatasourceFactory(context: Context, oAuth: OAuth): DataSource.Factory { val http = DefaultHttpDataSourceFactory( - Util.getUserAgent(context, context.getString(R.string.app_name)) + Util.getUserAgent(context, context.getString(R.string.app_name)) ) return if (!Settings.isAnonymous()) { - OAuth2DatasourceFactory(context, http, oAuth) + OAuth2DatasourceFactory(context, http, oAuth) } else { http } 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 27c94ad..7fe2a5b 100644 --- a/app/src/main/java/audio/funkwhale/ffa/playback/MediaControlsManager.kt +++ b/app/src/main/java/audio/funkwhale/ffa/playback/MediaControlsManager.kt @@ -13,7 +13,7 @@ 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.utils.Track +import audio.funkwhale.ffa.model.Track 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 2e39bd3..34ce450 100644 --- a/app/src/main/java/audio/funkwhale/ffa/playback/MediaSession.kt +++ b/app/src/main/java/audio/funkwhale/ffa/playback/MediaSession.kt @@ -40,7 +40,7 @@ class MediaSession(private val context: Context) { val connector: MediaSessionConnector by lazy { MediaSessionConnector(session).also { - it.setQueueNavigator(OtterQueueNavigator()) + it.setQueueNavigator(FFAQueueNavigator()) it.setMediaButtonEventHandler { _, _, intent -> if (!active) { @@ -59,7 +59,7 @@ class MediaSession(private val context: Context) { } } -class OtterQueueNavigator : MediaSessionConnector.QueueNavigator { +class FFAQueueNavigator : MediaSessionConnector.QueueNavigator { override fun onSkipToQueueItem(player: Player, controlDispatcher: ControlDispatcher, id: Long) { CommandBus.send(Command.PlayTrack(id.toInt())) } 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 e9a3091..0ef225c 100644 --- a/app/src/main/java/audio/funkwhale/ffa/playback/PinService.kt +++ b/app/src/main/java/audio/funkwhale/ffa/playback/PinService.kt @@ -5,6 +5,8 @@ import android.content.Context import android.content.Intent import android.net.Uri import audio.funkwhale.ffa.R +import audio.funkwhale.ffa.model.DownloadInfo +import audio.funkwhale.ffa.model.Track import audio.funkwhale.ffa.utils.* import com.google.android.exoplayer2.offline.Download import com.google.android.exoplayer2.offline.DownloadManager 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 310834d..5032195 100644 --- a/app/src/main/java/audio/funkwhale/ffa/playback/PlayerService.kt +++ b/app/src/main/java/audio/funkwhale/ffa/playback/PlayerService.kt @@ -12,11 +12,11 @@ import android.media.MediaMetadata import android.os.Build import android.os.IBinder import android.support.v4.media.MediaMetadataCompat -import android.util.Log import android.view.KeyEvent 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 com.google.android.exoplayer2.C import com.google.android.exoplayer2.ExoPlaybackException 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 45e90fb..f716701 100644 --- a/app/src/main/java/audio/funkwhale/ffa/playback/QueueManager.kt +++ b/app/src/main/java/audio/funkwhale/ffa/playback/QueueManager.kt @@ -2,6 +2,8 @@ package audio.funkwhale.ffa.playback 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 com.github.kittinunf.fuel.gson.gsonDeserializerOf import com.google.android.exoplayer2.source.ConcatenatingMediaSource @@ -48,7 +50,6 @@ class QueueManager(val context: Context) { ) } - fun replace(tracks: List) { tracks.map { it.formatted }.log("Replacing queue with ${tracks.size} tracks") val factory = cacheDataSourceFactoryProvider.create(context) 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 9a66665..35a9c86 100644 --- a/app/src/main/java/audio/funkwhale/ffa/playback/RadioPlayer.kt +++ b/app/src/main/java/audio/funkwhale/ffa/playback/RadioPlayer.kt @@ -2,6 +2,8 @@ package audio.funkwhale.ffa.playback import android.content.Context import audio.funkwhale.ffa.R +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.* diff --git a/app/src/main/java/audio/funkwhale/ffa/repositories/AlbumsRepository.kt b/app/src/main/java/audio/funkwhale/ffa/repositories/AlbumsRepository.kt index daa43f5..37df6e7 100644 --- a/app/src/main/java/audio/funkwhale/ffa/repositories/AlbumsRepository.kt +++ b/app/src/main/java/audio/funkwhale/ffa/repositories/AlbumsRepository.kt @@ -1,9 +1,9 @@ package audio.funkwhale.ffa.repositories import android.content.Context -import audio.funkwhale.ffa.utils.Album -import audio.funkwhale.ffa.utils.AlbumsCache -import audio.funkwhale.ffa.utils.AlbumsResponse +import audio.funkwhale.ffa.model.Album +import audio.funkwhale.ffa.model.AlbumsCache +import audio.funkwhale.ffa.model.AlbumsResponse import audio.funkwhale.ffa.utils.OAuth import com.github.kittinunf.fuel.gson.gsonDeserializerOf import com.google.gson.reflect.TypeToken diff --git a/app/src/main/java/audio/funkwhale/ffa/repositories/ArtistTracksRepository.kt b/app/src/main/java/audio/funkwhale/ffa/repositories/ArtistTracksRepository.kt index b5aeade..46f9dd9 100644 --- a/app/src/main/java/audio/funkwhale/ffa/repositories/ArtistTracksRepository.kt +++ b/app/src/main/java/audio/funkwhale/ffa/repositories/ArtistTracksRepository.kt @@ -1,7 +1,11 @@ package audio.funkwhale.ffa.repositories import android.content.Context -import audio.funkwhale.ffa.utils.* +import audio.funkwhale.ffa.model.FFAResponse +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 com.github.kittinunf.fuel.gson.gsonDeserializerOf import com.google.gson.reflect.TypeToken import org.koin.java.KoinJavaComponent.inject @@ -14,7 +18,7 @@ class ArtistTracksRepository(override val context: Context?, private val artistI override val cacheId = "tracks-artist-$artistId" - override val upstream = HttpUpstream>( + override val upstream = HttpUpstream>( context, HttpUpstream.Behavior.AtOnce, "/api/v1/tracks/?playable=true&artist=$artistId", diff --git a/app/src/main/java/audio/funkwhale/ffa/repositories/ArtistsRepository.kt b/app/src/main/java/audio/funkwhale/ffa/repositories/ArtistsRepository.kt index a67d994..3a108d7 100644 --- a/app/src/main/java/audio/funkwhale/ffa/repositories/ArtistsRepository.kt +++ b/app/src/main/java/audio/funkwhale/ffa/repositories/ArtistsRepository.kt @@ -1,7 +1,11 @@ package audio.funkwhale.ffa.repositories import android.content.Context -import audio.funkwhale.ffa.utils.* +import audio.funkwhale.ffa.model.Artist +import audio.funkwhale.ffa.model.ArtistsCache +import audio.funkwhale.ffa.model.ArtistsResponse +import audio.funkwhale.ffa.model.FFAResponse +import audio.funkwhale.ffa.utils.OAuth import com.github.kittinunf.fuel.gson.gsonDeserializerOf import com.google.gson.reflect.TypeToken import org.koin.java.KoinJavaComponent.inject @@ -13,7 +17,7 @@ class ArtistsRepository(override val context: Context?) : Repository>( + override val upstream = HttpUpstream>( context, HttpUpstream.Behavior.Progressive, "/api/v1/artists/?playable=true&ordering=name", 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 049c115..ca7a04d 100644 --- a/app/src/main/java/audio/funkwhale/ffa/repositories/FavoritesRepository.kt +++ b/app/src/main/java/audio/funkwhale/ffa/repositories/FavoritesRepository.kt @@ -1,6 +1,7 @@ package audio.funkwhale.ffa.repositories import android.content.Context +import audio.funkwhale.ffa.model.* import audio.funkwhale.ffa.utils.* import com.github.kittinunf.fuel.Fuel import com.github.kittinunf.fuel.coroutines.awaitByteArrayResponseResult @@ -25,7 +26,7 @@ class FavoritesRepository(override val context: Context?) : Repository>( + override val upstream = HttpUpstream>( context!!, HttpUpstream.Behavior.AtOnce, "/api/v1/tracks/?favorites=true&playable=true&ordering=title", @@ -106,7 +107,7 @@ class FavoritedRepository(override val context: Context?) : Repository>( + override val upstream = HttpUpstream>( context, HttpUpstream.Behavior.Single, "/api/v1/favorites/tracks/all/?playable=true", 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 f01c4d3..bbf71cb 100644 --- a/app/src/main/java/audio/funkwhale/ffa/repositories/HttpUpstream.kt +++ b/app/src/main/java/audio/funkwhale/ffa/repositories/HttpUpstream.kt @@ -3,6 +3,7 @@ package audio.funkwhale.ffa.repositories import android.content.Context import android.net.Uri import android.util.Log +import audio.funkwhale.ffa.model.FFAResponse import audio.funkwhale.ffa.utils.* import com.github.kittinunf.fuel.Fuel import com.github.kittinunf.fuel.core.FuelError @@ -19,7 +20,7 @@ import java.io.Reader import java.lang.reflect.Type import kotlin.math.ceil -class HttpUpstream>( +class HttpUpstream>( val context: Context?, val behavior: Behavior, private val url: String, @@ -78,7 +79,7 @@ class HttpUpstream>( hasMore ) - class GenericDeserializer>(val type: Type) : ResponseDeserializable { + class GenericDeserializer>(val type: Type) : ResponseDeserializable { override fun deserialize(reader: Reader): T? { return Gson().fromJson(reader, type) } diff --git a/app/src/main/java/audio/funkwhale/ffa/repositories/PlaylistTracksRepository.kt b/app/src/main/java/audio/funkwhale/ffa/repositories/PlaylistTracksRepository.kt index 0dde71c..e8802ac 100644 --- a/app/src/main/java/audio/funkwhale/ffa/repositories/PlaylistTracksRepository.kt +++ b/app/src/main/java/audio/funkwhale/ffa/repositories/PlaylistTracksRepository.kt @@ -1,7 +1,11 @@ package audio.funkwhale.ffa.repositories import android.content.Context -import audio.funkwhale.ffa.utils.* +import audio.funkwhale.ffa.model.FFAResponse +import audio.funkwhale.ffa.model.PlaylistTrack +import audio.funkwhale.ffa.model.PlaylistTracksCache +import audio.funkwhale.ffa.model.PlaylistTracksResponse +import audio.funkwhale.ffa.utils.OAuth import com.github.kittinunf.fuel.gson.gsonDeserializerOf import com.google.gson.reflect.TypeToken import kotlinx.coroutines.flow.map @@ -17,7 +21,7 @@ class PlaylistTracksRepository(override val context: Context?, playlistId: Int) override val cacheId = "tracks-playlist-$playlistId" - override val upstream = HttpUpstream>( + override val upstream = HttpUpstream>( context, HttpUpstream.Behavior.Single, "/api/v1/playlists/$playlistId/tracks/?playable=true", 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 2aeab52..a496447 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.utils.* +import audio.funkwhale.ffa.model.* +import audio.funkwhale.ffa.utils.OAuth +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.coroutines.awaitByteArrayResponseResult import com.github.kittinunf.fuel.coroutines.awaitObjectResponseResult @@ -21,7 +25,7 @@ class PlaylistsRepository(override val context: Context?) : Repository>( + override val upstream = HttpUpstream>( context!!, HttpUpstream.Behavior.Progressive, "/api/v1/playlists/?playable=true&ordering=name", @@ -41,7 +45,7 @@ class ManagementPlaylistsRepository(override val context: Context?) : override val cacheId = "tracks-playlists-management" - override val upstream = HttpUpstream>( + override val upstream = HttpUpstream>( context, HttpUpstream.Behavior.AtOnce, "/api/v1/playlists/?scope=me&ordering=name", diff --git a/app/src/main/java/audio/funkwhale/ffa/repositories/RadiosRepository.kt b/app/src/main/java/audio/funkwhale/ffa/repositories/RadiosRepository.kt index 8684bef..cf70f53 100644 --- a/app/src/main/java/audio/funkwhale/ffa/repositories/RadiosRepository.kt +++ b/app/src/main/java/audio/funkwhale/ffa/repositories/RadiosRepository.kt @@ -1,7 +1,11 @@ package audio.funkwhale.ffa.repositories import android.content.Context -import audio.funkwhale.ffa.utils.* +import audio.funkwhale.ffa.model.FFAResponse +import audio.funkwhale.ffa.model.Radio +import audio.funkwhale.ffa.model.RadiosCache +import audio.funkwhale.ffa.model.RadiosResponse +import audio.funkwhale.ffa.utils.OAuth import com.github.kittinunf.fuel.gson.gsonDeserializerOf import com.google.gson.reflect.TypeToken import org.koin.java.KoinJavaComponent.inject @@ -13,7 +17,7 @@ class RadiosRepository(override val context: Context?) : Repository>( + override val upstream = HttpUpstream>( context, HttpUpstream.Behavior.Progressive, "/api/v1/radios/radios/?ordering=name", 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 adc53ff..bef2f27 100644 --- a/app/src/main/java/audio/funkwhale/ffa/repositories/Repository.kt +++ b/app/src/main/java/audio/funkwhale/ffa/repositories/Repository.kt @@ -2,7 +2,7 @@ package audio.funkwhale.ffa.repositories import android.content.Context import audio.funkwhale.ffa.utils.AppContext -import audio.funkwhale.ffa.utils.CacheItem +import audio.funkwhale.ffa.model.CacheItem import audio.funkwhale.ffa.utils.FFACache import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers.IO 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 c23788c..cd27c73 100644 --- a/app/src/main/java/audio/funkwhale/ffa/repositories/SearchRepository.kt +++ b/app/src/main/java/audio/funkwhale/ffa/repositories/SearchRepository.kt @@ -1,6 +1,7 @@ package audio.funkwhale.ffa.repositories import android.content.Context +import audio.funkwhale.ffa.model.* import audio.funkwhale.ffa.utils.* import com.github.kittinunf.fuel.gson.gsonDeserializerOf import com.google.android.exoplayer2.offline.DownloadManager diff --git a/app/src/main/java/audio/funkwhale/ffa/repositories/TracksRepository.kt b/app/src/main/java/audio/funkwhale/ffa/repositories/TracksRepository.kt index b6b5f3e..c247869 100644 --- a/app/src/main/java/audio/funkwhale/ffa/repositories/TracksRepository.kt +++ b/app/src/main/java/audio/funkwhale/ffa/repositories/TracksRepository.kt @@ -1,7 +1,13 @@ package audio.funkwhale.ffa.repositories import android.content.Context -import audio.funkwhale.ffa.utils.* +import audio.funkwhale.ffa.model.FFAResponse +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.getMetadata +import audio.funkwhale.ffa.utils.mustNormalizeUrl import com.github.kittinunf.fuel.gson.gsonDeserializerOf import com.google.android.exoplayer2.offline.Download import com.google.android.exoplayer2.offline.DownloadManager @@ -23,7 +29,7 @@ class TracksRepository(override val context: Context?, albumId: Int) : override val cacheId = "tracks-album-$albumId" - override val upstream = HttpUpstream>( + override val upstream = HttpUpstream>( context, HttpUpstream.Behavior.AtOnce, "/api/v1/tracks/?playable=true&album=$albumId&ordering=disc_number,position", diff --git a/app/src/main/java/audio/funkwhale/ffa/utils/Bus.kt b/app/src/main/java/audio/funkwhale/ffa/utils/Bus.kt index 791df86..49e836c 100644 --- a/app/src/main/java/audio/funkwhale/ffa/utils/Bus.kt +++ b/app/src/main/java/audio/funkwhale/ffa/utils/Bus.kt @@ -1,6 +1,8 @@ package audio.funkwhale.ffa.utils import audio.funkwhale.ffa.FFA +import audio.funkwhale.ffa.model.Radio +import audio.funkwhale.ffa.model.Track import com.google.android.exoplayer2.offline.Download import com.google.android.exoplayer2.offline.DownloadCursor import kotlinx.coroutines.Dispatchers.IO 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 ababd6e..70d5d11 100644 --- a/app/src/main/java/audio/funkwhale/ffa/utils/Extensions.kt +++ b/app/src/main/java/audio/funkwhale/ffa/utils/Extensions.kt @@ -2,11 +2,11 @@ package audio.funkwhale.ffa.utils import android.content.Context import android.os.Build -import android.os.SystemClock import android.util.Log import androidx.fragment.app.Fragment import audio.funkwhale.ffa.R import audio.funkwhale.ffa.fragments.BrowseFragment +import audio.funkwhale.ffa.model.DownloadInfo import audio.funkwhale.ffa.repositories.Repository import com.github.kittinunf.fuel.core.FuelError import com.github.kittinunf.fuel.core.Request @@ -26,7 +26,6 @@ import java.text.SimpleDateFormat import java.util.* import kotlin.coroutines.CoroutineContext - inline fun Flow>.untilNetwork( scope: CoroutineScope, context: CoroutineContext = Main, diff --git a/app/src/main/java/audio/funkwhale/ffa/utils/FFACache.kt b/app/src/main/java/audio/funkwhale/ffa/utils/FFACache.kt index 446c209..2d4bbca 100644 --- a/app/src/main/java/audio/funkwhale/ffa/utils/FFACache.kt +++ b/app/src/main/java/audio/funkwhale/ffa/utils/FFACache.kt @@ -7,6 +7,7 @@ import java.nio.charset.Charset import java.security.MessageDigest object FFACache { + private fun key(key: String): String { val md = MessageDigest.getInstance("SHA-1") val digest = md.digest(key.toByteArray(Charset.defaultCharset())) @@ -35,4 +36,4 @@ object FFACache { delete() } } -} \ No newline at end of file +} diff --git a/app/src/main/java/audio/funkwhale/ffa/utils/Models.kt b/app/src/main/java/audio/funkwhale/ffa/utils/Models.kt deleted file mode 100644 index dc6bae9..0000000 --- a/app/src/main/java/audio/funkwhale/ffa/utils/Models.kt +++ /dev/null @@ -1,213 +0,0 @@ -package audio.funkwhale.ffa.utils - -import com.google.android.exoplayer2.offline.Download -import com.preference.PowerPreference - -data class User( - val full_username: String -) - -sealed class CacheItem(val data: List) -class ArtistsCache(data: List) : CacheItem(data) -class AlbumsCache(data: List) : CacheItem(data) -class TracksCache(data: List) : CacheItem(data) -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) - -abstract class OtterResponse { - abstract val count: Int - abstract val next: String? - - abstract fun getData(): List -} - -data class UserResponse( - override val count: Int, - override val next: String?, - val results: List -) : OtterResponse() { - override fun getData() = results -} - -data class ArtistsResponse( - override val count: Int, - override val next: String?, - val results: List -) : OtterResponse() { - override fun getData() = results -} - -data class AlbumsResponse( - override val count: Int, - override val next: String?, - val results: AlbumList -) : OtterResponse() { - override fun getData() = results -} - -data class TracksResponse( - override val count: Int, - override val next: String?, - val results: List -) : OtterResponse() { - override fun getData() = results -} - -data class FavoritedResponse( - override val count: Int, - override val next: String?, - val results: List -) : OtterResponse() { - override fun getData() = results.map { it.track } -} - -data class PlaylistsResponse( - override val count: Int, - override val next: String?, - val results: List -) : OtterResponse() { - override fun getData() = results -} - -data class PlaylistTracksResponse( - override val count: Int, - override val next: String?, - val results: List -) : OtterResponse() { - override fun getData() = results -} - -data class RadiosResponse( - override val count: Int, - override val next: String?, - val results: List -) : OtterResponse() { - override fun getData() = results -} - -data class Covers(val urls: CoverUrls) -data class CoverUrls(val original: String) - -typealias AlbumList = List - -interface SearchResult { - fun cover(): String? - fun title(): String - fun subtitle(): String -} - -data class Album( - val id: Int, - val artist: Artist, - val title: String, - val cover: Covers?, - val release_date: String? -) : SearchResult { - data class Artist(val name: String) - - override fun cover() = cover?.urls?.original - override fun title() = title - override fun subtitle() = artist.name -} - -data class Artist( - val id: Int, - val name: String, - val albums: List? -) : SearchResult { - data class Album( - val title: String, - val cover: Covers? - ) - - override fun cover(): String? = albums?.getOrNull(0)?.cover?.urls?.original - override fun title() = name - override fun subtitle() = "Artist" -} - -data class Track( - val id: Int = 0, - val title: String, - val artist: Artist, - val album: Album?, - val disc_number: Int = 0, - val position: Int = 0, - val uploads: List = listOf(), - val copyright: String? = null, - val license: String? = null -) : SearchResult { - var current: Boolean = false - var favorite: Boolean = false - var cached: Boolean = false - var downloaded: Boolean = false - - companion object { - fun fromDownload(download: DownloadInfo): Track = Track( - id = download.id, - title = download.title, - artist = Artist(0, download.artist, listOf()), - album = Album(0, Album.Artist(""), "", Covers(CoverUrls("")), ""), - uploads = listOf(Upload(download.contentId, 0, 0)) - ) - } - - data class Upload( - val listen_url: String, - val duration: Int, - val bitrate: Int - ) - - override fun equals(other: Any?): Boolean { - return when (other) { - is Track -> other.id == id - else -> false - } - } - - fun bestUpload(): Upload? { - if (uploads.isEmpty()) return null - - return when (PowerPreference.getDefaultFile().getString("media_cache_quality")) { - "quality" -> uploads.maxByOrNull { it.bitrate } ?: uploads[0] - "size" -> uploads.minByOrNull { it.bitrate } ?: uploads[0] - else -> uploads.maxByOrNull { it.bitrate } ?: uploads[0] - } - } - - override fun cover() = album?.cover?.urls?.original - override fun title() = title - override fun subtitle() = artist.name - - val formatted: String get() = "$id $artist ($album): $title" -} - -data class Favorited(val track: Int) - -data class Playlist( - val id: Int, - val name: String, - val album_covers: List, - val tracks_count: Int, - val duration: Int -) - -data class PlaylistTrack(val track: Track) - -data class Radio( - val id: Int, - var radio_type: String, - val name: String, - val description: String, - var related_object_id: String? = null -) - -data class DownloadInfo( - val id: Int, - val contentId: String, - val title: String, - val artist: String, - var download: Download? -) diff --git a/app/src/main/java/audio/funkwhale/ffa/utils/RefreshError.kt b/app/src/main/java/audio/funkwhale/ffa/utils/RefreshError.kt index 1f572a4..1aa4271 100644 --- a/app/src/main/java/audio/funkwhale/ffa/utils/RefreshError.kt +++ b/app/src/main/java/audio/funkwhale/ffa/utils/RefreshError.kt @@ -1,4 +1,3 @@ package audio.funkwhale.ffa.utils object RefreshError : Throwable() - diff --git a/app/src/main/java/audio/funkwhale/ffa/utils/Userinfo.kt b/app/src/main/java/audio/funkwhale/ffa/utils/Userinfo.kt index 2131d0b..737c890 100644 --- a/app/src/main/java/audio/funkwhale/ffa/utils/Userinfo.kt +++ b/app/src/main/java/audio/funkwhale/ffa/utils/Userinfo.kt @@ -1,6 +1,7 @@ package audio.funkwhale.ffa.utils import android.content.Context +import audio.funkwhale.ffa.model.User import com.github.kittinunf.fuel.Fuel import com.github.kittinunf.fuel.coroutines.awaitObjectResponseResult import com.github.kittinunf.fuel.gson.gsonDeserializerOf diff --git a/build.gradle.kts b/build.gradle.kts index 13a8650..4fd1c5d 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -7,7 +7,7 @@ buildscript { } dependencies { - classpath("com.android.tools.build:gradle:${Versions.androidGradlePlugin}") + classpath("com.android.tools.build:gradle:7.0.1") classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${Versions.kotlin}") classpath("com.github.bjoernq:unmockplugin:${Versions.unmock}") classpath("com.github.ben-manes:gradle-versions-plugin:${Versions.gradleDependencyPlugin}") diff --git a/buildSrc/src/main/java/Versions.kt b/buildSrc/src/main/java/Versions.kt index dd2f605..db8e8f8 100644 --- a/buildSrc/src/main/java/Versions.kt +++ b/buildSrc/src/main/java/Versions.kt @@ -2,7 +2,6 @@ object Versions { const val kotlin = "1.5.21" const val jacoco = "0.8.7" const val unmock = "0.7.8" - const val androidGradlePlugin = "7.0.0" const val gradleDependencyPlugin = "0.38.0" const val exoPlayer = "2.11.8"