<div dir="ltr"><div><div><div><div>Yes exactly,<br><br></div>And reinserting it at a wrong position could mess up the current sorting.<br></div>Or if item is added at the end of the list, user is likely to not see it showing back at all.<br><br></div><div>I don't have any good solution for this particular case.<br></div><div><br></div>At least, user is now warned by a snack that deletion failed. So user won't be surprised to see it appear later.<br><br></div>For successful reinsertion, we may use diffutil for safety.<br></div><br><div class="gmail_quote"><div dir="ltr">Le mar. 9 janv. 2018 à 16:06, Romain Vimont <<a href="mailto:rom@rom1v.com">rom@rom1v.com</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Tue, Jan 09, 2018 at 03:36:54PM +0100, Geoffrey Métais wrote:<br>
> vlc-android | branch: master | Geoffrey Métais <<a href="mailto:geoffrey.metais@gmail.com" target="_blank">geoffrey.metais@gmail.com</a>> | Tue Jan 9 09:51:49 2018 +0100| [5cc334ce561866ee91cab70f533732c845b78829] | committer: Geoffrey Métais<br>
><br>
> Fix IndexOutOfBoundsException on media delete fail<br>
><br>
> > <a href="https://code.videolan.org/videolan/vlc-android/commit/5cc334ce561866ee91cab70f533732c845b78829" rel="noreferrer" target="_blank">https://code.videolan.org/videolan/vlc-android/commit/5cc334ce561866ee91cab70f533732c845b78829</a><br>
> ---<br>
><br>
> vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserAdapter.java | 1 +<br>
> vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java | 1 +<br>
> 2 files changed, 2 insertions(+)<br>
><br>
> diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserAdapter.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserAdapter.java<br>
> index c0df3a9a1..a2930c820 100644<br>
> --- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserAdapter.java<br>
> +++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserAdapter.java<br>
> @@ -333,6 +333,7 @@ public class AudioBrowserAdapter extends SortableAdapter<MediaLibraryItem, Audio<br>
><br>
> public void addItem(final int position, final MediaLibraryItem item) {<br>
> final List<MediaLibraryItem> referenceList = peekLast();<br>
> + if (position < 0 || position >= referenceList.size()) return;<br>
<br>
IMO, providing a valid position is the caller responsability. Here, the<br>
error is silently ignored.<br>
<br>
This method is always called from a Runnable passed to<br>
UiTools.snackerWithCancel(), relying on the position of the item when it<br>
was deleted. But the list may have changed in the meantime, so adding<br>
the item back should not rely on the position.<br>
<br>
In the worst case, the position is out-of-range (with this patch it does<br>
not crash anymore, but the item is not added back); but even when it is<br>
in-range, there is no guarantee that the position is correct.<br>
<br>
> final List<MediaLibraryItem> dataList = new ArrayList<>(referenceList);<br>
> dataList.add(position,item);<br>
> update(dataList);<br>
> diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java<br>
> index 2f5863fcf..4ad8f091b 100644<br>
> --- a/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java<br>
> +++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java<br>
> @@ -148,6 +148,7 @@ public class VideoListAdapter extends SortableAdapter<MediaWrapper, VideoListAda<br>
> @MainThread<br>
> public void add(MediaWrapper item, int position) {<br>
> final List<MediaWrapper> list = new ArrayList<>(peekLast());<br>
> + if (position < 0 || position >= list.size()) return;<br>
> list.add(position, item);<br>
> update(list);<br>
> }<br>
><br>
> _______________________________________________<br>
> Android mailing list<br>
> <a href="mailto:Android@videolan.org" target="_blank">Android@videolan.org</a><br>
> <a href="https://mailman.videolan.org/listinfo/android" rel="noreferrer" target="_blank">https://mailman.videolan.org/listinfo/android</a><br>
_______________________________________________<br>
Android mailing list<br>
<a href="mailto:Android@videolan.org" target="_blank">Android@videolan.org</a><br>
<a href="https://mailman.videolan.org/listinfo/android" rel="noreferrer" target="_blank">https://mailman.videolan.org/listinfo/android</a><br>
</blockquote></div>