mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Merge pull request #1551 from tanvidadu/feedback2
Feedback on how my pictures get used [WIP]
This commit is contained in:
commit
bd1555f558
12 changed files with 567 additions and 14 deletions
|
|
@ -68,7 +68,7 @@ dependencies {
|
||||||
testImplementation 'org.robolectric:robolectric:3.7.1'
|
testImplementation 'org.robolectric:robolectric:3.7.1'
|
||||||
testImplementation 'com.nhaarman:mockito-kotlin:1.5.0'
|
testImplementation 'com.nhaarman:mockito-kotlin:1.5.0'
|
||||||
testImplementation 'com.squareup.okhttp3:mockwebserver:3.8.1'
|
testImplementation 'com.squareup.okhttp3:mockwebserver:3.8.1'
|
||||||
compile 'com.dinuscxj:circleprogressbar:1.1.1'
|
implementation 'com.dinuscxj:circleprogressbar:1.1.1'
|
||||||
|
|
||||||
androidTestImplementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
|
androidTestImplementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
|
||||||
androidTestImplementation 'com.squareup.okhttp3:mockwebserver:3.8.1'
|
androidTestImplementation 'com.squareup.okhttp3:mockwebserver:3.8.1'
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,127 @@
|
||||||
package fr.free.nrw.commons.achievements;
|
package fr.free.nrw.commons.achievements;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* represnts Achievements
|
||||||
|
*/
|
||||||
public class Achievements {
|
public class Achievements {
|
||||||
|
private int uniqueUsedImages;
|
||||||
|
private int articlesUsingImages;
|
||||||
|
private int thanksReceived;
|
||||||
|
private int imagesEditedBySomeoneElse;
|
||||||
|
private int featuredImages;
|
||||||
|
private int imagesUploaded;
|
||||||
|
|
||||||
|
public Achievements(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public Achievements(int uniqueUsedImages,
|
||||||
|
int articlesUsingImages,
|
||||||
|
int thanksReceived,
|
||||||
|
int imagesEditedBySomeoneElse,
|
||||||
|
int featuredImages,
|
||||||
|
int imagesUploaded) {
|
||||||
|
this.uniqueUsedImages = uniqueUsedImages;
|
||||||
|
this.articlesUsingImages = articlesUsingImages;
|
||||||
|
this.thanksReceived = thanksReceived;
|
||||||
|
this.imagesEditedBySomeoneElse = imagesEditedBySomeoneElse;
|
||||||
|
this.featuredImages = featuredImages;
|
||||||
|
this.imagesUploaded = imagesUploaded;
|
||||||
|
}
|
||||||
|
public class AchievementsBuilder {
|
||||||
|
private int nestedUniqueUsedImages;
|
||||||
|
private int nestedArticlesUsingImages;
|
||||||
|
private int nestedThanksReceived;
|
||||||
|
private int nestedImagesEditedBySomeoneElse;
|
||||||
|
private int nestedFeaturedImages;
|
||||||
|
private int nestedImagesUploaded;
|
||||||
|
|
||||||
|
public AchievementsBuilder setUniqueUsedImages(int uniqueUsedImages) {
|
||||||
|
this.nestedUniqueUsedImages = uniqueUsedImages;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AchievementsBuilder setArticlesUsingImages(int articlesUsingImages) {
|
||||||
|
this.nestedArticlesUsingImages = articlesUsingImages;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AchievementsBuilder setThanksReceived(int thanksReceived) {
|
||||||
|
this.nestedThanksReceived = thanksReceived;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AchievementsBuilder setImagesEditedBySomeoneElse(int imagesEditedBySomeoneElse) {
|
||||||
|
this.nestedImagesEditedBySomeoneElse = imagesEditedBySomeoneElse;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AchievementsBuilder setFeaturedImages(int featuredImages) {
|
||||||
|
this.nestedFeaturedImages = featuredImages;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AchievementsBuilder setImagesUploaded(int imagesUploaded) {
|
||||||
|
this.nestedImagesUploaded = imagesUploaded;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Achievements createAchievements(){
|
||||||
|
return new Achievements(nestedUniqueUsedImages,
|
||||||
|
nestedArticlesUsingImages,
|
||||||
|
nestedThanksReceived,
|
||||||
|
nestedImagesEditedBySomeoneElse,
|
||||||
|
nestedFeaturedImages,
|
||||||
|
nestedImagesUploaded);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getImagesUploaded() {
|
||||||
|
return imagesUploaded;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getFeaturedImages() {
|
||||||
|
return featuredImages;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getImagesEditedBySomeoneElse() {
|
||||||
|
return imagesEditedBySomeoneElse;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getThanksReceived() {
|
||||||
|
return thanksReceived;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getArticlesUsingImages() {
|
||||||
|
return articlesUsingImages;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getUniqueUsedImages() {
|
||||||
|
return uniqueUsedImages;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setImagesUploaded(int imagesUploaded) {
|
||||||
|
this.imagesUploaded = imagesUploaded;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFeaturedImages(int featuredImages) {
|
||||||
|
this.featuredImages = featuredImages;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setImagesEditedBySomeoneElse(int imagesEditedBySomeoneElse) {
|
||||||
|
this.imagesEditedBySomeoneElse = imagesEditedBySomeoneElse;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setThanksReceived(int thanksReceived) {
|
||||||
|
this.thanksReceived = thanksReceived;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setArticlesUsingImages(int articlesUsingImages) {
|
||||||
|
this.articlesUsingImages = articlesUsingImages;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUniqueUsedImages(int uniqueUsedImages) {
|
||||||
|
this.uniqueUsedImages = uniqueUsedImages;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,20 +2,37 @@ package fr.free.nrw.commons.achievements;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.BitmapFactory;
|
||||||
|
import android.graphics.Canvas;
|
||||||
|
import android.graphics.Color;
|
||||||
|
import android.graphics.Paint;
|
||||||
|
import android.graphics.Rect;
|
||||||
|
import android.graphics.drawable.BitmapDrawable;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.support.v4.content.res.ResourcesCompat;
|
||||||
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.support.v7.widget.Toolbar;
|
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.ContextThemeWrapper;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
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.ProgressBar;
|
||||||
import android.widget.RelativeLayout;
|
import android.widget.RelativeLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.dinuscxj.progressbar.CircleProgressBar;
|
||||||
|
|
||||||
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
@ -26,6 +43,7 @@ import javax.inject.Inject;
|
||||||
|
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
|
import butterknife.OnClick;
|
||||||
import fr.free.nrw.commons.R;
|
import fr.free.nrw.commons.R;
|
||||||
import fr.free.nrw.commons.Utils;
|
import fr.free.nrw.commons.Utils;
|
||||||
import fr.free.nrw.commons.auth.SessionManager;
|
import fr.free.nrw.commons.auth.SessionManager;
|
||||||
|
|
@ -34,6 +52,7 @@ 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
|
||||||
|
|
@ -42,13 +61,36 @@ 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;
|
||||||
|
private Boolean isUploadFetched = false;
|
||||||
|
private Boolean isStatisticsFetched = false;
|
||||||
|
private Achievements achievements = new Achievements();
|
||||||
|
private LevelController level;
|
||||||
|
private LevelController.LevelInfo levelInfo;
|
||||||
|
|
||||||
@BindView(R.id.achievement_badge)
|
@BindView(R.id.achievement_badge)
|
||||||
ImageView imageView;
|
ImageView imageView;
|
||||||
@BindView(R.id.achievement_level)
|
@BindView(R.id.achievement_level)
|
||||||
TextView textView;
|
TextView levelNumber;
|
||||||
@BindView(R.id.toolbar)
|
@BindView(R.id.toolbar)
|
||||||
Toolbar toolbar;
|
Toolbar toolbar;
|
||||||
|
@BindView(R.id.thanks_received)
|
||||||
|
TextView thanksReceived;
|
||||||
|
@BindView(R.id.images_uploaded_progressbar)
|
||||||
|
CircleProgressBar imagesUploadedProgressbar;
|
||||||
|
@BindView(R.id.images_used_by_wiki_progressbar)
|
||||||
|
CircleProgressBar imagesUsedByWikiProgessbar;
|
||||||
|
@BindView(R.id.image_featured)
|
||||||
|
TextView imagesFeatured;
|
||||||
|
@BindView(R.id.progressBar)
|
||||||
|
ProgressBar progressBar;
|
||||||
|
@BindView(R.id.layout_image_uploaded)
|
||||||
|
RelativeLayout layoutImageUploaded;
|
||||||
|
@BindView(R.id.layout_image_reverts)
|
||||||
|
RelativeLayout layoutImageReverts;
|
||||||
|
@BindView(R.id.layout_image_used_by_wiki)
|
||||||
|
RelativeLayout layoutImageUsedByWiki;
|
||||||
|
@BindView(R.id.layout_statistics)
|
||||||
|
LinearLayout layoutStatistics;
|
||||||
@Inject
|
@Inject
|
||||||
SessionManager sessionManager;
|
SessionManager sessionManager;
|
||||||
@Inject
|
@Inject
|
||||||
|
|
@ -83,14 +125,32 @@ public class AchievementsActivity extends NavigationBaseActivity {
|
||||||
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.badge);
|
||||||
imageView.requestLayout();
|
imageView.requestLayout();
|
||||||
|
|
||||||
setSupportActionBar(toolbar);
|
setSupportActionBar(toolbar);
|
||||||
|
progressBar.setVisibility(View.VISIBLE);
|
||||||
|
hideLayouts();
|
||||||
setAchievements();
|
setAchievements();
|
||||||
|
setUploadCount();
|
||||||
initDrawer();
|
initDrawer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* to invoke the AlertDialog on clicking info button
|
||||||
|
*/
|
||||||
|
@OnClick(R.id.achievement_info)
|
||||||
|
public void showInfoDialog(){
|
||||||
|
new AlertDialog.Builder(AchievementsActivity.this)
|
||||||
|
.setTitle(R.string.Achievements)
|
||||||
|
.setMessage(R.string.achievements_info_message)
|
||||||
|
.setCancelable(true)
|
||||||
|
.setNeutralButton(android.R.string.ok, (dialog, id) -> dialog.cancel())
|
||||||
|
.create()
|
||||||
|
.show();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
// Inflate the menu; this adds items to the action bar if it is present.
|
// Inflate the menu; this adds items to the action bar if it is present.
|
||||||
|
|
@ -104,7 +164,7 @@ public class AchievementsActivity extends NavigationBaseActivity {
|
||||||
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 = Utils.getScreenShot(rootView);
|
Bitmap screenShot = Utils.getScreenShot(rootView);
|
||||||
shareScreen(screenShot);
|
showAlert(screenShot);
|
||||||
}
|
}
|
||||||
|
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
|
|
@ -147,13 +207,76 @@ public class AchievementsActivity extends NavigationBaseActivity {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* used to the count of images uploaded by user
|
||||||
|
*/
|
||||||
|
private void setUploadCount() {
|
||||||
|
compositeDisposable.add(mediaWikiApi
|
||||||
|
.getUploadCount(sessionManager.getCurrentAccount().name)
|
||||||
|
.subscribeOn(Schedulers.io())
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.subscribe(
|
||||||
|
uploadCount -> achievements.setImagesUploaded(uploadCount),
|
||||||
|
t -> Timber.e(t, "Fetching upload count failed")
|
||||||
|
));
|
||||||
|
isUploadFetched = true;
|
||||||
|
hideProgressBar();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* used to the uploaded images progressbar
|
||||||
|
* @param uploadCount
|
||||||
|
*/
|
||||||
|
private void setUploadProgress( int uploadCount){
|
||||||
|
|
||||||
|
imagesUploadedProgressbar.setProgress
|
||||||
|
(100*uploadCount/levelInfo.getMaxUploadCount());
|
||||||
|
imagesUploadedProgressbar.setProgressTextFormatPattern
|
||||||
|
(uploadCount +"/" + levelInfo.getMaxUploadCount() );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* used to parse the JSONObject containing results
|
* used to parse the JSONObject containing results
|
||||||
*
|
*
|
||||||
* @param object
|
* @param object
|
||||||
*/
|
*/
|
||||||
private void parseJson(JSONObject object) {
|
private void parseJson(JSONObject object) {
|
||||||
Log.i("json", object.toString());
|
try {
|
||||||
|
achievements.setUniqueUsedImages(object.getInt("uniqueUsedImages"));
|
||||||
|
achievements.setArticlesUsingImages(object.getInt("articlesUsingImages"));
|
||||||
|
achievements.setThanksReceived(object.getInt("thanksReceived"));
|
||||||
|
achievements.setImagesEditedBySomeoneElse(object.getInt("imagesEditedBySomeoneElse"));
|
||||||
|
JSONObject featuredImages = object.getJSONObject("featuredImages");
|
||||||
|
achievements.setFeaturedImages
|
||||||
|
(featuredImages.getInt("Quality_images") +
|
||||||
|
featuredImages.getInt("Featured_pictures_on_Wikimedia_Commons"));
|
||||||
|
} catch (JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
isStatisticsFetched = true;
|
||||||
|
hideProgressBar();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used the inflate the fetched statistics of the images uploaded by user
|
||||||
|
* and assign badge and level
|
||||||
|
* @param achievements
|
||||||
|
*/
|
||||||
|
private void inflateAchievements( Achievements achievements ){
|
||||||
|
thanksReceived.setText(Integer.toString(achievements.getThanksReceived()));
|
||||||
|
imagesUsedByWikiProgessbar.setProgress
|
||||||
|
(100*achievements.getUniqueUsedImages()/levelInfo.getMaxUniqueImages() );
|
||||||
|
imagesUsedByWikiProgessbar.setProgressTextFormatPattern
|
||||||
|
(achievements.getUniqueUsedImages() + "/" + levelInfo.getMaxUniqueImages());
|
||||||
|
imagesFeatured.setText(Integer.toString(achievements.getFeaturedImages()));
|
||||||
|
String levelUpInfoString = getString(R.string.level);
|
||||||
|
levelUpInfoString += " " + Integer.toString(levelInfo.getLevelNumber());
|
||||||
|
levelNumber.setText(levelUpInfoString);
|
||||||
|
final ContextThemeWrapper wrapper = new ContextThemeWrapper(this, levelInfo.getLevelStyle());
|
||||||
|
Drawable drawable = ResourcesCompat.getDrawable(getResources(), R.drawable.badge, wrapper.getTheme());
|
||||||
|
Bitmap bitmap = BitmapUtils.drawableToBitmap(drawable);
|
||||||
|
BitmapDrawable bitmapImage = BitmapUtils.writeOnDrawable(bitmap, Integer.toString(levelInfo.getLevelNumber()),this);
|
||||||
|
imageView.setImageDrawable(bitmapImage);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -168,4 +291,61 @@ public class AchievementsActivity extends NavigationBaseActivity {
|
||||||
context.startActivity(intent);
|
context.startActivity(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* to hide progressbar
|
||||||
|
*/
|
||||||
|
private void hideProgressBar() {
|
||||||
|
if (progressBar != null && isUploadFetched && isStatisticsFetched) {
|
||||||
|
levelInfo = LevelController.LevelInfo.from(achievements.getImagesUploaded(),achievements.getUniqueUsedImages());
|
||||||
|
inflateAchievements(achievements);
|
||||||
|
setUploadProgress(achievements.getImagesUploaded());
|
||||||
|
progressBar.setVisibility(View.GONE);
|
||||||
|
layoutImageReverts.setVisibility(View.VISIBLE);
|
||||||
|
layoutImageUploaded.setVisibility(View.VISIBLE);
|
||||||
|
layoutImageUsedByWiki.setVisibility(View.VISIBLE);
|
||||||
|
layoutStatistics.setVisibility(View.VISIBLE);
|
||||||
|
imageView.setVisibility(View.VISIBLE);
|
||||||
|
levelNumber.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* used to hide the layouts while fetching results from api
|
||||||
|
*/
|
||||||
|
private void hideLayouts(){
|
||||||
|
layoutImageUsedByWiki.setVisibility(View.INVISIBLE);
|
||||||
|
layoutImageUploaded.setVisibility(View.INVISIBLE);
|
||||||
|
layoutImageReverts.setVisibility(View.INVISIBLE);
|
||||||
|
layoutStatistics.setVisibility(View.INVISIBLE);
|
||||||
|
imageView.setVisibility(View.INVISIBLE);
|
||||||
|
levelNumber.setVisibility(View.INVISIBLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* It display the alertDialog with Image of screenshot
|
||||||
|
* @param screenshot
|
||||||
|
*/
|
||||||
|
public void showAlert(Bitmap screenshot){
|
||||||
|
AlertDialog.Builder alertadd = new AlertDialog.Builder(AchievementsActivity.this);
|
||||||
|
LayoutInflater factory = LayoutInflater.from(AchievementsActivity.this);
|
||||||
|
final View view = factory.inflate(R.layout.image_alert_layout, null);
|
||||||
|
ImageView screenShotImage = (ImageView) view.findViewById(R.id.alert_image);
|
||||||
|
screenShotImage.setImageBitmap(screenshot);
|
||||||
|
TextView shareMessage = (TextView) view.findViewById(R.id.alert_text);
|
||||||
|
shareMessage.setText(R.string.achievements_share_message);
|
||||||
|
alertadd.setView(view);
|
||||||
|
alertadd.setPositiveButton("Proceed", new DialogInterface.OnClickListener() {
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
shareScreen(screenshot);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
alertadd.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
dialog.cancel();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
alertadd.show();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,54 @@
|
||||||
|
package fr.free.nrw.commons.achievements;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.Canvas;
|
||||||
|
import android.graphics.Color;
|
||||||
|
import android.graphics.Paint;
|
||||||
|
import android.graphics.Rect;
|
||||||
|
import android.graphics.drawable.BitmapDrawable;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
|
|
||||||
|
public class BitmapUtils {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* write level Number on the badge
|
||||||
|
* @param bm
|
||||||
|
* @param text
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static BitmapDrawable writeOnDrawable(Bitmap bm, String text, Context context){
|
||||||
|
Bitmap.Config config = bm.getConfig();
|
||||||
|
if(config == null){
|
||||||
|
config = Bitmap.Config.ARGB_8888;
|
||||||
|
}
|
||||||
|
Bitmap bitmap = Bitmap.createBitmap(bm.getWidth(),bm.getHeight(),config);
|
||||||
|
Canvas canvas = new Canvas(bitmap);
|
||||||
|
canvas.drawBitmap(bm, 0, 0, null);
|
||||||
|
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||||
|
paint.setStyle(Paint.Style.FILL);
|
||||||
|
paint.setColor(Color.WHITE);
|
||||||
|
paint.setTextSize(Math.round(canvas.getHeight()/2));
|
||||||
|
paint.setTextAlign(Paint.Align.CENTER);
|
||||||
|
Rect rectText = new Rect();
|
||||||
|
paint.getTextBounds(text,0, text.length(),rectText);
|
||||||
|
canvas.drawText(text, Math.round(canvas.getWidth()/2),Math.round(canvas.getHeight()/1.35), paint);
|
||||||
|
return new BitmapDrawable(context.getResources(), bitmap);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert Drawable to bitmap
|
||||||
|
* @param drawable
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static Bitmap drawableToBitmap (Drawable drawable) {
|
||||||
|
if (drawable instanceof BitmapDrawable) {
|
||||||
|
return ((BitmapDrawable)drawable).getBitmap();
|
||||||
|
}
|
||||||
|
Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
|
||||||
|
Canvas canvas = new Canvas(bitmap);
|
||||||
|
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
|
||||||
|
drawable.draw(canvas);
|
||||||
|
return bitmap;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,73 @@
|
||||||
|
package fr.free.nrw.commons.achievements;
|
||||||
|
|
||||||
|
import fr.free.nrw.commons.R;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* calculates the level of the user
|
||||||
|
*/
|
||||||
|
public class LevelController {
|
||||||
|
|
||||||
|
public LevelInfo level;
|
||||||
|
public enum LevelInfo{
|
||||||
|
LEVEL_15(15,R.style.LevelFive, 80, 160),
|
||||||
|
LEVEL_14(14,R.style.LevelFour, 75 , 150),
|
||||||
|
LEVEL_13(13,R.style.LevelThree, 70, 140),
|
||||||
|
LEVEL_12(12,R.style.LevelTwo,65 , 130),
|
||||||
|
LEVEL_11(11,R.style.LevelOne, 60, 120),
|
||||||
|
LEVEL_10(10, R.style.LevelFive, 55, 110),
|
||||||
|
LEVEL_9(9, R.style.LevelFour, 50, 100),
|
||||||
|
LEVEL_8(8, R.style.LevelThree, 45, 90),
|
||||||
|
LEVEL_7(7, R.style.LevelTwo, 40, 80),
|
||||||
|
LEVEL_6(6,R.style.LevelOne,30,70),
|
||||||
|
LEVEL_5(5, R.style.LevelFive, 25, 60),
|
||||||
|
LEVEL_4(4, R.style.LevelFour,20,50),
|
||||||
|
LEVEL_3(3, R.style.LevelThree, 15,40),
|
||||||
|
LEVEL_2(2, R.style.LevelTwo, 10, 30),
|
||||||
|
LEVEL_1(1, R.style.LevelOne, 5, 20 );
|
||||||
|
|
||||||
|
private int levelNumber;
|
||||||
|
private int levelStyle;
|
||||||
|
private int maxUniqueImages;
|
||||||
|
private int maxUploadCount;
|
||||||
|
|
||||||
|
LevelInfo(int levelNumber, int levelStyle, int maxUniqueImages, int maxUploadCount) {
|
||||||
|
this.levelNumber = levelNumber;
|
||||||
|
this.levelStyle = levelStyle;
|
||||||
|
this.maxUniqueImages = maxUniqueImages;
|
||||||
|
this.maxUploadCount = maxUploadCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static LevelInfo from(int imagesUploaded, int uniqueImagesUsed) {
|
||||||
|
LevelInfo level = LEVEL_1;
|
||||||
|
|
||||||
|
for (LevelInfo levelInfo : LevelInfo.values()) {
|
||||||
|
if (imagesUploaded > levelInfo.maxUploadCount && uniqueImagesUsed > levelInfo.maxUniqueImages) {
|
||||||
|
level = levelInfo;
|
||||||
|
return level;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return level;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLevelStyle() {
|
||||||
|
return levelStyle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLevelNumber() {
|
||||||
|
return levelNumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLevelStyle(int levelStyle) {
|
||||||
|
this.levelStyle = levelStyle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMaxUniqueImages() {
|
||||||
|
return maxUniqueImages;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMaxUploadCount() {
|
||||||
|
return maxUploadCount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
33
app/src/main/res/drawable-mdpi/badge.xml
Normal file
33
app/src/main/res/drawable-mdpi/badge.xml
Normal file
File diff suppressed because one or more lines are too long
|
|
@ -71,18 +71,22 @@
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginLeft="@dimen/activity_margin_horizontal"
|
android:layout_marginLeft="@dimen/activity_margin_horizontal"
|
||||||
android:layout_marginStart="@dimen/activity_margin_horizontal"
|
android:layout_marginStart="@dimen/activity_margin_horizontal"
|
||||||
|
android:layout_marginTop="@dimen/achievements_activity_margin_vertical"
|
||||||
android:text="@string/images_uploaded" />
|
android:text="@string/images_uploaded" />
|
||||||
|
|
||||||
<com.dinuscxj.progressbar.CircleProgressBar
|
<com.dinuscxj.progressbar.CircleProgressBar
|
||||||
android:layout_width="35dp"
|
android:layout_width="40dp"
|
||||||
android:layout_height="35dp"
|
android:layout_height="40dp"
|
||||||
android:layout_alignParentRight="true"
|
android:layout_alignParentRight="true"
|
||||||
android:layout_marginRight="32dp"
|
android:layout_marginRight="32dp"
|
||||||
|
android:id="@+id/images_uploaded_progressbar"
|
||||||
android:progress="50"
|
android:progress="50"
|
||||||
|
app:progress_text_size="9dp"
|
||||||
app:progress_end_color="#8C8B98"
|
app:progress_end_color="#8C8B98"
|
||||||
app:progress_start_color="#3A3381"
|
app:progress_start_color="#3A3381"
|
||||||
app:progress_stroke_width="3dp"
|
app:progress_stroke_width="3dp"
|
||||||
app:progress_text_format_pattern="12/24"
|
app:progress_text_format_pattern="573/110"
|
||||||
|
app:progress_text_color="@color/secondaryColor"
|
||||||
app:style="solid_line" />
|
app:style="solid_line" />
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
@ -103,19 +107,32 @@
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginLeft="@dimen/activity_margin_horizontal"
|
android:layout_marginLeft="@dimen/activity_margin_horizontal"
|
||||||
|
android:id="@+id/images_reverted_text"
|
||||||
android:layout_marginStart="@dimen/activity_margin_horizontal"
|
android:layout_marginStart="@dimen/activity_margin_horizontal"
|
||||||
android:text="@string/image_reverts" />
|
android:text="@string/image_reverts" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="(minimum required: 90%)"
|
||||||
|
android:textSize="10dp"
|
||||||
|
android:layout_marginLeft="@dimen/activity_margin_horizontal"
|
||||||
|
android:layout_marginStart="@dimen/activity_margin_horizontal"
|
||||||
|
android:layout_below="@+id/images_reverted_text"/>
|
||||||
|
|
||||||
<com.dinuscxj.progressbar.CircleProgressBar
|
<com.dinuscxj.progressbar.CircleProgressBar
|
||||||
android:layout_width="35dp"
|
android:layout_width="40dp"
|
||||||
android:layout_height="35dp"
|
android:layout_height="40dp"
|
||||||
android:layout_alignParentRight="true"
|
android:layout_alignParentRight="true"
|
||||||
android:layout_marginRight="32dp"
|
android:layout_marginRight="32dp"
|
||||||
android:progress="50"
|
android:progress="50"
|
||||||
|
android:id="@+id/image_reverts_progressbar"
|
||||||
app:progress_end_color="#8C8B98"
|
app:progress_end_color="#8C8B98"
|
||||||
app:progress_start_color="#3A3381"
|
app:progress_start_color="#3A3381"
|
||||||
|
app:progress_text_size="9dp"
|
||||||
app:progress_stroke_width="3dp"
|
app:progress_stroke_width="3dp"
|
||||||
app:progress_text_format_pattern="12/24"
|
app:progress_text_format_pattern="92%%"
|
||||||
|
app:progress_text_color="@color/secondaryColor"
|
||||||
app:style="solid_line" />
|
app:style="solid_line" />
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
@ -138,26 +155,38 @@
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginLeft="@dimen/activity_margin_horizontal"
|
android:layout_marginLeft="@dimen/activity_margin_horizontal"
|
||||||
android:layout_marginStart="@dimen/activity_margin_horizontal"
|
android:layout_marginStart="@dimen/activity_margin_horizontal"
|
||||||
|
android:layout_marginTop="@dimen/achievements_activity_margin_vertical"
|
||||||
android:text="@string/images_used_by_wiki" />
|
android:text="@string/images_used_by_wiki" />
|
||||||
|
|
||||||
<com.dinuscxj.progressbar.CircleProgressBar
|
<com.dinuscxj.progressbar.CircleProgressBar
|
||||||
android:layout_width="35dp"
|
android:layout_width="40dp"
|
||||||
android:layout_height="35dp"
|
android:layout_height="40dp"
|
||||||
android:layout_alignParentRight="true"
|
android:layout_alignParentRight="true"
|
||||||
android:layout_marginRight="32dp"
|
android:layout_marginRight="32dp"
|
||||||
android:progress="50"
|
android:progress="50"
|
||||||
|
app:progress_text_size="9dp"
|
||||||
|
android:id="@+id/images_used_by_wiki_progressbar"
|
||||||
app:progress_end_color="#8C8B98"
|
app:progress_end_color="#8C8B98"
|
||||||
app:progress_start_color="#3A3381"
|
app:progress_start_color="#3A3381"
|
||||||
app:progress_stroke_width="2.5dp"
|
app:progress_stroke_width="2.5dp"
|
||||||
|
app:progress_text_color="@color/secondaryColor"
|
||||||
app:progress_text_format_pattern="12/24"
|
app:progress_text_format_pattern="12/24"
|
||||||
app:style="solid_line" />
|
app:style="solid_line" />
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
|
<ProgressBar
|
||||||
|
android:id="@+id/progressBar"
|
||||||
|
android:layout_centerVertical="true"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:id="@+id/layout_statistics"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
|
|
@ -202,6 +231,7 @@
|
||||||
android:layout_marginTop="@dimen/activity_margin_horizontal"
|
android:layout_marginTop="@dimen/activity_margin_horizontal"
|
||||||
android:layout_marginStart="@dimen/activity_margin_horizontal"
|
android:layout_marginStart="@dimen/activity_margin_horizontal"
|
||||||
android:text="2"
|
android:text="2"
|
||||||
|
android:id="@+id/image_featured"
|
||||||
android:layout_marginLeft="@dimen/activity_margin_horizontal"
|
android:layout_marginLeft="@dimen/activity_margin_horizontal"
|
||||||
android:layout_marginRight="44dp" />
|
android:layout_marginRight="44dp" />
|
||||||
|
|
||||||
|
|
@ -242,6 +272,7 @@
|
||||||
android:layout_marginStart="@dimen/activity_margin_horizontal"
|
android:layout_marginStart="@dimen/activity_margin_horizontal"
|
||||||
android:layout_marginLeft="@dimen/activity_margin_horizontal"
|
android:layout_marginLeft="@dimen/activity_margin_horizontal"
|
||||||
android:text="2"
|
android:text="2"
|
||||||
|
android:id="@+id/thanks_received"
|
||||||
android:layout_marginRight="44dp" />
|
android:layout_marginRight="44dp" />
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
|
||||||
21
app/src/main/res/layout/image_alert_layout.xml
Normal file
21
app/src/main/res/layout/image_alert_layout.xml
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:gravity="center">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:layout_margin="@dimen/activity_margin_horizontal"
|
||||||
|
android:layout_width="140dp"
|
||||||
|
android:layout_height="200dp"
|
||||||
|
android:id="@+id/alert_image" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:id="@+id/alert_text"
|
||||||
|
android:layout_marginRight="@dimen/activity_margin_horizontal"
|
||||||
|
android:layout_marginLeft="@dimen/activity_margin_horizontal"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
@ -23,4 +23,10 @@
|
||||||
<attr name="drawableEnd" format="reference"/>
|
<attr name="drawableEnd" format="reference"/>
|
||||||
<attr name="drawableBottom" format="reference"/>
|
<attr name="drawableBottom" format="reference"/>
|
||||||
</declare-styleable>
|
</declare-styleable>
|
||||||
|
|
||||||
|
<declare-styleable name="Badge">
|
||||||
|
<attr name="boundary" format="color"/>
|
||||||
|
<attr name="camera" format="color"/>
|
||||||
|
<attr name="centerRegion" format="color"/>
|
||||||
|
</declare-styleable>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
<!-- Standard margin / padding for the containing activity -->
|
<!-- Standard margin / padding for the containing activity -->
|
||||||
<dimen name="activity_margin_horizontal">16dp</dimen>
|
<dimen name="activity_margin_horizontal">16dp</dimen>
|
||||||
<dimen name="activity_margin_vertical">16dp</dimen>
|
<dimen name="activity_margin_vertical">16dp</dimen>
|
||||||
|
<dimen name="achievements_activity_margin_vertical">8dp</dimen>
|
||||||
|
|
||||||
<!-- Standard margins / padding -->
|
<!-- Standard margins / padding -->
|
||||||
<dimen name="huge_gap">48dp</dimen>
|
<dimen name="huge_gap">48dp</dimen>
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<resources>
|
||||||
<string name="preference_category_appearance">Appearance</string
|
<string name="preference_category_appearance">Appearance</string>
|
||||||
<string name="preference_category_general">General</string>
|
<string name="preference_category_general">General</string>
|
||||||
<string name="preference_category_feedback">Feedback</string>
|
<string name="preference_category_feedback">Feedback</string>
|
||||||
<string name="preference_category_location">Location</string>
|
<string name="preference_category_location">Location</string>
|
||||||
|
|
@ -292,4 +292,6 @@
|
||||||
<string name="images_uploaded">Images Uploaded</string>
|
<string name="images_uploaded">Images Uploaded</string>
|
||||||
<string name="image_reverts">Images Not Reverted</string>
|
<string name="image_reverts">Images Not Reverted</string>
|
||||||
<string name="images_used_by_wiki">Images Used By Wiki</string>
|
<string name="images_used_by_wiki">Images Used By Wiki</string>
|
||||||
|
<string name="achievements_share_message">Share your achievements with your friends!</string>
|
||||||
|
<string name="achievements_info_message">Your level increases as you meet these requirements. Items in the "statistics" section do not count towards your level.</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
||||||
|
|
@ -57,4 +57,34 @@
|
||||||
<item name="android:background">@android:color/transparent</item>
|
<item name="android:background">@android:color/transparent</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
<style name="LevelOne">
|
||||||
|
<item name="boundary">#ddb4aa</item>
|
||||||
|
<item name="camera">#ae403a</item>
|
||||||
|
<item name="centerRegion">#bc6853</item>
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<style name="LevelTwo">
|
||||||
|
<item name="boundary">#a8a8c0</item>
|
||||||
|
<item name="camera">#604890</item>
|
||||||
|
<item name="centerRegion">#6060a8</item>
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<style name="LevelThree">
|
||||||
|
<item name="boundary">#90c0a8</item>
|
||||||
|
<item name="camera">#487878</item>
|
||||||
|
<item name="centerRegion">#48a8a8</item>
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<style name="LevelFour">
|
||||||
|
<item name="boundary">#ffc078</item>
|
||||||
|
<item name="camera">#d87818</item>
|
||||||
|
<item name="centerRegion">#f09018</item>
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<style name="LevelFive">
|
||||||
|
<item name="boundary">#c0a8c0</item>
|
||||||
|
<item name="camera">#784878</item>
|
||||||
|
<item name="centerRegion">#906078</item>
|
||||||
|
</style>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue