mirror of
				https://github.com/commons-app/apps-android-commons.git
				synced 2025-10-31 06:43:56 +01:00 
			
		
		
		
	Convert top level "Utils" class to kotlin (#6364)
* Unused class removed * Convert BasePresenter to kotlin * Removed redundent class * Move the Utils class into the utils package * Inline the creation of a page title object * Move license utilities into their own file * Inline app rating since its only ever used in 1 place * Moved GeoCoordinates utilities into their own class * Moved Monuments related utils into their own class * Moved screen capture into its own util class * Moved handleWebUrl to its own utility class * Moved fixExtension to its own class * Moved clipboard copy into its own utility class * Renames class to match remaining utility method * Convert UnderlineUtils to kotlin * Converted the copy-to-clipboard utility to kotlin * Converted license name and url lookup to kotlin * Converted fixExtension to kotlin * Convert handleGeoCoordinates to kotlin * Monument utils converted to kotlin * Convert then inline screeen capture in kotlin * Convert handleWebUrl to kotlin
This commit is contained in:
		
							parent
							
								
									4befff8f42
								
							
						
					
					
						commit
						3bd0ec4466
					
				
					 44 changed files with 387 additions and 519 deletions
				
			
		|  | @ -1,11 +1,11 @@ | |||
| package fr.free.nrw.commons.upload | ||||
| 
 | ||||
| import android.content.Context | ||||
| import fr.free.nrw.commons.Utils | ||||
| import fr.free.nrw.commons.contributions.Contribution | ||||
| import fr.free.nrw.commons.filepicker.UploadableFile.DateTimeWithSource | ||||
| import fr.free.nrw.commons.settings.Prefs.Licenses | ||||
| import fr.free.nrw.commons.utils.ConfigUtils.getVersionNameWithSha | ||||
| import fr.free.nrw.commons.utils.getWikiLovesMonumentsYear | ||||
| import org.apache.commons.lang3.StringUtils | ||||
| import java.text.SimpleDateFormat | ||||
| import java.util.Calendar | ||||
|  | @ -49,7 +49,7 @@ class PageContentsCreator @Inject constructor(private val context: Context) { | |||
|                 String.format( | ||||
|                     Locale.ENGLISH, | ||||
|                     "{{Wiki Loves Monuments %d|1= %s}}\n", | ||||
|                     Utils.getWikiLovesMonumentsYear(Calendar.getInstance()), | ||||
|                     getWikiLovesMonumentsYear(Calendar.getInstance()), | ||||
|                     contribution.countryCode | ||||
|                 ) | ||||
|             ) | ||||
|  |  | |||
|  | @ -1,10 +1,10 @@ | |||
| package fr.free.nrw.commons.upload | ||||
| 
 | ||||
| import android.net.Uri | ||||
| import fr.free.nrw.commons.Utils | ||||
| import fr.free.nrw.commons.filepicker.MimeTypeMapWrapper.Companion.getExtensionFromMimeType | ||||
| import fr.free.nrw.commons.nearby.Place | ||||
| import fr.free.nrw.commons.utils.ImageUtils | ||||
| import fr.free.nrw.commons.utils.fixExtension | ||||
| 
 | ||||
| class UploadItem( | ||||
|     var mediaUri: Uri?, | ||||
|  | @ -32,7 +32,7 @@ class UploadItem( | |||
|      * languages have been entered, the first language is used. | ||||
|      */ | ||||
|     val filename: String | ||||
|         get() = Utils.fixExtension( | ||||
|         get() = fixExtension( | ||||
|             uploadMediaDetails[0].captionText, | ||||
|             getExtensionFromMimeType(mimeType) | ||||
|         ) | ||||
|  |  | |||
|  | @ -16,11 +16,13 @@ import android.widget.AdapterView | |||
| import android.widget.ArrayAdapter | ||||
| import android.widget.TextView | ||||
| import fr.free.nrw.commons.R | ||||
| import fr.free.nrw.commons.Utils | ||||
| import fr.free.nrw.commons.databinding.FragmentMediaLicenseBinding | ||||
| import fr.free.nrw.commons.upload.UploadActivity | ||||
| import fr.free.nrw.commons.upload.UploadBaseFragment | ||||
| import fr.free.nrw.commons.utils.DialogUtil.showAlertDialog | ||||
| import fr.free.nrw.commons.utils.handleWebUrl | ||||
| import fr.free.nrw.commons.utils.toLicenseName | ||||
| import fr.free.nrw.commons.utils.toLicenseUrl | ||||
| import timber.log.Timber | ||||
| import javax.inject.Inject | ||||
| 
 | ||||
|  | @ -126,20 +128,20 @@ class MediaLicenseFragment : UploadBaseFragment(), MediaLicenseContract.View { | |||
|     } | ||||
| 
 | ||||
|     override fun setSelectedLicense(license: String?) { | ||||
|         var position = licenses!!.indexOf(getString(Utils.licenseNameFor(license))) | ||||
|         var position = license?.let { licenses!!.indexOf(getString(it.toLicenseName())) } ?: -1 | ||||
|         // Check if position is valid | ||||
|         if (position < 0) { | ||||
|             Timber.d("Invalid position: %d. Using default licenses", position) | ||||
|             position = licenses!!.size - 1 | ||||
|         } else { | ||||
|             Timber.d("Position: %d %s", position, getString(Utils.licenseNameFor(license))) | ||||
|         } | ||||
|         binding.spinnerLicenseList.setSelection(position) | ||||
|     } | ||||
| 
 | ||||
|     override fun updateLicenseSummary(selectedLicense: String?, numberOfItems: Int) { | ||||
|         val licenseHyperLink = "<a href='" + Utils.licenseUrlFor(selectedLicense) + "'>" + | ||||
|                 getString(Utils.licenseNameFor(selectedLicense)) + "</a><br>" | ||||
|         if (selectedLicense == null) return | ||||
| 
 | ||||
|         val licenseHyperLink = "<a href='" + selectedLicense.toLicenseUrl() + "'>" + | ||||
|                 getString(selectedLicense.toLicenseName()) + "</a><br>" | ||||
| 
 | ||||
|         setTextViewHTML( | ||||
|             binding.tvShareLicenseSummary, resources | ||||
|  | @ -184,7 +186,7 @@ class MediaLicenseFragment : UploadBaseFragment(), MediaLicenseContract.View { | |||
|     } | ||||
| 
 | ||||
|     private fun launchBrowser(hyperLink: String) = | ||||
|         Utils.handleWebUrl(context, Uri.parse(hyperLink)) | ||||
|         handleWebUrl(requireContext(), Uri.parse(hyperLink)) | ||||
| 
 | ||||
|     override fun onDestroyView() { | ||||
|         presenter.onDetachView() | ||||
|  |  | |||
|  | @ -1,9 +1,9 @@ | |||
| package fr.free.nrw.commons.upload.license | ||||
| 
 | ||||
| import fr.free.nrw.commons.Utils | ||||
| import fr.free.nrw.commons.kvstore.JsonKvStore | ||||
| import fr.free.nrw.commons.repository.UploadRepository | ||||
| import fr.free.nrw.commons.settings.Prefs | ||||
| import fr.free.nrw.commons.utils.toLicenseName | ||||
| import timber.log.Timber | ||||
| import java.lang.reflect.Method | ||||
| import java.lang.reflect.Proxy | ||||
|  | @ -34,12 +34,14 @@ class MediaLicensePresenter @Inject constructor( | |||
|         val licenses = repository.getLicenses() | ||||
|         view.setLicenses(licenses) | ||||
| 
 | ||||
|         var selectedLicense = defaultKVStore.getString( | ||||
|         //CC_BY_SA_4 is the default one used by the commons web app | ||||
|         var selectedLicense: String = defaultKVStore.getString( | ||||
|             Prefs.DEFAULT_LICENSE, | ||||
|             Prefs.Licenses.CC_BY_SA_4 | ||||
|         ) //CC_BY_SA_4 is the default one used by the commons web app | ||||
|         ) ?: Prefs.Licenses.CC_BY_SA_4 | ||||
| 
 | ||||
|         try { //I have to make sure that the stored default license was not one of the deprecated one's | ||||
|             Utils.licenseNameFor(selectedLicense) | ||||
|             selectedLicense.toLicenseName() | ||||
|         } catch (exception: IllegalStateException) { | ||||
|             Timber.e(exception) | ||||
|             selectedLicense = Prefs.Licenses.CC_BY_SA_4 | ||||
|  |  | |||
|  | @ -54,7 +54,7 @@ interface UploadMediaDetailsContract { | |||
|         fun showBadImagePopup(errorCode: Int, index: Int, uploadItem: UploadItem) | ||||
|     } | ||||
| 
 | ||||
|     interface UserActionListener : BasePresenter<View?> { | ||||
|     interface UserActionListener : BasePresenter<View> { | ||||
|         fun setupBasicKvStoreFactory(factory: (String) -> BasicKvStore) | ||||
| 
 | ||||
|         fun receiveImage( | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Paul Hawke
						Paul Hawke