mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Fix : UninitializedPropertyAccessException (#6248)
* Fix crash when uploading a duplicate file * Fix: app crash * added Kdoc * remove line b/w kdoc and function --------- Co-authored-by: Nicolas Raoul <nicolas.raoul@gmail.com>
This commit is contained in:
parent
91ca2e6672
commit
c49c85e68b
2 changed files with 29 additions and 4 deletions
|
|
@ -173,6 +173,9 @@ class UploadActivity : BaseActivity(), UploadContract.View, UploadBaseFragment.C
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
|
// Ensure basicKvStoreFactory is always initialized before use
|
||||||
|
presenter?.setupBasicKvStoreFactory { BasicKvStore(this@UploadActivity, it) }
|
||||||
|
|
||||||
_binding = ActivityUploadBinding.inflate(layoutInflater)
|
_binding = ActivityUploadBinding.inflate(layoutInflater)
|
||||||
setContentView(binding.root)
|
setContentView(binding.root)
|
||||||
|
|
||||||
|
|
@ -903,7 +906,6 @@ 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
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,8 +34,7 @@ class UploadPresenter @Inject internal constructor(
|
||||||
|
|
||||||
private val compositeDisposable = CompositeDisposable()
|
private val compositeDisposable = CompositeDisposable()
|
||||||
|
|
||||||
lateinit var basicKvStoreFactory: (String) -> BasicKvStore
|
private var basicKvStoreFactory: ((String) -> BasicKvStore)? = null
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called by the submit button in [UploadActivity]
|
* Called by the submit button in [UploadActivity]
|
||||||
*/
|
*/
|
||||||
|
|
@ -132,14 +131,38 @@ class UploadPresenter @Inject internal constructor(
|
||||||
basicKvStoreFactory = factory
|
basicKvStoreFactory = factory
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the current BasicKvStore factory or throws if not initialized.
|
||||||
|
*
|
||||||
|
* @throws IllegalStateException if basicKvStoreFactory has not been initialized.
|
||||||
|
*/
|
||||||
|
private fun getBasicKvStoreFactory(): (String) -> BasicKvStore {
|
||||||
|
return basicKvStoreFactory ?: throw IllegalStateException("basicKvStoreFactory has not been initialized")
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ensures that the BasicKvStore factory has been initialized before use.
|
||||||
|
*
|
||||||
|
* @throws IllegalStateException if the factory is null.
|
||||||
|
*/
|
||||||
|
private fun requireFactoryInitialized() {
|
||||||
|
val field = this::class.java.getDeclaredField("basicKvStoreFactory")
|
||||||
|
field.isAccessible = true
|
||||||
|
val value = field.get(this)
|
||||||
|
if (value == null) {
|
||||||
|
throw IllegalStateException("basicKvStoreFactory must be initialized before use. Please call setupBasicKvStoreFactory() before using presenter methods that require it.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calls checkImageQuality of UploadMediaPresenter to check image quality of next image
|
* Calls checkImageQuality of UploadMediaPresenter to check image quality of next image
|
||||||
*
|
*
|
||||||
* @param uploadItemIndex Index of next image, whose quality is to be checked
|
* @param uploadItemIndex Index of next image, whose quality is to be checked
|
||||||
*/
|
*/
|
||||||
override fun checkImageQuality(uploadItemIndex: Int) {
|
override fun checkImageQuality(uploadItemIndex: Int) {
|
||||||
|
requireFactoryInitialized()
|
||||||
repository.getUploadItem(uploadItemIndex)?.let {
|
repository.getUploadItem(uploadItemIndex)?.let {
|
||||||
presenter.setupBasicKvStoreFactory(basicKvStoreFactory)
|
presenter.setupBasicKvStoreFactory(getBasicKvStoreFactory())
|
||||||
presenter.checkImageQuality(it, uploadItemIndex)
|
presenter.checkImageQuality(it, uploadItemIndex)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue