mirror of
				https://github.com/commons-app/apps-android-commons.git
				synced 2025-10-30 22:34:02 +01:00 
			
		
		
		
	Make license in MediaDetail clickable
This commit is contained in:
		
							parent
							
								
									0a6e8b0cc8
								
							
						
					
					
						commit
						1044fe13ae
					
				
					 2 changed files with 32 additions and 1 deletions
				
			
		|  | @ -1,5 +1,7 @@ | |||
| package fr.free.nrw.commons; | ||||
| 
 | ||||
| import android.support.annotation.Nullable; | ||||
| 
 | ||||
| public class License { | ||||
|     String key; | ||||
|     String template; | ||||
|  | @ -36,7 +38,7 @@ public class License { | |||
|         } | ||||
|     } | ||||
| 
 | ||||
|     public String getUrl(String language) { | ||||
|     public @Nullable String getUrl(String language) { | ||||
|         if (url == null) { | ||||
|             return null; | ||||
|         } else { | ||||
|  |  | |||
|  | @ -2,8 +2,10 @@ package fr.free.nrw.commons.media; | |||
| 
 | ||||
| import android.content.Intent; | ||||
| import android.database.DataSetObserver; | ||||
| import android.net.Uri; | ||||
| import android.os.AsyncTask; | ||||
| import android.os.Bundle; | ||||
| import android.support.annotation.Nullable; | ||||
| import android.support.v4.app.Fragment; | ||||
| import android.util.TypedValue; | ||||
| import android.view.LayoutInflater; | ||||
|  | @ -18,6 +20,7 @@ import java.io.IOException; | |||
| import java.text.SimpleDateFormat; | ||||
| import java.util.ArrayList; | ||||
| import java.util.Date; | ||||
| import java.util.Locale; | ||||
| 
 | ||||
| import fr.free.nrw.commons.License; | ||||
| import fr.free.nrw.commons.LicenseList; | ||||
|  | @ -228,6 +231,14 @@ public class MediaDetailFragment extends Fragment { | |||
|                         categoryNames.add(getString(R.string.detail_panel_cats_none)); | ||||
|                     } | ||||
|                     rebuildCatList(); | ||||
| 
 | ||||
|                     // Set hyperlinks | ||||
|                     license.setOnClickListener(new View.OnClickListener() { | ||||
|                         @Override | ||||
|                         public void onClick(View v) { | ||||
|                             openWebBrowser(licenseLink(media)); | ||||
|                         } | ||||
|                     }); | ||||
|                 } else { | ||||
|                     Timber.d("Failed to load photo details."); | ||||
|                 } | ||||
|  | @ -342,4 +353,22 @@ public class MediaDetailFragment extends Fragment { | |||
|     private String prettyCoordinates(Media media) { | ||||
|         return media.getCoordinates(); | ||||
|     } | ||||
| 
 | ||||
|     private @Nullable String licenseLink(Media media) { | ||||
|         String licenseKey = media.getLicense(); | ||||
|         if (licenseKey == null || licenseKey.equals("")) { | ||||
|             return null; | ||||
|         } | ||||
|         License licenseObj = licenseList.get(licenseKey); | ||||
|         if (licenseObj == null) { | ||||
|             return null; | ||||
|         } else { | ||||
|             return licenseObj.getUrl(Locale.getDefault().getLanguage()); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     private void openWebBrowser(String url) { | ||||
|         Intent browser = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); | ||||
|         startActivity(browser); | ||||
|     } | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Mikel
						Mikel