Fixing animations

This commit is contained in:
h4h13 2020-01-02 09:23:43 +05:30
parent 5a51d0bfc0
commit 44baab2109
25 changed files with 476 additions and 386 deletions

File diff suppressed because one or more lines are too long

View file

@ -3,6 +3,7 @@ package code.name.monkey.retromusic.activities
import android.app.ActivityOptions import android.app.ActivityOptions
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.transition.Slide
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import android.view.SubMenu import android.view.SubMenu
@ -42,6 +43,7 @@ import code.name.monkey.retromusic.util.PreferenceUtil
import code.name.monkey.retromusic.util.RetroColorUtil import code.name.monkey.retromusic.util.RetroColorUtil
import com.afollestad.materialcab.MaterialCab import com.afollestad.materialcab.MaterialCab
import com.bumptech.glide.Glide import com.bumptech.glide.Glide
import kotlinx.android.synthetic.main.activity_album.albumCoverContainer
import kotlinx.android.synthetic.main.activity_album.albumText import kotlinx.android.synthetic.main.activity_album.albumText
import kotlinx.android.synthetic.main.activity_album.albumTitle import kotlinx.android.synthetic.main.activity_album.albumTitle
import kotlinx.android.synthetic.main.activity_album.image import kotlinx.android.synthetic.main.activity_album.image
@ -90,6 +92,16 @@ class AlbumDetailsActivity : AbsSlidingMusicPanelActivity(), AlbumDetailsView, C
@Inject @Inject
lateinit var albumDetailsPresenter: AlbumDetailsPresenter lateinit var albumDetailsPresenter: AlbumDetailsPresenter
private fun windowEnterTransition() {
val slide = Slide()
slide.excludeTarget(R.id.appBarLayout, true)
slide.excludeTarget(R.id.status_bar, true)
slide.excludeTarget(android.R.id.statusBarBackground, true)
slide.excludeTarget(android.R.id.navigationBarBackground, true)
window.enterTransition = slide
}
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
setDrawUnderStatusBar() setDrawUnderStatusBar()
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
@ -98,10 +110,24 @@ class AlbumDetailsActivity : AbsSlidingMusicPanelActivity(), AlbumDetailsView, C
setNavigationbarColorAuto() setNavigationbarColorAuto()
setTaskDescriptionColorAuto() setTaskDescriptionColorAuto()
setLightNavigationBar(true) setLightNavigationBar(true)
window.sharedElementsUseOverlay = true
ActivityCompat.postponeEnterTransition(this)
App.musicComponent.inject(this) App.musicComponent.inject(this)
albumDetailsPresenter.attachView(this)
if (intent.extras!!.containsKey(EXTRA_ALBUM_ID)) {
intent.extras?.getInt(EXTRA_ALBUM_ID)?.let {
albumDetailsPresenter.loadAlbum(it)
albumCoverContainer?.transitionName = "${getString(R.string.transition_album_art)}_$it"
}
} else {
finish()
}
windowEnterTransition()
ActivityCompat.postponeEnterTransition(this)
artistImage = findViewById(R.id.artistImage) artistImage = findViewById(R.id.artistImage)
setupRecyclerView() setupRecyclerView()
@ -109,7 +135,10 @@ class AlbumDetailsActivity : AbsSlidingMusicPanelActivity(), AlbumDetailsView, C
artistImage.setOnClickListener { artistImage.setOnClickListener {
val artistPairs = ActivityOptions.makeSceneTransitionAnimation( val artistPairs = ActivityOptions.makeSceneTransitionAnimation(
this, this,
UtilPair.create(artistImage, getString(R.string.transition_artist_image)) UtilPair.create(
artistImage,
"${getString(R.string.transition_artist_image)}_${album.artistId}"
)
) )
NavigationUtil.goToArtistOptions(this, album.artistId, artistPairs) NavigationUtil.goToArtistOptions(this, album.artistId, artistPairs)
} }
@ -119,15 +148,6 @@ class AlbumDetailsActivity : AbsSlidingMusicPanelActivity(), AlbumDetailsView, C
shuffleAction.apply { shuffleAction.apply {
setOnClickListener { MusicPlayerRemote.openAndShuffleQueue(album.songs!!, true) } setOnClickListener { MusicPlayerRemote.openAndShuffleQueue(album.songs!!, true) }
} }
albumDetailsPresenter.attachView(this)
if (intent.extras!!.containsKey(EXTRA_ALBUM_ID)) {
intent.extras?.getInt(EXTRA_ALBUM_ID)?.let { albumDetailsPresenter.loadAlbum(it) }
} else {
finish()
}
} }
private fun setupRecyclerView() { private fun setupRecyclerView() {
@ -150,7 +170,7 @@ class AlbumDetailsActivity : AbsSlidingMusicPanelActivity(), AlbumDetailsView, C
} }
override fun album(album: Album) { override fun album(album: Album) {
complete()
if (album.songs!!.isEmpty()) { if (album.songs!!.isEmpty()) {
finish() finish()
return return

View file

@ -6,6 +6,7 @@ import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.text.Html import android.text.Html
import android.text.Spanned import android.text.Spanned
import android.transition.Slide
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import android.view.View import android.view.View
@ -49,8 +50,9 @@ import kotlinx.android.synthetic.main.activity_artist_content.playAction
import kotlinx.android.synthetic.main.activity_artist_content.recyclerView import kotlinx.android.synthetic.main.activity_artist_content.recyclerView
import kotlinx.android.synthetic.main.activity_artist_content.shuffleAction import kotlinx.android.synthetic.main.activity_artist_content.shuffleAction
import kotlinx.android.synthetic.main.activity_artist_content.songTitle import kotlinx.android.synthetic.main.activity_artist_content.songTitle
import kotlinx.android.synthetic.main.activity_artist_details.artistImage import kotlinx.android.synthetic.main.activity_artist_details.artistCoverContainer
import kotlinx.android.synthetic.main.activity_artist_details.artistTitle import kotlinx.android.synthetic.main.activity_artist_details.artistTitle
import kotlinx.android.synthetic.main.activity_artist_details.image
import kotlinx.android.synthetic.main.activity_artist_details.imageContainer import kotlinx.android.synthetic.main.activity_artist_details.imageContainer
import kotlinx.android.synthetic.main.activity_artist_details.text import kotlinx.android.synthetic.main.activity_artist_details.text
import kotlinx.android.synthetic.main.activity_artist_details.toolbar import kotlinx.android.synthetic.main.activity_artist_details.toolbar
@ -91,6 +93,16 @@ class ArtistDetailActivity : AbsSlidingMusicPanelActivity(), ArtistDetailsView,
@Inject @Inject
lateinit var artistDetailsPresenter: ArtistDetailsPresenter lateinit var artistDetailsPresenter: ArtistDetailsPresenter
private fun windowEnterTransition() {
val slide = Slide()
slide.excludeTarget(R.id.appBarLayout, true)
slide.excludeTarget(R.id.status_bar, true)
slide.excludeTarget(android.R.id.statusBarBackground, true)
slide.excludeTarget(android.R.id.navigationBarBackground, true)
window.enterTransition = slide
}
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
setDrawUnderStatusBar() setDrawUnderStatusBar()
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
@ -99,7 +111,21 @@ class ArtistDetailActivity : AbsSlidingMusicPanelActivity(), ArtistDetailsView,
setNavigationbarColorAuto() setNavigationbarColorAuto()
setTaskDescriptionColorAuto() setTaskDescriptionColorAuto()
setLightNavigationBar(true) setLightNavigationBar(true)
window.sharedElementsUseOverlay = true
App.musicComponent.inject(this)
artistDetailsPresenter.attachView(this)
if (intent.extras!!.containsKey(EXTRA_ARTIST_ID)) {
intent.extras?.getInt(EXTRA_ARTIST_ID)?.let {
artistDetailsPresenter.loadArtist(it)
artistCoverContainer?.transitionName = "${getString(R.string.transition_artist_image)}_$it"
}
} else {
finish()
}
windowEnterTransition()
ActivityCompat.postponeEnterTransition(this) ActivityCompat.postponeEnterTransition(this)
setUpViews() setUpViews()
@ -118,15 +144,6 @@ class ArtistDetailActivity : AbsSlidingMusicPanelActivity(), ArtistDetailsView,
biographyText.maxLines = 4 biographyText.maxLines = 4
} }
} }
App.musicComponent.inject(this)
artistDetailsPresenter.attachView(this)
if (intent.extras!!.containsKey(EXTRA_ARTIST_ID)) {
intent.extras?.getInt(EXTRA_ARTIST_ID)?.let { artistDetailsPresenter.loadArtist(it) }
} else {
finish()
}
} }
override fun onDestroy() { override fun onDestroy() {
@ -184,6 +201,7 @@ class ArtistDetailActivity : AbsSlidingMusicPanelActivity(), ArtistDetailsView,
} }
override fun artist(artist: Artist) { override fun artist(artist: Artist) {
complete()
if (artist.songCount <= 0) { if (artist.songCount <= 0) {
finish() finish()
} }
@ -238,7 +256,7 @@ class ArtistDetailActivity : AbsSlidingMusicPanelActivity(), ArtistDetailsView,
private fun loadArtistImage() { private fun loadArtistImage() {
ArtistGlideRequest.Builder.from(Glide.with(this), artist).generatePalette(this).build() ArtistGlideRequest.Builder.from(Glide.with(this), artist).generatePalette(this).build()
.dontAnimate().into(object : RetroMusicColoredTarget(artistImage) { .dontAnimate().into(object : RetroMusicColoredTarget(image) {
override fun onColorReady(color: Int) { override fun onColorReady(color: Int) {
setColors(color) setColors(color)
} }

View file

@ -28,16 +28,17 @@ import com.bumptech.glide.Glide
import com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView import com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView
open class AlbumAdapter( open class AlbumAdapter(
protected val activity: AppCompatActivity, protected val activity: AppCompatActivity,
dataSet: ArrayList<Album>, dataSet: ArrayList<Album>,
protected var itemLayoutRes: Int, protected var itemLayoutRes: Int,
usePalette: Boolean, usePalette: Boolean,
cabHolder: CabHolder? cabHolder: CabHolder?
) : AbsMultiSelectAdapter<AlbumAdapter.ViewHolder, Album>( ) : AbsMultiSelectAdapter<AlbumAdapter.ViewHolder, Album>(
activity, activity,
cabHolder, cabHolder,
R.menu.menu_media_selection R.menu.menu_media_selection
), FastScrollRecyclerView.SectionedAdapter { ), FastScrollRecyclerView.SectionedAdapter {
var dataSet: ArrayList<Album> var dataSet: ArrayList<Album>
protected set protected set
@ -87,14 +88,32 @@ open class AlbumAdapter(
holder.itemView.isActivated = isChecked holder.itemView.isActivated = isChecked
holder.title?.text = getAlbumTitle(album) holder.title?.text = getAlbumTitle(album)
holder.text?.text = getAlbumText(album) holder.text?.text = getAlbumText(album)
holder.playSongs?.setOnClickListener { album.songs?.let { songs -> MusicPlayerRemote.openQueue(songs, 0, true) } } holder.playSongs?.setOnClickListener {
album.songs?.let { songs ->
MusicPlayerRemote.openQueue(
songs,
0,
true
)
}
}
loadAlbumCover(album, holder) loadAlbumCover(album, holder)
} }
protected open fun setColors(color: Int, holder: ViewHolder) { protected open fun setColors(color: Int, holder: ViewHolder) {
if (holder.paletteColorContainer != null) { if (holder.paletteColorContainer != null) {
holder.title?.setTextColor(MaterialValueHelper.getPrimaryTextColor(activity, ColorUtil.isColorLight(color))) holder.title?.setTextColor(
holder.text?.setTextColor(MaterialValueHelper.getSecondaryTextColor(activity, ColorUtil.isColorLight(color))) MaterialValueHelper.getPrimaryTextColor(
activity,
ColorUtil.isColorLight(color)
)
)
holder.text?.setTextColor(
MaterialValueHelper.getSecondaryTextColor(
activity,
ColorUtil.isColorLight(color)
)
)
holder.paletteColorContainer?.setBackgroundColor(color) holder.paletteColorContainer?.setBackgroundColor(color)
} }
holder.mask?.backgroundTintList = ColorStateList.valueOf(color) holder.mask?.backgroundTintList = ColorStateList.valueOf(color)
@ -106,17 +125,17 @@ open class AlbumAdapter(
} }
SongGlideRequest.Builder.from(Glide.with(activity), album.safeGetFirstSong()) SongGlideRequest.Builder.from(Glide.with(activity), album.safeGetFirstSong())
.checkIgnoreMediaStore(activity).generatePalette(activity).build() .checkIgnoreMediaStore(activity).generatePalette(activity).build()
.into(object : RetroMusicColoredTarget(holder.image!!) { .into(object : RetroMusicColoredTarget(holder.image!!) {
override fun onLoadCleared(placeholder: Drawable?) { override fun onLoadCleared(placeholder: Drawable?) {
super.onLoadCleared(placeholder) super.onLoadCleared(placeholder)
setColors(defaultFooterColor, holder) setColors(defaultFooterColor, holder)
} }
override fun onColorReady(color: Int) { override fun onColorReady(color: Int) {
setColors(color, holder) setColors(color, holder)
} }
}) })
} }
override fun getItemCount(): Int { override fun getItemCount(): Int {
@ -136,7 +155,7 @@ open class AlbumAdapter(
} }
override fun onMultipleItemAction( override fun onMultipleItemAction(
menuItem: MenuItem, selection: ArrayList<Album> menuItem: MenuItem, selection: ArrayList<Album>
) { ) {
SongsMenuHelper.handleMenuClick(activity, getSongList(selection), menuItem.itemId) SongsMenuHelper.handleMenuClick(activity, getSongList(selection), menuItem.itemId)
} }
@ -152,10 +171,11 @@ open class AlbumAdapter(
override fun getSectionName(position: Int): String { override fun getSectionName(position: Int): String {
var sectionName: String? = null var sectionName: String? = null
when (PreferenceUtil.getInstance(activity).albumSortOrder) { when (PreferenceUtil.getInstance(activity).albumSortOrder) {
SortOrder.AlbumSortOrder.ALBUM_A_Z, SortOrder.AlbumSortOrder.ALBUM_Z_A -> sectionName = dataSet[position].title SortOrder.AlbumSortOrder.ALBUM_A_Z, SortOrder.AlbumSortOrder.ALBUM_Z_A -> sectionName =
dataSet[position].title
SortOrder.AlbumSortOrder.ALBUM_ARTIST -> sectionName = dataSet[position].artistName SortOrder.AlbumSortOrder.ALBUM_ARTIST -> sectionName = dataSet[position].artistName
SortOrder.AlbumSortOrder.ALBUM_YEAR -> return MusicUtil.getYearString( SortOrder.AlbumSortOrder.ALBUM_YEAR -> return MusicUtil.getYearString(
dataSet[position].year dataSet[position].year
) )
} }
@ -175,13 +195,11 @@ open class AlbumAdapter(
toggleChecked(adapterPosition) toggleChecked(adapterPosition)
} else { } else {
val activityOptions = ActivityOptions.makeSceneTransitionAnimation( val activityOptions = ActivityOptions.makeSceneTransitionAnimation(
activity, image, activity.getString( activity,
R.string.transition_album_art imageContainerCard ?: image,
) "${activity.getString(R.string.transition_album_art)}_${dataSet[adapterPosition].id}"
)
NavigationUtil.goToAlbumOptions(
activity, dataSet[adapterPosition].id, activityOptions
) )
NavigationUtil.goToAlbumOptions(activity, dataSet[adapterPosition].id, activityOptions)
} }
} }

View file

@ -16,11 +16,11 @@ import code.name.monkey.retromusic.model.Song
import code.name.monkey.retromusic.util.NavigationUtil import code.name.monkey.retromusic.util.NavigationUtil
import code.name.monkey.retromusic.util.PreferenceUtil import code.name.monkey.retromusic.util.PreferenceUtil
import com.bumptech.glide.Glide import com.bumptech.glide.Glide
import java.util.* import java.util.ArrayList
class AlbumCoverPagerAdapter( class AlbumCoverPagerAdapter(
fm: FragmentManager, fm: FragmentManager,
private val dataSet: ArrayList<Song> private val dataSet: ArrayList<Song>
) : CustomFragmentStatePagerAdapter(fm) { ) : CustomFragmentStatePagerAdapter(fm) {
private var currentColorReceiver: AlbumCoverFragment.ColorReceiver? = null private var currentColorReceiver: AlbumCoverFragment.ColorReceiver? = null
@ -90,9 +90,9 @@ class AlbumCoverPagerAdapter(
} }
override fun onCreateView( override fun onCreateView(
inflater: LayoutInflater, inflater: LayoutInflater,
container: ViewGroup?, container: ViewGroup?,
savedInstanceState: Bundle? savedInstanceState: Bundle?
): View? { ): View? {
val finalLayout = when { val finalLayout = when {
PreferenceUtil.getInstance(activity).carouselEffect() -> R.layout.fragment_album_carousel_cover PreferenceUtil.getInstance(activity).carouselEffect() -> R.layout.fragment_album_carousel_cover
@ -119,13 +119,13 @@ class AlbumCoverPagerAdapter(
private fun loadAlbumCover() { private fun loadAlbumCover() {
SongGlideRequest.Builder.from(Glide.with(requireContext()), song) SongGlideRequest.Builder.from(Glide.with(requireContext()), song)
.checkIgnoreMediaStore(requireContext()) .checkIgnoreMediaStore(requireContext())
.generatePalette(requireContext()).build() .generatePalette(requireContext()).build()
.into(object : RetroMusicColoredTarget(albumCover) { .into(object : RetroMusicColoredTarget(albumCover) {
override fun onColorReady(color: Int) { override fun onColorReady(color: Int) {
setColor(color) setColor(color)
} }
}) })
} }
private fun setColor(color: Int) { private fun setColor(color: Int) {

View file

@ -31,9 +31,9 @@ import code.name.monkey.retromusic.views.MetalRecyclerViewPager
import com.bumptech.glide.Glide 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: ArrayList<Album>,
metrics: DisplayMetrics metrics: DisplayMetrics
) : MetalRecyclerViewPager.MetalAdapter<AlbumFullWidthAdapter.FullMetalViewHolder>(metrics) { ) : MetalRecyclerViewPager.MetalAdapter<AlbumFullWidthAdapter.FullMetalViewHolder>(metrics) {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): FullMetalViewHolder { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): FullMetalViewHolder {
@ -46,7 +46,15 @@ class AlbumFullWidthAdapter(
val album = dataSet[position] val album = dataSet[position]
holder.title?.text = getAlbumTitle(album) holder.title?.text = getAlbumTitle(album)
holder.text?.text = getAlbumText(album) holder.text?.text = getAlbumText(album)
holder.playSongs?.setOnClickListener { album.songs?.let { songs -> MusicPlayerRemote.openQueue(songs, 0, true) } } holder.playSongs?.setOnClickListener {
album.songs?.let { songs ->
MusicPlayerRemote.openQueue(
songs,
0,
true
)
}
}
loadAlbumCover(album, holder) loadAlbumCover(album, holder)
} }
@ -63,14 +71,13 @@ class AlbumFullWidthAdapter(
return return
} }
SongGlideRequest.Builder.from(Glide.with(activity), album.safeGetFirstSong()) SongGlideRequest.Builder.from(Glide.with(activity), album.safeGetFirstSong())
.checkIgnoreMediaStore(activity) .checkIgnoreMediaStore(activity)
.generatePalette(activity) .generatePalette(activity)
.build() .build()
.into(object : RetroMusicColoredTarget(holder.image!!) { .into(object : RetroMusicColoredTarget(holder.image!!) {
override fun onColorReady(color: Int) { override fun onColorReady(color: Int) {
}
} })
})
} }
override fun getItemCount(): Int { override fun getItemCount(): Int {
@ -80,7 +87,11 @@ class AlbumFullWidthAdapter(
inner class FullMetalViewHolder(itemView: View) : MetalRecyclerViewPager.MetalViewHolder(itemView) { inner class FullMetalViewHolder(itemView: View) : MetalRecyclerViewPager.MetalViewHolder(itemView) {
override fun onClick(v: View?) { override fun onClick(v: View?) {
val activityOptions = ActivityOptions.makeSceneTransitionAnimation(activity, image, activity.getString(R.string.transition_album_art)) val activityOptions = ActivityOptions.makeSceneTransitionAnimation(
activity,
imageContainerCard ?: image,
"${activity.getString(R.string.transition_album_art)}_${dataSet[adapterPosition].id}"
)
NavigationUtil.goToAlbumOptions(activity, dataSet[adapterPosition].id, activityOptions) NavigationUtil.goToAlbumOptions(activity, dataSet[adapterPosition].id, activityOptions)
} }
} }

View file

@ -3,150 +3,158 @@ package code.name.monkey.retromusic.adapter.artist
import android.app.ActivityOptions import android.app.ActivityOptions
import android.content.res.ColorStateList import android.content.res.ColorStateList
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
import android.view.* import android.view.LayoutInflater
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import code.name.monkey.appthemehelper.util.* import code.name.monkey.appthemehelper.util.ColorUtil
import code.name.monkey.appthemehelper.util.MaterialValueHelper
import code.name.monkey.retromusic.R import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.adapter.base.* import code.name.monkey.retromusic.adapter.base.AbsMultiSelectAdapter
import code.name.monkey.retromusic.glide.* import code.name.monkey.retromusic.adapter.base.MediaEntryViewHolder
import code.name.monkey.retromusic.glide.ArtistGlideRequest
import code.name.monkey.retromusic.glide.RetroMusicColoredTarget
import code.name.monkey.retromusic.helper.menu.SongsMenuHelper import code.name.monkey.retromusic.helper.menu.SongsMenuHelper
import code.name.monkey.retromusic.interfaces.CabHolder import code.name.monkey.retromusic.interfaces.CabHolder
import code.name.monkey.retromusic.model.* import code.name.monkey.retromusic.model.Artist
import code.name.monkey.retromusic.util.* import code.name.monkey.retromusic.model.Song
import code.name.monkey.retromusic.util.MusicUtil
import code.name.monkey.retromusic.util.NavigationUtil
import com.bumptech.glide.Glide import com.bumptech.glide.Glide
import com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView import com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView
import java.util.* import java.util.ArrayList
class ArtistAdapter( class ArtistAdapter(
val activity: AppCompatActivity, val activity: AppCompatActivity,
var dataSet: ArrayList<Artist>, var dataSet: ArrayList<Artist>,
var itemLayoutRes: Int, var itemLayoutRes: Int,
var usePalette: Boolean, 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
), FastScrollRecyclerView.SectionedAdapter { ), FastScrollRecyclerView.SectionedAdapter {
fun swapDataSet(dataSet: ArrayList<Artist>) { fun swapDataSet(dataSet: ArrayList<Artist>) {
this.dataSet = dataSet this.dataSet = dataSet
notifyDataSetChanged() notifyDataSetChanged()
} }
fun usePalette(usePalette: Boolean) { fun usePalette(usePalette: Boolean) {
this.usePalette = usePalette this.usePalette = usePalette
notifyDataSetChanged() notifyDataSetChanged()
} }
override fun getItemId(position: Int): Long { override fun getItemId(position: Int): Long {
return dataSet[position].id.toLong() return dataSet[position].id.toLong()
} }
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val view = LayoutInflater.from(activity).inflate(itemLayoutRes, parent, false) val view = LayoutInflater.from(activity).inflate(itemLayoutRes, parent, false)
return createViewHolder(view) return createViewHolder(view)
} }
private fun createViewHolder(view: View): ViewHolder { private fun createViewHolder(view: View): ViewHolder {
return ViewHolder(view) return ViewHolder(view)
} }
override fun onBindViewHolder(holder: ViewHolder, position: Int) { override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val artist = dataSet[position] val artist = dataSet[position]
val isChecked = isChecked(artist) val isChecked = isChecked(artist)
holder.itemView.isActivated = isChecked holder.itemView.isActivated = isChecked
holder.title?.text = artist.name holder.title?.text = artist.name
holder.text?.visibility = View.GONE holder.text?.visibility = View.GONE
loadArtistImage(artist, holder) loadArtistImage(artist, holder)
} }
fun setColors(color: Int, holder: ViewHolder) { fun setColors(color: Int, holder: ViewHolder) {
if (holder.paletteColorContainer != null) { if (holder.paletteColorContainer != null) {
holder.paletteColorContainer?.setBackgroundColor(color) holder.paletteColorContainer?.setBackgroundColor(color)
holder.title?.setTextColor( holder.title?.setTextColor(
MaterialValueHelper.getPrimaryTextColor( MaterialValueHelper.getPrimaryTextColor(
activity, ColorUtil.isColorLight( activity, ColorUtil.isColorLight(
color color
) )
) )
) )
} }
holder.mask?.backgroundTintList = ColorStateList.valueOf(color) holder.mask?.backgroundTintList = ColorStateList.valueOf(color)
} }
private fun loadArtistImage(artist: Artist, holder: ViewHolder) { private fun loadArtistImage(artist: Artist, holder: ViewHolder) {
if (holder.image == null) { if (holder.image == null) {
return return
} }
ArtistGlideRequest.Builder.from(Glide.with(activity), artist).generatePalette(activity) ArtistGlideRequest.Builder.from(Glide.with(activity), artist).generatePalette(activity)
.build().into(object : RetroMusicColoredTarget(holder.image!!) { .build().into(object : RetroMusicColoredTarget(holder.image!!) {
override fun onLoadCleared(placeholder: Drawable?) { override fun onLoadCleared(placeholder: Drawable?) {
super.onLoadCleared(placeholder) super.onLoadCleared(placeholder)
setColors(defaultFooterColor, holder) setColors(defaultFooterColor, holder)
} }
override fun onColorReady(color: Int) { override fun onColorReady(color: Int) {
setColors(color, holder) setColors(color, holder)
} }
}) })
} }
override fun getItemCount(): Int { override fun getItemCount(): Int {
return dataSet.size return dataSet.size
} }
override fun getIdentifier(position: Int): Artist? { override fun getIdentifier(position: Int): Artist? {
return dataSet[position] return dataSet[position]
} }
override fun getName(artist: Artist): String { override fun getName(artist: Artist): String {
return artist.name return artist.name
} }
override fun onMultipleItemAction( override fun onMultipleItemAction(
menuItem: MenuItem, selection: ArrayList<Artist> menuItem: MenuItem, selection: ArrayList<Artist>
) { ) {
SongsMenuHelper.handleMenuClick(activity, getSongList(selection), menuItem.itemId) SongsMenuHelper.handleMenuClick(activity, getSongList(selection), menuItem.itemId)
} }
private fun getSongList(artists: List<Artist>): ArrayList<Song> { private fun getSongList(artists: List<Artist>): ArrayList<Song> {
val songs = ArrayList<Song>() val songs = ArrayList<Song>()
for (artist in artists) { for (artist in artists) {
songs.addAll(artist.songs) // maybe async in future? songs.addAll(artist.songs) // maybe async in future?
} }
return songs return songs
} }
override fun getSectionName(position: Int): String { override fun getSectionName(position: Int): String {
return MusicUtil.getSectionName(dataSet[position].name) return MusicUtil.getSectionName(dataSet[position].name)
} }
inner class ViewHolder(itemView: View) : MediaEntryViewHolder(itemView) { inner class ViewHolder(itemView: View) : MediaEntryViewHolder(itemView) {
init { init {
setImageTransitionName(activity.getString(R.string.transition_artist_image)) setImageTransitionName(activity.getString(R.string.transition_artist_image))
menu?.visibility = View.GONE menu?.visibility = View.GONE
} }
override fun onClick(v: View?) { override fun onClick(v: View?) {
super.onClick(v) super.onClick(v)
if (isInQuickSelectMode) { if (isInQuickSelectMode) {
toggleChecked(adapterPosition) toggleChecked(adapterPosition)
} else { } else {
val activityOptions = ActivityOptions.makeSceneTransitionAnimation( val activityOptions = ActivityOptions.makeSceneTransitionAnimation(
activity, image, activity.getString( activity,
R.string.transition_artist_image imageContainerCard ?: image,
) "${activity.getString(R.string.transition_artist_image)}_${dataSet[adapterPosition].id}"
) )
NavigationUtil.goToArtistOptions( NavigationUtil.goToArtistOptions(
activity, dataSet[adapterPosition].id, activityOptions activity, dataSet[adapterPosition].id, activityOptions
) )
} }
} }
override fun onLongClick(v: View?): Boolean { override fun onLongClick(v: View?): Boolean {
toggleChecked(adapterPosition) toggleChecked(adapterPosition)
return super.onLongClick(v) return super.onLongClick(v)
} }
} }
} }

View file

@ -19,29 +19,25 @@ import android.view.ViewGroup;
import android.widget.ImageButton; import android.widget.ImageButton;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import code.name.monkey.appthemehelper.util.ATHUtil;
import code.name.monkey.retromusic.R;
import com.google.android.material.card.MaterialCardView; import com.google.android.material.card.MaterialCardView;
import com.h6ah4i.android.widget.advrecyclerview.utils.AbstractDraggableSwipeableItemViewHolder; import com.h6ah4i.android.widget.advrecyclerview.utils.AbstractDraggableSwipeableItemViewHolder;
import code.name.monkey.appthemehelper.util.ATHUtil; public class MediaEntryViewHolder extends AbstractDraggableSwipeableItemViewHolder
import code.name.monkey.retromusic.R; implements View.OnLongClickListener, View.OnClickListener {
public class MediaEntryViewHolder extends AbstractDraggableSwipeableItemViewHolder implements View.OnLongClickListener, View.OnClickListener {
@Nullable
public TextView title;
@Nullable @Nullable
public TextView text; public View dragView;
@Nullable @Nullable
public TextView time; public View dummyContainer;
@Nullable @Nullable
public TextView imageText; public ImageView image;
@Nullable @Nullable
public ViewGroup imageContainer; public ViewGroup imageContainer;
@ -50,30 +46,34 @@ public class MediaEntryViewHolder extends AbstractDraggableSwipeableItemViewHold
public MaterialCardView imageContainerCard; public MaterialCardView imageContainerCard;
@Nullable @Nullable
public View menu; public TextView imageText;
@Nullable
public View dragView;
@Nullable
public View paletteColorContainer;
@Nullable
public RecyclerView recyclerView;
@Nullable
public ImageButton playSongs;
@Nullable
public View mask;
@Nullable @Nullable
public MaterialCardView imageTextContainer; public MaterialCardView imageTextContainer;
@Nullable @Nullable
public ImageView image; public View mask;
@Nullable @Nullable
public View dummyContainer; public View menu;
@Nullable
public View paletteColorContainer;
@Nullable
public ImageButton playSongs;
@Nullable
public RecyclerView recyclerView;
@Nullable
public TextView text;
@Nullable
public TextView time;
@Nullable
public TextView title;
public MediaEntryViewHolder(@NonNull View itemView) { public MediaEntryViewHolder(@NonNull View itemView) {
super(itemView); super(itemView);
@ -97,7 +97,8 @@ public class MediaEntryViewHolder extends AbstractDraggableSwipeableItemViewHold
dummyContainer = itemView.findViewById(R.id.dummy_view); dummyContainer = itemView.findViewById(R.id.dummy_view);
if (imageContainerCard != null) { if (imageContainerCard != null) {
imageContainerCard.setCardBackgroundColor(ATHUtil.INSTANCE.resolveColor(itemView.getContext(), R.attr.colorSurface)); imageContainerCard.setCardBackgroundColor(
ATHUtil.INSTANCE.resolveColor(itemView.getContext(), R.attr.colorSurface));
} }
itemView.setOnClickListener(this); itemView.setOnClickListener(this);
itemView.setOnLongClickListener(this); itemView.setOnLongClickListener(this);
@ -108,17 +109,20 @@ public class MediaEntryViewHolder extends AbstractDraggableSwipeableItemViewHold
return null; return null;
} }
@Override
public boolean onLongClick(View v) {
return false;
}
@Override @Override
public void onClick(View v) { public void onClick(View v) {
} }
@Override
public boolean onLongClick(View v) {
return false;
}
public void setImageTransitionName(@NonNull String transitionName) { public void setImageTransitionName(@NonNull String transitionName) {
if (imageContainerCard != null) {
imageContainerCard.setTransitionName(transitionName);
}
if (image != null) { if (image != null) {
image.setTransitionName(transitionName); image.setTransitionName(transitionName);
} }

View file

@ -10,14 +10,14 @@ 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.* import java.util.ArrayList
open class PlaylistSongAdapter( open class PlaylistSongAdapter(
activity: AppCompatActivity, activity: AppCompatActivity,
dataSet: ArrayList<Song>, dataSet: ArrayList<Song>,
itemLayoutRes: Int, itemLayoutRes: Int,
usePalette: Boolean, usePalette: Boolean,
cabHolder: CabHolder? cabHolder: CabHolder?
) : AbsOffsetSongAdapter(activity, dataSet, itemLayoutRes, usePalette, cabHolder, false) { ) : AbsOffsetSongAdapter(activity, dataSet, itemLayoutRes, usePalette, cabHolder, false) {
init { init {
@ -60,13 +60,11 @@ open class PlaylistSongAdapter(
override fun onSongMenuItemClick(item: MenuItem): Boolean { override fun onSongMenuItemClick(item: MenuItem): Boolean {
if (item.itemId == R.id.action_go_to_album) { if (item.itemId == R.id.action_go_to_album) {
val activityOptions = ActivityOptions.makeSceneTransitionAnimation( val activityOptions = ActivityOptions.makeSceneTransitionAnimation(
activity, image, activity.getString( activity,
R.string.transition_album_art imageContainerCard ?: image,
) "${activity.getString(R.string.transition_album_art)}_${song.albumId}"
)
NavigationUtil.goToAlbumOptions(
activity, dataSet[adapterPosition - 1].albumId, activityOptions
) )
NavigationUtil.goToAlbumOptions(activity, song.albumId, activityOptions)
return true return true
} }
return super.onSongMenuItemClick(item) return super.onSongMenuItemClick(item)

View file

@ -26,22 +26,23 @@ import code.name.monkey.retromusic.util.PreferenceUtil
import com.afollestad.materialcab.MaterialCab import com.afollestad.materialcab.MaterialCab
import com.bumptech.glide.Glide import com.bumptech.glide.Glide
import com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView import com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView
import java.util.* import java.util.ArrayList
/** /**
* Created by hemanths on 13/08/17. * Created by hemanths on 13/08/17.
*/ */
open class SongAdapter( open class SongAdapter(
protected val activity: AppCompatActivity, protected val activity: AppCompatActivity,
dataSet: ArrayList<Song>, dataSet: ArrayList<Song>,
protected var itemLayoutRes: Int, protected var itemLayoutRes: Int,
usePalette: Boolean, usePalette: Boolean,
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, FastScrollRecyclerView.SectionedAdapter { ), MaterialCab.Callback, FastScrollRecyclerView.SectionedAdapter {
var dataSet: ArrayList<Song> var dataSet: ArrayList<Song>
protected var usePalette = false protected var usePalette = false
@ -104,18 +105,18 @@ open class SongAdapter(
return return
} }
SongGlideRequest.Builder.from(Glide.with(activity), song).checkIgnoreMediaStore(activity) SongGlideRequest.Builder.from(Glide.with(activity), song).checkIgnoreMediaStore(activity)
.generatePalette(activity).build() .generatePalette(activity).build()
.into(object : RetroMusicColoredTarget(holder.image!!) { .into(object : RetroMusicColoredTarget(holder.image!!) {
override fun onLoadCleared(placeholder: Drawable?) { override fun onLoadCleared(placeholder: Drawable?) {
super.onLoadCleared(placeholder) super.onLoadCleared(placeholder)
setColors(defaultFooterColor, holder) setColors(defaultFooterColor, holder)
} }
override fun onColorReady(color: Int) { override fun onColorReady(color: Int) {
if (usePalette) setColors(color, holder) if (usePalette) setColors(color, holder)
else setColors(defaultFooterColor, holder) else setColors(defaultFooterColor, holder)
} }
}) })
} }
private fun getSongTitle(song: Song): String? { private fun getSongTitle(song: Song): String? {
@ -183,10 +184,12 @@ open class SongAdapter(
if (image != null && image!!.visibility == View.VISIBLE) { if (image != null && image!!.visibility == View.VISIBLE) {
when (item.itemId) { when (item.itemId) {
R.id.action_go_to_album -> { R.id.action_go_to_album -> {
val options: ActivityOptions = ActivityOptions.makeSceneTransitionAnimation( val activityOptions = ActivityOptions.makeSceneTransitionAnimation(
activity, image, activity.getString(R.string.transition_album_art) activity,
imageContainerCard ?: image,
"${activity.getString(R.string.transition_album_art)}_${song.albumId}"
) )
NavigationUtil.goToAlbumOptions(activity, song.albumId, options) NavigationUtil.goToAlbumOptions(activity, song.albumId, activityOptions)
return true return true
} }
} }

View file

@ -7,8 +7,8 @@ import androidx.recyclerview.widget.RecyclerView
import code.name.monkey.retromusic.R import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.util.RetroUtil import code.name.monkey.retromusic.util.RetroUtil
abstract class AbsLibraryPagerRecyclerViewCustomGridSizeFragment<A : RecyclerView.Adapter<*>, LM : RecyclerView.LayoutManager> :
abstract class AbsLibraryPagerRecyclerViewCustomGridSizeFragment<A : RecyclerView.Adapter<*>, LM : RecyclerView.LayoutManager> : AbsLibraryPagerRecyclerViewFragment<A, LM>() { AbsLibraryPagerRecyclerViewFragment<A, LM>() {
private var gridSize: Int = 0 private var gridSize: Int = 0
private var sortOrder: String? = null private var sortOrder: String? = null
@ -149,6 +149,4 @@ abstract class AbsLibraryPagerRecyclerViewCustomGridSizeFragment<A : RecyclerVie
protected abstract fun loadUsePalette(): Boolean protected abstract fun loadUsePalette(): Boolean
protected abstract fun setUsePalette(usePalette: Boolean) protected abstract fun setUsePalette(usePalette: Boolean)
} }

View file

@ -13,7 +13,9 @@ import code.name.monkey.retromusic.mvp.presenter.ArtistsView
import code.name.monkey.retromusic.util.PreferenceUtil import code.name.monkey.retromusic.util.PreferenceUtil
import javax.inject.Inject import javax.inject.Inject
class ArtistsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment<ArtistAdapter, GridLayoutManager>(), ArtistsView { class ArtistsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment<ArtistAdapter, GridLayoutManager>(),
ArtistsView {
override fun artists(artists: ArrayList<Artist>) { override fun artists(artists: ArrayList<Artist>) {
adapter?.swapDataSet(artists) adapter?.swapDataSet(artists)
} }
@ -33,6 +35,7 @@ class ArtistsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment<Artist
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
artistsPresenter.attachView(this) artistsPresenter.attachView(this)
} }
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
if (adapter!!.dataSet.isEmpty()) { if (adapter!!.dataSet.isEmpty()) {
@ -67,7 +70,6 @@ class ArtistsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment<Artist
return ArtistAdapter(libraryFragment.mainActivity, dataSet, itemLayoutRes, loadUsePalette(), libraryFragment) return ArtistAdapter(libraryFragment.mainActivity, dataSet, itemLayoutRes, loadUsePalette(), libraryFragment)
} }
override fun loadGridSize(): Int { override fun loadGridSize(): Int {
return PreferenceUtil.getInstance(requireContext()).getArtistGridSize(activity!!) return PreferenceUtil.getInstance(requireContext()).getArtistGridSize(activity!!)
} }
@ -101,7 +103,6 @@ class ArtistsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment<Artist
adapter?.notifyDataSetChanged() adapter?.notifyDataSetChanged()
} }
override fun loadSortOrder(): String { override fun loadSortOrder(): String {
return PreferenceUtil.getInstance(requireContext()).artistSortOrder return PreferenceUtil.getInstance(requireContext()).artistSortOrder
} }
@ -110,7 +111,6 @@ class ArtistsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment<Artist
PreferenceUtil.getInstance(requireContext()).artistSortOrder = sortOrder PreferenceUtil.getInstance(requireContext()).artistSortOrder = sortOrder
} }
override fun showEmptyView() { override fun showEmptyView() {
adapter?.swapDataSet(ArrayList()) adapter?.swapDataSet(ArrayList())
} }

View file

@ -20,21 +20,19 @@ import android.view.View
import android.widget.PopupMenu import android.widget.PopupMenu
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.FragmentActivity import androidx.fragment.app.FragmentActivity
import code.name.monkey.retromusic.R import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.activities.tageditor.AbsTagEditorActivity
import code.name.monkey.retromusic.activities.tageditor.SongTagEditorActivity
import code.name.monkey.retromusic.dialogs.AddToPlaylistDialog import code.name.monkey.retromusic.dialogs.AddToPlaylistDialog
import code.name.monkey.retromusic.dialogs.DeleteSongsDialog import code.name.monkey.retromusic.dialogs.DeleteSongsDialog
import code.name.monkey.retromusic.dialogs.SongDetailDialog import code.name.monkey.retromusic.dialogs.SongDetailDialog
import code.name.monkey.retromusic.helper.MusicPlayerRemote import code.name.monkey.retromusic.helper.MusicPlayerRemote
import code.name.monkey.retromusic.interfaces.PaletteColorHolder import code.name.monkey.retromusic.interfaces.PaletteColorHolder
import code.name.monkey.retromusic.model.Song import code.name.monkey.retromusic.model.Song
import code.name.monkey.retromusic.activities.tageditor.AbsTagEditorActivity
import code.name.monkey.retromusic.activities.tageditor.SongTagEditorActivity
import code.name.monkey.retromusic.util.MusicUtil import code.name.monkey.retromusic.util.MusicUtil
import code.name.monkey.retromusic.util.NavigationUtil import code.name.monkey.retromusic.util.NavigationUtil
import code.name.monkey.retromusic.util.RingtoneManager import code.name.monkey.retromusic.util.RingtoneManager
object SongMenuHelper { object SongMenuHelper {
val MENU_RES = R.menu.menu_item_song val MENU_RES = R.menu.menu_item_song
@ -49,7 +47,12 @@ object SongMenuHelper {
return true return true
} }
R.id.action_share -> { R.id.action_share -> {
activity.startActivity(Intent.createChooser(MusicUtil.createShareSongFileIntent(song, activity), null)) activity.startActivity(
Intent.createChooser(
MusicUtil.createShareSongFileIntent(song, activity),
null
)
)
return true return true
} }
R.id.action_delete_from_device -> { R.id.action_delete_from_device -> {
@ -72,7 +75,10 @@ object SongMenuHelper {
val tagEditorIntent = Intent(activity, SongTagEditorActivity::class.java) val tagEditorIntent = Intent(activity, SongTagEditorActivity::class.java)
tagEditorIntent.putExtra(AbsTagEditorActivity.EXTRA_ID, song.id) tagEditorIntent.putExtra(AbsTagEditorActivity.EXTRA_ID, song.id)
if (activity is PaletteColorHolder) if (activity is PaletteColorHolder)
tagEditorIntent.putExtra(AbsTagEditorActivity.EXTRA_PALETTE, (activity as PaletteColorHolder).paletteColor) tagEditorIntent.putExtra(
AbsTagEditorActivity.EXTRA_PALETTE,
(activity as PaletteColorHolder).paletteColor
)
activity.startActivity(tagEditorIntent) activity.startActivity(tagEditorIntent)
return true return true
} }
@ -92,7 +98,8 @@ object SongMenuHelper {
return false return false
} }
abstract class OnClickSongMenu protected constructor(private val activity: AppCompatActivity) : View.OnClickListener, PopupMenu.OnMenuItemClickListener { abstract class OnClickSongMenu protected constructor(private val activity: AppCompatActivity) :
View.OnClickListener, PopupMenu.OnMenuItemClickListener {
open val menuRes: Int open val menuRes: Int
get() = MENU_RES get() = MENU_RES

View file

@ -21,15 +21,19 @@ import code.name.monkey.retromusic.model.Artist
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
/** /**
* Created by hemanths on 20/08/17. * Created by hemanths on 20/08/17.
*/ */
interface AlbumDetailsView { interface AlbumDetailsView {
fun album(album: Album) fun album(album: Album)
fun complete() fun complete()
@ -45,8 +49,9 @@ interface AlbumDetailsPresenter : Presenter<AlbumDetailsView> {
fun loadMore(artistId: Int) fun loadMore(artistId: Int)
class AlbumDetailsPresenterImpl @Inject constructor( class AlbumDetailsPresenterImpl @Inject constructor(
private val repository: Repository private val repository: Repository
) : PresenterImpl<AlbumDetailsView>(), AlbumDetailsPresenter, CoroutineScope { ) : PresenterImpl<AlbumDetailsView>(), AlbumDetailsPresenter, CoroutineScope {
private val job = Job() private val job = Job()
private lateinit var album: Album private lateinit var album: Album
@ -63,11 +68,10 @@ interface AlbumDetailsPresenter : Presenter<AlbumDetailsView> {
view?.loadArtistImage(artist) view?.loadArtistImage(artist)
artist.albums?.filter { it.id != album.id }?.let { artist.albums?.filter { it.id != album.id }?.let {
view?.moreAlbums(ArrayList(it)) if (it.isNotEmpty()) view?.moreAlbums(ArrayList(it))
} }
} }
override fun loadAlbum(albumId: Int) { override fun loadAlbum(albumId: Int) {
launch { launch {
when (val result = repository.albumById(albumId)) { when (val result = repository.albumById(albumId)) {
@ -77,7 +81,6 @@ interface AlbumDetailsPresenter : Presenter<AlbumDetailsView> {
} }
is Error -> withContext(Dispatchers.Main) { view?.complete() } is Error -> withContext(Dispatchers.Main) { view?.complete() }
} }
view?.complete()
} }
} }

View file

@ -21,8 +21,12 @@ 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 code.name.monkey.retromusic.rest.model.LastFmArtist import code.name.monkey.retromusic.rest.model.LastFmArtist
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 java.util.Locale
import javax.inject.Inject import javax.inject.Inject
import kotlin.coroutines.CoroutineContext import kotlin.coroutines.CoroutineContext
@ -69,7 +73,7 @@ interface ArtistDetailsPresenter : Presenter<ArtistDetailsView> {
when (val result = repository.artistById(artistId)) { when (val result = repository.artistById(artistId)) {
is Result.Success -> withContext(Dispatchers.Main) { is Result.Success -> withContext(Dispatchers.Main) {
view?.artist(result.data) view?.artist(result.data)
view?.complete()
} }
is Result.Error -> withContext(Dispatchers.Main) { is Result.Error -> withContext(Dispatchers.Main) {
view?.showEmptyView() view?.showEmptyView()

View file

@ -14,6 +14,9 @@
package code.name.monkey.retromusic.util; package code.name.monkey.retromusic.util;
import static code.name.monkey.retromusic.Constants.RATE_ON_GOOGLE_PLAY;
import static code.name.monkey.retromusic.util.RetroUtil.openUrl;
import android.app.Activity; import android.app.Activity;
import android.app.ActivityOptions; import android.app.ActivityOptions;
import android.content.ActivityNotFoundException; import android.content.ActivityNotFoundException;
@ -21,13 +24,9 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.media.audiofx.AudioEffect; import android.media.audiofx.AudioEffect;
import android.widget.Toast; import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat; import androidx.core.app.ActivityCompat;
import org.jetbrains.annotations.NotNull;
import code.name.monkey.retromusic.R; import code.name.monkey.retromusic.R;
import code.name.monkey.retromusic.activities.AboutActivity; import code.name.monkey.retromusic.activities.AboutActivity;
import code.name.monkey.retromusic.activities.AlbumDetailsActivity; import code.name.monkey.retromusic.activities.AlbumDetailsActivity;
@ -47,13 +46,19 @@ import code.name.monkey.retromusic.activities.bugreport.BugReportActivity;
import code.name.monkey.retromusic.helper.MusicPlayerRemote; import code.name.monkey.retromusic.helper.MusicPlayerRemote;
import code.name.monkey.retromusic.model.Genre; import code.name.monkey.retromusic.model.Genre;
import code.name.monkey.retromusic.model.Playlist; import code.name.monkey.retromusic.model.Playlist;
import org.jetbrains.annotations.NotNull;
import static code.name.monkey.retromusic.Constants.RATE_ON_GOOGLE_PLAY;
import static code.name.monkey.retromusic.util.RetroUtil.openUrl;
public class NavigationUtil { public class NavigationUtil {
public static void bugReport(@NonNull Activity activity) {
ActivityCompat.startActivity(activity, new Intent(activity, BugReportActivity.class), null);
}
public static void goToAbout(@NonNull Activity activity) {
ActivityCompat.startActivity(activity, new Intent(activity, AboutActivity.class), null);
}
public static void goToAlbum(@NonNull Activity activity, int albumId) { public static void goToAlbum(@NonNull Activity activity, int albumId) {
Intent intent = new Intent(activity, AlbumDetailsActivity.class); Intent intent = new Intent(activity, AlbumDetailsActivity.class);
intent.putExtra(AlbumDetailsActivity.EXTRA_ALBUM_ID, albumId); intent.putExtra(AlbumDetailsActivity.EXTRA_ALBUM_ID, albumId);
@ -61,34 +66,93 @@ public class NavigationUtil {
} }
public static void goToAlbumOptions(@NonNull Activity activity, public static void goToAlbumOptions(@NonNull Activity activity,
int albumId, int albumId,
@NonNull ActivityOptions options) { @NonNull ActivityOptions options) {
Intent intent = new Intent(activity, AlbumDetailsActivity.class); Intent intent = new Intent(activity, AlbumDetailsActivity.class);
intent.putExtra(AlbumDetailsActivity.EXTRA_ALBUM_ID, albumId); intent.putExtra(AlbumDetailsActivity.EXTRA_ALBUM_ID, albumId);
ActivityCompat.startActivity(activity, intent, options.toBundle()); ActivityCompat.startActivity(activity, intent, options.toBundle());
} }
public static void goToArtistOptions(@NotNull AppCompatActivity activity,
int artistId,
@NonNull ActivityOptions options) {
Intent intent = new Intent(activity, ArtistDetailActivity.class);
intent.putExtra(ArtistDetailActivity.EXTRA_ARTIST_ID, artistId);
ActivityCompat.startActivity(activity, intent, options.toBundle());
}
public static void goToArtist(@NonNull Activity activity, int i) { public static void goToArtist(@NonNull Activity activity, int i) {
Intent intent = new Intent(activity, ArtistDetailActivity.class); Intent intent = new Intent(activity, ArtistDetailActivity.class);
intent.putExtra(ArtistDetailActivity.EXTRA_ARTIST_ID, i); intent.putExtra(ArtistDetailActivity.EXTRA_ARTIST_ID, i);
ActivityCompat.startActivity(activity, intent, null); ActivityCompat.startActivity(activity, intent, null);
} }
public static void goToArtistOptions(@NotNull AppCompatActivity activity,
int artistId,
@NonNull ActivityOptions options) {
Intent intent = new Intent(activity, ArtistDetailActivity.class);
intent.putExtra(ArtistDetailActivity.EXTRA_ARTIST_ID, artistId);
ActivityCompat.startActivity(activity, intent, options.toBundle());
}
public static void goToGenre(@NonNull Activity activity, @NonNull Genre genre) {
Intent intent = new Intent(activity, GenreDetailsActivity.class);
intent.putExtra(GenreDetailsActivity.EXTRA_GENRE_ID, genre);
ActivityCompat.startActivity(activity, intent, null);
}
public static void goToLyrics(@NonNull Activity activity) {
Intent intent = new Intent(activity, LyricsActivity.class);
ActivityCompat.startActivity(activity, intent, null);
}
public static void goToOpenSource(@NonNull Activity activity) {
ActivityCompat.startActivity(activity, new Intent(activity, LicenseActivity.class), null);
}
public static void goToPlayStore(@NonNull Activity activity) {
openUrl(activity, RATE_ON_GOOGLE_PLAY);
}
public static void goToPlayingQueue(@NonNull Activity activity) {
Intent intent = new Intent(activity, PlayingQueueActivity.class);
ActivityCompat.startActivity(activity, intent, null);
}
public static void goToPlaylistNew(@NonNull Activity activity, @NonNull Playlist playlist) { public static void goToPlaylistNew(@NonNull Activity activity, @NonNull Playlist playlist) {
Intent intent = new Intent(activity, PlaylistDetailActivity.class); Intent intent = new Intent(activity, PlaylistDetailActivity.class);
intent.putExtra(PlaylistDetailActivity.Companion.getEXTRA_PLAYLIST(), playlist); intent.putExtra(PlaylistDetailActivity.Companion.getEXTRA_PLAYLIST(), playlist);
ActivityCompat.startActivity(activity, intent, null); ActivityCompat.startActivity(activity, intent, null);
} }
public static void goToProVersion(@NonNull Context context) {
ActivityCompat.startActivity(context, new Intent(context, PurchaseActivity.class), null);
}
public static void goToSearch(@NonNull Activity activity,
@NonNull ActivityOptions activityOptions) {
ActivityCompat.startActivity(activity, new Intent(activity, SearchActivity.class),
activityOptions.toBundle());
}
public static void goToSearch(@NonNull Activity activity, boolean isMicOpen,
@NonNull ActivityOptions activityOptions) {
ActivityCompat.startActivity(activity, new Intent(activity, SearchActivity.class)
.putExtra(SearchActivity.EXTRA_SHOW_MIC, isMicOpen),
activityOptions.toBundle());
}
public static void goToSettings(@NonNull Activity activity) {
ActivityCompat.startActivity(activity, new Intent(activity, SettingsActivity.class), null);
}
public static void goToSupportDevelopment(@NonNull Activity activity) {
ActivityCompat.startActivity(activity, new Intent(activity, SupportDevelopmentActivity.class), null);
}
public static void goToUserInfo(@NonNull Activity activity,
@NonNull ActivityOptions activityOptions) {
ActivityCompat.startActivity(activity, new Intent(activity, UserInfoActivity.class),
activityOptions.toBundle());
}
public static void gotoWhatNews(@NonNull Activity activity) {
ActivityCompat.startActivity(activity, new Intent(activity, WhatsNewActivity.class), null);
}
public static void openEqualizer(@NonNull final Activity activity) { public static void openEqualizer(@NonNull final Activity activity) {
stockEqalizer(activity); stockEqalizer(activity);
} }
@ -111,72 +175,5 @@ public class NavigationUtil {
} }
} }
public static void goToPlayingQueue(@NonNull Activity activity) {
Intent intent = new Intent(activity, PlayingQueueActivity.class);
ActivityCompat.startActivity(activity, intent, null);
}
public static void goToLyrics(@NonNull Activity activity) {
Intent intent = new Intent(activity, LyricsActivity.class);
ActivityCompat.startActivity(activity, intent, null);
}
public static void goToGenre(@NonNull Activity activity, @NonNull Genre genre) {
Intent intent = new Intent(activity, GenreDetailsActivity.class);
intent.putExtra(GenreDetailsActivity.EXTRA_GENRE_ID, genre);
ActivityCompat.startActivity(activity, intent, null);
}
public static void goToProVersion(@NonNull Context context) {
ActivityCompat.startActivity(context, new Intent(context, PurchaseActivity.class), null);
}
public static void goToSettings(@NonNull Activity activity) {
ActivityCompat.startActivity(activity, new Intent(activity, SettingsActivity.class), null);
}
public static void goToAbout(@NonNull Activity activity) {
ActivityCompat.startActivity(activity, new Intent(activity, AboutActivity.class), null);
}
public static void goToUserInfo(@NonNull Activity activity,
@NonNull ActivityOptions activityOptions) {
ActivityCompat.startActivity(activity, new Intent(activity, UserInfoActivity.class),
activityOptions.toBundle());
}
public static void goToOpenSource(@NonNull Activity activity) {
ActivityCompat.startActivity(activity, new Intent(activity, LicenseActivity.class), null);
}
public static void goToSearch(@NonNull Activity activity,
@NonNull ActivityOptions activityOptions) {
ActivityCompat.startActivity(activity, new Intent(activity, SearchActivity.class),
activityOptions.toBundle());
}
public static void goToSearch(@NonNull Activity activity, boolean isMicOpen,
@NonNull ActivityOptions activityOptions) {
ActivityCompat.startActivity(activity, new Intent(activity, SearchActivity.class)
.putExtra(SearchActivity.EXTRA_SHOW_MIC, isMicOpen),
activityOptions.toBundle());
}
public static void goToSupportDevelopment(@NonNull Activity activity) {
ActivityCompat.startActivity(activity, new Intent(activity, SupportDevelopmentActivity.class), null);
}
public static void goToPlayStore(@NonNull Activity activity) {
openUrl(activity, RATE_ON_GOOGLE_PLAY);
}
public static void gotoWhatNews(@NonNull Activity activity) {
ActivityCompat.startActivity(activity, new Intent(activity, WhatsNewActivity.class), null);
}
public static void bugReport(@NonNull Activity activity) {
ActivityCompat.startActivity(activity, new Intent(activity, BugReportActivity.class), null);
}
} }

View file

@ -43,6 +43,7 @@
<com.google.android.material.card.MaterialCardView <com.google.android.material.card.MaterialCardView
android:id="@+id/albumCoverContainer"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_margin="16dp" android:layout_margin="16dp"

View file

@ -42,6 +42,7 @@
</FrameLayout> </FrameLayout>
<com.google.android.material.card.MaterialCardView <com.google.android.material.card.MaterialCardView
android:id="@+id/artistCoverContainer"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_margin="16dp" android:layout_margin="16dp"
@ -50,7 +51,7 @@
app:cardElevation="8dp"> app:cardElevation="8dp">
<androidx.appcompat.widget.AppCompatImageView <androidx.appcompat.widget.AppCompatImageView
android:id="@+id/artistImage" android:id="@+id/image"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:scaleType="centerCrop" android:scaleType="centerCrop"

View file

@ -14,7 +14,6 @@
android:scaleType="centerCrop" android:scaleType="centerCrop"
tools:srcCompat="@tools:sample/backgrounds/scenic[12]" /> tools:srcCompat="@tools:sample/backgrounds/scenic[12]" />
<com.google.android.material.appbar.AppBarLayout <com.google.android.material.appbar.AppBarLayout
android:id="@+id/appBarLayout" android:id="@+id/appBarLayout"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -89,6 +88,7 @@
android:layout_weight="0"> android:layout_weight="0">
<com.google.android.material.card.MaterialCardView <com.google.android.material.card.MaterialCardView
android:id="@+id/albumCoverContainer"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_margin="8dp" android:layout_margin="8dp"

View file

@ -7,7 +7,7 @@
android:layout_height="match_parent"> android:layout_height="match_parent">
<androidx.appcompat.widget.AppCompatImageView <androidx.appcompat.widget.AppCompatImageView
android:id="@+id/artistImage" android:id="@+id/image"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:scaleType="centerCrop" android:scaleType="centerCrop"

View file

@ -14,7 +14,6 @@
android:scaleType="centerCrop" android:scaleType="centerCrop"
tools:srcCompat="@tools:sample/backgrounds/scenic[15]" /> tools:srcCompat="@tools:sample/backgrounds/scenic[15]" />
<com.google.android.material.appbar.AppBarLayout <com.google.android.material.appbar.AppBarLayout
android:id="@+id/appBarLayout" android:id="@+id/appBarLayout"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -90,6 +89,7 @@
android:layout_weight="0"> android:layout_weight="0">
<com.google.android.material.card.MaterialCardView <com.google.android.material.card.MaterialCardView
android:id="@+id/albumCoverContainer"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_margin="8dp" android:layout_margin="8dp"
@ -134,11 +134,11 @@
android:focusable="true" android:focusable="true"
android:focusableInTouchMode="true" android:focusableInTouchMode="true"
android:freezesText="true" android:freezesText="true"
android:textColor="?android:attr/textColorSecondary"
android:marqueeRepeatLimit="marquee_forever" android:marqueeRepeatLimit="marquee_forever"
android:paddingTop="4dp" android:paddingTop="4dp"
android:scrollHorizontally="true" android:scrollHorizontally="true"
android:singleLine="true" android:singleLine="true"
android:textColor="?android:attr/textColorSecondary"
tools:ignore="MissingPrefix" tools:ignore="MissingPrefix"
tools:text="Album details" /> tools:text="Album details" />

View file

@ -7,7 +7,7 @@
android:layout_height="match_parent"> android:layout_height="match_parent">
<androidx.appcompat.widget.AppCompatImageView <androidx.appcompat.widget.AppCompatImageView
android:id="@+id/artistImage" android:id="@+id/image"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:scaleType="centerCrop" android:scaleType="centerCrop"

View file

@ -53,7 +53,7 @@
android:orientation="vertical"> android:orientation="vertical">
<code.name.monkey.retromusic.views.WidthFitSquareCardView <code.name.monkey.retromusic.views.WidthFitSquareCardView
android:id="@+id/albumCoverContainer" android:id="@+id/artistCoverContainer"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_margin="16dp" android:layout_margin="16dp"
@ -65,7 +65,7 @@
app:layout_constraintTop_toTopOf="parent"> app:layout_constraintTop_toTopOf="parent">
<androidx.appcompat.widget.AppCompatImageView <androidx.appcompat.widget.AppCompatImageView
android:id="@+id/artistImage" android:id="@+id/image"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:scaleType="centerCrop" android:scaleType="centerCrop"
@ -86,7 +86,7 @@
android:textStyle="bold" android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/albumCoverContainer" app:layout_constraintTop_toBottomOf="@id/artistCoverContainer"
tools:ignore="MissingPrefix" tools:ignore="MissingPrefix"
tools:text="Title" /> tools:text="Title" />

View file

@ -37,7 +37,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="center_vertical" android:gravity="center_vertical"
android:orientation="vertical" android:orientation="vertical"
android:padding="8dp" > android:padding="8dp">
<com.google.android.material.textview.MaterialTextView <com.google.android.material.textview.MaterialTextView
android:id="@+id/title" android:id="@+id/title"

View file

@ -55,7 +55,6 @@
android:id="@+id/imageText" android:id="@+id/imageText"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_height="match_parent"
android:gravity="center" android:gravity="center"
android:maxLines="1" android:maxLines="1"
android:minHeight="40dp" android:minHeight="40dp"