Skip to content

Refactor location handling in UploadMediaDetailFragment and related classes #6274

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -215,21 +215,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 =
Expand Down Expand Up @@ -323,6 +309,7 @@ class UploadMediaDetailFragment : UploadBaseFragment(), UploadMediaDetailsContra
)
binding.locationImageView.setImageDrawable(mapTick)
binding.locationTextView.setText(R.string.edit_location)
updateMapTickIcon(0)
}

override fun onNegativeResponse() {
Expand Down Expand Up @@ -437,6 +424,7 @@ class UploadMediaDetailFragment : UploadBaseFragment(), UploadMediaDetailsContra
if (fragmentCallback == null) {
return
}
updateMapTickIcon(this.indexOfFragment)
presenter.fetchTitleAndDescription(indexOfFragment)
if (showNearbyFound) {
if (UploadActivity.nearbyPopupAnswers!!.containsKey(nearbyPlace!!)) {
Expand Down Expand Up @@ -718,6 +706,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
Expand Down Expand Up @@ -871,6 +861,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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,5 +124,7 @@ interface UploadMediaDetailsContract {
fun onEditButtonClicked(indexInViewFlipper: Int)

fun onUserConfirmedUploadIsOfPlace(place: Place?, uploadItemIndex: Int)

fun getUploadItem(index: Int): UploadItem?
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

/**
Expand Down Expand Up @@ -256,7 +283,6 @@ class UploadMediaPresenter @Inject constructor(
setUploadIsOfAPlace(true)
}


/**
* Calculates the image quality
*
Expand Down