Skip to content

Commit c6352a3

Browse files
author
nextLane
committed
Merged, Resolve merge conflicts
2 parents 0de8c44 + 639908a commit c6352a3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+284
-75
lines changed

.travis.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ android:
33
components:
44
- platform-tools
55
- tools
6-
- build-tools-25.0.0
6+
- build-tools-25.0.1
77
- extra-google-m2repository
88
- extra-android-m2repository
9-
- android-23
9+
- android-25
1010
- sys-img-x86-android-18
1111
jdk:
1212
# - openjdk8 # not yet available

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Wikimedia Commons for Android
22

3+
##v2.0.2
4+
- Make "View in browser" direct to mobile website
5+
36
##v2.0.1
47
- Disabled minify again (reenabling test failed)
58
- Hotfix for ShareAction bug

README.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
# Wikimedia Commons Android app
1+
# Wikimedia Commons Android app [![Build status](https://api.travis-ci.org/commons-app/apps-android-commons.svg)](https://travis-ci.org/commons-app/apps-android-commons)
22

33
The Wikimedia Commons Android app allows users to upload pictures from their Android phone/tablet to Wikimedia Commons. Download the app [here][8], or view our [website][9].
44

55
Initially started by the Wikimedia Foundation, this app is now maintained by volunteers. Anyone is welcome to improve it, just choose among the [open issues](https://github.com/commons-app/apps-android-commons/issues) and send us a pull request :-)
66

7-
[![Build status](https://api.travis-ci.org/commons-app/apps-android-commons.svg)](https://travis-ci.org/commons-app/apps-android-commons)
7+
<a href="https://f-droid.org/repository/browse/?fdid=fr.free.nrw.commons" target="_blank">
8+
<img src="https://f-droid.org/badge/get-it-on.png" alt="Get it on F-Droid" height="90"/></a>
9+
<a href="https://play.google.com/store/apps/details?id=fr.free.nrw.commons" target="_blank">
10+
<img src="https://play.google.com/intl/en_us/badges/images/generic/en-play-badge.png" alt="Get it on Google Play" height="90"/></a>
811

912
## Develop with Android Studio or IntelliJ ##
1013

app/build.gradle

+11-17
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,24 @@ dependencies {
1212
compile 'ch.acra:acra:4.7.0'
1313
compile 'org.mediawiki:api:1.3'
1414
compile 'commons-codec:commons-codec:1.10'
15-
compile 'com.android.support:support-v4:25.0.0'
16-
compile 'com.android.support:appcompat-v7:25.0.0'
17-
compile 'com.android.support:design:25.0.0'
15+
compile "com.android.support:support-v4:${project.supportLibVersion}"
16+
compile "com.android.support:appcompat-v7:${project.supportLibVersion}"
17+
compile "com.android.support:design:${project.supportLibVersion}"
18+
compile 'com.google.code.gson:gson:2.7'
1819

1920
testCompile 'junit:junit:4.12'
20-
21-
//noinspection GradleDependency - old version has required feature
22-
compile 'com.google.code.gson:gson:1.4'
2321
}
2422

2523
android {
26-
compileSdkVersion 23
27-
buildToolsVersion '25'
24+
compileSdkVersion project.compileSdkVersion
25+
buildToolsVersion project.buildToolsVersion
2826

29-
useLibrary 'org.apache.http.legacy'
27+
useLibrary 'org.apache.http.legacy'
3028

3129
defaultConfig {
32-
applicationId "fr.free.nrw.commons"
33-
minSdkVersion 15
34-
targetSdkVersion 23
35-
36-
ndk {
37-
moduleName "libtranscode"
38-
}
30+
applicationId 'fr.free.nrw.commons'
31+
minSdkVersion project.minSdkVersion
32+
targetSdkVersion project.targetSdkVersion
3933
}
4034

4135
buildTypes {
@@ -50,4 +44,4 @@ android {
5044
disable 'ExtraTranslation'
5145
abortOnError false
5246
}
53-
}
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<string name="placeholder_place_distance">Overlay</string>
4+
<string name="placeholder_place_name">Name</string>
5+
<string name="placeholder_place_description">Description</string>
6+
</resources>

app/src/main/AndroidManifest.xml

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
xmlns:tools="http://schemas.android.com/tools"
23
package="fr.free.nrw.commons"
3-
android:versionCode="64"
4-
android:versionName="2.0.1" >
4+
android:versionCode="65"
5+
android:versionName="2.0.2" >
56

67
<uses-permission android:name="android.permission.INTERNET" />
78
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
@@ -85,7 +86,7 @@
8586
<activity
8687
android:name=".nearby.NearbyActivity"
8788
android:label="@string/title_activity_nearby"
88-
android:parentActivityName=".contributions.ContributionsActivity"/>
89+
android:parentActivityName=".contributions.ContributionsActivity" />
8990

9091
<service android:name=".upload.UploadService" >
9192
</service>

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

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public class CommonsApplication extends Application {
5959
public static final String API_URL = "https://commons.wikimedia.org/w/api.php";
6060
public static final String IMAGE_URL_BASE = "https://upload.wikimedia.org/wikipedia/commons";
6161
public static final String HOME_URL = "https://commons.wikimedia.org/wiki/";
62+
public static final String MOBILE_HOME_URL = "https://commons.m.wikimedia.org/wiki/";
6263
public static final String EVENTLOG_URL = "https://www.wikimedia.org/beacon/event";
6364
public static final String EVENTLOG_WIKI = "commonswiki";
6465

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import java.util.Collection;
99
import java.util.HashMap;
10+
import java.util.Locale;
1011
import java.util.Map;
1112
import java.util.Set;
1213

@@ -54,7 +55,7 @@ public License licenseForTemplate(String template) {
5455
public String nameIdForTemplate(String template) {
5556
// hack :D (converts dashes and periods to underscores)
5657
// cc-by-sa-3.0 -> cc_by_sa_3_0
57-
return "license_name_" + template.toLowerCase().replace("-", "_").replace(".", "_");
58+
return "license_name_" + template.toLowerCase(Locale.ENGLISH).replace("-", "_").replace(".", "_");
5859
}
5960

6061
private int stringIdByName(String stringId) {

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

+4
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ public String getDescriptionUrl() {
6161
return CommonsApplication.HOME_URL + "File:" + Utils.urlEncode(getFilename().replace("File:", "").replace(" ", "_"));
6262
}
6363

64+
public String getMobileDescriptionUrl() {
65+
return CommonsApplication.MOBILE_HOME_URL + "File:" + Utils.urlEncode(getFilename().replace("File:", "").replace(" ", "_"));
66+
}
67+
6468
public Uri getLocalUri() {
6569
return localUri;
6670
}

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

+10-5
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.text.ParseException;
2828
import java.text.SimpleDateFormat;
2929
import java.util.Date;
30+
import java.util.Locale;
3031
import java.util.TimeZone;
3132
import java.util.concurrent.Executor;
3233
import java.util.regex.Pattern;
@@ -81,7 +82,7 @@ public static String getSHA1(InputStream is) {
8182
}
8283

8384
public static Date parseMWDate(String mwDate) {
84-
SimpleDateFormat isoFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); // Assuming MW always gives me UTC
85+
SimpleDateFormat isoFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.ENGLISH); // Assuming MW always gives me UTC
8586
try {
8687
return isoFormat.parse(mwDate);
8788
} catch (ParseException e) {
@@ -90,7 +91,7 @@ public static Date parseMWDate(String mwDate) {
9091
}
9192

9293
public static String toMWDate(Date date) {
93-
SimpleDateFormat isoFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); // Assuming MW always gives me UTC
94+
SimpleDateFormat isoFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.ENGLISH); // Assuming MW always gives me UTC
9495
isoFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
9596
return isoFormat.format(date);
9697
}
@@ -201,7 +202,7 @@ public static String makeThumbUrl(String imageUrl, String filename, int width) {
201202
}
202203

203204
public static String capitalize(String string) {
204-
return string.substring(0,1).toUpperCase() + string.substring(1);
205+
return string.substring(0,1).toUpperCase(Locale.getDefault()) + string.substring(1);
205206
}
206207

207208
public static String licenseTemplateFor(String license) {
@@ -303,13 +304,17 @@ public static String fixExtension(String title, String extension) {
303304
Pattern jpegPattern = Pattern.compile("\\.jpeg$", Pattern.CASE_INSENSITIVE);
304305

305306
// People are used to ".jpg" more than ".jpeg" which the system gives us.
306-
if (extension != null && extension.toLowerCase().equals("jpeg")) {
307+
if (extension != null && extension.toLowerCase(Locale.ENGLISH).equals("jpeg")) {
307308
extension = "jpg";
308309
}
309310
title = jpegPattern.matcher(title).replaceFirst(".jpg");
310-
if (extension != null && !title.toLowerCase().endsWith("." + extension.toLowerCase())) {
311+
if (extension != null && !title.toLowerCase(Locale.getDefault()).endsWith("." + extension.toLowerCase(Locale.ENGLISH))) {
311312
title += "." + extension;
312313
}
313314
return title;
314315
}
316+
317+
public static boolean isNullOrWhiteSpace(String value) {
318+
return value == null || value.trim().isEmpty();
319+
}
315320
}

app/src/main/java/fr/free/nrw/commons/auth/AuthenticatedActivity.java

+27-10
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
package fr.free.nrw.commons.auth;
22

3+
import android.Manifest;
34
import android.accounts.Account;
45
import android.accounts.AccountManager;
56
import android.accounts.AccountManagerFuture;
67
import android.accounts.AuthenticatorException;
78
import android.accounts.OperationCanceledException;
9+
import android.content.pm.PackageManager;
810
import android.os.AsyncTask;
911
import android.os.Bundle;
12+
import android.support.annotation.Nullable;
13+
import android.support.v4.app.ActivityCompat;
1014
import android.support.v7.app.AppCompatActivity;
1115

1216
import java.io.IOException;
@@ -20,23 +24,24 @@ public abstract class AuthenticatedActivity extends AppCompatActivity {
2024
CommonsApplication app;
2125

2226
private String authCookie;
23-
27+
2428
public AuthenticatedActivity(String accountType) {
25-
this.accountType = accountType;
29+
this.accountType = accountType;
2630
}
27-
31+
2832
private class GetAuthCookieTask extends AsyncTask<Void, String, String> {
2933
private Account account;
3034
private AccountManager accountManager;
35+
3136
public GetAuthCookieTask(Account account, AccountManager accountManager) {
3237
this.account = account;
3338
this.accountManager = accountManager;
3439
}
35-
40+
3641
@Override
3742
protected void onPostExecute(String result) {
3843
super.onPostExecute(result);
39-
if(result != null) {
44+
if (result != null) {
4045
authCookie = result;
4146
onAuthCookieAcquired(result);
4247
} else {
@@ -60,26 +65,38 @@ protected String doInBackground(Void... params) {
6065
}
6166
}
6267
}
63-
68+
6469
private class AddAccountTask extends AsyncTask<Void, String, String> {
6570
private AccountManager accountManager;
71+
6672
public AddAccountTask(AccountManager accountManager) {
6773
this.accountManager = accountManager;
6874
}
69-
75+
7076
@Override
7177
protected void onPostExecute(String result) {
7278
super.onPostExecute(result);
73-
if(result != null) {
74-
Account[] allAccounts =accountManager.getAccountsByType(accountType);
75-
Account curAccount = allAccounts[0];
79+
if (result != null) {
80+
Account curAccount = getCurrentAccount();
7681
GetAuthCookieTask getCookieTask = new GetAuthCookieTask(curAccount, accountManager);
7782
getCookieTask.execute();
7883
} else {
7984
onAuthFailure();
8085
}
8186
}
8287

88+
@Nullable
89+
private Account getCurrentAccount() {
90+
if (ActivityCompat.checkSelfPermission(AuthenticatedActivity.this, Manifest.permission.GET_ACCOUNTS) != PackageManager.PERMISSION_GRANTED) {
91+
return null;
92+
}
93+
Account[] allAccounts = accountManager.getAccountsByType(accountType);
94+
if (allAccounts == null) {
95+
return null;
96+
}
97+
return allAccounts[0];
98+
}
99+
83100
@Override
84101
protected String doInBackground(Void... params) {
85102
AccountManagerFuture<Bundle> resultFuture = accountManager.addAccount(accountType, null, null, null, AuthenticatedActivity.this, null, null);

app/src/main/java/fr/free/nrw/commons/auth/LoginActivity.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@
2626
import android.widget.Toast;
2727

2828
import java.io.IOException;
29+
import java.util.Locale;
2930

3031
import fr.free.nrw.commons.CommonsApplication;
3132
import fr.free.nrw.commons.EventLog;
3233
import fr.free.nrw.commons.R;
34+
import fr.free.nrw.commons.Utils;
3335
import fr.free.nrw.commons.WelcomeActivity;
3436
import fr.free.nrw.commons.contributions.ContributionsActivity;
3537
import fr.free.nrw.commons.contributions.ContributionsContentProvider;
@@ -220,7 +222,7 @@ protected void onResume() {
220222
private void performLogin() {
221223
String username = usernameEdit.getText().toString();
222224
// Because Mediawiki is upercase-first-char-then-case-sensitive :)
223-
String canonicalUsername = username.substring(0,1).toUpperCase() + username.substring(1);
225+
String canonicalUsername = Utils.capitalize(username.substring(0,1)) + username.substring(1);
224226

225227
String password = passwordEdit.getText().toString();
226228

app/src/main/java/fr/free/nrw/commons/contributions/Contribution.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import java.text.SimpleDateFormat;
1313
import java.util.Date;
14+
import java.util.Locale;
1415

1516
import fr.free.nrw.commons.CommonsApplication;
1617
import fr.free.nrw.commons.EventLog;
@@ -131,7 +132,7 @@ public String getTrackingTemplates() {
131132

132133
public String getPageContents() {
133134
StringBuffer buffer = new StringBuffer();
134-
SimpleDateFormat isoFormat = new SimpleDateFormat("yyyy-MM-dd");
135+
SimpleDateFormat isoFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH);
135136

136137
buffer
137138
.append("== {{int:filedesc}} ==\n")

app/src/main/java/fr/free/nrw/commons/media/MediaDetailPagerFragment.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
143143
// View in browser
144144
Intent viewIntent = new Intent();
145145
viewIntent.setAction(Intent.ACTION_VIEW);
146-
viewIntent.setData(Uri.parse(m.getDescriptionUrl()));
146+
viewIntent.setData(Uri.parse(m.getMobileDescriptionUrl()));
147147
startActivity(viewIntent);
148148
return true;
149149
case R.id.menu_download_current_image:

app/src/main/java/fr/free/nrw/commons/modifications/ModificationsSyncAdapter.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,16 @@ public void onPerformSync(Account account, Bundle bundle, String s, ContentProvi
4949
String authCookie;
5050
try {
5151
authCookie = AccountManager.get(getContext()).blockingGetAuthToken(account, "", false);
52-
} catch (OperationCanceledException e) {
52+
} catch (OperationCanceledException | AuthenticatorException e) {
5353
throw new RuntimeException(e);
5454
} catch (IOException e) {
5555
Log.d("Commons", "Could not authenticate :(");
5656
return;
57-
} catch (AuthenticatorException e) {
58-
throw new RuntimeException(e);
57+
}
58+
59+
if(Utils.isNullOrWhiteSpace(authCookie)) {
60+
Log.d("Commons", "Could not authenticate :(");
61+
return;
5962
}
6063

6164
MWApi api = CommonsApplication.createMWApi();

app/src/main/java/fr/free/nrw/commons/upload/SingleUploadFragment.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public void onItemSelected(AdapterView<?> parent, View view, int position, long
130130
setLicenseSummary(license);
131131
SharedPreferences.Editor editor = prefs.edit();
132132
editor.putString(Prefs.DEFAULT_LICENSE, license);
133-
editor.commit();
133+
editor.apply();
134134
}
135135

136136
@Override

app/src/main/res/layout-land/welcome_final.xml

+1-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@
4141
android:textStyle="bold"
4242
android:textAlignment="center"
4343
android:gravity="center_horizontal"
44-
android:textColor="@android:color/white"
45-
android:singleLine="false"/>
44+
android:textColor="@android:color/white"/>
4645

4746
<Button
4847
android:layout_width="120dp"

app/src/main/res/layout/activity_contributions.xml

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
android:layout_height="match_parent"
66
android:orientation="horizontal"
77
android:id="@+id/contributionsFragmentContainer"
8-
android:background="#000000"
98
>
109

1110
<fragment

app/src/main/res/layout/activity_login.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<LinearLayout
88
android:layout_width="match_parent"
9-
android:layout_height="match_parent"
9+
android:layout_height="wrap_content"
1010
android:layout_gravity="center"
1111
android:layout_margin="16dp"
1212
android:gravity="center"

0 commit comments

Comments
 (0)