diff options
author | Scott Jackson <daneren2005@gmail.com> | 2014-09-13 09:06:19 -0700 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2014-09-13 09:06:19 -0700 |
commit | 46de452c50617c2bde3b648977b22a9f363a5b85 (patch) | |
tree | a61b390e61aac015a96ea07543610c59a8e26f4b | |
parent | da0176422bf9fe48878479038ed6bdfc10972af0 (diff) | |
download | dsub-46de452c50617c2bde3b648977b22a9f363a5b85.tar.gz dsub-46de452c50617c2bde3b648977b22a9f363a5b85.tar.bz2 dsub-46de452c50617c2bde3b648977b22a9f363a5b85.zip |
#397 Add star/rating to album header, added OnStarChange/OnRatingChange callbacks
8 files changed, 150 insertions, 21 deletions
diff --git a/res/layout/select_album_header.xml b/res/layout/select_album_header.xml index 4110d530..a253aa31 100644 --- a/res/layout/select_album_header.xml +++ b/res/layout/select_album_header.xml @@ -71,16 +71,44 @@ </LinearLayout> - <ImageView - android:id="@+id/select_album_share" - android:layout_height="wrap_content" + <LinearLayout android:layout_width="wrap_content" - android:scaleType="fitCenter" - android:src="?attr/share" - android:padding="10dip" + android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" - style="@style/BasicButton"/> + android:padding="10dip"> + + <LinearLayout + android:id="@+id/select_album_rate_wrapper" + android:layout_width="wrap_content" + android:layout_height="fill_parent"> + + <RatingBar + android:id="@+id/select_album_rate" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:numStars="5" + style="@android:style/Widget.Holo.RatingBar.Small" + android:layout_gravity="center_vertical"/> + </LinearLayout> + + <ImageButton + android:id="@+id/select_album_star" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + style="@style/BasicButton" + android:src="@android:drawable/star_big_off" + android:layout_gravity="center_vertical"/> + + <ImageView + android:id="@+id/select_album_share" + android:layout_height="wrap_content" + android:layout_width="wrap_content" + android:scaleType="fitCenter" + android:src="?attr/share" + style="@style/BasicButton" + android:layout_gravity="center_vertical"/> + </LinearLayout> </RelativeLayout> diff --git a/src/github/daneren2005/dsub/fragments/NowPlayingFragment.java b/src/github/daneren2005/dsub/fragments/NowPlayingFragment.java index c962bc1b..a957c7f3 100644 --- a/src/github/daneren2005/dsub/fragments/NowPlayingFragment.java +++ b/src/github/daneren2005/dsub/fragments/NowPlayingFragment.java @@ -194,9 +194,13 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis public void onClick(View v) {
DownloadFile currentDownload = getDownloadService().getCurrentPlaying();
if (currentDownload != null) {
- Entry currentSong = currentDownload.getSong();
- toggleStarred(currentSong);
- starButton.setImageResource(currentSong.isStarred() ? android.R.drawable.btn_star_big_on : android.R.drawable.btn_star_big_off);
+ final Entry currentSong = currentDownload.getSong();
+ toggleStarred(currentSong, new OnStarChange() {
+ @Override
+ void starChange(boolean starred) {
+ starButton.setImageResource(currentSong.isStarred() ? android.R.drawable.btn_star_big_on : android.R.drawable.btn_star_big_off);
+ }
+ });
}
}
});
diff --git a/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java b/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java index 1e09f334..4acccad2 100644 --- a/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java +++ b/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java @@ -17,9 +17,11 @@ import android.view.View; import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.GridView;
+import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.ListView;
+import android.widget.RatingBar;
import android.widget.TextView;
import github.daneren2005.dsub.R;
import github.daneren2005.dsub.domain.MusicDirectory;
@@ -70,6 +72,8 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter String id;
String name;
+ boolean starred;
+ int rating;
String playlistId;
String playlistName;
boolean playlistOwner;
@@ -113,6 +117,8 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter if(args != null) {
id = args.getString(Constants.INTENT_EXTRA_NAME_ID);
name = args.getString(Constants.INTENT_EXTRA_NAME_NAME);
+ starred = args.getBoolean(Constants.INTENT_EXTRA_NAME_STARRED, false);
+ rating = args.getInt(Constants.INTENT_EXTRA_NAME_RATING, 0);
playlistId = args.getString(Constants.INTENT_EXTRA_NAME_PLAYLIST_ID);
playlistName = args.getString(Constants.INTENT_EXTRA_NAME_PLAYLIST_NAME);
playlistOwner = args.getBoolean(Constants.INTENT_EXTRA_NAME_PLAYLIST_OWNER, false);
@@ -392,6 +398,8 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter Bundle args = new Bundle();
args.putString(Constants.INTENT_EXTRA_NAME_ID, entry.getId());
args.putString(Constants.INTENT_EXTRA_NAME_NAME, entry.getTitle());
+ args.putBoolean(Constants.INTENT_EXTRA_NAME_STARRED, entry.isStarred());
+ args.putInt(Constants.INTENT_EXTRA_NAME_RATING, entry.getRating());
if ("newest".equals(albumListType)) {
args.putBoolean(Constants.INTENT_EXTRA_REFRESH_LISTINGS, true);
}
@@ -722,6 +730,8 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter Bundle args = new Bundle();
args.putString(Constants.INTENT_EXTRA_NAME_ID, entry.getId());
args.putString(Constants.INTENT_EXTRA_NAME_NAME, entry.getTitle());
+ args.putBoolean(Constants.INTENT_EXTRA_NAME_STARRED, entry.isStarred());
+ args.putInt(Constants.INTENT_EXTRA_NAME_RATING, entry.getRating());
if ("newest".equals(albumListType)) {
args.putBoolean(Constants.INTENT_EXTRA_REFRESH_LISTINGS, true);
}
@@ -1281,6 +1291,50 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter }
});
}
+
+ final Entry album = new Entry();
+ album.setId(id);
+ album.setTitle(name);
+ album.setDirectory(true);
+ album.setStarred(starred);
+ album.setRating(rating);
+
+ final ImageButton starButton = (ImageButton) header.findViewById(R.id.select_album_star);
+ if(id != null && Util.getPreferences(context).getBoolean(Constants.PREFERENCES_KEY_MENU_STAR, true)) {
+ starButton.setImageResource(album.isStarred() ? android.R.drawable.btn_star_big_on : android.R.drawable.btn_star_big_off);
+ starButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ toggleStarred(album, new OnStarChange() {
+ @Override
+ void starChange(boolean starred) {
+ starButton.setImageResource(album.isStarred() ? android.R.drawable.btn_star_big_on : android.R.drawable.btn_star_big_off);
+ }
+ });
+ }
+ });
+ } else {
+ starButton.setVisibility(View.GONE);
+ }
+
+ View ratingBarWrapper = header.findViewById(R.id.select_album_rate_wrapper);
+ final RatingBar ratingBar = (RatingBar) header.findViewById(R.id.select_album_rate);
+ if(id != null && Util.getPreferences(context).getBoolean(Constants.PREFERENCES_KEY_MENU_RATING, true) && !Util.isOffline(context)) {
+ ratingBar.setRating(album.getRating());
+ ratingBarWrapper.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ setRating(album, new OnRatingChange() {
+ @Override
+ void ratingChange(int rating) {
+ ratingBar.setRating(album.getRating());
+ }
+ });
+ }
+ });
+ } else {
+ ratingBar.setVisibility(View.GONE);
+ }
}
if(add) {
diff --git a/src/github/daneren2005/dsub/fragments/SubsonicFragment.java b/src/github/daneren2005/dsub/fragments/SubsonicFragment.java index 8918baee..7ff25d2d 100644 --- a/src/github/daneren2005/dsub/fragments/SubsonicFragment.java +++ b/src/github/daneren2005/dsub/fragments/SubsonicFragment.java @@ -671,9 +671,15 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR dialog.show();
}
- public void toggleStarred(final Entry entry) {
+ public void toggleStarred(Entry entry) {
+ toggleStarred(entry, null);
+ }
+ public void toggleStarred(final Entry entry, final OnStarChange onStarChange) {
final boolean starred = !entry.isStarred();
entry.setStarred(starred);
+ if(onStarChange != null) {
+ onStarChange.starChange(starred);
+ }
new SilentBackgroundTask<Void>(context) {
@Override
@@ -709,6 +715,9 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR protected void error(Throwable error) {
Log.w(TAG, "Failed to star", error);
entry.setStarred(!starred);
+ if(onStarChange != null) {
+ onStarChange.starChange(!starred);
+ }
String msg;
if (error instanceof OfflineException || error instanceof ServerTooOldException) {
@@ -1529,8 +1538,11 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR }
});
}
-
- protected void setRating(final Entry entry) {
+
+ protected void setRating(Entry entry) {
+ setRating(entry, null);
+ }
+ protected void setRating(final Entry entry, final OnRatingChange onRatingChange) {
View layout = context.getLayoutInflater().inflate(R.layout.rating, null);
final RatingBar ratingBar = (RatingBar) layout.findViewById(R.id.rating_bar);
ratingBar.setRating((float) entry.getRating());
@@ -1542,7 +1554,7 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR @Override
public void onClick(DialogInterface dialog, int id) {
int rating = (int) ratingBar.getRating();
- setRating(entry, rating);
+ setRating(entry, rating, onRatingChange);
}
})
.setNegativeButton(R.string.common_cancel, null);
@@ -1551,9 +1563,16 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR dialog.show();
}
- protected void setRating(final Entry entry, final int rating) {
+ protected void setRating(Entry entry, int rating) {
+ setRating(entry, rating, null);
+ }
+ protected void setRating(final Entry entry, final int rating, final OnRatingChange onRatingChange) {
final int oldRating = entry.getRating();
entry.setRating(rating);
+
+ if(onRatingChange != null) {
+ onRatingChange.ratingChange(rating);
+ }
new SilentBackgroundTask<Void>(context) {
@Override
@@ -1578,6 +1597,9 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR @Override
protected void error(Throwable error) {
entry.setRating(oldRating);
+ if(onRatingChange != null) {
+ onRatingChange.ratingChange(oldRating);
+ }
String msg;
if (error instanceof OfflineException || error instanceof ServerTooOldException) {
@@ -1624,4 +1646,11 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR }
}
}
+
+ public abstract class OnRatingChange {
+ abstract void ratingChange(int rating);
+ }
+ public abstract class OnStarChange {
+ abstract void starChange(boolean starred);
+ }
}
diff --git a/src/github/daneren2005/dsub/util/Constants.java b/src/github/daneren2005/dsub/util/Constants.java index ac21df4c..f22fd3f0 100644 --- a/src/github/daneren2005/dsub/util/Constants.java +++ b/src/github/daneren2005/dsub/util/Constants.java @@ -37,6 +37,8 @@ public final class Constants { // Names for intent extras. public static final String INTENT_EXTRA_NAME_ID = "subsonic.id"; public static final String INTENT_EXTRA_NAME_NAME = "subsonic.name"; + public static final String INTENT_EXTRA_NAME_STARRED = "subsonic.starred"; + public static final String INTENT_EXTRA_NAME_RATING = "subsonic.rating"; public static final String INTENT_EXTRA_NAME_CHILD_ID = "subsonic.child.id"; public static final String INTENT_EXTRA_NAME_ARTIST = "subsonic.artist"; public static final String INTENT_EXTRA_NAME_TITLE = "subsonic.title"; @@ -73,8 +75,6 @@ public final class Constants { public static final String PREFERENCES_KEY_SERVER_URL = "serverUrl"; public static final String PREFERENCES_KEY_SERVER_INTERNAL_URL = "serverInternalUrl"; public static final String PREFERENCES_KEY_SERVER_LOCAL_NETWORK_SSID = "serverLocalNetworkSSID"; - public static final String PREFERENCES_KEY_SERVER_VERSION = "serverVersion"; - public static final String PREFERENCES_KEY_SERVER_TYPE = "serverType"; public static final String PREFERENCES_KEY_TEST_CONNECTION = "serverTestConnection"; public static final String PREFERENCES_KEY_OPEN_BROWSER = "openBrowser"; public static final String PREFERENCES_KEY_MUSIC_FOLDER_ID = "musicFolderId"; diff --git a/src/github/daneren2005/dsub/view/AlbumCell.java b/src/github/daneren2005/dsub/view/AlbumCell.java index 0ad6861b..d6a18205 100644 --- a/src/github/daneren2005/dsub/view/AlbumCell.java +++ b/src/github/daneren2005/dsub/view/AlbumCell.java @@ -97,4 +97,8 @@ public class AlbumCell extends UpdateView { isStarred = album.isStarred();
isRated = album.getRating();
}
+
+ public MusicDirectory.Entry getEntry() {
+ return album;
+ }
}
diff --git a/src/github/daneren2005/dsub/view/AlbumView.java b/src/github/daneren2005/dsub/view/AlbumView.java index 27a3c8a1..7785a8af 100644 --- a/src/github/daneren2005/dsub/view/AlbumView.java +++ b/src/github/daneren2005/dsub/view/AlbumView.java @@ -96,4 +96,8 @@ public class AlbumView extends UpdateView { isStarred = album.isStarred();
isRated = album.getRating();
}
+
+ public MusicDirectory.Entry getEntry() {
+ return album;
+ }
}
diff --git a/src/github/daneren2005/dsub/view/UpdateView.java b/src/github/daneren2005/dsub/view/UpdateView.java index 8ca3f29a..c491fc6d 100644 --- a/src/github/daneren2005/dsub/view/UpdateView.java +++ b/src/github/daneren2005/dsub/view/UpdateView.java @@ -221,11 +221,17 @@ public class UpdateView extends LinearLayout { public static MusicDirectory.Entry findEntry(MusicDirectory.Entry entry) {
for(UpdateView view: INSTANCES.keySet()) {
+ MusicDirectory.Entry check = null;
if(view instanceof SongView) {
- MusicDirectory.Entry check = ((SongView) view).getEntry();
- if(check != null && entry != check && check.getId().equals(entry.getId())) {
- return check;
- }
+ check = ((SongView) view).getEntry();
+ } else if(view instanceof AlbumCell) {
+ check = ((AlbumCell) view).getEntry();
+ } else if(view instanceof AlbumView) {
+ check = ((AlbumView) view).getEntry();
+ }
+
+ if(check != null && entry != check && check.getId().equals(entry.getId())) {
+ return check;
}
}
|