8000 Merge backend-overhaul to master (#3198) · commons-app/apps-android-commons@8ccad22 · GitHub
Skip to content

Commit 8ccad22

Browse files
maskaravivekashishkumar468
authored andcommitted
Merge backend-overhaul to master (#3198)
* Migrated log 8E73 Events to retrofit (#3087) * Switched wikimedia-android-data-client for new features * Added UserCLient and UserInterface * Migrated ContributionsSyncAdapter to UserClient Fixed sync related bugs * Removed unused code * Removed unused code * Updated wikimedia-android-data-client to new version * Update library for data client (#3131) * Backend overhaul fetch media by filename (#3081) * Added class MwParseResponse and MwParseResult for receiving parse output * Migrated fetchMediaByFilename to retrofit * Removed unused code * Added tests * Migrated isUserBlockedFromCommons to retrofit (#3085) * Switched wikimedia-android-data-client for new features * Added UserCLient and UserInterface * Migrated isUserBlockedFromCommons to retrofit * Added tests and removed dead code * Implemented ban checking functionality in UploadActivity * Removed unused class AuthenticatedActivity * Fixed tests * Fixed NullPointerException when a user accessed image details without logging in. * * Login the login token way, handle LoginResult minutely, add account based on LoginResult (#3151) * Added progress updater in UploadService to show upload progress in no… (#3156) * added progress updater in UploadService to show upload progress in notification * formatting changes * [Dependency: Quadtree] Remove unused code from cache controller (#3163) * Basic logging with redacted sensitive headers (#3159) * As per #3026, removed the obsolete classes in package mwapi (#3150) * fixed compile time error (#3165) * [Dependency fluent]: Remove unused dependency fluent (#3164) * Donot init quiz checker in onResume (#3167) * clear image cache on logout (#3168) * Fixed default locale and upload locales in descrptions (#3166) * Fix 2FA login (#3170) * Fix build (#3172) * Localisation updates from https://translatewiki.net. * Closes #3094 (#3095) * BugFix in SpinnerDescriptionsAdapter and SpinnerLanguagesAdapter (use the langguage code provided by the spinner, donot set the language to the one returned by the locale) * Update changelog.md * Versioning for v2.11.0 * Localisation updates from https://translatewiki.net. * Localisation updates from https://translatewiki.net. * Localisation updates from https://translatewiki.net. * Center map on location clicked in nearby list and notification card(#2060) (#2366) * center map on location clicked in nearby (#2060) * improved animation * Center map on location clicked in nearby list * removed unnecessary methods * center map on location clicked in nearby notification card * some minor changes * travis build error * resolved errors * Tidy up PR * removed swipe to delete (#2589) * Localisation updates from https://translatewiki.net. * Localisation updates from https://translatewiki.net. * Localisation updates from https://translatewiki.net. * Localisation updates from https://translatewiki.net. * Localisation updates from https://translatewiki.net. * Localisation updates from https://translatewiki.net. * edited CREDITS file (#3145) * Unused dependencies are removed (#3141) Part of #3128 * Localisation updates from https://translatewiki.net. * Localisation updates from https://translatewiki.net. * Localisation updates from https://translatewiki.net. * Working with #3129 issue (#3146) * Replace Hard-Coded strings with those from strings.xml. * Localisation updates from https://translatewiki.net. * Localisation updates from https://translatewiki.net. * Localisation updates from https://translatewiki.net. * Localisation updates from https://translatewiki.net. * delete res/values-en-gb (#3153) * Localisation updates from https://translatewiki.net. * Localisation updates from https://translatewiki.net. * First commit (#3093) Fixes info icon color is Review * Solution #3126 (#3155) Fixed wrong upload dates after image upload * Bugfix/fix upload presenter tests (#3158) * Revert "Merge branch 'backend-overhaul' into master" This reverts commit 0090f24, reversing changes made to 9bccbfe. * * Fixed upload presenter tests * Deleted app/src/main/res/values-en-gb/error.xml * Localisation updates from https://translatewiki.net. * Remove dependency on Exif parsing library. (#2947) * Remove dependency on Exif parsing library. * Fix test. * Localisation updates from https://translatewiki.net. * Localisation updates from https://translatewiki.net. * Refactor nearby classes mvp (#2969) * Create parent contract * Create map child contract and fill methods * Add javadocs and specific interfaces for list * Move general method to parent and add javadocs for parent * Add explanation for keeping an emty View interface under NearbyListContract * Move constracts under contract package * Create presenters for map and list and implement user actions accordingly * Add javadocs * Add presenter, contract and fragment for parent Fragment of both NearyListFragment and NearbyMapFragment * Implement missing methods * Fix typo * Add main views on fragment * İmplement child fragment logic and their retain * Relate parent presenter with parent fragment * Add all location permission related methods to view contract and implement in fragment. Call them from presenter by passing locationServiceManager parameter * Define refreshView method as updateMapAndList which is a better naming. Define it at presenter part. * Define a presenter variable in fragment and call updateMapAndList method from there, if permissions are okay * Add lock neabry method to unlisten nearby operations during updates * Add network connection established check on view side, check it from presenter * try to simplify previous method during refactor * Add missing methods for NearbyMap * Connect child fragment and prent fragment with presenter * Change nearby design, first create views then register listeners * AddnetworkBroadcatsReceiver on view side, call it from presenter * Add comments * Change the old NearbyFragment by our new NearbyParentFragment for first tests * Prevent crash caused child fragment is actually null by checking if it is attached or not. * Makes sure that initialize nearby operations method is called just after all views and fragments are ready and attached * Make sure updateMAoAndList method is called when everything ready * Rename a method with prepoer name * Call update map and add required markers * Find out zoom level problem * Implement add nearby markers and add current marker methods * remove unneeded codes copied from previous implementation * Revert "remove unneeded codes copied from previous implementation" This reverts commit 4253965. * add some commits and clear code * Remove location listener implementation from view, handle them in presenter instead. And add timber debug notes and required method calls * Style ,issues * Refactor a variable name to camel case and bind search this area view * Search this area button action is added * Mostly implement search this area methods, not tested yet even once * Make sure everything is called in required order and seach this area method basically works * Rename methods accordingly and add Javadocs * Add current location marker and remove circle around it * Remove unused methods * Add current location marker with object animator and remove previous marker is exists * include clear map into add markers method and reorder methods * Make search this area button appear at correct time * Try to load un search this area is called * Clear logs * Add changes for permission made by Vivek to newly added fragments along with our nearby classes * Add a view to nearby map ragment and insert map view as an item inside it * Add logs to uınderstand why on meap ready callback is never called * Add list item clicked and bottom sheet for list of nearby items is expanded * Make nearby map ready callback came * Add required methods to be called after map view is ready * State: Map ready call is not called but permissions and methods are in correct order * Remove unused logs * Try to use SupportMapFragment instead, still no success... * use SupportMapFragment instead * Remove unused Near * Upgrade mapbox sdk versions * Remove Style import from fragment/NearbyMapFragment * Remove Style import from **fragments/NearbyParentFragment * Remove nearby/NearbyMapFragment * Remove unused/old NearbyFragment and NearbyMapFragment * Remove import of already removed class * Make sure you removed everything related with mapbox implementation * Update mapbox map * Remove unused classes, do not forget centerMapToPlace doesn't work on this branch * Remove Style class it required updated version of mapbox map * Add base codes for new activity * Prove that our mapbox sdk let us implement the map directly inside the activity * Add base codes for testing mapbox activity in a single fragment inside activity * Add codes from mapbox demo repository to test support fragment, map works in a single layer fragment * Add base codes for test layered fragment activity * Add Support fragment inside a fragment and proves that layered fragmentw with map works * Test view pager and tab layout with support map fragment to see it works, it works! * Move Contributions Fragment related codes to test activity * Move nearby card methods * Inject location manager and implement NerabyParentFragmentContract.View on test fragment * Coppy the content of SupportMapFragment from mapbox repository, use this code to modify later. This method war suggested by mapbox team instead of extending the class * Implement NearbyMapContract.View on our new SupportMapFragment * Start to mplement logic of checking permissions * Fix small dagger issue to inject location manager properly * Request permission for nearby places if fragment is loaded and tab is selected * Initialize map operations if map ready and tab is selected * Markers loads at correct time * Style the map according to new version of mapbox map * Add some map elements like FABs and give their actions * Implement map marker click actions * Implement nearby Fabs logic with a small issue * fix FABs are not closing problem * Unkown problem occurs at map load when I try to use MainActivity again. * Revert "Unkown problem occurs at map load when I try to use MainActivity again." This reverts commit 3dc0844. * Search this area buttons are added but button function does not work and button visibility is problematic * Fix issue with MainActivity with the help of Ashish * Fix search this area button visibility issue * Fix the issues with updating search nearby markers and camera position together * Fix progress bar visibility issue * Prevent loding map each time tab selected * Take toolbar back * Implement back button with presenter * Add click actoion to bottom sheet details * Add nearby list into bottom sheeet * Make reuse existing fragments if there is any * Code cleanup * Cleanup * Code cleanup * Add lifecyle codes to prevent leaks * Cleanup * Code cleanup * cleanup * Make list item clicked and map focus to same place * Add bookmark from list fragment * Make nearby card click action work * Revert "Fix conflicts" This reverts commit f345174, reversing changes made to c5d4d55. * Code cleanup * Cleanup * Make recenter button work when list sheet is expanded * Cleanup * Code cleanups * NPE issue is not detected for now, can be solved on seperate PR * Update map after Wikidata edit * Cherry picked previously reverted merge, hoping this will fix enourmus amounts of diff files * Previous merge bringed an file which should be deleted. Delete it. * Revert irrelevant changes on build.gradle * Revert irrelevant changes * Jetbrains annotation is not included to build gradle, this issue caused build issues on my branch so I removed it to be able to build * Rename ListView * Use a singleton to access the presenter, instead of passing it to a variable inside fragment * Fix code style issues * Move hardcoded colors to colors.xml file * Make larger methods smaller * Make current location marker follow * Do not track users position if user is searching around * Revert irrelevant shanges at build gradle * Remove unneeded variable * Remove mvp directory, add sub directories directly under nearby directory instead * Remove unneeded public definiton * Remove unneeded namespace * Add public defiiton, it is needed to reach the constructor. * On Logout, fetch the CSRF token and then make the post logout call (#3182) * Api call for logout * call clear cached onCompleteSessionLogout * Correction is passed file name to checkPageExistsUsingTitle, function expects file name prefixed with File: (#3194) * Merge master (#3196) * Localisation updates from https://translatewiki.net. * Localisation updates from https://translatewiki.net. * Localisation updates from https://translatewiki.net. * Mapped values-en-gb to values-en-rGB (#3161) Fixes "Error: Invalid resource directory name" bug. * Localisation updates from https://translatewiki.net. * Removes the "Other" deletion option mentioned in #3174 (#3183) * Localisation updates from https://translatewiki.net. * Renamed resource file to prevent build from failing (#3189) * Localisation updates from https://translatewiki.net. * Removed some jargon/slang from strings.xml (#3162) * Localisation updates from https://translatewiki.net. * solve issue Avoid 'form movements' in the login screen #1107 (#2936) * Disabled review buttons while an image is being loaded (#3185) * Disabled review buttons while an image is being loaded * Added javadocs for the new methods * Fix build
1 parent 2ed3216 commit 8ccad22

File tree

119 files changed

+2555
-5013
lines changed

Some content is hidden

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

119 files changed

+2555
-5013
lines changed

app/build.gradle

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
plugins {
22
id 'com.github.triplet.play' version '2.2.1' apply false
33
}
4-
54
apply from: '../gitutils.gradle'
65
apply plugin: 'com.android.application'
76
apply plugin: 'kotlin-android'
@@ -20,15 +19,18 @@ dependencies {
2019
// Utils
2120
implementation 'com.github.nicolas-raoul:Quadtree:ac16ea8035bf07'
2221
implementation 'in.yuvi:http.fluent:1.3'
23-
implementation 'com.squareup.okhttp3:okhttp:3.12.1'
24-
implementation 'com.squareup.okio:okio:1.15.0'
22+
implementation 'com.google.code.gson:gson:2.8.5'
23+
implementation 'com.squareup.okhttp3:okhttp:4.2.0'
24+
implementation 'com.squareup.okio:okio:2.2.2'
25+
implementation 'io.reactivex.rxjava2:rxandroid:2.1.0'
26+
implementation 'io.reactivex.rxjava2:rxjava:2.2.3'
2527
implementation 'com.jakewharton.rxbinding2:rxbinding:2.1.1'
2628
implementation 'com.jakewharton.rxbinding2:rxbinding-support-v4:2.1.1'
2729
implementation 'com.jakewharton.rxbinding2:rxbinding-appcompat-v7:2.1.1'
2830
implementation 'com.jakewharton.rxbinding2:rxbinding-design:2.1.1'
2931
implementation 'com.facebook.fresco:fresco:1.13.0'
30-
implementation 'com.dmitrybrant:wikimedia-android-data-client:0.0.18'
3132
implementation 'org.apache.commons:commons-lang3:3.8.1'
33+
implementation 'com.github.maskaravivek:wikimedia-android-data-client:v0.0.28'
3234

3335
// UI
3436
implementation 'fr.avianey.com.viewpagerindicator:library:2.4.1.1@aar'
@@ -49,6 +51,7 @@ dependencies {
4951
api('com.github.tony19:logback-android-classic:1.1.1-6') {
5052
exclude group: 'com.google.android', module: 'android'
5153
}
54+
implementation "com.squareup.okhttp3:logging-interceptor:4.2.0"
5255

5356
// Dependency injector
5457
implementation "com.google.dagger:dagger-android-support:$DAGGER_VERSION"
@@ -62,21 +65,21 @@ dependencies {
6265
testImplementation 'org.robolectric:robolectric:4.3'
6366
testImplementation 'androidx.test:core:1.2.0'
6467
testImplementation 'com.nhaarman:mockito-kotlin:1.5.0'
65-
testImplementation 'com.squareup.okhttp3:mockwebserver:3.10.0'
68+
testImplementation 'com.squareup.okhttp3:mockwebserver:3.12.1'
6669
testImplementation "org.powermock:powermock-module-junit4:2.0.0-beta.5"
6770
testImplementation "org.powermock:powermock-api-mockito2:2.0.0-beta.5"
6871

6972
// Android testing
7073
androidTestImplementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$KOTLIN_VERSION"
71-
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
72-
androidTestImplementation 'androidx.test.espresso:espresso-intents:3.1.1'
73-
androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.1.1'
74-
androidTestImplementation 'androidx.test:runner:1.1.1'
75-
androidTestImplementation 'androidx.test:rules:1.1.1'
76-
androidTestImplementation 'androidx.annotation:annotation:1.0.2'
77-
androidTestImplementation 'com.squareup.okhttp3:mockwebserver:3.10.0'
78-
androidTestImplementation 'org.mockito:mockito-core:2.10.0'
79-
androidTestUtil 'androidx.test:orchestrator:1.1.1'
74+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
75+
androidTestImplementation 'androidx.test.espresso:espresso-intents:3.2.0'
76+
androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.2.0'
77+
androidTestImplementation 'androidx.test:runner:1.2.0'
78+
androidTestImplementation 'androidx.test:rules:1.2.0'
79+
androidTestImplementation 'androidx.annotation:annotation:1.1.0'
80+
androidTestImplementation 'com.squareup.okhttp3:mockwebserver:3.12.1'
81+
androidTestImplementation 'org.mockito:mockito-core:2.13.0'
82+
androidTestUtil 'androidx.test:orchestrator:1.2.0'
8083

8184
// Debugging
8285
debugImplementation "com.squareup.leakcanary:leakcanary-android:$LEAK_CANARY_VERSION"
@@ -187,6 +190,7 @@ android {
187190
buildConfigField "String", "IMAGE_URL_BASE", "\"https://upload.wikimedia.org/wikipedia/commons\""
188191
buildConfigField "String", "HOME_URL", "\"https://commons.wikimedia.org/wiki/\""
189192
buildConfigField "String", "COMMONS_URL", "\"https://commons.wikimedia.org\""
193+
buildConfigField "String", "WIKIDATA_URL", "\"https://wikidata.org\""
190194
buildConfigField "String", "MOBILE_HOME_URL", "\"https://commons.m.wikimedia.org/wiki/\""
191195
buildConfigField "String", "SIGNUP_LANDING_URL", "\"https://commons.m.wikimedia.org/w/index.php?title=Special:CreateAccount&returnto=Main+Page&returntoquery=welcome%3Dyes\""
192196
buildConfigField "String", "SIGNUP_SUCCESS_REDIRECTION_URL", "\"https://commons.m.wikimedia.org/w/index.php?title=Main_Page&welcome=yes\""
@@ -218,6 +222,7 @@ android {
218222
buildConfigField "String", "IMAGE_URL_BASE", "\"https://upload.beta.wmflabs.org/wikipedia/commons\""
219223
buildConfigField "String", "HOME_URL", "\"https://commons.wikimedia.beta.wmflabs.org/wiki/\""
220224
buildConfigField "String", "COMMONS_URL", "\"https://commons.wikimedia.beta.wmflabs.org\""
225+
buildConfigField "String", "WIKIDATA_URL", "\"https://wikidata.org\""
221226
buildConfigField "String", "MOBILE_HOME_URL", "\"https://commons.m.wikimedia.beta.wmflabs.org/wiki/\""
222227
buildConfigField "String", "SIGNUP_LANDING_URL", "\"https://commons.m.wikimedia.beta.wmflabs.org/w/index.php?title=Special:CreateAccount&returnto=Main+Page&returntoquery=welcome%3Dyes\""
223228
buildConfigField "String", "SIGNUP_SUCCESS_REDIRECTION_URL", "\"https://commons.m.wikimedia.beta.wmflabs.org/w/index.php?title=Main_Page&welcome=yes\""

app/src/main/AndroidManifest.xml

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@
152152
</service>
153153
<service
154154
android:name=".contributions.ContributionsSyncService"
155-
android:exported="true">
155+
android:exported="true"
156+
android:process=":sync">
156157
<intent-filter>
157158
<action android:name="android.content.SyncAdapter" />
158159
</int 2263 ent-filter>
@@ -161,17 +162,6 @@
161162
android:name="android.content.SyncAdapter"
162163
android:resource="@xml/contributions_sync_adapter" />
163164
</service>
164-
<service
165-
android:name=".modifications.ModificationsSyncService"
166-
android:exported="true">
167-
<intent-filter>
168-
<action android:name="android.content.SyncAdapter" />
169-
</intent-filter>
170-
171-
<meta-data
172-
android:name="android.content.SyncAdapter"
173-
android:resource="@xml/modifications_sync_adapter" />
174-
</service>
175165

176166
<service
177167
android:name="org.acra.sender.SenderService"
@@ -193,12 +183,7 @@
193183
android:exported="false"
194184
android:label="@string/provider_contributions"
195185
android:syncable="true" />
196-
<provider
197-
android:name=".modifications.ModificationsContentProvider"
198-
android:authorities="${applicationId}.modifications.contentprovider"
199-
android:exported="false"
200-
android:label="@string/provider_modifications"
201-
android:syncable="true" />
186+
202187
<provider
203188
android:name=".category.CategoryContentProvider"
204189
android:authorities="${applicationId}.categories.contentprovider"

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,16 @@ public String getPassword() {
6161

6262
@Override
6363
public void updateAccount(@NonNull LoginResult result) {
64-
// TODO: sessionManager.updateAccount(result);
64+
sessionManager.updateAccount(result);
6565
}
6666

6767
@Override
6868
public SharedPreferenceCookieManager getCookies() {
6969
if (!preferences.contains(COOKIE_STORE_NAME)) {
7070
return null;
7171
}
72-
return GsonUnmarshaller.unmarshal(SharedPreferenceCookieManager.class, preferences.getString(COOKIE_STORE_NAME, null));
72+
return GsonUnmarshaller.unmarshal(SharedPreferenceCookieManager.class,
73+
preferences.getString(COOKIE_STORE_NAME, null));
7374
}
7475

7576
@Override

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

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
package fr.free.nrw.commons;
22

3+
import static org.acra.ReportField.ANDROID_VERSION;
4+
import static org.acra.ReportField.APP_VERSION_CODE;
5+
import static org.acra.ReportField.APP_VERSION_NAME;
6+
import static org.acra.ReportField.PHONE_MODEL;
7+
import static org.acra.ReportField.STACK_TRACE;
8+
import static org.acra.ReportField.USER_COMMENT;
9+
310
import android.annotation.SuppressLint;
411
import android.app.Application;
512
import android.app.NotificationChannel;
@@ -9,26 +16,12 @@
916
import android.os.Build;
1017
import android.os.Process;
1118
import android.util.Log;
12-
19+
import androidx.annotation.NonNull;
1320
import com.facebook.drawee.backends.pipeline.Fresco;
21+
import com.facebook.imagepipeline.core.ImagePipeline;
1422
import com.facebook.imagepipeline.core.ImagePipelineConfig;
1523
import com.squareup.leakcanary.LeakCanary;
1624
import com.squareup.leakcanary.RefWatcher;
17-
18-
import org.acra.ACRA;
19-
import org.acra.annotation.AcraCore;
20-
import org.acra.annotation.AcraDialog;
21-
import org.acra.annotation.AcraMailSender;
22-
import org.acra.data.StringFormat;
23-
import org.wikipedia.AppAdapter;
24-
import org.wikipedia.language.AppLanguageLookUpTable;
25-
26-
import java.io.File;
27-
28-
import javax.inject.Inject;
29-
import javax.inject.Named;
30-
31-
import androidx.annotation.NonNull;
3225
import fr.free.nrw.commons.auth.SessionManager;
3326
import fr.free.nrw.commons.bookmarks.locations.BookmarkLocationsDao;
3427
import fr.free.nrw.commons.bookmarks.pictures.BookmarkPicturesDao;
@@ -41,22 +34,24 @@
4134
import fr.free.nrw.commons.kvstore.JsonKvStore;
4235
import fr.free.nrw.commons.logging.FileLoggingTree;
4336
import fr.free.nrw.commons.logging.LogUtils;
44-
import fr.free.nrw.commons.modifications.ModifierSequenceDao;
4537
import fr.free.nrw.commons.upload.FileUtils;
4638
import fr.free.nrw.commons.utils.ConfigUtils;
4739
import io.reactivex.android.schedulers.AndroidSchedulers;
4840
import io.reactivex.internal.functions.Functions;
4941
import io.reactivex.plugins.RxJavaPlugins;
5042
import io.reactivex.schedulers.Schedulers;
43+
import java.io.File;
44+
import javax.inject.Inject;
45+
import javax.inject.Named;
46+
import org.acra.ACRA;
47+
import org.acra.annotation.AcraCore;
48+
import org.acra.annotation.AcraDialog;
49+
import org.acra.annotation.AcraMailSender;
50+
import org.acra.data.StringFormat;
51+
import org.wikipedia.AppAdapter;
52+
import org.wikipedia.language.AppLanguageLookUpTable;
5153
import timber.log.Timber;
5254

53-
import static org.acra.ReportField.ANDROID_VERSION;
54-
import static org.acra.ReportField.APP_VERSION_CODE;
55-
import static org.acra.ReportField.APP_VERSION_NAME;
56-
import static org.acra.ReportField.PHONE_MODEL;
57-
import static org.acra.ReportField.STACK_TRACE;
58-
import static org.acra.ReportField.USER_COMMENT;
59-
6055
@AcraCore(
6156
buildConfigClass = BuildConfig.class,
6257
resReportSendSuccessToast = R.string.crash_dialog_ok_toast,
@@ -250,6 +245,7 @@ public void clearApplicationData(Context context, LogoutListener logoutListener)
250245
.observeOn(AndroidSchedulers.mainThread())
251246
.subscribe(() -> {
252247
Timber.d("All accounts have been removed");
248+
clearImageCache();
253249
//TODO: fix preference manager
254250
defaultPrefs.clearAll();
255251
defaultPrefs.putBoolean("firstrun", false);
@@ -258,14 +254,21 @@ public void clearApplicationData(Context context, LogoutListener logoutListener)
258254
});
259255
}
260256

257+
/**
258+
* Clear all images cache held by Fresco
259+
*/
260+
private void clearImageCache() {
261+
ImagePipeline imagePipeline = Fresco.getImagePipeline();
262+
imagePipeline.clearCaches();
263+
}
264+
261265
/**
262266
* Deletes all tables and re-creates them.
263267
*/
264268
private void updateAllDatabases() {
265269
dbOpenHelper.getReadableDatabase().close();
266270
SQLiteDatabase db = dbOpenHelper.getWritableDatabase();
267271

268-
ModifierSequenceDao.Table.onDelete(db);
269272
CategoryDao.Table.onDelete(db);
270273
ContributionDao.Table.onDelete(db);
271274
BookmarkPicturesDao.Table.onDelete(db);

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

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
import android.os.Parcel;
55
import android.os.Parcelable;
66

7+
import androidx.annotation.NonNull;
8+
import androidx.annotation.Nullable;
9+
710
import org.apache.commons.lang3.StringUtils;
811
import org.wikipedia.dataclient.mwapi.MwQueryPage;
912
import org.wikipedia.gallery.ExtMetadata;
@@ -20,14 +23,13 @@
2023
import java.util.Locale;
2124
import java.util.Map;
2225

23-
import androidx.annotation.NonNull;
24-
import androidx.annotation.Nullable;
2526
import fr.free.nrw.commons.location.LatLng;
2627
import fr.free.nrw.commons.utils.CommonsDateUtil;
2728
import fr.free.nrw.commons.utils.MediaDataExtractorUtil;
2829

2930
public class Media implements Parcelable {
3031

32+
public static final Media EMPTY = new Media("");
3133
public static Creator<Media> CREATOR = new Creator<Media>() {
3234
@Override
3335
public Media createFromParcel(Parcel parcel) {
@@ -156,9 +158,9 @@ public static Media from(MwQueryPage page) {
156158
page.title(),
157159
"",
158160
0,
159-
safeParseDate(metadata.dateTimeOriginal().value()),
160-
safeParseDate(metadata.dateTime().value()),
161-
StringUtil.fromHtml(metadata.artist().value()).toString()
161+
safeParseDate(metadata.dateTime()),
162+
safeParseDate(metadata.dateTime()),
163+
StringUtil.fromHtml(metadata.artist()).toString()
162164
);
163165

164166
if (!StringUtils.isBlank(imageInfo.getThumbUrl())) {
@@ -170,17 +172,17 @@ public static Media from(MwQueryPage page) {
170172
language = "default";
171173
}
172174

173-
media.setDescriptions(Collections.singletonMap(language, metadata.imageDescription().value()));
174-
media.setCategories(MediaDataExtractorUtil.extractCategoriesFromList(metadata.categories().value()));
175-
String latitude = metadata.gpsLatitude().value();
176-
String longitude = metadata.gpsLongitude().value();
175+
media.setDescriptions(Collections.singletonMap(language, metadata.imageDescription()));
176+
media.setCategories(MediaDataExtractorUtil.extractCategoriesFromList(metadata.getCategories()));
177+
String latitude = metadata.getGpsLatitude();
178+
String longitude = metadata.getGpsLongitude();
177179

178180
if (!StringUtils.isBlank(latitude) && !StringUtils.isBlank(longitude)) {
179181
LatLng latLng = new LatLng(Double.parseDouble(latitude), Double.parseDouble(longitude), 0);
180182
media.setCoordinates(latLng);
181183
}
182184

183-
media.setLicenseInformation(metadata.licenseShortName().value(), metadata.licenseUrl().value());
185+
media.setLicenseInformation(metadata.licenseShortName(), metadata.licenseUrl());
184186
return media;
185187
}
186188

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package fr.free.nrw.commons;
22

3+
import androidx.core.text.HtmlCompat;
4+
35
import javax.inject.Inject;
46
import javax.inject.Singleton;
57

6-
import androidx.core.text.HtmlCompat;
7-
import fr.free.nrw.commons.mwapi.MediaWikiApi;
8+
import fr.free.nrw.commons.media.MediaClient;
89
import fr.free.nrw.commons.mwapi.OkHttpJsonApiClient;
910
import io.reactivex.Single;
1011
import timber.log.Timber;
@@ -17,14 +18,14 @@
1718
*/
1819
@Singleton
1920
public class MediaDataExtractor {
20-
private final MediaWikiApi mediaWikiApi;
2121
private final OkHttpJsonApiClient okHttpJsonApiClient;
22+
private final MediaClient mediaClient;
2223

2324
@Inject
24-
public MediaDataExtractor(MediaWikiApi mwApi,
25-
OkHttpJsonApiClient okHttpJsonApiClient) {
25+
public MediaDataExtractor(OkHttpJsonApiClient okHttpJsonApiClient,
26+
MediaClient mediaClient) {
2627
this.okHttpJsonApiClient = okHttpJsonApiClient;
27-
this.mediaWikiApi = mwApi;
28+
this.mediaClient = mediaClient;
2829
}
2930

3031
/**
@@ -35,7 +36,7 @@ public MediaDataExtractor(MediaWikiApi mwApi,
3536
*/
3637
public Single<Media> fetchMediaDetails(String filename) {
3738
Single<Media> mediaSingle = getMediaFromFileName(filename);
38-
Single<Boolean> pageExistsSingle = mediaWikiApi.pageExists("Commons:Deletion_requests/" + filename);
39+
Single<Boolean> pageExistsSingle = mediaClient.checkPageExistsUsingTitle("Commons:Deletion_requests/" + filename);
3940
Single<String> discussionSingle = getDiscussion(filename);
4041
return Single.zip(mediaSingle, pageExistsSingle, discussionSingle, (media, deletionStatus, discussion) -> {
4142
media.setDiscussion(discussion);
@@ -52,7 +53,7 @@ public Single<Media> fetchMediaDetails(String filename) {
5253
* @return return data rich Media object
5354
*/
5455
public Single<Media> getMediaFromFileName(String filename) {
55-
return okHttpJsonApiClient.getMedia(filename, false);
56+
return mediaClient.getMedia(filename);
5657
}
5758

5859
/**
@@ -61,8 +62,7 @@ public Single<Media> getMediaFromFileName(String filename) {
6162
* @return
6263
*/
6364
private Single<String> getDiscussion(String filename) {
64-
return mediaWikiApi.fetchMediaByFilename(filename.replace("File", "File talk"))
65-
.flatMap(mediaResult -> mediaWikiApi.parseWikicode(mediaResult.getWikiSource()))
65+
return mediaClient.getPageHtml(filename.replace("File", "File talk"))
6666
.map(discussion -> HtmlCompat.fromHtml(discussion, HtmlCompat.FROM_HTML_MODE_LEGACY).toString())
6767
.onErrorReturn(throwable -> {
6868
Timber.e(throwable, "Error occurred while fetching discussion");

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,22 @@ private static OkHttpClient createClient() {
3131
return new OkHttpClient.Builder()
3232
.cookieJar(SharedPreferenceCookieManager.getInstance())
3333
.cache(NET_CACHE)
34-
.addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
34+
.addInterceptor(getLoggingInterceptor())
3535
.addInterceptor(new UnsuccessfulResponseInterceptor())
3636
.addInterceptor(new CommonHeaderRequestInterceptor())
3737
.build();
3838
}
3939

40+
private static HttpLoggingInterceptor getLoggingInterceptor() {
41+
HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor()
42+
.setLevel(HttpLoggingInterceptor.Level.BASIC);
43+
44+
httpLoggingInterceptor.redactHeader("Authorization");
45+
httpLoggingInterceptor.redactHeader("Cookie");
46+
47+
return httpLoggingInterceptor;
48+
}
49+
4050
private static class CommonHeaderRequestInterceptor implements Interceptor {
4151
@Override @NonNull public Response intercept(@NonNull Chain chain) throws IOException {
4252
Request request = chain.request().newBuilder()

0 commit comments

Comments
 (0)