Show placeholder and display depiction section when no depictions are available (#6163) (#6165)

* corrected

* corrected

* Update MediaDetailFragment.kt

Spelling correction
This commit is contained in:
Sujal 2025-01-29 19:20:29 +05:30 committed by GitHub
parent e01ecb20fa
commit 36f844a709
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -650,10 +650,8 @@ class MediaDetailFragment : CommonsDaggerSupportFragment(), CategoryEditHelper.C
} }
private fun onDepictionsLoaded(idAndCaptions: List<IdAndCaptions>) { private fun onDepictionsLoaded(idAndCaptions: List<IdAndCaptions>) {
binding.depictsLayout.visibility = binding.depictsLayout.visibility = View.VISIBLE
if (idAndCaptions.isEmpty()) View.GONE else View.VISIBLE binding.depictionsEditButton.visibility = View.VISIBLE
binding.depictionsEditButton.visibility =
if (idAndCaptions.isEmpty()) View.GONE else View.VISIBLE
buildDepictionList(idAndCaptions) buildDepictionList(idAndCaptions)
} }
@ -863,8 +861,22 @@ class MediaDetailFragment : CommonsDaggerSupportFragment(), CategoryEditHelper.C
*/ */
private fun buildDepictionList(idAndCaptions: List<IdAndCaptions>) { private fun buildDepictionList(idAndCaptions: List<IdAndCaptions>) {
binding.mediaDetailDepictionContainer.removeAllViews() binding.mediaDetailDepictionContainer.removeAllViews()
// Create a mutable list from the original list
val mutableIdAndCaptions = idAndCaptions.toMutableList()
if (mutableIdAndCaptions.isEmpty()) {
// Create a placeholder IdAndCaptions object and add it to the list
mutableIdAndCaptions.add(
IdAndCaptions(
id = media?.pageId ?: "", // Use an empty string if media?.pageId is null
captions = mapOf(Locale.getDefault().language to getString(R.string.detail_panel_cats_none)) // Create a Map with the language as the key and the message as the value
)
)
}
val locale: String = Locale.getDefault().language val locale: String = Locale.getDefault().language
for (idAndCaption: IdAndCaptions in idAndCaptions) { for (idAndCaption: IdAndCaptions in mutableIdAndCaptions) {
binding.mediaDetailDepictionContainer.addView( binding.mediaDetailDepictionContainer.addView(
buildDepictLabel( buildDepictLabel(
getDepictionCaption(idAndCaption, locale), getDepictionCaption(idAndCaption, locale),
@ -875,6 +887,7 @@ class MediaDetailFragment : CommonsDaggerSupportFragment(), CategoryEditHelper.C
} }
} }
private fun getDepictionCaption(idAndCaption: IdAndCaptions, locale: String): String? { private fun getDepictionCaption(idAndCaption: IdAndCaptions, locale: String): String? {
// Check if the Depiction Caption is available in user's locale // Check if the Depiction Caption is available in user's locale
// if not then check for english, else show any available. // if not then check for english, else show any available.