Added JavaDocs and improved quality

This commit is contained in:
tanvidadu 2018-05-23 02:34:32 +05:30
parent 157e744ba3
commit f40a566e10
5 changed files with 83 additions and 50 deletions

View file

@ -2,11 +2,13 @@ package fr.free.nrw.commons;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri; import android.net.Uri;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.customtabs.CustomTabsIntent; import android.support.customtabs.CustomTabsIntent;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
import android.view.View;
import android.widget.Toast; import android.widget.Toast;
import org.apache.commons.codec.binary.Hex; import org.apache.commons.codec.binary.Hex;
@ -58,6 +60,7 @@ public class Utils {
/** /**
* URL Encode an URL in UTF-8 format * URL Encode an URL in UTF-8 format
*
* @param url Unformatted URL * @param url Unformatted URL
* @return Encoded URL * @return Encoded URL
*/ */
@ -81,6 +84,7 @@ public class Utils {
/** /**
* Generates licence name with given ID * Generates licence name with given ID
*
* @param license License ID * @param license License ID
* @return Name of license * @return Name of license
*/ */
@ -106,6 +110,7 @@ public class Utils {
/** /**
* Fixing incorrect extension * Fixing incorrect extension
*
* @param title File name * @param title File name
* @param extension Correct extension * @param extension Correct extension
* @return File with correct extension * @return File with correct extension
@ -127,6 +132,7 @@ public class Utils {
/** /**
* Tells whether dark theme is active or not * Tells whether dark theme is active or not
*
* @param context Activity context * @param context Activity context
* @return The state of dark theme * @return The state of dark theme
*/ */
@ -171,8 +177,7 @@ public class Utils {
final String appPackageName = BuildConfig.class.getPackage().getName(); final String appPackageName = BuildConfig.class.getPackage().getName();
try { try {
context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName))); context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)));
} } catch (android.content.ActivityNotFoundException anfe) {
catch (android.content.ActivityNotFoundException anfe) {
context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName))); context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName)));
} }
} }
@ -194,4 +199,18 @@ public class Utils {
customTabsIntent.launchUrl(context, url); customTabsIntent.launchUrl(context, url);
} }
/**
* To take screenshot of the screen and return it in Bitmap format
*
* @param view
* @return
*/
public static Bitmap getScreenShot(View view) {
View screenView = view.getRootView();
screenView.setDrawingCacheEnabled(true);
Bitmap bitmap = Bitmap.createBitmap(screenView.getDrawingCache());
screenView.setDrawingCacheEnabled(false);
return bitmap;
}
} }

View file

@ -1,45 +1,39 @@
package fr.free.nrw.commons.achievements; package fr.free.nrw.commons.achievements;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.net.Uri; import android.net.Uri;
import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.util.Log; import android.util.Log;
import android.view.Menu; import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout; import android.widget.RelativeLayout;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast;
import android.widget.Toolbar;
import org.json.JSONObject; import org.json.JSONObject;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.Random;
import javax.inject.Inject; import javax.inject.Inject;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import dagger.Binds;
import fr.free.nrw.commons.R; import fr.free.nrw.commons.R;
import fr.free.nrw.commons.Utils;
import fr.free.nrw.commons.auth.SessionManager; import fr.free.nrw.commons.auth.SessionManager;
import fr.free.nrw.commons.mwapi.MediaWikiApi; import fr.free.nrw.commons.mwapi.MediaWikiApi;
import fr.free.nrw.commons.theme.NavigationBaseActivity; import fr.free.nrw.commons.theme.NavigationBaseActivity;
import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable; import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.schedulers.Schedulers; import io.reactivex.schedulers.Schedulers;
import timber.log.Timber;
/** /**
* activity for sharing feedback on uploaded activity * activity for sharing feedback on uploaded activity
@ -49,14 +43,19 @@ public class AchievementsActivity extends NavigationBaseActivity {
private static final double BADGE_IMAGE_WIDTH_RATIO = 0.4; private static final double BADGE_IMAGE_WIDTH_RATIO = 0.4;
private static final double BADGE_IMAGE_HEIGHT_RATIO = 0.3; private static final double BADGE_IMAGE_HEIGHT_RATIO = 0.3;
@BindView(R.id.achievement_badge) ImageView imageView; @BindView(R.id.achievement_badge)
ImageView imageView;
@BindView(R.id.achievement_level) @BindView(R.id.achievement_level)
TextView textView; TextView textView;
@BindView(R.id.toolbar) android.support.v7.widget.Toolbar toolbar; @BindView(R.id.toolbar)
@Inject SessionManager sessionManager; Toolbar toolbar;
@Inject MediaWikiApi mediaWikiApi; @Inject
SessionManager sessionManager;
@Inject
MediaWikiApi mediaWikiApi;
private CompositeDisposable compositeDisposable = new CompositeDisposable(); private CompositeDisposable compositeDisposable = new CompositeDisposable();
/** /**
* This method helps in the creation Achievement screen and * This method helps in the creation Achievement screen and
* dynamically set the size of imageView * dynamically set the size of imageView
@ -88,7 +87,7 @@ public class AchievementsActivity extends NavigationBaseActivity {
imageView.requestLayout(); imageView.requestLayout();
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
setUploadCount(); setAchievements();
initDrawer(); initDrawer();
} }
@ -104,28 +103,16 @@ public class AchievementsActivity extends NavigationBaseActivity {
int id = item.getItemId(); int id = item.getItemId();
if (id == R.id.share_app_icon) { if (id == R.id.share_app_icon) {
View rootView = getWindow().getDecorView().findViewById(android.R.id.content); View rootView = getWindow().getDecorView().findViewById(android.R.id.content);
Bitmap screenShot = getScreenShot(rootView); Bitmap screenShot = Utils.getScreenShot(rootView);
shareScreen(screenShot); shareScreen(screenShot);
} }
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }
/**
* To take screenshot of the screen and return it in Bitmap format
* @param view
* @return
*/
public static Bitmap getScreenShot(View view) {
View screenView = view.getRootView();
screenView.setDrawingCacheEnabled(true);
Bitmap bitmap = Bitmap.createBitmap(screenView.getDrawingCache());
screenView.setDrawingCacheEnabled(false);
return bitmap;
}
/** /**
* To take bitmap and store it temporary storage and share it * To take bitmap and store it temporary storage and share it
*
* @param bitmap * @param bitmap
*/ */
void shareScreen(Bitmap bitmap) { void shareScreen(Bitmap bitmap) {
@ -146,7 +133,11 @@ public class AchievementsActivity extends NavigationBaseActivity {
} }
} }
private void setUploadCount() { /**
* To call the API to get results in form Single<JSONObject>
* which then calls parseJson when results are fetched
*/
private void setAchievements() {
compositeDisposable.add(mediaWikiApi compositeDisposable.add(mediaWikiApi
.getAchievements(sessionManager.getCurrentAccount().name) .getAchievements(sessionManager.getCurrentAccount().name)
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
@ -156,8 +147,25 @@ public class AchievementsActivity extends NavigationBaseActivity {
)); ));
} }
/**
* used to parse the JSONObject containing results
*
* @param object
*/
private void parseJson(JSONObject object) { private void parseJson(JSONObject object) {
Log.i("json", object.toString()); Log.i("json", object.toString());
} }
/**
* Creates a way to change current activity to AchievementActivity
*
* @param context
*/
public static void startYourself(Context context) {
Intent intent = new Intent(context, AchievementsActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
context.startActivity(intent);
}
} }

View file

@ -43,7 +43,6 @@ import java.util.concurrent.Callable;
import fr.free.nrw.commons.BuildConfig; import fr.free.nrw.commons.BuildConfig;
import fr.free.nrw.commons.Media; import fr.free.nrw.commons.Media;
import fr.free.nrw.commons.PageTitle; import fr.free.nrw.commons.PageTitle;
import fr.free.nrw.commons.achievements.Achievements;
import fr.free.nrw.commons.category.CategoryImageUtils; import fr.free.nrw.commons.category.CategoryImageUtils;
import fr.free.nrw.commons.category.QueryContinue; import fr.free.nrw.commons.category.QueryContinue;
import fr.free.nrw.commons.notification.Notification; import fr.free.nrw.commons.notification.Notification;
@ -473,6 +472,7 @@ public class ApacheHttpClientMediaWikiApi implements MediaWikiApi {
* The method takes categoryName as input and returns a List of Media objects * The method takes categoryName as input and returns a List of Media objects
* It uses the generator query API to get the images in a category, 10 at a time. * It uses the generator query API to get the images in a category, 10 at a time.
* Uses the query continue values for fetching paginated responses * Uses the query continue values for fetching paginated responses
*
* @param categoryName Category name as defined on commons * @param categoryName Category name as defined on commons
* @return * @return
*/ */
@ -524,6 +524,7 @@ public class ApacheHttpClientMediaWikiApi implements MediaWikiApi {
* For APIs that return paginated responses, MediaWiki APIs uses the QueryContinue to facilitate fetching of subsequent pages * For APIs that return paginated responses, MediaWiki APIs uses the QueryContinue to facilitate fetching of subsequent pages
* https://www.mediawiki.org/wiki/API:Raw_query_continue * https://www.mediawiki.org/wiki/API:Raw_query_continue
* After fetching images a page of image for a particular category, shared prefs are updated with the latest QueryContinue Values * After fetching images a page of image for a particular category, shared prefs are updated with the latest QueryContinue Values
*
* @param keyword * @param keyword
* @param queryContinue * @param queryContinue
*/ */
@ -535,6 +536,7 @@ public class ApacheHttpClientMediaWikiApi implements MediaWikiApi {
/** /**
* Before making a paginated API call, this method is called to get the latest query continue values to be used * Before making a paginated API call, this method is called to get the latest query continue values to be used
*
* @param keyword * @param keyword
* @return * @return
*/ */
@ -621,6 +623,12 @@ public class ApacheHttpClientMediaWikiApi implements MediaWikiApi {
}); });
} }
/**
* This takes userName as input, which is then used to fetch the feedback/achievements
* statistics using OkHttp and JavaRx. This function return JSONObject
* @param userName
* @return
*/
@NonNull @NonNull
@Override @Override
public Single<JSONObject> getAchievements(String userName) { public Single<JSONObject> getAchievements(String userName) {

View file

@ -10,7 +10,6 @@ import java.io.InputStream;
import java.util.List; import java.util.List;
import fr.free.nrw.commons.Media; import fr.free.nrw.commons.Media;
import fr.free.nrw.commons.achievements.Achievements;
import fr.free.nrw.commons.notification.Notification; import fr.free.nrw.commons.notification.Notification;
import io.reactivex.Observable; import io.reactivex.Observable;
import io.reactivex.Single; import io.reactivex.Single;

View file

@ -80,8 +80,7 @@ public abstract class NavigationBaseActivity extends BaseActivity
@Override @Override
public void onClick(View v) { public void onClick(View v) {
drawerLayout.closeDrawer(navigationView); drawerLayout.closeDrawer(navigationView);
startActivityWithFlags(NavigationBaseActivity.this, AchievementsActivity.class, Intent.FLAG_ACTIVITY_CLEAR_TOP, AchievementsActivity.startYourself(NavigationBaseActivity.this);
Intent.FLAG_ACTIVITY_SINGLE_TOP);
} }
}); });
} }