Removed Rx java
This commit is contained in:
parent
ccad96dd41
commit
62726de918
12 changed files with 189 additions and 386 deletions
|
@ -1,165 +1,171 @@
|
|||
package code.name.monkey.retromusic.adapter.album
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.*
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ImageView
|
||||
import androidx.fragment.app.*
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import code.name.monkey.retromusic.R
|
||||
import code.name.monkey.retromusic.fragments.AlbumCoverStyle
|
||||
import code.name.monkey.retromusic.glide.*
|
||||
import code.name.monkey.retromusic.glide.RetroMusicColoredTarget
|
||||
import code.name.monkey.retromusic.glide.SongGlideRequest
|
||||
import code.name.monkey.retromusic.misc.CustomFragmentStatePagerAdapter
|
||||
import code.name.monkey.retromusic.model.Song
|
||||
import code.name.monkey.retromusic.util.*
|
||||
import code.name.monkey.retromusic.util.NavigationUtil
|
||||
import code.name.monkey.retromusic.util.PreferenceUtil
|
||||
import com.bumptech.glide.Glide
|
||||
import java.util.*
|
||||
|
||||
class AlbumCoverPagerAdapter(
|
||||
fm: FragmentManager,
|
||||
private val dataSet: ArrayList<Song>
|
||||
fm: FragmentManager,
|
||||
private val dataSet: ArrayList<Song>
|
||||
) : CustomFragmentStatePagerAdapter(fm) {
|
||||
|
||||
private var currentColorReceiver: AlbumCoverFragment.ColorReceiver? = null
|
||||
private var currentColorReceiverPosition = -1
|
||||
private var currentColorReceiver: AlbumCoverFragment.ColorReceiver? = null
|
||||
private var currentColorReceiverPosition = -1
|
||||
|
||||
override fun getItem(position: Int): Fragment {
|
||||
return AlbumCoverFragment.newInstance(dataSet[position])
|
||||
}
|
||||
override fun getItem(position: Int): Fragment {
|
||||
return AlbumCoverFragment.newInstance(dataSet[position])
|
||||
}
|
||||
|
||||
override fun getCount(): Int {
|
||||
return dataSet.size
|
||||
}
|
||||
override fun getCount(): Int {
|
||||
return dataSet.size
|
||||
}
|
||||
|
||||
override fun instantiateItem(container: ViewGroup, position: Int): Any {
|
||||
val o = super.instantiateItem(container, position)
|
||||
if (currentColorReceiver != null && currentColorReceiverPosition == position) {
|
||||
receiveColor(currentColorReceiver!!, currentColorReceiverPosition)
|
||||
}
|
||||
return o
|
||||
}
|
||||
override fun instantiateItem(container: ViewGroup, position: Int): Any {
|
||||
val o = super.instantiateItem(container, position)
|
||||
if (currentColorReceiver != null && currentColorReceiverPosition == position) {
|
||||
receiveColor(currentColorReceiver!!, currentColorReceiverPosition)
|
||||
}
|
||||
return o
|
||||
}
|
||||
|
||||
/**
|
||||
* Only the latest passed [AlbumCoverFragment.ColorReceiver] is guaranteed to receive a
|
||||
* response
|
||||
*/
|
||||
fun receiveColor(colorReceiver: AlbumCoverFragment.ColorReceiver, position: Int) {
|
||||
/**
|
||||
* Only the latest passed [AlbumCoverFragment.ColorReceiver] is guaranteed to receive a
|
||||
* response
|
||||
*/
|
||||
fun receiveColor(colorReceiver: AlbumCoverFragment.ColorReceiver, position: Int) {
|
||||
|
||||
if (getFragment(position) is AlbumCoverFragment) {
|
||||
val fragment = getFragment(position) as AlbumCoverFragment
|
||||
currentColorReceiver = null
|
||||
currentColorReceiverPosition = -1
|
||||
fragment.receiveColor(colorReceiver, position)
|
||||
} else {
|
||||
currentColorReceiver = colorReceiver
|
||||
currentColorReceiverPosition = position
|
||||
}
|
||||
}
|
||||
if (getFragment(position) is AlbumCoverFragment) {
|
||||
val fragment = getFragment(position) as AlbumCoverFragment
|
||||
currentColorReceiver = null
|
||||
currentColorReceiverPosition = -1
|
||||
fragment.receiveColor(colorReceiver, position)
|
||||
} else {
|
||||
currentColorReceiver = colorReceiver
|
||||
currentColorReceiverPosition = position
|
||||
}
|
||||
}
|
||||
|
||||
class AlbumCoverFragment : Fragment() {
|
||||
class AlbumCoverFragment : Fragment() {
|
||||
|
||||
lateinit var albumCover: ImageView
|
||||
private var isColorReady: Boolean = false
|
||||
private var color: Int = 0
|
||||
private lateinit var song: Song
|
||||
private var colorReceiver: ColorReceiver? = null
|
||||
private var request: Int = 0
|
||||
lateinit var albumCover: ImageView
|
||||
private var isColorReady: Boolean = false
|
||||
private var color: Int = 0
|
||||
private lateinit var song: Song
|
||||
private var colorReceiver: ColorReceiver? = null
|
||||
private var request: Int = 0
|
||||
|
||||
private val layout: Int
|
||||
get() {
|
||||
return when (PreferenceUtil.getInstance(activity).albumCoverStyle) {
|
||||
AlbumCoverStyle.NORMAL -> R.layout.fragment_album_cover
|
||||
AlbumCoverStyle.FLAT -> R.layout.fragment_album_flat_cover
|
||||
AlbumCoverStyle.CIRCLE -> R.layout.fragment_album_circle_cover
|
||||
AlbumCoverStyle.CARD -> R.layout.fragment_album_card_cover
|
||||
AlbumCoverStyle.MATERIAL -> R.layout.fragment_album_material_cover
|
||||
AlbumCoverStyle.FULL -> R.layout.fragment_album_full_cover
|
||||
AlbumCoverStyle.FULL_CARD -> R.layout.fragment_album_full_card_cover
|
||||
else -> R.layout.fragment_album_cover
|
||||
}
|
||||
}
|
||||
private val layout: Int
|
||||
get() {
|
||||
return when (PreferenceUtil.getInstance(activity).albumCoverStyle) {
|
||||
AlbumCoverStyle.NORMAL -> R.layout.fragment_album_cover
|
||||
AlbumCoverStyle.FLAT -> R.layout.fragment_album_flat_cover
|
||||
AlbumCoverStyle.CIRCLE -> R.layout.fragment_album_circle_cover
|
||||
AlbumCoverStyle.CARD -> R.layout.fragment_album_card_cover
|
||||
AlbumCoverStyle.MATERIAL -> R.layout.fragment_album_material_cover
|
||||
AlbumCoverStyle.FULL -> R.layout.fragment_album_full_cover
|
||||
AlbumCoverStyle.FULL_CARD -> R.layout.fragment_album_full_card_cover
|
||||
else -> R.layout.fragment_album_cover
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
if (arguments != null) {
|
||||
song = arguments!!.getParcelable(SONG_ARG)!!
|
||||
}
|
||||
}
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
if (arguments != null) {
|
||||
song = arguments!!.getParcelable(SONG_ARG)!!
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View? {
|
||||
val finalLayout = when {
|
||||
PreferenceUtil.getInstance(activity).carouselEffect() -> R.layout.fragment_album_carousel_cover
|
||||
else -> layout
|
||||
}
|
||||
val view = inflater.inflate(finalLayout, container, false)
|
||||
albumCover = view.findViewById(R.id.player_image)
|
||||
albumCover.setOnClickListener {
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View? {
|
||||
val finalLayout = when {
|
||||
PreferenceUtil.getInstance(activity).carouselEffect() -> R.layout.fragment_album_carousel_cover
|
||||
else -> layout
|
||||
}
|
||||
val view = inflater.inflate(finalLayout, container, false)
|
||||
albumCover = view.findViewById(R.id.player_image)
|
||||
albumCover.setOnClickListener {
|
||||
|
||||
NavigationUtil.goToLyrics(requireActivity())
|
||||
}
|
||||
return view
|
||||
}
|
||||
NavigationUtil.goToLyrics(requireActivity())
|
||||
}
|
||||
return view
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
loadAlbumCover()
|
||||
}
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
loadAlbumCover()
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
colorReceiver = null
|
||||
}
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
colorReceiver = null
|
||||
}
|
||||
|
||||
private fun loadAlbumCover() {
|
||||
SongGlideRequest.Builder.from(Glide.with(requireContext()), song)
|
||||
.checkIgnoreMediaStore(activity).generatePalette(activity).build()
|
||||
.into(object : RetroMusicColoredTarget(albumCover) {
|
||||
override fun onColorReady(color: Int) {
|
||||
setColor(color)
|
||||
}
|
||||
})
|
||||
}
|
||||
private fun loadAlbumCover() {
|
||||
SongGlideRequest.Builder.from(Glide.with(requireContext()), song)
|
||||
.checkIgnoreMediaStore(requireContext())
|
||||
.generatePalette(requireContext()).build()
|
||||
.into(object : RetroMusicColoredTarget(albumCover) {
|
||||
override fun onColorReady(color: Int) {
|
||||
setColor(color)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun setColor(color: Int) {
|
||||
this.color = color
|
||||
isColorReady = true
|
||||
if (colorReceiver != null) {
|
||||
colorReceiver!!.onColorReady(color, request)
|
||||
colorReceiver = null
|
||||
}
|
||||
}
|
||||
private fun setColor(color: Int) {
|
||||
this.color = color
|
||||
isColorReady = true
|
||||
if (colorReceiver != null) {
|
||||
colorReceiver!!.onColorReady(color, request)
|
||||
colorReceiver = null
|
||||
}
|
||||
}
|
||||
|
||||
internal fun receiveColor(colorReceiver: ColorReceiver, request: Int) {
|
||||
if (isColorReady) {
|
||||
colorReceiver.onColorReady(color, request)
|
||||
} else {
|
||||
this.colorReceiver = colorReceiver
|
||||
this.request = request
|
||||
}
|
||||
}
|
||||
internal fun receiveColor(colorReceiver: ColorReceiver, request: Int) {
|
||||
if (isColorReady) {
|
||||
colorReceiver.onColorReady(color, request)
|
||||
} else {
|
||||
this.colorReceiver = colorReceiver
|
||||
this.request = request
|
||||
}
|
||||
}
|
||||
|
||||
interface ColorReceiver {
|
||||
fun onColorReady(color: Int, request: Int)
|
||||
}
|
||||
interface ColorReceiver {
|
||||
fun onColorReady(color: Int, request: Int)
|
||||
}
|
||||
|
||||
companion object {
|
||||
companion object {
|
||||
|
||||
private const val SONG_ARG = "song"
|
||||
private const val SONG_ARG = "song"
|
||||
|
||||
fun newInstance(song: Song): AlbumCoverFragment {
|
||||
val frag = AlbumCoverFragment()
|
||||
val args = Bundle()
|
||||
args.putParcelable(SONG_ARG, song)
|
||||
frag.arguments = args
|
||||
return frag
|
||||
}
|
||||
}
|
||||
}
|
||||
fun newInstance(song: Song): AlbumCoverFragment {
|
||||
val frag = AlbumCoverFragment()
|
||||
val args = Bundle()
|
||||
args.putParcelable(SONG_ARG, song)
|
||||
frag.arguments = args
|
||||
return frag
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
val TAG: String = AlbumCoverPagerAdapter::class.java.simpleName
|
||||
}
|
||||
companion object {
|
||||
val TAG: String = AlbumCoverPagerAdapter::class.java.simpleName
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,6 @@ import android.provider.MediaStore.Audio.AudioColumns
|
|||
import code.name.monkey.retromusic.model.Album
|
||||
import code.name.monkey.retromusic.model.Song
|
||||
import code.name.monkey.retromusic.util.PreferenceUtil
|
||||
import io.reactivex.Observable
|
||||
import java.util.*
|
||||
import kotlin.collections.ArrayList
|
||||
|
||||
|
@ -29,31 +28,6 @@ import kotlin.collections.ArrayList
|
|||
*/
|
||||
|
||||
object AlbumLoader {
|
||||
fun getAllAlbumsFlowable(
|
||||
context: Context
|
||||
): Observable<ArrayList<Album>> {
|
||||
val songs = SongLoader.getSongsFlowable(
|
||||
SongLoader.makeSongCursor(
|
||||
context, null, null,
|
||||
getSongLoaderSortOrder(context))
|
||||
)
|
||||
|
||||
return splitIntoAlbumsFlowable(songs)
|
||||
}
|
||||
|
||||
fun getAlbumsFlowable(
|
||||
context: Context,
|
||||
query: String
|
||||
): Observable<ArrayList<Album>> {
|
||||
val songs = SongLoader.getSongsFlowable(
|
||||
SongLoader.makeSongCursor(
|
||||
context,
|
||||
AudioColumns.ALBUM + " LIKE ?",
|
||||
arrayOf("%$query%"),
|
||||
getSongLoaderSortOrder(context))
|
||||
)
|
||||
return splitIntoAlbumsFlowable(songs)
|
||||
}
|
||||
|
||||
fun getAlbums(
|
||||
context: Context,
|
||||
|
@ -68,26 +42,6 @@ object AlbumLoader {
|
|||
return splitIntoAlbums(songs)
|
||||
}
|
||||
|
||||
fun getAlbumFlowable(
|
||||
context: Context,
|
||||
albumId: Int
|
||||
): Observable<Album> {
|
||||
return Observable.create { e ->
|
||||
val songs = SongLoader.getSongsFlowable(
|
||||
SongLoader.makeSongCursor(
|
||||
context,
|
||||
AudioColumns.ALBUM_ID + "=?",
|
||||
arrayOf(albumId.toString()),
|
||||
getSongLoaderSortOrder(context)
|
||||
)
|
||||
)
|
||||
songs.subscribe { songs1 ->
|
||||
e.onNext(Album(songs1))
|
||||
e.onComplete()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun getAlbum(
|
||||
context: Context,
|
||||
albumId: Int
|
||||
|
@ -103,35 +57,10 @@ object AlbumLoader {
|
|||
return album
|
||||
}
|
||||
|
||||
fun splitIntoAlbumsFlowable(
|
||||
songs: Observable<ArrayList<Song>>?
|
||||
): Observable<ArrayList<Album>> {
|
||||
return Observable.create { e ->
|
||||
val albums = ArrayList<Album>()
|
||||
songs?.subscribe { songs1 ->
|
||||
for (song in songs1) {
|
||||
getOrCreateAlbumFlowable(albums, song.albumId).subscribe { album ->
|
||||
album.songs!!.add(song)
|
||||
}
|
||||
}
|
||||
}
|
||||
for (album in albums) {
|
||||
sortSongsByTrackNumber(album)
|
||||
}
|
||||
e.onNext(albums)
|
||||
e.onComplete()
|
||||
}
|
||||
}
|
||||
|
||||
fun getAllAlbums(
|
||||
context: Context
|
||||
): ArrayList<Album> {
|
||||
val songs = SongLoader.getSongs(
|
||||
SongLoader.makeSongCursor(
|
||||
context, null, null,
|
||||
getSongLoaderSortOrder(context))
|
||||
)
|
||||
|
||||
val songs = SongLoader.getSongs(SongLoader.makeSongCursor(context, null, null, getSongLoaderSortOrder(context)))
|
||||
return splitIntoAlbums(songs)
|
||||
}
|
||||
|
||||
|
@ -150,25 +79,6 @@ object AlbumLoader {
|
|||
return albums
|
||||
}
|
||||
|
||||
private fun getOrCreateAlbumFlowable(
|
||||
albums: ArrayList<Album>,
|
||||
albumId: Int
|
||||
): Observable<Album> {
|
||||
return Observable.create { e ->
|
||||
for (album in albums) {
|
||||
if (!album.songs!!.isEmpty() && album.songs[0].albumId == albumId) {
|
||||
e.onNext(album)
|
||||
e.onComplete()
|
||||
return@create
|
||||
}
|
||||
}
|
||||
val album = Album()
|
||||
albums.add(album)
|
||||
e.onNext(album)
|
||||
e.onComplete()
|
||||
}
|
||||
}
|
||||
|
||||
private fun getOrCreateAlbum(
|
||||
albums: ArrayList<Album>,
|
||||
albumId: Int
|
||||
|
@ -183,14 +93,11 @@ object AlbumLoader {
|
|||
return album
|
||||
}
|
||||
|
||||
private fun sortSongsByTrackNumber(
|
||||
album: Album
|
||||
) {
|
||||
album.songs?.sortWith(Comparator { o1, o2 -> o1.trackNumber - o2.trackNumber })
|
||||
private fun sortSongsByTrackNumber(album: Album) {
|
||||
album.songs?.sortWith(Comparator { o1, o2 -> o1.trackNumber.compareTo(o2.trackNumber) })
|
||||
}
|
||||
|
||||
private fun getSongLoaderSortOrder(context: Context): String {
|
||||
return PreferenceUtil.getInstance(context).albumSortOrder + ", " +
|
||||
PreferenceUtil.getInstance(context).albumDetailSongSortOrder
|
||||
return PreferenceUtil.getInstance(context).albumSortOrder + ", " + PreferenceUtil.getInstance(context).albumSongSortOrder
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,15 +19,11 @@ import android.provider.MediaStore.Audio.AudioColumns
|
|||
import code.name.monkey.retromusic.model.Album
|
||||
import code.name.monkey.retromusic.model.Artist
|
||||
import code.name.monkey.retromusic.util.PreferenceUtil
|
||||
import io.reactivex.Observable
|
||||
|
||||
|
||||
object ArtistLoader {
|
||||
private fun getSongLoaderSortOrder(context: Context): String {
|
||||
return PreferenceUtil.getInstance(context).artistSortOrder + ", " +
|
||||
PreferenceUtil.getInstance(context).artistAlbumSortOrder + ", " +
|
||||
PreferenceUtil.getInstance(context).albumDetailSongSortOrder + ", " +
|
||||
PreferenceUtil.getInstance(context).artistDetailSongSortOrder
|
||||
return PreferenceUtil.getInstance(context).artistSortOrder + ", " + PreferenceUtil.getInstance(context).artistAlbumSortOrder + ", " + PreferenceUtil.getInstance(context).albumSongSortOrder
|
||||
}
|
||||
|
||||
fun getAllArtists(context: Context): ArrayList<Artist> {
|
||||
|
@ -70,34 +66,6 @@ object ArtistLoader {
|
|||
return album
|
||||
}
|
||||
|
||||
fun splitIntoArtists(albums: Observable<ArrayList<Album>>): Observable<ArrayList<Artist>> {
|
||||
return Observable.create { e ->
|
||||
val artists = ArrayList<Artist>()
|
||||
albums.subscribe { localAlbums ->
|
||||
if (localAlbums != null) {
|
||||
for (album in localAlbums) {
|
||||
getOrCreateArtist(artists, album.artistId).albums!!.add(album)
|
||||
}
|
||||
}
|
||||
e.onNext(artists)
|
||||
e.onComplete()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun getArtistFlowable(context: Context, artistId: Int): Observable<Artist> {
|
||||
return Observable.create { e ->
|
||||
SongLoader.getSongsFlowable(SongLoader.makeSongCursor(context, AudioColumns.ARTIST_ID + "=?",
|
||||
arrayOf(artistId.toString()),
|
||||
getSongLoaderSortOrder(context)))
|
||||
.subscribe { songs ->
|
||||
val artist = Artist(AlbumLoader.splitIntoAlbums(songs))
|
||||
e.onNext(artist)
|
||||
e.onComplete()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun getArtist(context: Context, artistId: Int): Artist {
|
||||
val songs = SongLoader.getSongs(SongLoader.makeSongCursor(
|
||||
context,
|
||||
|
|
|
@ -21,9 +21,6 @@ import code.name.monkey.retromusic.model.Album
|
|||
import code.name.monkey.retromusic.model.Artist
|
||||
import code.name.monkey.retromusic.model.Song
|
||||
import code.name.monkey.retromusic.util.PreferenceUtil
|
||||
import io.reactivex.Observable
|
||||
import java.util.*
|
||||
import kotlin.collections.ArrayList
|
||||
|
||||
/**
|
||||
* Created by hemanths on 16/08/17.
|
||||
|
@ -31,11 +28,6 @@ import kotlin.collections.ArrayList
|
|||
|
||||
object LastAddedSongsLoader {
|
||||
|
||||
|
||||
fun getLastAddedSongsFlowable(context: Context): Observable<ArrayList<Song>> {
|
||||
return SongLoader.getSongsFlowable(makeLastAddedCursor(context))
|
||||
}
|
||||
|
||||
fun getLastAddedSongs(context: Context): ArrayList<Song> {
|
||||
return SongLoader.getSongs(makeLastAddedCursor(context))
|
||||
}
|
||||
|
@ -50,21 +42,10 @@ object LastAddedSongsLoader {
|
|||
MediaStore.Audio.Media.DATE_ADDED + " DESC")
|
||||
}
|
||||
|
||||
|
||||
fun getLastAddedAlbumsFlowable(context: Context): Observable<ArrayList<Album>> {
|
||||
return AlbumLoader.splitIntoAlbumsFlowable(getLastAddedSongsFlowable(context))
|
||||
}
|
||||
|
||||
|
||||
fun getLastAddedAlbums(context: Context): ArrayList<Album> {
|
||||
return AlbumLoader.splitIntoAlbums(getLastAddedSongs(context))
|
||||
}
|
||||
|
||||
|
||||
fun getLastAddedArtistsFlowable(context: Context): Observable<ArrayList<Artist>> {
|
||||
return ArtistLoader.splitIntoArtists(getLastAddedAlbumsFlowable(context))
|
||||
}
|
||||
|
||||
fun getLastAddedArtists(context: Context): ArrayList<Artist> {
|
||||
return ArtistLoader.splitIntoArtists(getLastAddedAlbums(context))
|
||||
}
|
||||
|
|
|
@ -23,8 +23,6 @@ import org.jetbrains.annotations.NotNull;
|
|||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
|
||||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
|
@ -41,9 +39,6 @@ public abstract class AbsCustomPlaylist extends Playlist {
|
|||
super(in);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public abstract Observable<ArrayList<Song>> getSongsFlowable(@NotNull Context context);
|
||||
|
||||
@NonNull
|
||||
public abstract ArrayList<Song> getSongs(@NotNull Context context);
|
||||
}
|
||||
|
|
|
@ -27,7 +27,6 @@ import code.name.monkey.retromusic.R;
|
|||
import code.name.monkey.retromusic.loaders.TopAndRecentlyPlayedTracksLoader;
|
||||
import code.name.monkey.retromusic.model.Song;
|
||||
import code.name.monkey.retromusic.providers.HistoryStore;
|
||||
import io.reactivex.Observable;
|
||||
|
||||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
|
@ -52,12 +51,6 @@ public class HistoryPlaylist extends AbsSmartPlaylist {
|
|||
super(in);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Observable<ArrayList<Song>> getSongsFlowable(@NotNull @NonNull Context context) {
|
||||
return TopAndRecentlyPlayedTracksLoader.INSTANCE.getRecentlyPlayedTracksFlowable(context);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public ArrayList<Song> getSongs(@NotNull @NonNull Context context) {
|
||||
|
|
|
@ -26,7 +26,6 @@ import java.util.ArrayList;
|
|||
import code.name.monkey.retromusic.R;
|
||||
import code.name.monkey.retromusic.loaders.LastAddedSongsLoader;
|
||||
import code.name.monkey.retromusic.model.Song;
|
||||
import io.reactivex.Observable;
|
||||
|
||||
|
||||
public class LastAddedPlaylist extends AbsSmartPlaylist {
|
||||
|
@ -49,12 +48,6 @@ public class LastAddedPlaylist extends AbsSmartPlaylist {
|
|||
super(in);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Observable<ArrayList<Song>> getSongsFlowable(@NotNull @NonNull Context context) {
|
||||
return LastAddedSongsLoader.INSTANCE.getLastAddedSongsFlowable(context);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public ArrayList<Song> getSongs(@NotNull @NonNull Context context) {
|
||||
|
|
|
@ -27,7 +27,6 @@ import code.name.monkey.retromusic.R;
|
|||
import code.name.monkey.retromusic.loaders.TopAndRecentlyPlayedTracksLoader;
|
||||
import code.name.monkey.retromusic.model.Song;
|
||||
import code.name.monkey.retromusic.providers.SongPlayCountStore;
|
||||
import io.reactivex.Observable;
|
||||
|
||||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
|
@ -52,11 +51,6 @@ public class MyTopTracksPlaylist extends AbsSmartPlaylist {
|
|||
super(in);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Observable<ArrayList<Song>> getSongsFlowable(@NotNull @NonNull Context context) {
|
||||
return TopAndRecentlyPlayedTracksLoader.INSTANCE.getTopTracksFlowable(context);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
|
|
|
@ -14,13 +14,16 @@
|
|||
|
||||
package code.name.monkey.retromusic.mvp.presenter
|
||||
|
||||
import code.name.monkey.retromusic.Result
|
||||
import code.name.monkey.retromusic.Result.Success
|
||||
import code.name.monkey.retromusic.model.Album
|
||||
import code.name.monkey.retromusic.model.Artist
|
||||
import code.name.monkey.retromusic.mvp.Presenter
|
||||
import code.name.monkey.retromusic.mvp.PresenterImpl
|
||||
import code.name.monkey.retromusic.providers.interfaces.Repository
|
||||
import io.reactivex.disposables.CompositeDisposable
|
||||
import kotlinx.coroutines.*
|
||||
import javax.inject.Inject
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
|
||||
|
||||
/**
|
||||
|
@ -43,44 +46,47 @@ interface AlbumDetailsPresenter : Presenter<AlbumDetailsView> {
|
|||
|
||||
class AlbumDetailsPresenterImpl @Inject constructor(
|
||||
private val repository: Repository
|
||||
) : PresenterImpl<AlbumDetailsView>(), AlbumDetailsPresenter {
|
||||
|
||||
) : PresenterImpl<AlbumDetailsView>(), AlbumDetailsPresenter, CoroutineScope {
|
||||
private val job = Job()
|
||||
private lateinit var album: Album
|
||||
|
||||
private var disposable: CompositeDisposable = CompositeDisposable()
|
||||
|
||||
override fun loadMore(artistId: Int) {
|
||||
disposable += repository.getArtistByIdFlowable(artistId)
|
||||
.map {
|
||||
view?.loadArtistImage(it)
|
||||
return@map it.albums
|
||||
}
|
||||
.map {
|
||||
it.filter { filterAlbum -> album.id != filterAlbum.id }
|
||||
}
|
||||
.subscribe({
|
||||
if (it.isEmpty()) {
|
||||
return@subscribe
|
||||
}
|
||||
view?.moreAlbums(ArrayList(it))
|
||||
}, { t -> println(t) })
|
||||
launch {
|
||||
when (val result = repository.artistById(artistId)) {
|
||||
is Success -> withContext(Dispatchers.Main) { showArtistImage(result.data) }
|
||||
is Result.Error -> withContext(Dispatchers.Main) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun showArtistImage(artist: Artist) {
|
||||
view?.loadArtistImage(artist)
|
||||
|
||||
artist.albums?.filter { it.id != album.id }?.let {
|
||||
view?.moreAlbums(ArrayList(it))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
override fun loadAlbum(albumId: Int) {
|
||||
disposable += repository.getAlbumFlowable(albumId)
|
||||
.doOnComplete {
|
||||
view?.complete()
|
||||
launch {
|
||||
when (val result = repository.albumById(albumId)) {
|
||||
is Success -> withContext(Dispatchers.Main) {
|
||||
album = result.data
|
||||
view?.album(result.data)
|
||||
}
|
||||
.subscribe({
|
||||
album = it
|
||||
view?.album(it)
|
||||
}, { t -> println(t) })
|
||||
is Error -> withContext(Dispatchers.Main) { view?.complete() }
|
||||
}
|
||||
view?.complete()
|
||||
}
|
||||
}
|
||||
|
||||
override fun detachView() {
|
||||
super.detachView()
|
||||
disposable.dispose()
|
||||
job.cancel()
|
||||
}
|
||||
|
||||
override val coroutineContext: CoroutineContext
|
||||
get() = Dispatchers.IO + job
|
||||
}
|
||||
}
|
|
@ -25,9 +25,6 @@ import code.name.monkey.retromusic.model.*
|
|||
import code.name.monkey.retromusic.providers.interfaces.Repository
|
||||
import code.name.monkey.retromusic.rest.LastFMRestClient
|
||||
import code.name.monkey.retromusic.rest.model.LastFmArtist
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import java.io.IOException
|
||||
|
||||
class RepositoryImpl(private val context: Context) : Repository {
|
||||
|
@ -45,6 +42,19 @@ class RepositoryImpl(private val context: Context) : Repository {
|
|||
}
|
||||
}
|
||||
|
||||
override suspend fun albumById(albumId: Int): Result<Album> {
|
||||
return try {
|
||||
val album = AlbumLoader.getAlbum(context, albumId)
|
||||
if (album != null) {
|
||||
Success(album)
|
||||
} else {
|
||||
Error(Throwable("No album"))
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Error(e)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun allArtists(): Result<ArrayList<Artist>> {
|
||||
return try {
|
||||
val artists = ArtistLoader.getAllArtists(context)
|
||||
|
@ -246,43 +256,6 @@ class RepositoryImpl(private val context: Context) : Repository {
|
|||
Error(Throwable("Error loading artist"))
|
||||
}
|
||||
}
|
||||
|
||||
override fun getAlbumFlowable(albumId: Int): Observable<Album> {
|
||||
return AlbumLoader.getAlbumFlowable(context, albumId)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
}
|
||||
|
||||
override fun getArtistByIdFlowable(artistId: Int): Observable<Artist> {
|
||||
return ArtistLoader.getArtistFlowable(context, artistId)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
}
|
||||
|
||||
override fun getPlaylistSongsFlowable(playlist: Playlist): Observable<ArrayList<Song>> {
|
||||
return PlaylistSongsLoader.getPlaylistSongListFlowable(context, playlist)
|
||||
.subscribeOn(Schedulers.computation())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
}
|
||||
|
||||
override val favoritePlaylistFlowable: Observable<ArrayList<Playlist>>
|
||||
get() = PlaylistLoader.getFavoritePlaylistFlowable(context)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
|
||||
|
||||
override fun getSong(id: Int): Song {
|
||||
return SongLoader.getSong(context, id)
|
||||
}
|
||||
|
||||
override fun getAlbum(albumId: Int): Album {
|
||||
return AlbumLoader.getAlbum(context, albumId)
|
||||
}
|
||||
|
||||
override fun getArtistById(artistId: Long): Artist {
|
||||
return ArtistLoader.getArtist(context, artistId.toInt())
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
suspend fun <T : Any> safeApiCall(call: suspend () -> Result<T>, errorMessage: String): Result<T> = try {
|
||||
|
|
|
@ -17,7 +17,6 @@ package code.name.monkey.retromusic.providers.interfaces
|
|||
import code.name.monkey.retromusic.Result
|
||||
import code.name.monkey.retromusic.model.*
|
||||
import code.name.monkey.retromusic.rest.model.LastFmArtist
|
||||
import io.reactivex.Observable
|
||||
|
||||
/**
|
||||
* Created by hemanths on 11/08/17.
|
||||
|
@ -27,6 +26,8 @@ interface Repository {
|
|||
|
||||
suspend fun allAlbums(): Result<ArrayList<Album>>
|
||||
|
||||
suspend fun albumById(albumId: Int): Result<Album>
|
||||
|
||||
suspend fun allSongs(): Result<ArrayList<Song>>
|
||||
|
||||
suspend fun allArtists(): Result<ArrayList<Artist>>
|
||||
|
@ -54,19 +55,4 @@ interface Repository {
|
|||
suspend fun artistInfo(name: String, lang: String?, cache: String?): Result<LastFmArtist>
|
||||
|
||||
suspend fun artistById(artistId: Int): Result<Artist>
|
||||
|
||||
fun getSong(id: Int): Song
|
||||
|
||||
fun getAlbumFlowable(albumId: Int): Observable<Album>
|
||||
|
||||
fun getAlbum(albumId: Int): Album
|
||||
|
||||
fun getArtistByIdFlowable(artistId: Int): Observable<Artist>
|
||||
|
||||
fun getArtistById(artistId: Long): Artist
|
||||
|
||||
fun getPlaylistSongsFlowable(playlist: Playlist): Observable<ArrayList<Song>>
|
||||
|
||||
val favoritePlaylistFlowable: Observable<ArrayList<Playlist>>
|
||||
|
||||
}
|
|
@ -42,6 +42,7 @@ import code.name.monkey.retromusic.model.Album;
|
|||
import code.name.monkey.retromusic.model.Artist;
|
||||
import code.name.monkey.retromusic.model.Playlist;
|
||||
import code.name.monkey.retromusic.model.Song;
|
||||
import code.name.monkey.retromusic.util.MusicUtil;
|
||||
import code.name.monkey.retromusic.util.RetroUtil;
|
||||
|
||||
/**
|
||||
|
@ -234,7 +235,7 @@ public class WearBrowserService extends MediaBrowserService {
|
|||
Integer.toString(TYPE_ALBUM_SONGS) + Long.toString(album.getId()),
|
||||
album.getTitle(),
|
||||
album.getArtistName(),
|
||||
RetroUtil.getAlbumArtUri(album.getId()),
|
||||
MusicUtil.getMediaStoreAlbumCoverUri(album.getId()),
|
||||
MediaBrowser.MediaItem.FLAG_BROWSABLE);
|
||||
}
|
||||
break;
|
||||
|
|
Loading…
Reference in a new issue