mirror of
https://github.com/playmusicexporter/playmusicexporter
synced 2024-05-14 00:46:42 +00:00
Add select all button
Do not close activity on deselect or export
This commit is contained in:
parent
c6fc6493ef
commit
3a97bbebc1
|
@ -120,11 +120,13 @@ public abstract class SelectionList<T> {
|
|||
// Set the selection state
|
||||
setSelected(item, state);
|
||||
|
||||
// Change the background
|
||||
if (state)
|
||||
view.setBackgroundColor(view.getResources().getColor(mResColorSelected));
|
||||
else
|
||||
view.setBackgroundColor(view.getResources().getColor(mResColorNormal));
|
||||
if (view != null) {
|
||||
// Change the background
|
||||
if (state)
|
||||
view.setBackgroundColor(view.getResources().getColor(mResColorSelected));
|
||||
else
|
||||
view.setBackgroundColor(view.getResources().getColor(mResColorNormal));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -48,6 +48,11 @@ public class ActionModeTitle implements ActionMode.Callback {
|
|||
*/
|
||||
private SelectedTrackList mSelectionList;
|
||||
|
||||
/**
|
||||
* Flag to not close the activity when action mode is closing
|
||||
*/
|
||||
private boolean mDoNotCloseActivity;
|
||||
|
||||
public ActionModeTitle(Context context, SelectedTrackList selectionList) {
|
||||
mContext = context;
|
||||
mSelectionList = selectionList;
|
||||
|
@ -87,13 +92,25 @@ public class ActionModeTitle implements ActionMode.Callback {
|
|||
selectedTrack.export(mContext);
|
||||
}
|
||||
|
||||
// Do not close the activity
|
||||
mDoNotCloseActivity = true;
|
||||
|
||||
// Clear the selection
|
||||
SelectedTrackList.getInstance().clear();
|
||||
return true;
|
||||
case R.id.action_select_all:
|
||||
// We are in the track list
|
||||
if (mSelectionList.getActivity() instanceof MusicTrackListActivity) {
|
||||
MusicTrackListActivity trackDetailActivity = (MusicTrackListActivity)mSelectionList.getActivity();
|
||||
|
||||
trackDetailActivity.selectAll();
|
||||
}
|
||||
|
||||
// Close the action mode
|
||||
//mode.finish();
|
||||
return true;
|
||||
case R.id.action_deselect_all:
|
||||
// Do not close the activity
|
||||
mDoNotCloseActivity = true;
|
||||
|
||||
// Clear the selection
|
||||
SelectedTrackList.getInstance().clear();
|
||||
|
||||
|
@ -127,7 +144,7 @@ public class ActionModeTitle implements ActionMode.Callback {
|
|||
@Override
|
||||
public void onDestroyActionMode(ActionMode mode) {
|
||||
// We are in the music track list
|
||||
if (mSelectionList.getActivity() instanceof MusicTrackListActivity) {
|
||||
if (mSelectionList.getActivity() instanceof MusicTrackListActivity && !mDoNotCloseActivity) {
|
||||
// Clear the action mode
|
||||
SelectedTrackList.getInstance().clearActionMode();
|
||||
|
||||
|
|
|
@ -136,4 +136,16 @@ public class MusicTrackListActivity extends AppCompatActivity {
|
|||
if (musicTrackDetailFragment != null)
|
||||
musicTrackDetailFragment.updateListView();
|
||||
}
|
||||
|
||||
/**
|
||||
* Select all items
|
||||
*/
|
||||
public void selectAll() {
|
||||
// Gets the music list fragment
|
||||
MusicTrackListFragment musicTrackDetailFragment = (MusicTrackListFragment) getSupportFragmentManager()
|
||||
.findFragmentById(R.id.track_detail_container);
|
||||
|
||||
if (musicTrackDetailFragment != null)
|
||||
musicTrackDetailFragment.selectAll();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -103,6 +103,7 @@ public class MusicContainerListFragment extends ListFragment {
|
|||
getListView().invalidateViews();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param list Set the list
|
||||
*/
|
||||
|
|
|
@ -72,6 +72,8 @@ public class MusicTrackListFragment extends Fragment {
|
|||
*/
|
||||
private ListView mListView;
|
||||
|
||||
private MusicTrackListAdapter mMusicTrackAdapter;
|
||||
|
||||
/**
|
||||
* Mandatory empty constructor for the fragment manager to instantiate the
|
||||
* fragment (e.g. upon screen orientation changes).
|
||||
|
@ -87,6 +89,20 @@ public class MusicTrackListFragment extends Fragment {
|
|||
mListView.invalidateViews();
|
||||
}
|
||||
|
||||
/**
|
||||
* Select all items
|
||||
*/
|
||||
public void selectAll() {
|
||||
// Select all tracks
|
||||
for(int i = 0; i < mMusicTrackAdapter.getCount(); i++ ) {
|
||||
MusicTrack musicTrack = mMusicTrackAdapter.getItem(i);
|
||||
|
||||
selectTrack(musicTrack, null, false);
|
||||
}
|
||||
|
||||
updateListView();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
@ -114,9 +130,9 @@ public class MusicTrackListFragment extends Fragment {
|
|||
// Show the dummy content as text in a TextView.
|
||||
if (mMusicTrackList != null) {
|
||||
mListView = (ListView)rootView.findViewById(R.id.list_music_track);
|
||||
final MusicTrackListAdapter musicTrackAdapter = new MusicTrackListAdapter(getActivity());
|
||||
mMusicTrackAdapter = new MusicTrackListAdapter(getActivity());
|
||||
|
||||
musicTrackAdapter.setShowArtworks(mMusicTrackList.getShowArtworkInTrack());
|
||||
mMusicTrackAdapter.setShowArtworks(mMusicTrackList.getShowArtworkInTrack());
|
||||
|
||||
View headerView = inflater.inflate(R.layout.header_music_track_list, mListView, false);
|
||||
headerView.setEnabled(false);
|
||||
|
@ -140,9 +156,9 @@ public class MusicTrackListFragment extends Fragment {
|
|||
|
||||
mListView.addHeaderView(headerView);
|
||||
|
||||
musicTrackAdapter.setList(mMusicTrackList.getMusicTrackList());
|
||||
mMusicTrackAdapter.setList(mMusicTrackList.getMusicTrackList());
|
||||
|
||||
mListView.setAdapter(musicTrackAdapter);
|
||||
mListView.setAdapter(mMusicTrackAdapter);
|
||||
|
||||
// Click on one list item
|
||||
mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
|
@ -154,29 +170,10 @@ public class MusicTrackListFragment extends Fragment {
|
|||
position -= 1;
|
||||
|
||||
// Gets the selected track
|
||||
MusicTrack musicTrack = musicTrackAdapter.getItem(position);
|
||||
MusicTrack musicTrack = mMusicTrackAdapter.getItem(position);
|
||||
|
||||
// Track is available
|
||||
if (musicTrack.isOfflineAvailable()) {
|
||||
|
||||
// Default structure
|
||||
String pathStructure = "{album-artist}/{album}/{disc=CD $}/{no=$$.} {title}.mp3";
|
||||
|
||||
// Track is exported from a group (playlist or artist)
|
||||
if (!TextUtils.isEmpty(musicTrack.getContainerName()))
|
||||
{
|
||||
pathStructure = "{group}/{group-no=$$.} {title}.mp3";
|
||||
}
|
||||
|
||||
// Build the path
|
||||
String path = MusicPathBuilder.Build(musicTrack, pathStructure);
|
||||
|
||||
// Path to the public music folder
|
||||
path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC) + "/" + path;
|
||||
|
||||
// Toggles the music track
|
||||
SelectedTrackList.getInstance().toggle(new SelectedTrack(musicTrack.getId(), path), view);
|
||||
}
|
||||
// Toggle the track
|
||||
selectTrack(musicTrack, view, true);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -184,4 +181,38 @@ public class MusicTrackListFragment extends Fragment {
|
|||
|
||||
return rootView;
|
||||
}
|
||||
|
||||
/**
|
||||
* Select a track
|
||||
* @param musicTrack The track
|
||||
* @param view The view
|
||||
* @param toggle If you want to toggle the selection set this to true
|
||||
*/
|
||||
private void selectTrack(MusicTrack musicTrack, View view, boolean toggle) {
|
||||
// Track is available
|
||||
if (musicTrack.isOfflineAvailable()) {
|
||||
|
||||
// Default structure
|
||||
String pathStructure = "{album-artist}/{album}/{disc=CD $}/{no=$$.} {title}.mp3";
|
||||
|
||||
// Track is exported from a group (playlist or artist)
|
||||
if (!TextUtils.isEmpty(musicTrack.getContainerName()))
|
||||
{
|
||||
pathStructure = "{group}/{group-no=$$.} {title}.mp3";
|
||||
}
|
||||
|
||||
// Build the path
|
||||
String path = MusicPathBuilder.Build(musicTrack, pathStructure);
|
||||
|
||||
// Path to the public music folder
|
||||
path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC) + "/" + path;
|
||||
|
||||
if (toggle) {
|
||||
// Toggles the music track
|
||||
SelectedTrackList.getInstance().toggle(new SelectedTrack(musicTrack.getId(), path), view);
|
||||
} else {
|
||||
SelectedTrackList.getInstance().setSelected(new SelectedTrack(musicTrack.getId(), path), true, view);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue