mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 12:23:58 +01:00
Fix NullPointerException in UploadCategoriesFragment (#6246)
This commit is contained in:
parent
ba89894dc4
commit
e1466c866b
1 changed files with 32 additions and 29 deletions
|
|
@ -97,9 +97,9 @@ class UploadCategoriesFragment : UploadBaseFragment(), CategoriesContract.View {
|
||||||
}
|
}
|
||||||
if (media == null) {
|
if (media == null) {
|
||||||
if (callback != null) {
|
if (callback != null) {
|
||||||
binding!!.tvTitle.text = getString(R.string.step_count,
|
binding?.tvTitle?.text = getString(R.string.step_count,
|
||||||
callback!!.getIndexInViewFlipper(this) + 1,
|
callback?.getIndexInViewFlipper(this)?.plus(1) ?: 1,
|
||||||
callback!!.totalNumberOfSteps,
|
callback?.totalNumberOfSteps ?: 1,
|
||||||
getString(R.string.categories_activity_title))
|
getString(R.string.categories_activity_title))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -110,7 +110,7 @@ class UploadCategoriesFragment : UploadBaseFragment(), CategoriesContract.View {
|
||||||
}
|
}
|
||||||
|
|
||||||
setTvSubTitle()
|
setTvSubTitle()
|
||||||
binding!!.tooltip.setOnClickListener {
|
binding?.let { it.tooltip.setOnClickListener {
|
||||||
showAlertDialog(
|
showAlertDialog(
|
||||||
requireActivity(),
|
requireActivity(),
|
||||||
getString(R.string.categories_activity_title),
|
getString(R.string.categories_activity_title),
|
||||||
|
|
@ -119,10 +119,11 @@ class UploadCategoriesFragment : UploadBaseFragment(), CategoriesContract.View {
|
||||||
null
|
null
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (media == null) {
|
if (media == null) {
|
||||||
presenter!!.onAttachView(this)
|
presenter?.onAttachView(this)
|
||||||
} else {
|
} else {
|
||||||
presenter!!.onAttachViewWithMedia(this, media!!)
|
presenter?.onAttachViewWithMedia(this, media!!)
|
||||||
}
|
}
|
||||||
binding!!.btnNext.setOnClickListener { v: View? -> onNextButtonClicked() }
|
binding!!.btnNext.setOnClickListener { v: View? -> onNextButtonClicked() }
|
||||||
binding!!.btnPrevious.setOnClickListener { v: View? -> onPreviousButtonClicked() }
|
binding!!.btnPrevious.setOnClickListener { v: View? -> onPreviousButtonClicked() }
|
||||||
|
|
@ -137,7 +138,7 @@ class UploadCategoriesFragment : UploadBaseFragment(), CategoriesContract.View {
|
||||||
}
|
}
|
||||||
subscribe = RxTextView.textChanges(binding!!.etSearch)
|
subscribe = RxTextView.textChanges(binding!!.etSearch)
|
||||||
.doOnEach { v: Notification<CharSequence?>? ->
|
.doOnEach { v: Notification<CharSequence?>? ->
|
||||||
binding!!.tilContainerSearch.error =
|
binding?.tilContainerSearch?.error =
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
.takeUntil(RxView.detaches(binding!!.etSearch))
|
.takeUntil(RxView.detaches(binding!!.etSearch))
|
||||||
|
|
@ -163,25 +164,25 @@ class UploadCategoriesFragment : UploadBaseFragment(), CategoriesContract.View {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun searchForCategory(query: String) {
|
private fun searchForCategory(query: String) {
|
||||||
presenter!!.searchForCategories(query)
|
presenter?.searchForCategories(query)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initRecyclerView() {
|
private fun initRecyclerView() {
|
||||||
adapter = UploadCategoryAdapter({ categoryItem: CategoryItem? ->
|
if (adapter == null) { adapter = UploadCategoryAdapter({ categoryItem: CategoryItem? ->
|
||||||
presenter!!.onCategoryItemClicked(categoryItem!!)
|
presenter?.onCategoryItemClicked(categoryItem!!)
|
||||||
Unit
|
Unit
|
||||||
}, nearbyPlaceCategory)
|
}, nearbyPlaceCategory)
|
||||||
|
}
|
||||||
if (binding != null) {
|
binding?.rvCategories?.apply {
|
||||||
binding!!.rvCategories.layoutManager = LinearLayoutManager(context)
|
layoutManager = LinearLayoutManager(context)
|
||||||
binding!!.rvCategories.adapter = adapter
|
adapter = this@UploadCategoriesFragment.adapter
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroyView() {
|
override fun onDestroyView() {
|
||||||
super.onDestroyView()
|
super.onDestroyView()
|
||||||
presenter!!.onDetachView()
|
presenter?.onDetachView()
|
||||||
subscribe!!.dispose()
|
subscribe?.dispose()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun showProgress(shouldShow: Boolean) {
|
override fun showProgress(shouldShow: Boolean) {
|
||||||
|
|
@ -197,6 +198,11 @@ class UploadCategoriesFragment : UploadBaseFragment(), CategoriesContract.View {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setCategories(categories: List<CategoryItem>?) {
|
override fun setCategories(categories: List<CategoryItem>?) {
|
||||||
|
if (adapter == null) {
|
||||||
|
Timber.e("Adapter is null in setCategories")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if (categories == null) {
|
if (categories == null) {
|
||||||
adapter!!.clear()
|
adapter!!.clear()
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -204,19 +210,16 @@ class UploadCategoriesFragment : UploadBaseFragment(), CategoriesContract.View {
|
||||||
}
|
}
|
||||||
adapter!!.notifyDataSetChanged()
|
adapter!!.notifyDataSetChanged()
|
||||||
|
|
||||||
if (binding == null) {
|
binding?.let {
|
||||||
return
|
it.rvCategories.post {
|
||||||
}
|
it.rvCategories.smoothScrollToPosition(0)
|
||||||
// Nested waiting for search result data to load into the category
|
it.rvCategories.post {
|
||||||
// list and smoothly scroll to the top of the search result list.
|
it.rvCategories.smoothScrollToPosition(
|
||||||
binding!!.rvCategories.post {
|
|
||||||
binding!!.rvCategories.smoothScrollToPosition(0)
|
|
||||||
binding!!.rvCategories.post {
|
|
||||||
binding!!.rvCategories.smoothScrollToPosition(
|
|
||||||
0
|
0
|
||||||
)
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
} ?: Timber.e("Binding is null in setCategories")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun goToNextScreen() {
|
override fun goToNextScreen() {
|
||||||
|
|
@ -308,7 +311,7 @@ class UploadCategoriesFragment : UploadBaseFragment(), CategoriesContract.View {
|
||||||
|
|
||||||
fun onNextButtonClicked() {
|
fun onNextButtonClicked() {
|
||||||
if (media != null) {
|
if (media != null) {
|
||||||
presenter!!.updateCategories(media!!, wikiText!!)
|
presenter?.updateCategories(media!!, wikiText!!)
|
||||||
} else {
|
} else {
|
||||||
presenter!!.verifyCategories()
|
presenter!!.verifyCategories()
|
||||||
}
|
}
|
||||||
|
|
@ -318,7 +321,7 @@ class UploadCategoriesFragment : UploadBaseFragment(), CategoriesContract.View {
|
||||||
if (media != null) {
|
if (media != null) {
|
||||||
presenter!!.clearPreviousSelection()
|
presenter!!.clearPreviousSelection()
|
||||||
adapter!!.items = null
|
adapter!!.items = null
|
||||||
val mediaDetailFragment = checkNotNull(parentFragment as MediaDetailFragment?)
|
val mediaDetailFragment = parentFragment as? MediaDetailFragment?: return
|
||||||
mediaDetailFragment.onResume()
|
mediaDetailFragment.onResume()
|
||||||
goBackToPreviousScreen()
|
goBackToPreviousScreen()
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -345,7 +348,7 @@ class UploadCategoriesFragment : UploadBaseFragment(), CategoriesContract.View {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
|
|
||||||
if (media != null) {
|
if (media != null) {
|
||||||
binding!!.etSearch.setOnKeyListener { v: View?, keyCode: Int, event: KeyEvent? ->
|
binding?.etSearch?.setOnKeyListener { v: View?, keyCode: Int, event: KeyEvent? ->
|
||||||
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
||||||
binding!!.etSearch.clearFocus()
|
binding!!.etSearch.clearFocus()
|
||||||
presenter!!.clearPreviousSelection()
|
presenter!!.clearPreviousSelection()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue