mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-28 21:33:53 +01:00
Improve credit line in image list (#6295)
Some checks are pending
Android CI / Run tests and generate APK (push) Waiting to run
Some checks are pending
Android CI / Run tests and generate APK (push) Waiting to run
- When author is not uploader, show both. - When failing to parse author from HTML, use structured data.
This commit is contained in:
parent
30762971db
commit
329a68216e
21 changed files with 363 additions and 81 deletions
|
|
@ -0,0 +1,39 @@
|
|||
package fr.free.nrw.commons.utils
|
||||
|
||||
import android.content.Context
|
||||
import android.icu.text.ListFormatter
|
||||
import android.os.Build
|
||||
import fr.free.nrw.commons.Media
|
||||
import fr.free.nrw.commons.R
|
||||
import fr.free.nrw.commons.media.IdAndLabels
|
||||
import java.util.Locale
|
||||
|
||||
object MediaAttributionUtil {
|
||||
fun getTagLine(media: Media, context: Context): String {
|
||||
val uploader = media.user
|
||||
val author = media.getAttributedAuthor()
|
||||
return if (author.isNullOrEmpty()) {
|
||||
context.getString(R.string.image_uploaded_by, uploader)
|
||||
} else if (author == uploader) {
|
||||
context.getString(R.string.image_tag_line_created_and_uploaded_by, author)
|
||||
} else {
|
||||
context.getString(
|
||||
R.string.image_tag_line_created_by_and_uploaded_by,
|
||||
author,
|
||||
uploader
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun getCreatorName(idAndLabels: List<IdAndLabels>): String? {
|
||||
val locale = Locale.getDefault()
|
||||
val names = idAndLabels.map{ x -> x.getLocalizedLabel(locale.language)}
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
val formatter = ListFormatter.getInstance(locale)
|
||||
return formatter.format(names)
|
||||
} else {
|
||||
return names.joinToString(", ")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,9 +1,8 @@
|
|||
package fr.free.nrw.commons.utils
|
||||
|
||||
import android.os.Build
|
||||
import android.text.Html
|
||||
import android.text.Spanned
|
||||
import android.text.SpannedString
|
||||
import androidx.core.text.HtmlCompat
|
||||
|
||||
object StringUtil {
|
||||
|
||||
|
|
@ -26,12 +25,6 @@ object StringUtil {
|
|||
.replace("‏", "\u200F")
|
||||
.replace("&", "&")
|
||||
|
||||
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
Html.fromHtml(processedSource, Html.FROM_HTML_MODE_LEGACY)
|
||||
} else {
|
||||
//noinspection deprecation
|
||||
@Suppress("DEPRECATION")
|
||||
Html.fromHtml(processedSource)
|
||||
}
|
||||
return HtmlCompat.fromHtml(processedSource, HtmlCompat.FROM_HTML_MODE_LEGACY)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue