@@ -371,8 +371,6 @@ public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int
371371 public void swapDirectory (final File directory ) {
372372 localFileListFragmentInterface .setLoading (true );
373373 currentOffset = 0 ;
374- mFiles .clear ();
375- mFilesAll .clear ();
376374
377375 singleThreadExecutor .execute (() -> {
378376 // Load first page of folders
@@ -398,8 +396,10 @@ public void swapDirectory(final File directory) {
398396 @ SuppressLint ("NotifyDataSetChanged" )
399397 private void updateUIForFirstPage (List <File > firstPage ) {
400398 new Handler (Looper .getMainLooper ()).post (() -> {
401- mFiles = new ArrayList <>(firstPage );
402- mFilesAll = new ArrayList <>(firstPage );
399+ mFiles .clear ();
400+ mFilesAll .clear ();
401+ mFiles .addAll (firstPage );
402+ mFilesAll .addAll (firstPage );
403403 notifyDataSetChanged ();
404404 localFileListFragmentInterface .setLoading (false );
405405 });
@@ -432,15 +432,16 @@ private void loadRemainingEntries(File directory, boolean fetchFolders) {
432432
433433 private void notifyItemRange (List <File > updatedList ) {
434434 new Handler (Looper .getMainLooper ()).post (() -> {
435- int from = mFiles .size ();
436- int to = updatedList .size ();
435+ int headerOffset = shouldShowHeader () ? 1 : 0 ;
436+ int startPositionInAdapter = mFiles .size () + headerOffset ;
437+ int itemCount = updatedList .size ();
437438
438439 mFiles .addAll (updatedList );
439440 mFilesAll .addAll (updatedList );
440441
441442 Log_OC .d (TAG , "notifyItemRange, item size: " + mFilesAll .size ());
442443
443- notifyItemRangeInserted (from , to );
444+ notifyItemRangeInserted (startPositionInAdapter , itemCount );
444445 });
445446 }
446447
0 commit comments