fix: npe on MediaRepository.java in list sorting comparison

This commit is contained in:
Harris 2021-07-23 09:46:44 +10:00
parent 0131bc171a
commit 701a40b224

View File

@ -16,15 +16,16 @@ import androidx.annotation.WorkerThread;
import com.annimon.stream.Stream; import com.annimon.stream.Stream;
import org.thoughtcrime.securesms.mms.PartAuthority;
import org.thoughtcrime.securesms.util.MediaUtil;
import org.session.libsession.utilities.Util; import org.session.libsession.utilities.Util;
import org.session.libsignal.utilities.guava.Optional; import org.session.libsignal.utilities.guava.Optional;
import org.thoughtcrime.securesms.mms.PartAuthority;
import org.thoughtcrime.securesms.util.MediaUtil;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
@ -78,11 +79,17 @@ class MediaRepository {
} }
} }
Comparator<MediaFolder> folderNameSorter = (Comparator<MediaFolder>) (first, second) -> {
if (first == null || first.getTitle() == null) return 1;
if (second == null || second.getTitle() == null) return -1;
return first.getTitle().toLowerCase().compareTo(second.getTitle().toLowerCase());
};
List<MediaFolder> mediaFolders = Stream.of(folders.values()).map(folder -> new MediaFolder(folder.getThumbnail(), List<MediaFolder> mediaFolders = Stream.of(folders.values()).map(folder -> new MediaFolder(folder.getThumbnail(),
folder.getTitle(), folder.getTitle(),
folder.getCount(), folder.getCount(),
folder.getBucketId())) folder.getBucketId()))
.sorted((o1, o2) -> o1.getTitle().toLowerCase().compareTo(o2.getTitle().toLowerCase())) .sorted(folderNameSorter)
.toList(); .toList();
Uri allMediaThumbnail = imageFolders.getThumbnailTimestamp() > videoFolders.getThumbnailTimestamp() ? imageFolders.getThumbnail() : videoFolders.getThumbnail(); Uri allMediaThumbnail = imageFolders.getThumbnailTimestamp() > videoFolders.getThumbnailTimestamp() ? imageFolders.getThumbnail() : videoFolders.getThumbnail();