Skip to content

Commit 1c4dc21

Browse files
Copy Title, description and location to subsequent media (commons-app#487)
* Copy Title, description and location to subsequent media * Show message on success * Refresh UI immediately after location update Refactor location handling in UploadMediaDetailFragment and related classes
1 parent 4496664 commit 1c4dc21

File tree

3 files changed

+64
-18
lines changed

3 files changed

+64
-18
lines changed

app/src/main/java/fr/free/nrw/commons/upload/mediaDetails/UploadMediaDetailFragment.kt

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import androidx.core.content.ContextCompat
2121
import androidx.core.os.bundleOf
2222
import androidx.exifinterface.media.ExifInterface
2323
import androidx.recyclerview.widget.LinearLayoutManager
24+
import androidx.viewpager.widget.ViewPager
25+
import androidx.viewpager2.widget.ViewPager2
2426
import fr.free.nrw.commons.CameraPosition
2527
import fr.free.nrw.commons.R
2628
import fr.free.nrw.commons.contributions.MainActivity
@@ -215,21 +217,7 @@ class UploadMediaDetailFragment : UploadBaseFragment(), UploadMediaDetailsContra
215217
btnPrevious.alpha = 1.0f
216218
}
217219

218-
// If the image EXIF data contains the location, show the map icon with a green tick
219-
if (inAppPictureLocation != null || (uploadableFile != null && uploadableFile!!.hasLocation())) {
220-
val mapTick =
221-
ContextCompat.getDrawable(requireContext(), R.drawable.ic_map_available_20dp)
222-
locationImageView.setImageDrawable(mapTick)
223-
locationTextView.setText(R.string.edit_location)
224-
} else {
225-
// Otherwise, show the map icon with a red question mark
226-
val mapQuestionMark = ContextCompat.getDrawable(
227-
requireContext(),
228-
R.drawable.ic_map_not_available_20dp
229-
)
230-
locationImageView.setImageDrawable(mapQuestionMark)
231-
locationTextView.setText(R.string.add_location)
232-
}
220+
updateMapTickIcon(0)
233221

234222
//If this is the last media, we have nothing to copy, lets not show the button
235223
btnCopySubsequentMedia.visibility =
@@ -323,6 +311,7 @@ class UploadMediaDetailFragment : UploadBaseFragment(), UploadMediaDetailsContra
323311
)
324312
binding.locationImageView.setImageDrawable(mapTick)
325313
binding.locationTextView.setText(R.string.edit_location)
314+
updateMapTickIcon(0)
326315
}
327316

328317
override fun onNegativeResponse() {
@@ -437,6 +426,7 @@ class UploadMediaDetailFragment : UploadBaseFragment(), UploadMediaDetailsContra
437426
if (fragmentCallback == null) {
438427
return
439428
}
429+
updateMapTickIcon(this.indexOfFragment)
440430
presenter.fetchTitleAndDescription(indexOfFragment)
441431
if (showNearbyFound) {
442432
if (UploadActivity.nearbyPopupAnswers!!.containsKey(nearbyPlace!!)) {
@@ -718,6 +708,8 @@ class UploadMediaDetailFragment : UploadBaseFragment(), UploadMediaDetailsContra
718708
binding.locationTextView.setText(R.string.add_location)
719709
}
720710

711+
updateMapTickIcon(this.indexOfFragment) // Refresh UI immediately
712+
721713
editableUploadItem!!.gpsCoords!!.decLatitude = 0.0
722714
editableUploadItem!!.gpsCoords!!.decLongitude = 0.0
723715
editableUploadItem!!.gpsCoords!!.imageCoordsExists = false
@@ -871,6 +863,32 @@ class UploadMediaDetailFragment : UploadBaseFragment(), UploadMediaDetailsContra
871863
Toast.makeText(context, R.string.copied_successfully, Toast.LENGTH_SHORT).show()
872864
}
873865

866+
private fun updateMapTickIcon(index: Int) {
867+
if (_binding == null) return
868+
869+
editableUploadItem = presenter.getUploadItem(index)
870+
871+
val hasLocation = (!hasUserRemovedLocation) && (
872+
inAppPictureLocation != null ||
873+
(uploadableFile != null && uploadableFile!!.hasLocation()) ||
874+
(editableUploadItem?.gpsCoords?.imageCoordsExists == true &&
875+
editableUploadItem?.gpsCoords?.decimalCoords != null)
876+
)
877+
878+
binding.locationImageView.setImageDrawable(
879+
ContextCompat.getDrawable(
880+
requireContext(),
881+
if (hasLocation) R.drawable.ic_map_available_20dp
882+
else R.drawable.ic_map_not_available_20dp
883+
)
884+
)
885+
886+
binding.locationTextView.setText(
887+
if (hasLocation) R.string.edit_location
888+
else R.string.add_location
889+
)
890+
}
891+
874892
override fun onSaveInstanceState(outState: Bundle) {
875893
super.onSaveInstanceState(outState)
876894

app/src/main/java/fr/free/nrw/commons/upload/mediaDetails/UploadMediaDetailsContract.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,5 +124,7 @@ interface UploadMediaDetailsContract {
124124
fun onEditButtonClicked(indexInViewFlipper: Int)
125125

126126
fun onUserConfirmedUploadIsOfPlace(place: Place?, uploadItemIndex: Int)
127+
128+
fun getUploadItem(index: Int): UploadItem?
127129
}
128130
}

app/src/main/java/fr/free/nrw/commons/upload/mediaDetails/UploadMediaPresenter.kt

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,15 +205,42 @@ class UploadMediaPresenter @Inject constructor(
205205

206206

207207
/**
208-
* Copies the caption and description of the current item to the subsequent media
208+
* Copies the caption. location and description of the current item to the subsequent media
209209
*/
210210
override fun copyTitleAndDescriptionToSubsequentMedia(indexInViewFlipper: Int) {
211+
val sourceItem = repository.getUploads()[indexInViewFlipper]
212+
211213
for (i in indexInViewFlipper + 1 until repository.getCount()) {
212214
val subsequentUploadItem = repository.getUploads()[i]
215+
213216
subsequentUploadItem.uploadMediaDetails = deepCopy(
214-
repository.getUploads()[indexInViewFlipper].uploadMediaDetails
217+
sourceItem.uploadMediaDetails
215218
).toMutableList()
219+
220+
sourceItem.gpsCoords?.let { sourceCoords ->
221+
if (sourceCoords.decimalCoords != null) {
222+
if (subsequentUploadItem.gpsCoords == null) {
223+
val latLng = sourceCoords.latLng
224+
if (latLng != null) {
225+
subsequentUploadItem.gpsCoords = ImageCoordinates(null, latLng)
226+
}
227+
} else {
228+
subsequentUploadItem.gpsCoords!!.decLatitude = sourceCoords.decLatitude
229+
subsequentUploadItem.gpsCoords!!.decLongitude = sourceCoords.decLongitude
230+
subsequentUploadItem.gpsCoords!!.decimalCoords = sourceCoords.decimalCoords
231+
subsequentUploadItem.gpsCoords!!.imageCoordsExists = true
232+
subsequentUploadItem.gpsCoords!!.zoomLevel = sourceCoords.zoomLevel
233+
}
234+
}
235+
}
216236
}
237+
238+
view?.showMessage("Title, description and location copied to subsequent media",
239+
android.R.color.holo_green_light)
240+
}
241+
242+
override fun getUploadItem(index: Int): UploadItem? {
243+
return repository.getUploads().getOrNull(index)
217244
}
218245

219246
/**
@@ -256,7 +283,6 @@ class UploadMediaPresenter @Inject constructor(
256283
setUploadIsOfAPlace(true)
257284
}
258285

259-
260286
/**
261287
* Calculates the image quality
262288
*

0 commit comments

Comments
 (0)