Refactored ListView mode changes into seperate methods.
This commit is contained in:
parent
956a16c5cc
commit
33c6eababa
3 changed files with 72 additions and 48 deletions
|
@ -179,14 +179,9 @@ public class RouteFragment extends MediaRouteDiscoveryFragment implements
|
|||
|
||||
if (savedInstanceState != null) {
|
||||
mListView.onRestoreInstanceState(savedInstanceState.getParcelable("list_state"));
|
||||
if (savedInstanceState.getBoolean("route_selected")) {
|
||||
mSelectedRoute = MediaRouter.getInstance(getActivity())
|
||||
.getSelectedRoute();
|
||||
mListView.setAdapter(mPlaylistAdapter);
|
||||
mControls.setVisibility(View.VISIBLE);
|
||||
TextView emptyView = (TextView) mListView.getEmptyView();
|
||||
emptyView.setText(R.string.playlist_empty);
|
||||
}
|
||||
if (savedInstanceState.getBoolean("route_selected"))
|
||||
playlistMode(MediaRouter.getInstance(getActivity())
|
||||
.getSelectedRoute());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -274,22 +269,40 @@ public class RouteFragment extends MediaRouteDiscoveryFragment implements
|
|||
*/
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> a, View v, final int position, long id) {
|
||||
if (mListView.getAdapter() == mRouteAdapter) {
|
||||
mSelectedRoute = mRouteAdapter.getItem(position);
|
||||
mMediaRouterPlayService.getService().selectRoute(mSelectedRoute);
|
||||
mListView.setAdapter(mPlaylistAdapter);
|
||||
mControls.setVisibility(View.VISIBLE);
|
||||
if (mStartPlayingOnSelect != -1) {
|
||||
mMediaRouterPlayService.getService().play(mStartPlayingOnSelect);
|
||||
mStartPlayingOnSelect = -1;
|
||||
}
|
||||
TextView emptyView = (TextView) mListView.getEmptyView();
|
||||
emptyView.setText(R.string.playlist_empty);
|
||||
}
|
||||
if (mListView.getAdapter() == mRouteAdapter)
|
||||
playlistMode(mRouteAdapter.getItem(position));
|
||||
else
|
||||
mMediaRouterPlayService.getService().play(position);
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays UPNP devices in the ListView.
|
||||
*/
|
||||
private void deviceListMode() {
|
||||
mControls.setVisibility(View.GONE);
|
||||
mListView.setAdapter(mRouteAdapter);
|
||||
disableTrackHighlight();
|
||||
mSelectedRoute = null;
|
||||
TextView emptyView = (TextView) mListView.getEmptyView();
|
||||
emptyView.setText(R.string.device_list_empty);
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays playlist for route in the ListView.
|
||||
*/
|
||||
private void playlistMode(RouteInfo route) {
|
||||
mSelectedRoute = route;
|
||||
mMediaRouterPlayService.getService().selectRoute(mSelectedRoute);
|
||||
mListView.setAdapter(mPlaylistAdapter);
|
||||
mControls.setVisibility(View.VISIBLE);
|
||||
if (mStartPlayingOnSelect != -1) {
|
||||
mMediaRouterPlayService.getService().play(mStartPlayingOnSelect);
|
||||
mStartPlayingOnSelect = -1;
|
||||
}
|
||||
TextView emptyView = (TextView) mListView.getEmptyView();
|
||||
emptyView.setText(R.string.playlist_empty);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets colored background on the item that is currently playing.
|
||||
*/
|
||||
|
@ -330,25 +343,14 @@ public class RouteFragment extends MediaRouteDiscoveryFragment implements
|
|||
public void onClick(DialogInterface dialog,
|
||||
int which) {
|
||||
mMediaRouterPlayService.getService().stop();
|
||||
mControls.setVisibility(View.GONE);
|
||||
mListView.setAdapter(mRouteAdapter);
|
||||
disableTrackHighlight();
|
||||
mSelectedRoute = null;
|
||||
TextView emptyView = (TextView) mListView.getEmptyView();
|
||||
emptyView.setText(R.string.device_list_empty);
|
||||
deviceListMode();
|
||||
}
|
||||
})
|
||||
.setNegativeButton(android.R.string.no, null)
|
||||
.show();
|
||||
}
|
||||
else {
|
||||
mControls.setVisibility(View.GONE);
|
||||
mListView.setAdapter(mRouteAdapter);
|
||||
disableTrackHighlight();
|
||||
mSelectedRoute = null;
|
||||
TextView emptyView = (TextView) mListView.getEmptyView();
|
||||
emptyView.setText(R.string.device_list_empty);
|
||||
}
|
||||
else
|
||||
deviceListMode();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -215,13 +215,8 @@ public class ServerFragment extends ListFragment implements OnBackPressedListene
|
|||
*/
|
||||
@Override
|
||||
public void onListItemClick(ListView l, View v, int position, long id) {
|
||||
if (getListAdapter() == mServerAdapter) {
|
||||
setListAdapter(mFileAdapter);
|
||||
mCurrentServer = mServerAdapter.getItem(position);
|
||||
getFiles(ROOT_DIRECTORY);
|
||||
TextView emptyView = (TextView) getListView().getEmptyView();
|
||||
emptyView.setText(R.string.folder_list_etmpy);
|
||||
}
|
||||
if (getListAdapter() == mServerAdapter)
|
||||
browsingMode(mServerAdapter.getItem(position));
|
||||
else if (getListAdapter() == mFileAdapter) {
|
||||
if (mFileAdapter.getItem(position) instanceof Container)
|
||||
getFiles(((Container) mFileAdapter.getItem(position)).getId());
|
||||
|
@ -237,6 +232,27 @@ public class ServerFragment extends ListFragment implements OnBackPressedListene
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays available servers in the ListView.
|
||||
*/
|
||||
private void serverMode() {
|
||||
setListAdapter(mServerAdapter);
|
||||
getListView().onRestoreInstanceState(mListState.peek());
|
||||
mCurrentServer = null;
|
||||
TextView emptyView = (TextView) getListView().getEmptyView();
|
||||
emptyView.setText(R.string.device_list_empty);
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays files for server (starting from root).
|
||||
*/
|
||||
private void browsingMode(Device<?, ?, ?> server) {
|
||||
setListAdapter(mFileAdapter);
|
||||
mCurrentServer = server;
|
||||
getFiles(ROOT_DIRECTORY);
|
||||
TextView emptyView = (TextView) getListView().getEmptyView();
|
||||
emptyView.setText(R.string.folder_list_etmpy);
|
||||
}
|
||||
/**
|
||||
* Opens a new directory and displays it.
|
||||
*/
|
||||
|
@ -307,13 +323,8 @@ public class ServerFragment extends ListFragment implements OnBackPressedListene
|
|||
|
||||
mCurrentPath.pop();
|
||||
mListState.pop();
|
||||
if (mCurrentPath.empty()) {
|
||||
setListAdapter(mServerAdapter);
|
||||
getListView().onRestoreInstanceState(mListState.peek());
|
||||
mCurrentServer = null;
|
||||
TextView emptyView = (TextView) getListView().getEmptyView();
|
||||
emptyView.setText(R.string.device_list_empty);
|
||||
}
|
||||
if (mCurrentPath.empty())
|
||||
serverMode();
|
||||
else
|
||||
getFiles(true);
|
||||
return true;
|
||||
|
|
|
@ -292,14 +292,25 @@ public class MediaRouterPlayService extends Service {
|
|||
mPlaylist = playlist;
|
||||
}
|
||||
|
||||
/**
|
||||
* Plays the track after current in the playlist.
|
||||
*/
|
||||
public void playNext() {
|
||||
play(mCurrentTrack + 1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Plays the track before current in the playlist.
|
||||
*/
|
||||
public void playPrevious() {
|
||||
play(mCurrentTrack - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns index of the track that is currently played (zero-based).
|
||||
* @return
|
||||
*/
|
||||
public int getCurrentTrack() {
|
||||
return mCurrentTrack;
|
||||
}
|
||||
|
|
Reference in a new issue