Refactor
This commit is contained in:
parent
d573be0a39
commit
63c417cd61
26 changed files with 235 additions and 268 deletions
|
@ -2,14 +2,14 @@ package code.name.monkey.retromusic.model;
|
|||
|
||||
import android.content.Context;
|
||||
import android.os.Parcel;
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import code.name.monkey.models.Song;
|
||||
import io.reactivex.Observable;
|
||||
|
||||
|
||||
|
||||
public abstract class AbsCustomPlaylist extends Playlist {
|
||||
public AbsCustomPlaylist(int id, String name) {
|
||||
super(id, name);
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package code.name.monkey.retromusic.model
|
||||
package code.name.monkey.models
|
||||
|
||||
import java.util.*
|
||||
|
||||
|
||||
class Album {
|
||||
val songs: ArrayList<Song>?
|
||||
val songs: ArrayList<code.name.monkey.models.Song>?
|
||||
|
||||
val id: Int
|
||||
get() = safeGetFirstSong().albumId
|
||||
|
@ -27,7 +27,7 @@ class Album {
|
|||
val songCount: Int
|
||||
get() = songs!!.size
|
||||
|
||||
constructor(songs: ArrayList<Song>) {
|
||||
constructor(songs: ArrayList<code.name.monkey.models.Song>) {
|
||||
this.songs = songs
|
||||
}
|
||||
|
||||
|
@ -35,7 +35,7 @@ class Album {
|
|||
this.songs = ArrayList()
|
||||
}
|
||||
|
||||
fun safeGetFirstSong(): Song {
|
||||
return if (songs!!.isEmpty()) Song.EMPTY_SONG else songs[0]
|
||||
fun safeGetFirstSong(): code.name.monkey.models.Song {
|
||||
return if (songs!!.isEmpty()) code.name.monkey.models.Song.EMPTY_SONG else songs[0]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,9 +30,9 @@ class Artist {
|
|||
val albumCount: Int
|
||||
get() = albums!!.size
|
||||
|
||||
val songs: ArrayList<Song>
|
||||
val songs: ArrayList<code.name.monkey.models.Song>
|
||||
get() {
|
||||
val songs = ArrayList<Song>()
|
||||
val songs = ArrayList<code.name.monkey.models.Song>()
|
||||
for (album in albums!!) {
|
||||
songs.addAll(album.songs!!)
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package code.name.monkey.retromusic.model;
|
||||
package code.name.monkey.models;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
|
|
@ -2,6 +2,8 @@ package code.name.monkey.retromusic.model;
|
|||
|
||||
import android.os.Parcel;
|
||||
|
||||
import code.name.monkey.models.Song;
|
||||
|
||||
public class PlaylistSong extends Song {
|
||||
public static PlaylistSong EMPTY_PLAYLIST_SONG = new PlaylistSong(-1, "", -1, -1, -1, "", -1, -1, "", -1, "", -1, -1);
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package code.name.monkey.retromusic.model.lyrics;
|
||||
package code.name.monkey.models.lyrics;
|
||||
|
||||
|
||||
import code.name.monkey.retromusic.model.Song;
|
||||
import code.name.monkey.models.Song;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package code.name.monkey.retromusic.model.smartplaylist;
|
||||
package code.name.monkey.models.smartplaylist;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Parcel;
|
||||
|
|
|
@ -7,9 +7,10 @@ import androidx.annotation.NonNull;
|
|||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import code.name.monkey.models.Song;
|
||||
import code.name.monkey.retromusic.R;
|
||||
import code.name.monkey.retromusic.loaders.TopAndRecentlyPlayedTracksLoader;
|
||||
import code.name.monkey.retromusic.model.Song;
|
||||
|
||||
import code.name.monkey.retromusic.providers.HistoryStore;
|
||||
import io.reactivex.Observable;
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ import androidx.annotation.NonNull;
|
|||
|
||||
import code.name.monkey.retromusic.R;
|
||||
import code.name.monkey.retromusic.loaders.LastAddedSongsLoader;
|
||||
import code.name.monkey.retromusic.model.Song;
|
||||
import code.name.monkey.models.Song;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ import androidx.annotation.NonNull;
|
|||
|
||||
import code.name.monkey.retromusic.R;
|
||||
import code.name.monkey.retromusic.loaders.TopAndRecentlyPlayedTracksLoader;
|
||||
import code.name.monkey.retromusic.model.Song;
|
||||
import code.name.monkey.models.Song;
|
||||
import code.name.monkey.retromusic.providers.SongPlayCountStore;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
|
|
@ -8,7 +8,7 @@ import androidx.annotation.NonNull;
|
|||
|
||||
import code.name.monkey.retromusic.R;
|
||||
import code.name.monkey.retromusic.loaders.SongLoader;
|
||||
import code.name.monkey.retromusic.model.Song;
|
||||
import code.name.monkey.models.Song;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
|
|
@ -1,96 +0,0 @@
|
|||
package code.name.monkey.retromusic.util;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.animation.ArgbEvaluator;
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Color;
|
||||
import android.os.Build;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.animation.PathInterpolator;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.ColorInt;
|
||||
import androidx.core.view.ViewCompat;
|
||||
|
||||
import com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import code.name.monkey.appthemehelper.util.ColorUtil;
|
||||
import code.name.monkey.appthemehelper.util.MaterialValueHelper;
|
||||
|
||||
public class ViewUtil {
|
||||
|
||||
public final static int RETRO_MUSIC_ANIM_TIME = 1000;
|
||||
|
||||
public static Animator createTextColorTransition(final TextView v, @ColorInt final int startColor, @ColorInt final int endColor) {
|
||||
return createColorAnimator(v, "textColor", startColor, endColor);
|
||||
}
|
||||
|
||||
private static Animator createColorAnimator(Object target, String propertyName, @ColorInt int startColor, @ColorInt int endColor) {
|
||||
ObjectAnimator animator;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
animator = ObjectAnimator.ofArgb(target, propertyName, startColor, endColor);
|
||||
} else {
|
||||
animator = ObjectAnimator.ofInt(target, propertyName, startColor, endColor);
|
||||
animator.setEvaluator(new ArgbEvaluator());
|
||||
}
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
animator.setInterpolator(new PathInterpolator(0.4f, 0f, 1f, 1f));
|
||||
}
|
||||
animator.setDuration(RETRO_MUSIC_ANIM_TIME);
|
||||
return animator;
|
||||
}
|
||||
|
||||
public static void setStatusBarHeight(final Context context, View statusBar) {
|
||||
ViewGroup.LayoutParams lp = statusBar.getLayoutParams();
|
||||
lp.height = getStatusBarHeight(context);
|
||||
statusBar.requestLayout();
|
||||
}
|
||||
|
||||
public static int getStatusBarHeight(final Context context) {
|
||||
int result = 0;
|
||||
int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
|
||||
if (resourceId > 0) {
|
||||
result = context.getResources().getDimensionPixelSize(resourceId);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static boolean hitTest(View v, int x, int y) {
|
||||
final int tx = (int) (ViewCompat.getTranslationX(v) + 0.5f);
|
||||
final int ty = (int) (ViewCompat.getTranslationY(v) + 0.5f);
|
||||
final int left = v.getLeft() + tx;
|
||||
final int right = v.getRight() + tx;
|
||||
final int top = v.getTop() + ty;
|
||||
final int bottom = v.getBottom() + ty;
|
||||
|
||||
return (x >= left) && (x <= right) && (y >= top) && (y <= bottom);
|
||||
}
|
||||
|
||||
public static void setUpFastScrollRecyclerViewColor(Context context,
|
||||
FastScrollRecyclerView recyclerView, int accentColor) {
|
||||
recyclerView.setPopupBgColor(accentColor);
|
||||
recyclerView.setPopupTextColor(
|
||||
MaterialValueHelper.INSTANCE.getPrimaryTextColor(context, ColorUtil.INSTANCE.isColorLight(accentColor)));
|
||||
recyclerView.setThumbColor(accentColor);
|
||||
recyclerView.setTrackColor(Color.TRANSPARENT);
|
||||
//recyclerView.setTrackColor(ColorUtil.withAlpha(ATHUtil.resolveColor(context, R.attr.colorControlNormal), 0.12f));
|
||||
}
|
||||
|
||||
public static float convertDpToPixel(float dp, Resources resources) {
|
||||
DisplayMetrics metrics = resources.getDisplayMetrics();
|
||||
return dp * metrics.density;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Animator createBackgroundColorTransition(@Nullable View colorGradientBackground, int lastColor, int newColor) {
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,96 @@
|
|||
package code.name.monkey.retromusic.util
|
||||
|
||||
import android.animation.Animator
|
||||
import android.animation.ArgbEvaluator
|
||||
import android.animation.ObjectAnimator
|
||||
import android.content.Context
|
||||
import android.content.res.Resources
|
||||
import android.graphics.Color
|
||||
import android.graphics.PorterDuff
|
||||
import android.os.Build
|
||||
import android.util.DisplayMetrics
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.animation.PathInterpolator
|
||||
import android.widget.SeekBar
|
||||
import android.widget.TextView
|
||||
|
||||
import com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView
|
||||
|
||||
import androidx.annotation.ColorInt
|
||||
import androidx.core.view.ViewCompat
|
||||
import code.name.monkey.appthemehelper.ThemeStore
|
||||
import code.name.monkey.appthemehelper.util.ColorUtil
|
||||
import code.name.monkey.appthemehelper.util.MaterialValueHelper
|
||||
|
||||
object ViewUtil {
|
||||
|
||||
val RETRO_MUSIC_ANIM_TIME = 1000
|
||||
|
||||
fun createTextColorTransition(v: TextView, @ColorInt startColor: Int, @ColorInt endColor: Int): Animator {
|
||||
return createColorAnimator(v, "textColor", startColor, endColor)
|
||||
}
|
||||
|
||||
fun setProgressDrawable(progressSlider: SeekBar, newColor: Int) {}
|
||||
|
||||
private fun createColorAnimator(target: Any, propertyName: String, @ColorInt startColor: Int, @ColorInt endColor: Int): Animator {
|
||||
val animator: ObjectAnimator
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
animator = ObjectAnimator.ofArgb(target, propertyName, startColor, endColor)
|
||||
} else {
|
||||
animator = ObjectAnimator.ofInt(target, propertyName, startColor, endColor)
|
||||
animator.setEvaluator(ArgbEvaluator())
|
||||
}
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
animator.interpolator = PathInterpolator(0.4f, 0f, 1f, 1f)
|
||||
}
|
||||
animator.duration = RETRO_MUSIC_ANIM_TIME.toLong()
|
||||
return animator
|
||||
}
|
||||
|
||||
fun setStatusBarHeight(context: Context, statusBar: View) {
|
||||
val lp = statusBar.layoutParams
|
||||
lp.height = getStatusBarHeight(context)
|
||||
statusBar.requestLayout()
|
||||
}
|
||||
|
||||
fun getStatusBarHeight(context: Context): Int {
|
||||
var result = 0
|
||||
val resourceId = context.resources.getIdentifier("status_bar_height", "dimen", "android")
|
||||
if (resourceId > 0) {
|
||||
result = context.resources.getDimensionPixelSize(resourceId)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
fun hitTest(v: View, x: Int, y: Int): Boolean {
|
||||
val tx = (ViewCompat.getTranslationX(v) + 0.5f).toInt()
|
||||
val ty = (ViewCompat.getTranslationY(v) + 0.5f).toInt()
|
||||
val left = v.left + tx
|
||||
val right = v.right + tx
|
||||
val top = v.top + ty
|
||||
val bottom = v.bottom + ty
|
||||
|
||||
return x >= left && x <= right && y >= top && y <= bottom
|
||||
}
|
||||
|
||||
fun setUpFastScrollRecyclerViewColor(context: Context,
|
||||
recyclerView: FastScrollRecyclerView, accentColor: Int) {
|
||||
recyclerView.setPopupBgColor(accentColor)
|
||||
recyclerView.setPopupTextColor(
|
||||
MaterialValueHelper.getPrimaryTextColor(context, ColorUtil.isColorLight(accentColor)))
|
||||
recyclerView.setThumbColor(accentColor)
|
||||
recyclerView.setTrackColor(Color.TRANSPARENT)
|
||||
//recyclerView.setTrackColor(ColorUtil.withAlpha(ATHUtil.resolveColor(context, R.attr.colorControlNormal), 0.12f));
|
||||
}
|
||||
|
||||
fun convertDpToPixel(dp: Float, resources: Resources): Float {
|
||||
val metrics = resources.displayMetrics
|
||||
return dp * metrics.density
|
||||
}
|
||||
|
||||
fun createBackgroundColorTransition(colorGradientBackground: View?, lastColor: Int, newColor: Int): Animator {
|
||||
return null
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue