From 2a625f25ff7eef0f900ca3eacfe8935dcf8d8bde Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Mon, 22 Feb 2016 17:19:18 -0800 Subject: #417 Add listened status indicator for Podcasts/Audio Books --- .../daneren2005/dsub/util/SongDBHandler.java | 8 +++++ .../github/daneren2005/dsub/view/SongView.java | 36 +++++++++++++++++---- .../main/res/drawable-hdpi/ic_toggle_played.png | Bin 0 -> 1064 bytes .../main/res/drawable-mdpi/ic_toggle_played.png | Bin 0 -> 579 bytes .../main/res/drawable-xhdpi/ic_toggle_played.png | Bin 0 -> 1341 bytes .../main/res/drawable-xxhdpi/ic_toggle_played.png | Bin 0 -> 2552 bytes .../main/res/drawable-xxxhdpi/ic_toggle_played.png | Bin 0 -> 3715 bytes app/src/main/res/layout/song_list_item.xml | 18 ++++++++--- app/src/main/res/values/dimens.xml | 1 + 9 files changed, 53 insertions(+), 10 deletions(-) create mode 100644 app/src/main/res/drawable-hdpi/ic_toggle_played.png create mode 100644 app/src/main/res/drawable-mdpi/ic_toggle_played.png create mode 100644 app/src/main/res/drawable-xhdpi/ic_toggle_played.png create mode 100644 app/src/main/res/drawable-xxhdpi/ic_toggle_played.png create mode 100644 app/src/main/res/drawable-xxxhdpi/ic_toggle_played.png (limited to 'app') diff --git a/app/src/main/java/github/daneren2005/dsub/util/SongDBHandler.java b/app/src/main/java/github/daneren2005/dsub/util/SongDBHandler.java index 8d91a251..859c32dd 100644 --- a/app/src/main/java/github/daneren2005/dsub/util/SongDBHandler.java +++ b/app/src/main/java/github/daneren2005/dsub/util/SongDBHandler.java @@ -150,6 +150,14 @@ public class SongDBHandler extends SQLiteOpenHelper { db.close(); } + public boolean hasBeenPlayed(MusicDirectory.Entry entry) { + Long[] lastPlayed = getLastPlayed(entry); + return lastPlayed != null && lastPlayed[0] != null && lastPlayed[0] > 0; + } + public boolean hasBeenCompleted(MusicDirectory.Entry entry) { + Long[] lastPlayed = getLastPlayed(entry); + return lastPlayed != null && lastPlayed[1] != null && lastPlayed[1] > 0; + } public synchronized Long[] getLastPlayed(MusicDirectory.Entry entry) { return getLastPlayed(getOnlineSongId(entry)); } diff --git a/app/src/main/java/github/daneren2005/dsub/view/SongView.java b/app/src/main/java/github/daneren2005/dsub/view/SongView.java index 2c0580af..95f7479f 100644 --- a/app/src/main/java/github/daneren2005/dsub/view/SongView.java +++ b/app/src/main/java/github/daneren2005/dsub/view/SongView.java @@ -20,7 +20,6 @@ package github.daneren2005.dsub.view; import android.content.Context; import android.graphics.Color; -import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.widget.*; @@ -30,6 +29,7 @@ import github.daneren2005.dsub.domain.PodcastEpisode; import github.daneren2005.dsub.service.DownloadService; import github.daneren2005.dsub.service.DownloadFile; import github.daneren2005.dsub.util.DrawableTint; +import github.daneren2005.dsub.util.SongDBHandler; import github.daneren2005.dsub.util.Util; import java.io.File; @@ -50,6 +50,7 @@ public class SongView extends UpdateView2 { private TextView statusTextView; private ImageView statusImageView; private ImageView bookmarkButton; + private ImageView playedButton; private View bottomRowView; private DownloadService downloadService; @@ -66,8 +67,10 @@ public class SongView extends UpdateView2 { private boolean partialFileExists = false; private boolean loaded = false; private boolean isBookmarked = false; - private boolean bookmarked = false; + private boolean isBookmarkedShown = false; private boolean showPodcast = false; + private boolean isPlayed = false; + private boolean isPlayedShown = false; public SongView(Context context) { super(context); @@ -84,6 +87,7 @@ public class SongView extends UpdateView2 { starButton.setFocusable(false); bookmarkButton = (ImageButton) findViewById(R.id.song_bookmark); bookmarkButton.setFocusable(false); + playedButton = (ImageButton) findViewById(R.id.song_played); moreButton = (ImageView) findViewById(R.id.item_more); bottomRowView = findViewById(R.id.song_bottom); } @@ -209,6 +213,10 @@ public class SongView extends UpdateView2 { item.loadMetadata(downloadFile.getCompleteFile()); loaded = true; } + + if(item instanceof PodcastEpisode || item.isAudioBook() || item.isPodcast()) { + isPlayed = SongDBHandler.getHandler(context).hasBeenCompleted(item); + } } @Override @@ -274,18 +282,34 @@ public class SongView extends UpdateView2 { } if(isBookmarked) { - if(!bookmarked) { + if(!isBookmarkedShown) { if(bookmarkButton.getDrawable() == null) { bookmarkButton.setImageDrawable(DrawableTint.getTintedDrawable(context, R.drawable.ic_menu_bookmark_selected)); } bookmarkButton.setVisibility(View.VISIBLE); - bookmarked = true; + isBookmarkedShown = true; } } else { - if(bookmarked) { + if(isBookmarkedShown) { bookmarkButton.setVisibility(View.GONE); - bookmarked = false; + isBookmarkedShown = false; + } + } + + if(isPlayed) { + if(!isPlayedShown) { + if(playedButton.getDrawable() == null) { + playedButton.setImageDrawable(DrawableTint.getTintedDrawable(context, R.drawable.ic_toggle_played)); + } + + playedButton.setVisibility(View.VISIBLE); + isPlayedShown = true; + } + } else { + if(isPlayedShown) { + playedButton.setVisibility(View.GONE); + isPlayedShown = false; } } diff --git a/app/src/main/res/drawable-hdpi/ic_toggle_played.png b/app/src/main/res/drawable-hdpi/ic_toggle_played.png new file mode 100644 index 00000000..944ff8be Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_toggle_played.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_toggle_played.png b/app/src/main/res/drawable-mdpi/ic_toggle_played.png new file mode 100644 index 00000000..02524f4c Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_toggle_played.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_toggle_played.png b/app/src/main/res/drawable-xhdpi/ic_toggle_played.png new file mode 100644 index 00000000..c681150c Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_toggle_played.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_toggle_played.png b/app/src/main/res/drawable-xxhdpi/ic_toggle_played.png new file mode 100644 index 00000000..33f9d819 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_toggle_played.png differ diff --git a/app/src/main/res/drawable-xxxhdpi/ic_toggle_played.png b/app/src/main/res/drawable-xxxhdpi/ic_toggle_played.png new file mode 100644 index 00000000..0907fd2c Binary files /dev/null and b/app/src/main/res/drawable-xxxhdpi/ic_toggle_played.png differ diff --git a/app/src/main/res/layout/song_list_item.xml b/app/src/main/res/layout/song_list_item.xml index 6a474787..d7c8d312 100644 --- a/app/src/main/res/layout/song_list_item.xml +++ b/app/src/main/res/layout/song_list_item.xml @@ -44,8 +44,8 @@ + + diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index 73ae6bed..9c53f472 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -6,6 +6,7 @@ 78dip 120dip 20dp + 24dp 4dp 8dp 2dp -- cgit v1.2.3