Created
August 30, 2018 09:02
-
-
Save dmitry-bystrov/7fa57868b3e0cc1c95624aa285aec7eb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void addPhotoToList(String path) { | |
if (photoInfoList.size() > 0 | |
&& photoInfoList.get(photoInfoList.size() - 1).getImageFilePath().equals(path)) { | |
// может получиться так, что новая фотография уже | |
// попала в список во время пересоздания активити | |
// в таком случае повторно добавлять её туда не нужно | |
return; | |
} | |
if (photoInfoList.size() == 0) { | |
photoInfoList.add(new PhotoInfo(path)); | |
notifyDataSetChanged(); | |
} else { | |
List<PhotoInfo> newPhotoInfoList = new ArrayList<>(photoInfoList); | |
newPhotoInfoList.add(new PhotoInfo(path)); | |
dispatchUpdates(newPhotoInfoList); | |
} | |
} | |
public void deletePhotoFromList(int position) { | |
List<PhotoInfo> newPhotoInfoList = new ArrayList<>(photoInfoList); | |
newPhotoInfoList.remove(position); | |
dispatchUpdates(newPhotoInfoList); | |
} | |
private void dispatchUpdates(List<PhotoInfo> newPhotoInfoList) { | |
DiffUtilCallback diffUtilCallback = | |
new DiffUtilCallback(photoInfoList, newPhotoInfoList); | |
DiffUtil.DiffResult diffResult = DiffUtil.calculateDiff(diffUtilCallback); | |
photoInfoList = newPhotoInfoList; | |
diffResult.dispatchUpdatesTo(this); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment