mirror of
				https://github.com/commons-app/apps-android-commons.git
				synced 2025-10-30 22:34:02 +01:00 
			
		
		
		
	Show wikidata edits done through the app (#2431)
* Show wikidata edits done through the app * Minor changes based on code review
This commit is contained in:
		
							parent
							
								
									aee8839eea
								
							
						
					
					
						commit
						73bb0c52c9
					
				
					 8 changed files with 138 additions and 18 deletions
				
			
		|  | @ -3,7 +3,6 @@ package fr.free.nrw.commons.achievements; | |||
| import android.accounts.Account; | ||||
| import android.annotation.SuppressLint; | ||||
| import android.content.Context; | ||||
| import android.content.DialogInterface; | ||||
| import android.content.Intent; | ||||
| import android.graphics.Bitmap; | ||||
| import android.graphics.drawable.BitmapDrawable; | ||||
|  | @ -27,8 +26,6 @@ import android.widget.TextView; | |||
| 
 | ||||
| import com.dinuscxj.progressbar.CircleProgressBar; | ||||
| 
 | ||||
| import org.w3c.dom.Text; | ||||
| 
 | ||||
| import java.io.File; | ||||
| import java.io.FileOutputStream; | ||||
| import java.io.IOException; | ||||
|  | @ -42,11 +39,10 @@ import butterknife.OnClick; | |||
| import fr.free.nrw.commons.R; | ||||
| import fr.free.nrw.commons.Utils; | ||||
| import fr.free.nrw.commons.auth.SessionManager; | ||||
| import fr.free.nrw.commons.mwapi.MediaWikiApi; | ||||
| import fr.free.nrw.commons.mwapi.OkHttpJsonApiClient; | ||||
| import fr.free.nrw.commons.theme.NavigationBaseActivity; | ||||
| import fr.free.nrw.commons.utils.StringUtils; | ||||
| import fr.free.nrw.commons.utils.ViewUtil; | ||||
| import io.reactivex.Single; | ||||
| import io.reactivex.android.schedulers.AndroidSchedulers; | ||||
| import io.reactivex.disposables.CompositeDisposable; | ||||
| import io.reactivex.schedulers.Schedulers; | ||||
|  | @ -98,6 +94,10 @@ public class AchievementsActivity extends NavigationBaseActivity { | |||
|     TextView imageRevertedText; | ||||
|     @BindView(R.id.images_upload_text_param) | ||||
|     TextView imageUploadedText; | ||||
|     @BindView(R.id.wikidata_edits) | ||||
|     TextView wikidataEditsText; | ||||
| 
 | ||||
| 
 | ||||
|     @Inject | ||||
|     SessionManager sessionManager; | ||||
|     @Inject | ||||
|  | @ -138,6 +138,7 @@ public class AchievementsActivity extends NavigationBaseActivity { | |||
| 
 | ||||
|         hideLayouts(); | ||||
|         setAchievements(); | ||||
|         setWikidataEditCount(); | ||||
|         initDrawer(); | ||||
|     } | ||||
| 
 | ||||
|  | @ -229,6 +230,18 @@ public class AchievementsActivity extends NavigationBaseActivity { | |||
|         } | ||||
|     } | ||||
| 
 | ||||
|     @SuppressLint("CheckResult") | ||||
|     private void setWikidataEditCount() { | ||||
|         String userName = sessionManager.getUserName(); | ||||
|         if (StringUtils.isNullOrWhiteSpace(userName)) { | ||||
|             return; | ||||
|         } | ||||
|         okHttpJsonApiClient.getWikidataEdits(userName) | ||||
|                 .subscribeOn(Schedulers.io()) | ||||
|                 .observeOn(AndroidSchedulers.mainThread()) | ||||
|                 .subscribe(edits -> wikidataEditsText.setText(String.valueOf(edits))); | ||||
|     } | ||||
| 
 | ||||
|     private void showSnackBarWithRetry() { | ||||
|         progressBar.setVisibility(View.GONE); | ||||
|         ViewUtil.showDismissibleSnackBar(findViewById(android.R.id.content), | ||||
|  |  | |||
|  | @ -34,7 +34,9 @@ public class NetworkingModule { | |||
|     private static final String WIKIDATA_SPARQL_QUERY_URL = "https://query.wikidata.org/sparql"; | ||||
|     private final String WIKIMEDIA_CAMPAIGNS_BASE_URL = | ||||
|             "https://raw.githubusercontent.com/commons-app/campaigns/master/campaigns.json"; | ||||
|     private static final String TOOLS_FORGE_URL = "https://tools.wmflabs.org/"; | ||||
|     private static final String TOOLS_FORGE_URL = "https://tools.wmflabs.org/urbanecmbot/commonsmisc"; | ||||
| 
 | ||||
|     private static final String TEST_TOOLS_FORGE_URL = "https://tools.wmflabs.org/commons-android-app/tool-commons-android-app"; | ||||
| 
 | ||||
|     public static final long OK_HTTP_CACHE_SIZE = 10 * 1024 * 1024; | ||||
| 
 | ||||
|  |  | |||
|  | @ -26,6 +26,7 @@ import fr.free.nrw.commons.nearby.model.NearbyResponse; | |||
| import fr.free.nrw.commons.nearby.model.NearbyResultItem; | ||||
| import fr.free.nrw.commons.upload.FileUtils; | ||||
| import fr.free.nrw.commons.utils.DateUtils; | ||||
| import fr.free.nrw.commons.wikidata.model.GetWikidataEditCountResponse; | ||||
| import io.reactivex.Observable; | ||||
| import io.reactivex.Single; | ||||
| import okhttp3.HttpUrl; | ||||
|  | @ -63,7 +64,7 @@ public class OkHttpJsonApiClient { | |||
|     public Single<Integer> getUploadCount(String userName) { | ||||
|         HttpUrl.Builder urlBuilder = wikiMediaToolforgeUrl.newBuilder(); | ||||
|         urlBuilder | ||||
|                 .addPathSegments("urbanecmbot/commonsmisc/uploadsbyuser.py") | ||||
|                 .addPathSegments("/uploadsbyuser.py") | ||||
|                 .addQueryParameter("user", userName); | ||||
|         Request request = new Request.Builder() | ||||
|                 .url(urlBuilder.build()) | ||||
|  | @ -72,12 +73,38 @@ public class OkHttpJsonApiClient { | |||
|         return Single.fromCallable(() -> { | ||||
|             Response response = okHttpClient.newCall(request).execute(); | ||||
|             if (response != null && response.isSuccessful()) { | ||||
| 
 | ||||
|                 return Integer.parseInt(response.body().string().trim()); | ||||
|             } | ||||
|             return 0; | ||||
|         }); | ||||
|     } | ||||
| 
 | ||||
|     @NonNull | ||||
|     public Single<Integer> getWikidataEdits(String userName) { | ||||
|         HttpUrl.Builder urlBuilder = wikiMediaToolforgeUrl.newBuilder(); | ||||
|         urlBuilder | ||||
|                 .addPathSegments("/wikidataedits.py") | ||||
|                 .addQueryParameter("user", userName); | ||||
|         Request request = new Request.Builder() | ||||
|                 .url(urlBuilder.build()) | ||||
|                 .build(); | ||||
| 
 | ||||
|         return Single.fromCallable(() -> { | ||||
|             Response response = okHttpClient.newCall(request).execute(); | ||||
|             if (response != null && | ||||
|                     response.isSuccessful() && response.body() != null) { | ||||
|                 String json = response.body().string(); | ||||
|                 if (json == null) { | ||||
|                     return 0; | ||||
|                 } | ||||
|                 GetWikidataEditCountResponse countResponse = gson.fromJson(json, GetWikidataEditCountResponse.class); | ||||
|                 return countResponse.getWikidataEditCount(); | ||||
|             } | ||||
|             return 0; | ||||
|         }); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * This takes userName as input, which is then used to fetch the feedback/achievements | ||||
|      * statistics using OkHttp and JavaRx. This function return JSONObject | ||||
|  | @ -87,7 +114,7 @@ public class OkHttpJsonApiClient { | |||
|      */ | ||||
|     public Single<FeedbackResponse> getAchievements(String userName) { | ||||
|         final String fetchAchievementUrlTemplate = | ||||
|                 wikiMediaToolforgeUrl + "urbanecmbot/commonsmisc/feedback.py"; | ||||
|                 wikiMediaToolforgeUrl + "/feedback.py"; | ||||
|         return Single.fromCallable(() -> { | ||||
|             String url = String.format( | ||||
|                     Locale.ENGLISH, | ||||
|  |  | |||
|  | @ -0,0 +1,16 @@ | |||
| package fr.free.nrw.commons.wikidata.model; | ||||
| 
 | ||||
| import com.google.gson.annotations.SerializedName; | ||||
| 
 | ||||
| public class GetWikidataEditCountResponse { | ||||
|     @SerializedName("edits") | ||||
|     private final int wikidataEditCount; | ||||
| 
 | ||||
|     public GetWikidataEditCountResponse(int wikidataEditCount) { | ||||
|         this.wikidataEditCount = wikidataEditCount; | ||||
|     } | ||||
| 
 | ||||
|     public int getWikidataEditCount() { | ||||
|         return wikidataEditCount; | ||||
|     } | ||||
| } | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Vivek Maskara
						Vivek Maskara