private HashSet getOpenedPlaylists() { HashSet<String> myHashSet = new HashSet<>(); for (AbstractSong data : getAllItems()) { if (data.getClass() == PlaylistData.class && ((PlaylistData) data).isExpanded()) { myHashSet.add(String.valueOf(data.getId())); } } return myHashSet; }
public PlaylistData getPlaylistBySong(MusicData song) { for (AbstractSong playlistData : getAllItems()) { if (playlistData.getClass() == PlaylistData.class && ((PlaylistData) playlistData).getSongs().contains(song)) { return ((PlaylistData) playlistData); } } return null; }
public void updatePlaylist() { ArrayList<AbstractSong> playlists = getPlaylists(); for (AbstractSong playlistData : playlists) { ((PlaylistData) playlistData) .setSongs( ((PlaylistData) playlistData) .getSongsFromPlaylist(getContext(), playlistData.getId())); } updateAdapter(playlists); }
public void collapseAll() { ArrayList<MusicData> music = new ArrayList<>(); ArrayList<AbstractSong> playlists = getAllItems(); for (AbstractSong data : playlists) { if (data.getClass() == MusicData.class) { music.add((MusicData) data); } else { ((PlaylistData) data).setExpanded(false); } } playlists.removeAll(music); updateAdapter(playlists); }
private void setOpened() { ArrayList<AbstractSong> allItems = getAllItems(); HashSet<String> myHashSet = (HashSet<String>) MusicApp.getSharedPreferences().getStringSet(PREF_LAST_OPENED, new HashSet<String>()); for (AbstractSong data : getAllItems()) { if (data.getClass() == PlaylistData.class && myHashSet.contains(String.valueOf(data.getId()))) { if (((PlaylistData) data).getSongs().size() == 0 || ((PlaylistData) data).isExpanded()) continue; allItems.addAll(allItems.indexOf(data) + 1, ((PlaylistData) data).getSongs()); ((PlaylistData) data).setExpanded(true); } } updateAdapter(allItems); }
@Override protected void hold(AbstractSong data, int position) { super.hold(data, position); if (data.getClass() == PlaylistData.class) { ((ImageView) customGroupIndicator) .setImageDrawable( getContext() .getResources() .getDrawable( ((PlaylistData) data).isExpanded() ? R.drawable.ic_keyboard_arrow_up_black_18dp : R.drawable.ic_keyboard_arrow_down_black_18dp)); } }
protected void showDialog() { final ArrayList<String> playlistNames = new ArrayList<>(); for (AbstractSong abstractSong : getAllItems()) { if (abstractSong.getClass() == PlaylistData.class) { playlistNames.add(((PlaylistData) abstractSong).getName()); } } final View dialoglayout = LayoutInflater.from(getContext()).inflate(R.layout.playlist_create_new_dialog, null); newPlaylistDialog = new AlertDialog.Builder(getContext()); newPlaylistDialog.setView(dialoglayout); newPlaylistDialog.setNegativeButton( R.string.edit_mp3_cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Util.hideKeyboard(getContext(), dialoglayout); dialog.cancel(); } }); newPlaylistDialog.setPositiveButton( R.string.create, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String newTitle = ((EditText) dialoglayout.findViewById(R.id.newPlaylistET)) .getText() .toString() .trim(); if (newTitle.isEmpty()) { showMessage(getContext(), R.string.playlist_cannot_be_empty); return; } for (AbstractSong data : getAllItems()) { if (data.getClass() == PlaylistData.class && ((PlaylistData) data).getName().equals(newTitle)) { showMessage(getContext(), R.string.playlist_already_exists); return; } } createPlaylist(getContext().getContentResolver(), newTitle); Util.hideKeyboard(getContext(), dialoglayout); dialog.cancel(); } }); dialog = newPlaylistDialog.create(); dialog.setCancelable(false); EditText editText = (EditText) dialoglayout.findViewById(R.id.newPlaylistET); final TextView errorView = (TextView) dialoglayout.findViewById(R.id.errorView); editText.addTextChangedListener( new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) {} @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) {} @Override public void afterTextChanged(Editable s) { if (playlistNames.contains(s.toString().trim())) { dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false); errorView.setText(R.string.playlist_already_exists); errorView.setVisibility(View.VISIBLE); } else { dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(true); errorView.setText(""); errorView.setVisibility(View.GONE); } } }); dialog.show(); }