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