mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Fix empty username (#6209)
* revert changes from #5860 Signed-off-by: parneet-guraya <gurayaparneet@gmail.com> * read author prop instead Signed-off-by: parneet-guraya <gurayaparneet@gmail.com> * Use user prop if author is empty or null Signed-off-by: parneet-guraya <gurayaparneet@gmail.com> * fix test Signed-off-by: parneet-guraya <gurayaparneet@gmail.com> --------- Signed-off-by: parneet-guraya <gurayaparneet@gmail.com>
This commit is contained in:
parent
32d485cc51
commit
972bf785f1
8 changed files with 29 additions and 26 deletions
|
|
@ -125,6 +125,19 @@ class Media constructor(
|
||||||
categoriesHiddenStatus = categoriesHiddenStatus
|
categoriesHiddenStatus = categoriesHiddenStatus
|
||||||
)
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns Author if it's not null or empty, otherwise
|
||||||
|
* returns user
|
||||||
|
* @return Author or User
|
||||||
|
*/
|
||||||
|
fun getAuthorOrUser(): String? {
|
||||||
|
return if (!author.isNullOrEmpty()) {
|
||||||
|
author
|
||||||
|
} else{
|
||||||
|
user
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets media display title
|
* Gets media display title
|
||||||
* @return Media title
|
* @return Media title
|
||||||
|
|
|
||||||
|
|
@ -98,14 +98,9 @@ class GridViewAdapter(
|
||||||
*/
|
*/
|
||||||
@SuppressLint("StringFormatInvalid")
|
@SuppressLint("StringFormatInvalid")
|
||||||
private fun setUploaderView(item: Media, uploader: TextView) {
|
private fun setUploaderView(item: Media, uploader: TextView) {
|
||||||
if (!item.author.isNullOrEmpty()) {
|
uploader.text = context.getString(
|
||||||
uploader.visibility = View.VISIBLE
|
R.string.image_uploaded_by,
|
||||||
uploader.text = context.getString(
|
item.getAuthorOrUser()
|
||||||
R.string.image_uploaded_by,
|
)
|
||||||
item.user
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
uploader.visibility = View.GONE
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ an upload might take a dozen seconds. */
|
||||||
this.contribution = contribution
|
this.contribution = contribution
|
||||||
this.position = position
|
this.position = position
|
||||||
binding.contributionTitle.text = contribution.media.mostRelevantCaption
|
binding.contributionTitle.text = contribution.media.mostRelevantCaption
|
||||||
binding.authorView.text = contribution.media.author
|
binding.authorView.text = contribution.media.getAuthorOrUser()
|
||||||
|
|
||||||
//Removes flicker of loading image.
|
//Removes flicker of loading image.
|
||||||
binding.contributionImage.hierarchy.fadeDuration = 0
|
binding.contributionImage.hierarchy.fadeDuration = 0
|
||||||
|
|
|
||||||
|
|
@ -111,7 +111,7 @@ class DeleteHelper @Inject constructor(
|
||||||
|
|
||||||
val userPageString = "\n{{subst:idw|${media.filename}}} ~~~~"
|
val userPageString = "\n{{subst:idw|${media.filename}}} ~~~~"
|
||||||
|
|
||||||
val creator = media.author
|
val creator = media.getAuthorOrUser()
|
||||||
?: throw RuntimeException("Failed to nominate for deletion")
|
?: throw RuntimeException("Failed to nominate for deletion")
|
||||||
|
|
||||||
return pageEditClient.prependEdit(
|
return pageEditClient.prependEdit(
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ class MediaConverter
|
||||||
metadata.licenseShortName(),
|
metadata.licenseShortName(),
|
||||||
metadata.prefixedLicenseUrl,
|
metadata.prefixedLicenseUrl,
|
||||||
getAuthor(metadata),
|
getAuthor(metadata),
|
||||||
getAuthor(metadata),
|
imageInfo.getUser(),
|
||||||
MediaDataExtractorUtil.extractCategoriesFromList(metadata.categories()),
|
MediaDataExtractorUtil.extractCategoriesFromList(metadata.categories()),
|
||||||
metadata.latLng,
|
metadata.latLng,
|
||||||
entity.labels().mapValues { it.value.value() },
|
entity.labels().mapValues { it.value.value() },
|
||||||
|
|
|
||||||
|
|
@ -52,12 +52,7 @@ class SearchImagesViewHolder(
|
||||||
binding.categoryImageView.setOnClickListener { onImageClicked(item.second) }
|
binding.categoryImageView.setOnClickListener { onImageClicked(item.second) }
|
||||||
binding.categoryImageTitle.text = media.mostRelevantCaption
|
binding.categoryImageTitle.text = media.mostRelevantCaption
|
||||||
binding.categoryImageView.setImageURI(media.thumbUrl)
|
binding.categoryImageView.setImageURI(media.thumbUrl)
|
||||||
if (media.author?.isNotEmpty() == true) {
|
binding.categoryImageAuthor.text =
|
||||||
binding.categoryImageAuthor.visibility = View.VISIBLE
|
containerView.context.getString(R.string.image_uploaded_by, media.getAuthorOrUser())
|
||||||
binding.categoryImageAuthor.text =
|
|
||||||
containerView.context.getString(R.string.image_uploaded_by, media.user)
|
|
||||||
} else {
|
|
||||||
binding.categoryImageAuthor.visibility = View.GONE
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -328,7 +328,7 @@ public class MediaDetailPagerFragment extends CommonsDaggerSupportFragment imple
|
||||||
.append("\n\n");
|
.append("\n\n");
|
||||||
|
|
||||||
builder.append("User that you want to report: ")
|
builder.append("User that you want to report: ")
|
||||||
.append(media.getAuthor())
|
.append(media.getUser())
|
||||||
.append("\n\n");
|
.append("\n\n");
|
||||||
|
|
||||||
if (sessionManager.getUserName() != null) {
|
if (sessionManager.getUserName() != null) {
|
||||||
|
|
@ -423,7 +423,7 @@ public class MediaDetailPagerFragment extends CommonsDaggerSupportFragment imple
|
||||||
// Initialize bookmark object
|
// Initialize bookmark object
|
||||||
bookmark = new Bookmark(
|
bookmark = new Bookmark(
|
||||||
m.getFilename(),
|
m.getFilename(),
|
||||||
m.getAuthor(),
|
m.getAuthorOrUser(),
|
||||||
BookmarkPicturesContentProvider.uriForName(m.getFilename())
|
BookmarkPicturesContentProvider.uriForName(m.getFilename())
|
||||||
);
|
);
|
||||||
updateBookmarkState(menu.findItem(R.id.menu_bookmark_current_image));
|
updateBookmarkState(menu.findItem(R.id.menu_bookmark_current_image));
|
||||||
|
|
|
||||||
|
|
@ -96,7 +96,7 @@ class DeleteHelperTest {
|
||||||
).thenReturn("Media successfully deleted: Test Media Title")
|
).thenReturn("Media successfully deleted: Test Media Title")
|
||||||
|
|
||||||
val creatorName = "Creator"
|
val creatorName = "Creator"
|
||||||
whenever(media.author).thenReturn("$creatorName")
|
whenever(media.getAuthorOrUser()).thenReturn("$creatorName")
|
||||||
whenever(media.filename).thenReturn("Test file.jpg")
|
whenever(media.filename).thenReturn("Test file.jpg")
|
||||||
val makeDeletion = deleteHelper.makeDeletion(
|
val makeDeletion = deleteHelper.makeDeletion(
|
||||||
context,
|
context,
|
||||||
|
|
@ -133,7 +133,7 @@ class DeleteHelperTest {
|
||||||
|
|
||||||
whenever(media.displayTitle).thenReturn("Test file")
|
whenever(media.displayTitle).thenReturn("Test file")
|
||||||
whenever(media.filename).thenReturn("Test file.jpg")
|
whenever(media.filename).thenReturn("Test file.jpg")
|
||||||
whenever(media.author).thenReturn("Creator (page does not exist)")
|
whenever(media.getAuthorOrUser()).thenReturn("Creator (page does not exist)")
|
||||||
|
|
||||||
deleteHelper.makeDeletion(context, media, "Test reason")?.blockingGet()
|
deleteHelper.makeDeletion(context, media, "Test reason")?.blockingGet()
|
||||||
}
|
}
|
||||||
|
|
@ -148,7 +148,7 @@ class DeleteHelperTest {
|
||||||
.thenReturn(Observable.just(false))
|
.thenReturn(Observable.just(false))
|
||||||
whenever(media.displayTitle).thenReturn("Test file")
|
whenever(media.displayTitle).thenReturn("Test file")
|
||||||
whenever(media.filename).thenReturn("Test file.jpg")
|
whenever(media.filename).thenReturn("Test file.jpg")
|
||||||
whenever(media.author).thenReturn("Creator (page does not exist)")
|
whenever(media.getAuthorOrUser()).thenReturn("Creator (page does not exist)")
|
||||||
|
|
||||||
deleteHelper.makeDeletion(context, media, "Test reason")?.blockingGet()
|
deleteHelper.makeDeletion(context, media, "Test reason")?.blockingGet()
|
||||||
}
|
}
|
||||||
|
|
@ -163,7 +163,7 @@ class DeleteHelperTest {
|
||||||
.thenReturn(Observable.just(true))
|
.thenReturn(Observable.just(true))
|
||||||
whenever(media.displayTitle).thenReturn("Test file")
|
whenever(media.displayTitle).thenReturn("Test file")
|
||||||
whenever(media.filename).thenReturn("Test file.jpg")
|
whenever(media.filename).thenReturn("Test file.jpg")
|
||||||
whenever(media.author).thenReturn("Creator (page does not exist)")
|
whenever(media.getAuthorOrUser()).thenReturn("Creator (page does not exist)")
|
||||||
|
|
||||||
deleteHelper.makeDeletion(context, media, "Test reason")?.blockingGet()
|
deleteHelper.makeDeletion(context, media, "Test reason")?.blockingGet()
|
||||||
}
|
}
|
||||||
|
|
@ -221,7 +221,7 @@ class DeleteHelperTest {
|
||||||
whenever(media.displayTitle).thenReturn("Test file")
|
whenever(media.displayTitle).thenReturn("Test file")
|
||||||
whenever(media.filename).thenReturn("Test file.jpg")
|
whenever(media.filename).thenReturn("Test file.jpg")
|
||||||
|
|
||||||
whenever(media.author).thenReturn(null)
|
whenever(media.getAuthorOrUser()).thenReturn(null)
|
||||||
|
|
||||||
deleteHelper.makeDeletion(context, media, "Test reason")?.blockingGet()
|
deleteHelper.makeDeletion(context, media, "Test reason")?.blockingGet()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue