mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-29 22:03:55 +01:00
Fix NPE that broke uploads
This commit is contained in:
parent
b9c2d79fe7
commit
561191cd29
7 changed files with 28 additions and 17 deletions
|
|
@ -112,7 +112,7 @@ data class Contribution constructor(
|
||||||
*/
|
*/
|
||||||
fun formatDescriptions(descriptions: List<UploadMediaDetail>) =
|
fun formatDescriptions(descriptions: List<UploadMediaDetail>) =
|
||||||
descriptions
|
descriptions
|
||||||
.filter { it.descriptionText!!.isNotEmpty() }
|
.filter { !it.descriptionText.isNullOrEmpty() }
|
||||||
.joinToString(separator = "") { "{{${it.languageCode}|1=${it.descriptionText}}}" }
|
.joinToString(separator = "") { "{{${it.languageCode}|1=${it.descriptionText}}}" }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -836,6 +836,7 @@ class UploadActivity : BaseActivity(), UploadContract.View, UploadBaseFragment.C
|
||||||
// Save the user's choice to not show the dialog again
|
// Save the user's choice to not show the dialog again
|
||||||
defaultKvStore.putBoolean("hasAlreadyLaunchedCategoriesDialog", true)
|
defaultKvStore.putBoolean("hasAlreadyLaunchedCategoriesDialog", true)
|
||||||
}
|
}
|
||||||
|
presenter!!.setupBasicKvStoreFactory { BasicKvStore(this@UploadActivity, it) }
|
||||||
presenter!!.checkImageQuality(0)
|
presenter!!.checkImageQuality(0)
|
||||||
UploadMediaPresenter.isCategoriesDialogShowing = false
|
UploadMediaPresenter.isCategoriesDialogShowing = false
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package fr.free.nrw.commons.upload
|
||||||
|
|
||||||
import fr.free.nrw.commons.BasePresenter
|
import fr.free.nrw.commons.BasePresenter
|
||||||
import fr.free.nrw.commons.filepicker.UploadableFile
|
import fr.free.nrw.commons.filepicker.UploadableFile
|
||||||
|
import fr.free.nrw.commons.kvstore.BasicKvStore
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The contract using which the UplaodActivity would communicate with its presenter
|
* The contract using which the UplaodActivity would communicate with its presenter
|
||||||
|
|
@ -73,5 +74,7 @@ interface UploadContract {
|
||||||
* @param uploadItemIndex Index of next image, whose quality is to be checked
|
* @param uploadItemIndex Index of next image, whose quality is to be checked
|
||||||
*/
|
*/
|
||||||
fun checkImageQuality(uploadItemIndex: Int)
|
fun checkImageQuality(uploadItemIndex: Int)
|
||||||
|
|
||||||
|
fun setupBasicKvStoreFactory(factory: (String) -> BasicKvStore)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import android.annotation.SuppressLint
|
||||||
import fr.free.nrw.commons.CommonsApplication.Companion.IS_LIMITED_CONNECTION_MODE_ENABLED
|
import fr.free.nrw.commons.CommonsApplication.Companion.IS_LIMITED_CONNECTION_MODE_ENABLED
|
||||||
import fr.free.nrw.commons.R
|
import fr.free.nrw.commons.R
|
||||||
import fr.free.nrw.commons.contributions.Contribution
|
import fr.free.nrw.commons.contributions.Contribution
|
||||||
|
import fr.free.nrw.commons.kvstore.BasicKvStore
|
||||||
import fr.free.nrw.commons.kvstore.JsonKvStore
|
import fr.free.nrw.commons.kvstore.JsonKvStore
|
||||||
import fr.free.nrw.commons.repository.UploadRepository
|
import fr.free.nrw.commons.repository.UploadRepository
|
||||||
import fr.free.nrw.commons.upload.mediaDetails.UploadMediaDetailsContract
|
import fr.free.nrw.commons.upload.mediaDetails.UploadMediaDetailsContract
|
||||||
|
|
@ -33,6 +34,8 @@ class UploadPresenter @Inject internal constructor(
|
||||||
|
|
||||||
private val compositeDisposable = CompositeDisposable()
|
private val compositeDisposable = CompositeDisposable()
|
||||||
|
|
||||||
|
lateinit var basicKvStoreFactory: (String) -> BasicKvStore
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called by the submit button in [UploadActivity]
|
* Called by the submit button in [UploadActivity]
|
||||||
*/
|
*/
|
||||||
|
|
@ -125,6 +128,10 @@ class UploadPresenter @Inject internal constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun setupBasicKvStoreFactory(factory: (String) -> BasicKvStore) {
|
||||||
|
basicKvStoreFactory = factory
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calls checkImageQuality of UploadMediaPresenter to check image quality of next image
|
* Calls checkImageQuality of UploadMediaPresenter to check image quality of next image
|
||||||
*
|
*
|
||||||
|
|
@ -132,6 +139,7 @@ class UploadPresenter @Inject internal constructor(
|
||||||
*/
|
*/
|
||||||
override fun checkImageQuality(uploadItemIndex: Int) {
|
override fun checkImageQuality(uploadItemIndex: Int) {
|
||||||
repository.getUploadItem(uploadItemIndex)?.let {
|
repository.getUploadItem(uploadItemIndex)?.let {
|
||||||
|
presenter.setupBasicKvStoreFactory(basicKvStoreFactory)
|
||||||
presenter.checkImageQuality(it, uploadItemIndex)
|
presenter.checkImageQuality(it, uploadItemIndex)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -197,6 +197,8 @@ class UploadMediaDetailFragment : UploadBaseFragment(), UploadMediaDetailsContra
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
presenter.onAttachView(this)
|
presenter.onAttachView(this)
|
||||||
|
presenter.setupBasicKvStoreFactory { BasicKvStore(requireActivity(), it) }
|
||||||
|
|
||||||
presenter.receiveImage(uploadableFile, place, inAppPictureLocation)
|
presenter.receiveImage(uploadableFile, place, inAppPictureLocation)
|
||||||
initRecyclerView()
|
initRecyclerView()
|
||||||
|
|
||||||
|
|
@ -801,9 +803,6 @@ class UploadMediaDetailFragment : UploadBaseFragment(), UploadMediaDetailsContra
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun createBasicKvStore(storeName: String): BasicKvStore =
|
|
||||||
BasicKvStore(requireActivity(), storeName)
|
|
||||||
|
|
||||||
override fun showBadImagePopup(errorCode: Int, index: Int, uploadItem: UploadItem) {
|
override fun showBadImagePopup(errorCode: Int, index: Int, uploadItem: UploadItem) {
|
||||||
//If the error message is null, we will probably not show anything
|
//If the error message is null, we will probably not show anything
|
||||||
val activity = requireActivity()
|
val activity = requireActivity()
|
||||||
|
|
|
||||||
|
|
@ -51,12 +51,12 @@ interface UploadMediaDetailsContract {
|
||||||
|
|
||||||
fun displayAddLocationDialog(runnable: Runnable)
|
fun displayAddLocationDialog(runnable: Runnable)
|
||||||
|
|
||||||
fun createBasicKvStore(storeName: String): BasicKvStore
|
|
||||||
|
|
||||||
fun showBadImagePopup(errorCode: Int, index: Int, uploadItem: UploadItem)
|
fun showBadImagePopup(errorCode: Int, index: Int, uploadItem: UploadItem)
|
||||||
}
|
}
|
||||||
|
|
||||||
interface UserActionListener : BasePresenter<View?> {
|
interface UserActionListener : BasePresenter<View?> {
|
||||||
|
fun setupBasicKvStoreFactory(factory: (String) -> BasicKvStore)
|
||||||
|
|
||||||
fun receiveImage(
|
fun receiveImage(
|
||||||
uploadableFile: UploadableFile?,
|
uploadableFile: UploadableFile?,
|
||||||
place: Place?,
|
place: Place?,
|
||||||
|
|
|
||||||
|
|
@ -16,12 +16,10 @@ import fr.free.nrw.commons.upload.UploadActivity.Companion.setUploadIsOfAPlace
|
||||||
import fr.free.nrw.commons.upload.UploadItem
|
import fr.free.nrw.commons.upload.UploadItem
|
||||||
import fr.free.nrw.commons.upload.UploadMediaDetail
|
import fr.free.nrw.commons.upload.UploadMediaDetail
|
||||||
import fr.free.nrw.commons.upload.mediaDetails.UploadMediaDetailFragment.UploadMediaDetailFragmentCallback
|
import fr.free.nrw.commons.upload.mediaDetails.UploadMediaDetailFragment.UploadMediaDetailFragmentCallback
|
||||||
import fr.free.nrw.commons.utils.DialogUtil.showAlertDialog
|
|
||||||
import fr.free.nrw.commons.utils.ImageUtils.EMPTY_CAPTION
|
import fr.free.nrw.commons.utils.ImageUtils.EMPTY_CAPTION
|
||||||
import fr.free.nrw.commons.utils.ImageUtils.FILE_NAME_EXISTS
|
import fr.free.nrw.commons.utils.ImageUtils.FILE_NAME_EXISTS
|
||||||
import fr.free.nrw.commons.utils.ImageUtils.IMAGE_KEEP
|
import fr.free.nrw.commons.utils.ImageUtils.IMAGE_KEEP
|
||||||
import fr.free.nrw.commons.utils.ImageUtils.IMAGE_OK
|
import fr.free.nrw.commons.utils.ImageUtils.IMAGE_OK
|
||||||
import fr.free.nrw.commons.utils.ImageUtils.getErrorMessageForResult
|
|
||||||
import io.github.coordinates2country.Coordinates2Country
|
import io.github.coordinates2country.Coordinates2Country
|
||||||
import io.reactivex.Maybe
|
import io.reactivex.Maybe
|
||||||
import io.reactivex.Scheduler
|
import io.reactivex.Scheduler
|
||||||
|
|
@ -53,6 +51,7 @@ class UploadMediaPresenter @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
lateinit var basicKvStoreFactory: (String) -> BasicKvStore
|
||||||
|
|
||||||
override fun onAttachView(view: UploadMediaDetailsContract.View) {
|
override fun onAttachView(view: UploadMediaDetailsContract.View) {
|
||||||
this.view = view
|
this.view = view
|
||||||
|
|
@ -73,6 +72,10 @@ class UploadMediaPresenter @Inject constructor(
|
||||||
repository.getUploads()[uploadItemIndex].uploadMediaDetails = uploadMediaDetails.toMutableList()
|
repository.getUploads()[uploadItemIndex].uploadMediaDetails = uploadMediaDetails.toMutableList()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun setupBasicKvStoreFactory(factory: (String) -> BasicKvStore) {
|
||||||
|
basicKvStoreFactory = factory
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Receives the corresponding uploadable file, processes it and return the view with and uplaod item
|
* Receives the corresponding uploadable file, processes it and return the view with and uplaod item
|
||||||
*/
|
*/
|
||||||
|
|
@ -336,10 +339,8 @@ class UploadMediaPresenter @Inject constructor(
|
||||||
*/
|
*/
|
||||||
override fun checkImageQuality(uploadItem: UploadItem, index: Int) {
|
override fun checkImageQuality(uploadItem: UploadItem, index: Int) {
|
||||||
if ((uploadItem.imageQuality != IMAGE_OK) && (uploadItem.imageQuality != IMAGE_KEEP)) {
|
if ((uploadItem.imageQuality != IMAGE_OK) && (uploadItem.imageQuality != IMAGE_KEEP)) {
|
||||||
val store = view.createBasicKvStore(
|
val value = basicKvStoreFactory(UploadActivity.storeNameForCurrentUploadImagesSize)
|
||||||
UploadActivity.storeNameForCurrentUploadImagesSize
|
.getString(UPLOAD_QUALITIES_KEY, null)
|
||||||
)
|
|
||||||
val value = store.getString(UPLOAD_QUALITIES_KEY, null)
|
|
||||||
try {
|
try {
|
||||||
val imageQuality = value.asJsonObject()["UploadItem$index"] as Int
|
val imageQuality = value.asJsonObject()["UploadItem$index"] as Int
|
||||||
view.showProgress(false)
|
view.showProgress(false)
|
||||||
|
|
@ -362,10 +363,8 @@ class UploadMediaPresenter @Inject constructor(
|
||||||
* @param index Index of the UploadItem which was deleted
|
* @param index Index of the UploadItem which was deleted
|
||||||
*/
|
*/
|
||||||
override fun updateImageQualitiesJSON(size: Int, index: Int) {
|
override fun updateImageQualitiesJSON(size: Int, index: Int) {
|
||||||
val store = view.createBasicKvStore(
|
val value = basicKvStoreFactory(UploadActivity.storeNameForCurrentUploadImagesSize)
|
||||||
UploadActivity.storeNameForCurrentUploadImagesSize
|
.getString(UPLOAD_QUALITIES_KEY, null)
|
||||||
)
|
|
||||||
val value = store.getString(UPLOAD_QUALITIES_KEY, null)
|
|
||||||
try {
|
try {
|
||||||
val jsonObject = value.asJsonObject().apply {
|
val jsonObject = value.asJsonObject().apply {
|
||||||
for (i in index until (size - 1)) {
|
for (i in index until (size - 1)) {
|
||||||
|
|
@ -373,7 +372,8 @@ class UploadMediaPresenter @Inject constructor(
|
||||||
}
|
}
|
||||||
remove("UploadItem" + (size - 1))
|
remove("UploadItem" + (size - 1))
|
||||||
}
|
}
|
||||||
store.putString(UPLOAD_QUALITIES_KEY, jsonObject.toString())
|
basicKvStoreFactory(UploadActivity.storeNameForCurrentUploadImagesSize)
|
||||||
|
.putString(UPLOAD_QUALITIES_KEY, jsonObject.toString())
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Timber.e(e)
|
Timber.e(e)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue