Skip to content

Commit eb816b4

Browse files
madhurgupta10maskaravivektranslatewikimacgillsneslihanturan
authored
[GSoC] Merge Leaderboard branch with master (commons-app#3905)
* [GSoC] Fixes commons-app#3789 Updated UI of achievements activity to display level in first tab & Leaderboard in the second tab (commons-app#3794) * Updated UI of achievements activity to display level in first tab and Leaderboard in the second tab * Removed hardcoded string * Fixes commons-app#3861 Use the APIs to fetch leaderboard’s based on uploads via mobile app (all time) and display it in the Leaderboard screen. (commons-app#3865) * [GSoC] Added Unit Tests and Fixed Landscape Mode Bug (commons-app#3872) * Fixes commons-app#3861 Use the APIs to fetch leaderboard’s based on uploads via mobile app (all time) and display it in the Leaderboard screen. * Fixed Bug - missing data in landscape mode * Added Unit Tests for Leaderboard * Added JavaDocs * Updated JavaDocs * [GSoC] Added Pagination to Leaderboard (commons-app#3881) * Fixes commons-app#3861 Use the APIs to fetch leaderboard’s based on uploads via mobile app (all time) and display it in the Leaderboard screen. * Fixed Bug - missing data in landscape mode * Added Unit Tests for Leaderboard * Added JavaDocs * Updated JavaDocs * Added Pagination * Added Merge Adapter * Fixed Test Case * Added Smooth Scroll * Added Progress Bar for Paging * Fixed Gradle * [GSoC] Added option to set a new avatar (commons-app#3892) * Fixes commons-app#3861 Use the APIs to fetch leaderboard’s based on uploads via mobile app (all time) and display it in the Leaderboard screen. * Added option to set a new avatar * [GSoC] Added Click to open user profile for leaderboard (commons-app#3887) * Localisation updates from https://translatewiki.net. * Localisation updates from https://translatewiki.net. * commons-app#3749 Improve MediaClient UnitTests (commons-app#3846) * commons-app#3468 Switch from RvRenderer to AdapterDelegates - replace SearchDepictionsRenderer * commons-app#3468 Switch from RvRenderer to AdapterDelegates - replace UploadCategoryDepictionsRenderer * commons-app#3468 Switch from RvRenderer to AdapterDelegates - update BaseAdapter to be easier to use * commons-app#3468 Switch from RvRenderer to AdapterDelegates - replace SearchImagesRenderer * commons-app#3468 Switch from RvRenderer to AdapterDelegates - replace SearchCategoriesRenderer * commons-app#3468 Switch from RvRenderer to AdapterDelegates - replace NotificationRenderer * commons-app#3468 Switch from RvRenderer to AdapterDelegates - replace UploadDepictsRenderer * commons-app#3468 Switch from RvRenderer to AdapterDelegates - replace PlaceRenderer * commons-app#3756 Convert SearchDepictionsFragment to use Pagination - convert SearchDepictionsFragment * commons-app#3756 Convert SearchDepictionsFragment to use Pagination - fix presenter unit tests now that view is not nullable - fix Category prefix imports * commons-app#3756 Convert SearchDepictionsFragment to use Pagination - test DataSource related classes * commons-app#3756 Convert SearchDepictionsFragment to use Pagination - reset rx scheduler - ignore failing test * commons-app#3760 Convert SearchCategoriesFragment to use Pagination - extract functionality of pagination to base classes - add category pagination * commons-app#3772 Convert SearchImagesFragment to use Pagination - convert SearchImagesFragment - tidy up showing the empty view - make search fragments show snackbar with appropriate text * commons-app#3772 Convert SearchImagesFragment to use Pagination - allow viewpager to load more data * commons-app#3760 remove test that got re-added by merge * commons-app#3760 remove duplicate dependency * commons-app#3772 fix compilation * commons-app#3780 Create media using a combination of Entities & MwQueryResult - construct media with an entity - move fields from media down to contribution - move dynamic fields outside of media - remove unused constructors - remove all unnecessary fetching of captions/descriptions - bump database version * commons-app#3808 Construct media objects that depict an item id correctly - use generator to construct media for DepictedImages * commons-app#3810 Convert DepictedImagesFragment to use Pagination - extract common media paging methods - convert to DepictedImages to use pagination * commons-app#3810 Convert DepictedImagesFragment to use Pagination - rename base classes to better reflect usage * commons-app#3810 Convert DepictedImagesFragment to use Pagination - map to empty result with no pages * commons-app#3810 Convert DepictedImagesFragment to use Pagination - align test with returned values * commons-app#3780 Create media using a combination of Entities & MwQueryResult - update wikicode to align with expected behaviour * commons-app#3780 Create media using a combination of Entities & MwQueryResult - replace old site of thumbnail title with most relevant caption * commons-app#3818 Convert SubDepictionListFragment to use Pagination - replace SubDepictionList with Child and Parent Fragments - replace contracts with simple presenter declarations - move classes to appropriate packages - delete unused network models - delete duplicated paging classes * commons-app#3820 Convert CategoryImagesListFragment to use Pagination - replace CategoryImagesListFragment with CategoriesMediaFragment - disallow the construction of media objects without imageinfo * commons-app#3822 Convert SubCategoryImagesListFragment to use Pagination - convert subcategories - add continuation support in category client - rely on interfaces for callbacks of PageableMediaFragments * commons-app#3822 Convert SubCategoryImagesListFragment to use Pagination - convert parent categories - delete list fragment - creat base class to support continuation requests in clients * commons-app#3822 Convert SubCategoryImagesListFragment to use Pagination - add tests for ParentCategoriesDataSource * commons-app#3822 Convert SubCategoryImagesListFragment to use Pagination - remove no longer applicable test * commons-app#3749 Improve MediaClient UnitTests - test rewrite * commons-app#3749 Improve MediaClient UnitTests - align with buildConfig property * With pause and resume for uploads (commons-app#3858) * With pause and resume for uploads * Dispose current upload * Make pause and resume work * Check stash validity * With java docs * minor * Localisation updates from https://translatewiki.net. * Localisation updates from https://translatewiki.net. * Add nearby presenter unit tests (commons-app#3615) * init the test file * Add tests to check if searchthisarea button action and checkbox actions are added after initialize test * Add tests to locked unlocked nearby cases * Add tests for null cases in updateMapAndList method * Add test to check which locations are used to populate places, depending to LocationChangeType * Add tests to test users position is not followed if blue dot (current location marker) is not visible * Add tests to decide search this area method visibility on camera move * Add tests for multi filteirng of placetypes * add tests for single place type selection too * Add tests to tests search view focus gain and bottom sheet visibilities * Add tests for SearchCloseToCurrentLocation * Remove two unneeded getter and setter for isNearbyLocked, use @VisibleForTesting annotation instead * Add VisibleForTesting annotation to initializeNearbyOperations method so that it will be private by default * Add missing tests * Add tests for map updated case and add missing lines those are being tested * Add some missind method verifications * Create real latlang objects isntead of spying them * Use a real presenter object instead of a spy * Revert nonneeded @VisibleForTest annotations, instead reach via lockUnlock method * Reduce code repetitions * Do not call a test from another test method * Add some more tests * Fix minor issues * Hidden categories are not showed in suggested categories (commons-app#3853) * Localisation updates from https://translatewiki.net. * Clarify that the caption would also be used as the image title (commons-app#3876) The app uses the fist caption as the file title. This should also be communicated to the user via the info box as they would not be aware of it otherwise. * Localisation updates from https://translatewiki.net. * Added Click event for leaderboard, Fixed commons-app#3886 * Fixed Travis Co-authored-by: translatewiki.net <l10n-bot@translatewiki.net> Co-authored-by: Seán Mac Gillicuddy <seantheappdev@gmail.com> Co-authored-by: Vivek Maskara <maskaravivek@gmail.com> Co-authored-by: neslihanturan <tur.neslihan@gmail.com> Co-authored-by: Paulina <63326136+PaulinaQuintero@users.noreply.github.com> Co-authored-by: Kaartic Sivaraam <kaartic.sivaraam@gmail.com> * [GSoC] Added Leaderboard Filters (commons-app#3902) * Attempt to add filters * Basic Filter Working * Filter Improved * Filter Completed * Add JavaDocs * Added Test for Update Avatar * Decreased Margin of Filter * [GSoC] Updated leaderboard string (commons-app#3897) * Localisation updates from https://translatewiki.net. * Localisation updates from https://translatewiki.net. * commons-app#3749 Improve MediaClient UnitTests (commons-app#3846) * commons-app#3468 Switch from RvRenderer to AdapterDelegates - replace SearchDepictionsRenderer * commons-app#3468 Switch from RvRenderer to AdapterDelegates - replace UploadCategoryDepictionsRenderer * commons-app#3468 Switch from RvRenderer to AdapterDelegates - update BaseAdapter to be easier to use * commons-app#3468 Switch from RvRenderer to AdapterDelegates - replace SearchImagesRenderer * commons-app#3468 Switch from RvRenderer to AdapterDelegates - replace SearchCategoriesRenderer * commons-app#3468 Switch from RvRenderer to AdapterDelegates - replace NotificationRenderer * commons-app#3468 Switch from RvRenderer to AdapterDelegates - replace UploadDepictsRenderer * commons-app#3468 Switch from RvRenderer to AdapterDelegates - replace PlaceRenderer * commons-app#3756 Convert SearchDepictionsFragment to use Pagination - convert SearchDepictionsFragment * commons-app#3756 Convert SearchDepictionsFragment to use Pagination - fix presenter unit tests now that view is not nullable - fix Category prefix imports * commons-app#3756 Convert SearchDepictionsFragment to use Pagination - test DataSource related classes * commons-app#3756 Convert SearchDepictionsFragment to use Pagination - reset rx scheduler - ignore failing test * commons-app#3760 Convert SearchCategoriesFragment to use Pagination - extract functionality of pagination to base classes - add category pagination * commons-app#3772 Convert SearchImagesFragment to use Pagination - convert SearchImagesFragment - tidy up showing the empty view - make search fragments show snackbar with appropriate text * commons-app#3772 Convert SearchImagesFragment to use Pagination - allow viewpager to load more data * commons-app#3760 remove test that got re-added by merge * commons-app#3760 remove duplicate dependency * commons-app#3772 fix compilation * commons-app#3780 Create media using a combination of Entities & MwQueryResult - construct media with an entity - move fields from media down to contribution - move dynamic fields outside of media - remove unused constructors - remove all unnecessary fetching of captions/descriptions - bump database version * commons-app#3808 Construct media objects that depict an item id correctly - use generator to construct media for DepictedImages * commons-app#3810 Convert DepictedImagesFragment to use Pagination - extract common media paging methods - convert to DepictedImages to use pagination * commons-app#3810 Convert DepictedImagesFragment to use Pagination - rename base classes to better reflect usage * commons-app#3810 Convert DepictedImagesFragment to use Pagination - map to empty result with no pages * commons-app#3810 Convert DepictedImagesFragment to use Pagination - align test with returned values * commons-app#3780 Create media using a combination of Entities & MwQueryResult - update wikicode to align with expected behaviour * commons-app#3780 Create media using a combination of Entities & MwQueryResult - replace old site of thumbnail title with most relevant caption * commons-app#3818 Convert SubDepictionListFragment to use Pagination - replace SubDepictionList with Child and Parent Fragments - replace contracts with simple presenter declarations - move classes to appropriate packages - delete unused network models - delete duplicated paging classes * commons-app#3820 Convert CategoryImagesListFragment to use Pagination - replace CategoryImagesListFragment with CategoriesMediaFragment - disallow the construction of media objects without imageinfo * commons-app#3822 Convert SubCategoryImagesListFragment to use Pagination - convert subcategories - add continuation support in category client - rely on interfaces for callbacks of PageableMediaFragments * commons-app#3822 Convert SubCategoryImagesListFragment to use Pagination - convert parent categories - delete list fragment - creat base class to support continuation requests in clients * commons-app#3822 Convert SubCategoryImagesListFragment to use Pagination - add tests for ParentCategoriesDataSource * commons-app#3822 Convert SubCategoryImagesListFragment to use Pagination - remove no longer applicable test * commons-app#3749 Improve MediaClient UnitTests - test rewrite * commons-app#3749 Improve MediaClient UnitTests - align with buildConfig property * With pause and resume for uploads (commons-app#3858) * With pause and resume for uploads * Dispose current upload * Make pause and resume work * Check stash validity * With java docs * minor * Localisation updates from https://translatewiki.net. * Localisation updates from https://translatewiki.net. * Add nearby presenter unit tests (commons-app#3615) * init the test file * Add tests to check if searchthisarea button action and checkbox actions are added after initialize test * Add tests to locked unlocked nearby cases * Add tests for null cases in updateMapAndList method * Add test to check which locations are used to populate places, depending to LocationChangeType * Add tests to test users position is not followed if blue dot (current location marker) is not visible * Add tests to decide search this area method visibility on camera move * Add tests for multi filteirng of placetypes * add tests for single place type selection too * Add tests to tests search view focus gain and bottom sheet visibilities * Add tests for SearchCloseToCurrentLocation * Remove two unneeded getter and setter for isNearbyLocked, use @VisibleForTesting annotation instead * Add VisibleForTesting annotation to initializeNearbyOperations method so that it will be private by default * Add missing tests * Add tests for map updated case and add missing lines those are being tested * Add some missind method verifications * Create real latlang objects isntead of spying them * Use a real presenter object instead of a spy * Revert nonneeded @VisibleForTest annotations, instead reach via lockUnlock method * Reduce code repetitions * Do not call a test from another test method * Add some more tests * Fix minor issues * Hidden categories are not showed in suggested categories (commons-app#3853) * Localisation updates from https://translatewiki.net. * Clarify that the caption would also be used as the image title (commons-app#3876) The app uses the fist caption as the file title. This should also be communicated to the user via the info box as they would not be aware of it otherwise. * Localisation updates from https://translatewiki.net. * Delete NearbyMapFragment & NearbyListFragment (commons-app#3885) * Fixes commons-app#3884 * Delete NearbyMapFragment & NearbyListFragment * Fixed NearbyParentFragmentPresenterTest * Localisation updates from https://translatewiki.net. * Localisation updates from https://translatewiki.net. * Add more nearby tests (commons-app#3877) * more nearby tests added * Add tests for Label class * Add checkbox test javadocs * Add javadocs for label * Localisation updates from https://translatewiki.net. * Updated strings.xml Co-authored-by: translatewiki.net <l10n-bot@translatewiki.net> Co-authored-by: Seán Mac Gillicuddy <seantheappdev@gmail.com> Co-authored-by: Vivek Maskara <maskaravivek@gmail.com> Co-authored-by: neslihanturan <tur.neslihan@gmail.com> Co-authored-by: Paulina <63326136+PaulinaQuintero@users.noreply.github.com> Co-authored-by: Kaartic Sivaraam <kaartic.sivaraam@gmail.com> Co-authored-by: Ashish Kumar <ashishkumar468@gmail.com> * Updated Strings * Added JavaDocs for all methods and classes * Added JavaDocs for all methods and classes * Added More JavaDocs * Revert string.xml * Revert "Revert string.xml" This reverts commit 00019b5. * Added protected * Fixed strings.xml extra changes * Revert codeStyle change * Fixed extra string change Co-authored-by: Vivek Maskara <maskaravivek@gmail.com> Co-authored-by: translatewiki.net <l10n-bot@translatewiki.net> Co-authored-by: Seán Mac Gillicuddy <seantheappdev@gmail.com> Co-authored-by: neslihanturan <tur.neslihan@gmail.com> Co-authored-by: Paulina <63326136+PaulinaQuintero@users.noreply.github.com> Co-authored-by: Kaartic Sivaraam <kaartic.sivaraam@gmail.com> Co-authored-by: Ashish Kumar <ashishkumar468@gmail.com>
1 parent 50bcaab commit eb816b4

Some content is hidden

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

44 files changed

+2839
-641
lines changed

app/build.gradle

+6-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ dependencies {
2121
// Utils
2222
implementation 'in.yuvi:http.fluent:1.3'
2323
implementation 'com.google.code.gson:gson:2.8.5'
24-
implementation 'com.squareup.okhttp3:okhttp:4.5.0'
24+
implementation 'com.squareup.okhttp3:okhttp:4.8.0'
2525
implementation 'com.squareup.okio:okio:2.2.2'
2626
implementation 'io.reactivex.rxjava2:rxandroid:2.1.0'
2727
implementation 'io.reactivex.rxjava2:rxjava:2.2.3'
@@ -42,6 +42,7 @@ dependencies {
4242
implementation 'com.dinuscxj:circleprogressbar:1.1.1'
4343
implementation 'com.karumi:dexter:5.0.0'
4444
implementation "com.jakewharton:butterknife:$BUTTERKNIFE_VERSION"
45+
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
4546

4647
kapt "com.jakewharton:butterknife-compiler:$BUTTERKNIFE_VERSION"
4748
implementation "com.hannesdorfmann:adapterdelegates4-kotlin-dsl-layoutcontainer:$ADAPTER_DELEGATES_VERSION"
@@ -50,6 +51,7 @@ dependencies {
5051
testImplementation "androidx.paging:paging-common-ktx:$PAGING_VERSION"
5152
implementation "androidx.paging:paging-rxjava2-ktx:$PAGING_VERSION"
5253
implementation "androidx.recyclerview:recyclerview:1.2.0-alpha02"
54+
implementation 'com.squareup.okhttp3:okhttp-ws:3.4.1'
5355

5456
// Logging
5557
implementation 'ch.acra:acra-dialog:5.3.0'
@@ -79,7 +81,7 @@ dependencies {
7981
testImplementation 'junit:junit:4.13'
8082
testImplementation 'org.robolectric:robolectric:4.3'
8183
testImplementation 'androidx.test:core:1.2.0'
82-
testImplementation 'com.squareup.okhttp3:mockwebserver:3.12.1'
84+
testImplementation "com.squareup.okhttp3:mockwebserver:4.8.0"
8385
testImplementation "org.powermock:powermock-module-junit4:2.0.0-beta.5"
8486
testImplementation "org.powermock:powermock-api-mockito2:2.0.0-beta.5"
8587
testImplementation 'org.mockito:mockito-core:2.23.0'
@@ -94,7 +96,7 @@ dependencies {
9496
androidTestImplementation 'androidx.test:runner:1.2.0'
9597
androidTestImplementation 'androidx.test:rules:1.2.0'
9698
androidTestImplementation 'androidx.annotation:annotation:1.1.0'
97-
androidTestImplementation 'com.squareup.okhttp3:mockwebserver:3.12.1'
99+
androidTestImplementation 'com.squareup.okhttp3:mockwebserver:4.8.0'
98100
androidTestUtil 'androidx.test:orchestrator:1.2.0'
99101

100102
// Debugging
@@ -209,8 +211,8 @@ android {
209211

210212
configurations.all {
211213
resolutionStrategy.force 'androidx.annotation:annotation:1.0.2'
214+
exclude module: 'okhttp-ws'
212215
}
213-
214216
flavorDimensions 'tier'
215217
productFlavors {
216218
prod {

app/src/androidTest/java/fr/free/nrw/commons/AchievementsActivityTest.kt

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@ import androidx.test.espresso.intent.Intents
77
import androidx.test.espresso.intent.matcher.IntentMatchers.hasComponent
88
import androidx.test.espresso.intent.rule.IntentsTestRule
99
import androidx.test.espresso.matcher.ViewMatchers.withId
10-
import androidx.test.filters.MediumTest
1110
import androidx.test.runner.AndroidJUnit4
12-
import fr.free.nrw.commons.achievements.AchievementsActivity
1311
import fr.free.nrw.commons.auth.LoginActivity
12+
import fr.free.nrw.commons.profile.ProfileActivity
1413
import org.junit.Before
1514
import org.junit.Rule
1615
import org.junit.Test
@@ -32,6 +31,6 @@ class AchievementsActivityTest {
3231
onView(withId(R.id.drawer_layout)).perform(DrawerActions.open())
3332
onView(withId(R.id.user_icon)).perform(click())
3433

35-
Intents.intended(hasComponent(AchievementsActivity::class.java.name))
34+
Intents.intended(hasComponent(ProfileActivity::class.java.name))
3635
}
3736
}

app/src/main/AndroidManifest.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@
137137
/>
138138

139139
<activity
140-
android:name=".achievements.AchievementsActivity"
141-
android:label="@string/Achievements" />
140+
android:name=".profile.ProfileActivity"
141+
android:label="@string/Profile" />
142142

143143
<activity
144144
android:name=".bookmarks.BookmarksActivity"

app/src/main/java/fr/free/nrw/commons/delete/ReasonBuilder.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
import fr.free.nrw.commons.Media;
1414
import fr.free.nrw.commons.R;
15-
import fr.free.nrw.commons.achievements.FeedbackResponse;
15+
import fr.free.nrw.commons.profile.achievements.FeedbackResponse;
1616
import fr.free.nrw.commons.auth.SessionManager;
1717
import fr.free.nrw.commons.mwapi.OkHttpJsonApiClient;
1818
import fr.free.nrw.commons.utils.ViewUtilWrapper;

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
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;
87
import fr.free.nrw.commons.auth.LoginActivity;
98
import fr.free.nrw.commons.auth.SignupActivity;
109
import fr.free.nrw.commons.bookmarks.BookmarksActivity;
@@ -15,6 +14,7 @@
1514
import fr.free.nrw.commons.explore.SearchActivity;
1615
import fr.free.nrw.commons.explore.ExploreActivity;
1716
import fr.free.nrw.commons.notification.NotificationActivity;
17+
import fr.free.nrw.commons.profile.ProfileActivity;
1818
import fr.free.nrw.commons.review.ReviewActivity;
1919
import fr.free.nrw.commons.settings.SettingsActivity;
2020
import fr.free.nrw.commons.upload.UploadActivity;
@@ -68,7 +68,7 @@ public abstract class ActivityBuilderModule {
6868
abstract ExploreActivity bindExploreActivity();
6969

7070
@ContributesAndroidInjector
71-
abstract AchievementsActivity bindAchievementsActivity();
71+
abstract ProfileActivity bindAchievementsActivity();
7272

7373
@ContributesAndroidInjector
7474
abstract BookmarksActivity bindBookmarksActivity();

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

+8
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import fr.free.nrw.commons.media.MediaDetailFragment;
2020
import fr.free.nrw.commons.media.MediaDetailPagerFragment;
2121
import fr.free.nrw.commons.nearby.fragments.NearbyParentFragment;
22+
import fr.free.nrw.commons.profile.achievements.AchievementsFragment;
23+
import fr.free.nrw.commons.profile.leaderboard.LeaderboardFragment;
2224
import fr.free.nrw.commons.review.ReviewImageFragment;
2325
import fr.free.nrw.commons.settings.SettingsFragment;
2426
import fr.free.nrw.commons.upload.categories.UploadCategoriesFragment;
@@ -103,4 +105,10 @@ public abstract class FragmentBuilderModule {
103105

104106
@ContributesAndroidInjector
105107
abstract ParentCategoriesFragment bindParentCategoriesFragment();
108+
109+
@ContributesAndroidInjector
110+
abstract AchievementsFragment bindAchievementsFragment();
111+
112+
@ContributesAndroidInjector
113+
abstract LeaderboardFragment bindLeaderboardFragment();
106114
}

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

+10
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,13 @@ public HttpLoggingInterceptor provideHttpLoggingInterceptor() {
8585
public OkHttpJsonApiClient provideOkHttpJsonApiClient(OkHttpClient okHttpClient,
8686
DepictsClient depictsClient,
8787
@Named("tools_forge") HttpUrl toolsForgeUrl,
88+
@Named("test_tools_forge") HttpUrl testToolsForgeUrl,
8889
@Named("default_preferences") JsonKvStore defaultKvStore,
8990
Gson gson) {
9091
return new OkHttpJsonApiClient(okHttpClient,
9192
depictsClient,
9293
toolsForgeUrl,
94+
testToolsForgeUrl,
9395
WIKIDATA_SPARQL_QUERY_URL,
9496
BuildConfig.WIKIMEDIA_CAMPAIGNS_URL,
9597
gson);
@@ -124,6 +126,14 @@ public HttpUrl provideToolsForgeUrl() {
124126
return HttpUrl.parse(TOOLS_FORGE_URL);
125127
}
126128

129+
@Provides
130+
@Named("test_tools_forge")
131+
@NonNull
132+
@SuppressWarnings("ConstantConditions")
133+
public HttpUrl provideTestToolsForgeUrl() {
134+
return HttpUrl.parse(TEST_TOOLS_FORGE_URL);
135+
}
136+
127137
@Provides
128138
@Singleton
129139
@Named(NAMED_COMMONS_WIKI_SITE)

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

+30
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,34 @@
2222
import com.google.android.material.snackbar.Snackbar;
2323
import fr.free.nrw.commons.Media;
2424
import fr.free.nrw.commons.R;
25+
import fr.free.nrw.commons.auth.SessionManager;
2526
import fr.free.nrw.commons.bookmarks.Bookmark;
2627
import fr.free.nrw.commons.bookmarks.pictures.BookmarkPicturesContentProvider;
2728
import fr.free.nrw.commons.bookmarks.pictures.BookmarkPicturesDao;
2829
import fr.free.nrw.commons.contributions.Contribution;
2930
import fr.free.nrw.commons.di.CommonsDaggerSupportFragment;
31+
import fr.free.nrw.commons.mwapi.OkHttpJsonApiClient;
3032
import fr.free.nrw.commons.utils.DownloadUtils;
3133
import fr.free.nrw.commons.utils.ImageUtils;
3234
import fr.free.nrw.commons.utils.NetworkUtils;
3335
import fr.free.nrw.commons.utils.ViewUtil;
36+
import io.reactivex.disposables.CompositeDisposable;
37+
import java.util.Objects;
3438
import javax.inject.Inject;
3539
import timber.log.Timber;
3640

3741
public class MediaDetailPagerFragment extends CommonsDaggerSupportFragment implements ViewPager.OnPageChangeListener {
3842

3943
@Inject BookmarkPicturesDao bookmarkDao;
4044

45+
@Inject
46+
protected OkHttpJsonApiClient okHttpJsonApiClient;
47+
48+
@Inject
49+
protected SessionManager sessionManager;
50+
51+
private static CompositeDisposable compositeDisposable = new CompositeDisposable();
52+
4153
@BindView(R.id.mediaDetailsPager) ViewPager pager;
4254
private Boolean editable;
4355
private boolean isFeaturedImage;
@@ -160,6 +172,10 @@ public boolean onOptionsItemSelected(MenuItem item) {
160172
// Set wallpaper
161173
setWallpaper(m);
162174
return true;
175+
case R.id.menu_set_as_avatar:
176+
// Set avatar
177+
setAvatar(m);
178+
return true;
163179
default:
164180
return super.onOptionsItemSelected(item);
165181
}
@@ -178,6 +194,20 @@ private void setWallpaper(Media media) {
178194
ImageUtils.setWallpaperFromImageUrl(getActivity(), Uri.parse(media.getImageUrl()));
179195
}
180196

197+
/**
198+
* Set the media as user's leaderboard avatar
199+
* @param media
200+
*/
201+
private void setAvatar(Media media) {
202+
if (media.getImageUrl() == null || media.getImageUrl().isEmpty()) {
203+
Timber.d("Media URL not present");
204+
return;
205+
}
206+
ImageUtils.setAvatarFromImageUrl(getActivity(), media.getImageUrl(),
207+
Objects.requireNonNull(sessionManager.getCurrentAccount()).name,
208+
okHttpJsonApiClient, compositeDisposable);
209+
}
210+
181211
@Override
182212
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
183213
if (!editable) { // Disable menu options for editable views

app/src/main/java/fr/free/nrw/commons/mwapi/OkHttpJsonApiClient.java

+96-3
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
package fr.free.nrw.commons.mwapi;
22

3+
import static fr.free.nrw.commons.profile.leaderboard.LeaderboardConstants.LEADERBOARD_END_POINT;
4+
import static fr.free.nrw.commons.profile.leaderboard.LeaderboardConstants.UPDATE_AVATAR_END_POINT;
5+
36
import android.text.TextUtils;
47
import androidx.annotation.NonNull;
58
import com.google.gson.Gson;
6-
import fr.free.nrw.commons.achievements.FeaturedImages;
7-
import fr.free.nrw.commons.achievements.FeedbackResponse;
89
import fr.free.nrw.commons.campaigns.CampaignResponseDTO;
910
import fr.free.nrw.commons.explore.depictions.DepictsClient;
1011
import fr.free.nrw.commons.location.LatLng;
1112
import fr.free.nrw.commons.nearby.Place;
1213
import fr.free.nrw.commons.nearby.model.NearbyResponse;
1314
import fr.free.nrw.commons.nearby.model.NearbyResultItem;
15+
import fr.free.nrw.commons.profile.achievements.FeaturedImages;
16+
import fr.free.nrw.commons.profile.achievements.FeedbackResponse;
17+
import fr.free.nrw.commons.profile.leaderboard.LeaderboardResponse;
18+
import fr.free.nrw.commons.profile.leaderboard.UpdateAvatarResponse;
1419
import fr.free.nrw.commons.upload.FileUtils;
1520
import fr.free.nrw.commons.upload.structure.depictions.DepictedItem;
1621
import fr.free.nrw.commons.utils.ConfigUtils;
@@ -40,6 +45,7 @@ public class OkHttpJsonApiClient {
4045
private final OkHttpClient okHttpClient;
4146
private final DepictsClient depictsClient;
4247
private final HttpUrl wikiMediaToolforgeUrl;
48+
private final HttpUrl wikiMediaTestToolforgeUrl;
4349
private final String sparqlQueryUrl;
4450
private final String campaignsUrl;
4551
private final Gson gson;
@@ -49,17 +55,105 @@ public class OkHttpJsonApiClient {
4955
public OkHttpJsonApiClient(OkHttpClient okHttpClient,
5056
DepictsClient depictsClient,
5157
HttpUrl wikiMediaToolforgeUrl,
58+
HttpUrl wikiMediaTestToolforgeUrl,
5259
String sparqlQueryUrl,
5360
String campaignsUrl,
5461
Gson gson) {
5562
this.okHttpClient = okHttpClient;
5663
this.depictsClient = depictsClient;
5764
this.wikiMediaToolforgeUrl = wikiMediaToolforgeUrl;
65+
this.wikiMediaTestToolforgeUrl = wikiMediaTestToolforgeUrl;
5866
this.sparqlQueryUrl = sparqlQueryUrl;
5967
this.campaignsUrl = campaignsUrl;
6068
this.gson = gson;
6169
}
6270

71+
/**
72+
* The method will gradually calls the leaderboard API and fetches the leaderboard
73+
* @param userName username of leaderboard user
74+
* @param duration duration for leaderboard
75+
* @param category category for leaderboard
76+
* @param limit page size limit for list
77+
* @param offset offset for the list
78+
* @return LeaderboardResponse object
79+
*/
80+
@NonNull
81+
public Observable<LeaderboardResponse> getLeaderboard(String userName, String duration, String category, String limit, String offset) {
82+
final String fetchLeaderboardUrlTemplate = wikiMediaTestToolforgeUrl
83+
+ LEADERBOARD_END_POINT;
84+
String url = String.format(Locale.ENGLISH,
85+
fetchLeaderboardUrlTemplate,
86+
userName,
87+
duration,
88+
category,
89+
limit,
90+
offset);
91+
HttpUrl.Builder urlBuilder = HttpUrl.parse(url).newBuilder();
92+
urlBuilder.addQueryParameter("user", userName);
93+
urlBuilder.addQueryParameter("duration", duration);
94+
urlBuilder.addQueryParameter("category", category);
95+
urlBuilder.addQueryParameter("limit", limit);
96+
urlBuilder.addQueryParameter("offset", offset);
97+
Timber.i("Url %s", urlBuilder.toString());
98+
Request request = new Request.Builder()
99+
.url(urlBuilder.toString())
100+
.build();
101+
return Observable.fromCallable(() -> {
102+
Response response = okHttpClient.newCall(request).execute();
103+
if (response != null && response.body() != null && response.isSuccessful()) {
104+
String json = response.body().string();
105+
if (json == null) {
106+
return new LeaderboardResponse();
107+
}
108+
Timber.d("Response for leaderboard is %s", json);
109+
try {
110+
return gson.fromJson(json, LeaderboardResponse.class);
111+
} catch (Exception e) {
112+
return new LeaderboardResponse();
113+
}
114+
}
115+
return new LeaderboardResponse();
116+
});
117+
}
118+
119+
/**
120+
* This method will update the leaderboard user avatar
121+
* @param username username to update
122+
* @param avatar url of the new avatar
123+
* @return UpdateAvatarResponse object
124+
*/
125+
@NonNull
126+
public Single<UpdateAvatarResponse> setAvatar(String username, String avatar) {
127+
final String urlTemplate = wikiMediaTestToolforgeUrl
128+
+ UPDATE_AVATAR_END_POINT;
129+
return Single.fromCallable(() -> {
130+
String url = String.format(Locale.ENGLISH,
131+
urlTemplate,
132+
username,
133+
avatar);
134+
HttpUrl.Builder urlBuilder = HttpUrl.parse(url).newBuilder();
135+
urlBuilder.addQueryParameter("user", username);
136+
urlBuilder.addQueryParameter("avatar", avatar);
137+
Timber.i("Url %s", urlBuilder.toString());
138+
Request request = new Request.Builder()
139+
.url(urlBuilder.toString())
140+
.build();
141+
Response response = okHttpClient.newCall(request).execute();
142+
if (response != null && response.body() != null && response.isSuccessful()) {
143+
String json = response.body().string();
144+
if (json == null) {
145+
return null;
146+
}
147+
try {
148+
return gson.fromJson(json, UpdateAvatarResponse.class);
149+
} catch (Exception e) {
150+
return new UpdateAvatarResponse();
151+
}
152+
}
153+
return null;
154+
});
155+
}
156+
63157
@NonNull
64158
public Single<Integer> getUploadCount(String userName) {
65159
HttpUrl.Builder urlBuilder = wikiMediaToolforgeUrl.newBuilder();
@@ -145,7 +239,6 @@ public Single<FeedbackResponse> getAchievements(String userName) {
145239
userName);
146240
HttpUrl.Builder urlBuilder = HttpUrl.parse(url).newBuilder();
147241
urlBuilder.addQueryParameter("user", userName);
148-
Timber.i("Url %s", urlBuilder.toString());
149242
Request request = new Request.Builder()
150243
.url(urlBuilder.toString())
151244
.build();

0 commit comments

Comments
 (0)