From 2ded932e517a1b53f5f61297c5b062fadee30045 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Sat, 10 Nov 2012 20:43:57 -0800 Subject: Made arrows on artist/albums/playlists clickable to quickly bring up context menus #47 --- subsonic-android/res/layout/album_list_item.xml | 14 ++-- subsonic-android/res/layout/artist_list_item.xml | 8 ++- subsonic-android/res/layout/playlist_list_item.xml | 36 +++++++--- .../dsub/activity/SelectPlaylistActivity.java | 1 + .../github/daneren2005/dsub/view/AlbumView.java | 9 +++ .../github/daneren2005/dsub/view/ArtistView.java | 9 ++- .../daneren2005/dsub/view/PlaylistAdapter.java | 81 +++++++--------------- .../github/daneren2005/dsub/view/PlaylistView.java | 60 ++++++++++++++++ 8 files changed, 141 insertions(+), 77 deletions(-) create mode 100644 subsonic-android/src/github/daneren2005/dsub/view/PlaylistView.java diff --git a/subsonic-android/res/layout/album_list_item.xml b/subsonic-android/res/layout/album_list_item.xml index 6bd12fd1..d76f105f 100644 --- a/subsonic-android/res/layout/album_list_item.xml +++ b/subsonic-android/res/layout/album_list_item.xml @@ -44,13 +44,15 @@ android:layout_height="wrap_content" android:layout_gravity="right|center_vertical" android:src="@drawable/ic_stat_star" - android:background="@null" + android:background="@android:color/transparent" android:focusable="false"/> + android:id="@+id/album_more" + android:src="@drawable/list_item_more" + android:layout_width="wrap_content" + android:layout_height="fill_parent" + android:layout_gravity="right|center_vertical" + android:paddingRight="6dip" + android:background="@drawable/menubar_button"/> diff --git a/subsonic-android/res/layout/artist_list_item.xml b/subsonic-android/res/layout/artist_list_item.xml index ed78b543..09ecd802 100644 --- a/subsonic-android/res/layout/artist_list_item.xml +++ b/subsonic-android/res/layout/artist_list_item.xml @@ -21,13 +21,15 @@ android:layout_height="wrap_content" android:layout_gravity="right|center_vertical" android:src="@drawable/ic_stat_star" - android:background="@null" + android:background="@android:color/transparent" android:focusable="false"/> + android:paddingRight="6dip" + android:background="@drawable/menubar_button"/> \ No newline at end of file diff --git a/subsonic-android/res/layout/playlist_list_item.xml b/subsonic-android/res/layout/playlist_list_item.xml index 3c99ccbd..1ec5753f 100644 --- a/subsonic-android/res/layout/playlist_list_item.xml +++ b/subsonic-android/res/layout/playlist_list_item.xml @@ -1,12 +1,26 @@ - \ No newline at end of file + + + + + + \ No newline at end of file diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/SelectPlaylistActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/SelectPlaylistActivity.java index 84a10d08..a88cdcaf 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/SelectPlaylistActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/SelectPlaylistActivity.java @@ -19,6 +19,7 @@ package github.daneren2005.dsub.activity; +import github.daneren2005.dsub.view.PlaylistAdapter; import android.app.AlertDialog; import android.content.DialogInterface; import android.content.Intent; diff --git a/subsonic-android/src/github/daneren2005/dsub/view/AlbumView.java b/subsonic-android/src/github/daneren2005/dsub/view/AlbumView.java index 1636776c..6415984f 100644 --- a/subsonic-android/src/github/daneren2005/dsub/view/AlbumView.java +++ b/subsonic-android/src/github/daneren2005/dsub/view/AlbumView.java @@ -22,6 +22,7 @@ import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.widget.ImageButton; +import android.widget.ImageView; import android.widget.TextView; import github.daneren2005.dsub.R; import github.daneren2005.dsub.domain.MusicDirectory; @@ -41,6 +42,7 @@ public class AlbumView extends UpdateView { private TextView artistView; private View coverArtView; private ImageButton starButton; + private ImageView moreButton; public AlbumView(Context context) { super(context); @@ -50,6 +52,13 @@ public class AlbumView extends UpdateView { artistView = (TextView) findViewById(R.id.album_artist); coverArtView = findViewById(R.id.album_coverart); starButton = (ImageButton) findViewById(R.id.album_star); + + moreButton = (ImageView) findViewById(R.id.album_more); + moreButton.setOnClickListener(new View.OnClickListener() { + public void onClick(View v) { + v.showContextMenu(); + } + }); } public void setAlbum(MusicDirectory.Entry album, ImageLoader imageLoader) { diff --git a/subsonic-android/src/github/daneren2005/dsub/view/ArtistView.java b/subsonic-android/src/github/daneren2005/dsub/view/ArtistView.java index 8eaca821..86c39d14 100644 --- a/subsonic-android/src/github/daneren2005/dsub/view/ArtistView.java +++ b/subsonic-android/src/github/daneren2005/dsub/view/ArtistView.java @@ -22,10 +22,10 @@ import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.widget.ImageButton; +import android.widget.ImageView; import android.widget.TextView; import github.daneren2005.dsub.R; import github.daneren2005.dsub.domain.Artist; -import github.daneren2005.dsub.util.ImageLoader; import github.daneren2005.dsub.util.Util; /** @@ -40,6 +40,7 @@ public class ArtistView extends UpdateView { private TextView titleView; private ImageButton starButton; + private ImageView moreButton; public ArtistView(Context context) { super(context); @@ -47,6 +48,12 @@ public class ArtistView extends UpdateView { titleView = (TextView) findViewById(R.id.artist_name); starButton = (ImageButton) findViewById(R.id.artist_star); + moreButton = (ImageView) findViewById(R.id.artist_more); + moreButton.setOnClickListener(new View.OnClickListener() { + public void onClick(View v) { + v.showContextMenu(); + } + }); } public void setArtist(Artist artist) { diff --git a/subsonic-android/src/github/daneren2005/dsub/view/PlaylistAdapter.java b/subsonic-android/src/github/daneren2005/dsub/view/PlaylistAdapter.java index 54379150..c9377721 100644 --- a/subsonic-android/src/github/daneren2005/dsub/view/PlaylistAdapter.java +++ b/subsonic-android/src/github/daneren2005/dsub/view/PlaylistAdapter.java @@ -14,77 +14,46 @@ You should have received a copy of the GNU General Public License along with Subsonic. If not, see . - Copyright 2009 (C) Sindre Mehus + Copyright 2010 (C) Sindre Mehus */ package github.daneren2005.dsub.view; -import android.content.Context; -import android.widget.ArrayAdapter; -import android.widget.SectionIndexer; import github.daneren2005.dsub.R; +import java.util.List; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import github.daneren2005.dsub.activity.SubsonicTabActivity; import github.daneren2005.dsub.domain.Playlist; - -import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Set; /** -* @author Sindre Mehus -* @version $Id$ -*/ -public class PlaylistAdapter extends ArrayAdapter implements SectionIndexer { - - // Both arrays are indexed by section ID. - private final Object[] sections; - private final Integer[] positions; - - /** - * Note: playlists must be sorted alphabetically. - */ - public PlaylistAdapter(Context context, List playlists) { - super(context, R.layout.playlist_list_item, playlists); - - Set sectionSet = new LinkedHashSet(30); - List positionList = new ArrayList(30); - for (int i = 0; i < playlists.size(); i++) { - Playlist playlist = playlists.get(i); - if (playlist.getName().length() > 0) { - String index = playlist.getName().substring(0, 1).toUpperCase(); - if (!sectionSet.contains(index)) { - sectionSet.add(index); - positionList.add(i); - } - } - } - sections = sectionSet.toArray(new Object[sectionSet.size()]); - positions = positionList.toArray(new Integer[positionList.size()]); - } + * @author Sindre Mehus + */ +public class PlaylistAdapter extends ArrayAdapter { - @Override - public Object[] getSections() { - return sections; - } + private final SubsonicTabActivity activity; - @Override - public int getPositionForSection(int section) { - section = Math.min(section, positions.length - 1); - return positions[section]; + public PlaylistAdapter(SubsonicTabActivity activity, List Playlists) { + super(activity, R.layout.playlist_list_item, Playlists); + this.activity = activity; } @Override - public int getSectionForPosition(int pos) { - for (int i = 0; i < sections.length - 1; i++) { - if (pos < positions[i + 1]) { - return i; - } - } - return sections.length - 1; + public View getView(int position, View convertView, ViewGroup parent) { + Playlist entry = getItem(position); + PlaylistView view; + if (convertView != null && convertView instanceof PlaylistView) { + view = (PlaylistView) convertView; + } else { + view = new PlaylistView(activity); + } + view.setPlaylist(entry); + return view; } - - public static class PlaylistComparator implements Comparator { + + public static class PlaylistComparator implements Comparator { @Override public int compare(Playlist playlist1, Playlist playlist2) { return playlist1.getName().compareToIgnoreCase(playlist2.getName()); diff --git a/subsonic-android/src/github/daneren2005/dsub/view/PlaylistView.java b/subsonic-android/src/github/daneren2005/dsub/view/PlaylistView.java new file mode 100644 index 00000000..d1b9340a --- /dev/null +++ b/subsonic-android/src/github/daneren2005/dsub/view/PlaylistView.java @@ -0,0 +1,60 @@ +/* + This file is part of Subsonic. + + Subsonic 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. + + Subsonic 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. + + You should have received a copy of the GNU General Public License + along with Subsonic. If not, see . + + Copyright 2009 (C) Sindre Mehus + */ +package github.daneren2005.dsub.view; + +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.ImageView; +import android.widget.TextView; +import github.daneren2005.dsub.R; +import github.daneren2005.dsub.domain.Playlist; + +/** + * Used to display albums in a {@code ListView}. + * + * @author Sindre Mehus + */ +public class PlaylistView extends UpdateView { + private static final String TAG = ArtistView.class.getSimpleName(); + + private Playlist playlist; + + private TextView titleView; + private ImageView moreButton; + + public PlaylistView(Context context) { + super(context); + LayoutInflater.from(context).inflate(R.layout.artist_list_item, this, true); + + titleView = (TextView) findViewById(R.id.artist_name); + moreButton = (ImageView) findViewById(R.id.artist_more); + moreButton.setOnClickListener(new View.OnClickListener() { + public void onClick(View v) { + v.showContextMenu(); + } + }); + } + + public void setPlaylist(Playlist playlist) { + this.playlist = playlist; + + titleView.setText(playlist.getName()); + } +} -- cgit v1.2.3