Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions app/src/main/java/fr/free/nrw/commons/media/MediaDetailFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -650,10 +650,8 @@ class MediaDetailFragment : CommonsDaggerSupportFragment(), CategoryEditHelper.C
}

private fun onDepictionsLoaded(idAndCaptions: List<IdAndCaptions>) {
binding.depictsLayout.visibility =
if (idAndCaptions.isEmpty()) View.GONE else View.VISIBLE
binding.depictionsEditButton.visibility =
if (idAndCaptions.isEmpty()) View.GONE else View.VISIBLE
binding.depictsLayout.visibility = View.VISIBLE
binding.depictionsEditButton.visibility = View.VISIBLE
buildDepictionList(idAndCaptions)
}

Expand Down Expand Up @@ -863,8 +861,22 @@ class MediaDetailFragment : CommonsDaggerSupportFragment(), CategoryEditHelper.C
*/
private fun buildDepictionList(idAndCaptions: List<IdAndCaptions>) {
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
for (idAndCaption: IdAndCaptions in idAndCaptions) {
for (idAndCaption: IdAndCaptions in mutableIdAndCaptions) {
binding.mediaDetailDepictionContainer.addView(
buildDepictLabel(
getDepictionCaption(idAndCaption, locale),
Expand All @@ -875,6 +887,7 @@ class MediaDetailFragment : CommonsDaggerSupportFragment(), CategoryEditHelper.C
}
}


private fun getDepictionCaption(idAndCaption: IdAndCaptions, locale: String): String? {
// Check if the Depiction Caption is available in user's locale
// if not then check for english, else show any available.
Expand Down