Code refactor ArrayList to List
This commit is contained in:
parent
67f4b4ecf2
commit
87954b43f2
43 changed files with 236 additions and 305 deletions
|
@ -214,12 +214,12 @@ class AlbumDetailsActivity : AbsSlidingMusicPanelActivity(), AlbumDetailsView, C
|
||||||
albumDetailsPresenter.aboutAlbum(album.artistName!!, album.title!!)
|
albumDetailsPresenter.aboutAlbum(album.artistName!!, album.title!!)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun moreAlbums(albums: ArrayList<Album>) {
|
override fun moreAlbums(albums: List<Album>) {
|
||||||
moreTitle.show()
|
moreTitle.show()
|
||||||
moreRecyclerView.show()
|
moreRecyclerView.show()
|
||||||
moreTitle.text = String.format(getString(R.string.label_more_from), album.artistName)
|
moreTitle.text = String.format(getString(R.string.label_more_from), album.artistName)
|
||||||
|
|
||||||
val albumAdapter = HorizontalAlbumAdapter(this, albums, false, null)
|
val albumAdapter = HorizontalAlbumAdapter(this, albums, null)
|
||||||
moreRecyclerView.layoutManager = GridLayoutManager(
|
moreRecyclerView.layoutManager = GridLayoutManager(
|
||||||
this,
|
this,
|
||||||
1,
|
1,
|
||||||
|
|
|
@ -154,7 +154,7 @@ class ArtistDetailActivity : AbsSlidingMusicPanelActivity(), ArtistDetailsView,
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupRecyclerView() {
|
private fun setupRecyclerView() {
|
||||||
albumAdapter = HorizontalAlbumAdapter(this, ArrayList(), false, null)
|
albumAdapter = HorizontalAlbumAdapter(this, ArrayList(), null)
|
||||||
albumRecyclerView.apply {
|
albumRecyclerView.apply {
|
||||||
itemAnimator = DefaultItemAnimator()
|
itemAnimator = DefaultItemAnimator()
|
||||||
layoutManager = GridLayoutManager(this.context, 1, GridLayoutManager.HORIZONTAL, false)
|
layoutManager = GridLayoutManager(this.context, 1, GridLayoutManager.HORIZONTAL, false)
|
||||||
|
|
|
@ -129,7 +129,7 @@ class GenreDetailsActivity : AbsSlidingMusicPanelActivity(), CabHolder, GenreDet
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun songs(songs: ArrayList<Song>) {
|
override fun songs(songs: List<Song>) {
|
||||||
songAdapter.swapDataSet(songs)
|
songAdapter.swapDataSet(songs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -220,8 +220,20 @@ class MainActivity : AbsSlidingMusicPanelActivity(), SharedPreferences.OnSharedP
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String) {
|
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String) {
|
||||||
if (key == PreferenceUtil.GENERAL_THEME || key == PreferenceUtil.BLACK_THEME || key == PreferenceUtil.ADAPTIVE_COLOR_APP || key == PreferenceUtil.DOMINANT_COLOR || key == PreferenceUtil.USER_NAME || key == PreferenceUtil.TOGGLE_FULL_SCREEN || key == PreferenceUtil.TOGGLE_VOLUME || key == PreferenceUtil.ROUND_CORNERS || key == PreferenceUtil.CAROUSEL_EFFECT || key == PreferenceUtil.NOW_PLAYING_SCREEN_ID || key == PreferenceUtil.TOGGLE_GENRE || key == PreferenceUtil.BANNER_IMAGE_PATH || key == PreferenceUtil.PROFILE_IMAGE_PATH || key == PreferenceUtil.CIRCULAR_ALBUM_ART || key == PreferenceUtil.KEEP_SCREEN_ON || key == PreferenceUtil.TOGGLE_SEPARATE_LINE || key == PreferenceUtil.ALBUM_GRID_STYLE || key == PreferenceUtil.ARTIST_GRID_STYLE || key == PreferenceUtil.TOGGLE_HOME_BANNER || key == PreferenceUtil.TOGGLE_ADD_CONTROLS || key == PreferenceUtil.ALBUM_COVER_STYLE || key == PreferenceUtil.HOME_ARTIST_GRID_STYLE || key == PreferenceUtil.ALBUM_COVER_TRANSFORM || key == PreferenceUtil.DESATURATED_COLOR || key == PreferenceUtil.TAB_TEXT_MODE || key == PreferenceUtil.LIBRARY_CATEGORIES
|
if (key == PreferenceUtil.GENERAL_THEME || key == PreferenceUtil.BLACK_THEME ||
|
||||||
) postRecreate()
|
key == PreferenceUtil.ADAPTIVE_COLOR_APP || key == PreferenceUtil.DOMINANT_COLOR ||
|
||||||
|
key == PreferenceUtil.USER_NAME || key == PreferenceUtil.TOGGLE_FULL_SCREEN ||
|
||||||
|
key == PreferenceUtil.TOGGLE_VOLUME || key == PreferenceUtil.ROUND_CORNERS ||
|
||||||
|
key == PreferenceUtil.CAROUSEL_EFFECT || key == PreferenceUtil.NOW_PLAYING_SCREEN_ID ||
|
||||||
|
key == PreferenceUtil.TOGGLE_GENRE || key == PreferenceUtil.BANNER_IMAGE_PATH ||
|
||||||
|
key == PreferenceUtil.PROFILE_IMAGE_PATH || key == PreferenceUtil.CIRCULAR_ALBUM_ART ||
|
||||||
|
key == PreferenceUtil.KEEP_SCREEN_ON || key == PreferenceUtil.TOGGLE_SEPARATE_LINE ||
|
||||||
|
key == PreferenceUtil.TOGGLE_HOME_BANNER || key == PreferenceUtil.TOGGLE_ADD_CONTROLS ||
|
||||||
|
key == PreferenceUtil.ALBUM_COVER_STYLE || key == PreferenceUtil.HOME_ARTIST_GRID_STYLE ||
|
||||||
|
key == PreferenceUtil.ALBUM_COVER_TRANSFORM || key == PreferenceUtil.DESATURATED_COLOR ||
|
||||||
|
key == PreferenceUtil.TAB_TEXT_MODE || key == PreferenceUtil.LIBRARY_CATEGORIES
|
||||||
|
)
|
||||||
|
postRecreate()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun selectedFragment(itemId: Int) {
|
private fun selectedFragment(itemId: Int) {
|
||||||
|
|
|
@ -238,7 +238,7 @@ class PlaylistDetailActivity : AbsSlidingMusicPanelActivity(), CabHolder, Playli
|
||||||
emptyText.visibility = View.VISIBLE
|
emptyText.visibility = View.VISIBLE
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun songs(songs: ArrayList<Song>) {
|
override fun songs(songs: List<Song>) {
|
||||||
adapter.swapDataSet(songs)
|
adapter.swapDataSet(songs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,6 @@ import code.name.monkey.retromusic.R
|
||||||
import code.name.monkey.retromusic.adapter.base.MediaEntryViewHolder
|
import code.name.monkey.retromusic.adapter.base.MediaEntryViewHolder
|
||||||
import code.name.monkey.retromusic.model.Genre
|
import code.name.monkey.retromusic.model.Genre
|
||||||
import code.name.monkey.retromusic.util.NavigationUtil
|
import code.name.monkey.retromusic.util.NavigationUtil
|
||||||
import java.util.ArrayList
|
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -18,16 +17,10 @@ import java.util.Locale
|
||||||
|
|
||||||
class GenreAdapter(
|
class GenreAdapter(
|
||||||
private val activity: Activity,
|
private val activity: Activity,
|
||||||
dataSet: ArrayList<Genre>,
|
var dataSet: List<Genre>,
|
||||||
private val mItemLayoutRes: Int
|
private val mItemLayoutRes: Int
|
||||||
) : RecyclerView.Adapter<GenreAdapter.ViewHolder>() {
|
) : RecyclerView.Adapter<GenreAdapter.ViewHolder>() {
|
||||||
|
|
||||||
var dataSet = ArrayList<Genre>()
|
|
||||||
private set
|
|
||||||
|
|
||||||
init {
|
|
||||||
this.dataSet = dataSet
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||||
return ViewHolder(LayoutInflater.from(activity).inflate(mItemLayoutRes, parent, false))
|
return ViewHolder(LayoutInflater.from(activity).inflate(mItemLayoutRes, parent, false))
|
||||||
|
@ -48,7 +41,7 @@ class GenreAdapter(
|
||||||
return dataSet.size
|
return dataSet.size
|
||||||
}
|
}
|
||||||
|
|
||||||
fun swapDataSet(list: ArrayList<Genre>) {
|
fun swapDataSet(list: List<Genre>) {
|
||||||
dataSet = list
|
dataSet = list
|
||||||
notifyDataSetChanged()
|
notifyDataSetChanged()
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ class HomeAdapter(
|
||||||
private val displayMetrics: DisplayMetrics
|
private val displayMetrics: DisplayMetrics
|
||||||
) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
|
) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
|
||||||
|
|
||||||
private var list = ArrayList<Home>()
|
private var list = listOf<Home>()
|
||||||
|
|
||||||
override fun getItemViewType(position: Int): Int {
|
override fun getItemViewType(position: Int): Int {
|
||||||
return list[position].homeSection
|
return list[position].homeSection
|
||||||
|
@ -81,7 +81,7 @@ class HomeAdapter(
|
||||||
return list.size
|
return list.size
|
||||||
}
|
}
|
||||||
|
|
||||||
fun swapData(sections: ArrayList<Home>) {
|
fun swapData(sections: List<Home>) {
|
||||||
list = sections
|
list = sections
|
||||||
notifyDataSetChanged()
|
notifyDataSetChanged()
|
||||||
}
|
}
|
||||||
|
@ -121,7 +121,6 @@ class HomeAdapter(
|
||||||
activity,
|
activity,
|
||||||
list,
|
list,
|
||||||
PreferenceUtil.getInstance(activity).getHomeGridStyle(activity),
|
PreferenceUtil.getInstance(activity).getHomeGridStyle(activity),
|
||||||
false,
|
|
||||||
null
|
null
|
||||||
)
|
)
|
||||||
adapter = artistAdapter
|
adapter = artistAdapter
|
||||||
|
|
|
@ -29,9 +29,8 @@ import me.zhanghai.android.fastscroll.PopupTextProvider
|
||||||
|
|
||||||
open class AlbumAdapter(
|
open class AlbumAdapter(
|
||||||
protected val activity: AppCompatActivity,
|
protected val activity: AppCompatActivity,
|
||||||
dataSet: ArrayList<Album>,
|
var dataSet: List<Album>,
|
||||||
protected var itemLayoutRes: Int,
|
protected var itemLayoutRes: Int,
|
||||||
usePalette: Boolean,
|
|
||||||
cabHolder: CabHolder?
|
cabHolder: CabHolder?
|
||||||
) : AbsMultiSelectAdapter<AlbumAdapter.ViewHolder, Album>(
|
) : AbsMultiSelectAdapter<AlbumAdapter.ViewHolder, Album>(
|
||||||
activity,
|
activity,
|
||||||
|
@ -39,28 +38,11 @@ open class AlbumAdapter(
|
||||||
R.menu.menu_media_selection
|
R.menu.menu_media_selection
|
||||||
), PopupTextProvider {
|
), PopupTextProvider {
|
||||||
|
|
||||||
var dataSet: ArrayList<Album>
|
|
||||||
protected set
|
|
||||||
|
|
||||||
protected var usePalette = false
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
this.dataSet = dataSet
|
|
||||||
this.usePalette = usePalette
|
|
||||||
this.setHasStableIds(true)
|
this.setHasStableIds(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun useItemLayout(itemLayoutRes: Int) {
|
fun swapDataSet(dataSet: List<Album>) {
|
||||||
this.itemLayoutRes = itemLayoutRes
|
|
||||||
notifyDataSetChanged()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun usePalette(usePalette: Boolean) {
|
|
||||||
this.usePalette = usePalette
|
|
||||||
notifyDataSetChanged()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun swapDataSet(dataSet: ArrayList<Album>) {
|
|
||||||
this.dataSet = dataSet
|
this.dataSet = dataSet
|
||||||
notifyDataSetChanged()
|
notifyDataSetChanged()
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ import com.bumptech.glide.Glide
|
||||||
|
|
||||||
class AlbumFullWidthAdapter(
|
class AlbumFullWidthAdapter(
|
||||||
private val activity: Activity,
|
private val activity: Activity,
|
||||||
private val dataSet: ArrayList<Album>,
|
private val dataSet: List<Album>,
|
||||||
metrics: DisplayMetrics
|
metrics: DisplayMetrics
|
||||||
) : MetalRecyclerViewPager.MetalAdapter<AlbumFullWidthAdapter.FullMetalViewHolder>(metrics) {
|
) : MetalRecyclerViewPager.MetalAdapter<AlbumFullWidthAdapter.FullMetalViewHolder>(metrics) {
|
||||||
|
|
||||||
|
|
|
@ -12,15 +12,13 @@ import code.name.monkey.retromusic.interfaces.CabHolder
|
||||||
import code.name.monkey.retromusic.model.Album
|
import code.name.monkey.retromusic.model.Album
|
||||||
import code.name.monkey.retromusic.util.MusicUtil
|
import code.name.monkey.retromusic.util.MusicUtil
|
||||||
import com.bumptech.glide.Glide
|
import com.bumptech.glide.Glide
|
||||||
import java.util.ArrayList
|
|
||||||
|
|
||||||
class HorizontalAlbumAdapter(
|
class HorizontalAlbumAdapter(
|
||||||
activity: AppCompatActivity,
|
activity: AppCompatActivity,
|
||||||
dataSet: ArrayList<Album>,
|
dataSet: List<Album>,
|
||||||
usePalette: Boolean,
|
|
||||||
cabHolder: CabHolder?
|
cabHolder: CabHolder?
|
||||||
) : AlbumAdapter(
|
) : AlbumAdapter(
|
||||||
activity, dataSet, HorizontalAdapterHelper.LAYOUT_RES, usePalette, cabHolder
|
activity, dataSet, HorizontalAdapterHelper.LAYOUT_RES, cabHolder
|
||||||
) {
|
) {
|
||||||
|
|
||||||
override fun createViewHolder(view: View, viewType: Int): ViewHolder {
|
override fun createViewHolder(view: View, viewType: Int): ViewHolder {
|
||||||
|
@ -45,8 +43,7 @@ class HorizontalAlbumAdapter(
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onColorReady(color: Int) {
|
override fun onColorReady(color: Int) {
|
||||||
if (usePalette) setColors(color, holder)
|
setColors(color, holder)
|
||||||
else setColors(albumArtistFooterColor, holder)
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,24 +28,18 @@ import java.util.ArrayList
|
||||||
|
|
||||||
class ArtistAdapter(
|
class ArtistAdapter(
|
||||||
val activity: AppCompatActivity,
|
val activity: AppCompatActivity,
|
||||||
var dataSet: ArrayList<Artist>,
|
var dataSet: List<Artist>,
|
||||||
var itemLayoutRes: Int,
|
var itemLayoutRes: Int,
|
||||||
var usePalette: Boolean,
|
|
||||||
cabHolder: CabHolder?
|
cabHolder: CabHolder?
|
||||||
) : AbsMultiSelectAdapter<ArtistAdapter.ViewHolder, Artist>(
|
) : AbsMultiSelectAdapter<ArtistAdapter.ViewHolder, Artist>(
|
||||||
activity, cabHolder, R.menu.menu_media_selection
|
activity, cabHolder, R.menu.menu_media_selection
|
||||||
), PopupTextProvider {
|
), PopupTextProvider {
|
||||||
|
|
||||||
fun swapDataSet(dataSet: ArrayList<Artist>) {
|
fun swapDataSet(dataSet: List<Artist>) {
|
||||||
this.dataSet = dataSet
|
this.dataSet = dataSet
|
||||||
notifyDataSetChanged()
|
notifyDataSetChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun usePalette(usePalette: Boolean) {
|
|
||||||
this.usePalette = usePalette
|
|
||||||
notifyDataSetChanged()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getItemId(position: Int): Long {
|
override fun getItemId(position: Int): Long {
|
||||||
return dataSet[position].id.toLong()
|
return dataSet[position].id.toLong()
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ import java.util.ArrayList
|
||||||
|
|
||||||
class PlaylistAdapter(
|
class PlaylistAdapter(
|
||||||
private val activity: AppCompatActivity,
|
private val activity: AppCompatActivity,
|
||||||
var dataSet: ArrayList<Playlist>,
|
var dataSet: List<Playlist>,
|
||||||
private var itemLayoutRes: Int,
|
private var itemLayoutRes: Int,
|
||||||
cabHolder: CabHolder?
|
cabHolder: CabHolder?
|
||||||
) : AbsMultiSelectAdapter<PlaylistAdapter.ViewHolder, Playlist>(
|
) : AbsMultiSelectAdapter<PlaylistAdapter.ViewHolder, Playlist>(
|
||||||
|
@ -43,13 +43,12 @@ class PlaylistAdapter(
|
||||||
R.menu.menu_playlists_selection
|
R.menu.menu_playlists_selection
|
||||||
) {
|
) {
|
||||||
|
|
||||||
var songs = ArrayList<Song>()
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
setHasStableIds(true)
|
setHasStableIds(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun swapDataSet(dataSet: ArrayList<Playlist>) {
|
fun swapDataSet(dataSet: List<Playlist>) {
|
||||||
this.dataSet = dataSet
|
this.dataSet = dataSet
|
||||||
notifyDataSetChanged()
|
notifyDataSetChanged()
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,11 +9,10 @@ import code.name.monkey.retromusic.R
|
||||||
import code.name.monkey.retromusic.helper.MusicPlayerRemote
|
import code.name.monkey.retromusic.helper.MusicPlayerRemote
|
||||||
import code.name.monkey.retromusic.interfaces.CabHolder
|
import code.name.monkey.retromusic.interfaces.CabHolder
|
||||||
import code.name.monkey.retromusic.model.Song
|
import code.name.monkey.retromusic.model.Song
|
||||||
import java.util.ArrayList
|
|
||||||
|
|
||||||
abstract class AbsOffsetSongAdapter(
|
abstract class AbsOffsetSongAdapter(
|
||||||
activity: AppCompatActivity,
|
activity: AppCompatActivity,
|
||||||
dataSet: ArrayList<Song>,
|
dataSet: MutableList<Song>,
|
||||||
@LayoutRes itemLayoutRes: Int,
|
@LayoutRes itemLayoutRes: Int,
|
||||||
cabHolder: CabHolder?
|
cabHolder: CabHolder?
|
||||||
) : SongAdapter(activity, dataSet, itemLayoutRes, cabHolder) {
|
) : SongAdapter(activity, dataSet, itemLayoutRes, cabHolder) {
|
||||||
|
|
|
@ -96,7 +96,7 @@ class OrderablePlaylistSongAdapter(
|
||||||
private var mDragStateFlags: Int = 0
|
private var mDragStateFlags: Int = 0
|
||||||
|
|
||||||
override var songMenuRes: Int
|
override var songMenuRes: Int
|
||||||
get() = code.name.monkey.retromusic.R.menu.menu_item_playlist_song
|
get() = R.menu.menu_item_playlist_song
|
||||||
set(value) {
|
set(value) {
|
||||||
super.songMenuRes = value
|
super.songMenuRes = value
|
||||||
}
|
}
|
||||||
|
@ -113,7 +113,7 @@ class OrderablePlaylistSongAdapter(
|
||||||
|
|
||||||
override fun onSongMenuItemClick(item: MenuItem): Boolean {
|
override fun onSongMenuItemClick(item: MenuItem): Boolean {
|
||||||
when (item.itemId) {
|
when (item.itemId) {
|
||||||
code.name.monkey.retromusic.R.id.action_remove_from_playlist -> {
|
R.id.action_remove_from_playlist -> {
|
||||||
RemoveFromPlaylistDialog.create(song as PlaylistSong)
|
RemoveFromPlaylistDialog.create(song as PlaylistSong)
|
||||||
.show(activity.supportFragmentManager, "REMOVE_FROM_PLAYLIST")
|
.show(activity.supportFragmentManager, "REMOVE_FROM_PLAYLIST")
|
||||||
return true
|
return true
|
||||||
|
|
|
@ -10,11 +10,10 @@ import code.name.monkey.retromusic.interfaces.CabHolder
|
||||||
import code.name.monkey.retromusic.model.Song
|
import code.name.monkey.retromusic.model.Song
|
||||||
import code.name.monkey.retromusic.util.NavigationUtil
|
import code.name.monkey.retromusic.util.NavigationUtil
|
||||||
import com.google.android.material.button.MaterialButton
|
import com.google.android.material.button.MaterialButton
|
||||||
import java.util.ArrayList
|
|
||||||
|
|
||||||
open class PlaylistSongAdapter(
|
open class PlaylistSongAdapter(
|
||||||
activity: AppCompatActivity,
|
activity: AppCompatActivity,
|
||||||
dataSet: ArrayList<Song>,
|
dataSet: MutableList<Song>,
|
||||||
itemLayoutRes: Int,
|
itemLayoutRes: Int,
|
||||||
cabHolder: CabHolder?
|
cabHolder: CabHolder?
|
||||||
) : AbsOffsetSongAdapter(activity, dataSet, itemLayoutRes, cabHolder) {
|
) : AbsOffsetSongAdapter(activity, dataSet, itemLayoutRes, cabHolder) {
|
||||||
|
|
|
@ -7,11 +7,10 @@ import code.name.monkey.retromusic.helper.MusicPlayerRemote
|
||||||
import code.name.monkey.retromusic.interfaces.CabHolder
|
import code.name.monkey.retromusic.interfaces.CabHolder
|
||||||
import code.name.monkey.retromusic.model.Song
|
import code.name.monkey.retromusic.model.Song
|
||||||
import com.google.android.material.button.MaterialButton
|
import com.google.android.material.button.MaterialButton
|
||||||
import java.util.ArrayList
|
|
||||||
|
|
||||||
class ShuffleButtonSongAdapter(
|
class ShuffleButtonSongAdapter(
|
||||||
activity: AppCompatActivity,
|
activity: AppCompatActivity,
|
||||||
dataSet: ArrayList<Song>,
|
dataSet: MutableList<Song>,
|
||||||
itemLayoutRes: Int,
|
itemLayoutRes: Int,
|
||||||
cabHolder: CabHolder?
|
cabHolder: CabHolder?
|
||||||
) : AbsOffsetSongAdapter(activity, dataSet, itemLayoutRes, cabHolder) {
|
) : AbsOffsetSongAdapter(activity, dataSet, itemLayoutRes, cabHolder) {
|
||||||
|
|
|
@ -15,9 +15,8 @@ class SimpleSongAdapter(
|
||||||
cabHolder: CabHolder?
|
cabHolder: CabHolder?
|
||||||
) : SongAdapter(context, songs, layoutRes, cabHolder) {
|
) : SongAdapter(context, songs, layoutRes, cabHolder) {
|
||||||
|
|
||||||
override fun swapDataSet(dataSet: ArrayList<Song>) {
|
override fun swapDataSet(dataSet: List<Song>) {
|
||||||
this.dataSet.clear()
|
this.dataSet = dataSet.toMutableList()
|
||||||
this.dataSet = dataSet
|
|
||||||
notifyDataSetChanged()
|
notifyDataSetChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,25 +34,25 @@ import java.util.ArrayList
|
||||||
|
|
||||||
open class SongAdapter(
|
open class SongAdapter(
|
||||||
protected val activity: AppCompatActivity,
|
protected val activity: AppCompatActivity,
|
||||||
dataSet: ArrayList<Song>,
|
var dataSet: MutableList<Song>,
|
||||||
protected var itemLayoutRes: Int,
|
protected var itemLayoutRes: Int,
|
||||||
cabHolder: CabHolder?,
|
cabHolder: CabHolder?,
|
||||||
showSectionName: Boolean = true
|
showSectionName: Boolean = true
|
||||||
) : AbsMultiSelectAdapter<SongAdapter.ViewHolder, Song>(
|
) : AbsMultiSelectAdapter<SongAdapter.ViewHolder, Song>(
|
||||||
activity, cabHolder, R.menu.menu_media_selection
|
activity,
|
||||||
|
cabHolder,
|
||||||
|
R.menu.menu_media_selection
|
||||||
), MaterialCab.Callback, PopupTextProvider {
|
), MaterialCab.Callback, PopupTextProvider {
|
||||||
|
|
||||||
var dataSet: ArrayList<Song>
|
|
||||||
private var showSectionName = true
|
private var showSectionName = true
|
||||||
|
|
||||||
init {
|
init {
|
||||||
this.dataSet = dataSet
|
|
||||||
this.showSectionName = showSectionName
|
this.showSectionName = showSectionName
|
||||||
this.setHasStableIds(true)
|
this.setHasStableIds(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
open fun swapDataSet(dataSet: ArrayList<Song>) {
|
open fun swapDataSet(dataSet: List<Song>) {
|
||||||
this.dataSet = dataSet
|
this.dataSet = dataSet.toMutableList()
|
||||||
notifyDataSetChanged()
|
notifyDataSetChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,6 @@ import com.afollestad.materialdialogs.MaterialDialog
|
||||||
import com.afollestad.materialdialogs.bottomsheets.BottomSheet
|
import com.afollestad.materialdialogs.bottomsheets.BottomSheet
|
||||||
import com.afollestad.materialdialogs.list.listItems
|
import com.afollestad.materialdialogs.list.listItems
|
||||||
|
|
||||||
|
|
||||||
class AddToPlaylistDialog : DialogFragment() {
|
class AddToPlaylistDialog : DialogFragment() {
|
||||||
|
|
||||||
override fun onCreateDialog(
|
override fun onCreateDialog(
|
||||||
|
@ -47,7 +46,9 @@ class AddToPlaylistDialog : DialogFragment() {
|
||||||
val songs = arguments!!.getParcelableArrayList<Song>("songs") ?: return@listItems
|
val songs = arguments!!.getParcelableArrayList<Song>("songs") ?: return@listItems
|
||||||
if (index == 0) {
|
if (index == 0) {
|
||||||
dialog.dismiss()
|
dialog.dismiss()
|
||||||
activity?.supportFragmentManager?.let { CreatePlaylistDialog.create(songs).show(it, "ADD_TO_PLAYLIST") }
|
activity?.supportFragmentManager?.let {
|
||||||
|
CreatePlaylistDialog.create(songs).show(it, "ADD_TO_PLAYLIST")
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
dialog.dismiss()
|
dialog.dismiss()
|
||||||
PlaylistsUtil.addToPlaylist(requireContext(), songs, playlists[index - 1].id, true)
|
PlaylistsUtil.addToPlaylist(requireContext(), songs, playlists[index - 1].id, true)
|
||||||
|
@ -64,10 +65,10 @@ class AddToPlaylistDialog : DialogFragment() {
|
||||||
return create(list)
|
return create(list)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun create(songs: ArrayList<Song>): AddToPlaylistDialog {
|
fun create(songs: List<Song>): AddToPlaylistDialog {
|
||||||
val dialog = AddToPlaylistDialog()
|
val dialog = AddToPlaylistDialog()
|
||||||
val args = Bundle()
|
val args = Bundle()
|
||||||
args.putParcelableArrayList("songs", songs)
|
args.putParcelableArrayList("songs", ArrayList(songs))
|
||||||
dialog.arguments = args
|
dialog.arguments = args
|
||||||
return dialog
|
return dialog
|
||||||
}
|
}
|
||||||
|
|
|
@ -104,10 +104,10 @@ class DeleteSongsDialog : DialogFragment() {
|
||||||
return create(list)
|
return create(list)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun create(songs: ArrayList<Song>): DeleteSongsDialog {
|
fun create(songs: List<Song>): DeleteSongsDialog {
|
||||||
val dialog = DeleteSongsDialog()
|
val dialog = DeleteSongsDialog()
|
||||||
val args = Bundle()
|
val args = Bundle()
|
||||||
args.putParcelableArrayList("songs", songs)
|
args.putParcelableArrayList("songs", ArrayList(songs))
|
||||||
dialog.arguments = args
|
dialog.arguments = args
|
||||||
return dialog
|
return dialog
|
||||||
}
|
}
|
||||||
|
|
|
@ -118,12 +118,6 @@ abstract class AbsLibraryPagerRecyclerViewCustomGridSizeFragment<A : RecyclerVie
|
||||||
|
|
||||||
protected abstract fun saveGridSizeLand(gridColumns: Int)
|
protected abstract fun saveGridSizeLand(gridColumns: Int)
|
||||||
|
|
||||||
protected abstract fun saveUsePalette(usePalette: Boolean)
|
|
||||||
|
|
||||||
protected abstract fun loadUsePalette(): Boolean
|
|
||||||
|
|
||||||
protected abstract fun setUsePalette(usePalette: Boolean)
|
|
||||||
|
|
||||||
protected abstract fun loadLayoutRes(): Int
|
protected abstract fun loadLayoutRes(): Int
|
||||||
|
|
||||||
protected abstract fun saveLayoutRes(layoutRes: Int)
|
protected abstract fun saveLayoutRes(layoutRes: Int)
|
||||||
|
|
|
@ -13,7 +13,7 @@ import code.name.monkey.retromusic.mvp.presenter.AlbumsView
|
||||||
import code.name.monkey.retromusic.util.PreferenceUtil
|
import code.name.monkey.retromusic.util.PreferenceUtil
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
open class AlbumsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment<AlbumAdapter, GridLayoutManager>(),
|
class AlbumsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment<AlbumAdapter, GridLayoutManager>(),
|
||||||
AlbumsView {
|
AlbumsView {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
|
@ -41,7 +41,7 @@ open class AlbumsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment<Al
|
||||||
albumsPresenter.detachView()
|
albumsPresenter.detachView()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun albums(albums: java.util.ArrayList<Album>) {
|
override fun albums(albums: List<Album>) {
|
||||||
adapter?.swapDataSet(albums)
|
adapter?.swapDataSet(albums)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,21 +53,13 @@ open class AlbumsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment<Al
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun createAdapter(): AlbumAdapter {
|
override fun createAdapter(): AlbumAdapter {
|
||||||
/* var itemLayoutRes = itemLayoutRes
|
|
||||||
notifyLayoutResChanged(itemLayoutRes)
|
|
||||||
if (itemLayoutRes != R.layout.item_list) {
|
|
||||||
itemLayoutRes = PreferenceUtil.getInstance(requireContext()).getAlbumGridStyle(requireContext())
|
|
||||||
}*/
|
|
||||||
val dataSet = if (adapter == null) ArrayList() else adapter!!.dataSet
|
val dataSet = if (adapter == null) ArrayList() else adapter!!.dataSet
|
||||||
return AlbumAdapter(libraryFragment.mainActivity, dataSet, itemLayoutRes(), loadUsePalette(), libraryFragment)
|
return AlbumAdapter(
|
||||||
}
|
libraryFragment.mainActivity,
|
||||||
|
dataSet,
|
||||||
public override fun loadUsePalette(): Boolean {
|
itemLayoutRes(),
|
||||||
return PreferenceUtil.getInstance(requireContext()).albumColoredFooters()
|
libraryFragment
|
||||||
}
|
)
|
||||||
|
|
||||||
override fun setUsePalette(usePalette: Boolean) {
|
|
||||||
adapter?.usePalette(usePalette)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setGridSize(gridSize: Int) {
|
override fun setGridSize(gridSize: Int) {
|
||||||
|
@ -99,10 +91,6 @@ open class AlbumsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment<Al
|
||||||
PreferenceUtil.getInstance(requireContext()).setAlbumGridSizeLand(gridColumns)
|
PreferenceUtil.getInstance(requireContext()).setAlbumGridSizeLand(gridColumns)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun saveUsePalette(usePalette: Boolean) {
|
|
||||||
PreferenceUtil.getInstance(requireContext()).setAlbumColoredFooters(usePalette)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onMediaStoreChanged() {
|
override fun onMediaStoreChanged() {
|
||||||
albumsPresenter.loadAlbums()
|
albumsPresenter.loadAlbums()
|
||||||
}
|
}
|
||||||
|
@ -116,7 +104,6 @@ open class AlbumsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment<Al
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setLayoutRes(layoutRes: Int) {
|
override fun setLayoutRes(layoutRes: Int) {
|
||||||
//adapter?.itemCount?.let { adapter?.notifyItemRangeChanged(0, it) }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun loadLayoutRes(): Int {
|
override fun loadLayoutRes(): Int {
|
||||||
|
|
|
@ -16,7 +16,7 @@ import javax.inject.Inject
|
||||||
class ArtistsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment<ArtistAdapter, GridLayoutManager>(),
|
class ArtistsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment<ArtistAdapter, GridLayoutManager>(),
|
||||||
ArtistsView {
|
ArtistsView {
|
||||||
|
|
||||||
override fun artists(artists: ArrayList<Artist>) {
|
override fun artists(artists: List<Artist>) {
|
||||||
adapter?.swapDataSet(artists)
|
adapter?.swapDataSet(artists)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,7 +66,6 @@ class ArtistsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment<Artist
|
||||||
libraryFragment.mainActivity,
|
libraryFragment.mainActivity,
|
||||||
dataSet,
|
dataSet,
|
||||||
itemLayoutRes(),
|
itemLayoutRes(),
|
||||||
loadUsePalette(),
|
|
||||||
libraryFragment
|
libraryFragment
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -87,18 +86,6 @@ class ArtistsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment<Artist
|
||||||
PreferenceUtil.getInstance(requireContext()).setArtistGridSizeLand(gridColumns)
|
PreferenceUtil.getInstance(requireContext()).setArtistGridSizeLand(gridColumns)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun saveUsePalette(usePalette: Boolean) {
|
|
||||||
PreferenceUtil.getInstance(requireContext()).setArtistColoredFooters(usePalette)
|
|
||||||
}
|
|
||||||
|
|
||||||
public override fun loadUsePalette(): Boolean {
|
|
||||||
return PreferenceUtil.getInstance(requireContext()).artistColoredFooters()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun setUsePalette(usePalette: Boolean) {
|
|
||||||
adapter?.usePalette(usePalette)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun setGridSize(gridSize: Int) {
|
override fun setGridSize(gridSize: Int) {
|
||||||
layoutManager?.spanCount = gridSize
|
layoutManager?.spanCount = gridSize
|
||||||
adapter?.notifyDataSetChanged()
|
adapter?.notifyDataSetChanged()
|
||||||
|
@ -121,9 +108,7 @@ class ArtistsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment<Artist
|
||||||
val TAG: String = ArtistsFragment::class.java.simpleName
|
val TAG: String = ArtistsFragment::class.java.simpleName
|
||||||
|
|
||||||
fun newInstance(): ArtistsFragment {
|
fun newInstance(): ArtistsFragment {
|
||||||
|
|
||||||
val args = Bundle()
|
val args = Bundle()
|
||||||
|
|
||||||
val fragment = ArtistsFragment()
|
val fragment = ArtistsFragment()
|
||||||
fragment.arguments = args
|
fragment.arguments = args
|
||||||
return fragment
|
return fragment
|
||||||
|
|
|
@ -26,14 +26,12 @@ import code.name.monkey.retromusic.mvp.presenter.GenresPresenter
|
||||||
import code.name.monkey.retromusic.mvp.presenter.GenresView
|
import code.name.monkey.retromusic.mvp.presenter.GenresView
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
|
||||||
class GenresFragment : AbsLibraryPagerRecyclerViewFragment<GenreAdapter, LinearLayoutManager>(), GenresView {
|
class GenresFragment : AbsLibraryPagerRecyclerViewFragment<GenreAdapter, LinearLayoutManager>(), GenresView {
|
||||||
override fun genres(genres: ArrayList<Genre>) {
|
override fun genres(genres: List<Genre>) {
|
||||||
adapter?.swapDataSet(genres)
|
adapter?.swapDataSet(genres)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun showEmptyView() {
|
override fun showEmptyView() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun createLayoutManager(): LinearLayoutManager {
|
override fun createLayoutManager(): LinearLayoutManager {
|
||||||
|
@ -48,11 +46,9 @@ class GenresFragment : AbsLibraryPagerRecyclerViewFragment<GenreAdapter, LinearL
|
||||||
override val emptyMessage: Int
|
override val emptyMessage: Int
|
||||||
get() = R.string.no_genres
|
get() = R.string.no_genres
|
||||||
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
lateinit var genresPresenter: GenresPresenter
|
lateinit var genresPresenter: GenresPresenter
|
||||||
|
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
App.musicComponent.inject(this)
|
App.musicComponent.inject(this)
|
||||||
|
@ -62,6 +58,7 @@ class GenresFragment : AbsLibraryPagerRecyclerViewFragment<GenreAdapter, LinearL
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
genresPresenter.attachView(this)
|
genresPresenter.attachView(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
if (adapter!!.dataSet.isEmpty()) {
|
if (adapter!!.dataSet.isEmpty()) {
|
||||||
|
|
|
@ -63,7 +63,7 @@ class PlaylistsFragment : AbsLibraryPagerRecyclerViewFragment<PlaylistAdapter, L
|
||||||
adapter?.swapDataSet(ArrayList())
|
adapter?.swapDataSet(ArrayList())
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun playlists(playlists: ArrayList<Playlist>) {
|
override fun playlists(playlists: List<Playlist>) {
|
||||||
adapter?.swapDataSet(playlists)
|
adapter?.swapDataSet(playlists)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ class SongsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment<SongAdap
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun createAdapter(): SongAdapter {
|
override fun createAdapter(): SongAdapter {
|
||||||
val dataSet = if (adapter == null) ArrayList() else adapter!!.dataSet
|
val dataSet = if (adapter == null) mutableListOf() else adapter!!.dataSet
|
||||||
return ShuffleButtonSongAdapter(
|
return ShuffleButtonSongAdapter(
|
||||||
libraryFragment.mainActivity,
|
libraryFragment.mainActivity,
|
||||||
dataSet,
|
dataSet,
|
||||||
|
@ -49,7 +49,7 @@ class SongsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment<SongAdap
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun songs(songs: ArrayList<Song>) {
|
override fun songs(songs: List<Song>) {
|
||||||
adapter?.swapDataSet(songs)
|
adapter?.swapDataSet(songs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,27 +73,15 @@ class SongsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment<SongAdap
|
||||||
PreferenceUtil.getInstance(requireContext()).setSongGridSizeLand(gridColumns)
|
PreferenceUtil.getInstance(requireContext()).setSongGridSizeLand(gridColumns)
|
||||||
}
|
}
|
||||||
|
|
||||||
public override fun saveUsePalette(usePalette: Boolean) {
|
|
||||||
PreferenceUtil.getInstance(requireContext()).setSongColoredFooters(usePalette)
|
|
||||||
}
|
|
||||||
|
|
||||||
public override fun loadUsePalette(): Boolean {
|
|
||||||
return PreferenceUtil.getInstance(requireContext()).songColoredFooters()
|
|
||||||
}
|
|
||||||
|
|
||||||
public override fun setUsePalette(usePalette: Boolean) {
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun setGridSize(gridSize: Int) {
|
override fun setGridSize(gridSize: Int) {
|
||||||
adapter?.notifyDataSetChanged()
|
adapter?.notifyDataSetChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
if (adapter!!.dataSet.isEmpty()) {
|
if (adapter?.itemCount != 0)
|
||||||
songPresenter.loadSongs()
|
songPresenter.loadSongs()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
override fun onDestroyView() {
|
override fun onDestroyView() {
|
||||||
super.onDestroyView()
|
super.onDestroyView()
|
||||||
|
|
|
@ -47,7 +47,6 @@ import kotlinx.android.synthetic.main.fragment_banner_home.userImage
|
||||||
import kotlinx.android.synthetic.main.home_content.emptyContainer
|
import kotlinx.android.synthetic.main.home_content.emptyContainer
|
||||||
import kotlinx.android.synthetic.main.home_content.recyclerView
|
import kotlinx.android.synthetic.main.home_content.recyclerView
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.util.ArrayList
|
|
||||||
import java.util.Calendar
|
import java.util.Calendar
|
||||||
import java.util.Random
|
import java.util.Random
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
@ -59,7 +58,7 @@ class BannerHomeFragment : AbsMainActivityFragment(), MainActivityFragmentCallba
|
||||||
private lateinit var homeAdapter: HomeAdapter
|
private lateinit var homeAdapter: HomeAdapter
|
||||||
private lateinit var toolbar: Toolbar
|
private lateinit var toolbar: Toolbar
|
||||||
|
|
||||||
override fun sections(sections: ArrayList<Home>) {
|
override fun sections(sections: List<Home>) {
|
||||||
println(sections.size)
|
println(sections.size)
|
||||||
homeAdapter.swapData(sections)
|
homeAdapter.swapData(sections)
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,6 @@ import android.os.Environment
|
||||||
import android.os.IBinder
|
import android.os.IBinder
|
||||||
import android.provider.DocumentsContract
|
import android.provider.DocumentsContract
|
||||||
import android.provider.MediaStore
|
import android.provider.MediaStore
|
||||||
import android.util.Log
|
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import code.name.monkey.retromusic.loaders.SongLoader
|
import code.name.monkey.retromusic.loaders.SongLoader
|
||||||
|
@ -158,7 +157,7 @@ object MusicPlayerRemote {
|
||||||
return cursor.getString(columnIndex)
|
return cursor.getString(columnIndex)
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.e(TAG, e.message)
|
println(e.message)
|
||||||
} finally {
|
} finally {
|
||||||
cursor?.close()
|
cursor?.close()
|
||||||
}
|
}
|
||||||
|
@ -166,65 +165,51 @@ object MusicPlayerRemote {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getQueueDurationSongs(): Int {
|
fun getQueueDurationSongs(): Int {
|
||||||
return if (musicService != null) {
|
return musicService?.playingQueue?.size ?: -1
|
||||||
musicService!!.playingQueue!!.size
|
|
||||||
} else -1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Async
|
* Async
|
||||||
*/
|
*/
|
||||||
fun playSongAt(position: Int) {
|
fun playSongAt(position: Int) {
|
||||||
if (musicService != null) {
|
musicService?.playSongAt(position)
|
||||||
musicService!!.playSongAt(position)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun pauseSong() {
|
fun pauseSong() {
|
||||||
if (musicService != null) {
|
musicService?.pause()
|
||||||
musicService!!.pause()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Async
|
* Async
|
||||||
*/
|
*/
|
||||||
fun playNextSong() {
|
fun playNextSong() {
|
||||||
if (musicService != null) {
|
musicService?.playNextSong(true)
|
||||||
musicService!!.playNextSong(true)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Async
|
* Async
|
||||||
*/
|
*/
|
||||||
fun playPreviousSong() {
|
fun playPreviousSong() {
|
||||||
if (musicService != null) {
|
musicService?.playPreviousSong(true)
|
||||||
musicService!!.playPreviousSong(true)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Async
|
* Async
|
||||||
*/
|
*/
|
||||||
fun back() {
|
fun back() {
|
||||||
if (musicService != null) {
|
musicService?.back(true)
|
||||||
musicService!!.back(true)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun resumePlaying() {
|
fun resumePlaying() {
|
||||||
if (musicService != null) {
|
musicService?.play()
|
||||||
musicService!!.play()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Async
|
* Async
|
||||||
*/
|
*/
|
||||||
fun openQueue(queue: ArrayList<Song>, startPosition: Int, startPlaying: Boolean) {
|
fun openQueue(queue: List<Song>, startPosition: Int, startPlaying: Boolean) {
|
||||||
if (!tryToHandleOpenPlayingQueue(queue, startPosition, startPlaying) && musicService != null) {
|
if (!tryToHandleOpenPlayingQueue(queue, startPosition, startPlaying) && musicService != null) {
|
||||||
musicService!!.openQueue(queue, startPosition, startPlaying)
|
musicService?.openQueue(queue, startPosition, startPlaying)
|
||||||
if (PreferenceUtil.getInstance(musicService).isShuffleModeOn)
|
if (PreferenceUtil.getInstance(musicService).isShuffleModeOn)
|
||||||
setShuffleMode(MusicService.SHUFFLE_MODE_NONE)
|
setShuffleMode(MusicService.SHUFFLE_MODE_NONE)
|
||||||
}
|
}
|
||||||
|
@ -233,7 +218,7 @@ object MusicPlayerRemote {
|
||||||
/**
|
/**
|
||||||
* Async
|
* Async
|
||||||
*/
|
*/
|
||||||
fun openAndShuffleQueue(queue: ArrayList<Song>, startPlaying: Boolean) {
|
fun openAndShuffleQueue(queue: List<Song>, startPlaying: Boolean) {
|
||||||
var startPosition = 0
|
var startPosition = 0
|
||||||
if (queue.isNotEmpty()) {
|
if (queue.isNotEmpty()) {
|
||||||
startPosition = Random().nextInt(queue.size)
|
startPosition = Random().nextInt(queue.size)
|
||||||
|
@ -246,7 +231,7 @@ object MusicPlayerRemote {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun tryToHandleOpenPlayingQueue(
|
private fun tryToHandleOpenPlayingQueue(
|
||||||
queue: ArrayList<Song>,
|
queue: List<Song>,
|
||||||
startPosition: Int,
|
startPosition: Int,
|
||||||
startPlaying: Boolean
|
startPlaying: Boolean
|
||||||
): Boolean {
|
): Boolean {
|
||||||
|
@ -275,7 +260,7 @@ object MusicPlayerRemote {
|
||||||
|
|
||||||
fun cycleRepeatMode(): Boolean {
|
fun cycleRepeatMode(): Boolean {
|
||||||
if (musicService != null) {
|
if (musicService != null) {
|
||||||
musicService!!.cycleRepeatMode()
|
musicService?.cycleRepeatMode()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
|
@ -283,7 +268,7 @@ object MusicPlayerRemote {
|
||||||
|
|
||||||
fun toggleShuffleMode(): Boolean {
|
fun toggleShuffleMode(): Boolean {
|
||||||
if (musicService != null) {
|
if (musicService != null) {
|
||||||
musicService!!.toggleShuffle()
|
musicService?.toggleShuffle()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
|
@ -300,7 +285,7 @@ object MusicPlayerRemote {
|
||||||
fun playNext(song: Song): Boolean {
|
fun playNext(song: Song): Boolean {
|
||||||
if (musicService != null) {
|
if (musicService != null) {
|
||||||
if (playingQueue.size > 0) {
|
if (playingQueue.size > 0) {
|
||||||
musicService!!.addSong(position + 1, song)
|
musicService?.addSong(position + 1, song)
|
||||||
} else {
|
} else {
|
||||||
val queue = ArrayList<Song>()
|
val queue = ArrayList<Song>()
|
||||||
queue.add(song)
|
queue.add(song)
|
||||||
|
@ -316,10 +301,10 @@ object MusicPlayerRemote {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
fun playNext(songs: ArrayList<Song>): Boolean {
|
fun playNext(songs: List<Song>): Boolean {
|
||||||
if (musicService != null) {
|
if (musicService != null) {
|
||||||
if (playingQueue.size > 0) {
|
if (playingQueue.size > 0) {
|
||||||
musicService!!.addSongs(position + 1, songs)
|
musicService?.addSongs(position + 1, songs)
|
||||||
} else {
|
} else {
|
||||||
openQueue(songs, 0, false)
|
openQueue(songs, 0, false)
|
||||||
}
|
}
|
||||||
|
@ -337,7 +322,7 @@ object MusicPlayerRemote {
|
||||||
fun enqueue(song: Song): Boolean {
|
fun enqueue(song: Song): Boolean {
|
||||||
if (musicService != null) {
|
if (musicService != null) {
|
||||||
if (playingQueue.size > 0) {
|
if (playingQueue.size > 0) {
|
||||||
musicService!!.addSong(song)
|
musicService?.addSong(song)
|
||||||
} else {
|
} else {
|
||||||
val queue = ArrayList<Song>()
|
val queue = ArrayList<Song>()
|
||||||
queue.add(song)
|
queue.add(song)
|
||||||
|
@ -353,10 +338,10 @@ object MusicPlayerRemote {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
fun enqueue(songs: ArrayList<Song>): Boolean {
|
fun enqueue(songs: List<Song>): Boolean {
|
||||||
if (musicService != null) {
|
if (musicService != null) {
|
||||||
if (playingQueue.size > 0) {
|
if (playingQueue.size > 0) {
|
||||||
musicService!!.addSongs(songs)
|
musicService?.addSongs(songs)
|
||||||
} else {
|
} else {
|
||||||
openQueue(songs, 0, false)
|
openQueue(songs, 0, false)
|
||||||
}
|
}
|
||||||
|
@ -407,7 +392,7 @@ object MusicPlayerRemote {
|
||||||
fun playFromUri(uri: Uri) {
|
fun playFromUri(uri: Uri) {
|
||||||
if (musicService != null) {
|
if (musicService != null) {
|
||||||
|
|
||||||
var songs: ArrayList<Song>? = null
|
var songs: List<Song>? = null
|
||||||
if (uri.scheme != null && uri.authority != null) {
|
if (uri.scheme != null && uri.authority != null) {
|
||||||
if (uri.scheme == ContentResolver.SCHEME_CONTENT) {
|
if (uri.scheme == ContentResolver.SCHEME_CONTENT) {
|
||||||
var songId: String? = null
|
var songId: String? = null
|
||||||
|
@ -455,6 +440,7 @@ object MusicPlayerRemote {
|
||||||
openQueue(songs, 0, true)
|
openQueue(songs, 0, true)
|
||||||
} else {
|
} else {
|
||||||
//TODO the file is not listed in the media store
|
//TODO the file is not listed in the media store
|
||||||
|
println("The file is not listed in the media store")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,5 +19,6 @@ package code.name.monkey.retromusic.mvp
|
||||||
*/
|
*/
|
||||||
|
|
||||||
interface BaseView {
|
interface BaseView {
|
||||||
|
|
||||||
fun showEmptyView()
|
fun showEmptyView()
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,9 +40,7 @@ interface AlbumDetailsView {
|
||||||
|
|
||||||
fun loadArtistImage(artist: Artist)
|
fun loadArtistImage(artist: Artist)
|
||||||
|
|
||||||
fun moreAlbums(
|
fun moreAlbums(albums: List<Album>)
|
||||||
albums: ArrayList<Album>
|
|
||||||
)
|
|
||||||
|
|
||||||
fun aboutAlbum(lastFmAlbum: LastFmAlbum)
|
fun aboutAlbum(lastFmAlbum: LastFmAlbum)
|
||||||
}
|
}
|
||||||
|
@ -51,6 +49,7 @@ interface AlbumDetailsPresenter : Presenter<AlbumDetailsView> {
|
||||||
fun loadAlbum(albumId: Int)
|
fun loadAlbum(albumId: Int)
|
||||||
|
|
||||||
fun loadMore(artistId: Int)
|
fun loadMore(artistId: Int)
|
||||||
|
|
||||||
fun aboutAlbum(artist: String, album: String)
|
fun aboutAlbum(artist: String, album: String)
|
||||||
|
|
||||||
class AlbumDetailsPresenterImpl @Inject constructor(
|
class AlbumDetailsPresenterImpl @Inject constructor(
|
||||||
|
|
|
@ -14,7 +14,8 @@
|
||||||
|
|
||||||
package code.name.monkey.retromusic.mvp.presenter
|
package code.name.monkey.retromusic.mvp.presenter
|
||||||
|
|
||||||
import code.name.monkey.retromusic.Result
|
import code.name.monkey.retromusic.Result.Error
|
||||||
|
import code.name.monkey.retromusic.Result.Success
|
||||||
import code.name.monkey.retromusic.model.Album
|
import code.name.monkey.retromusic.model.Album
|
||||||
import code.name.monkey.retromusic.mvp.BaseView
|
import code.name.monkey.retromusic.mvp.BaseView
|
||||||
import code.name.monkey.retromusic.mvp.Presenter
|
import code.name.monkey.retromusic.mvp.Presenter
|
||||||
|
@ -25,7 +26,6 @@ import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import java.util.ArrayList
|
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import kotlin.coroutines.CoroutineContext
|
import kotlin.coroutines.CoroutineContext
|
||||||
|
|
||||||
|
@ -33,7 +33,8 @@ import kotlin.coroutines.CoroutineContext
|
||||||
* Created by hemanths on 12/08/17.
|
* Created by hemanths on 12/08/17.
|
||||||
*/
|
*/
|
||||||
interface AlbumsView : BaseView {
|
interface AlbumsView : BaseView {
|
||||||
fun albums(albums: ArrayList<Album>)
|
|
||||||
|
fun albums(albums: List<Album>)
|
||||||
}
|
}
|
||||||
|
|
||||||
interface AlbumsPresenter : Presenter<AlbumsView> {
|
interface AlbumsPresenter : Presenter<AlbumsView> {
|
||||||
|
@ -43,6 +44,7 @@ interface AlbumsPresenter : Presenter<AlbumsView> {
|
||||||
class AlbumsPresenterImpl @Inject constructor(
|
class AlbumsPresenterImpl @Inject constructor(
|
||||||
private val repository: Repository
|
private val repository: Repository
|
||||||
) : PresenterImpl<AlbumsView>(), AlbumsPresenter, CoroutineScope {
|
) : PresenterImpl<AlbumsView>(), AlbumsPresenter, CoroutineScope {
|
||||||
|
|
||||||
private val job = Job()
|
private val job = Job()
|
||||||
|
|
||||||
override val coroutineContext: CoroutineContext
|
override val coroutineContext: CoroutineContext
|
||||||
|
@ -56,10 +58,8 @@ interface AlbumsPresenter : Presenter<AlbumsView> {
|
||||||
override fun loadAlbums() {
|
override fun loadAlbums() {
|
||||||
launch {
|
launch {
|
||||||
when (val result = repository.allAlbums()) {
|
when (val result = repository.allAlbums()) {
|
||||||
is Result.Success -> withContext(Dispatchers.Main) {
|
is Success -> withContext(Dispatchers.Main) { view?.albums(result.data) }
|
||||||
view?.albums(result.data)
|
is Error -> withContext(Dispatchers.Main) { view?.showEmptyView() }
|
||||||
}
|
|
||||||
is Result.Error -> withContext(Dispatchers.Main) { view?.showEmptyView() }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,8 @@
|
||||||
|
|
||||||
package code.name.monkey.retromusic.mvp.presenter
|
package code.name.monkey.retromusic.mvp.presenter
|
||||||
|
|
||||||
import code.name.monkey.retromusic.Result
|
import code.name.monkey.retromusic.Result.Error
|
||||||
|
import code.name.monkey.retromusic.Result.Success
|
||||||
import code.name.monkey.retromusic.model.Artist
|
import code.name.monkey.retromusic.model.Artist
|
||||||
import code.name.monkey.retromusic.mvp.BaseView
|
import code.name.monkey.retromusic.mvp.BaseView
|
||||||
import code.name.monkey.retromusic.mvp.Presenter
|
import code.name.monkey.retromusic.mvp.Presenter
|
||||||
|
@ -36,7 +37,9 @@ import kotlin.coroutines.CoroutineContext
|
||||||
interface ArtistDetailsView : BaseView {
|
interface ArtistDetailsView : BaseView {
|
||||||
|
|
||||||
fun artist(artist: Artist)
|
fun artist(artist: Artist)
|
||||||
|
|
||||||
fun artistInfo(lastFmArtist: LastFmArtist?)
|
fun artistInfo(lastFmArtist: LastFmArtist?)
|
||||||
|
|
||||||
fun complete()
|
fun complete()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,12 +65,8 @@ interface ArtistDetailsPresenter : Presenter<ArtistDetailsView> {
|
||||||
override fun loadBiography(name: String, lang: String?, cache: String?) {
|
override fun loadBiography(name: String, lang: String?, cache: String?) {
|
||||||
launch {
|
launch {
|
||||||
when (val result = repository.artistInfo(name, lang, cache)) {
|
when (val result = repository.artistInfo(name, lang, cache)) {
|
||||||
is Result.Success -> withContext(Dispatchers.Main) {
|
is Success -> withContext(Dispatchers.Main) { view?.artistInfo(result.data) }
|
||||||
view?.artistInfo(result.data)
|
is Error -> withContext(Dispatchers.Main) {}
|
||||||
}
|
|
||||||
is Result.Error -> withContext(Dispatchers.Main) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -75,13 +74,8 @@ interface ArtistDetailsPresenter : Presenter<ArtistDetailsView> {
|
||||||
override fun loadArtist(artistId: Int) {
|
override fun loadArtist(artistId: Int) {
|
||||||
launch {
|
launch {
|
||||||
when (val result = repository.artistById(artistId)) {
|
when (val result = repository.artistById(artistId)) {
|
||||||
is Result.Success -> withContext(Dispatchers.Main) {
|
is Success -> withContext(Dispatchers.Main) { view?.artist(result.data) }
|
||||||
view?.artist(result.data)
|
is Error -> withContext(Dispatchers.Main) { view?.showEmptyView() }
|
||||||
|
|
||||||
}
|
|
||||||
is Result.Error -> withContext(Dispatchers.Main) {
|
|
||||||
view?.showEmptyView()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,18 +14,23 @@
|
||||||
|
|
||||||
package code.name.monkey.retromusic.mvp.presenter
|
package code.name.monkey.retromusic.mvp.presenter
|
||||||
|
|
||||||
import code.name.monkey.retromusic.Result
|
import code.name.monkey.retromusic.Result.Error
|
||||||
|
import code.name.monkey.retromusic.Result.Success
|
||||||
import code.name.monkey.retromusic.model.Artist
|
import code.name.monkey.retromusic.model.Artist
|
||||||
import code.name.monkey.retromusic.mvp.BaseView
|
import code.name.monkey.retromusic.mvp.BaseView
|
||||||
import code.name.monkey.retromusic.mvp.Presenter
|
import code.name.monkey.retromusic.mvp.Presenter
|
||||||
import code.name.monkey.retromusic.mvp.PresenterImpl
|
import code.name.monkey.retromusic.mvp.PresenterImpl
|
||||||
import code.name.monkey.retromusic.providers.interfaces.Repository
|
import code.name.monkey.retromusic.providers.interfaces.Repository
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.Job
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import kotlin.coroutines.CoroutineContext
|
import kotlin.coroutines.CoroutineContext
|
||||||
|
|
||||||
interface ArtistsView : BaseView {
|
interface ArtistsView : BaseView {
|
||||||
fun artists(artists: ArrayList<Artist>)
|
fun artists(artists: List<Artist>)
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ArtistsPresenter : Presenter<ArtistsView> {
|
interface ArtistsPresenter : Presenter<ArtistsView> {
|
||||||
|
@ -35,6 +40,7 @@ interface ArtistsPresenter : Presenter<ArtistsView> {
|
||||||
class ArtistsPresenterImpl @Inject constructor(
|
class ArtistsPresenterImpl @Inject constructor(
|
||||||
private val repository: Repository
|
private val repository: Repository
|
||||||
) : PresenterImpl<ArtistsView>(), ArtistsPresenter, CoroutineScope {
|
) : PresenterImpl<ArtistsView>(), ArtistsPresenter, CoroutineScope {
|
||||||
|
|
||||||
private val job = Job()
|
private val job = Job()
|
||||||
|
|
||||||
override val coroutineContext: CoroutineContext
|
override val coroutineContext: CoroutineContext
|
||||||
|
@ -48,8 +54,8 @@ interface ArtistsPresenter : Presenter<ArtistsView> {
|
||||||
override fun loadArtists() {
|
override fun loadArtists() {
|
||||||
launch {
|
launch {
|
||||||
when (val result = repository.allArtists()) {
|
when (val result = repository.allArtists()) {
|
||||||
is Result.Success -> withContext(Dispatchers.Main) { view?.artists(result.data) }
|
is Success -> withContext(Dispatchers.Main) { view?.artists(result.data) }
|
||||||
is Result.Error -> withContext(Dispatchers.Main) { view?.showEmptyView() }
|
is Error -> withContext(Dispatchers.Main) { view?.showEmptyView() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,24 +14,28 @@
|
||||||
|
|
||||||
package code.name.monkey.retromusic.mvp.presenter
|
package code.name.monkey.retromusic.mvp.presenter
|
||||||
|
|
||||||
import code.name.monkey.retromusic.Result
|
import code.name.monkey.retromusic.Result.Error
|
||||||
|
import code.name.monkey.retromusic.Result.Success
|
||||||
import code.name.monkey.retromusic.model.Song
|
import code.name.monkey.retromusic.model.Song
|
||||||
import code.name.monkey.retromusic.mvp.BaseView
|
import code.name.monkey.retromusic.mvp.BaseView
|
||||||
import code.name.monkey.retromusic.mvp.Presenter
|
import code.name.monkey.retromusic.mvp.Presenter
|
||||||
import code.name.monkey.retromusic.mvp.PresenterImpl
|
import code.name.monkey.retromusic.mvp.PresenterImpl
|
||||||
import code.name.monkey.retromusic.providers.interfaces.Repository
|
import code.name.monkey.retromusic.providers.interfaces.Repository
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import java.util.*
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.Job
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import kotlin.coroutines.CoroutineContext
|
import kotlin.coroutines.CoroutineContext
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by hemanths on 20/08/17.
|
* Created by hemanths on 20/08/17.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
interface GenreDetailsView : BaseView {
|
interface GenreDetailsView : BaseView {
|
||||||
fun songs(songs: ArrayList<Song>)
|
|
||||||
|
fun songs(songs: List<Song>)
|
||||||
}
|
}
|
||||||
|
|
||||||
interface GenreDetailsPresenter : Presenter<GenreDetailsView> {
|
interface GenreDetailsPresenter : Presenter<GenreDetailsView> {
|
||||||
|
@ -40,6 +44,7 @@ interface GenreDetailsPresenter : Presenter<GenreDetailsView> {
|
||||||
class GenreDetailsPresenterImpl @Inject constructor(
|
class GenreDetailsPresenterImpl @Inject constructor(
|
||||||
private val repository: Repository
|
private val repository: Repository
|
||||||
) : PresenterImpl<GenreDetailsView>(), GenreDetailsPresenter, CoroutineScope {
|
) : PresenterImpl<GenreDetailsView>(), GenreDetailsPresenter, CoroutineScope {
|
||||||
|
|
||||||
private val job = Job()
|
private val job = Job()
|
||||||
|
|
||||||
override val coroutineContext: CoroutineContext
|
override val coroutineContext: CoroutineContext
|
||||||
|
@ -50,16 +55,11 @@ interface GenreDetailsPresenter : Presenter<GenreDetailsView> {
|
||||||
job.cancel()
|
job.cancel()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
override fun loadGenreSongs(genreId: Int) {
|
override fun loadGenreSongs(genreId: Int) {
|
||||||
launch {
|
launch {
|
||||||
when (val result = repository.getGenre(genreId)) {
|
when (val result = repository.getGenre(genreId)) {
|
||||||
is Result.Success -> withContext(Dispatchers.Main) {
|
is Success -> withContext(Dispatchers.Main) { view?.songs(result.data) }
|
||||||
view?.songs(result.data)
|
is Error -> withContext(Dispatchers.Main) { view?.showEmptyView() }
|
||||||
}
|
|
||||||
is Result.Error -> withContext(Dispatchers.Main) {
|
|
||||||
view?.showEmptyView()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,14 +14,18 @@
|
||||||
|
|
||||||
package code.name.monkey.retromusic.mvp.presenter
|
package code.name.monkey.retromusic.mvp.presenter
|
||||||
|
|
||||||
import code.name.monkey.retromusic.Result
|
import code.name.monkey.retromusic.Result.Error
|
||||||
|
import code.name.monkey.retromusic.Result.Success
|
||||||
import code.name.monkey.retromusic.model.Genre
|
import code.name.monkey.retromusic.model.Genre
|
||||||
import code.name.monkey.retromusic.mvp.BaseView
|
import code.name.monkey.retromusic.mvp.BaseView
|
||||||
import code.name.monkey.retromusic.mvp.Presenter
|
import code.name.monkey.retromusic.mvp.Presenter
|
||||||
import code.name.monkey.retromusic.mvp.PresenterImpl
|
import code.name.monkey.retromusic.mvp.PresenterImpl
|
||||||
import code.name.monkey.retromusic.providers.interfaces.Repository
|
import code.name.monkey.retromusic.providers.interfaces.Repository
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import java.util.*
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.Job
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import kotlin.coroutines.CoroutineContext
|
import kotlin.coroutines.CoroutineContext
|
||||||
|
|
||||||
|
@ -29,7 +33,8 @@ import kotlin.coroutines.CoroutineContext
|
||||||
* @author Hemanth S (h4h13).
|
* @author Hemanth S (h4h13).
|
||||||
*/
|
*/
|
||||||
interface GenresView : BaseView {
|
interface GenresView : BaseView {
|
||||||
fun genres(genres: ArrayList<Genre>)
|
|
||||||
|
fun genres(genres: List<Genre>)
|
||||||
}
|
}
|
||||||
|
|
||||||
interface GenresPresenter : Presenter<GenresView> {
|
interface GenresPresenter : Presenter<GenresView> {
|
||||||
|
@ -38,6 +43,7 @@ interface GenresPresenter : Presenter<GenresView> {
|
||||||
class GenresPresenterImpl @Inject constructor(
|
class GenresPresenterImpl @Inject constructor(
|
||||||
private val repository: Repository
|
private val repository: Repository
|
||||||
) : PresenterImpl<GenresView>(), GenresPresenter, CoroutineScope {
|
) : PresenterImpl<GenresView>(), GenresPresenter, CoroutineScope {
|
||||||
|
|
||||||
private val job = Job()
|
private val job = Job()
|
||||||
|
|
||||||
override val coroutineContext: CoroutineContext
|
override val coroutineContext: CoroutineContext
|
||||||
|
@ -51,10 +57,8 @@ interface GenresPresenter : Presenter<GenresView> {
|
||||||
override fun loadGenres() {
|
override fun loadGenres() {
|
||||||
launch {
|
launch {
|
||||||
when (val result = repository.allGenres()) {
|
when (val result = repository.allGenres()) {
|
||||||
is Result.Success -> withContext(Dispatchers.Main) {
|
is Success -> withContext(Dispatchers.Main) { view?.genres(result.data) }
|
||||||
view?.genres(result.data)
|
is Error -> withContext(Dispatchers.Main) { view?.showEmptyView() }
|
||||||
}
|
|
||||||
is Result.Error -> withContext(Dispatchers.Main) { view?.showEmptyView() }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ import javax.inject.Inject
|
||||||
import kotlin.coroutines.CoroutineContext
|
import kotlin.coroutines.CoroutineContext
|
||||||
|
|
||||||
interface HomeView : BaseView {
|
interface HomeView : BaseView {
|
||||||
fun sections(sections: ArrayList<Home>)
|
fun sections(sections: List<Home>)
|
||||||
}
|
}
|
||||||
|
|
||||||
interface HomePresenter : Presenter<HomeView> {
|
interface HomePresenter : Presenter<HomeView> {
|
||||||
|
|
|
@ -16,19 +16,25 @@ package code.name.monkey.retromusic.mvp.presenter
|
||||||
|
|
||||||
import code.name.monkey.retromusic.Result
|
import code.name.monkey.retromusic.Result
|
||||||
import code.name.monkey.retromusic.model.Playlist
|
import code.name.monkey.retromusic.model.Playlist
|
||||||
import code.name.monkey.retromusic.mvp.*
|
import code.name.monkey.retromusic.mvp.BaseView
|
||||||
|
import code.name.monkey.retromusic.mvp.Presenter
|
||||||
|
import code.name.monkey.retromusic.mvp.PresenterImpl
|
||||||
import code.name.monkey.retromusic.providers.interfaces.Repository
|
import code.name.monkey.retromusic.providers.interfaces.Repository
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.Job
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import kotlin.coroutines.CoroutineContext
|
import kotlin.coroutines.CoroutineContext
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by hemanths on 19/08/17.
|
* Created by hemanths on 19/08/17.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
interface PlaylistView : BaseView {
|
interface PlaylistView : BaseView {
|
||||||
fun playlists(playlists: ArrayList<Playlist>)
|
|
||||||
|
fun playlists(playlists: List<Playlist>)
|
||||||
}
|
}
|
||||||
|
|
||||||
interface PlaylistsPresenter : Presenter<PlaylistView> {
|
interface PlaylistsPresenter : Presenter<PlaylistView> {
|
||||||
|
@ -52,9 +58,7 @@ interface PlaylistsPresenter : Presenter<PlaylistView> {
|
||||||
override fun playlists() {
|
override fun playlists() {
|
||||||
launch {
|
launch {
|
||||||
when (val result = repository.allPlaylists()) {
|
when (val result = repository.allPlaylists()) {
|
||||||
is Result.Success -> withContext(Dispatchers.Main) {
|
is Result.Success -> withContext(Dispatchers.Main) { view?.playlists(result.data) }
|
||||||
view?.playlists(result.data)
|
|
||||||
}
|
|
||||||
is Result.Error -> withContext(Dispatchers.Main) { view?.showEmptyView() }
|
is Result.Error -> withContext(Dispatchers.Main) { view?.showEmptyView() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,11 +14,19 @@
|
||||||
|
|
||||||
package code.name.monkey.retromusic.mvp.presenter
|
package code.name.monkey.retromusic.mvp.presenter
|
||||||
|
|
||||||
import code.name.monkey.retromusic.Result
|
import code.name.monkey.retromusic.Result.Error
|
||||||
import code.name.monkey.retromusic.model.*
|
import code.name.monkey.retromusic.Result.Success
|
||||||
import code.name.monkey.retromusic.mvp.*
|
import code.name.monkey.retromusic.model.Playlist
|
||||||
|
import code.name.monkey.retromusic.model.Song
|
||||||
|
import code.name.monkey.retromusic.mvp.BaseView
|
||||||
|
import code.name.monkey.retromusic.mvp.Presenter
|
||||||
|
import code.name.monkey.retromusic.mvp.PresenterImpl
|
||||||
import code.name.monkey.retromusic.providers.interfaces.Repository
|
import code.name.monkey.retromusic.providers.interfaces.Repository
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.Job
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import kotlin.coroutines.CoroutineContext
|
import kotlin.coroutines.CoroutineContext
|
||||||
|
|
||||||
|
@ -26,7 +34,8 @@ import kotlin.coroutines.CoroutineContext
|
||||||
* Created by hemanths on 20/08/17.
|
* Created by hemanths on 20/08/17.
|
||||||
*/
|
*/
|
||||||
interface PlaylistSongsView : BaseView {
|
interface PlaylistSongsView : BaseView {
|
||||||
fun songs(songs: ArrayList<Song>)
|
|
||||||
|
fun songs(songs: List<Song>)
|
||||||
}
|
}
|
||||||
|
|
||||||
interface PlaylistSongsPresenter : Presenter<PlaylistSongsView> {
|
interface PlaylistSongsPresenter : Presenter<PlaylistSongsView> {
|
||||||
|
@ -44,10 +53,8 @@ interface PlaylistSongsPresenter : Presenter<PlaylistSongsView> {
|
||||||
override fun loadPlaylistSongs(playlist: Playlist) {
|
override fun loadPlaylistSongs(playlist: Playlist) {
|
||||||
launch {
|
launch {
|
||||||
when (val songs = repository.getPlaylistSongs(playlist)) {
|
when (val songs = repository.getPlaylistSongs(playlist)) {
|
||||||
is Result.Success -> withContext(Dispatchers.Main) {
|
is Success -> withContext(Dispatchers.Main) { view?.songs(songs.data) }
|
||||||
view?.songs(songs.data)
|
is Error -> withContext(Dispatchers.Main) { view?.showEmptyView() }
|
||||||
}
|
|
||||||
is Result.Error -> withContext(Dispatchers.Main) { view?.showEmptyView() }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,10 +16,14 @@ package code.name.monkey.retromusic.mvp.presenter
|
||||||
|
|
||||||
import code.name.monkey.retromusic.Result
|
import code.name.monkey.retromusic.Result
|
||||||
import code.name.monkey.retromusic.model.Song
|
import code.name.monkey.retromusic.model.Song
|
||||||
import code.name.monkey.retromusic.mvp.*
|
import code.name.monkey.retromusic.mvp.Presenter
|
||||||
|
import code.name.monkey.retromusic.mvp.PresenterImpl
|
||||||
import code.name.monkey.retromusic.providers.interfaces.Repository
|
import code.name.monkey.retromusic.providers.interfaces.Repository
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import java.util.*
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.Job
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import kotlin.coroutines.CoroutineContext
|
import kotlin.coroutines.CoroutineContext
|
||||||
|
|
||||||
|
@ -27,13 +31,16 @@ import kotlin.coroutines.CoroutineContext
|
||||||
* Created by hemanths on 10/08/17.
|
* Created by hemanths on 10/08/17.
|
||||||
*/
|
*/
|
||||||
interface SongView {
|
interface SongView {
|
||||||
fun songs(songs: ArrayList<Song>)
|
|
||||||
|
fun songs(songs: List<Song>)
|
||||||
|
|
||||||
fun showEmptyView()
|
fun showEmptyView()
|
||||||
}
|
}
|
||||||
|
|
||||||
interface SongPresenter : Presenter<SongView> {
|
interface SongPresenter : Presenter<SongView> {
|
||||||
|
|
||||||
fun loadSongs()
|
fun loadSongs()
|
||||||
|
|
||||||
class SongPresenterImpl @Inject constructor(
|
class SongPresenterImpl @Inject constructor(
|
||||||
private val repository: Repository
|
private val repository: Repository
|
||||||
) : PresenterImpl<SongView>(), SongPresenter, CoroutineScope {
|
) : PresenterImpl<SongView>(), SongPresenter, CoroutineScope {
|
||||||
|
@ -54,7 +61,7 @@ interface SongPresenter : Presenter<SongView> {
|
||||||
|
|
||||||
override fun detachView() {
|
override fun detachView() {
|
||||||
super.detachView()
|
super.detachView()
|
||||||
job.cancel();
|
job.cancel()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -844,7 +844,7 @@ public class MusicService extends Service implements
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void openQueue(@Nullable final ArrayList<Song> playingQueue, final int startPosition,
|
public void openQueue(@Nullable final List<Song> playingQueue, final int startPosition,
|
||||||
final boolean startPlaying) {
|
final boolean startPlaying) {
|
||||||
if (playingQueue != null && !playingQueue.isEmpty() && startPosition >= 0 && startPosition < playingQueue
|
if (playingQueue != null && !playingQueue.isEmpty() && startPosition >= 0 && startPosition < playingQueue
|
||||||
.size()) {
|
.size()) {
|
||||||
|
|
|
@ -12,8 +12,8 @@
|
||||||
android:id="@+id/imageContainer"
|
android:id="@+id/imageContainer"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="156dp"
|
android:layout_height="156dp"
|
||||||
app:cardCornerRadius="16dp"
|
android:layout_margin="8dp"
|
||||||
app:cardUseCompatPadding="true">
|
app:cardCornerRadius="16dp">
|
||||||
|
|
||||||
<androidx.appcompat.widget.AppCompatImageView
|
<androidx.appcompat.widget.AppCompatImageView
|
||||||
android:id="@+id/image"
|
android:id="@+id/image"
|
||||||
|
|
|
@ -12,8 +12,8 @@
|
||||||
android:id="@+id/imageContainer"
|
android:id="@+id/imageContainer"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="256dp"
|
android:layout_height="256dp"
|
||||||
app:cardCornerRadius="16dp"
|
android:layout_margin="8dp"
|
||||||
app:cardUseCompatPadding="true">
|
app:cardCornerRadius="16dp">
|
||||||
|
|
||||||
<androidx.appcompat.widget.AppCompatImageView
|
<androidx.appcompat.widget.AppCompatImageView
|
||||||
android:id="@+id/image"
|
android:id="@+id/image"
|
||||||
|
|
|
@ -12,8 +12,8 @@
|
||||||
android:id="@+id/imageContainer"
|
android:id="@+id/imageContainer"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="196dp"
|
android:layout_height="196dp"
|
||||||
app:cardCornerRadius="16dp"
|
android:layout_margin="8dp"
|
||||||
app:cardUseCompatPadding="true">
|
app:cardCornerRadius="16dp">
|
||||||
|
|
||||||
<androidx.appcompat.widget.AppCompatImageView
|
<androidx.appcompat.widget.AppCompatImageView
|
||||||
android:id="@+id/image"
|
android:id="@+id/image"
|
||||||
|
|
Loading…
Reference in a new issue