Skip to content

Commit

Permalink
find new photos
Browse files Browse the repository at this point in the history
  • Loading branch information
Helium314 authored Nov 8, 2022
1 parent c3bd422 commit a9c1b31
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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())
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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<String>? = null
}
}

0 comments on commit a9c1b31

Please sign in to comment.