Commit 96594af8 authored by Jean-Baptiste Kempf's avatar Jean-Baptiste Kempf

Move AudioListActivity to Fragment

parent de7060b9
......@@ -51,6 +51,7 @@ import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.util.Log;
import android.view.View;
......@@ -499,9 +500,11 @@ public class MainActivity extends SherlockFragmentActivity {
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
if (mTag.equalsIgnoreCase("video"))
ft.setCustomAnimations(R.anim.anim_enter_left, R.anim.anim_leave_left);
else if (mTag.equalsIgnoreCase("audio"))
else if (mTag.equalsIgnoreCase("audio")) {
ft.setCustomAnimations(R.anim.anim_enter_right, R.anim.anim_leave_right);
mActivity.getSupportFragmentManager().popBackStack();
}
if (mFragment != null) {
ft.detach(mFragment);
}
......
......@@ -65,6 +65,7 @@ import android.widget.HorizontalScrollView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.support.v4.app.FragmentTransaction;
import com.actionbarsherlock.app.SherlockFragment;
......@@ -209,10 +210,19 @@ public class AudioBrowserFragment extends SherlockFragment implements ISortable
return false;
String name = adapter.getGroup(groupPosition);
Intent intent = new Intent(getActivity(), AudioListActivity.class);
AudioListActivity.set(intent, name, null, mFlingViewGroup.getPosition());
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
AudioListActivity audioList = new AudioListActivity();
Bundle b = new Bundle();
b.putString(AudioListActivity.EXTRA_NAME, name);
b.putString(AudioListActivity.EXTRA_NAME2, null);
b.putInt(AudioListActivity.EXTRA_MODE, mFlingViewGroup.getPosition());
audioList.setArguments(b);
FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
ft.replace(R.id.fragment_placeholder, audioList);
ft.addToBackStack(null);
ft.commit();
return true;
}
};
......@@ -223,10 +233,19 @@ public class AudioBrowserFragment extends SherlockFragment implements ISortable
AudioPlaylistAdapter adapter = (AudioPlaylistAdapter) elv.getExpandableListAdapter();
String name = adapter.getGroup(groupPosition);
String child = adapter.getChild(groupPosition, childPosition);
Intent intent = new Intent(getActivity(), AudioListActivity.class);
AudioListActivity.set(intent, name, child, mFlingViewGroup.getPosition());
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
AudioListActivity audioList = new AudioListActivity();
Bundle b = new Bundle();
b.putString(AudioListActivity.EXTRA_NAME, name);
b.putString(AudioListActivity.EXTRA_NAME2, child);
b.putInt(AudioListActivity.EXTRA_MODE, mFlingViewGroup.getPosition());
audioList.setArguments(b);
FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
ft.replace(R.id.fragment_placeholder, audioList);
ft.addToBackStack(null);
ft.commit();
return false;
}
};
......
......@@ -40,17 +40,19 @@ import android.os.Handler;
import android.os.Message;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnCreateContextMenuListener;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.ListView;
import android.widget.TextView;
import com.actionbarsherlock.app.SherlockListActivity;
import com.actionbarsherlock.app.SherlockListFragment;
public class AudioListActivity extends SherlockListActivity {
public class AudioListActivity extends SherlockListFragment {
public final static String TAG = "VLC/AudioListActivity";
......@@ -69,38 +71,50 @@ public class AudioListActivity extends SherlockListActivity {
public final static String EXTRA_MODE = "mode";
@Override
protected void onCreate(Bundle savedInstanceState) {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.audio_list);
mAudioController = AudioServiceController.getInstance();
mMediaLibrary = MediaLibrary.getInstance(this);
mMediaLibrary = MediaLibrary.getInstance(getActivity());
mMediaLibrary.addUpdateHandler(mHandler);
mTitle = (TextView) findViewById(R.id.title);
mSongsAdapter = new AudioSongsListAdapter(this);
mSongsAdapter = new AudioSongsListAdapter(getActivity());
setListAdapter(mSongsAdapter);
getListView().setOnCreateContextMenuListener(contextMenuListener);
mHandler.sendEmptyMessageDelayed(MediaLibrary.MEDIA_ITEMS_UPDATED, 250);
}
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
getListView().setOnCreateContextMenuListener(contextMenuListener);
updateList();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.audio_list, container, false);
mTitle = (TextView) v.findViewById(R.id.title);
return v;
}
@Override
protected void onResume() {
AudioServiceController.getInstance().bindAudioService(this);
public void onResume() {
AudioServiceController.getInstance().bindAudioService(getActivity());
super.onResume();
}
@Override
protected void onPause() {
AudioServiceController.getInstance().unbindAudioService(this);
public void onPause() {
AudioServiceController.getInstance().unbindAudioService(getActivity());
super.onPause();
}
@Override
protected void onDestroy() {
public void onDestroy() {
mMediaLibrary.removeUpdateHandler(mHandler);
mSongsAdapter.clear();
super.onDestroy();
......@@ -113,9 +127,9 @@ public class AudioListActivity extends SherlockListActivity {
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
public void onListItemClick(ListView l, View v, int position, long id) {
mAudioController.load(mSongsAdapter.getLocations(), position);
Intent intent = new Intent(AudioListActivity.this, AudioPlayerActivity.class);
Intent intent = new Intent(getActivity(), AudioPlayerActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
super.onListItemClick(l, v, position, id);
......@@ -134,7 +148,7 @@ public class AudioListActivity extends SherlockListActivity {
};
public void deleteMedia( final List<String> addressMedia, final Media aMedia ) {
AlertDialog alertDialog = new AlertDialog.Builder(this)
AlertDialog alertDialog = new AlertDialog.Builder(getActivity())
.setTitle(R.string.confirm_delete)
.setMessage(R.string.validation)
.setIcon(android.R.drawable.ic_dialog_alert)
......@@ -187,7 +201,7 @@ public class AudioListActivity extends SherlockListActivity {
else
mAudioController.load(medias, startPosition);
Intent intent = new Intent(AudioListActivity.this, AudioPlayerActivity.class);
Intent intent = new Intent(getActivity(), AudioPlayerActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
return super.onContextItemSelected(item);
......@@ -226,9 +240,11 @@ public class AudioListActivity extends SherlockListActivity {
};
private void updateList() {
String name = getIntent().getStringExtra(EXTRA_NAME);
String name2 = getIntent().getStringExtra(EXTRA_NAME2);
int mode = getIntent().getIntExtra(EXTRA_MODE, 0);
final Bundle b = getArguments();
String name = b.getString(EXTRA_NAME);
String name2 = b.getString(EXTRA_NAME2);
int mode = b.getInt(EXTRA_MODE, 0);
List<Media> audioList;
List<String> itemList;
String currentItem = null;
......@@ -238,11 +254,11 @@ public class AudioListActivity extends SherlockListActivity {
mTitle.setText(R.string.songs);
itemList = AudioServiceController.getInstance().getItems();
currentItem = AudioServiceController.getInstance().getItem();
audioList = MediaLibrary.getInstance(this).getMediaItems(itemList);
audioList = MediaLibrary.getInstance(getActivity()).getMediaItems(itemList);
}
else {
mTitle.setText(name2 != null ? name2 : name);
audioList = MediaLibrary.getInstance(this).getAudioItems(name, name2, mode);
audioList = MediaLibrary.getInstance(getActivity()).getAudioItems(name, name2, mode);
}
mSongsAdapter.clear();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment