diff --git a/app/src/main/java/fr/free/nrw/commons/upload/mediaDetails/UploadMediaDetailFragment.kt b/app/src/main/java/fr/free/nrw/commons/upload/mediaDetails/UploadMediaDetailFragment.kt index af850a7e3..a30a10791 100644 --- a/app/src/main/java/fr/free/nrw/commons/upload/mediaDetails/UploadMediaDetailFragment.kt +++ b/app/src/main/java/fr/free/nrw/commons/upload/mediaDetails/UploadMediaDetailFragment.kt @@ -21,6 +21,8 @@ import androidx.core.content.ContextCompat import androidx.core.os.bundleOf import androidx.exifinterface.media.ExifInterface import androidx.recyclerview.widget.LinearLayoutManager +import androidx.viewpager.widget.ViewPager +import androidx.viewpager2.widget.ViewPager2 import fr.free.nrw.commons.CameraPosition import fr.free.nrw.commons.R import fr.free.nrw.commons.contributions.MainActivity @@ -215,21 +217,7 @@ class UploadMediaDetailFragment : UploadBaseFragment(), UploadMediaDetailsContra btnPrevious.alpha = 1.0f } - // If the image EXIF data contains the location, show the map icon with a green tick - if (inAppPictureLocation != null || (uploadableFile != null && uploadableFile!!.hasLocation())) { - val mapTick = - ContextCompat.getDrawable(requireContext(), R.drawable.ic_map_available_20dp) - locationImageView.setImageDrawable(mapTick) - locationTextView.setText(R.string.edit_location) - } else { - // Otherwise, show the map icon with a red question mark - val mapQuestionMark = ContextCompat.getDrawable( - requireContext(), - R.drawable.ic_map_not_available_20dp - ) - locationImageView.setImageDrawable(mapQuestionMark) - locationTextView.setText(R.string.add_location) - } + updateMapTickIcon(0) //If this is the last media, we have nothing to copy, lets not show the button btnCopySubsequentMedia.visibility = @@ -323,6 +311,7 @@ class UploadMediaDetailFragment : UploadBaseFragment(), UploadMediaDetailsContra ) binding.locationImageView.setImageDrawable(mapTick) binding.locationTextView.setText(R.string.edit_location) + updateMapTickIcon(0) } override fun onNegativeResponse() { @@ -437,6 +426,7 @@ class UploadMediaDetailFragment : UploadBaseFragment(), UploadMediaDetailsContra if (fragmentCallback == null) { return } + updateMapTickIcon(this.indexOfFragment) presenter.fetchTitleAndDescription(indexOfFragment) if (showNearbyFound) { if (UploadActivity.nearbyPopupAnswers!!.containsKey(nearbyPlace!!)) { @@ -718,6 +708,8 @@ class UploadMediaDetailFragment : UploadBaseFragment(), UploadMediaDetailsContra binding.locationTextView.setText(R.string.add_location) } + updateMapTickIcon(this.indexOfFragment) // Refresh UI immediately + editableUploadItem!!.gpsCoords!!.decLatitude = 0.0 editableUploadItem!!.gpsCoords!!.decLongitude = 0.0 editableUploadItem!!.gpsCoords!!.imageCoordsExists = false @@ -871,6 +863,32 @@ class UploadMediaDetailFragment : UploadBaseFragment(), UploadMediaDetailsContra Toast.makeText(context, R.string.copied_successfully, Toast.LENGTH_SHORT).show() } + private fun updateMapTickIcon(index: Int) { + if (_binding == null) return + + editableUploadItem = presenter.getUploadItem(index) + + val hasLocation = (!hasUserRemovedLocation) && ( + inAppPictureLocation != null || + (uploadableFile != null && uploadableFile!!.hasLocation()) || + (editableUploadItem?.gpsCoords?.imageCoordsExists == true && + editableUploadItem?.gpsCoords?.decimalCoords != null) + ) + + binding.locationImageView.setImageDrawable( + ContextCompat.getDrawable( + requireContext(), + if (hasLocation) R.drawable.ic_map_available_20dp + else R.drawable.ic_map_not_available_20dp + ) + ) + + binding.locationTextView.setText( + if (hasLocation) R.string.edit_location + else R.string.add_location + ) + } + override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) diff --git a/app/src/main/java/fr/free/nrw/commons/upload/mediaDetails/UploadMediaDetailsContract.kt b/app/src/main/java/fr/free/nrw/commons/upload/mediaDetails/UploadMediaDetailsContract.kt index c368b96ac..347449979 100644 --- a/app/src/main/java/fr/free/nrw/commons/upload/mediaDetails/UploadMediaDetailsContract.kt +++ b/app/src/main/java/fr/free/nrw/commons/upload/mediaDetails/UploadMediaDetailsContract.kt @@ -124,5 +124,7 @@ interface UploadMediaDetailsContract { fun onEditButtonClicked(indexInViewFlipper: Int) fun onUserConfirmedUploadIsOfPlace(place: Place?, uploadItemIndex: Int) + + fun getUploadItem(index: Int): UploadItem? } } diff --git a/app/src/main/java/fr/free/nrw/commons/upload/mediaDetails/UploadMediaPresenter.kt b/app/src/main/java/fr/free/nrw/commons/upload/mediaDetails/UploadMediaPresenter.kt index 90c426091..414b74a01 100644 --- a/app/src/main/java/fr/free/nrw/commons/upload/mediaDetails/UploadMediaPresenter.kt +++ b/app/src/main/java/fr/free/nrw/commons/upload/mediaDetails/UploadMediaPresenter.kt @@ -205,15 +205,42 @@ class UploadMediaPresenter @Inject constructor( /** - * Copies the caption and description of the current item to the subsequent media + * Copies the caption. location and description of the current item to the subsequent media */ override fun copyTitleAndDescriptionToSubsequentMedia(indexInViewFlipper: Int) { + val sourceItem = repository.getUploads()[indexInViewFlipper] + for (i in indexInViewFlipper + 1 until repository.getCount()) { val subsequentUploadItem = repository.getUploads()[i] + subsequentUploadItem.uploadMediaDetails = deepCopy( - repository.getUploads()[indexInViewFlipper].uploadMediaDetails + sourceItem.uploadMediaDetails ).toMutableList() + + sourceItem.gpsCoords?.let { sourceCoords -> + if (sourceCoords.decimalCoords != null) { + if (subsequentUploadItem.gpsCoords == null) { + val latLng = sourceCoords.latLng + if (latLng != null) { + subsequentUploadItem.gpsCoords = ImageCoordinates(null, latLng) + } + } else { + subsequentUploadItem.gpsCoords!!.decLatitude = sourceCoords.decLatitude + subsequentUploadItem.gpsCoords!!.decLongitude = sourceCoords.decLongitude + subsequentUploadItem.gpsCoords!!.decimalCoords = sourceCoords.decimalCoords + subsequentUploadItem.gpsCoords!!.imageCoordsExists = true + subsequentUploadItem.gpsCoords!!.zoomLevel = sourceCoords.zoomLevel + } + } + } } + + view?.showMessage("Title, description and location copied to subsequent media", + android.R.color.holo_green_light) + } + + override fun getUploadItem(index: Int): UploadItem? { + return repository.getUploads().getOrNull(index) } /** @@ -256,7 +283,6 @@ class UploadMediaPresenter @Inject constructor( setUploadIsOfAPlace(true) } - /** * Calculates the image quality *