Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix rendering after deleting playlist items #912

Open
wants to merge 1 commit into
base: edge
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package github.daneren2005.dsub.adapter;


import android.content.Context;
import android.test.AndroidTestCase;
import android.test.mock.MockContext;
import android.util.Log;
import android.view.View;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import github.daneren2005.dsub.domain.MusicDirectory.Entry;


public class EntryGridAdapterTest extends AndroidTestCase {
private EntryGridAdapter mAdapter;


public EntryGridAdapterTest() {
super();
}

protected void setUp() throws Exception {
super.setUp();
}

public void testRemoveAt() {
Entry a = new Entry("a");
Entry c = new Entry("c");

List<Entry> section = new ArrayList<>(Arrays.asList(
a,
new Entry("b"),
c,
new Entry("d"),
new Entry("e")));
mAdapter = new EntryGridAdapter(null, section, null, false);

mAdapter.removeAt(Arrays.asList(1, 3, 4));
assertEquals(new ArrayList<>(Arrays.asList(a, c)), section);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import android.view.View;
import android.view.ViewGroup;

import java.util.Iterator;
import java.util.List;

import github.daneren2005.dsub.R;
Expand Down Expand Up @@ -129,12 +130,20 @@ public void setShowAlbum(boolean showAlbum) {
this.showAlbum = showAlbum;
}

public void removeAt(int index) {
sections.get(0).remove(index);
if(header != null) {
public void removeAt(List<Integer> indices) {
List<Entry> section = sections.get(0);

Iterator iter = section.iterator();
int index = 0;

while (iter.hasNext()) {
iter.next();
if (indices.contains(index)){
iter.remove();
}
index++;
}
notifyItemRemoved(index);
notifyDataSetChanged();
}

public void setRemoveFromPlaylist(boolean removeFromPlaylist) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -917,9 +917,7 @@ protected Void doInBackground() throws Throwable {

@Override
protected void done(Void result) {
for(Integer index: indexes) {
entryGridAdapter.removeAt(index);
}
entryGridAdapter.removeAt(indexes);
Util.toast(context, context.getResources().getString(R.string.removed_playlist, String.valueOf(indexes.size()), name));
}

Expand Down