Removed unneeded indirection.
This commit is contained in:
parent
91719cf885
commit
b016780fca
1 changed files with 31 additions and 32 deletions
|
@ -114,17 +114,18 @@ OnSeekBarChangeListener, OnScrollListener {
|
||||||
*/
|
*/
|
||||||
private int mStartPlayingOnSelect = -1;
|
private int mStartPlayingOnSelect = -1;
|
||||||
|
|
||||||
private MediaRouterPlayServiceBinder mMediaRouterPlayService;
|
private MediaRouterPlayService mMediaRouterPlayService;
|
||||||
|
|
||||||
private ServiceConnection mPlayServiceConnection = new ServiceConnection() {
|
private ServiceConnection mPlayServiceConnection = new ServiceConnection() {
|
||||||
|
|
||||||
public void onServiceConnected(ComponentName className, IBinder service) {
|
public void onServiceConnected(ComponentName className, IBinder service) {
|
||||||
mMediaRouterPlayService = (MediaRouterPlayServiceBinder) service;
|
MediaRouterPlayServiceBinder binder = (MediaRouterPlayServiceBinder) service;
|
||||||
mMediaRouterPlayService.getService().setRouterFragment(RouteFragment.this);
|
mMediaRouterPlayService = binder.getService();
|
||||||
mPlaylistAdapter.add(mMediaRouterPlayService.getService().getPlaylist());
|
mMediaRouterPlayService.setRouterFragment(RouteFragment.this);
|
||||||
|
mPlaylistAdapter.add(mMediaRouterPlayService.getPlaylist());
|
||||||
scrollToCurrent();
|
scrollToCurrent();
|
||||||
applyColors();
|
applyColors();
|
||||||
RouteInfo currentRoute = mMediaRouterPlayService.getService().getCurrentRoute();
|
RouteInfo currentRoute = mMediaRouterPlayService.getCurrentRoute();
|
||||||
if (currentRoute != null)
|
if (currentRoute != null)
|
||||||
playlistMode(currentRoute);
|
playlistMode(currentRoute);
|
||||||
}
|
}
|
||||||
|
@ -139,8 +140,8 @@ OnSeekBarChangeListener, OnScrollListener {
|
||||||
*/
|
*/
|
||||||
public RouteFragment() {
|
public RouteFragment() {
|
||||||
MediaRouteSelector mSelector = new MediaRouteSelector.Builder()
|
MediaRouteSelector mSelector = new MediaRouteSelector.Builder()
|
||||||
.addControlCategory(MediaControlIntent.CATEGORY_REMOTE_PLAYBACK)
|
.addControlCategory(MediaControlIntent.CATEGORY_REMOTE_PLAYBACK)
|
||||||
.build();
|
.build();
|
||||||
setRouteSelector(mSelector);
|
setRouteSelector(mSelector);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -212,6 +213,7 @@ OnSeekBarChangeListener, OnScrollListener {
|
||||||
public void onSaveInstanceState(Bundle outState) {
|
public void onSaveInstanceState(Bundle outState) {
|
||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
|
|
||||||
|
//outState.putBoolean("route_selected", mSelectedRoute != null);
|
||||||
outState.putParcelable("list_state", mListView.onSaveInstanceState());
|
outState.putParcelable("list_state", mListView.onSaveInstanceState());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -298,7 +300,7 @@ OnSeekBarChangeListener, OnScrollListener {
|
||||||
if (mListView.getAdapter() == mRouteAdapter)
|
if (mListView.getAdapter() == mRouteAdapter)
|
||||||
playlistMode(mRouteAdapter.getItem(position));
|
playlistMode(mRouteAdapter.getItem(position));
|
||||||
else {
|
else {
|
||||||
mMediaRouterPlayService.getService().play(position);
|
mMediaRouterPlayService.play(position);
|
||||||
changePlayPauseState(true);
|
changePlayPauseState(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -320,11 +322,11 @@ OnSeekBarChangeListener, OnScrollListener {
|
||||||
*/
|
*/
|
||||||
private void playlistMode(RouteInfo route) {
|
private void playlistMode(RouteInfo route) {
|
||||||
mSelectedRoute = route;
|
mSelectedRoute = route;
|
||||||
mMediaRouterPlayService.getService().selectRoute(mSelectedRoute);
|
mMediaRouterPlayService.selectRoute(mSelectedRoute);
|
||||||
mListView.setAdapter(mPlaylistAdapter);
|
mListView.setAdapter(mPlaylistAdapter);
|
||||||
mControls.setVisibility(View.VISIBLE);
|
mControls.setVisibility(View.VISIBLE);
|
||||||
if (mStartPlayingOnSelect != -1) {
|
if (mStartPlayingOnSelect != -1) {
|
||||||
mMediaRouterPlayService.getService().play(mStartPlayingOnSelect);
|
mMediaRouterPlayService.play(mStartPlayingOnSelect);
|
||||||
changePlayPauseState(true);
|
changePlayPauseState(true);
|
||||||
mStartPlayingOnSelect = -1;
|
mStartPlayingOnSelect = -1;
|
||||||
}
|
}
|
||||||
|
@ -340,8 +342,7 @@ OnSeekBarChangeListener, OnScrollListener {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
disableTrackHighlight();
|
disableTrackHighlight();
|
||||||
mCurrentTrackView = mListView.getChildAt(mMediaRouterPlayService.getService()
|
mCurrentTrackView = mListView.getChildAt(mMediaRouterPlayService.getCurrentTrack()
|
||||||
.getCurrentTrack()
|
|
||||||
- mListView.getFirstVisiblePosition() + mListView.getHeaderViewsCount());
|
- mListView.getFirstVisiblePosition() + mListView.getHeaderViewsCount());
|
||||||
if (mCurrentTrackView != null)
|
if (mCurrentTrackView != null)
|
||||||
mCurrentTrackView.setBackgroundColor(
|
mCurrentTrackView.setBackgroundColor(
|
||||||
|
@ -371,7 +372,7 @@ OnSeekBarChangeListener, OnScrollListener {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog,
|
public void onClick(DialogInterface dialog,
|
||||||
int which) {
|
int which) {
|
||||||
mMediaRouterPlayService.getService().stop();
|
mMediaRouterPlayService.stop();
|
||||||
changePlayPauseState(false);
|
changePlayPauseState(false);
|
||||||
deviceListMode();
|
deviceListMode();
|
||||||
}
|
}
|
||||||
|
@ -390,20 +391,19 @@ OnSeekBarChangeListener, OnScrollListener {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
final MediaRouterPlayService s = mMediaRouterPlayService.getService();
|
|
||||||
switch (v.getId()) {
|
switch (v.getId()) {
|
||||||
case R.id.playpause:
|
case R.id.playpause:
|
||||||
if (mPlaying) {
|
if (mPlaying) {
|
||||||
s.pause();
|
mMediaRouterPlayService.pause();
|
||||||
changePlayPauseState(false);
|
changePlayPauseState(false);
|
||||||
} else {
|
} else {
|
||||||
s.resume();
|
mMediaRouterPlayService.resume();
|
||||||
scrollToCurrent();
|
scrollToCurrent();
|
||||||
changePlayPauseState(true);
|
changePlayPauseState(true);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case R.id.shuffle:
|
case R.id.shuffle:
|
||||||
s.toggleShuffleEnabled();
|
mMediaRouterPlayService.toggleShuffleEnabled();
|
||||||
applyColors();
|
applyColors();
|
||||||
break;
|
break;
|
||||||
case R.id.previous:
|
case R.id.previous:
|
||||||
|
@ -415,7 +415,7 @@ OnSeekBarChangeListener, OnScrollListener {
|
||||||
public void run() {
|
public void run() {
|
||||||
// Single tap.
|
// Single tap.
|
||||||
mPreviousTapCount = 0;
|
mPreviousTapCount = 0;
|
||||||
s.play(s.getCurrentTrack());
|
mMediaRouterPlayService.play(mMediaRouterPlayService.getCurrentTrack());
|
||||||
changePlayPauseState(true);
|
changePlayPauseState(true);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -424,15 +424,15 @@ OnSeekBarChangeListener, OnScrollListener {
|
||||||
else if(mPreviousTapCount == 2) {
|
else if(mPreviousTapCount == 2) {
|
||||||
// Double tap.
|
// Double tap.
|
||||||
mPreviousTapCount = 0;
|
mPreviousTapCount = 0;
|
||||||
s.playPrevious();
|
mMediaRouterPlayService.playPrevious();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case R.id.next:
|
case R.id.next:
|
||||||
boolean stillPlaying = s.playNext();
|
boolean stillPlaying = mMediaRouterPlayService.playNext();
|
||||||
changePlayPauseState(stillPlaying);
|
changePlayPauseState(stillPlaying);
|
||||||
break;
|
break;
|
||||||
case R.id.repeat:
|
case R.id.repeat:
|
||||||
s.toggleRepeatEnabled();
|
mMediaRouterPlayService.toggleRepeatEnabled();
|
||||||
applyColors();
|
applyColors();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -443,16 +443,15 @@ OnSeekBarChangeListener, OnScrollListener {
|
||||||
* if they are enabled or disabled).
|
* if they are enabled or disabled).
|
||||||
*/
|
*/
|
||||||
private void applyColors() {
|
private void applyColors() {
|
||||||
MediaRouterPlayService s = mMediaRouterPlayService.getService();
|
|
||||||
int highlight = getResources().getColor(R.color.button_highlight);
|
int highlight = getResources().getColor(R.color.button_highlight);
|
||||||
int transparent = getResources().getColor(android.R.color.transparent);
|
int transparent = getResources().getColor(android.R.color.transparent);
|
||||||
|
|
||||||
mShuffle.setColorFilter((s.getShuffleEnabled())
|
mShuffle.setColorFilter((mMediaRouterPlayService.getShuffleEnabled())
|
||||||
? highlight
|
? highlight
|
||||||
: transparent);
|
: transparent);
|
||||||
mRepeat.setColorFilter((s.getRepeatEnabled())
|
mRepeat.setColorFilter((mMediaRouterPlayService.getRepeatEnabled())
|
||||||
? highlight
|
? highlight
|
||||||
: transparent);
|
: transparent);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -462,7 +461,7 @@ OnSeekBarChangeListener, OnScrollListener {
|
||||||
public void onProgressChanged(SeekBar seekBar, int progress,
|
public void onProgressChanged(SeekBar seekBar, int progress,
|
||||||
boolean fromUser) {
|
boolean fromUser) {
|
||||||
if (fromUser)
|
if (fromUser)
|
||||||
mMediaRouterPlayService.getService().seek(progress);
|
mMediaRouterPlayService.seek(progress);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -487,11 +486,11 @@ OnSeekBarChangeListener, OnScrollListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void increaseVolume() {
|
public void increaseVolume() {
|
||||||
mMediaRouterPlayService.getService().increaseVolume();
|
mMediaRouterPlayService.increaseVolume();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void decreaseVolume() {
|
public void decreaseVolume() {
|
||||||
mMediaRouterPlayService.getService().decreaseVolume();
|
mMediaRouterPlayService.decreaseVolume();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -500,10 +499,10 @@ OnSeekBarChangeListener, OnScrollListener {
|
||||||
public void play(List<Item> playlist, int start) {
|
public void play(List<Item> playlist, int start) {
|
||||||
mPlaylistAdapter.clear();
|
mPlaylistAdapter.clear();
|
||||||
mPlaylistAdapter.add(playlist);
|
mPlaylistAdapter.add(playlist);
|
||||||
mMediaRouterPlayService.getService().setPlaylist(playlist);
|
mMediaRouterPlayService.setPlaylist(playlist);
|
||||||
|
|
||||||
if (mSelectedRoute != null) {
|
if (mSelectedRoute != null) {
|
||||||
mMediaRouterPlayService.getService().play(start);
|
mMediaRouterPlayService.play(start);
|
||||||
changePlayPauseState(true);
|
changePlayPauseState(true);
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(getActivity(), R.string.select_route, Toast.LENGTH_SHORT)
|
Toast.makeText(getActivity(), R.string.select_route, Toast.LENGTH_SHORT)
|
||||||
|
@ -584,7 +583,7 @@ OnSeekBarChangeListener, OnScrollListener {
|
||||||
public void scrollToCurrent() {
|
public void scrollToCurrent() {
|
||||||
if (mMediaRouterPlayService != null) {
|
if (mMediaRouterPlayService != null) {
|
||||||
mListView.smoothScrollToPosition(
|
mListView.smoothScrollToPosition(
|
||||||
mMediaRouterPlayService.getService().getCurrentTrack());
|
mMediaRouterPlayService.getCurrentTrack());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in a new issue