From b06d889c100cfb249e6b9bfe957e2dc1eab81144 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Fri, 21 Feb 2014 23:29:56 +0100 Subject: [PATCH] Added scrolling to current track on notification click. --- .../nutomic/controldlna/gui/MainActivity.java | 4 ++- .../controldlna/gui/RouteFragment.java | 26 +++++++++---------- .../mediarouter/MediaRouterPlayService.java | 2 +- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/com/github/nutomic/controldlna/gui/MainActivity.java b/src/com/github/nutomic/controldlna/gui/MainActivity.java index ddb7b24..9fcc689 100644 --- a/src/com/github/nutomic/controldlna/gui/MainActivity.java +++ b/src/com/github/nutomic/controldlna/gui/MainActivity.java @@ -182,8 +182,10 @@ public class MainActivity extends ActionBarActivity { */ @Override protected void onNewIntent(Intent intent) { - if (intent.getAction().equals("showRouteFragment")) + if (intent.getAction().equals("showRouteFragment")) { mViewPager.setCurrentItem(1); + mRouteFragment.scrollToCurrent(); + } } /** diff --git a/src/com/github/nutomic/controldlna/gui/RouteFragment.java b/src/com/github/nutomic/controldlna/gui/RouteFragment.java index c3ed0e5..b9c7668 100644 --- a/src/com/github/nutomic/controldlna/gui/RouteFragment.java +++ b/src/com/github/nutomic/controldlna/gui/RouteFragment.java @@ -80,8 +80,8 @@ import com.github.nutomic.controldlna.utility.RouteAdapter; * */ public class RouteFragment extends MediaRouteDiscoveryFragment implements - OnBackPressedListener, OnItemClickListener, OnClickListener, - OnSeekBarChangeListener, OnScrollListener { +OnBackPressedListener, OnItemClickListener, OnClickListener, +OnSeekBarChangeListener, OnScrollListener { private ListView mListView; @@ -122,7 +122,7 @@ public class RouteFragment extends MediaRouteDiscoveryFragment implements mMediaRouterPlayService = (MediaRouterPlayServiceBinder) service; mMediaRouterPlayService.getService().setRouterFragment(RouteFragment.this); mPlaylistAdapter.add(mMediaRouterPlayService.getService().getPlaylist()); - receiveIsPlaying(mMediaRouterPlayService.getService().getCurrentTrack()); + scrollToCurrent(); applyColors(); RouteInfo currentRoute = mMediaRouterPlayService.getService().getCurrentRoute(); if (currentRoute != null) @@ -399,7 +399,7 @@ public class RouteFragment extends MediaRouteDiscoveryFragment implements changePlayPauseState(false); } else { s.resume(); - mListView.smoothScrollToPosition(s.getCurrentTrack()); + scrollToCurrent(); changePlayPauseState(true); } break; @@ -532,15 +532,6 @@ public class RouteFragment extends MediaRouteDiscoveryFragment implements : "0" + Integer.toString(seconds)); } - /** - * Sent by MediaRouterPlayService when playback of a new track is started. - * - * @param track Index of the track in the playlist. - */ - public void receiveIsPlaying(int track) { - mListView.smoothScrollToPosition(track); - } - /** * Receives information from MediaRouterPlayService about playback status. */ @@ -587,4 +578,13 @@ public class RouteFragment extends MediaRouteDiscoveryFragment implements } } + + /** + * When in playlist mode, scrolls to the item that is currently playing. + */ + public void scrollToCurrent() { + mListView.smoothScrollToPosition( + mMediaRouterPlayService.getService().getCurrentTrack()); + } + } diff --git a/src/com/github/nutomic/controldlna/mediarouter/MediaRouterPlayService.java b/src/com/github/nutomic/controldlna/mediarouter/MediaRouterPlayService.java index 6708b3b..81f5704 100644 --- a/src/com/github/nutomic/controldlna/mediarouter/MediaRouterPlayService.java +++ b/src/com/github/nutomic/controldlna/mediarouter/MediaRouterPlayService.java @@ -239,7 +239,7 @@ public class MediaRouterPlayService extends Service { .getFirstPropertyValue(DIDLObject.Property.UPNP.ALBUM_ART_URI.class)); if (mRouterFragment.get() != null) - mRouterFragment.get().receiveIsPlaying(mCurrentTrack); + mRouterFragment.get().scrollToCurrent(); } }); }