Added scrolling to current track on notification click.

This commit is contained in:
Felix Ableitner 2014-02-21 23:29:56 +01:00
parent 86b6179ad0
commit b06d889c10
3 changed files with 17 additions and 15 deletions

View file

@ -182,8 +182,10 @@ public class MainActivity extends ActionBarActivity {
*/ */
@Override @Override
protected void onNewIntent(Intent intent) { protected void onNewIntent(Intent intent) {
if (intent.getAction().equals("showRouteFragment")) if (intent.getAction().equals("showRouteFragment")) {
mViewPager.setCurrentItem(1); mViewPager.setCurrentItem(1);
mRouteFragment.scrollToCurrent();
}
} }
/** /**

View file

@ -122,7 +122,7 @@ public class RouteFragment extends MediaRouteDiscoveryFragment implements
mMediaRouterPlayService = (MediaRouterPlayServiceBinder) service; mMediaRouterPlayService = (MediaRouterPlayServiceBinder) service;
mMediaRouterPlayService.getService().setRouterFragment(RouteFragment.this); mMediaRouterPlayService.getService().setRouterFragment(RouteFragment.this);
mPlaylistAdapter.add(mMediaRouterPlayService.getService().getPlaylist()); mPlaylistAdapter.add(mMediaRouterPlayService.getService().getPlaylist());
receiveIsPlaying(mMediaRouterPlayService.getService().getCurrentTrack()); scrollToCurrent();
applyColors(); applyColors();
RouteInfo currentRoute = mMediaRouterPlayService.getService().getCurrentRoute(); RouteInfo currentRoute = mMediaRouterPlayService.getService().getCurrentRoute();
if (currentRoute != null) if (currentRoute != null)
@ -399,7 +399,7 @@ public class RouteFragment extends MediaRouteDiscoveryFragment implements
changePlayPauseState(false); changePlayPauseState(false);
} else { } else {
s.resume(); s.resume();
mListView.smoothScrollToPosition(s.getCurrentTrack()); scrollToCurrent();
changePlayPauseState(true); changePlayPauseState(true);
} }
break; break;
@ -532,15 +532,6 @@ public class RouteFragment extends MediaRouteDiscoveryFragment implements
: "0" + Integer.toString(seconds)); : "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. * 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());
}
} }

View file

@ -239,7 +239,7 @@ public class MediaRouterPlayService extends Service {
.getFirstPropertyValue(DIDLObject.Property.UPNP.ALBUM_ART_URI.class)); .getFirstPropertyValue(DIDLObject.Property.UPNP.ALBUM_ART_URI.class));
if (mRouterFragment.get() != null) if (mRouterFragment.get() != null)
mRouterFragment.get().receiveIsPlaying(mCurrentTrack); mRouterFragment.get().scrollToCurrent();
} }
}); });
} }