Skip to content

Commit

Permalink
Fix rendering after deleting playlist items
Browse files Browse the repository at this point in the history
Fixes #910
  • Loading branch information
vrih committed Nov 18, 2018
1 parent 5076b67 commit 410c0dc
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 7 deletions.
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

0 comments on commit 410c0dc

Please sign in to comment.