aboutsummaryrefslogtreecommitdiff
path: root/subsonic-android/src
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2012-10-03 22:15:26 -0700
committerScott Jackson <daneren2005@gmail.com>2012-10-03 22:15:26 -0700
commitf9a6738054febd93932cd3f6ab66e985777d45f1 (patch)
treec2cd3898bdcbf8dbd273b01ca4b7b6bebb531603 /subsonic-android/src
parentac6b7ae5a6f63bf4d4573d478ec5e4fc64190098 (diff)
downloaddsub-f9a6738054febd93932cd3f6ab66e985777d45f1.tar.gz
dsub-f9a6738054febd93932cd3f6ab66e985777d45f1.tar.bz2
dsub-f9a6738054febd93932cd3f6ab66e985777d45f1.zip
Updated star support to only display star when starred + star/unstar from long press menu
Diffstat (limited to 'subsonic-android/src')
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java18
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/activity/SelectAlbumActivity.java12
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/activity/SubsonicTabActivity.java32
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/util/AlbumView.java60
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/util/SongView.java15
5 files changed, 79 insertions, 58 deletions
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() {