示例#1
0
 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;
 }
示例#2
0
 public PlaylistData getPlaylistBySong(MusicData song) {
   for (AbstractSong playlistData : getAllItems()) {
     if (playlistData.getClass() == PlaylistData.class
         && ((PlaylistData) playlistData).getSongs().contains(song)) {
       return ((PlaylistData) playlistData);
     }
   }
   return null;
 }
示例#3
0
 public void updatePlaylist() {
   ArrayList<AbstractSong> playlists = getPlaylists();
   for (AbstractSong playlistData : playlists) {
     ((PlaylistData) playlistData)
         .setSongs(
             ((PlaylistData) playlistData)
                 .getSongsFromPlaylist(getContext(), playlistData.getId()));
   }
   updateAdapter(playlists);
 }
示例#4
0
 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);
 }
示例#5
0
 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);
 }
示例#6
0
 @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));
   }
 }
示例#7
0
  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();
  }