From 3d6c6e0301e604308a24f50a8b209641ab3eb404 Mon Sep 17 00:00:00 2001 From: prajgov Date: Tue, 19 Dec 2017 19:11:39 +0530 Subject: [PATCH 01/21] added JavaDoc comments --- .../fr/free/nrw/commons/AboutActivity.java | 8 +++ .../free/nrw/commons/CommonsApplication.java | 52 ++++++++++++++----- build.gradle | 2 +- 3 files changed, 48 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/fr/free/nrw/commons/AboutActivity.java b/app/src/main/java/fr/free/nrw/commons/AboutActivity.java index 0ef5fa171..6ed1bba1d 100644 --- a/app/src/main/java/fr/free/nrw/commons/AboutActivity.java +++ b/app/src/main/java/fr/free/nrw/commons/AboutActivity.java @@ -8,10 +8,18 @@ import butterknife.ButterKnife; import fr.free.nrw.commons.theme.NavigationBaseActivity; import fr.free.nrw.commons.ui.widget.HtmlTextView; +/** + * Represents about screen of this app + */ public class AboutActivity extends NavigationBaseActivity { @BindView(R.id.about_version) TextView versionText; @BindView(R.id.about_license) HtmlTextView aboutLicenseText; + /** + * This method helps in the creation About screen + * + * @param savedInstanceState Data bundle + */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); diff --git a/app/src/main/java/fr/free/nrw/commons/CommonsApplication.java b/app/src/main/java/fr/free/nrw/commons/CommonsApplication.java index 9a7b94a99..c2da8ad98 100644 --- a/app/src/main/java/fr/free/nrw/commons/CommonsApplication.java +++ b/app/src/main/java/fr/free/nrw/commons/CommonsApplication.java @@ -44,21 +44,32 @@ import timber.log.Timber; ) public class CommonsApplication extends DaggerApplication { + public static final String DEFAULT_EDIT_SUMMARY = "Uploaded using Android Commons app"; + public static final String FEEDBACK_EMAIL = "commons-app-android@googlegroups.com"; + public static final String LOGS_PRIVATE_EMAIL = "commons-app-android-private@googlegroups.com"; + public static final String FEEDBACK_EMAIL_SUBJECT = "Commons Android App (%s) Feedback"; @Inject SessionManager sessionManager; @Inject DBOpenHelper dbOpenHelper; @Inject @Named("default_preferences") SharedPreferences defaultPrefs; @Inject @Named("application_preferences") SharedPreferences applicationPrefs; @Inject @Named("prefs") SharedPreferences otherPrefs; - - public static final String DEFAULT_EDIT_SUMMARY = "Uploaded using Android Commons app"; - - public static final String FEEDBACK_EMAIL = "commons-app-android@googlegroups.com"; - public static final String LOGS_PRIVATE_EMAIL = "commons-app-android-private@googlegroups.com"; - public static final String FEEDBACK_EMAIL_SUBJECT = "Commons Android App (%s) Feedback"; - private CommonsApplicationComponent component; private RefWatcher refWatcher; + /** + * Provides a way to get member refWatcher + * + * @param context Application context + * @return application member refWatcher + */ + public static RefWatcher getRefWatcher(Context context) { + CommonsApplication application = (CommonsApplication) context.getApplicationContext(); + return application.refWatcher; + } + + /** + * Used to declare and initialize various components and dependencies + */ @Override public void onCreate() { super.onCreate(); @@ -80,6 +91,10 @@ public class CommonsApplication extends DaggerApplication { System.setProperty("in.yuvi.http.fluent.PROGRESS_TRIGGER_THRESHOLD", "3.0"); } + /** + * Helps in setting up LeakCanary library + * @return instance of LeakCanary + */ protected RefWatcher setupLeakCanary() { if (LeakCanary.isInAnalyzerProcess(this)) { return RefWatcher.DISABLED; @@ -87,16 +102,19 @@ public class CommonsApplication extends DaggerApplication { return LeakCanary.install(this); } - public static RefWatcher getRefWatcher(Context context) { - CommonsApplication application = (CommonsApplication) context.getApplicationContext(); - return application.refWatcher; - } - + /** + * Helps in injecting dependency library Dagger + * @return Dagger injector + */ @Override - protected AndroidInjector applicationInjector() { + protected AndroidInjector applicationInjector() { return injector(); } + /** + * used to create injector of application component + * @return Application component of Dagger + */ public CommonsApplicationComponent injector() { if (component == null) { component = DaggerCommonsApplicationComponent.builder() @@ -106,6 +124,11 @@ public class CommonsApplication extends DaggerApplication { return component; } + /** + * clears data of current application + * @param context Application context + * @param logoutListener Implementation of interface LogoutListener + */ public void clearApplicationData(Context context, LogoutListener logoutListener) { File cacheDirectory = context.getCacheDir(); File applicationDirectory = new File(cacheDirectory.getParent()); @@ -145,6 +168,9 @@ public class CommonsApplication extends DaggerApplication { Contribution.Table.onDelete(db); } + /** + * Interface used to get log-out events + */ public interface LogoutListener { void onLogoutComplete(); } diff --git a/build.gradle b/build.gradle index 6b7e5dc00..b0e8b6718 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ buildscript { google() } dependencies { - classpath "com.android.tools.build:gradle:${project.gradleVersion}" + classpath 'com.android.tools.build:gradle:3.0.1' classpath 'com.dicedmelon.gradle:jacoco-android:0.1.1' classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.7.1' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" From 19ef7b126c5f1fb27d6e9553355741bac090c3a7 Mon Sep 17 00:00:00 2001 From: prajgov Date: Tue, 19 Dec 2017 19:25:49 +0530 Subject: [PATCH 02/21] added JavaDoc comments --- .../java/fr/free/nrw/commons/License.java | 9 ++++++ .../java/fr/free/nrw/commons/LicenseList.java | 32 +++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/app/src/main/java/fr/free/nrw/commons/License.java b/app/src/main/java/fr/free/nrw/commons/License.java index 7b75cfda8..db893de16 100644 --- a/app/src/main/java/fr/free/nrw/commons/License.java +++ b/app/src/main/java/fr/free/nrw/commons/License.java @@ -2,6 +2,9 @@ package fr.free.nrw.commons; import android.support.annotation.Nullable; +/** + * represents Licence object + */ public class License { private String key; private String template; @@ -56,6 +59,12 @@ public class License { } } + /** + * Gets the license URL + * + * @param language license language + * @return URL + */ public @Nullable String getUrl(String language) { if (url == null) { return null; diff --git a/app/src/main/java/fr/free/nrw/commons/LicenseList.java b/app/src/main/java/fr/free/nrw/commons/LicenseList.java index ab32f8815..536be225b 100644 --- a/app/src/main/java/fr/free/nrw/commons/LicenseList.java +++ b/app/src/main/java/fr/free/nrw/commons/LicenseList.java @@ -13,10 +13,18 @@ import java.util.HashMap; import java.util.Locale; import java.util.Map; +/** + * Represents LicenseList + */ public class LicenseList { private Map licenses = new HashMap<>(); private Resources res; + /** + * Constructs new instance of LicenceList + * + * @param activity License activity + */ public LicenseList(Activity activity) { res = activity.getResources(); XmlPullParser parser = res.getXml(R.xml.wikimedia_licenses); @@ -31,14 +39,28 @@ public class LicenseList { } } + /** + * Gets a collection of licenses + * @return License values + */ public Collection values() { return licenses.values(); } + /** + * Gets license + * @param key License key + * @return License that matches key + */ public License get(String key) { return licenses.get(key); } + /** + * Creates a license from template + * @param template License template + * @return null + */ @Nullable License licenseForTemplate(String template) { String ucTemplate = new PageTitle(template).getDisplayText(); @@ -50,6 +72,11 @@ public class LicenseList { return null; } + /** + * Gets template name id + * @param template License template + * @return name id of template + */ private String nameIdForTemplate(String template) { // hack :D (converts dashes and periods to underscores) // cc-by-sa-3.0 -> cc_by_sa_3_0 @@ -57,6 +84,11 @@ public class LicenseList { "_").replace(".", "_"); } + /** + * Gets name of given template + * @param template License template + * @return name of template + */ private String nameForTemplate(String template) { int nameId = res.getIdentifier("fr.free.nrw.commons:string/" + nameIdForTemplate(template), null, null); From 93b7611bc1c16a0c5c8f05257c0bfff8bfc2c64a Mon Sep 17 00:00:00 2001 From: prajgov Date: Tue, 19 Dec 2017 19:58:38 +0530 Subject: [PATCH 03/21] added JavaDoc comments --- .../fr/free/nrw/commons/data/Category.java | 170 ++++++++++++------ 1 file changed, 112 insertions(+), 58 deletions(-) diff --git a/app/src/main/java/fr/free/nrw/commons/data/Category.java b/app/src/main/java/fr/free/nrw/commons/data/Category.java index 757f6b691..25214fdc6 100644 --- a/app/src/main/java/fr/free/nrw/commons/data/Category.java +++ b/app/src/main/java/fr/free/nrw/commons/data/Category.java @@ -14,6 +14,9 @@ import java.util.Date; import fr.free.nrw.commons.category.CategoryContentProvider; +/** + * Represents a category + */ public class Category { private Uri contentUri; @@ -22,67 +25,12 @@ public class Category { private int timesUsed; // Getters/setters - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - private Date getLastUsed() { - // warning: Date objects are mutable. - return (Date)lastUsed.clone(); - } - - public void setLastUsed(Date lastUsed) { - // warning: Date objects are mutable. - this.lastUsed = (Date)lastUsed.clone(); - } - - private void touch() { - lastUsed = new Date(); - } - - private int getTimesUsed() { - return timesUsed; - } - - public void setTimesUsed(int timesUsed) { - this.timesUsed = timesUsed; - } - - public void incTimesUsed() { - timesUsed++; - touch(); - } - - //region Database/content-provider stuff /** - * Persist category. - * @param client ContentProviderClient to handle DB connection + * Gets category from cursor + * @param cursor Category cursor + * @return Category from cursor */ - public void save(ContentProviderClient client) { - try { - if (contentUri == null) { - contentUri = client.insert(CategoryContentProvider.BASE_URI, this.toContentValues()); - } else { - client.update(contentUri, toContentValues(), null, null); - } - } catch (RemoteException e) { - throw new RuntimeException(e); - } - } - - private ContentValues toContentValues() { - ContentValues cv = new ContentValues(); - cv.put(Table.COLUMN_NAME, getName()); - cv.put(Table.COLUMN_LAST_USED, getLastUsed().getTime()); - cv.put(Table.COLUMN_TIMES_USED, getTimesUsed()); - return cv; - } - private static Category fromCursor(Cursor cursor) { // Hardcoding column positions! Category c = new Category(); @@ -152,6 +100,112 @@ public class Category { return items; } + /** + * Gets name + * + * @return name + */ + public String getName() { + return name; + } + + /** + * Modifies name + * + * @param name Category name + */ + public void setName(String name) { + this.name = name; + } + + /** + * Gets last used date + * + * @return Last used date + */ + private Date getLastUsed() { + // warning: Date objects are mutable. + return (Date) lastUsed.clone(); + } + + /** + * Modifies last used date + * + * @param lastUsed Category date + */ + public void setLastUsed(Date lastUsed) { + // warning: Date objects are mutable. + this.lastUsed = (Date) lastUsed.clone(); + } + + /** + * Generates new last used date + */ + private void touch() { + lastUsed = new Date(); + } + + //region Database/content-provider stuff + + /** + * Gets no. of times the category is used + * + * @return no. of times used + */ + private int getTimesUsed() { + return timesUsed; + } + + /** + * Modifies no. of times used + * + * @param timesUsed Category used times + */ + public void setTimesUsed(int timesUsed) { + this.timesUsed = timesUsed; + } + + /** + * Increments timesUsed by 1 and sets last used date as now. + */ + public void incTimesUsed() { + timesUsed++; + touch(); + } + + /** + * Persist category. + * + * @param client ContentProviderClient to handle DB connection + */ + public void save(ContentProviderClient client) { + try { + if (contentUri == null) { + contentUri = client.insert(CategoryContentProvider.BASE_URI, this.toContentValues()); + } else { + client.update(contentUri, toContentValues(), null, null); + } + } catch (RemoteException e) { + throw new RuntimeException(e); + } + } + + /** + * Gets content values + * + * @return Content values + */ + private ContentValues toContentValues() { + ContentValues cv = new ContentValues(); + cv.put(Table.COLUMN_NAME, getName()); + cv.put(Table.COLUMN_LAST_USED, getLastUsed().getTime()); + cv.put(Table.COLUMN_TIMES_USED, getTimesUsed()); + return cv; + } + + /** + * Represents table + */ public static class Table { public static final String TABLE_NAME = "categories"; From 4bb3e58c4ee8c9906be094bfb8c3bdf8edaf04ec Mon Sep 17 00:00:00 2001 From: prajgov Date: Tue, 19 Dec 2017 20:30:37 +0530 Subject: [PATCH 04/21] added JavaDoc comments --- .../java/fr/free/nrw/commons/data/Category.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/app/src/main/java/fr/free/nrw/commons/data/Category.java b/app/src/main/java/fr/free/nrw/commons/data/Category.java index 25214fdc6..87ab6f2ea 100644 --- a/app/src/main/java/fr/free/nrw/commons/data/Category.java +++ b/app/src/main/java/fr/free/nrw/commons/data/Category.java @@ -229,15 +229,30 @@ public class Category { + COLUMN_TIMES_USED + " INTEGER" + ");"; + /** + * Creates new database with provided SQLite database + * + * @param db Category database + */ public static void onCreate(SQLiteDatabase db) { db.execSQL(CREATE_TABLE_STATEMENT); } + /** + * Deletes existing database + * @param db Category database + */ public static void onDelete(SQLiteDatabase db) { db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME); onCreate(db); } + /** + * Updates given database + * @param db Category database + * @param from Exiting category id + * @param to New category id + */ public static void onUpdate(SQLiteDatabase db, int from, int to) { if (from == to) { return; From 7e6374f11a1dd4263003b7e75094a66ca1983230 Mon Sep 17 00:00:00 2001 From: prajgov Date: Tue, 19 Dec 2017 20:54:28 +0530 Subject: [PATCH 05/21] added JavaDoc comments --- .../main/java/fr/free/nrw/commons/Utils.java | 27 ++++++++++++++++ .../fr/free/nrw/commons/WelcomeActivity.java | 23 ++++++++++--- .../free/nrw/commons/utils/LengthUtils.java | 32 +++++++++++++++++++ 3 files changed, 77 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/fr/free/nrw/commons/Utils.java b/app/src/main/java/fr/free/nrw/commons/Utils.java index 87dab7f68..a8bd91a39 100644 --- a/app/src/main/java/fr/free/nrw/commons/Utils.java +++ b/app/src/main/java/fr/free/nrw/commons/Utils.java @@ -37,12 +37,23 @@ public class Utils { } } + /** + * Creates an URL for thumbnail + * + * @param filename Thumbnail file name + * @return URL of thumbnail + */ public static String makeThumbBaseUrl(@NonNull String filename) { String name = new PageTitle(filename).getPrefixedText(); String sha = new String(Hex.encodeHex(DigestUtils.md5(name))); return String.format("%s/%s/%s/%s", BuildConfig.IMAGE_URL_BASE, sha.substring(0, 1), sha.substring(0, 2), urlEncode(name)); } + /** + * Encodes given URL in UTF-8 format + * @param url Unformatted URL + * @return Formatted URL + */ public static String urlEncode(String url) { try { return URLEncoder.encode(url, "utf-8"); @@ -61,6 +72,11 @@ public class Utils { return string.substring(0, 1).toUpperCase(Locale.getDefault()) + string.substring(1); } + /** + * Generates licence name with given ID + * @param license License ID + * @return Name of license + */ public static int licenseNameFor(String license) { switch (license) { case Prefs.Licenses.CC_BY_3: @@ -81,6 +97,12 @@ public class Utils { throw new RuntimeException("Unrecognized license value: " + license); } + /** + * Fixing incorrect extension + * @param title File name + * @param extension Correct extension + * @return File with correct extension + */ public static String fixExtension(String title, String extension) { Pattern jpegPattern = Pattern.compile("\\.jpeg$", Pattern.CASE_INSENSITIVE); @@ -96,6 +118,11 @@ public class Utils { return title; } + /** + * Tells whether dark theme is active or not + * @param context Activity context + * @return The state of dark theme + */ public static boolean isDarkTheme(Context context) { return PreferenceManager.getDefaultSharedPreferences(context).getBoolean("theme", false); } diff --git a/app/src/main/java/fr/free/nrw/commons/WelcomeActivity.java b/app/src/main/java/fr/free/nrw/commons/WelcomeActivity.java index f6c5999e9..17c4be137 100644 --- a/app/src/main/java/fr/free/nrw/commons/WelcomeActivity.java +++ b/app/src/main/java/fr/free/nrw/commons/WelcomeActivity.java @@ -18,6 +18,21 @@ public class WelcomeActivity extends BaseActivity { private WelcomePagerAdapter adapter = new WelcomePagerAdapter(); + /** + * Creates a way to change current activity to WelcomeActivity + * + * @param context Activity context + */ + public static void startYourself(Context context) { + Intent welcomeIntent = new Intent(context, WelcomeActivity.class); + context.startActivity(welcomeIntent); + } + + /** + * Initialises exiting fields and dependencies + * + * @param savedInstanceState WelcomeActivity bundled data + */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -30,14 +45,12 @@ public class WelcomeActivity extends BaseActivity { adapter.setCallback(this::finish); } + /** + * References WelcomePageAdapter to null before the activity is destroyed + */ @Override public void onDestroy() { adapter.setCallback(null); super.onDestroy(); } - - public static void startYourself(Context context) { - Intent welcomeIntent = new Intent(context, WelcomeActivity.class); - context.startActivity(welcomeIntent); - } } diff --git a/app/src/main/java/fr/free/nrw/commons/utils/LengthUtils.java b/app/src/main/java/fr/free/nrw/commons/utils/LengthUtils.java index 6fd9f9612..ac59c1bbe 100644 --- a/app/src/main/java/fr/free/nrw/commons/utils/LengthUtils.java +++ b/app/src/main/java/fr/free/nrw/commons/utils/LengthUtils.java @@ -37,6 +37,13 @@ public class LengthUtils { return computeAngleBetween(from, to) * 6371009.0D; // Earth's radius in meter } + /** + * Computes angle between two points + * + * @param from Point A + * @param to Point B + * @return Angle in radius + */ private static double computeAngleBetween(LatLng from, LatLng to) { return distanceRadians(Math.toRadians(from.getLatitude()), Math.toRadians(from.getLongitude()), @@ -44,18 +51,43 @@ public class LengthUtils { Math.toRadians(to.getLongitude())); } + /** + * Computes arc length between 2 points + * @param lat1 Latitude of point A + * @param lng1 Longitude of point A + * @param lat2 Latitude of point B + * @param lng2 Longitude of point B + * @return Arc length between the points + */ private static double distanceRadians(double lat1, double lng1, double lat2, double lng2) { return arcHav(havDistance(lat1, lat2, lng1 - lng2)); } + /** + * Gets twice the amount of arc sine of (x)^(1/2) + * @param x Angle in radian + * @return Twice the angle + */ private static double arcHav(double x) { return 2.0D * Math.asin(Math.sqrt(x)); } + /** + * Computes distance between two points that are on same Longitude + * @param lat1 Latitude of point A + * @param lat2 Latitude of point B + * @param longitude Longitude on which they lie + * @return Arc length between points + */ private static double havDistance(double lat1, double lat2, double longitude) { return hav(lat1 - lat2) + hav(longitude) * Math.cos(lat1) * Math.cos(lat2); } + /** + * Computes square sine function for half of the value entered + * @param x Angle in radians + * @return One-forth of square of sine function + */ private static double hav(double x) { double sinHalf = Math.sin(x * 0.5D); return sinHalf * sinHalf; From 4ef996f2c0184a75cdc9ec56618bd623de4388fb Mon Sep 17 00:00:00 2001 From: prajgov Date: Thu, 21 Dec 2017 18:11:44 +0530 Subject: [PATCH 06/21] added JavaDoc comments --- .../main/java/fr/free/nrw/commons/Media.java | 67 ++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/fr/free/nrw/commons/Media.java b/app/src/main/java/fr/free/nrw/commons/Media.java index c75aae2a5..27888e350 100644 --- a/app/src/main/java/fr/free/nrw/commons/Media.java +++ b/app/src/main/java/fr/free/nrw/commons/Media.java @@ -47,16 +47,35 @@ public class Media implements Parcelable { private HashMap tags = new HashMap<>(); private @Nullable LatLng coordinates; + /** + * Provides local constructor + */ protected Media() { this.categories = new ArrayList<>(); this.descriptions = new HashMap<>(); } + /** + * Provides a minimal constructor + * + * @param filename Media filename + */ public Media(String filename) { this(); this.filename = filename; } + /** + * Provide Media constructor + * @param localUri Media URI + * @param imageUrl Media image URL + * @param filename Media filename + * @param description Media description + * @param dataLength Media date length + * @param dateCreated Media creation date + * @param dateUploaded Media date uploaded + * @param creator Media creator + */ public Media(Uri localUri, String imageUrl, String filename, String description, long dataLength, Date dateCreated, @Nullable Date dateUploaded, String creator) { this(); @@ -90,19 +109,33 @@ public class Media implements Parcelable { descriptions = in.readHashMap(ClassLoader.getSystemClassLoader()); } + /** + * Gets tag of media + * @param key Media key + * @return Media tag + */ public Object getTag(String key) { return tags.get(key); } + /** + * Modifies tag of media + * @param key Media key + * @param value Media value + */ public void setTag(String key, Object value) { tags.put(key, value); } + /** + * Gets media display title + * @return Media title + */ public String getDisplayTitle() { if (filename == null) { return ""; } - // FIXME: Gross hack bercause my regex skills suck maybe or I am too lazy who knows + // FIXME: Gross hack because my regex skills suck maybe or I am too lazy who knows String title = getFilePageTitle().getDisplayText().replaceFirst("^File:", ""); Matcher matcher = displayTitlePattern.matcher(title); if (matcher.matches()) { @@ -112,14 +145,27 @@ public class Media implements Parcelable { } } + /** + * Gets file page title + * @return New media page title + */ public PageTitle getFilePageTitle() { return new PageTitle("File:" + getFilename().replaceFirst("^File:", "")); } + /** + * Gets local URI + * @return Media local URI + */ public Uri getLocalUri() { return localUri; } + /** + * Gets image URL + * can be null. + * @return Image URL + */ @Nullable public String getImageUrl() { if (imageUrl == null && this.getFilename() != null) { @@ -304,6 +350,10 @@ public class Media implements Parcelable { this.categories.addAll(categories); } + /** + * Modifies (or sets) media descriptions + * @param descriptions Media descriptions + */ void setDescriptions(Map descriptions) { for (String key : this.descriptions.keySet()) { this.descriptions.remove(key); @@ -313,6 +363,11 @@ public class Media implements Parcelable { } } + /** + * Gets media description in preferred language + * @param preferredLanguage Language preferred + * @return Description in preferred language + */ public String getDescription(String preferredLanguage) { if (descriptions.containsKey(preferredLanguage)) { // See if the requested language is there. @@ -329,11 +384,21 @@ public class Media implements Parcelable { } } + /** + * Method of Parcelable interface + * @return zero + */ @Override public int describeContents() { return 0; } + /** + * Creates a way to transfer information between two or more + * activities. + * @param parcel Instance of Parcel + * @param flags Parcel flag + */ @Override public void writeToParcel(Parcel parcel, int flags) { parcel.writeParcelable(localUri, flags); From 28264e93ce0753f75735c8d6fe1ba95611c551c0 Mon Sep 17 00:00:00 2001 From: prajgov Date: Thu, 21 Dec 2017 18:32:54 +0530 Subject: [PATCH 07/21] added JavaDoc comments --- .../free/nrw/commons/WelcomePagerAdapter.java | 41 +++++++++++++++---- .../fr/free/nrw/commons/mwapi/LogBuilder.java | 21 ++++++++++ .../fr/free/nrw/commons/mwapi/LogTask.java | 10 +++++ .../free/nrw/commons/mwapi/MediaResult.java | 14 +++++++ .../free/nrw/commons/mwapi/UploadResult.java | 33 +++++++++++++++ 5 files changed, 112 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/fr/free/nrw/commons/WelcomePagerAdapter.java b/app/src/main/java/fr/free/nrw/commons/WelcomePagerAdapter.java index 9669196e9..eedc5ee0d 100644 --- a/app/src/main/java/fr/free/nrw/commons/WelcomePagerAdapter.java +++ b/app/src/main/java/fr/free/nrw/commons/WelcomePagerAdapter.java @@ -10,13 +10,6 @@ import butterknife.ButterKnife; import butterknife.OnClick; public class WelcomePagerAdapter extends PagerAdapter { - private static final int PAGE_FINAL = 4; - private Callback callback; - - public interface Callback { - void onYesClicked(); - } - static final int[] PAGE_LAYOUTS = new int[]{ R.layout.welcome_wikipedia, R.layout.welcome_do_upload, @@ -24,16 +17,34 @@ public class WelcomePagerAdapter extends PagerAdapter { R.layout.welcome_image_details, R.layout.welcome_final }; + private static final int PAGE_FINAL = 4; + private Callback callback; + /** + * Changes callback to provided one + * + * @param callback New callback + * it can be null. + */ public void setCallback(@Nullable Callback callback) { this.callback = callback; } + /** + * Gets total number of layouts + * @return Number of layouts + */ @Override public int getCount() { return PAGE_LAYOUTS.length; } + /** + * Compares given view with provided object + * @param view Adapter view + * @param object Adapter object + * @return Equality between view and object + */ @Override public boolean isViewFromObject(View view, Object object) { return (view == object); @@ -52,16 +63,32 @@ public class WelcomePagerAdapter extends PagerAdapter { return layout; } + /** + * Provides a way to remove an item from container + * @param container Adapter view group container + * @param position Index of item + * @param obj Adapter object + */ @Override public void destroyItem(ViewGroup container, int position, Object obj) { container.removeView((View) obj); } + /** + * Interface used create on clicked callback(s). + */ + public interface Callback { + void onYesClicked(); + } + class ViewHolder { ViewHolder(View view) { ButterKnife.bind(this, view); } + /** + * Triggers on click callback on button click + */ @OnClick(R.id.welcomeYesButton) void onClicked() { if (callback != null) { diff --git a/app/src/main/java/fr/free/nrw/commons/mwapi/LogBuilder.java b/app/src/main/java/fr/free/nrw/commons/mwapi/LogBuilder.java index 7a4b294fa..c855d788b 100644 --- a/app/src/main/java/fr/free/nrw/commons/mwapi/LogBuilder.java +++ b/app/src/main/java/fr/free/nrw/commons/mwapi/LogBuilder.java @@ -22,6 +22,14 @@ public class LogBuilder { private final String schema; private final SharedPreferences prefs; + /** + * Main constructor of LogBuilder + * + * @param schema Log schema + * @param revision Log revision + * @param mwApi Wiki media API instance + * @param prefs Instance of SharedPreferences + */ LogBuilder(String schema, long revision, MediaWikiApi mwApi, SharedPreferences prefs) { this.prefs = prefs; this.data = new JSONObject(); @@ -30,6 +38,12 @@ public class LogBuilder { this.mwApi = mwApi; } + /** + * Adds data to preferences + * @param key Log key + * @param value Log object value + * @return LogBuilder + */ public LogBuilder param(String key, Object value) { try { data.put(key, value); @@ -39,6 +53,10 @@ public class LogBuilder { return this; } + /** + * Encodes JSON object to URL + * @return URL to JSON object + */ URL toUrl() { JSONObject fullData = new JSONObject(); try { @@ -66,6 +84,9 @@ public class LogBuilder { logTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, this); } + /** + * Logs in false + */ public void log() { log(false); } diff --git a/app/src/main/java/fr/free/nrw/commons/mwapi/LogTask.java b/app/src/main/java/fr/free/nrw/commons/mwapi/LogTask.java index 3fce8aaf1..e564a50ab 100644 --- a/app/src/main/java/fr/free/nrw/commons/mwapi/LogTask.java +++ b/app/src/main/java/fr/free/nrw/commons/mwapi/LogTask.java @@ -6,10 +6,20 @@ class LogTask extends AsyncTask { private final MediaWikiApi mwApi; + /** + * Main constructor of LogTask + * + * @param mwApi Media wiki API instance + */ public LogTask(MediaWikiApi mwApi) { this.mwApi = mwApi; } + /** + * Logs events in background + * @param logBuilders LogBuilder instance + * @return Background success state ( TRUE or FALSE ) + */ @Override protected Boolean doInBackground(LogBuilder... logBuilders) { return mwApi.logEvents(logBuilders); diff --git a/app/src/main/java/fr/free/nrw/commons/mwapi/MediaResult.java b/app/src/main/java/fr/free/nrw/commons/mwapi/MediaResult.java index cfddf8c15..f2f34ce6d 100644 --- a/app/src/main/java/fr/free/nrw/commons/mwapi/MediaResult.java +++ b/app/src/main/java/fr/free/nrw/commons/mwapi/MediaResult.java @@ -4,15 +4,29 @@ public class MediaResult { private final String wikiSource; private final String parseTreeXmlSource; + /** + * Full-fledged constructor of MediaResult + * + * @param wikiSource Media wiki source + * @param parseTreeXmlSource Media tree parsed in XML + */ MediaResult(String wikiSource, String parseTreeXmlSource) { this.wikiSource = wikiSource; this.parseTreeXmlSource = parseTreeXmlSource; } + /** + * Gets wiki source + * @return Wiki source + */ public String getWikiSource() { return wikiSource; } + /** + * Gets tree parsed in XML + * @return XML parsed tree + */ public String getParseTreeXmlSource() { return parseTreeXmlSource; } diff --git a/app/src/main/java/fr/free/nrw/commons/mwapi/UploadResult.java b/app/src/main/java/fr/free/nrw/commons/mwapi/UploadResult.java index 34d050b2c..9422497b3 100644 --- a/app/src/main/java/fr/free/nrw/commons/mwapi/UploadResult.java +++ b/app/src/main/java/fr/free/nrw/commons/mwapi/UploadResult.java @@ -9,11 +9,24 @@ public class UploadResult { private String imageUrl; private String canonicalFilename; + /** + * Minimal constructor + * + * @param resultStatus Upload result status + * @param errorCode Upload error code + */ UploadResult(String resultStatus, String errorCode) { this.resultStatus = resultStatus; this.errorCode = errorCode; } + /** + * Full-fledged constructor + * @param resultStatus Upload result status + * @param dateUploaded Uploaded date + * @param canonicalFilename Uploaded file name + * @param imageUrl Uploaded image file name + */ UploadResult(String resultStatus, Date dateUploaded, String canonicalFilename, String imageUrl) { this.resultStatus = resultStatus; this.dateUploaded = dateUploaded; @@ -21,22 +34,42 @@ public class UploadResult { this.imageUrl = imageUrl; } + /** + * Gets uploaded date + * @return Upload date + */ public Date getDateUploaded() { return dateUploaded; } + /** + * Gets image url + * @return Uploaded image url + */ public String getImageUrl() { return imageUrl; } + /** + * Gets canonical file name + * @return Uploaded file name + */ public String getCanonicalFilename() { return canonicalFilename; } + /** + * Gets upload error code + * @return Error code + */ public String getErrorCode() { return errorCode; } + /** + * Gets upload result status + * @return Upload result status + */ public String getResultStatus() { return resultStatus; } From 2ef4fdc46581f9a49ce00fab24024c466f950d86 Mon Sep 17 00:00:00 2001 From: Prajeen Govardhanam <32291277+prajgov@users.noreply.github.com> Date: Thu, 21 Dec 2017 20:38:53 +0530 Subject: [PATCH 08/21] Update LicenseList.java --- app/src/main/java/fr/free/nrw/commons/LicenseList.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/fr/free/nrw/commons/LicenseList.java b/app/src/main/java/fr/free/nrw/commons/LicenseList.java index 536be225b..a2a4bb3ea 100644 --- a/app/src/main/java/fr/free/nrw/commons/LicenseList.java +++ b/app/src/main/java/fr/free/nrw/commons/LicenseList.java @@ -14,7 +14,7 @@ import java.util.Locale; import java.util.Map; /** - * Represents LicenseList + * Represents a list of */ public class LicenseList { private Map licenses = new HashMap<>(); @@ -124,4 +124,4 @@ public class LicenseList { } } -} \ No newline at end of file +} From 80635adbfc895bf155e6831d2ab0c80747d1ca77 Mon Sep 17 00:00:00 2001 From: Prajeen Govardhanam <32291277+prajgov@users.noreply.github.com> Date: Thu, 21 Dec 2017 20:40:16 +0530 Subject: [PATCH 09/21] Update Media.java --- app/src/main/java/fr/free/nrw/commons/Media.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/fr/free/nrw/commons/Media.java b/app/src/main/java/fr/free/nrw/commons/Media.java index 27888e350..726d787f3 100644 --- a/app/src/main/java/fr/free/nrw/commons/Media.java +++ b/app/src/main/java/fr/free/nrw/commons/Media.java @@ -119,7 +119,7 @@ public class Media implements Parcelable { } /** - * Modifies tag of media + * Modifies( or creates a) tag of media * @param key Media key * @param value Media value */ From 8f32fc1c0173d18313da21d7f2e7d1324dc782d1 Mon Sep 17 00:00:00 2001 From: Prajeen Govardhanam <32291277+prajgov@users.noreply.github.com> Date: Thu, 21 Dec 2017 20:47:17 +0530 Subject: [PATCH 10/21] Update CommonsApplication.java --- .../fr/free/nrw/commons/CommonsApplication.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/fr/free/nrw/commons/CommonsApplication.java b/app/src/main/java/fr/free/nrw/commons/CommonsApplication.java index c2da8ad98..b9ec73863 100644 --- a/app/src/main/java/fr/free/nrw/commons/CommonsApplication.java +++ b/app/src/main/java/fr/free/nrw/commons/CommonsApplication.java @@ -44,15 +44,20 @@ import timber.log.Timber; ) public class CommonsApplication extends DaggerApplication { - public static final String DEFAULT_EDIT_SUMMARY = "Uploaded using Android Commons app"; - public static final String FEEDBACK_EMAIL = "commons-app-android@googlegroups.com"; - public static final String LOGS_PRIVATE_EMAIL = "commons-app-android-private@googlegroups.com"; - public static final String FEEDBACK_EMAIL_SUBJECT = "Commons Android App (%s) Feedback"; @Inject SessionManager sessionManager; @Inject DBOpenHelper dbOpenHelper; @Inject @Named("default_preferences") SharedPreferences defaultPrefs; @Inject @Named("application_preferences") SharedPreferences applicationPrefs; @Inject @Named("prefs") SharedPreferences otherPrefs; + + public static final String DEFAULT_EDIT_SUMMARY = "Uploaded using Android Commons app"; + + public static final String FEEDBACK_EMAIL = "commons-app-android@googlegroups.com"; + + public static final String LOGS_PRIVATE_EMAIL = "commons-app-android-private@googlegroups.com"; + + public static final String FEEDBACK_EMAIL_SUBJECT = "Commons Android App (%s) Feedback"; + private CommonsApplicationComponent component; private RefWatcher refWatcher; From 1d94b8a87c1589a5ebc387cd962b965d3c3b757a Mon Sep 17 00:00:00 2001 From: Prajeen Govardhanam <32291277+prajgov@users.noreply.github.com> Date: Thu, 21 Dec 2017 20:54:37 +0530 Subject: [PATCH 11/21] Update CommonsApplication.java --- .../free/nrw/commons/CommonsApplication.java | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/fr/free/nrw/commons/CommonsApplication.java b/app/src/main/java/fr/free/nrw/commons/CommonsApplication.java index b9ec73863..ee0f10019 100644 --- a/app/src/main/java/fr/free/nrw/commons/CommonsApplication.java +++ b/app/src/main/java/fr/free/nrw/commons/CommonsApplication.java @@ -61,17 +61,6 @@ public class CommonsApplication extends DaggerApplication { private CommonsApplicationComponent component; private RefWatcher refWatcher; - /** - * Provides a way to get member refWatcher - * - * @param context Application context - * @return application member refWatcher - */ - public static RefWatcher getRefWatcher(Context context) { - CommonsApplication application = (CommonsApplication) context.getApplicationContext(); - return application.refWatcher; - } - /** * Used to declare and initialize various components and dependencies */ @@ -106,11 +95,22 @@ public class CommonsApplication extends DaggerApplication { } return LeakCanary.install(this); } - - /** - * Helps in injecting dependency library Dagger - * @return Dagger injector + + /** + * Provides a way to get member refWatcher + * + * @param context Application context + * @return application member refWatcher */ + public static RefWatcher getRefWatcher(Context context) { + CommonsApplication application = (CommonsApplication) context.getApplicationContext(); + return application.refWatcher; + } + + /** + * Helps in injecting dependency library Dagger + * @return Dagger injector + */ @Override protected AndroidInjector applicationInjector() { return injector(); From 278b655a10d2aaf249e3cb36cb8a82755ec36e73 Mon Sep 17 00:00:00 2001 From: Prajeen Govardhanam <32291277+prajgov@users.noreply.github.com> Date: Thu, 21 Dec 2017 20:56:25 +0530 Subject: [PATCH 12/21] Update LicenseList.java --- app/src/main/java/fr/free/nrw/commons/LicenseList.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/fr/free/nrw/commons/LicenseList.java b/app/src/main/java/fr/free/nrw/commons/LicenseList.java index a2a4bb3ea..d08e314cc 100644 --- a/app/src/main/java/fr/free/nrw/commons/LicenseList.java +++ b/app/src/main/java/fr/free/nrw/commons/LicenseList.java @@ -14,7 +14,7 @@ import java.util.Locale; import java.util.Map; /** - * Represents a list of + * Represents a list of Licenses */ public class LicenseList { private Map licenses = new HashMap<>(); From d3f2ef32fd6c8fce7aba8da8bb36211e19eb107f Mon Sep 17 00:00:00 2001 From: Prajeen Govardhanam <32291277+prajgov@users.noreply.github.com> Date: Thu, 21 Dec 2017 20:58:02 +0530 Subject: [PATCH 13/21] Update Utils.java --- app/src/main/java/fr/free/nrw/commons/Utils.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/fr/free/nrw/commons/Utils.java b/app/src/main/java/fr/free/nrw/commons/Utils.java index a8bd91a39..967f2cf8e 100644 --- a/app/src/main/java/fr/free/nrw/commons/Utils.java +++ b/app/src/main/java/fr/free/nrw/commons/Utils.java @@ -50,9 +50,9 @@ public class Utils { } /** - * Encodes given URL in UTF-8 format + * URL Encode an URL in UTF-8 format * @param url Unformatted URL - * @return Formatted URL + * @return Encoded URL */ public static String urlEncode(String url) { try { From 1bb7dbeb13271a3ae0641b80fbc5074a45e5f744 Mon Sep 17 00:00:00 2001 From: Prajeen Govardhanam <32291277+prajgov@users.noreply.github.com> Date: Fri, 22 Dec 2017 11:35:16 +0530 Subject: [PATCH 14/21] Update build.gradle --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index b0e8b6718..6b7e5dc00 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ buildscript { google() } dependencies { - classpath 'com.android.tools.build:gradle:3.0.1' + classpath "com.android.tools.build:gradle:${project.gradleVersion}" classpath 'com.dicedmelon.gradle:jacoco-android:0.1.1' classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.7.1' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" From 57820e75b859a0296cd3c53dda03680ec89cee3b Mon Sep 17 00:00:00 2001 From: Prajeen Govardhanam <32291277+prajgov@users.noreply.github.com> Date: Fri, 22 Dec 2017 11:42:35 +0530 Subject: [PATCH 15/21] Update LengthUtils.java --- .../main/java/fr/free/nrw/commons/utils/LengthUtils.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/fr/free/nrw/commons/utils/LengthUtils.java b/app/src/main/java/fr/free/nrw/commons/utils/LengthUtils.java index ac59c1bbe..8b687164b 100644 --- a/app/src/main/java/fr/free/nrw/commons/utils/LengthUtils.java +++ b/app/src/main/java/fr/free/nrw/commons/utils/LengthUtils.java @@ -64,9 +64,9 @@ public class LengthUtils { } /** - * Gets twice the amount of arc sine of (x)^(1/2) + * Computes inverse of haversine * @param x Angle in radian - * @return Twice the angle + * @return Inverse of haversine */ private static double arcHav(double x) { return 2.0D * Math.asin(Math.sqrt(x)); @@ -84,9 +84,9 @@ public class LengthUtils { } /** - * Computes square sine function for half of the value entered + * Computes haversine * @param x Angle in radians - * @return One-forth of square of sine function + * @return Haversine of x */ private static double hav(double x) { double sinHalf = Math.sin(x * 0.5D); From 75056581d94b2af7be8011aa2633cce4f521433a Mon Sep 17 00:00:00 2001 From: Prajeen Govardhanam <32291277+prajgov@users.noreply.github.com> Date: Fri, 22 Dec 2017 11:43:39 +0530 Subject: [PATCH 16/21] Update LogBuilder.java --- app/src/main/java/fr/free/nrw/commons/mwapi/LogBuilder.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/app/src/main/java/fr/free/nrw/commons/mwapi/LogBuilder.java b/app/src/main/java/fr/free/nrw/commons/mwapi/LogBuilder.java index c855d788b..2a2456cc3 100644 --- a/app/src/main/java/fr/free/nrw/commons/mwapi/LogBuilder.java +++ b/app/src/main/java/fr/free/nrw/commons/mwapi/LogBuilder.java @@ -83,10 +83,7 @@ public class LogBuilder { LogTask logTask = new LogTask(mwApi); logTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, this); } - - /** - * Logs in false - */ + public void log() { log(false); } From af20ec068c49e15badeb4fb0600b8c1922175574 Mon Sep 17 00:00:00 2001 From: prajgov Date: Fri, 22 Dec 2017 11:46:48 +0530 Subject: [PATCH 17/21] added JavaDoc comments --- app/src/main/java/fr/free/nrw/commons/data/Category.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/fr/free/nrw/commons/data/Category.java b/app/src/main/java/fr/free/nrw/commons/data/Category.java index 87ab6f2ea..05a8681f7 100644 --- a/app/src/main/java/fr/free/nrw/commons/data/Category.java +++ b/app/src/main/java/fr/free/nrw/commons/data/Category.java @@ -42,10 +42,10 @@ public class Category { } /** - * Find persisted category in database, based on its name. + * Find persisted category in database table, based on its name. * @param client ContentProviderClient to handle DB connection * @param name Category's name - * @return category from database, or null if not found + * @return category from , database table, or null if not found */ public static @Nullable Category find(ContentProviderClient client, String name) { Cursor cursor = null; @@ -230,7 +230,7 @@ public class Category { + ");"; /** - * Creates new database with provided SQLite database + * Creates new table with provided SQLite database * * @param db Category database */ @@ -239,7 +239,7 @@ public class Category { } /** - * Deletes existing database + * Deletes existing table * @param db Category database */ public static void onDelete(SQLiteDatabase db) { From f4cfa5d544e440144d0ee8d517ec4966654a5842 Mon Sep 17 00:00:00 2001 From: prajgov Date: Fri, 22 Dec 2017 11:58:50 +0530 Subject: [PATCH 18/21] added JavaDoc comments --- .../fr/free/nrw/commons/data/Category.java | 213 +++++++++--------- 1 file changed, 104 insertions(+), 109 deletions(-) diff --git a/app/src/main/java/fr/free/nrw/commons/data/Category.java b/app/src/main/java/fr/free/nrw/commons/data/Category.java index 05a8681f7..be4a29846 100644 --- a/app/src/main/java/fr/free/nrw/commons/data/Category.java +++ b/app/src/main/java/fr/free/nrw/commons/data/Category.java @@ -25,6 +25,107 @@ public class Category { private int timesUsed; // Getters/setters + /** + * Gets name + * + * @return name + */ + public String getName() { + return name; + } + + /** + * Modifies name + * + * @param name Category name + */ + public void setName(String name) { + this.name = name; + } + + /** + * Gets last used date + * + * @return Last used date + */ + private Date getLastUsed() { + // warning: Date objects are mutable. + return (Date)lastUsed.clone(); + } + + /** + * Modifies last used date + * + * @param lastUsed Category date + */ + public void setLastUsed(Date lastUsed) { + // warning: Date objects are mutable. + this.lastUsed = (Date)lastUsed.clone(); + } + + /** + * Generates new last used date + */ + private void touch() { + lastUsed = new Date(); + } + + /** + * Gets no. of times the category is used + * + * @return no. of times used + */ + private int getTimesUsed() { + return timesUsed; + } + + /** + * Modifies no. of times used + * + * @param timesUsed Category used times + */ + public void setTimesUsed(int timesUsed) { + this.timesUsed = timesUsed; + } + + /** + * Increments timesUsed by 1 and sets last used date as now. + */ + public void incTimesUsed() { + timesUsed++; + touch(); + } + + //region Database/content-provider stuff + + /** + * Persist category. + * @param client ContentProviderClient to handle DB connection + */ + public void save(ContentProviderClient client) { + try { + if (contentUri == null) { + contentUri = client.insert(CategoryContentProvider.BASE_URI, this.toContentValues()); + } else { + client.update(contentUri, toContentValues(), null, null); + } + } catch (RemoteException e) { + throw new RuntimeException(e); + } + } + + /** + * Gets content values + * + * @return Content values + */ + private ContentValues toContentValues() { + ContentValues cv = new ContentValues(); + cv.put(Table.COLUMN_NAME, getName()); + cv.put(Table.COLUMN_LAST_USED, getLastUsed().getTime()); + cv.put(Table.COLUMN_TIMES_USED, getTimesUsed()); + return cv; + } /** * Gets category from cursor @@ -42,10 +143,10 @@ public class Category { } /** - * Find persisted category in database table, based on its name. + * Find persisted category in database, based on its name. * @param client ContentProviderClient to handle DB connection * @param name Category's name - * @return category from , database table, or null if not found + * @return category from database, or null if not found */ public static @Nullable Category find(ContentProviderClient client, String name) { Cursor cursor = null; @@ -100,112 +201,6 @@ public class Category { return items; } - /** - * Gets name - * - * @return name - */ - public String getName() { - return name; - } - - /** - * Modifies name - * - * @param name Category name - */ - public void setName(String name) { - this.name = name; - } - - /** - * Gets last used date - * - * @return Last used date - */ - private Date getLastUsed() { - // warning: Date objects are mutable. - return (Date) lastUsed.clone(); - } - - /** - * Modifies last used date - * - * @param lastUsed Category date - */ - public void setLastUsed(Date lastUsed) { - // warning: Date objects are mutable. - this.lastUsed = (Date) lastUsed.clone(); - } - - /** - * Generates new last used date - */ - private void touch() { - lastUsed = new Date(); - } - - //region Database/content-provider stuff - - /** - * Gets no. of times the category is used - * - * @return no. of times used - */ - private int getTimesUsed() { - return timesUsed; - } - - /** - * Modifies no. of times used - * - * @param timesUsed Category used times - */ - public void setTimesUsed(int timesUsed) { - this.timesUsed = timesUsed; - } - - /** - * Increments timesUsed by 1 and sets last used date as now. - */ - public void incTimesUsed() { - timesUsed++; - touch(); - } - - /** - * Persist category. - * - * @param client ContentProviderClient to handle DB connection - */ - public void save(ContentProviderClient client) { - try { - if (contentUri == null) { - contentUri = client.insert(CategoryContentProvider.BASE_URI, this.toContentValues()); - } else { - client.update(contentUri, toContentValues(), null, null); - } - } catch (RemoteException e) { - throw new RuntimeException(e); - } - } - - /** - * Gets content values - * - * @return Content values - */ - private ContentValues toContentValues() { - ContentValues cv = new ContentValues(); - cv.put(Table.COLUMN_NAME, getName()); - cv.put(Table.COLUMN_LAST_USED, getLastUsed().getTime()); - cv.put(Table.COLUMN_TIMES_USED, getTimesUsed()); - return cv; - } - - /** - * Represents table - */ public static class Table { public static final String TABLE_NAME = "categories"; @@ -278,4 +273,4 @@ public class Category { } } //endregion -} +} \ No newline at end of file From f86fb5ed53a1b77b241d0aa9fb7b88d75bd9d2a2 Mon Sep 17 00:00:00 2001 From: Prajeen Govardhanam <32291277+prajgov@users.noreply.github.com> Date: Fri, 22 Dec 2017 12:02:02 +0530 Subject: [PATCH 19/21] Update WelcomePagerAdapter.java --- app/src/main/java/fr/free/nrw/commons/WelcomePagerAdapter.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/src/main/java/fr/free/nrw/commons/WelcomePagerAdapter.java b/app/src/main/java/fr/free/nrw/commons/WelcomePagerAdapter.java index eedc5ee0d..a346655cf 100644 --- a/app/src/main/java/fr/free/nrw/commons/WelcomePagerAdapter.java +++ b/app/src/main/java/fr/free/nrw/commons/WelcomePagerAdapter.java @@ -74,9 +74,6 @@ public class WelcomePagerAdapter extends PagerAdapter { container.removeView((View) obj); } - /** - * Interface used create on clicked callback(s). - */ public interface Callback { void onYesClicked(); } From d4f35f2c74c3eabbb6a3f63efc3484fe22039ef4 Mon Sep 17 00:00:00 2001 From: Prajeen Govardhanam <32291277+prajgov@users.noreply.github.com> Date: Fri, 22 Dec 2017 12:05:11 +0530 Subject: [PATCH 20/21] Update WelcomeActivity.java --- .../fr/free/nrw/commons/WelcomeActivity.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/fr/free/nrw/commons/WelcomeActivity.java b/app/src/main/java/fr/free/nrw/commons/WelcomeActivity.java index 17c4be137..72d122e77 100644 --- a/app/src/main/java/fr/free/nrw/commons/WelcomeActivity.java +++ b/app/src/main/java/fr/free/nrw/commons/WelcomeActivity.java @@ -18,16 +18,6 @@ public class WelcomeActivity extends BaseActivity { private WelcomePagerAdapter adapter = new WelcomePagerAdapter(); - /** - * Creates a way to change current activity to WelcomeActivity - * - * @param context Activity context - */ - public static void startYourself(Context context) { - Intent welcomeIntent = new Intent(context, WelcomeActivity.class); - context.startActivity(welcomeIntent); - } - /** * Initialises exiting fields and dependencies * @@ -53,4 +43,14 @@ public class WelcomeActivity extends BaseActivity { adapter.setCallback(null); super.onDestroy(); } + + /** + * Creates a way to change current activity to WelcomeActivity + * + * @param context Activity context + */ + public static void startYourself(Context context) { + Intent welcomeIntent = new Intent(context, WelcomeActivity.class); + context.startActivity(welcomeIntent); + } } From a4e8b9a26af94c149f171342e109af0a6c94925c Mon Sep 17 00:00:00 2001 From: Prajeen Govardhanam <32291277+prajgov@users.noreply.github.com> Date: Fri, 22 Dec 2017 12:18:17 +0530 Subject: [PATCH 21/21] Update WelcomeActivity.java --- app/src/main/java/fr/free/nrw/commons/WelcomeActivity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/fr/free/nrw/commons/WelcomeActivity.java b/app/src/main/java/fr/free/nrw/commons/WelcomeActivity.java index 72d122e77..7bfb22890 100644 --- a/app/src/main/java/fr/free/nrw/commons/WelcomeActivity.java +++ b/app/src/main/java/fr/free/nrw/commons/WelcomeActivity.java @@ -43,7 +43,7 @@ public class WelcomeActivity extends BaseActivity { adapter.setCallback(null); super.onDestroy(); } - + /** * Creates a way to change current activity to WelcomeActivity *