Skip to content

Commit 18fbd47

Browse files
committed
Merge remote-tracking branch 'refs/remotes/origin/2.8-release'
2 parents 386bd0a + d29aa2e commit 18fbd47

36 files changed

+649
-162
lines changed

app/build.gradle

+17-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ android {
122122
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt', 'proguard-glide.txt'
123123
}
124124
debug {
125-
applicationIdSuffix ".debug"
126125
testCoverageEnabled true
127126
versionNameSuffix "-debug-" + getBranchName() + "~" + getBuildVersion()
128127
}
@@ -131,6 +130,9 @@ android {
131130
flavorDimensions 'tier'
132131
productFlavors {
133132
prod {
133+
134+
applicationId 'fr.free.nrw.commons'
135+
134136
buildConfigField "String", "WIKIMEDIA_API_POTD", "\"https://commons.wikimedia.org/w/api.php?action=featuredfeed&feed=potd&feedformat=rss&language=en\""
135137
buildConfigField "String", "WIKIMEDIA_API_HOST", "\"https://commons.wikimedia.org/w/api.php\""
136138
buildConfigField "String", "WIKIDATA_API_HOST", "\"https://www.wikidata.org/w/api.php\""
@@ -144,10 +146,18 @@ android {
144146
buildConfigField "String", "SIGNUP_LANDING_URL", "\"https://commons.m.wikimedia.org/w/index.php?title=Special:CreateAccount&returnto=Main+Page&returntoquery=welcome%3Dyes\""
145147
buildConfigField "String", "SIGNUP_SUCCESS_REDIRECTION_URL", "\"https://commons.m.wikimedia.org/w/index.php?title=Main_Page&welcome=yes\""
146148
buildConfigField "String", "FORGOT_PASSWORD_URL", "\"https://commons.wikimedia.org/wiki/Special:PasswordReset\""
149+
150+
buildConfigField "String", "ACCOUNT_TYPE", "\"fr.free.nrw.commons\""
151+
buildConfigField "String", "CONTRIBUTION_AUTHORITY", "\"fr.free.nrw.commons.contributions.contentprovider\""
152+
buildConfigField "String", "MODIFICATION_AUTHORITY", "\"fr.free.nrw.commons.modifications.contentprovider\""
153+
buildConfigField "String", "CATEGORY_AUTHORITY", "\"fr.free.nrw.commons.categories.contentprovider\""
154+
147155
dimension 'tier'
148156
}
149157

150158
beta {
159+
applicationId 'fr.free.nrw.commons.beta'
160+
151161
// What values do we need to hit the BETA versions of the site / api ?
152162
buildConfigField "String", "WIKIMEDIA_API_POTD", "\"https://commons.wikimedia.org/w/api.php?action=featuredfeed&feed=potd&feedformat=rss&language=en\""
153163
buildConfigField "String", "WIKIMEDIA_API_HOST", "\"https://commons.wikimedia.beta.wmflabs.org/w/api.php\""
@@ -162,6 +172,12 @@ android {
162172
buildConfigField "String", "SIGNUP_LANDING_URL", "\"https://commons.m.wikimedia.beta.wmflabs.org/w/index.php?title=Special:CreateAccount&returnto=Main+Page&returntoquery=welcome%3Dyes\""
163173
buildConfigField "String", "SIGNUP_SUCCESS_REDIRECTION_URL", "\"https://commons.m.wikimedia.beta.wmflabs.org/w/index.php?title=Main_Page&welcome=yes\""
164174
buildConfigField "String", "FORGOT_PASSWORD_URL", "\"https://commons.wikimedia.beta.wmflabs.org/wiki/Special:PasswordReset\""
175+
176+
buildConfigField "String", "ACCOUNT_TYPE", "\"fr.free.nrw.commons.beta\""
177+
buildConfigField "String", "CONTRIBUTION_AUTHORITY", "\"fr.free.nrw.commons.beta.contributions.contentprovider\""
178+
buildConfigField "String", "MODIFICATION_AUTHORITY", "\"fr.free.nrw.commons.beta.modifications.contentprovider\""
179+
buildConfigField "String", "CATEGORY_AUTHORITY", "\"fr.free.nrw.commons.beta.categories.contentprovider\""
180+
165181
dimension 'tier'
166182
}
167183
}

app/src/beta/res/values/adapter.xml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<string name="account_type">fr.free.nrw.commons.beta</string>
4+
<string name="contribution_authority">fr.free.nrw.commons.beta.contributions.contentprovider</string>
5+
<string name="modification_authority">fr.free.nrw.commons.beta.modifications.contentprovider</string>
6+
<string name="category_authority">fr.free.nrw.commons.beta.categories.contentprovider</string>
7+
</resources>

app/src/debug/res/values/placeholder_strings.xml

-6
This file was deleted.

app/src/main/AndroidManifest.xml

+3-3
Original file line numberDiff line numberDiff line change
@@ -168,21 +168,21 @@
168168

169169
<provider
170170
android:name=".contributions.ContributionsContentProvider"
171-
android:authorities="fr.free.nrw.commons.contributions.contentprovider"
171+
android:authorities="${applicationId}.contributions.contentprovider"
172172
android:exported="false"
173173
android:label="@string/provider_contributions"
174174
android:syncable="true" />
175175

176176
<provider
177177
android:name=".modifications.ModificationsContentProvider"
178-
android:authorities="fr.free.nrw.commons.modifications.contentprovider"
178+
android:authorities="${applicationId}.modifications.contentprovider"
179179
android:exported="false"
180180
android:label="@string/provider_modifications"
181181
android:syncable="true" />
182182

183183
<provider
184184
android:name=".category.CategoryContentProvider"
185-
android:authorities="fr.free.nrw.commons.categories.contentprovider"
185+
android:authorities="${applicationId}.categories.contentprovider"
186186
android:exported="false"
187187
android:label="@string/provider_categories"
188188
android:syncable="false" />

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import fr.free.nrw.commons.di.ApplicationlessInjection;
2828
import fr.free.nrw.commons.modifications.ModifierSequenceDao;
2929
import fr.free.nrw.commons.upload.FileUtils;
30+
import fr.free.nrw.commons.utils.ContributionUtils;
3031
import io.reactivex.android.schedulers.AndroidSchedulers;
3132
import io.reactivex.schedulers.Schedulers;
3233
import timber.log.Timber;
@@ -68,7 +69,6 @@ public class CommonsApplication extends MultiDexApplication {
6869
@Override
6970
public void onCreate() {
7071
super.onCreate();
71-
7272
ApplicationlessInjection
7373
.getInstance(this)
7474
.getCommonsApplicationComponent()
@@ -81,6 +81,8 @@ public void onCreate() {
8181
if (setupLeakCanary() == RefWatcher.DISABLED) {
8282
return;
8383
}
84+
// Empty temp directory in case some temp files are created and never removed.
85+
ContributionUtils.emptyTemporaryDirectory();
8486

8587
Timber.plant(new Timber.DebugTree());
8688

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

+4-10
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,10 @@ public void setMedia(Media media) {
5151
return;
5252
}
5353

54-
if(media.getFilename() != null) {
55-
if (thumbnailUrlCache.get(media.getFilename()) != null) {
56-
setImageUrl(thumbnailUrlCache.get(media.getFilename()));
57-
} else {
58-
setImageUrl(null);
59-
currentThumbnailTask = new ThumbnailFetchTask(media, mwApi);
60-
currentThumbnailTask.execute(media.getFilename());
61-
}
62-
} else { // local image
63-
setImageUrl(media.getLocalUri().toString());
54+
if (media.getFilename() != null && thumbnailUrlCache.get(media.getFilename()) != null) {
55+
setImageUrl(thumbnailUrlCache.get(media.getFilename()));
56+
} else {
57+
setImageUrl(null);
6458
currentThumbnailTask = new ThumbnailFetchTask(media, mwApi);
6559
currentThumbnailTask.execute(media.getFilename());
6660
}
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,6 @@
11
package fr.free.nrw.commons.auth;
22

3-
import android.accounts.Account;
4-
import android.accounts.AccountAuthenticatorResponse;
5-
import android.accounts.AccountManager;
6-
import android.content.ContentResolver;
73
import android.content.Context;
8-
import android.os.Bundle;
9-
import android.support.annotation.Nullable;
10-
11-
import timber.log.Timber;
12-
13-
import static android.accounts.AccountManager.ERROR_CODE_REMOTE_EXCEPTION;
14-
import static android.accounts.AccountManager.KEY_ACCOUNT_NAME;
15-
import static android.accounts.AccountManager.KEY_ACCOUNT_TYPE;
16-
import static fr.free.nrw.commons.contributions.ContributionsContentProvider.CONTRIBUTION_AUTHORITY;
17-
import static fr.free.nrw.commons.modifications.ModificationsContentProvider.MODIFICATIONS_AUTHORITY;
184

195
public class AccountUtil {
206

@@ -27,38 +13,4 @@ public AccountUtil(Context context) {
2713
this.context = context;
2814
}
2915

30-
public void createAccount(@Nullable AccountAuthenticatorResponse response,
31-
String username, String password) {
32-
33-
Account account = new Account(username, ACCOUNT_TYPE);
34-
boolean created = accountManager().addAccountExplicitly(account, password, null);
35-
36-
Timber.d("account creation " + (created ? "successful" : "failure"));
37-
38-
if (created) {
39-
if (response != null) {
40-
Bundle bundle = new Bundle();
41-
bundle.putString(KEY_ACCOUNT_NAME, username);
42-
bundle.putString(KEY_ACCOUNT_TYPE, ACCOUNT_TYPE);
43-
44-
45-
response.onResult(bundle);
46-
}
47-
48-
} else {
49-
if (response != null) {
50-
response.onError(ERROR_CODE_REMOTE_EXCEPTION, "");
51-
}
52-
Timber.d("account creation failure");
53-
}
54-
55-
// FIXME: If the user turns it off, it shouldn't be auto turned back on
56-
ContentResolver.setSyncAutomatically(account, CONTRIBUTION_AUTHORITY, true); // Enable sync by default!
57-
ContentResolver.setSyncAutomatically(account, MODIFICATIONS_AUTHORITY, true); // Enable sync by default!
58-
}
59-
60-
private AccountManager accountManager() {
61-
return AccountManager.get(context);
62-
}
63-
6416
}

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ public class LoginActivity extends AccountAuthenticatorActivity {
6363
public static final String PARAM_USERNAME = "fr.free.nrw.commons.login.username";
6464

6565
@Inject MediaWikiApi mwApi;
66-
@Inject AccountUtil accountUtil;
6766
@Inject SessionManager sessionManager;
6867
@Inject @Named("application_preferences") SharedPreferences prefs;
6968
@Inject @Named("default_preferences") SharedPreferences defaultPrefs;
@@ -248,7 +247,7 @@ private void handlePassResult(String username, String password) {
248247
}
249248
}
250249

251-
accountUtil.createAccount(response, username, password);
250+
sessionManager.createAccount(response, username, password);
252251
startMainActivity();
253252
}
254253

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

+55-5
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
11
package fr.free.nrw.commons.auth;
22

33
import android.accounts.Account;
4+
import android.accounts.AccountAuthenticatorResponse;
45
import android.accounts.AccountManager;
6+
import android.content.ContentResolver;
57
import android.content.Context;
68
import android.content.SharedPreferences;
9+
import android.os.Bundle;
710

811
import javax.annotation.Nullable;
912

13+
import fr.free.nrw.commons.BuildConfig;
1014
import fr.free.nrw.commons.mwapi.MediaWikiApi;
1115
import io.reactivex.Completable;
1216
import io.reactivex.Observable;
1317
import timber.log.Timber;
1418

15-
import static fr.free.nrw.commons.auth.AccountUtil.ACCOUNT_TYPE;
19+
import static android.accounts.AccountManager.ERROR_CODE_REMOTE_EXCEPTION;
20+
import static android.accounts.AccountManager.KEY_ACCOUNT_NAME;
21+
import static android.accounts.AccountManager.KEY_ACCOUNT_TYPE;
1622

1723
/**
1824
* Manage the current logged in user session.
@@ -23,21 +29,65 @@ public class SessionManager {
2329
private Account currentAccount; // Unlike a savings account... ;-)
2430
private SharedPreferences sharedPreferences;
2531

26-
public SessionManager(Context context, MediaWikiApi mediaWikiApi, SharedPreferences sharedPreferences) {
32+
33+
public SessionManager(Context context,
34+
MediaWikiApi mediaWikiApi,
35+
SharedPreferences sharedPreferences) {
2736
this.context = context;
2837
this.mediaWikiApi = mediaWikiApi;
2938
this.currentAccount = null;
3039
this.sharedPreferences = sharedPreferences;
3140
}
3241

42+
/**
43+
* Creata a new account
44+
*
45+
* @param response
46+
* @param username
47+
* @param password
48+
*/
49+
public void createAccount(@Nullable AccountAuthenticatorResponse response,
50+
String username, String password) {
51+
52+
Account account = new Account(username, BuildConfig.ACCOUNT_TYPE);
53+
boolean created = accountManager().addAccountExplicitly(account, password, null);
54+
55+
Timber.d("account creation " + (created ? "successful" : "failure"));
56+
57+
if (created) {
58+
if (response != null) {
59+
Bundle bundle = new Bundle();
60+
bundle.putString(KEY_ACCOUNT_NAME, username);
61+
bundle.putString(KEY_ACCOUNT_TYPE, BuildConfig.ACCOUNT_TYPE);
62+
63+
64+
response.onResult(bundle);
65+
}
66+
67+
} else {
68+
if (response != null) {
69+
response.onError(ERROR_CODE_REMOTE_EXCEPTION, "");
70+
}
71+
Timber.d("account creation failure");
72+
}
73+
74+
// FIXME: If the user turns it off, it shouldn't be auto turned back on
75+
ContentResolver.setSyncAutomatically(account, BuildConfig.CONTRIBUTION_AUTHORITY, true); // Enable sync by default!
76+
ContentResolver.setSyncAutomatically(account, BuildConfig.MODIFICATION_AUTHORITY, true); // Enable sync by default!
77+
}
78+
79+
private AccountManager accountManager() {
80+
return AccountManager.get(context);
81+
}
82+
3383
/**
3484
* @return Account|null
3585
*/
3686
@Nullable
3787
public Account getCurrentAccount() {
3888
if (currentAccount == null) {
3989
AccountManager accountManager = AccountManager.get(context);
40-
Account[] allAccounts = accountManager.getAccountsByType(ACCOUNT_TYPE);
90+
Account[] allAccounts = accountManager.getAccountsByType(BuildConfig.ACCOUNT_TYPE);
4191
if (allAccounts.length != 0) {
4292
currentAccount = allAccounts[0];
4393
}
@@ -53,7 +103,7 @@ public Boolean revalidateAuthToken() {
53103
return false; // This should never happen
54104
}
55105

56-
accountManager.invalidateAuthToken(ACCOUNT_TYPE, mediaWikiApi.getAuthCookie());
106+
accountManager.invalidateAuthToken(BuildConfig.ACCOUNT_TYPE, mediaWikiApi.getAuthCookie());
57107
String authCookie = getAuthCookie();
58108

59109
if (authCookie == null) {
@@ -92,7 +142,7 @@ public void forceLogin(Context context) {
92142

93143
public Completable clearAllAccounts() {
94144
AccountManager accountManager = AccountManager.get(context);
95-
Account[] allAccounts = accountManager.getAccountsByType(ACCOUNT_TYPE);
145+
Account[] allAccounts = accountManager.getAccountsByType(BuildConfig.ACCOUNT_TYPE);
96146
return Completable.fromObservable(Observable.fromArray(allAccounts)
97147
.map(a -> accountManager.removeAccount(a, null, null).getResult()))
98148
.doOnComplete(() -> currentAccount = null);

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@
1212
import android.support.annotation.NonNull;
1313
import android.support.annotation.Nullable;
1414

15+
import fr.free.nrw.commons.BuildConfig;
1516
import fr.free.nrw.commons.contributions.ContributionsContentProvider;
1617
import fr.free.nrw.commons.modifications.ModificationsContentProvider;
1718

1819
import static fr.free.nrw.commons.auth.AccountUtil.ACCOUNT_TYPE;
1920
import static fr.free.nrw.commons.auth.AccountUtil.AUTH_TOKEN_TYPE;
2021

2122
public class WikiAccountAuthenticator extends AbstractAccountAuthenticator {
22-
private static final String[] SYNC_AUTHORITIES = {ContributionsContentProvider.CONTRIBUTION_AUTHORITY, ModificationsContentProvider.MODIFICATIONS_AUTHORITY};
23+
private static final String[] SYNC_AUTHORITIES = {BuildConfig.CONTRIBUTION_AUTHORITY, BuildConfig.MODIFICATION_AUTHORITY};
2324

2425
@NonNull
2526
private final Context context;

app/src/main/java/fr/free/nrw/commons/category/CategoryContentProvider.java

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

1212
import javax.inject.Inject;
1313

14+
import fr.free.nrw.commons.BuildConfig;
1415
import fr.free.nrw.commons.data.DBOpenHelper;
1516
import fr.free.nrw.commons.di.CommonsDaggerContentProvider;
1617
import timber.log.Timber;
@@ -22,19 +23,18 @@
2223

2324
public class CategoryContentProvider extends CommonsDaggerContentProvider {
2425

25-
public static final String AUTHORITY = "fr.free.nrw.commons.categories.contentprovider";
2626
// For URI matcher
2727
private static final int CATEGORIES = 1;
2828
private static final int CATEGORIES_ID = 2;
2929
private static final String BASE_PATH = "categories";
3030

31-
public static final Uri BASE_URI = Uri.parse("content://" + AUTHORITY + "/" + BASE_PATH);
31+
public static final Uri BASE_URI = Uri.parse("content://" + BuildConfig.CATEGORY_AUTHORITY + "/" + BASE_PATH);
3232

3333
private static final UriMatcher uriMatcher = new UriMatcher(NO_MATCH);
3434

3535
static {
36-
uriMatcher.addURI(AUTHORITY, BASE_PATH, CATEGORIES);
37-
uriMatcher.addURI(AUTHORITY, BASE_PATH + "/#", CATEGORIES_ID);
36+
uriMatcher.addURI(BuildConfig.CATEGORY_AUTHORITY, BASE_PATH, CATEGORIES);
37+
uriMatcher.addURI(BuildConfig.CATEGORY_AUTHORITY, BASE_PATH + "/#", CATEGORIES_ID);
3838
}
3939

4040
public static Uri uriForId(int id) {

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

+9
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public Contribution[] newArray(int i) {
4646
private String decimalCoords;
4747
private boolean isMultiple;
4848
private String wikiDataEntityId;
49+
private Uri contentProviderUri;
4950

5051
public Contribution(Uri contentUri, String filename, Uri localUri, String imageUrl, Date timestamp,
5152
int state, long dataLength, Date dateUploaded, long transferred,
@@ -236,4 +237,12 @@ public String getWikiDataEntityId() {
236237
public void setWikiDataEntityId(String wikiDataEntityId) {
237238
this.wikiDataEntityId = wikiDataEntityId;
238239
}
240+
241+
public void setContentProviderUri(Uri contentProviderUri) {
242+
this.contentProviderUri = contentProviderUri;
243+
}
244+
245+
public Uri getContentProviderUri() {
246+
return contentProviderUri;
247+
}
239248
}

0 commit comments

Comments
 (0)