Skip to content

Commit 654ea2f

Browse files
author
Vivek Maskara
authored
Merge branch 'master' into test
2 parents ed22a02 + f46da66 commit 654ea2f

35 files changed

+563
-118
lines changed

app/build.gradle

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ android {
120120
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt', 'proguard-glide.txt'
121121
}
122122
debug {
123-
applicationIdSuffix ".debug"
124123
testCoverageEnabled true
125124
versionNameSuffix "-debug-" + getBranchName() + "~" + getBuildVersion()
126125
}
@@ -129,6 +128,9 @@ android {
129128
flavorDimensions 'tier'
130129
productFlavors {
131130
prod {
131+
132+
applicationId 'fr.free.nrw.commons'
133+
132134
buildConfigField "String", "WIKIMEDIA_API_POTD", "\"https://commons.wikimedia.org/w/api.php?action=featuredfeed&feed=potd&feedformat=rss&language=en\""
133135
buildConfigField "String", "WIKIMEDIA_API_HOST", "\"https://commons.wikimedia.org/w/api.php\""
134136
buildConfigField "String", "WIKIDATA_API_HOST", "\"https://www.wikidata.org/w/api.php\""
@@ -142,10 +144,18 @@ android {
142144
buildConfigField "String", "SIGNUP_LANDING_URL", "\"https://commons.m.wikimedia.org/w/index.php?title=Special:CreateAccount&returnto=Main+Page&returntoquery=welcome%3Dyes\""
143145
buildConfigField "String", "SIGNUP_SUCCESS_REDIRECTION_URL", "\"https://commons.m.wikimedia.org/w/index.php?title=Main_Page&welcome=yes\""
144146
buildConfigField "String", "FORGOT_PASSWORD_URL", "\"https://commons.wikimedia.org/wiki/Special:PasswordReset\""
147+
148+
buildConfigField "String", "ACCOUNT_TYPE", "\"fr.free.nrw.commons\""
149+
buildConfigField "String", "CONTRIBUTION_AUTHORITY", "\"fr.free.nrw.commons.contributions.contentprovider\""
150+
buildConfigField "String", "MODIFICATION_AUTHORITY", "\"fr.free.nrw.commons.modifications.contentprovider\""
151+
buildConfigField "String", "CATEGORY_AUTHORITY", "\"fr.free.nrw.commons.categories.contentprovider\""
152+
145153
dimension 'tier'
146154
}
147155

148156
beta {
157+
applicationId 'fr.free.nrw.commons.beta'
158+
149159
// What values do we need to hit the BETA versions of the site / api ?
150160
buildConfigField "String", "WIKIMEDIA_API_POTD", "\"https://commons.wikimedia.org/w/api.php?action=featuredfeed&feed=potd&feedformat=rss&language=en\""
151161
buildConfigField "String", "WIKIMEDIA_API_HOST", "\"https://commons.wikimedia.beta.wmflabs.org/w/api.php\""
@@ -160,6 +170,12 @@ android {
160170
buildConfigField "String", "SIGNUP_LANDING_URL", "\"https://commons.m.wikimedia.beta.wmflabs.org/w/index.php?title=Special:CreateAccount&returnto=Main+Page&returntoquery=welcome%3Dyes\""
161171
buildConfigField "String", "SIGNUP_SUCCESS_REDIRECTION_URL", "\"https://commons.m.wikimedia.beta.wmflabs.org/w/index.php?title=Main_Page&welcome=yes\""
162172
buildConfigField "String", "FORGOT_PASSWORD_URL", "\"https://commons.wikimedia.beta.wmflabs.org/wiki/Special:PasswordReset\""
173+
174+
buildConfigField "String", "ACCOUNT_TYPE", "\"fr.free.nrw.commons.beta\""
175+
buildConfigField "String", "CONTRIBUTION_AUTHORITY", "\"fr.free.nrw.commons.beta.contributions.contentprovider\""
176+
buildConfigField "String", "MODIFICATION_AUTHORITY", "\"fr.free.nrw.commons.beta.modifications.contentprovider\""
177+
buildConfigField "String", "CATEGORY_AUTHORITY", "\"fr.free.nrw.commons.beta.categories.contentprovider\""
178+
163179
dimension 'tier'
164180
}
165181
}
Lines changed: 7 additions & 0 deletions
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

Lines changed: 0 additions & 6 deletions
This file was deleted.

app/src/main/AndroidManifest.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,21 +169,21 @@
169169

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

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

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

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

Lines changed: 3 additions & 1 deletion
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

Lines changed: 4 additions & 10 deletions
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
}

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
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;
84
import android.os.Bundle;
95
import android.support.annotation.Nullable;

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

Lines changed: 1 addition & 2 deletions
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

Lines changed: 54 additions & 4 deletions
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
}
@@ -109,7 +159,7 @@ public void forceLogin(Context context) {
109159

110160
public Completable clearAllAccounts() {
111161
AccountManager accountManager = AccountManager.get(context);
112-
Account[] allAccounts = accountManager.getAccountsByType(ACCOUNT_TYPE);
162+
Account[] allAccounts = accountManager.getAccountsByType(BuildConfig.ACCOUNT_TYPE);
113163
return Completable.fromObservable(Observable.fromArray(allAccounts)
114164
.map(a -> accountManager.removeAccount(a, null, null).getResult()))
115165
.doOnComplete(() -> currentAccount = null);

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

Lines changed: 2 additions & 1 deletion
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;

0 commit comments

Comments
 (0)