diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/note_discussion/AttachPhotoFragment.kt b/app/src/main/java/de/westnordost/streetcomplete/quests/note_discussion/AttachPhotoFragment.kt index db6f4eb9096..09b7721fbfe 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/quests/note_discussion/AttachPhotoFragment.kt +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/note_discussion/AttachPhotoFragment.kt @@ -3,6 +3,7 @@ package de.westnordost.streetcomplete.quests.note_discussion import android.content.ActivityNotFoundException import android.content.pm.PackageManager.FEATURE_CAMERA_ANY import android.os.Bundle +import android.os.Environment import android.util.Log import android.view.View import androidx.appcompat.app.AlertDialog @@ -34,7 +35,14 @@ class AttachPhotoFragment : Fragment(R.layout.fragment_attach_photo) { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - val paths = savedInstanceState?.getStringArrayList(PHOTO_PATHS) ?: ArrayList() + val imageFiles = activity?.getExternalFilesDir(Environment.DIRECTORY_PICTURES)?.list() + val imageFilesWeKnowAbout = currentPhotoPaths + val newImageFiles = if (imageFiles != null && imageFilesWeKnowAbout != null) + imageFiles.toMutableList().also { it.removeAll(imageFilesWeKnowAbout) } + else + emptyList() + + val paths = (savedInstanceState?.getStringArrayList(PHOTO_PATHS) ?: ArrayList()) + newImageFiles noteImageAdapter = NoteImageAdapter(paths, requireContext()) } @@ -64,6 +72,7 @@ class AttachPhotoFragment : Fragment(R.layout.fragment_attach_photo) { private suspend fun takePhoto() { try { + currentPhotoPaths = activity?.getExternalFilesDir(Environment.DIRECTORY_PICTURES)?.list() val filePath = launchTakePhoto(requireActivity()) if (filePath == null) { if (activity?.hasCameraPermission == false) context?.toast(R.string.no_camera_permission_toast) @@ -106,5 +115,6 @@ class AttachPhotoFragment : Fragment(R.layout.fragment_attach_photo) { companion object { private const val TAG = "AttachPhotoFragment" private const val PHOTO_PATHS = "photo_paths" + private var currentPhotoPaths: Array? = null } }