mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 21:03:54 +01:00
5196: Fix in-app camera location loss (#5249)
Merging as this is a great improvement, additional issues/bugs can be filed as GitHub issues. * fix in-app camera location loss * fix failing unit tests * UploadMediaDetailFragmentUnitTest: modify testOnActivityResultAddLocationDialog to have null location * reintroduce removed variable * enable prePopulateCategoriesAndDepictionsBy for current user location * add relevant comment and fix failing test * modify dialog and disable location tag redaction from EXIF * modify in-app camera dialog flow and change location to inAppPictureLocation * change location to inAppPictureLocation * fix location flow * preferences.xml: remove redundant default value * inform users about location loss happening for first upload * FileProcessor.kt: remove commented-out code * prevent user location from getting attached to images with no EXIF location in normal and custom selector * handle onPermissionDenied for location permission * remove last location when the user turns the GPS off * disable photo picker and in app camera preferences in settings for logged-out users * remove debug statements and add toast inside runnables
This commit is contained in:
parent
1cab938d81
commit
5073ca08c3
21 changed files with 537 additions and 92 deletions
|
|
@ -28,6 +28,8 @@ class u {
|
|||
internal var readEXIF: EXIFReader?=null
|
||||
@Mock
|
||||
internal var mediaClient: MediaClient? = null
|
||||
@Mock
|
||||
internal var location: LatLng? = null
|
||||
|
||||
@InjectMocks
|
||||
var imageProcessingService: ImageProcessingService? = null
|
||||
|
|
@ -62,7 +64,7 @@ class u {
|
|||
`when`(fileUtilsWrapper!!.getSHA1(any(FileInputStream::class.java)))
|
||||
.thenReturn("fileSha")
|
||||
|
||||
`when`(fileUtilsWrapper!!.getGeolocationOfFile(ArgumentMatchers.anyString()))
|
||||
`when`(fileUtilsWrapper!!.getGeolocationOfFile(ArgumentMatchers.anyString(), any(LatLng::class.java)))
|
||||
.thenReturn("latLng")
|
||||
|
||||
`when`(imageUtilsWrapper?.checkIfImageIsTooDark(ArgumentMatchers.anyString()))
|
||||
|
|
@ -88,7 +90,7 @@ class u {
|
|||
@Test
|
||||
fun validateImageForKeepImage() {
|
||||
`when`(uploadItem.imageQuality).thenReturn(ImageUtils.IMAGE_KEEP)
|
||||
val validateImage = imageProcessingService!!.validateImage(uploadItem)
|
||||
val validateImage = imageProcessingService!!.validateImage(uploadItem, location)
|
||||
assertEquals(ImageUtils.IMAGE_OK, validateImage.blockingGet())
|
||||
}
|
||||
|
||||
|
|
@ -96,13 +98,13 @@ class u {
|
|||
fun validateImageForDuplicateImage() {
|
||||
`when`(mediaClient!!.checkFileExistsUsingSha(ArgumentMatchers.anyString()))
|
||||
.thenReturn(Single.just(true))
|
||||
val validateImage = imageProcessingService!!.validateImage(uploadItem)
|
||||
val validateImage = imageProcessingService!!.validateImage(uploadItem, location)
|
||||
assertEquals(ImageUtils.IMAGE_DUPLICATE, validateImage.blockingGet())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun validateImageForOkImage() {
|
||||
val validateImage = imageProcessingService!!.validateImage(uploadItem)
|
||||
val validateImage = imageProcessingService!!.validateImage(uploadItem, location)
|
||||
assertEquals(ImageUtils.IMAGE_OK, validateImage.blockingGet())
|
||||
}
|
||||
|
||||
|
|
@ -110,7 +112,7 @@ class u {
|
|||
fun validateImageForDarkImage() {
|
||||
`when`(imageUtilsWrapper?.checkIfImageIsTooDark(ArgumentMatchers.anyString()))
|
||||
.thenReturn(Single.just(ImageUtils.IMAGE_DARK))
|
||||
val validateImage = imageProcessingService!!.validateImage(uploadItem)
|
||||
val validateImage = imageProcessingService!!.validateImage(uploadItem, location)
|
||||
assertEquals(ImageUtils.IMAGE_DARK, validateImage.blockingGet())
|
||||
}
|
||||
|
||||
|
|
@ -118,7 +120,7 @@ class u {
|
|||
fun validateImageForWrongGeoLocation() {
|
||||
`when`(imageUtilsWrapper!!.checkImageGeolocationIsDifferent(ArgumentMatchers.anyString(), any(LatLng::class.java)))
|
||||
.thenReturn(Single.just(ImageUtils.IMAGE_GEOLOCATION_DIFFERENT))
|
||||
val validateImage = imageProcessingService!!.validateImage(uploadItem)
|
||||
val validateImage = imageProcessingService!!.validateImage(uploadItem, location)
|
||||
assertEquals(ImageUtils.IMAGE_GEOLOCATION_DIFFERENT, validateImage.blockingGet())
|
||||
}
|
||||
|
||||
|
|
@ -126,7 +128,7 @@ class u {
|
|||
fun validateImageForFileNameExistsWithCheckTitleOn() {
|
||||
`when`(mediaClient?.checkPageExistsUsingTitle(ArgumentMatchers.anyString()))
|
||||
.thenReturn(Single.just(true))
|
||||
val validateImage = imageProcessingService!!.validateImage(uploadItem)
|
||||
val validateImage = imageProcessingService!!.validateImage(uploadItem, location)
|
||||
assertEquals(ImageUtils.FILE_NAME_EXISTS, validateImage.blockingGet())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,6 +47,9 @@ class UploadMediaPresenterTest {
|
|||
@Mock
|
||||
private lateinit var place: Place
|
||||
|
||||
@Mock
|
||||
private var location: LatLng? = null
|
||||
|
||||
@Mock
|
||||
private lateinit var uploadItem: UploadItem
|
||||
|
||||
|
|
@ -88,10 +91,11 @@ class UploadMediaPresenterTest {
|
|||
repository.preProcessImage(
|
||||
ArgumentMatchers.any(UploadableFile::class.java),
|
||||
ArgumentMatchers.any(Place::class.java),
|
||||
ArgumentMatchers.any(UploadMediaPresenter::class.java)
|
||||
ArgumentMatchers.any(UploadMediaPresenter::class.java),
|
||||
ArgumentMatchers.any(LatLng::class.java)
|
||||
)
|
||||
).thenReturn(testObservableUploadItem)
|
||||
uploadMediaPresenter.receiveImage(uploadableFile, place)
|
||||
uploadMediaPresenter.receiveImage(uploadableFile, place, location)
|
||||
verify(view).showProgress(true)
|
||||
testScheduler.triggerActions()
|
||||
verify(view).onImageProcessed(
|
||||
|
|
@ -107,14 +111,14 @@ class UploadMediaPresenterTest {
|
|||
@Test
|
||||
fun verifyImageQualityTest() {
|
||||
whenever(repository.uploads).thenReturn(listOf(uploadItem))
|
||||
whenever(repository.getImageQuality(uploadItem))
|
||||
whenever(repository.getImageQuality(uploadItem, location))
|
||||
.thenReturn(testSingleImageResult)
|
||||
whenever(uploadItem.imageQuality).thenReturn(0)
|
||||
whenever(uploadItem.gpsCoords)
|
||||
.thenReturn(imageCoordinates)
|
||||
whenever(uploadItem.gpsCoords.decimalCoords)
|
||||
.thenReturn("imageCoordinates")
|
||||
uploadMediaPresenter.verifyImageQuality(0)
|
||||
uploadMediaPresenter.verifyImageQuality(0, location)
|
||||
verify(view).showProgress(true)
|
||||
testScheduler.triggerActions()
|
||||
verify(view).showProgress(false)
|
||||
|
|
@ -126,14 +130,14 @@ class UploadMediaPresenterTest {
|
|||
@Test
|
||||
fun `verify ImageQuality Test while coordinates equals to null`() {
|
||||
whenever(repository.uploads).thenReturn(listOf(uploadItem))
|
||||
whenever(repository.getImageQuality(uploadItem))
|
||||
whenever(repository.getImageQuality(uploadItem, location))
|
||||
.thenReturn(testSingleImageResult)
|
||||
whenever(uploadItem.imageQuality).thenReturn(0)
|
||||
whenever(uploadItem.gpsCoords)
|
||||
.thenReturn(imageCoordinates)
|
||||
whenever(uploadItem.gpsCoords.decimalCoords)
|
||||
.thenReturn(null)
|
||||
uploadMediaPresenter.verifyImageQuality(0)
|
||||
uploadMediaPresenter.verifyImageQuality(0, location)
|
||||
testScheduler.triggerActions()
|
||||
}
|
||||
|
||||
|
|
@ -167,7 +171,7 @@ class UploadMediaPresenterTest {
|
|||
val uploadMediaDetailList: ArrayList<UploadMediaDetail> = ArrayList()
|
||||
uploadMediaDetailList.add(uploadMediaDetail)
|
||||
uploadItem.setMediaDetails(uploadMediaDetailList)
|
||||
Mockito.`when`(repository.getImageQuality(uploadItem)).then {
|
||||
Mockito.`when`(repository.getImageQuality(uploadItem, location)).then {
|
||||
verify(view).showProgress(true)
|
||||
testScheduler.triggerActions()
|
||||
verify(view).showProgress(true)
|
||||
|
|
@ -183,7 +187,7 @@ class UploadMediaPresenterTest {
|
|||
uploadMediaDetail.captionText = "added caption"
|
||||
uploadMediaDetail.languageCode = "eo"
|
||||
uploadItem.setMediaDetails(Collections.singletonList(uploadMediaDetail))
|
||||
Mockito.`when`(repository.getImageQuality(uploadItem)).then {
|
||||
Mockito.`when`(repository.getImageQuality(uploadItem, location)).then {
|
||||
verify(view).showProgress(true)
|
||||
testScheduler.triggerActions()
|
||||
verify(view).showProgress(true)
|
||||
|
|
@ -264,11 +268,12 @@ class UploadMediaPresenterTest {
|
|||
repository.preProcessImage(
|
||||
ArgumentMatchers.any(UploadableFile::class.java),
|
||||
ArgumentMatchers.any(Place::class.java),
|
||||
ArgumentMatchers.any(UploadMediaPresenter::class.java)
|
||||
ArgumentMatchers.any(UploadMediaPresenter::class.java),
|
||||
ArgumentMatchers.any(LatLng::class.java)
|
||||
)
|
||||
).thenReturn(item)
|
||||
|
||||
uploadMediaPresenter.receiveImage(uploadableFile, germanyAsPlace)
|
||||
uploadMediaPresenter.receiveImage(uploadableFile, germanyAsPlace, location)
|
||||
verify(view).showProgress(true)
|
||||
testScheduler.triggerActions()
|
||||
|
||||
|
|
|
|||
|
|
@ -62,6 +62,9 @@ class UploadRepositoryUnitTest {
|
|||
@Mock
|
||||
private lateinit var place: Place
|
||||
|
||||
@Mock
|
||||
private var location: LatLng? = null
|
||||
|
||||
@Mock
|
||||
private lateinit var similarImageInterface: SimilarImageInterface
|
||||
|
||||
|
|
@ -175,16 +178,16 @@ class UploadRepositoryUnitTest {
|
|||
@Test
|
||||
fun testPreProcessImage() {
|
||||
assertEquals(
|
||||
repository.preProcessImage(uploadableFile, place, similarImageInterface),
|
||||
uploadModel.preProcessImage(uploadableFile, place, similarImageInterface)
|
||||
repository.preProcessImage(uploadableFile, place, similarImageInterface, location),
|
||||
uploadModel.preProcessImage(uploadableFile, place, similarImageInterface, location)
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testGetImageQuality() {
|
||||
assertEquals(
|
||||
repository.getImageQuality(uploadItem),
|
||||
uploadModel.getImageQuality(uploadItem)
|
||||
repository.getImageQuality(uploadItem, location),
|
||||
uploadModel.getImageQuality(uploadItem, location)
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -97,6 +97,9 @@ class UploadMediaDetailFragmentUnitTest {
|
|||
@Mock
|
||||
private lateinit var place: Place
|
||||
|
||||
@Mock
|
||||
private var location: fr.free.nrw.commons.location.LatLng? = null
|
||||
|
||||
@Mock
|
||||
private lateinit var defaultKvStore: JsonKvStore
|
||||
|
||||
|
|
@ -172,7 +175,7 @@ class UploadMediaDetailFragmentUnitTest {
|
|||
@Throws(Exception::class)
|
||||
fun testSetImageTobeUploaded() {
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
fragment.setImageTobeUploaded(null, null)
|
||||
fragment.setImageTobeUploaded(null, null, location)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -374,7 +377,7 @@ class UploadMediaDetailFragmentUnitTest {
|
|||
`when`(latLng.longitude).thenReturn(0.0)
|
||||
`when`(uploadItem.gpsCoords).thenReturn(imageCoordinates)
|
||||
fragment.onActivityResult(1211, Activity.RESULT_OK, intent)
|
||||
Mockito.verify(presenter, Mockito.times(0)).verifyImageQuality(0)
|
||||
Mockito.verify(presenter, Mockito.times(0)).verifyImageQuality(0, location)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -396,7 +399,7 @@ class UploadMediaDetailFragmentUnitTest {
|
|||
`when`(latLng.longitude).thenReturn(0.0)
|
||||
`when`(uploadItem.gpsCoords).thenReturn(imageCoordinates)
|
||||
fragment.onActivityResult(1211, Activity.RESULT_OK, intent)
|
||||
Mockito.verify(presenter, Mockito.times(1)).verifyImageQuality(0)
|
||||
Mockito.verify(presenter, Mockito.times(1)).verifyImageQuality(0, null)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue