mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 04:43:54 +01:00
Added JavaDocs and improved quality
This commit is contained in:
parent
157e744ba3
commit
f40a566e10
5 changed files with 83 additions and 50 deletions
|
|
@ -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,7 +110,8 @@ 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
|
||||||
*/
|
*/
|
||||||
|
|
@ -146,7 +152,7 @@ public class Utils {
|
||||||
StringBuilder stringBuilder = new StringBuilder();
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String[] command = new String[] {"logcat","-d","-v","threadtime"};
|
String[] command = new String[]{"logcat", "-d", "-v", "threadtime"};
|
||||||
|
|
||||||
Process process = Runtime.getRuntime().exec(command);
|
Process process = Runtime.getRuntime().exec(command);
|
||||||
|
|
||||||
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,62 +1,61 @@
|
||||||
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
|
||||||
*/
|
*/
|
||||||
public class AchievementsActivity extends NavigationBaseActivity {
|
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
|
||||||
|
|
@ -82,13 +81,13 @@ public class AchievementsActivity extends NavigationBaseActivity {
|
||||||
*/
|
*/
|
||||||
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams)
|
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams)
|
||||||
imageView.getLayoutParams();
|
imageView.getLayoutParams();
|
||||||
params.height = (int) (height*BADGE_IMAGE_HEIGHT_RATIO);
|
params.height = (int) (height * BADGE_IMAGE_HEIGHT_RATIO);
|
||||||
params.width = (int) (width*BADGE_IMAGE_WIDTH_RATIO);
|
params.width = (int) (width * BADGE_IMAGE_WIDTH_RATIO);
|
||||||
imageView.setImageResource(R.drawable.featured);
|
imageView.setImageResource(R.drawable.featured);
|
||||||
imageView.requestLayout();
|
imageView.requestLayout();
|
||||||
|
|
||||||
setSupportActionBar(toolbar);
|
setSupportActionBar(toolbar);
|
||||||
setUploadCount();
|
setAchievements();
|
||||||
initDrawer();
|
initDrawer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -104,33 +103,21 @@ 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) {
|
||||||
try {
|
try {
|
||||||
File file = new File(this.getExternalCacheDir(),"screen.png");
|
File file = new File(this.getExternalCacheDir(), "screen.png");
|
||||||
FileOutputStream fOut = new FileOutputStream(file);
|
FileOutputStream fOut = new FileOutputStream(file);
|
||||||
bitmap.compress(Bitmap.CompressFormat.PNG, 100, fOut);
|
bitmap.compress(Bitmap.CompressFormat.PNG, 100, fOut);
|
||||||
fOut.flush();
|
fOut.flush();
|
||||||
|
|
@ -146,18 +133,39 @@ 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())
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe(
|
.subscribe(
|
||||||
jsonObject -> parseJson(jsonObject)
|
jsonObject -> parseJson(jsonObject)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void parseJson(JSONObject object){
|
/**
|
||||||
Log.i("json",object.toString());
|
* used to parse the JSONObject containing results
|
||||||
|
*
|
||||||
|
* @param object
|
||||||
|
*/
|
||||||
|
private void parseJson(JSONObject object) {
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
|
@ -223,7 +222,7 @@ public class ApacheHttpClientMediaWikiApi implements MediaWikiApi {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean pageExists(String pageName) throws IOException {
|
public boolean pageExists(String pageName) throws IOException {
|
||||||
return Double.parseDouble( api.action("query")
|
return Double.parseDouble(api.action("query")
|
||||||
.param("titles", pageName)
|
.param("titles", pageName)
|
||||||
.get()
|
.get()
|
||||||
.getString("/api/query/pages/page/@_idx")) != -1;
|
.getString("/api/query/pages/page/@_idx")) != -1;
|
||||||
|
|
@ -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,19 +623,25 @@ 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) {
|
||||||
final String fetchAchievementUrlTemplate =
|
final String fetchAchievementUrlTemplate =
|
||||||
wikiMediaToolforgeUrl + "urbanecmbot/commonsmisc/feedback.py";
|
wikiMediaToolforgeUrl + "urbanecmbot/commonsmisc/feedback.py";
|
||||||
return Single.fromCallable(()->{
|
return Single.fromCallable(() -> {
|
||||||
String url = String.format(
|
String url = String.format(
|
||||||
Locale.ENGLISH,
|
Locale.ENGLISH,
|
||||||
fetchAchievementUrlTemplate,
|
fetchAchievementUrlTemplate,
|
||||||
new PageTitle(userName).getText());
|
new PageTitle(userName).getText());
|
||||||
HttpUrl.Builder urlBuilder = HttpUrl.parse(url).newBuilder();
|
HttpUrl.Builder urlBuilder = HttpUrl.parse(url).newBuilder();
|
||||||
urlBuilder.addQueryParameter("user",userName);
|
urlBuilder.addQueryParameter("user", userName);
|
||||||
Log.i("url",urlBuilder.toString());
|
Log.i("url", urlBuilder.toString());
|
||||||
Request request = new Request.Builder()
|
Request request = new Request.Builder()
|
||||||
.url(urlBuilder.toString())
|
.url(urlBuilder.toString())
|
||||||
.build();
|
.build();
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
|
@ -79,7 +78,7 @@ public interface MediaWikiApi {
|
||||||
Single<Integer> getUploadCount(String userName);
|
Single<Integer> getUploadCount(String userName);
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
Single<JSONObject> getAchievements (String userName);
|
Single<JSONObject> getAchievements(String userName);
|
||||||
|
|
||||||
interface ProgressListener {
|
interface ProgressListener {
|
||||||
void onProgress(long transferred, long total);
|
void onProgress(long transferred, long total);
|
||||||
|
|
|
||||||
|
|
@ -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);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue