Skip to content

Commit 1aabc3f

Browse files
author
Vivek Maskara
authored
Merge pull request commons-app#1524 from tanvidadu/feedback
Feedback on how my pictures get used [WIP}
2 parents e028658 + dbd2051 commit 1aabc3f

16 files changed

+1647
-26
lines changed

app/build.gradle

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ dependencies {
2121
implementation 'info.debatty:java-string-similarity:0.24'
2222
implementation 'com.borjabravo:readmoretextview:2.1.0'
2323
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
24-
implementation ('com.mapbox.mapboxsdk:mapbox-android-sdk:5.4.1@aar'){
25-
transitive=true
24+
implementation('com.mapbox.mapboxsdk:mapbox-android-sdk:5.4.1@aar') {
25+
transitive = true
2626
}
2727

2828
implementation "com.github.deano2390:MaterialShowcaseView:1.2.0"
@@ -68,6 +68,7 @@ dependencies {
6868
testImplementation 'org.robolectric:robolectric:3.7.1'
6969
testImplementation 'com.nhaarman:mockito-kotlin:1.5.0'
7070
testImplementation 'com.squareup.okhttp3:mockwebserver:3.8.1'
71+
compile 'com.dinuscxj:circleprogressbar:1.1.1'
7172

7273
androidTestImplementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
7374
androidTestImplementation 'com.squareup.okhttp3:mockwebserver:3.8.1'
@@ -116,7 +117,8 @@ android {
116117

117118
buildTypes {
118119
release {
119-
minifyEnabled false // See https://stackoverflow.com/questions/40232404/google-play-apk-and-android-studio-apk-usb-debug-behaving-differently - proguard.cfg modification alone insufficient.
120+
minifyEnabled false
121+
// See https://stackoverflow.com/questions/40232404/google-play-apk-and-android-studio-apk-usb-debug-behaving-differently - proguard.cfg modification alone insufficient.
120122
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
121123
}
122124
debug {

app/src/main/AndroidManifest.xml

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
12
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
23
package="fr.free.nrw.commons">
34

@@ -14,7 +15,7 @@
1415
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />
1516
<uses-permission android:name="android.permission.MANAGE_DOCUMENTS" />
1617
<uses-permission android:name="com.google.android.apps.photos.permission.GOOGLE_PHOTOS" />
17-
<uses-permission android:name="android.permission.READ_LOGS"/>
18+
<uses-permission android:name="android.permission.READ_LOGS" />
1819

1920
<!-- Needed only if your app targets Android 5.0 (API level 21) or higher. -->
2021
<uses-feature android:name="android.hardware.location.gps" />
@@ -23,17 +24,18 @@
2324
android:name=".CommonsApplication"
2425
android:icon="@drawable/ic_launcher"
2526
android:label="@string/app_name"
26-
android:theme="@style/LightAppTheme"
27-
android:supportsRtl="true" >
28-
<activity android:name="org.acra.CrashReportDialog"
29-
android:theme="@android:style/Theme.Dialog"
30-
android:launchMode="singleInstance"
31-
android:excludeFromRecents="true"
32-
android:finishOnTaskLaunch="true" />
33-
27+
android:supportsRtl="true"
28+
android:theme="@style/LightAppTheme">
29+
<activity
30+
android:name="org.acra.CrashReportDialog"
31+
android:excludeFromRecents="true"
32+
android:finishOnTaskLaunch="true"
33+
android:launchMode="singleInstance"
34+
android:theme="@android:style/Theme.Dialog" />
3435
<activity android:name=".auth.LoginActivity">
3536
<intent-filter>
3637
<category android:name="android.intent.category.LAUNCHER" />
38+
3739
<action android:name="android.intent.action.MAIN" />
3840
</intent-filter>
3941
</activity>
@@ -46,7 +48,9 @@
4648
android:label="@string/app_name">
4749
<intent-filter>
4850
<action android:name="android.intent.action.SEND" />
51+
4952
<category android:name="android.intent.category.DEFAULT" />
53+
5054
<data android:mimeType="image/*" />
5155
<data android:mimeType="audio/ogg" />
5256
</intent-filter>
@@ -58,7 +62,9 @@
5862
android:label="@string/app_name">
5963
<intent-filter>
6064
<action android:name="android.intent.action.SEND_MULTIPLE" />
65+
6166
<category android:name="android.intent.category.DEFAULT" />
67+
6268
<data android:mimeType="image/*" />
6369
<data android:mimeType="audio/ogg" />
6470
</intent-filter>
@@ -96,8 +102,12 @@
96102
android:label="@string/title_activity_featured_images"
97103
android:parentActivityName=".contributions.ContributionsActivity" />
98104

99-
<service android:name=".upload.UploadService" />
105+
<activity
106+
android:name=".achievements.AchievementsActivity"
107+
android:label="@string/Achievements" />
108+
100109

110+
<service android:name=".upload.UploadService" />
101111
<service
102112
android:name=".auth.WikiAccountAuthenticatorService"
103113
android:exported="true"
@@ -117,6 +127,7 @@
117127
<intent-filter>
118128
<action android:name="android.content.SyncAdapter" />
119129
</intent-filter>
130+
120131
<meta-data
121132
android:name="android.content.SyncAdapter"
122133
android:resource="@xml/contributions_sync_adapter" />
@@ -128,6 +139,7 @@
128139
<intent-filter>
129140
<action android:name="android.content.SyncAdapter" />
130141
</intent-filter>
142+
131143
<meta-data
132144
android:name="android.content.SyncAdapter"
133145
android:resource="@xml/modifications_sync_adapter" />
@@ -166,4 +178,4 @@
166178

167179
</application>
168180

169-
</manifest>
181+
</manifest>

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

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22

33
import android.content.Context;
44
import android.content.Intent;
5+
import android.graphics.Bitmap;
56
import android.net.Uri;
67
import android.preference.PreferenceManager;
78
import android.support.annotation.NonNull;
89
import android.support.customtabs.CustomTabsIntent;
910
import android.support.v4.content.ContextCompat;
11+
import android.view.View;
1012
import android.widget.Toast;
1113

1214
import org.apache.commons.codec.binary.Hex;
@@ -106,7 +108,7 @@ public static int licenseNameFor(String license) {
106108

107109
/**
108110
* Fixing incorrect extension
109-
* @param title File name
111+
* @param title File name
110112
* @param extension Correct extension
111113
* @return File with correct extension
112114
*/
@@ -146,7 +148,7 @@ public static String getAppLogs() {
146148
StringBuilder stringBuilder = new StringBuilder();
147149

148150
try {
149-
String[] command = new String[] {"logcat","-d","-v","threadtime"};
151+
String[] command = new String[]{"logcat", "-d", "-v", "threadtime"};
150152

151153
Process process = Runtime.getRuntime().exec(command);
152154

@@ -171,8 +173,7 @@ public static void rateApp(Context context) {
171173
final String appPackageName = BuildConfig.class.getPackage().getName();
172174
try {
173175
context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)));
174-
}
175-
catch (android.content.ActivityNotFoundException anfe) {
176+
} catch (android.content.ActivityNotFoundException anfe) {
176177
context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName)));
177178
}
178179
}
@@ -194,4 +195,18 @@ public static void handleWebUrl(Context context, Uri url) {
194195
customTabsIntent.launchUrl(context, url);
195196
}
196197

198+
/**
199+
* To take screenshot of the screen and return it in Bitmap format
200+
*
201+
* @param view
202+
* @return
203+
*/
204+
public static Bitmap getScreenShot(View view) {
205+
View screenView = view.getRootView();
206+
screenView.setDrawingCacheEnabled(true);
207+
Bitmap bitmap = Bitmap.createBitmap(screenView.getDrawingCache());
208+
screenView.setDrawingCacheEnabled(false);
209+
return bitmap;
210+
}
211+
197212
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package fr.free.nrw.commons.achievements;
2+
3+
public class Achievements {
4+
5+
}
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
package fr.free.nrw.commons.achievements;
2+
3+
import android.annotation.SuppressLint;
4+
import android.content.Context;
5+
import android.content.Intent;
6+
import android.graphics.Bitmap;
7+
import android.net.Uri;
8+
import android.os.Bundle;
9+
import android.support.v7.widget.Toolbar;
10+
import android.util.DisplayMetrics;
11+
import android.util.Log;
12+
import android.view.Menu;
13+
import android.view.MenuItem;
14+
import android.view.View;
15+
import android.widget.ImageView;
16+
import android.widget.RelativeLayout;
17+
import android.widget.TextView;
18+
19+
import org.json.JSONObject;
20+
21+
import java.io.File;
22+
import java.io.FileOutputStream;
23+
import java.io.IOException;
24+
25+
import javax.inject.Inject;
26+
27+
import butterknife.BindView;
28+
import butterknife.ButterKnife;
29+
import fr.free.nrw.commons.R;
30+
import fr.free.nrw.commons.Utils;
31+
import fr.free.nrw.commons.auth.SessionManager;
32+
import fr.free.nrw.commons.mwapi.MediaWikiApi;
33+
import fr.free.nrw.commons.theme.NavigationBaseActivity;
34+
import io.reactivex.android.schedulers.AndroidSchedulers;
35+
import io.reactivex.disposables.CompositeDisposable;
36+
import io.reactivex.schedulers.Schedulers;
37+
38+
/**
39+
* activity for sharing feedback on uploaded activity
40+
*/
41+
public class AchievementsActivity extends NavigationBaseActivity {
42+
43+
private static final double BADGE_IMAGE_WIDTH_RATIO = 0.4;
44+
private static final double BADGE_IMAGE_HEIGHT_RATIO = 0.3;
45+
46+
@BindView(R.id.achievement_badge)
47+
ImageView imageView;
48+
@BindView(R.id.achievement_level)
49+
TextView textView;
50+
@BindView(R.id.toolbar)
51+
Toolbar toolbar;
52+
@Inject
53+
SessionManager sessionManager;
54+
@Inject
55+
MediaWikiApi mediaWikiApi;
56+
57+
private CompositeDisposable compositeDisposable = new CompositeDisposable();
58+
59+
/**
60+
* This method helps in the creation Achievement screen and
61+
* dynamically set the size of imageView
62+
*
63+
* @param savedInstanceState Data bundle
64+
*/
65+
@Override
66+
@SuppressLint("StringFormatInvalid")
67+
protected void onCreate(Bundle savedInstanceState) {
68+
super.onCreate(savedInstanceState);
69+
setContentView(R.layout.activity_achievements);
70+
ButterKnife.bind(this);
71+
/**
72+
* DisplayMetrics used to fetch the size of the screen
73+
*/
74+
DisplayMetrics displayMetrics = new DisplayMetrics();
75+
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
76+
int height = displayMetrics.heightPixels;
77+
int width = displayMetrics.widthPixels;
78+
79+
/**
80+
* Used for the setting the size of imageView at runtime
81+
*/
82+
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams)
83+
imageView.getLayoutParams();
84+
params.height = (int) (height * BADGE_IMAGE_HEIGHT_RATIO);
85+
params.width = (int) (width * BADGE_IMAGE_WIDTH_RATIO);
86+
imageView.setImageResource(R.drawable.featured);
87+
imageView.requestLayout();
88+
89+
setSupportActionBar(toolbar);
90+
setAchievements();
91+
initDrawer();
92+
}
93+
94+
@Override
95+
public boolean onCreateOptionsMenu(Menu menu) {
96+
// Inflate the menu; this adds items to the action bar if it is present.
97+
getMenuInflater().inflate(R.menu.menu_about, menu);
98+
return true;
99+
}
100+
101+
@Override
102+
public boolean onOptionsItemSelected(MenuItem item) {
103+
int id = item.getItemId();
104+
if (id == R.id.share_app_icon) {
105+
View rootView = getWindow().getDecorView().findViewById(android.R.id.content);
106+
Bitmap screenShot = Utils.getScreenShot(rootView);
107+
shareScreen(screenShot);
108+
}
109+
110+
return super.onOptionsItemSelected(item);
111+
}
112+
113+
/**
114+
* To take bitmap and store it temporary storage and share it
115+
*
116+
* @param bitmap
117+
*/
118+
void shareScreen(Bitmap bitmap) {
119+
try {
120+
File file = new File(this.getExternalCacheDir(), "screen.png");
121+
FileOutputStream fOut = new FileOutputStream(file);
122+
bitmap.compress(Bitmap.CompressFormat.PNG, 100, fOut);
123+
fOut.flush();
124+
fOut.close();
125+
file.setReadable(true, false);
126+
final Intent intent = new Intent(android.content.Intent.ACTION_SEND);
127+
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
128+
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
129+
intent.setType("image/png");
130+
startActivity(Intent.createChooser(intent, "Share image via"));
131+
} catch (IOException e) {
132+
//Do Nothing
133+
}
134+
}
135+
136+
/**
137+
* To call the API to get results in form Single<JSONObject>
138+
* which then calls parseJson when results are fetched
139+
*/
140+
private void setAchievements() {
141+
compositeDisposable.add(mediaWikiApi
142+
.getAchievements(sessionManager.getCurrentAccount().name)
143+
.subscribeOn(Schedulers.io())
144+
.observeOn(AndroidSchedulers.mainThread())
145+
.subscribe(
146+
jsonObject -> parseJson(jsonObject)
147+
));
148+
}
149+
150+
/**
151+
* used to parse the JSONObject containing results
152+
*
153+
* @param object
154+
*/
155+
private void parseJson(JSONObject object) {
156+
Log.i("json", object.toString());
157+
}
158+
159+
/**
160+
* Creates a way to change current activity to AchievementActivity
161+
*
162+
* @param context
163+
*/
164+
public static void startYourself(Context context) {
165+
Intent intent = new Intent(context, AchievementsActivity.class);
166+
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
167+
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
168+
context.startActivity(intent);
169+
}
170+
171+
}

app/src/main/java/fr/free/nrw/commons/di/ActivityBuilderModule.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
import dagger.android.ContributesAndroidInjector;
55
import fr.free.nrw.commons.AboutActivity;
66
import fr.free.nrw.commons.WelcomeActivity;
7+
import fr.free.nrw.commons.achievements.AchievementsActivity;
78
import fr.free.nrw.commons.auth.LoginActivity;
89
import fr.free.nrw.commons.auth.SignupActivity;
9-
import fr.free.nrw.commons.contributions.ContributionsActivity;
1010
import fr.free.nrw.commons.category.CategoryImagesActivity;
11+
import fr.free.nrw.commons.contributions.ContributionsActivity;
1112
import fr.free.nrw.commons.nearby.NearbyActivity;
1213
import fr.free.nrw.commons.notification.NotificationActivity;
1314
import fr.free.nrw.commons.settings.SettingsActivity;
@@ -50,4 +51,7 @@ public abstract class ActivityBuilderModule {
5051

5152
@ContributesAndroidInjector
5253
abstract CategoryImagesActivity bindFeaturedImagesActivity();
54+
55+
@ContributesAndroidInjector
56+
abstract AchievementsActivity bindAchievementsActivity();
5357
}

0 commit comments

Comments
 (0)