aboutsummaryrefslogtreecommitdiff
path: root/subsonic-android
diff options
context:
space:
mode:
Diffstat (limited to 'subsonic-android')
-rw-r--r--subsonic-android/res/layout/artist_list_item.xml43
-rw-r--r--subsonic-android/res/menu/select_artist_context.xml2
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/activity/SearchActivity.java4
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/activity/SelectAlbumActivity.java4
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/activity/SelectArtistActivity.java2
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/activity/SubsonicTabActivity.java34
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/domain/Artist.java9
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/service/parser/IndexesParser.java2
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/service/parser/StarredListParser.java4
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/util/ArtistAdapter.java78
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/view/AlbumView.java2
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/view/ArtistAdapter.java53
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/view/ArtistView.java67
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/view/EntryAdapter.java (renamed from subsonic-android/src/github/daneren2005/dsub/util/EntryAdapter.java)3
14 files changed, 207 insertions, 100 deletions
diff --git a/subsonic-android/res/layout/artist_list_item.xml b/subsonic-android/res/layout/artist_list_item.xml
index 3c99ccbd..ed78b543 100644
--- a/subsonic-android/res/layout/artist_list_item.xml
+++ b/subsonic-android/res/layout/artist_list_item.xml
@@ -1,12 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
-<TextView xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@android:id/text1"
- android:drawableRight="@drawable/list_item_more"
- android:drawablePadding="6dip"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:textAppearance="?android:attr/textAppearanceMedium"
- android:gravity="center_vertical"
- android:paddingLeft="6dip"
- android:paddingRight="6dip"
- android:minHeight="50dip"/> \ No newline at end of file
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="horizontal"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content">
+
+ <TextView
+ android:id="@+id/artist_name"
+ android:layout_width="0dip"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:textAppearance="?android:attr/textAppearanceMedium"
+ android:gravity="left|center_vertical"
+ android:paddingLeft="6dip"
+ android:paddingRight="6dip"
+ android:minHeight="50dip"/>
+
+ <ImageButton
+ android:id="@+id/artist_star"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="right|center_vertical"
+ android:src="@drawable/ic_stat_star"
+ android:background="@null"
+ android:focusable="false"/>
+
+ <ImageView
+ android:src="@drawable/list_item_more"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="right|center_vertical"
+ android:paddingRight="6dip"/>
+</LinearLayout> \ No newline at end of file
diff --git a/subsonic-android/res/menu/select_artist_context.xml b/subsonic-android/res/menu/select_artist_context.xml
index 7f9db01a..428e23a1 100644
--- a/subsonic-android/res/menu/select_artist_context.xml
+++ b/subsonic-android/res/menu/select_artist_context.xml
@@ -24,5 +24,5 @@
<item
android:id="@+id/artist_menu_pin"
android:title="@string/common.pin"
- />
+ />
</menu>
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