Skip to content

Commit 9eb6414

Browse files
committed
Minor fixes in media and search
1 parent f0b1d68 commit 9eb6414

File tree

10 files changed

+76
-87
lines changed

10 files changed

+76
-87
lines changed

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,17 @@ public Media[] newArray(int i) {
4747
protected String imageUrl;
4848
protected String filename;
4949
protected String description; // monolingual description on input...
50-
protected String discussion;
51-
protected long dataLength;
50+
private String discussion;
51+
private long dataLength;
5252
protected Date dateCreated;
5353
protected @Nullable Date dateUploaded;
5454
protected int width;
5555
protected int height;
5656
protected String license;
57-
protected String licenseUrl;
57+
private String licenseUrl;
5858
protected String creator;
5959
protected ArrayList<String> categories; // as loaded at runtime?
60-
protected boolean requestedDeletion;
60+
private boolean requestedDeletion;
6161
private Map<String, String> descriptions; // multilingual descriptions as loaded
6262
private HashMap<String, Object> tags = new HashMap<>();
6363
private @Nullable LatLng coordinates;
@@ -261,7 +261,7 @@ public void setFilename(String filename) {
261261
* Sets the discussion of the file.
262262
* @param discussion
263263
*/
264-
public void setDiscussion(String discussion) {
264+
void setDiscussion(String discussion) {
265265
this.discussion = discussion;
266266
}
267267

@@ -387,7 +387,7 @@ public String getLicense() {
387387
return license;
388388
}
389389

390-
public void setThumbUrl(String thumbUrl) {
390+
private void setThumbUrl(String thumbUrl) {
391391
this.thumbUrl = thumbUrl;
392392
}
393393

@@ -399,7 +399,7 @@ public String getLicenseUrl() {
399399
* Sets the license name of the file.
400400
* @param license license name as a String
401401
*/
402-
public void setLicenseInformation(String license, String licenseUrl) {
402+
private void setLicenseInformation(String license, String licenseUrl) {
403403
this.license = license;
404404

405405
if (!licenseUrl.startsWith("http://") && !licenseUrl.startsWith("https://")) {
@@ -450,7 +450,7 @@ public void setCategories(List<String> categories) {
450450
* Modifies (or sets) media descriptions
451451
* @param descriptions Media descriptions
452452
*/
453-
void setDescriptions(Map<String, String> descriptions) {
453+
private void setDescriptions(Map<String, String> descriptions) {
454454
this.descriptions.clear();
455455
this.descriptions.putAll(descriptions);
456456
}
@@ -521,7 +521,7 @@ public void writeToParcel(Parcel parcel, int flags) {
521521
/**
522522
* Set requested deletion to true
523523
*/
524-
public void setRequestedDeletion(){
524+
void setRequestedDeletion(){
525525
requestedDeletion = true;
526526
}
527527

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

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
@Singleton
2222
public class CategoryClient {
2323

24-
private final CategoryInterface CategoryInterface;
24+
private final CategoryInterface categoryInterface;
2525

2626
@Inject
27-
public CategoryClient(CategoryInterface CategoryInterface) {
28-
this.CategoryInterface = CategoryInterface;
27+
public CategoryClient(CategoryInterface categoryInterface) {
28+
this.categoryInterface = categoryInterface;
2929
}
3030

3131
/**
@@ -37,7 +37,7 @@ public CategoryClient(CategoryInterface CategoryInterface) {
3737
* @return
3838
*/
3939
public Observable<String> searchCategories(String filter, int itemLimit, int offset) {
40-
return responseToCategoryName(CategoryInterface.searchCategories(filter, itemLimit, offset));
40+
return responseToCategoryName(categoryInterface.searchCategories(filter, itemLimit, offset));
4141

4242
}
4343

@@ -53,18 +53,6 @@ public Observable<String> searchCategories(String filter, int itemLimit) {
5353

5454
}
5555

56-
/**
57-
* Searches for categories starting with the specified string.
58-
*
59-
* @param prefix The prefix to be searched
60-
* @param itemLimit How many results are returned
61-
* @param offset Starts returning items from the nth result. If offset is 9, the response starts with the 9th item of the search result
62-
* @return
63-
*/
64-
public Observable<String> searchCategoriesForPrefix(String prefix, int itemLimit, int offset) {
65-
return responseToCategoryName(CategoryInterface.searchCategoriesForPrefix(prefix, itemLimit, offset));
66-
}
67-
6856
/**
6957
* Searches for categories starting with the specified string.
7058
*
@@ -73,10 +61,9 @@ public Observable<String> searchCategoriesForPrefix(String prefix, int itemLimit
7361
* @return
7462
*/
7563
public Observable<String> searchCategoriesForPrefix(String prefix, int itemLimit) {
76-
return searchCategoriesForPrefix(prefix, itemLimit, 0);
64+
return responseToCategoryName(categoryInterface.searchCategoriesForPrefix(prefix, itemLimit));
7765
}
7866

79-
8067
/**
8168
* The method takes categoryName as input and returns a List of Subcategories
8269
* It uses the generator query API to get the subcategories in a category, 500 at a time.
@@ -85,7 +72,7 @@ public Observable<String> searchCategoriesForPrefix(String prefix, int itemLimit
8572
* @return Observable emitting the categories returned. If our search yielded "Category:Test", "Test" is emitted.
8673
*/
8774
public Observable<String> getSubCategoryList(String categoryName) {
88-
return responseToCategoryName(CategoryInterface.getSubCategoryList(categoryName));
75+
return responseToCategoryName(categoryInterface.getSubCategoryList(categoryName));
8976
}
9077

9178
/**
@@ -97,7 +84,7 @@ public Observable<String> getSubCategoryList(String categoryName) {
9784
*/
9885
@NonNull
9986
public Observable<String> getParentCategoryList(String categoryName) {
100-
return responseToCategoryName(CategoryInterface.getParentCategoryList(categoryName));
87+
return responseToCategoryName(categoryInterface.getParentCategoryList(categoryName));
10188
}
10289

10390
/**
@@ -119,7 +106,6 @@ private Observable<String> responseToCategoryName(Observable<MwQueryResponse> re
119106
return Observable.fromIterable(pages);
120107
})
121108
.map(MwQueryPage::title)
122-
.doOnEach(s -> Timber.d("Category returned: %s", s))
123109
.map(cat -> cat.replace("Category:", ""));
124110
}
125111
}

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

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
package fr.free.nrw.commons.category;
22

3-
import android.content.Context;
4-
import android.content.Intent;
5-
import android.database.DataSetObserver;
63
import android.os.Bundle;
7-
import androidx.fragment.app.FragmentManager;
8-
import androidx.fragment.app.FragmentTransaction;
94
import android.view.Menu;
105
import android.view.MenuInflater;
116
import android.view.MenuItem;
127
import android.view.View;
138
import android.widget.AdapterView;
149

10+
import androidx.fragment.app.FragmentManager;
11+
import androidx.fragment.app.FragmentTransaction;
12+
1513
import butterknife.ButterKnife;
1614
import fr.free.nrw.commons.Media;
1715
import fr.free.nrw.commons.R;
@@ -127,20 +125,6 @@ public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
127125
forceInitBackButton();
128126
}
129127

130-
/**
131-
* Consumers should be simply using this method to use this activity.
132-
* @param context A Context of the application package implementing this class.
133-
* @param title Page title
134-
* @param categoryName Name of the category for displaying its images
135-
*/
136-
public static void startYourself(Context context, String title, String categoryName) {
137-
Intent intent = new Intent(context, CategoryImagesActivity.class);
138-
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_SINGLE_TOP);
139-
intent.putExtra("title", title);
140-
intent.putExtra("categoryName", categoryName);
141-
context.startActivity(intent);
142-
}
143-
144128
/**
145129
* This method is called mediaDetailPagerFragment. It returns the Media Object at that Index
146130
* @param i It is the index of which media object is to be returned which is same as

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@
1313
import android.widget.RelativeLayout;
1414
import android.widget.TextView;
1515

16+
import androidx.annotation.Nullable;
17+
1618
import java.util.List;
1719
import java.util.concurrent.TimeUnit;
1820

1921
import javax.inject.Inject;
2022
import javax.inject.Named;
2123

22-
import androidx.annotation.Nullable;
2324
import butterknife.BindView;
2425
import butterknife.ButterKnife;
2526
import dagger.android.support.DaggerFragment;
@@ -90,6 +91,9 @@ private void initViews() {
9091
String categoryName = getArguments().getString("categoryName");
9192
if (getArguments() != null && categoryName != null) {
9293
this.categoryName = categoryName;
94+
if (!this.categoryName.startsWith("Category:")) {
95+
this.categoryName = "Category:" + categoryName;
96+
}
9397
resetQueryContinueValues(categoryName);
9498
initList();
9599
setScrollListener();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Observable<MwQueryResponse> searchCategories(@Query("gsrsearch") String filter,
3333
@GET("w/api.php?action=query&format=json&formatversion=2"
3434
+ "&generator=allcategories")
3535
Observable<MwQueryResponse> searchCategoriesForPrefix(@Query("gacprefix") String prefix,
36-
@Query("gaclimit") int itemLimit, @Query("gacoffset") int offset);
36+
@Query("gaclimit") int itemLimit);
3737

3838
@GET("w/api.php?action=query&format=json&formatversion=2"
3939
+ "&generator=categorymembers&gcmtype=subcat"

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
package fr.free.nrw.commons.contributions;
22

3-
import static fr.free.nrw.commons.contributions.Contribution.STATE_FAILED;
4-
import static fr.free.nrw.commons.contributions.MainActivity.CONTRIBUTIONS_TAB_POSITION;
5-
import static fr.free.nrw.commons.utils.LengthUtils.formatDistanceBetween;
6-
73
import android.Manifest;
84
import android.content.ComponentName;
95
import android.content.Context;
106
import android.content.Intent;
117
import android.content.ServiceConnection;
12-
import android.database.DataSetObserver;
138
import android.os.Bundle;
149
import android.os.IBinder;
1510
import android.view.LayoutInflater;
1611
import android.view.View;
1712
import android.view.ViewGroup;
1813
import android.widget.CheckBox;
1914
import android.widget.Toast;
15+
2016
import androidx.annotation.NonNull;
2117
import androidx.annotation.Nullable;
2218
import androidx.fragment.app.Fragment;
2319
import androidx.fragment.app.FragmentManager;
2420
import androidx.fragment.app.FragmentManager.OnBackStackChangedListener;
2521
import androidx.fragment.app.FragmentTransaction;
22+
23+
import javax.inject.Inject;
24+
import javax.inject.Named;
25+
2626
import butterknife.BindView;
2727
import butterknife.ButterKnife;
2828
import fr.free.nrw.commons.HandlerService;
@@ -57,11 +57,12 @@
5757
import io.reactivex.android.schedulers.AndroidSchedulers;
5858
import io.reactivex.disposables.CompositeDisposable;
5959
import io.reactivex.schedulers.Schedulers;
60-
import java.util.ArrayList;
61-
import javax.inject.Inject;
62-
import javax.inject.Named;
6360
import timber.log.Timber;
6461

62+
import static fr.free.nrw.commons.contributions.Contribution.STATE_FAILED;
63+
import static fr.free.nrw.commons.contributions.MainActivity.CONTRIBUTIONS_TAB_POSITION;
64+
import static fr.free.nrw.commons.utils.LengthUtils.formatDistanceBetween;
65+
6566
public class ContributionsFragment
6667
extends CommonsDaggerSupportFragment
6768
implements
@@ -78,15 +79,14 @@ public class ContributionsFragment
7879
@Inject CampaignsPresenter presenter;
7980
@Inject LocationServiceManager locationManager;
8081

81-
private ArrayList<DataSetObserver> observersWaitingForLoad = new ArrayList<>();
8282
private UploadService uploadService;
8383
private boolean isUploadServiceConnected;
8484
private CompositeDisposable compositeDisposable = new CompositeDisposable();
8585

8686
private ContributionsListFragment contributionsListFragment;
8787
private MediaDetailPagerFragment mediaDetailPagerFragment;
88-
public static final String CONTRIBUTION_LIST_FRAGMENT_TAG = "ContributionListFragmentTag";
89-
public static final String MEDIA_DETAIL_PAGER_FRAGMENT_TAG = "MediaDetailFragmentTag";
88+
private static final String CONTRIBUTION_LIST_FRAGMENT_TAG = "ContributionListFragmentTag";
89+
static final String MEDIA_DETAIL_PAGER_FRAGMENT_TAG = "MediaDetailFragmentTag";
9090

9191
@BindView(R.id.card_view_nearby) public NearbyNotificationCardView nearbyNotificationCardView;
9292
@BindView(R.id.campaigns_view) CampaignView campaignView;
@@ -268,7 +268,7 @@ public void onAttach(Context context) {
268268
* Replace FrameLayout with ContributionsListFragment, user will see contributions list. Creates
269269
* new one if null.
270270
*/
271-
public void showContributionsListFragment() {
271+
private void showContributionsListFragment() {
272272
// show tabs on contribution list is visible
273273
((MainActivity) getActivity()).showTabs();
274274
// show nearby card view on contributions list is visible
@@ -289,7 +289,7 @@ public void showContributionsListFragment() {
289289
* Replace FrameLayout with MediaDetailPagerFragment, user will see details of selected media.
290290
* Creates new one if null.
291291
*/
292-
public void showMediaDetailPagerFragment() {
292+
private void showMediaDetailPagerFragment() {
293293
// hide tabs on media detail view is visible
294294
((MainActivity)getActivity()).hideTabs();
295295
// hide nearby card view on media detail is visible
@@ -308,7 +308,7 @@ public void onBackStackChanged() {
308308
* Called when onAuthCookieAcquired is called on authenticated parent activity
309309
* @param uploadServiceIntent
310310
*/
311-
public void onAuthCookieAcquired(Intent uploadServiceIntent) {
311+
void onAuthCookieAcquired(Intent uploadServiceIntent) {
312312
// Since we call onAuthCookieAcquired method from onAttach, isAdded is still false. So don't use it
313313

314314
if (getActivity() != null) { // If fragment is attached to parent activity
@@ -324,7 +324,7 @@ public void onAuthCookieAcquired(Intent uploadServiceIntent) {
324324
* mediaDetailPagerFragment, and preserve previous state in back stack.
325325
* Called when user selects a contribution.
326326
*/
327-
public void showDetail(int i) {
327+
private void showDetail(int i) {
328328
if (mediaDetailPagerFragment == null || !mediaDetailPagerFragment.isVisible()) {
329329
mediaDetailPagerFragment = new MediaDetailPagerFragment();
330330
showMediaDetailPagerFragment();

app/src/main/java/fr/free/nrw/commons/explore/categories/SearchCategoryFragment.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ public class SearchCategoryFragment extends CommonsDaggerSupportFragment {
5656
ProgressBar progressBar;
5757
@BindView(R.id.imagesNotFound)
5858
TextView categoriesNotFoundView;
59-
String query;
59+
private String query;
6060
@BindView(R.id.bottomProgressBar)
6161
ProgressBar bottomProgressBar;
62-
boolean isLoadingCategories;
62+
private boolean isLoadingCategories;
6363

6464
@Inject RecentSearchesDao recentSearchesDao;
6565
@Inject MediaWikiApi mwApi;
@@ -152,7 +152,7 @@ public void updateCategoryList(String query) {
152152
/**
153153
* Adds 25 more results to existing search results
154154
*/
155-
public void addCategoriesToList(String query) {
155+
private void addCategoriesToList(String query) {
156156
if(isLoadingCategories) return;
157157
isLoadingCategories=true;
158158
this.query = query;

0 commit comments

Comments
 (0)