Skip to content

Commit a299a9f

Browse files
* Defined two feild author and user in Media and used them at the corresponding places Minor bug fixes -displaying userName in uploadedBy. -modified HTML parsing in getArtist. -Replaced creator with author.
1 parent c93ab86 commit a299a9f

17 files changed

+56
-61
lines changed

app/src/main/java/fr/free/nrw/commons/Media.kt

+9-6
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,15 @@ class Media constructor(
5555
val licenseUrl: String? = null,
5656
/**
5757
* Gets the name of the creator of the file.
58-
* @return creator name as a String
58+
* @return author name as a String
5959
*/
6060
/**
61-
* Sets the creator name of the file.
62-
* @param creator creator name as a string
61+
* Sets the author name of the file.
62+
* @param author creator name as a string
6363
*/
64-
var creator: String? = null,
64+
var author: String? = null,
65+
66+
var user:String?=null,
6567

6668
/**
6769
* Gets the categories the file falls under.
@@ -83,12 +85,13 @@ class Media constructor(
8385
categories: List<String>?,
8486
filename: String?,
8587
fallbackDescription: String?,
86-
creator: String?
88+
author: String?, user:String?
8789
) : this(
8890
filename = filename,
8991
fallbackDescription = fallbackDescription,
9092
dateUploaded = Date(),
91-
creator = creator,
93+
author = author,
94+
user=user,
9295
categories = categories,
9396
captions = captions
9497
)

app/src/main/java/fr/free/nrw/commons/auth/SessionManager.java

-12
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ public class SessionManager {
2828
private final Context context;
2929
private Account currentAccount; // Unlike a savings account... ;-)
3030
private JsonKvStore defaultKvStore;
31-
private static final String KEY_RAWUSERNAME = "rawusername";
3231

3332
@Inject
3433
public SessionManager(Context context,
@@ -99,17 +98,6 @@ public String getUserName() {
9998
return account == null ? null : account.name;
10099
}
101100

102-
@Nullable
103-
private String getRawUserName() {
104-
Account account = getCurrentAccount();
105-
return account == null ? null : accountManager().getUserData(account, KEY_RAWUSERNAME);
106-
}
107-
108-
public String getAuthorName(){
109-
return getRawUserName() == null ? getUserName() : getRawUserName();
110-
}
111-
112-
113101
@Nullable
114102
public String getPassword() {
115103
Account account = getCurrentAccount();

app/src/main/java/fr/free/nrw/commons/category/GridViewAdapter.java

+8-9
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
import java.util.ArrayList;
1616
import java.util.List;
17-
import java.util.Locale;
1817

1918
import fr.free.nrw.commons.Media;
2019
import fr.free.nrw.commons.R;
@@ -87,9 +86,9 @@ public View getView(int position, View convertView, ViewGroup parent) {
8786
Media item = data.get(position);
8887
SimpleDraweeView imageView = convertView.findViewById(R.id.categoryImageView);
8988
TextView fileName = convertView.findViewById(R.id.categoryImageTitle);
90-
TextView author = convertView.findViewById(R.id.categoryImageAuthor);
89+
TextView uploader = convertView.findViewById(R.id.categoryImageAuthor);
9190
fileName.setText(item.getMostRelevantCaption());
92-
setAuthorView(item, author);
91+
setUploaderView(item, uploader);
9392
imageView.setImageURI(item.getThumbUrl());
9493
return convertView;
9594
}
@@ -107,14 +106,14 @@ public Media getItem(int position) {
107106
/**
108107
* Shows author information if its present
109108
* @param item
110-
* @param author
109+
* @param uploader
111110
*/
112-
private void setAuthorView(Media item, TextView author) {
113-
if (!TextUtils.isEmpty(item.getCreator())) {
114-
author.setVisibility(View.VISIBLE);
115-
author.setText(getContext().getString(R.string.image_uploaded_by, item.getCreator()));
111+
private void setUploaderView(Media item, TextView uploader) {
112+
if (!TextUtils.isEmpty(item.getAuthor())) {
113+
uploader.setVisibility(View.VISIBLE);
114+
uploader.setText(getContext().getString(R.string.image_uploaded_by, item.getUser()));
116115
} else {
117-
author.setVisibility(View.GONE);
116+
uploader.setVisibility(View.GONE);
118117
}
119118
}
120119
}

app/src/main/java/fr/free/nrw/commons/contributions/Contribution.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ data class Contribution constructor(
5757
categories,
5858
item.fileName,
5959
formatDescriptions(item.uploadMediaDetails),
60-
sessionManager.authorName
60+
sessionManager.userName,
61+
sessionManager.userName
6162
),
6263
localUri = item.mediaUri,
6364
decimalCoords = item.gpsCoords.decimalCoords,

app/src/main/java/fr/free/nrw/commons/contributions/ContributionViewHolder.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import fr.free.nrw.commons.R;
1919
import fr.free.nrw.commons.contributions.ContributionsListAdapter.Callback;
2020
import fr.free.nrw.commons.media.MediaClient;
21-
import fr.free.nrw.commons.utils.ViewUtil;
2221
import io.reactivex.android.schedulers.AndroidSchedulers;
2322
import io.reactivex.disposables.CompositeDisposable;
2423
import io.reactivex.schedulers.Schedulers;
@@ -68,7 +67,7 @@ public void init(final int position, final Contribution contribution) {
6867
this.contribution = contribution;
6968
this.position = position;
7069
titleView.setText(contribution.getMedia().getMostRelevantCaption());
71-
authorView.setText(contribution.getMedia().getCreator());
70+
authorView.setText(contribution.getMedia().getAuthor());
7271

7372
imageView.getHierarchy().setPlaceholderImage(R.drawable.image_placeholder);
7473
imageView.getHierarchy().setFailureImage(R.drawable.image_placeholder);

app/src/main/java/fr/free/nrw/commons/db/AppDatabase.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import fr.free.nrw.commons.contributions.ContributionDao
1010
* The database for accessing the respective DAOs
1111
*
1212
*/
13-
@Database(entities = [Contribution::class], version = 6, exportSchema = false)
13+
@Database(entities = [Contribution::class], version = 7, exportSchema = false)
1414
@TypeConverters(Converters::class)
1515
abstract class AppDatabase : RoomDatabase() {
1616
abstract fun contributionDao(): ContributionDao

app/src/main/java/fr/free/nrw/commons/delete/DeleteHelper.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,10 @@ private Observable<Boolean> delete(Media media, String reason) {
9494
String userPageString = "\n{{subst:idw|" + media.getFilename() +
9595
"}} ~~~~";
9696

97-
String creator = media.getCreator();
97+
String creator = media.getAuthor();
9898
if (creator == null || creator.isEmpty()) {
9999
throw new RuntimeException("Failed to nominate for deletion");
100100
}
101-
String creatorName = creator.replace(" (page does not exist)", "");
102101

103102
return pageEditClient.prependEdit(media.getFilename(), fileDeleteString + "\n", summary)
104103
.flatMap(result -> {
@@ -113,7 +112,7 @@ private Observable<Boolean> delete(Media media, String reason) {
113112
throw new RuntimeException("Failed to nominate for deletion");
114113
}).flatMap(result -> {
115114
if (result) {
116-
return pageEditClient.appendEdit("User_Talk:" + creatorName, userPageString + "\n", summary);
115+
return pageEditClient.appendEdit("User_Talk:" + creator, userPageString + "\n", summary);
117116
}
118117
throw new RuntimeException("Failed to nominate for deletion");
119118
});

app/src/main/java/fr/free/nrw/commons/explore/media/MediaConverter.kt

+11-5
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ class MediaConverter @Inject constructor() {
2929
safeParseDate(metadata.dateTime()),
3030
metadata.licenseShortName(),
3131
metadata.prefixedLicenseUrl,
32-
getArtist(metadata),
32+
getAuthor(metadata),
33+
imageInfo.user,
3334
MediaDataExtractorUtil.extractCategoriesFromList(metadata.categories),
3435
metadata.latLng,
3536
entity.labels().mapValues { it.value.value() },
@@ -61,11 +62,16 @@ class MediaConverter @Inject constructor() {
6162
* @param metadata
6263
* @return
6364
*/
64-
private fun getArtist(metadata: ExtMetadata): String? {
65+
private fun getAuthor(metadata: ExtMetadata): String? {
6566
return try {
66-
val artistHtml = metadata.artist()
67-
artistHtml.substring(artistHtml.indexOf("title=\""), artistHtml.indexOf("\">"))
68-
.replace("title=\"User:", "")
67+
val authorHtml = metadata.artist()
68+
val anchorStartTagTerminalChars = "\">"
69+
val anchorCloseTag = "</a>"
70+
71+
return authorHtml.substring(
72+
authorHtml.indexOf(anchorStartTagTerminalChars) + anchorStartTagTerminalChars
73+
.length, authorHtml.indexOf(anchorCloseTag)
74+
)
6975
} catch (ex: java.lang.Exception) {
7076
""
7177
}

app/src/main/java/fr/free/nrw/commons/explore/media/PagedMediaAdapter.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ class SearchImagesViewHolder(containerView: View, val onImageClicked: (Int) -> U
3737
categoryImageView.setOnClickListener { onImageClicked(item.second) }
3838
categoryImageTitle.text = media.mostRelevantCaption
3939
categoryImageView.setImageURI(media.thumbUrl)
40-
if (media.creator?.isNotEmpty() == true) {
40+
if (media.author?.isNotEmpty() == true) {
4141
categoryImageAuthor.visibility = View.VISIBLE
4242
categoryImageAuthor.text =
43-
containerView.context.getString(R.string.image_uploaded_by, media.creator)
43+
containerView.context.getString(R.string.image_uploaded_by, media.user)
4444
} else {
4545
categoryImageAuthor.visibility = View.GONE
4646
}

app/src/main/java/fr/free/nrw/commons/media/MediaDetailFragment.java

+3-5
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import android.text.Editable;
1818
import android.text.TextUtils;
1919
import android.text.TextWatcher;
20-
import android.util.Log;
2120
import android.view.LayoutInflater;
2221
import android.view.View;
2322
import android.view.ViewGroup;
@@ -66,7 +65,6 @@
6665
import fr.free.nrw.commons.nearby.Label;
6766
import fr.free.nrw.commons.ui.widget.HtmlTextView;
6867
import fr.free.nrw.commons.utils.ViewUtilWrapper;
69-
import io.reactivex.Observable;
7068
import io.reactivex.Single;
7169
import io.reactivex.android.schedulers.AndroidSchedulers;
7270
import io.reactivex.schedulers.Schedulers;
@@ -542,10 +540,10 @@ private void setTextFields(Media media) {
542540

543541
updateCategoryList();
544542

545-
if (media.getCreator() == null || media.getCreator().equals("")) {
543+
if (media.getAuthor() == null || media.getAuthor().equals("")) {
546544
authorLayout.setVisibility(GONE);
547545
} else {
548-
author.setText(media.getCreator());
546+
author.setText(media.getAuthor());
549547
}
550548
}
551549

@@ -679,7 +677,7 @@ public void updateCategories(List<String> selectedCategories) {
679677
@SuppressLint("StringFormatInvalid")
680678
@OnClick(R.id.nominateDeletion)
681679
public void onDeleteButtonClicked(){
682-
if (AccountUtil.getUserName(getContext()) != null && AccountUtil.getUserName(getContext()).equals(media.getCreator())) {
680+
if (AccountUtil.getUserName(getContext()) != null && AccountUtil.getUserName(getContext()).equals(media.getAuthor())) {
683681
final ArrayAdapter<String> languageAdapter = new ArrayAdapter<>(getActivity(),
684682
R.layout.simple_spinner_dropdown_list, reasonList);
685683
final Spinner spinner = new Spinner(getActivity());

app/src/main/java/fr/free/nrw/commons/media/MediaDetailPagerFragment.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
254254
// Initialize bookmark object
255255
bookmark = new Bookmark(
256256
m.getFilename(),
257-
m.getCreator(),
257+
m.getAuthor(),
258258
BookmarkPicturesContentProvider.uriForName(m.getFilename())
259259
);
260260
updateBookmarkState(menu.findItem(R.id.menu_bookmark_current_image));

app/src/main/java/fr/free/nrw/commons/media/MediaInterface.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* Interface for interacting with Commons media related APIs
1212
*/
1313
public interface MediaInterface {
14-
String MEDIA_PARAMS="&prop=imageinfo&iiprop=url|extmetadata&iiurlwidth=640" +
14+
String MEDIA_PARAMS="&prop=imageinfo&iiprop=url|extmetadata|user&&iiurlwidth=640" +
1515
"&iiextmetadatafilter=DateTime|Categories|GPSLatitude|GPSLongitude|ImageDescription|DateTimeOriginal" +
1616
"|Artist|LicenseShortName|LicenseUrl";
1717

app/src/main/java/fr/free/nrw/commons/upload/PageContentsCreator.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ public String createFrom(Contribution contribution) {
3737
.append("{{Information\n")
3838
.append("|description=").append(media.getFallbackDescription()).append("\n")
3939
.append("|source=").append("{{own}}\n")
40-
.append("|author=[[User:").append(media.getCreator()).append("|")
41-
.append(media.getCreator()).append("]]\n");
40+
.append("|author=[[User:").append(media.getAuthor()).append("|")
41+
.append(media.getAuthor()).append("]]\n");
4242

4343
String templatizedCreatedDate = getTemplatizedCreatedDate(
4444
contribution.getDateCreated(), contribution.getDateCreatedSource());

app/src/main/java/fr/free/nrw/commons/upload/UploadController.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -97,18 +97,18 @@ public void startUpload(final Contribution contribution) {
9797
final Media media = contribution.getMedia();
9898
if (store.getBoolean("useAuthorName", false)) {
9999
final String authorName = store.getString("authorName", "");
100-
media.setCreator(authorName);
100+
media.setAuthor(authorName);
101101
}
102102

103-
if (TextUtils.isEmpty(media.getCreator())) {
103+
if (TextUtils.isEmpty(media.getAuthor())) {
104104
final Account currentAccount = sessionManager.getCurrentAccount();
105105
if (currentAccount == null) {
106106
Timber.d("Current account is null");
107107
ViewUtil.showLongToast(context, context.getString(R.string.user_not_logged_in));
108108
sessionManager.forceLogin(context);
109109
return;
110110
}
111-
media.setCreator(sessionManager.getAuthorName());
111+
media.setAuthor(sessionManager.getUserName());
112112
}
113113

114114
if (media.getFallbackDescription() == null) {

app/src/test/kotlin/ModelFunctions.kt

+4-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ fun media(
4040
dateUploaded: Date? = Date(),
4141
license: String? = "license",
4242
licenseUrl: String? = "licenseUrl",
43-
creator: String? = "creator",
43+
author: String? = "creator",
44+
user:String?="user",
4445
pageId: String = "pageId",
4546
categories: List<String>? = listOf("categories"),
4647
coordinates: LatLng? = LatLng(0.0, 0.0, 0.0f),
@@ -56,7 +57,8 @@ fun media(
5657
dateUploaded,
5758
license,
5859
licenseUrl,
59-
creator,
60+
author,
61+
user,
6062
categories,
6163
coordinates,
6264
captions,

app/src/test/kotlin/fr/free/nrw/commons/delete/DeleteHelperTest.kt

+5-5
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class DeleteHelperTest {
5656
whenever(media.displayTitle).thenReturn("Test file")
5757

5858
val creatorName = "Creator"
59-
whenever(media.creator).thenReturn("$creatorName (page does not exist)")
59+
whenever(media.author).thenReturn("$creatorName")
6060
whenever(media.filename).thenReturn("Test file.jpg")
6161

6262
val makeDeletion = deleteHelper.makeDeletion(context, media, "Test reason")?.blockingGet()
@@ -78,7 +78,7 @@ class DeleteHelperTest {
7878
.thenReturn(Observable.just(true))
7979
whenever(media.displayTitle).thenReturn("Test file")
8080
whenever(media.filename).thenReturn("Test file.jpg")
81-
whenever(media.creator).thenReturn("Creator (page does not exist)")
81+
whenever(media.author).thenReturn("Creator (page does not exist)")
8282

8383
deleteHelper.makeDeletion(context, media, "Test reason")?.blockingGet()
8484
}
@@ -93,7 +93,7 @@ class DeleteHelperTest {
9393
.thenReturn(Observable.just(false))
9494
whenever(media.displayTitle).thenReturn("Test file")
9595
whenever(media.filename).thenReturn("Test file.jpg")
96-
whenever(media.creator).thenReturn("Creator (page does not exist)")
96+
whenever(media.author).thenReturn("Creator (page does not exist)")
9797

9898
deleteHelper.makeDeletion(context, media, "Test reason")?.blockingGet()
9999
}
@@ -108,7 +108,7 @@ class DeleteHelperTest {
108108
.thenReturn(Observable.just(true))
109109
whenever(media.displayTitle).thenReturn("Test file")
110110
whenever(media.filename).thenReturn("Test file.jpg")
111-
whenever(media.creator).thenReturn("Creator (page does not exist)")
111+
whenever(media.author).thenReturn("Creator (page does not exist)")
112112

113113
deleteHelper.makeDeletion(context, media, "Test reason")?.blockingGet()
114114
}
@@ -125,7 +125,7 @@ class DeleteHelperTest {
125125
whenever(media.displayTitle).thenReturn("Test file")
126126
whenever(media.filename).thenReturn("Test file.jpg")
127127

128-
whenever(media.creator).thenReturn(null)
128+
whenever(media.author).thenReturn(null)
129129

130130
deleteHelper.makeDeletion(context, media, "Test reason")?.blockingGet()
131131
}

app/src/test/kotlin/fr/free/nrw/commons/upload/UploadControllerTest.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class UploadControllerTest {
5252
val contribution = mock(Contribution::class.java)
5353
val media = mock<Media>()
5454
whenever(contribution.media).thenReturn(media)
55-
whenever(media.creator).thenReturn("Creator")
55+
whenever(media.author).thenReturn("Creator")
5656
uploadController!!.startUpload(contribution)
5757
}
5858
}

0 commit comments

Comments
 (0)