mirror of
				https://github.com/commons-app/apps-android-commons.git
				synced 2025-10-31 06:43:56 +01:00 
			
		
		
		
	Made a pass through the code to introduce lambdas / method references in the places the Android Studio suggested.
This commit is contained in:
		
							parent
							
								
									3824f31ef9
								
							
						
					
					
						commit
						4796557fb7
					
				
					 25 changed files with 206 additions and 374 deletions
				
			
		|  | @ -29,6 +29,7 @@ import fr.free.nrw.commons.R; | |||
| import fr.free.nrw.commons.nearby.NearbyActivity; | ||||
| import timber.log.Timber; | ||||
| 
 | ||||
| import static android.Manifest.permission.READ_EXTERNAL_STORAGE; | ||||
| import static android.app.Activity.RESULT_OK; | ||||
| 
 | ||||
| public class ContributionsListFragment extends Fragment { | ||||
|  | @ -110,11 +111,11 @@ public class ContributionsListFragment extends Fragment { | |||
| 
 | ||||
|                     // Here, thisActivity is the current activity | ||||
|                     if (ContextCompat.checkSelfPermission(getActivity(), | ||||
|                             Manifest.permission.READ_EXTERNAL_STORAGE) | ||||
|                             READ_EXTERNAL_STORAGE) | ||||
|                             != PackageManager.PERMISSION_GRANTED) { | ||||
| 
 | ||||
|                         // Should we show an explanation? | ||||
|                         if (shouldShowRequestPermissionRationale(Manifest.permission.READ_EXTERNAL_STORAGE)) { | ||||
|                         if (shouldShowRequestPermissionRationale(READ_EXTERNAL_STORAGE)) { | ||||
| 
 | ||||
|                             // Show an explanation to the user *asynchronously* -- don't block | ||||
|                             // this thread waiting for the user's response! After the user | ||||
|  | @ -122,15 +123,9 @@ public class ContributionsListFragment extends Fragment { | |||
| 
 | ||||
|                             new AlertDialog.Builder(getActivity()) | ||||
|                                     .setMessage(getString(R.string.storage_permission_rationale)) | ||||
|                                     .setPositiveButton("OK", new DialogInterface.OnClickListener() { | ||||
|                                         @Override | ||||
|                                         public void onClick(DialogInterface dialog, int which) { | ||||
| 
 | ||||
|                                             requestPermissions( | ||||
|                                                     new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, | ||||
|                                                     1); | ||||
|                                             dialog.dismiss(); | ||||
|                                         } | ||||
|                                     .setPositiveButton("OK", (dialog, which) -> { | ||||
|                                         requestPermissions(new String[]{READ_EXTERNAL_STORAGE}, 1); | ||||
|                                         dialog.dismiss(); | ||||
|                                     }) | ||||
|                                     .setNegativeButton("Cancel", null) | ||||
|                                     .create() | ||||
|  | @ -140,7 +135,7 @@ public class ContributionsListFragment extends Fragment { | |||
| 
 | ||||
|                             // No explanation needed, we can request the permission. | ||||
| 
 | ||||
|                             requestPermissions(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, | ||||
|                             requestPermissions(new String[]{READ_EXTERNAL_STORAGE}, | ||||
|                                     1); | ||||
| 
 | ||||
|                             // MY_PERMISSIONS_REQUEST_READ_CONTACTS is an | ||||
|  |  | |||
|  | @ -14,10 +14,10 @@ import fr.free.nrw.commons.concurrency.BackgroundPoolExceptionHandler; | |||
| import fr.free.nrw.commons.concurrency.ThreadPoolExecutorService; | ||||
| import timber.log.Timber; | ||||
| 
 | ||||
| public class UploadCountClient { | ||||
| class UploadCountClient { | ||||
|     private ThreadPoolExecutorService threadPoolExecutor; | ||||
| 
 | ||||
|     public UploadCountClient() { | ||||
|     UploadCountClient() { | ||||
|         threadPoolExecutor = new ThreadPoolExecutorService.Builder("bg-pool") | ||||
|                 .setPoolSize(Runtime.getRuntime().availableProcessors()) | ||||
|                 .setExceptionHandler(new BackgroundPoolExceptionHandler()) | ||||
|  | @ -27,29 +27,26 @@ public class UploadCountClient { | |||
|     private static final String UPLOAD_COUNT_URL_TEMPLATE = | ||||
|             "https://tools.wmflabs.org/urbanecmbot/uploadsbyuser/uploadsbyuser.py?user=%s"; | ||||
| 
 | ||||
|     public ListenableFuture<Integer> getUploadCount(final String userName) { | ||||
|     ListenableFuture<Integer> getUploadCount(final String userName) { | ||||
|         final SettableFuture<Integer> future = SettableFuture.create(); | ||||
|         threadPoolExecutor.schedule(new Runnable() { | ||||
|             @Override | ||||
|             public void run() { | ||||
|                 URL url; | ||||
|         threadPoolExecutor.schedule(() -> { | ||||
|             URL url; | ||||
|             try { | ||||
|                 url = new URL(String.format(Locale.ENGLISH, UPLOAD_COUNT_URL_TEMPLATE, | ||||
|                         new PageTitle(userName).getText())); | ||||
|                 HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection(); | ||||
|                 try { | ||||
|                     url = new URL(String.format(Locale.ENGLISH, UPLOAD_COUNT_URL_TEMPLATE, | ||||
|                             new PageTitle(userName).getText())); | ||||
|                     HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection(); | ||||
|                     try { | ||||
|                         BufferedReader bufferedReader = new BufferedReader(new | ||||
|                                 InputStreamReader(urlConnection.getInputStream())); | ||||
|                         String uploadCount = bufferedReader.readLine(); | ||||
|                         bufferedReader.close(); | ||||
|                         future.set(Integer.parseInt(uploadCount)); | ||||
|                     } finally { | ||||
|                         urlConnection.disconnect(); | ||||
|                     } | ||||
|                 } catch (Exception e) { | ||||
|                     Timber.e("Error getting upload count Error", e); | ||||
|                     future.setException(e); | ||||
|                     BufferedReader bufferedReader = new BufferedReader(new | ||||
|                             InputStreamReader(urlConnection.getInputStream())); | ||||
|                     String uploadCount = bufferedReader.readLine(); | ||||
|                     bufferedReader.close(); | ||||
|                     future.set(Integer.parseInt(uploadCount)); | ||||
|                 } finally { | ||||
|                     urlConnection.disconnect(); | ||||
|                 } | ||||
|             } catch (Exception e) { | ||||
|                 Timber.e("Error getting upload count Error", e); | ||||
|                 future.setException(e); | ||||
|             } | ||||
|         }); | ||||
|         return future; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Paul Hawke
						Paul Hawke