Code refactor

1. Chaning Home Album sections from MetalAdapter to Normal
2. Adding animation icons
3. Removed cardElevation 0dp
This commit is contained in:
Hemanth S 2020-07-18 02:55:04 +05:30
parent 768ab295b0
commit 76331eae7d
55 changed files with 490 additions and 815 deletions

View file

@ -0,0 +1,46 @@
package code.name.monkey.retromusic
import android.content.Context
import android.util.AttributeSet
import android.view.ViewGroup
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
class PeekingLinearLayoutManager : LinearLayoutManager {
@JvmOverloads
constructor(
context: Context?,
@RecyclerView.Orientation orientation: Int = RecyclerView.VERTICAL,
reverseLayout: Boolean = false
) : super(context, orientation, reverseLayout)
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int, defStyleRes: Int) : super(
context,
attrs,
defStyleAttr,
defStyleRes
)
override fun generateDefaultLayoutParams() =
scaledLayoutParams(super.generateDefaultLayoutParams())
override fun generateLayoutParams(lp: ViewGroup.LayoutParams?) =
scaledLayoutParams(super.generateLayoutParams(lp))
override fun generateLayoutParams(c: Context?, attrs: AttributeSet?) =
scaledLayoutParams(super.generateLayoutParams(c, attrs))
private fun scaledLayoutParams(layoutParams: RecyclerView.LayoutParams) =
layoutParams.apply {
when (orientation) {
HORIZONTAL -> width = (horizontalSpace * ratio).toInt()
VERTICAL -> height = (verticalSpace * ratio).toInt()
}
}
private val horizontalSpace get() = width - paddingStart - paddingEnd
private val verticalSpace get() = height - paddingTop - paddingBottom
private val ratio = 0.8f // change to 0.7f for 70%
}

View file

@ -11,9 +11,12 @@ import androidx.appcompat.widget.AppCompatTextView
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.RecyclerView.HORIZONTAL
import code.name.monkey.appthemehelper.ThemeStore
import code.name.monkey.appthemehelper.util.ColorUtil
import code.name.monkey.retromusic.PeekingLinearLayoutManager
import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.adapter.album.AlbumFullWidthAdapter
import code.name.monkey.retromusic.adapter.album.AlbumAdapter
import code.name.monkey.retromusic.adapter.artist.ArtistAdapter
import code.name.monkey.retromusic.adapter.song.SongAdapter
import code.name.monkey.retromusic.extensions.show
@ -23,6 +26,7 @@ import code.name.monkey.retromusic.loaders.PlaylistSongsLoader
import code.name.monkey.retromusic.model.*
import code.name.monkey.retromusic.util.PreferenceUtil
import com.bumptech.glide.Glide
import com.google.android.material.card.MaterialCardView
class HomeAdapter(
private val activity: AppCompatActivity,
@ -40,8 +44,14 @@ class HomeAdapter(
.inflate(R.layout.section_recycler_view, parent, false)
return when (viewType) {
RECENT_ARTISTS, TOP_ARTISTS -> ArtistViewHolder(layout)
TOP_ALBUMS, RECENT_ALBUMS -> {
AlbumViewHolder(
LayoutInflater.from(activity)
.inflate(R.layout.metal_section_recycler_view, parent, false)
)
}
FAVOURITES -> PlaylistViewHolder(layout)
SUGGESTIONS -> {
else -> {
SuggestionsViewHolder(
LayoutInflater.from(activity).inflate(
R.layout.item_suggestions,
@ -50,15 +60,6 @@ class HomeAdapter(
)
)
}
else -> {
AlbumViewHolder(
LayoutInflater.from(activity).inflate(
R.layout.metal_section_recycler_view,
parent,
false
)
)
}
}
}
@ -133,7 +134,9 @@ class HomeAdapter(
if (list.isNotEmpty()) {
recyclerView.apply {
show()
adapter = AlbumFullWidthAdapter(activity, list, displayMetrics)
adapter = AlbumAdapter(activity, list, R.layout.pager_item, null)
layoutManager =
PeekingLinearLayoutManager(activity, HORIZONTAL, false)
}
title.text = activity.getString(titleRes)
}
@ -175,17 +178,20 @@ class HomeAdapter(
fun bindView(arrayList: List<Song>) {
val color = ThemeStore.accentColor(activity)
itemView.findViewById<TextView>(R.id.text).setTextColor(color)
images.forEachIndexed { index, i ->
itemView.findViewById<View>(i).setOnClickListener {
MusicPlayerRemote.playNext(arrayList[index])
}
SongGlideRequest.Builder.from(Glide.with(activity), arrayList[index])
.asBitmap()
.build()
.into(itemView.findViewById(i))
itemView.findViewById<MaterialCardView>(R.id.card6).apply {
setCardBackgroundColor(ColorUtil.withAlpha(color, 0.2f))
}
if (arrayList.size > 9)
images.forEachIndexed { index, i ->
itemView.findViewById<View>(i).setOnClickListener {
MusicPlayerRemote.playNext(arrayList[index])
}
SongGlideRequest.Builder.from(Glide.with(activity), arrayList[index])
.asBitmap()
.build()
.into(itemView.findViewById(i))
}
}
}

View file

@ -1,108 +0,0 @@
/*
* Copyright (C) 2017. Alexander Bilchuk <a.bilchuk@sandrlab.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package code.name.monkey.retromusic.adapter.album
import android.app.Activity
import android.app.ActivityOptions
import android.util.DisplayMetrics
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.glide.AlbumGlideRequest
import code.name.monkey.retromusic.glide.RetroMusicColoredTarget
import code.name.monkey.retromusic.helper.MusicPlayerRemote
import code.name.monkey.retromusic.model.Album
import code.name.monkey.retromusic.util.NavigationUtil
import code.name.monkey.retromusic.util.color.MediaNotificationProcessor
import code.name.monkey.retromusic.views.MetalRecyclerViewPager
import com.bumptech.glide.Glide
class AlbumFullWidthAdapter(
private val activity: Activity,
private val dataSet: List<Album>,
metrics: DisplayMetrics
) : MetalRecyclerViewPager.MetalAdapter<AlbumFullWidthAdapter.FullMetalViewHolder>(metrics) {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): FullMetalViewHolder {
return FullMetalViewHolder(
LayoutInflater.from(parent.context).inflate(
R.layout.pager_item,
parent,
false
)
)
}
override fun onBindViewHolder(holder: FullMetalViewHolder, position: Int) {
// don't forget about calling supper.onBindViewHolder!
super.onBindViewHolder(holder, position)
val album = dataSet[position]
holder.title?.text = getAlbumTitle(album)
holder.text?.text = getAlbumText(album)
holder.playSongs?.setOnClickListener {
album.songs?.let { songs ->
MusicPlayerRemote.openQueue(
songs,
0,
true
)
}
}
loadAlbumCover(album, holder)
}
private fun getAlbumTitle(album: Album): String? {
return album.title
}
private fun getAlbumText(album: Album): String? {
return album.artistName
}
private fun loadAlbumCover(album: Album, holder: FullMetalViewHolder) {
if (holder.image == null) {
return
}
AlbumGlideRequest.Builder.from(Glide.with(activity), album.safeGetFirstSong())
.checkIgnoreMediaStore(activity)
.generatePalette(activity)
.build()
.into(object : RetroMusicColoredTarget(holder.image!!) {
override fun onColorReady(colors: MediaNotificationProcessor) {
}
})
}
override fun getItemCount(): Int {
return dataSet.size
}
inner class FullMetalViewHolder(itemView: View) :
MetalRecyclerViewPager.MetalViewHolder(itemView) {
override fun onClick(v: View?) {
val activityOptions = ActivityOptions.makeSceneTransitionAnimation(
activity,
imageContainerCard ?: image,
activity.getString(R.string.transition_album_art)
)
NavigationUtil.goToAlbumOptions(activity, dataSet[layoutPosition].id, activityOptions)
}
}
}

View file

@ -61,8 +61,7 @@ open class MiniPlayerFragment : AbsMusicServiceFragment(), MusicProgressViewUpda
actionPrevious?.show()
} else {
actionNext.visibility =
if (PreferenceUtil.isExtraControls) View.VISIBLE else View.GONE
actionNext.visibility = if (PreferenceUtil.isExtraControls) View.VISIBLE else View.GONE
actionPrevious.visibility =
if (PreferenceUtil.isExtraControls) View.VISIBLE else View.GONE
}

View file

@ -59,9 +59,9 @@ public class CategoryInfo implements Parcelable {
}
public enum Category {
Home(R.id.action_home, R.string.home, R.drawable.ic_home_white_24dp),
Songs(R.id.action_song, R.string.songs, R.drawable.ic_audiotrack_white_24dp),
Albums(R.id.action_album, R.string.albums, R.drawable.ic_album_white_24dp),
Home(R.id.action_home, R.string.home, R.drawable.asld_home),
Songs(R.id.action_song, R.string.songs, R.drawable.asld_music_note),
Albums(R.id.action_album, R.string.albums, R.drawable.asld_album),
Artists(R.id.action_artist, R.string.artists, R.drawable.ic_artist_white_24dp),
Playlists(R.id.action_playlist, R.string.playlists, R.drawable.ic_playlist_play_white_24dp),
Genres(R.id.action_genre, R.string.genres, R.drawable.ic_guitar_white_24dp),

View file

@ -43,7 +43,9 @@ class RepositoryImpl constructor(private val context: Context) : Repository {
ArtistLoader.getArtist(context, artistId)
override suspend fun suggestions(): Home? {
val songs = NotRecentlyPlayedPlaylist(context).getSongs(context).shuffled().subList(0, 9)
val songs = NotRecentlyPlayedPlaylist(context).getSongs(context).shuffled().apply {
if (size > 9) subList(0, 9)
}
if (songs.isNotEmpty()) {
return Home(
songs,

View file

@ -1,39 +0,0 @@
/*
* Copyright (c) 2019 Hemanth Savarala.
*
* Licensed under the GNU General Public License v3
*
* This is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by
* the Free Software Foundation either version 3 of the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*/
package code.name.monkey.retromusic.util;
import android.app.Activity;
import android.content.Context;
import android.util.DisplayMetrics;
import androidx.annotation.NonNull;
/**
* Created by hefuyi on 16/7/30.
*/
public class DensityUtil {
public static int getScreenHeight(@NonNull Context context) {
DisplayMetrics displayMetrics = new DisplayMetrics();
((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
return displayMetrics.heightPixels;
}
public static int dip2px(@NonNull Context context, float dpVale) {
final float scale = context.getResources().getDisplayMetrics().density;
return (int) (dpVale * scale + 0.5f);
}
}

View file

@ -0,0 +1,49 @@
/*
* Copyright (c) 2019 Hemanth Savarala.
*
* Licensed under the GNU General Public License v3
*
* This is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by
* the Free Software Foundation either version 3 of the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*/
package code.name.monkey.retromusic.util
import android.app.Activity
import android.content.Context
import android.util.DisplayMetrics
import android.util.TypedValue
/**
* Created by hefuyi on 16/7/30.
*/
object DensityUtil {
fun getScreenHeight(context: Context): Int {
val displayMetrics = DisplayMetrics()
(context as Activity).windowManager.defaultDisplay.getMetrics(displayMetrics)
return displayMetrics.heightPixels
}
fun getScreenWidth(context: Context): Int {
val displayMetrics = DisplayMetrics()
(context as Activity).windowManager.defaultDisplay.getMetrics(displayMetrics)
return displayMetrics.widthPixels
}
private fun toDP(context: Context, value: Int): Int {
return TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP,
value.toFloat(), context.resources.displayMetrics
).toInt()
}
@JvmStatic
fun dip2px(context: Context, dpVale: Float): Int {
val scale = context.resources.displayMetrics.density
return (dpVale * scale + 0.5f).toInt()
}
}

View file

@ -78,7 +78,8 @@ object ViewUtil {
}
fun setProgressDrawable(progressIndicator: ProgressIndicator, newColor: Int) {
progressIndicator.progressTintList = ColorStateList.valueOf(newColor)
progressIndicator.indicatorColors = intArrayOf(newColor)
progressIndicator.trackColor = ColorUtil.withAlpha(newColor, 0.2f)
}
fun hitTest(v: View, x: Int, y: Int): Boolean {

View file

@ -1,108 +0,0 @@
/*
* Copyright (c) 2019 Hemanth Savarala.
*
* Licensed under the GNU General Public License v3
*
* This is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by
* the Free Software Foundation either version 3 of the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*/
package code.name.monkey.retromusic.views
import android.content.Context
import android.util.AttributeSet
import android.util.DisplayMetrics
import android.view.View
import android.view.ViewGroup
import androidx.annotation.NonNull
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.PagerSnapHelper
import androidx.recyclerview.widget.RecyclerView
import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.adapter.base.MediaEntryViewHolder
import code.name.monkey.retromusic.util.RetroUtil
class MetalRecyclerViewPager : RecyclerView {
constructor(context: Context) : super(context) {
init(context, null)
}
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) {
init(context, attrs)
}
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(
context,
attrs,
defStyleAttr
) {
init(context, attrs)
}
private var itemMargin: Int = 0
fun init(context: Context, attrs: AttributeSet?) {
val typedArray =
context.obtainStyledAttributes(attrs, R.styleable.MetalRecyclerViewPager, 0, 0)
itemMargin =
typedArray.getDimension(R.styleable.MetalRecyclerViewPager_itemMargin, 0f).toInt()
typedArray.recycle()
layoutManager = LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)
val snapHelper = PagerSnapHelper()
snapHelper.attachToRecyclerView(this)
}
override fun setAdapter(adapter: Adapter<*>?) {
if (adapter is MetalAdapter) {
adapter.setItemMargin(itemMargin)
adapter.updateDisplayMetrics()
} else {
throw IllegalArgumentException("Only MetalAdapter is allowed here")
}
super.setAdapter(adapter)
}
abstract class MetalAdapter<VH : MetalViewHolder>(@NonNull val displayMetrics: DisplayMetrics) :
RecyclerView.Adapter<VH>() {
private var itemMargin: Int = 0
private var itemWidth: Int = 0
fun setItemMargin(itemMargin: Int) {
this.itemMargin = itemMargin
}
fun updateDisplayMetrics() {
itemWidth = if (RetroUtil.isTablet()) {
displayMetrics.widthPixels / 2 - itemMargin * 3
} else if (RetroUtil.isLandscape()) {
((displayMetrics.widthPixels / 2.5f) - itemMargin).toInt()
} else {
displayMetrics.widthPixels - itemMargin
}
}
override fun onBindViewHolder(holder: VH, position: Int) {
val currentItemWidth = itemWidth
if (position == 0) {
//currentItemWidth += itemMargin;
holder.rootLayout.setPadding(0, 0, 0, 0);
} else if (position == itemCount - 1) {
//currentItemWidth += itemMargin;
holder.rootLayout.setPadding(0, 0, 0, 0);
}
val height = holder.rootLayout.layoutParams.height
holder.rootLayout.layoutParams = ViewGroup.LayoutParams(currentItemWidth, height)
}
}
abstract class MetalViewHolder(itemView: View) : MediaEntryViewHolder(itemView) {
var rootLayout: ViewGroup = itemView.findViewById(R.id.root_layout)
}
}

View file

@ -405,7 +405,7 @@ public class SeekArc extends View {
thumbHalfheight);
mMax = a.getInteger(R.styleable.SeekArc_max, mMax);
mProgress = a.getInteger(R.styleable.SeekArc_progress, mProgress);
mProgress = a.getInteger(R.styleable.SeekArc_seekProgress, mProgress);
mProgressWidth = (int) a.getDimension(
R.styleable.SeekArc_progressWidth, mProgressWidth);
mArcWidth = (int) a.getDimension(R.styleable.SeekArc_arcWidth,