Smart playlist decoration (#619)
* Show smart playlist threshold and number of tracks in addition to the playlist title (#4) * Remove todo tags (#5) * Indentation * Code review
This commit is contained in:
parent
93bb9cf7fc
commit
e461f44ff0
9 changed files with 134 additions and 15 deletions
|
|
@ -83,6 +83,15 @@ public class PlaylistAdapter extends AbsMultiSelectAdapter<PlaylistAdapter.ViewH
|
|||
return new ViewHolder(view, viewType);
|
||||
}
|
||||
|
||||
protected String getPlaylistTitle(Playlist playlist) {
|
||||
return playlist.name;
|
||||
}
|
||||
|
||||
protected String getPlaylistText(Playlist playlist) {
|
||||
Context context = App.getInstance().getApplicationContext();
|
||||
return playlist.getInfoString(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
|
||||
final Playlist playlist = dataSet.get(position);
|
||||
|
|
@ -90,7 +99,10 @@ public class PlaylistAdapter extends AbsMultiSelectAdapter<PlaylistAdapter.ViewH
|
|||
holder.itemView.setActivated(isChecked(playlist));
|
||||
|
||||
if (holder.title != null) {
|
||||
holder.title.setText(playlist.name);
|
||||
holder.title.setText(getPlaylistTitle(playlist));
|
||||
}
|
||||
if (holder.text != null) {
|
||||
holder.text.setText(getPlaylistText(playlist));
|
||||
}
|
||||
|
||||
if (holder.getAdapterPosition() == getItemCount() - 1) {
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@ public class PlayingQueueAdapter extends SongAdapter implements DraggableItemAda
|
|||
if (holder.imageText != null) {
|
||||
holder.imageText.setText(String.valueOf(position - current));
|
||||
}
|
||||
|
||||
if (holder.getItemViewType() == HISTORY || holder.getItemViewType() == CURRENT) {
|
||||
setAlpha(holder, 0.5f);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ import android.content.Context;
|
|||
import android.os.Parcel;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.kabouzeid.gramophone.R;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
|
|
@ -11,6 +13,8 @@ import java.util.ArrayList;
|
|||
*/
|
||||
|
||||
public abstract class AbsCustomPlaylist extends Playlist {
|
||||
public static final String INFO_STRING_SEPARATOR = " • ";
|
||||
|
||||
public AbsCustomPlaylist(int id, String name) {
|
||||
super(id, name);
|
||||
}
|
||||
|
|
@ -24,4 +28,18 @@ public abstract class AbsCustomPlaylist extends Playlist {
|
|||
|
||||
@NonNull
|
||||
public abstract ArrayList<Song> getSongs(Context context);
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String getInfoString(@NonNull Context context) {
|
||||
String baseInfo = super.getInfoString(context);
|
||||
|
||||
int songCount = getSongs(context).size();
|
||||
String songCountText = (songCount == 0) ?
|
||||
context.getString(R.string.no_songs) :
|
||||
String.valueOf(songCount) + " " + context.getString(R.string.songs);
|
||||
|
||||
if (baseInfo.isEmpty()) {return songCountText;}
|
||||
return songCountText + INFO_STRING_SEPARATOR + baseInfo;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
package com.kabouzeid.gramophone.model;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
|
|
@ -20,6 +22,11 @@ public class Playlist implements Parcelable {
|
|||
this.name = "";
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public String getInfoString(@NonNull Context context) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
|
|
|
|||
|
|
@ -4,10 +4,11 @@ import android.content.Context;
|
|||
import android.os.Parcel;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.kabouzeid.gramophone.R;
|
||||
import com.kabouzeid.gramophone.loader.TopAndRecentlyPlayedTracksLoader;
|
||||
import com.kabouzeid.gramophone.model.Song;
|
||||
import com.kabouzeid.gramophone.provider.HistoryStore;
|
||||
import com.kabouzeid.gramophone.R;
|
||||
import com.kabouzeid.gramophone.util.PreferenceUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
|
@ -20,6 +21,16 @@ public class HistoryPlaylist extends AbsSmartPlaylist {
|
|||
super(context.getString(R.string.history), R.drawable.ic_access_time_white_24dp);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String getInfoString(@NonNull Context context) {
|
||||
String baseInfo = super.getInfoString(context);
|
||||
String cutoff = PreferenceUtil.getInstance(context).getRecentlyPlayedCutoffText(context);
|
||||
|
||||
if (baseInfo.isEmpty()) {return cutoff;}
|
||||
return cutoff + INFO_STRING_SEPARATOR + baseInfo;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public ArrayList<Song> getSongs(@NonNull Context context) {
|
||||
|
|
|
|||
|
|
@ -4,9 +4,10 @@ import android.content.Context;
|
|||
import android.os.Parcel;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.kabouzeid.gramophone.R;
|
||||
import com.kabouzeid.gramophone.loader.LastAddedLoader;
|
||||
import com.kabouzeid.gramophone.model.Song;
|
||||
import com.kabouzeid.gramophone.R;
|
||||
import com.kabouzeid.gramophone.util.PreferenceUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
|
@ -19,6 +20,16 @@ public class LastAddedPlaylist extends AbsSmartPlaylist {
|
|||
super(context.getString(R.string.last_added), R.drawable.ic_library_add_white_24dp);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String getInfoString(@NonNull Context context) {
|
||||
String baseInfo = super.getInfoString(context);
|
||||
String cutoff = PreferenceUtil.getInstance(context).getLastAddedCutoffText(context);
|
||||
|
||||
if (baseInfo.isEmpty()) {return cutoff;}
|
||||
return cutoff + INFO_STRING_SEPARATOR + baseInfo;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public ArrayList<Song> getSongs(@NonNull Context context) {
|
||||
|
|
|
|||
|
|
@ -4,10 +4,11 @@ import android.content.Context;
|
|||
import android.os.Parcel;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.kabouzeid.gramophone.R;
|
||||
import com.kabouzeid.gramophone.loader.TopAndRecentlyPlayedTracksLoader;
|
||||
import com.kabouzeid.gramophone.model.Song;
|
||||
import com.kabouzeid.gramophone.provider.HistoryStore;
|
||||
import com.kabouzeid.gramophone.R;
|
||||
import com.kabouzeid.gramophone.util.PreferenceUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
|
@ -20,6 +21,16 @@ public class NotRecentlyPlayedPlaylist extends AbsSmartPlaylist {
|
|||
super(context.getString(R.string.not_recently_played), R.drawable.ic_watch_later_white_24dp);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String getInfoString(@NonNull Context context) {
|
||||
String baseInfo = super.getInfoString(context);
|
||||
String cutoff = PreferenceUtil.getInstance(context).getRecentlyPlayedCutoffText(context);
|
||||
|
||||
if (baseInfo.isEmpty()) {return cutoff;}
|
||||
return cutoff + INFO_STRING_SEPARATOR + baseInfo;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public ArrayList<Song> getSongs(@NonNull Context context) {
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import android.support.annotation.StyleRes;
|
|||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
import com.kabouzeid.gramophone.R;
|
||||
import com.kabouzeid.gramophone.helper.SortOrder;
|
||||
import com.kabouzeid.gramophone.model.CategoryInfo;
|
||||
|
|
@ -311,6 +312,37 @@ public final class PreferenceUtil {
|
|||
return (System.currentTimeMillis() - interval);
|
||||
}
|
||||
|
||||
public String getLastAddedCutoffText(Context context) {
|
||||
return getCutoffText(LAST_ADDED_CUTOFF, context);
|
||||
}
|
||||
|
||||
public String getRecentlyPlayedCutoffText(Context context) {
|
||||
return getCutoffText(LAST_PLAYED_CUTOFF, context);
|
||||
}
|
||||
|
||||
private String getCutoffText(final String cutoff, Context context) {
|
||||
switch (mPreferences.getString(cutoff, "")) {
|
||||
case "today":
|
||||
return context.getString(R.string.today);
|
||||
|
||||
case "this_week":
|
||||
return context.getString(R.string.this_week);
|
||||
|
||||
case "past_seven_days":
|
||||
return context.getString(R.string.past_seven_days);
|
||||
|
||||
case "past_three_months":
|
||||
return context.getString(R.string.past_three_months);
|
||||
|
||||
case "this_year":
|
||||
return context.getString(R.string.this_year);
|
||||
|
||||
case "this_month":
|
||||
default:
|
||||
return context.getString(R.string.this_month);
|
||||
}
|
||||
}
|
||||
|
||||
public int getLastSleepTimerValue() {
|
||||
return mPreferences.getInt(LAST_SLEEP_TIMER_VALUE, 30);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,20 +54,36 @@
|
|||
|
||||
</FrameLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_marginLeft="16dp"
|
||||
android:layout_marginRight="16dp"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_gravity="center"
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical"
|
||||
android:paddingEnd="0dp"
|
||||
android:paddingLeft="16dp"
|
||||
android:paddingRight="0dp"
|
||||
android:paddingStart="16dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:fontFamily="sans-serif"
|
||||
android:singleLine="true"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Subhead" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:fontFamily="sans-serif"
|
||||
android:singleLine="true"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
|
||||
android:textColor="?android:textColorSecondary" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<com.kabouzeid.gramophone.views.IconImageView
|
||||
android:id="@+id/menu"
|
||||
style="@style/OverFlowButton"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue