diff options
14 files changed, 119 insertions, 80 deletions
diff --git a/subsonic-android/res/drawable-hdpi-v4/ic_stat_star.png b/subsonic-android/res/drawable-hdpi-v4/ic_stat_star.png Binary files differnew file mode 100644 index 00000000..b16e803c --- /dev/null +++ b/subsonic-android/res/drawable-hdpi-v4/ic_stat_star.png diff --git a/subsonic-android/res/layout/album_list_item.xml b/subsonic-android/res/layout/album_list_item.xml index a0f79fa7..80f40989 100644 --- a/subsonic-android/res/layout/album_list_item.xml +++ b/subsonic-android/res/layout/album_list_item.xml @@ -36,6 +36,15 @@ android:singleLine="true"/>
</LinearLayout>
+
+ <ImageButton
+ android:id="@+id/album_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"
@@ -43,14 +52,4 @@ android:layout_height="wrap_content"
android:layout_gravity="right|center_vertical"
android:paddingRight="6dip"/>
-
- <ImageButton
- android:id="@+id/album_star"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="right|center_vertical"
- android:background="@null"
- android:focusable="false"
- android:src="@android:drawable/star_big_off" />
-
</LinearLayout>
diff --git a/subsonic-android/res/layout/song_list_item.xml b/subsonic-android/res/layout/song_list_item.xml index 586f6803..e7c2aabb 100644 --- a/subsonic-android/res/layout/song_list_item.xml +++ b/subsonic-android/res/layout/song_list_item.xml @@ -35,6 +35,15 @@ android:drawablePadding="6dip"
android:paddingLeft="6dip"
android:paddingRight="6dip"/>
+
+ <ImageButton
+ android:id="@+id/song_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"/>
<TextView
android:id="@+id/song_status"
@@ -43,15 +52,6 @@ android:layout_gravity="right|center_vertical"
android:drawablePadding="1dip"
android:paddingRight="6dip"/>
-
- <ImageButton
- android:id="@+id/song_star"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="right|center_vertical"
- android:background="@null"
- android:focusable="false"
- android:src="@android:drawable/btn_star_big_off" />
</LinearLayout>
<LinearLayout android:orientation="horizontal"
diff --git a/subsonic-android/res/menu/nowplaying_context.xml b/subsonic-android/res/menu/nowplaying_context.xml index eeb49a26..9ad2be52 100644 --- a/subsonic-android/res/menu/nowplaying_context.xml +++ b/subsonic-android/res/menu/nowplaying_context.xml @@ -1,6 +1,5 @@ <?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android"> - <item android:id="@+id/menu_show_album" android:title="@string/download.menu_show_album"/> @@ -15,5 +14,9 @@ <item android:id="@+id/menu_delete" - android:title="@string/download.menu_delete"/> + android:title="@string/download.menu_delete"/> + + <item + android:id="@+id/menu_star" + android:title="@string/common.star"/> </menu> diff --git a/subsonic-android/res/menu/select_album_context.xml b/subsonic-android/res/menu/select_album_context.xml index 95ff22ca..ddfd134e 100644 --- a/subsonic-android/res/menu/select_album_context.xml +++ b/subsonic-android/res/menu/select_album_context.xml @@ -25,5 +25,9 @@ android:id="@+id/album_menu_pin" android:title="@string/common.pin" /> + + <item + android:id="@+id/album_menu_star" + android:title="@string/common.star"/> </menu> diff --git a/subsonic-android/res/menu/select_artist_context.xml b/subsonic-android/res/menu/select_artist_context.xml index 17f12162..d1fdbb02 100644 --- a/subsonic-android/res/menu/select_artist_context.xml +++ b/subsonic-android/res/menu/select_artist_context.xml @@ -25,5 +25,9 @@ android:id="@+id/artist_menu_pin" android:title="@string/common.pin" /> + + <item + android:id="@+id/artist_menu_star" + android:title="@string/common.star"/> </menu> diff --git a/subsonic-android/res/menu/select_playlist_context.xml b/subsonic-android/res/menu/select_playlist_context.xml index 5c3bfb48..4fe24f76 100644 --- a/subsonic-android/res/menu/select_playlist_context.xml +++ b/subsonic-android/res/menu/select_playlist_context.xml @@ -19,6 +19,6 @@ <item android:id="@+id/playlist_menu_pin" android:title="@string/common.pin" - /> + /> </menu>
\ No newline at end of file diff --git a/subsonic-android/res/menu/select_song_context.xml b/subsonic-android/res/menu/select_song_context.xml index c6393e77..cc88fd9d 100644 --- a/subsonic-android/res/menu/select_song_context.xml +++ b/subsonic-android/res/menu/select_song_context.xml @@ -15,5 +15,9 @@ android:id="@+id/song_menu_play_last" android:title="@string/common.play_last" /> + + <item + android:id="@+id/song_menu_star" + android:title="@string/common.star"/> </menu> diff --git a/subsonic-android/res/values/strings.xml b/subsonic-android/res/values/strings.xml index 96f1fc93..a71f896a 100644 --- a/subsonic-android/res/values/strings.xml +++ b/subsonic-android/res/values/strings.xml @@ -12,6 +12,8 @@ <string name="common.download">Download</string>
<string name="common.pin">Cache</string>
<string name="common.delete">Delete</string>
+ <string name="common.star">Star</string>
+ <string name="common.unstar">Unstar</string>
<string name="button_bar.home">DSub home</string>
<string name="button_bar.browse">Media library</string>
@@ -118,6 +120,8 @@ <string name="download.jukebox_offline">Remote control is not available in offline mode.</string>
<string name="download.jukebox_not_authorized">Remote control is not allowed. Please enable jukebox mode in <b>Users > Settings</b> on your Subsonic server.</string>
+ <string name="starring_content_starred">Starred \"%s\"</string>
+ <string name="starring_content_unstarred">Unstarred \"%s\"</string>
<string name="starring_content_error">Failed to update \"%s\", please try later.</string>
<string name="song_details.all">%1$s %2$s</string>
diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java index 61065c18..bbd4ba2e 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java @@ -162,16 +162,6 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi starButton = (ImageButton) findViewById(R.id.download_star); starButton.setVisibility(Util.isOffline(this) ? View.GONE : View.VISIBLE); - starButton.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - DownloadFile currentDownload = getDownloadService().getCurrentPlaying(); - if (currentDownload != null) { - MusicDirectory.Entry currentSong = currentDownload.getSong(); - toggleStarredInBackground(currentSong, starButton); - } - } - }); View.OnTouchListener touchListener = new View.OnTouchListener() { @Override @@ -541,7 +531,10 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi if (Util.isOffline(this)) { menu.findItem(R.id.menu_lyrics).setVisible(false); menu.findItem(R.id.menu_save_playlist).setVisible(false); - } + menu.findItem(R.id.menu_star).setVisible(false); + } else { + menu.findItem(R.id.menu_star).setTitle(downloadFile.getSong().isStarred() ? R.string.common_unstar : R.string.common_star); + } } } @@ -603,6 +596,9 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi case R.id.menu_save_playlist: showDialog(DIALOG_SAVE_PLAYLIST); return true; + case R.id.menu_star: + toggleStarred(song.getSong()); + return true; default: return false; } diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/SelectAlbumActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/SelectAlbumActivity.java index 9a600d59..09ddbacf 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/SelectAlbumActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/SelectAlbumActivity.java @@ -235,6 +235,12 @@ public class SelectAlbumActivity extends SubsonicTabActivity { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.select_song_context, menu); } + + if (Util.isOffline(this)) { + menu.findItem(entry.isDirectory() ? R.id.album_menu_star : R.id.song_menu_star).setVisible(false); + } else { + menu.findItem(entry.isDirectory() ? R.id.album_menu_star : R.id.song_menu_star).setTitle(entry.isStarred() ? R.string.common_unstar : R.string.common_star); + } } @Override @@ -259,6 +265,9 @@ public class SelectAlbumActivity extends SubsonicTabActivity { case R.id.album_menu_pin: downloadRecursively(entry.getId(), true, true, false, false, true); break; + case R.id.album_menu_star: + toggleStarred(entry); + break; case R.id.song_menu_play_now: getDownloadService().download(songs, false, true, true, false); break; @@ -268,6 +277,9 @@ public class SelectAlbumActivity extends SubsonicTabActivity { case R.id.song_menu_play_last: getDownloadService().download(songs, false, false, false, false); break; + case R.id.song_menu_star: + toggleStarred(entry); + break; default: return super.onContextItemSelected(menuItem); } diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicTabActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicTabActivity.java index 32b6c550..05ad2f4b 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicTabActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicTabActivity.java @@ -40,12 +40,7 @@ import android.widget.TextView; import github.daneren2005.dsub.R;
import com.actionbarsherlock.app.SherlockActivity;
import github.daneren2005.dsub.domain.MusicDirectory;
-import github.daneren2005.dsub.service.DownloadService;
-import github.daneren2005.dsub.service.DownloadServiceImpl;
-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.service.*;
import github.daneren2005.dsub.util.Constants;
import github.daneren2005.dsub.util.ImageLoader;
import github.daneren2005.dsub.util.ModalBackgroundTask;
@@ -127,8 +122,6 @@ public class SubsonicTabActivity extends SherlockActivity { } else if (this instanceof DownloadActivity || this instanceof LyricsActivity) {
nowPlayingButton.setEnabled(false);
}
-
- updateButtonVisibility();
}
@Override
@@ -195,20 +188,12 @@ public class SubsonicTabActivity extends SherlockActivity { public boolean isDestroyed() {
return destroyed;
}
-
- private void updateButtonVisibility() {
- int visibility = Util.isOffline(this) ? View.GONE : View.VISIBLE;
- }
- public void toggleStarredInBackground(final MusicDirectory.Entry entry, final ImageButton button) {
-
- final boolean starred = !entry.isStarred();
-
- button.setImageResource(starred ? android.R.drawable.btn_star_big_on : android.R.drawable.btn_star_big_off);
- entry.setStarred(starred);
-
- // Util.toast(SubsonicTabActivity.this, getResources().getString(R.string.starring_content, entry.getTitle()));
- new SilentBackgroundTask<Void>(this) {
+ public void toggleStarred(final MusicDirectory.Entry 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);
@@ -218,12 +203,11 @@ public class SubsonicTabActivity extends SherlockActivity { @Override
protected void done(Void result) {
- // Util.toast(SubsonicTabActivity.this, getResources().getString(R.string.starring_content_done, entry.getTitle()));
+ Util.toast(SubsonicTabActivity.this, getResources().getString(starred ? R.string.starring_content_starred : R.string.starring_content_unstarred, entry.getTitle()));
}
@Override
protected void error(Throwable error) {
- button.setImageResource(!starred ? android.R.drawable.btn_star_big_on : android.R.drawable.btn_star_big_off);
entry.setStarred(!starred);
String msg;
@@ -236,7 +220,7 @@ public class SubsonicTabActivity extends SherlockActivity { 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/util/AlbumView.java b/subsonic-android/src/github/daneren2005/dsub/util/AlbumView.java index 8c799aad..124f551d 100644 --- a/subsonic-android/src/github/daneren2005/dsub/util/AlbumView.java +++ b/subsonic-android/src/github/daneren2005/dsub/util/AlbumView.java @@ -19,14 +19,16 @@ package github.daneren2005.dsub.util; import android.content.Context; +import android.os.Handler; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.widget.ImageButton; import android.widget.LinearLayout; import android.widget.TextView; import github.daneren2005.dsub.R; -import github.daneren2005.dsub.activity.SubsonicTabActivity; import github.daneren2005.dsub.domain.MusicDirectory; +import java.util.WeakHashMap; /** * Used to display albums in a {@code ListView}. @@ -34,6 +36,9 @@ import github.daneren2005.dsub.domain.MusicDirectory; * @author Sindre Mehus */ public class AlbumView extends LinearLayout { + private static final String TAG = AlbumView.class.getSimpleName(); + private static final WeakHashMap<AlbumView, ?> INSTANCES = new WeakHashMap<AlbumView, Object>(); + private static Handler handler; private MusicDirectory.Entry album; @@ -50,14 +55,13 @@ public class AlbumView extends LinearLayout { artistView = (TextView) findViewById(R.id.album_artist); coverArtView = findViewById(R.id.album_coverart); starButton = (ImageButton) findViewById(R.id.album_star); - starButton.setVisibility(Util.isOffline(getContext()) ? View.GONE : View.VISIBLE); - starButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - SubsonicTabActivity activity = (SubsonicTabActivity) getContext(); - activity.toggleStarredInBackground(album, starButton); - } - }); + + INSTANCES.put(this, null); + int instanceCount = INSTANCES.size(); + if (instanceCount > 50) { + Log.w(TAG, instanceCount + " live AlbumView instances"); + } + startUpdater(); } public void setAlbum(MusicDirectory.Entry album, ImageLoader imageLoader) { @@ -68,7 +72,41 @@ public class AlbumView extends LinearLayout { artistView.setVisibility(album.getArtist() == null ? View.GONE : View.VISIBLE); imageLoader.loadImage(coverArtView, album, false, true); - starButton.setImageResource(album.isStarred() ? android.R.drawable.btn_star_big_on : android.R.drawable.btn_star_big_off); - starButton.setFocusable(false); + starButton.setVisibility((Util.isOffline(getContext()) || !album.isStarred()) ? View.GONE : View.VISIBLE); + starButton.setFocusable(false); + + update(); + } + + private void update() { + starButton.setVisibility((Util.isOffline(getContext()) || !album.isStarred()) ? View.GONE : View.VISIBLE); + } + + private static synchronized void startUpdater() { + if (handler != null) { + return; + } + + handler = new Handler(); + Runnable runnable = new Runnable() { + @Override + public void run() { + updateAll(); + handler.postDelayed(this, 1000L); + } + }; + handler.postDelayed(runnable, 1000L); + } + + private static void updateAll() { + try { + for (AlbumView view : INSTANCES.keySet()) { + if (view.isShown()) { + view.update(); + } + } + } catch (Throwable x) { + Log.w(TAG, "Error when updating song views.", x); + } } } diff --git a/subsonic-android/src/github/daneren2005/dsub/util/SongView.java b/subsonic-android/src/github/daneren2005/dsub/util/SongView.java index 1bc2b9c0..24c483dc 100644 --- a/subsonic-android/src/github/daneren2005/dsub/util/SongView.java +++ b/subsonic-android/src/github/daneren2005/dsub/util/SongView.java @@ -44,7 +44,6 @@ import java.util.WeakHashMap; * @author Sindre Mehus */ public class SongView extends LinearLayout implements Checkable { - private static final String TAG = SongView.class.getSimpleName(); private static final WeakHashMap<SongView, ?> INSTANCES = new WeakHashMap<SongView, Object>(); private static Handler handler; @@ -68,14 +67,6 @@ public class SongView extends LinearLayout implements Checkable { durationTextView = (TextView) findViewById(R.id.song_duration); statusTextView = (TextView) findViewById(R.id.song_status); starButton = (ImageButton) findViewById(R.id.song_star); - starButton.setVisibility(Util.isOffline(getContext()) ? View.GONE : View.VISIBLE); - starButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - SubsonicTabActivity activity = (SubsonicTabActivity) getContext(); - activity.toggleStarredInBackground(song, starButton); - } - }); INSTANCES.put(this, null); int instanceCount = INSTANCES.size(); @@ -109,9 +100,8 @@ public class SongView extends LinearLayout implements Checkable { artistTextView.setText(artist); durationTextView.setText(Util.formatDuration(song.getDuration())); checkedTextView.setVisibility(checkable && !song.isVideo() ? View.VISIBLE : View.GONE); - - starButton.setImageResource(song.isStarred() ? android.R.drawable.btn_star_big_on : android.R.drawable.btn_star_big_off); - starButton.setFocusable(false); + starButton.setVisibility((Util.isOffline(getContext()) || !song.isStarred()) ? View.GONE : View.VISIBLE); + starButton.setFocusable(false); update(); } @@ -147,6 +137,7 @@ public class SongView extends LinearLayout implements Checkable { } else { titleTextView.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); } + starButton.setVisibility((Util.isOffline(getContext()) || !song.isStarred()) ? View.GONE : View.VISIBLE); } private static synchronized void startUpdater() { |