diff options
author | Scott Jackson <daneren2005@gmail.com> | 2012-11-10 14:55:36 -0800 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2012-11-10 14:55:36 -0800 |
commit | f39d3a88e91424aec4e7ac5571dc49c785daefbd (patch) | |
tree | 5d24a220959c2b4294f1e3ee942b4188756922f0 /subsonic-android/src | |
parent | f068c1c71f4115bb4c73b6ad9bb807666270ff97 (diff) | |
download | dsub-f39d3a88e91424aec4e7ac5571dc49c785daefbd.tar.gz dsub-f39d3a88e91424aec4e7ac5571dc49c785daefbd.tar.bz2 dsub-f39d3a88e91424aec4e7ac5571dc49c785daefbd.zip |
Added support for starring to the artist views (not currently working entirely) + moved adapters to views folders
Diffstat (limited to 'subsonic-android/src')
12 files changed, 174 insertions, 88 deletions
diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/SearchActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/SearchActivity.java index 76054280..165054d2 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/SearchActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/SearchActivity.java @@ -45,10 +45,10 @@ import github.daneren2005.dsub.domain.SearchResult; import github.daneren2005.dsub.service.MusicService; import github.daneren2005.dsub.service.MusicServiceFactory; import github.daneren2005.dsub.service.DownloadService; -import github.daneren2005.dsub.util.ArtistAdapter; +import github.daneren2005.dsub.view.ArtistAdapter; import github.daneren2005.dsub.util.BackgroundTask; import github.daneren2005.dsub.util.Constants; -import github.daneren2005.dsub.util.EntryAdapter; +import github.daneren2005.dsub.view.EntryAdapter; import github.daneren2005.dsub.util.MergeAdapter; import github.daneren2005.dsub.util.TabActivityBackgroundTask; import github.daneren2005.dsub.util.Util; diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/SelectAlbumActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/SelectAlbumActivity.java index 591ae9d6..6af1b4ce 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/SelectAlbumActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/SelectAlbumActivity.java @@ -18,6 +18,7 @@ */ package github.daneren2005.dsub.activity; +import github.daneren2005.dsub.view.EntryAdapter; import android.app.AlertDialog; import android.content.DialogInterface; import android.content.Intent; @@ -33,11 +34,8 @@ import android.widget.*; import com.actionbarsherlock.view.Menu; import github.daneren2005.dsub.R; import github.daneren2005.dsub.domain.MusicDirectory; -import github.daneren2005.dsub.domain.Playlist; import github.daneren2005.dsub.service.MusicService; import github.daneren2005.dsub.service.MusicServiceFactory; -import github.daneren2005.dsub.service.OfflineException; -import github.daneren2005.dsub.service.ServerTooOldException; import github.daneren2005.dsub.util.*; import java.util.ArrayList; diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/SelectArtistActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/SelectArtistActivity.java index f9d45ac8..ff8a21c1 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/SelectArtistActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/SelectArtistActivity.java @@ -36,7 +36,7 @@ import github.daneren2005.dsub.domain.Indexes; import github.daneren2005.dsub.domain.MusicFolder; import github.daneren2005.dsub.service.MusicService; import github.daneren2005.dsub.service.MusicServiceFactory; -import github.daneren2005.dsub.util.ArtistAdapter; +import github.daneren2005.dsub.view.ArtistAdapter; import github.daneren2005.dsub.util.BackgroundTask; import github.daneren2005.dsub.util.Constants; import github.daneren2005.dsub.util.TabActivityBackgroundTask; diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicTabActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicTabActivity.java index 5b3ef186..dc72d311 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicTabActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicTabActivity.java @@ -41,6 +41,7 @@ import android.widget.ImageButton; import android.widget.TextView;
import github.daneren2005.dsub.R;
import com.actionbarsherlock.app.SherlockActivity;
+import github.daneren2005.dsub.domain.Artist;
import github.daneren2005.dsub.domain.MusicDirectory;
import github.daneren2005.dsub.domain.Playlist;
import github.daneren2005.dsub.service.*;
@@ -226,6 +227,39 @@ public class SubsonicTabActivity extends SherlockActivity { }
}.execute();
}
+ public void toggleStarred(final Artist entry) {
+ final boolean starred = !entry.isStarred();
+ entry.setStarred(starred);
+
+ new SilentBackgroundTask<Void>(this) {
+ @Override
+ protected Void doInBackground() throws Throwable {
+ MusicService musicService = MusicServiceFactory.getMusicService(SubsonicTabActivity.this);
+ musicService.setStarred(entry.getId(), starred, SubsonicTabActivity.this, null);
+ return null;
+ }
+
+ @Override
+ protected void done(Void result) {
+ // UpdateView
+ Util.toast(SubsonicTabActivity.this, getResources().getString(starred ? R.string.starring_content_starred : R.string.starring_content_unstarred, entry.getName()));
+ }
+
+ @Override
+ protected void error(Throwable error) {
+ entry.setStarred(!starred);
+
+ String msg;
+ if (error instanceof OfflineException || error instanceof ServerTooOldException) {
+ msg = getErrorMessage(error);
+ } else {
+ msg = getResources().getString(R.string.starring_content_error, entry.getName()) + " " + getErrorMessage(error);
+ }
+
+ Util.toast(SubsonicTabActivity.this, msg, false);
+ }
+ }.execute();
+ }
public void setProgressVisible(boolean visible) {
View view = findViewById(R.id.tab_progress);
diff --git a/subsonic-android/src/github/daneren2005/dsub/domain/Artist.java b/subsonic-android/src/github/daneren2005/dsub/domain/Artist.java index 29e6ad34..202af627 100644 --- a/subsonic-android/src/github/daneren2005/dsub/domain/Artist.java +++ b/subsonic-android/src/github/daneren2005/dsub/domain/Artist.java @@ -28,6 +28,7 @@ public class Artist implements Serializable { private String id; private String name; private String index; + private boolean starred; public String getId() { return id; @@ -52,6 +53,14 @@ public class Artist implements Serializable { public void setIndex(String index) { this.index = index; } + + public boolean isStarred() { + return starred; + } + + public void setStarred(boolean starred) { + this.starred = starred; + } @Override public String toString() { diff --git a/subsonic-android/src/github/daneren2005/dsub/service/parser/IndexesParser.java b/subsonic-android/src/github/daneren2005/dsub/service/parser/IndexesParser.java index d33021cd..4a307812 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/parser/IndexesParser.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/parser/IndexesParser.java @@ -69,6 +69,7 @@ public class IndexesParser extends AbstractParser { artist.setId(get("id")); artist.setName(get("name")); artist.setIndex(index); + artist.setStarred(get("starred") != null); artists.add(artist); if (artists.size() % 10 == 0) { @@ -80,6 +81,7 @@ public class IndexesParser extends AbstractParser { shortcut.setId(get("id")); shortcut.setName(get("name")); shortcut.setIndex("*"); + shortcut.setStarred(get("starred") != null); shortcuts.add(shortcut); } else if ("error".equals(name)) { handleError(); diff --git a/subsonic-android/src/github/daneren2005/dsub/service/parser/StarredListParser.java b/subsonic-android/src/github/daneren2005/dsub/service/parser/StarredListParser.java index c3c16949..bc1ed67c 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/parser/StarredListParser.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/parser/StarredListParser.java @@ -48,7 +48,9 @@ public class StarredListParser extends MusicDirectoryEntryParser { String name = getElementName(); if ("album".equals(name) || "song".equals(name)) { dir.addChild(parseEntry()); - } else if ("error".equals(name)) { + } else if("artist".equals(name)) { + + } else if ("error".equals(name)) { handleError(); } } diff --git a/subsonic-android/src/github/daneren2005/dsub/util/ArtistAdapter.java b/subsonic-android/src/github/daneren2005/dsub/util/ArtistAdapter.java deleted file mode 100644 index adb54ce7..00000000 --- a/subsonic-android/src/github/daneren2005/dsub/util/ArtistAdapter.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - 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 <http://www.gnu.org/licenses/>. - - Copyright 2010 (C) Sindre Mehus - */ -package github.daneren2005.dsub.util; - -import github.daneren2005.dsub.domain.Artist; -import github.daneren2005.dsub.R; -import android.widget.ArrayAdapter; -import android.widget.SectionIndexer; -import android.content.Context; - -import java.util.List; -import java.util.Set; -import java.util.LinkedHashSet; -import java.util.ArrayList; - -/** - * @author Sindre Mehus -*/ -public class ArtistAdapter extends ArrayAdapter<Artist> implements SectionIndexer { - - // Both arrays are indexed by section ID. - private final Object[] sections; - private final Integer[] positions; - - public ArtistAdapter(Context context, List<Artist> artists) { - super(context, R.layout.artist_list_item, artists); - - Set<String> sectionSet = new LinkedHashSet<String>(30); - List<Integer> positionList = new ArrayList<Integer>(30); - for (int i = 0; i < artists.size(); i++) { - Artist artist = artists.get(i); - String index = artist.getIndex(); - if (!sectionSet.contains(index)) { - sectionSet.add(index); - positionList.add(i); - } - } - sections = sectionSet.toArray(new Object[sectionSet.size()]); - positions = positionList.toArray(new Integer[positionList.size()]); - } - - @Override - public Object[] getSections() { - return sections; - } - - @Override - public int getPositionForSection(int section) { - section = Math.min(section, positions.length - 1); - return positions[section]; - } - - @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; - } -} diff --git a/subsonic-android/src/github/daneren2005/dsub/view/AlbumView.java b/subsonic-android/src/github/daneren2005/dsub/view/AlbumView.java index ea8f5110..1636776c 100644 --- a/subsonic-android/src/github/daneren2005/dsub/view/AlbumView.java +++ b/subsonic-android/src/github/daneren2005/dsub/view/AlbumView.java @@ -27,8 +27,6 @@ import github.daneren2005.dsub.R; import github.daneren2005.dsub.domain.MusicDirectory; import github.daneren2005.dsub.util.ImageLoader; import github.daneren2005.dsub.util.Util; -import github.daneren2005.dsub.view.UpdateView; - /** * Used to display albums in a {@code ListView}. * diff --git a/subsonic-android/src/github/daneren2005/dsub/view/ArtistAdapter.java b/subsonic-android/src/github/daneren2005/dsub/view/ArtistAdapter.java new file mode 100644 index 00000000..12956a14 --- /dev/null +++ b/subsonic-android/src/github/daneren2005/dsub/view/ArtistAdapter.java @@ -0,0 +1,53 @@ +/* + 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 <http://www.gnu.org/licenses/>. + + Copyright 2010 (C) Sindre Mehus + */ +package github.daneren2005.dsub.view; + +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.Artist; + +/** + * @author Sindre Mehus + */ +public class ArtistAdapter extends ArrayAdapter<Artist> { + + private final SubsonicTabActivity activity; + + public ArtistAdapter(SubsonicTabActivity activity, List<Artist> artists) { + super(activity, R.layout.artist_list_item, artists); + this.activity = activity; + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + Artist entry = getItem(position); + ArtistView view; + if (convertView != null && convertView instanceof ArtistView) { + view = (ArtistView) convertView; + } else { + view = new ArtistView(activity); + } + view.setArtist(entry); + return view; + } +} diff --git a/subsonic-android/src/github/daneren2005/dsub/view/ArtistView.java b/subsonic-android/src/github/daneren2005/dsub/view/ArtistView.java new file mode 100644 index 00000000..8eaca821 --- /dev/null +++ b/subsonic-android/src/github/daneren2005/dsub/view/ArtistView.java @@ -0,0 +1,67 @@ +/*
+ 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 <http://www.gnu.org/licenses/>.
+
+ 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.ImageButton;
+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;
+
+/**
+ * Used to display albums in a {@code ListView}.
+ *
+ * @author Sindre Mehus
+ */
+public class ArtistView extends UpdateView {
+ private static final String TAG = ArtistView.class.getSimpleName();
+
+ private Artist artist;
+
+ private TextView titleView;
+ private ImageButton starButton;
+
+ public ArtistView(Context context) {
+ super(context);
+ LayoutInflater.from(context).inflate(R.layout.artist_list_item, this, true);
+
+ titleView = (TextView) findViewById(R.id.artist_name);
+ starButton = (ImageButton) findViewById(R.id.artist_star);
+ }
+
+ public void setArtist(Artist artist) {
+ this.artist = artist;
+
+ titleView.setText(artist.getName());
+
+ starButton.setVisibility((Util.isOffline(getContext()) || !artist.isStarred()) ? View.GONE : View.VISIBLE);
+ starButton.setFocusable(false);
+
+ update();
+ }
+
+ @Override
+ protected void update() {
+ starButton.setVisibility((Util.isOffline(getContext()) || !artist.isStarred()) ? View.GONE : View.VISIBLE);
+ }
+}
diff --git a/subsonic-android/src/github/daneren2005/dsub/util/EntryAdapter.java b/subsonic-android/src/github/daneren2005/dsub/view/EntryAdapter.java index bca05e00..6d2c7a63 100644 --- a/subsonic-android/src/github/daneren2005/dsub/util/EntryAdapter.java +++ b/subsonic-android/src/github/daneren2005/dsub/view/EntryAdapter.java @@ -16,7 +16,7 @@ Copyright 2010 (C) Sindre Mehus */ -package github.daneren2005.dsub.util; +package github.daneren2005.dsub.view; import github.daneren2005.dsub.view.AlbumView; import github.daneren2005.dsub.view.SongView; @@ -27,6 +27,7 @@ import android.view.ViewGroup; import android.widget.ArrayAdapter; import github.daneren2005.dsub.activity.SubsonicTabActivity; import github.daneren2005.dsub.domain.MusicDirectory; +import github.daneren2005.dsub.util.ImageLoader; /** * @author Sindre Mehus |