Skip to content

Commit ed42194

Browse files
Merge pull request commons-app#1025 from prajgov/master
Added JavaDoc comments to few methods and classes
2 parents 0aa20ef + a4e8b9a commit ed42194

File tree

14 files changed

+397
-17
lines changed

14 files changed

+397
-17
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,18 @@
88
import fr.free.nrw.commons.theme.NavigationBaseActivity;
99
import fr.free.nrw.commons.ui.widget.HtmlTextView;
1010

11+
/**
12+
* Represents about screen of this app
13+
*/
1114
public class AboutActivity extends NavigationBaseActivity {
1215
@BindView(R.id.about_version) TextView versionText;
1316
@BindView(R.id.about_license) HtmlTextView aboutLicenseText;
1417

18+
/**
19+
* This method helps in the creation About screen
20+
*
21+
* @param savedInstanceState Data bundle
22+
*/
1523
@Override
1624
public void onCreate(Bundle savedInstanceState) {
1725
super.onCreate(savedInstanceState);

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

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,21 @@ public class CommonsApplication extends DaggerApplication {
4949
@Inject @Named("default_preferences") SharedPreferences defaultPrefs;
5050
@Inject @Named("application_preferences") SharedPreferences applicationPrefs;
5151
@Inject @Named("prefs") SharedPreferences otherPrefs;
52-
52+
5353
public static final String DEFAULT_EDIT_SUMMARY = "Uploaded using Android Commons app";
54-
54+
5555
public static final String FEEDBACK_EMAIL = "commons-app-android@googlegroups.com";
56+
5657
public static final String LOGS_PRIVATE_EMAIL = "commons-app-android-private@googlegroups.com";
58+
5759
public static final String FEEDBACK_EMAIL_SUBJECT = "Commons Android App (%s) Feedback";
58-
60+
5961
private CommonsApplicationComponent component;
6062
private RefWatcher refWatcher;
6163

64+
/**
65+
* Used to declare and initialize various components and dependencies
66+
*/
6267
@Override
6368
public void onCreate() {
6469
super.onCreate();
@@ -80,23 +85,41 @@ public void onCreate() {
8085
System.setProperty("in.yuvi.http.fluent.PROGRESS_TRIGGER_THRESHOLD", "3.0");
8186
}
8287

88+
/**
89+
* Helps in setting up LeakCanary library
90+
* @return instance of LeakCanary
91+
*/
8392
protected RefWatcher setupLeakCanary() {
8493
if (LeakCanary.isInAnalyzerProcess(this)) {
8594
return RefWatcher.DISABLED;
8695
}
8796
return LeakCanary.install(this);
8897
}
89-
98+
99+
/**
100+
* Provides a way to get member refWatcher
101+
*
102+
* @param context Application context
103+
* @return application member refWatcher
104+
*/
90105
public static RefWatcher getRefWatcher(Context context) {
91106
CommonsApplication application = (CommonsApplication) context.getApplicationContext();
92107
return application.refWatcher;
93108
}
94-
109+
110+
/**
111+
* Helps in injecting dependency library Dagger
112+
* @return Dagger injector
113+
*/
95114
@Override
96-
protected AndroidInjector<? extends DaggerApplication> applicationInjector() {
115+
protected AndroidInjector<? extends DaggerApplication> applicationInjector() {
97116
return injector();
98117
}
99118

119+
/**
120+
* used to create injector of application component
121+
* @return Application component of Dagger
122+
*/
100123
public CommonsApplicationComponent injector() {
101124
if (component == null) {
102125
component = DaggerCommonsApplicationComponent.builder()
@@ -106,6 +129,11 @@ public CommonsApplicationComponent injector() {
106129
return component;
107130
}
108131

132+
/**
133+
* clears data of current application
134+
* @param context Application context
135+
* @param logoutListener Implementation of interface LogoutListener
136+
*/
109137
public void clearApplicationData(Context context, LogoutListener logoutListener) {
110138
File cacheDirectory = context.getCacheDir();
111139
File applicationDirectory = new File(cacheDirectory.getParent());
@@ -145,6 +173,9 @@ private void updateAllDatabases() {
145173
Contribution.Table.onDelete(db);
146174
}
147175

176+
/**
177+
* Interface used to get log-out events
178+
*/
148179
public interface LogoutListener {
149180
void onLogoutComplete();
150181
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
import android.support.annotation.Nullable;
44

5+
/**
6+
* represents Licence object
7+
*/
58
public class License {
69
private String key;
710
private String template;
@@ -56,6 +59,12 @@ public String getName() {
5659
}
5760
}
5861

62+
/**
63+
* Gets the license URL
64+
*
65+
* @param language license language
66+
* @return URL
67+
*/
5968
public @Nullable String getUrl(String language) {
6069
if (url == null) {
6170
return null;

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

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,18 @@
1313
import java.util.Locale;
1414
import java.util.Map;
1515

16+
/**
17+
* Represents a list of Licenses
18+
*/
1619
public class LicenseList {
1720
private Map<String, License> licenses = new HashMap<>();
1821
private Resources res;
1922

23+
/**
24+
* Constructs new instance of LicenceList
25+
*
26+
* @param activity License activity
27+
*/
2028
public LicenseList(Activity activity) {
2129
res = activity.getResources();
2230
XmlPullParser parser = res.getXml(R.xml.wikimedia_licenses);
@@ -31,14 +39,28 @@ public LicenseList(Activity activity) {
3139
}
3240
}
3341

42+
/**
43+
* Gets a collection of licenses
44+
* @return License values
45+
*/
3446
public Collection<License> values() {
3547
return licenses.values();
3648
}
3749

50+
/**
51+
* Gets license
52+
* @param key License key
53+
* @return License that matches key
54+
*/
3855
public License get(String key) {
3956
return licenses.get(key);
4057
}
4158

59+
/**
60+
* Creates a license from template
61+
* @param template License template
62+
* @return null
63+
*/
4264
@Nullable
4365
License licenseForTemplate(String template) {
4466
String ucTemplate = new PageTitle(template).getDisplayText();
@@ -50,13 +72,23 @@ License licenseForTemplate(String template) {
5072
return null;
5173
}
5274

75+
/**
76+
* Gets template name id
77+
* @param template License template
78+
* @return name id of template
79+
*/
5380
private String nameIdForTemplate(String template) {
5481
// hack :D (converts dashes and periods to underscores)
5582
// cc-by-sa-3.0 -> cc_by_sa_3_0
5683
return "license_name_" + template.toLowerCase(Locale.ENGLISH).replace("-",
5784
"_").replace(".", "_");
5885
}
5986

87+
/**
88+
* Gets name of given template
89+
* @param template License template
90+
* @return name of template
91+
*/
6092
private String nameForTemplate(String template) {
6193
int nameId = res.getIdentifier("fr.free.nrw.commons:string/"
6294
+ nameIdForTemplate(template), null, null);
@@ -92,4 +124,4 @@ private boolean xmlFastForward(XmlPullParser parser, String namespace, String el
92124
}
93125
}
94126

95-
}
127+
}

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

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,35 @@ public Media[] newArray(int i) {
4747
private HashMap<String, Object> tags = new HashMap<>();
4848
private @Nullable LatLng coordinates;
4949

50+
/**
51+
* Provides local constructor
52+
*/
5053
protected Media() {
5154
this.categories = new ArrayList<>();
5255
this.descriptions = new HashMap<>();
5356
}
5457

58+
/**
59+
* Provides a minimal constructor
60+
*
61+
* @param filename Media filename
62+
*/
5563
public Media(String filename) {
5664
this();
5765
this.filename = filename;
5866
}
5967

68+
/**
69+
* Provide Media constructor
70+
* @param localUri Media URI
71+
* @param imageUrl Media image URL
72+
* @param filename Media filename
73+
* @param description Media description
74+
* @param dataLength Media date length
75+
* @param dateCreated Media creation date
76+
* @param dateUploaded Media date uploaded
77+
* @param creator Media creator
78+
*/
6079
public Media(Uri localUri, String imageUrl, String filename, String description,
6180
long dataLength, Date dateCreated, @Nullable Date dateUploaded, String creator) {
6281
this();
@@ -90,19 +109,33 @@ public Media(Parcel in) {
90109
descriptions = in.readHashMap(ClassLoader.getSystemClassLoader());
91110
}
92111

112+
/**
113+
* Gets tag of media
114+
* @param key Media key
115+
* @return Media tag
116+
*/
93117
public Object getTag(String key) {
94118
return tags.get(key);
95119
}
96120

121+
/**
122+
* Modifies( or creates a) tag of media
123+
* @param key Media key
124+
* @param value Media value
125+
*/
97126
public void setTag(String key, Object value) {
98127
tags.put(key, value);
99128
}
100129

130+
/**
131+
* Gets media display title
132+
* @return Media title
133+
*/
101134
public String getDisplayTitle() {
102135
if (filename == null) {
103136
return "";
104137
}
105-
// FIXME: Gross hack bercause my regex skills suck maybe or I am too lazy who knows
138+
// FIXME: Gross hack because my regex skills suck maybe or I am too lazy who knows
106139
String title = getFilePageTitle().getDisplayText().replaceFirst("^File:", "");
107140
Matcher matcher = displayTitlePattern.matcher(title);
108141
if (matcher.matches()) {
@@ -112,14 +145,27 @@ public String getDisplayTitle() {
112145
}
113146
}
114147

148+
/**
149+
* Gets file page title
150+
* @return New media page title
151+
*/
115152
public PageTitle getFilePageTitle() {
116153
return new PageTitle("File:" + getFilename().replaceFirst("^File:", ""));
117154
}
118155

156+
/**
157+
* Gets local URI
158+
* @return Media local URI
159+
*/
119160
public Uri getLocalUri() {
120161
return localUri;
121162
}
122163

164+
/**
165+
* Gets image URL
166+
* can be null.
167+
* @return Image URL
168+
*/
123169
@Nullable
124170
public String getImageUrl() {
125171
if (imageUrl == null && this.getFilename() != null) {
@@ -304,6 +350,10 @@ public void setCategories(List<String> categories) {
304350
this.categories.addAll(categories);
305351
}
306352

353+
/**
354+
* Modifies (or sets) media descriptions
355+
* @param descriptions Media descriptions
356+
*/
307357
void setDescriptions(Map<String, String> descriptions) {
308358
for (String key : this.descriptions.keySet()) {
309359
this.descriptions.remove(key);
@@ -313,6 +363,11 @@ void setDescriptions(Map<String, String> descriptions) {
313363
}
314364
}
315365

366+
/**
367+
* Gets media description in preferred language
368+
* @param preferredLanguage Language preferred
369+
* @return Description in preferred language
370+
*/
316371
public String getDescription(String preferredLanguage) {
317372
if (descriptions.containsKey(preferredLanguage)) {
318373
// See if the requested language is there.
@@ -329,11 +384,21 @@ public String getDescription(String preferredLanguage) {
329384
}
330385
}
331386

387+
/**
388+
* Method of Parcelable interface
389+
* @return zero
390+
*/
332391
@Override
333392
public int describeContents() {
334393
return 0;
335394
}
336395

396+
/**
397+
* Creates a way to transfer information between two or more
398+
* activities.
399+
* @param parcel Instance of Parcel
400+
* @param flags Parcel flag
401+
*/
337402
@Override
338403
public void writeToParcel(Parcel parcel, int flags) {
339404
parcel.writeParcelable(localUri, flags);

0 commit comments

Comments
 (0)