mirror of
				https://github.com/commons-app/apps-android-commons.git
				synced 2025-10-31 14:53:59 +01:00 
			
		
		
		
	Migrated FeedbackContentCreator to kotlin
This commit is contained in:
		
							parent
							
								
									0fa7ee480f
								
							
						
					
					
						commit
						6e5fa2cc52
					
				
					 2 changed files with 111 additions and 107 deletions
				
			
		|  | @ -1,120 +1,123 @@ | ||||||
| package fr.free.nrw.commons.feedback; | package fr.free.nrw.commons.feedback | ||||||
| 
 | 
 | ||||||
| import android.content.Context; | import android.content.Context | ||||||
| import fr.free.nrw.commons.R; | import fr.free.nrw.commons.R | ||||||
| import fr.free.nrw.commons.auth.AccountUtilKt; | import fr.free.nrw.commons.auth.getUserName | ||||||
| import fr.free.nrw.commons.feedback.model.Feedback; | import fr.free.nrw.commons.feedback.model.Feedback | ||||||
| import fr.free.nrw.commons.utils.LangCodeUtils; | import fr.free.nrw.commons.utils.LangCodeUtils.getLocalizedResources | ||||||
| import java.util.Locale; | import java.text.SimpleDateFormat | ||||||
| import java.text.SimpleDateFormat; | import java.util.Date | ||||||
| import java.util.Date; | import java.util.Locale | ||||||
| import java.util.TimeZone; | import java.util.TimeZone | ||||||
| 
 | 
 | ||||||
| /** | class FeedbackContentCreator(context: Context, feedback: Feedback) { | ||||||
|  * Creates a wikimedia recognizable format |     private var sectionTitleBuilder = StringBuilder() | ||||||
|  * from feedback information |     private var sectionTextBuilder = StringBuilder() | ||||||
|  */ |     init { | ||||||
| public class FeedbackContentCreator { |         // Localization is not needed here | ||||||
|     private StringBuilder sectionTextBuilder; |         // because this ends up on a page where developers read the feedback, | ||||||
|     private StringBuilder sectionTitleBuilder; |         // so English is the most convenient. | ||||||
|     private Feedback feedback; |  | ||||||
|     private Context context; |  | ||||||
| 
 |  | ||||||
|     public FeedbackContentCreator(Context context, Feedback feedback) { |  | ||||||
|         this.feedback = feedback; |  | ||||||
|         this.context = context; |  | ||||||
|         init(); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     /** |  | ||||||
|      * Initializes the string buffer object to append content from feedback object |  | ||||||
|      */ |  | ||||||
|     public void init() { |  | ||||||
|         // Localization is not needed here, because this ends up on a page where developers read the feedback, so English is the most convenient. |  | ||||||
| 
 |  | ||||||
|         /* |  | ||||||
|          * Construct the feedback section title |  | ||||||
|          */ |  | ||||||
| 
 | 
 | ||||||
|         //Get the UTC Date and Time and add it to the Title |         //Get the UTC Date and Time and add it to the Title | ||||||
|         final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss", Locale.ENGLISH); |         val dateFormat = SimpleDateFormat("yyyy/MM/dd HH:mm:ss", Locale.ENGLISH) | ||||||
|         dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); |         dateFormat.timeZone = TimeZone.getTimeZone("UTC") | ||||||
|         final String UTC_FormattedDate = dateFormat.format(new Date()); |         val utcFormattedDate = dateFormat.format(Date()) | ||||||
| 
 | 
 | ||||||
|         sectionTitleBuilder = new StringBuilder(); |         // Construct the feedback section title | ||||||
|         sectionTitleBuilder.append("Feedback from  "); |         sectionTitleBuilder.append("Feedback from  ") | ||||||
|         sectionTitleBuilder.append(AccountUtilKt.getUserName(context)); |         sectionTitleBuilder.append(getUserName(context)) | ||||||
|         sectionTitleBuilder.append(" for version "); |         sectionTitleBuilder.append(" for version ") | ||||||
|         sectionTitleBuilder.append(feedback.getVersion()); |         sectionTitleBuilder.append(feedback.version) | ||||||
|         sectionTitleBuilder.append(" on "); |         sectionTitleBuilder.append(" on ") | ||||||
|         sectionTitleBuilder.append(UTC_FormattedDate); |         sectionTitleBuilder.append(utcFormattedDate) | ||||||
| 
 |          | ||||||
|         /* |         // Construct the feedback section text | ||||||
|          * Construct the feedback section text |         sectionTextBuilder = StringBuilder() | ||||||
|          */ |         sectionTextBuilder.append("\n") | ||||||
|         sectionTextBuilder = new StringBuilder(); |         sectionTextBuilder.append(feedback.title) | ||||||
|         sectionTextBuilder.append("\n"); |         sectionTextBuilder.append("\n") | ||||||
|         sectionTextBuilder.append(feedback.getTitle()); |         sectionTextBuilder.append("\n") | ||||||
|         sectionTextBuilder.append("\n"); |         if (feedback.apiLevel != null) { | ||||||
|         sectionTextBuilder.append("\n"); |             sectionTextBuilder.append("* ") | ||||||
|         if (feedback.getApiLevel() != null) { |             sectionTextBuilder.append( | ||||||
|             sectionTextBuilder.append("* "); |                 getLocalizedResources( | ||||||
|             sectionTextBuilder.append(LangCodeUtils.getLocalizedResources(context, |                     context, | ||||||
|                 Locale.ENGLISH).getString(R.string.api_level)); |                     Locale.ENGLISH | ||||||
|             sectionTextBuilder.append(": "); |                 ).getString(R.string.api_level) | ||||||
|             sectionTextBuilder.append(feedback.getApiLevel()); |             ) | ||||||
|             sectionTextBuilder.append("\n"); |             sectionTextBuilder.append(": ") | ||||||
|  |             sectionTextBuilder.append(feedback.apiLevel) | ||||||
|  |             sectionTextBuilder.append("\n") | ||||||
|         } |         } | ||||||
|         if (feedback.getAndroidVersion() != null) { |         if (feedback.androidVersion != null) { | ||||||
|             sectionTextBuilder.append("* "); |             sectionTextBuilder.append("* ") | ||||||
|             sectionTextBuilder.append(LangCodeUtils.getLocalizedResources(context, |             sectionTextBuilder.append( | ||||||
|                 Locale.ENGLISH).getString(R.string.android_version)); |                 getLocalizedResources( | ||||||
|             sectionTextBuilder.append(": "); |                     context, | ||||||
|             sectionTextBuilder.append(feedback.getAndroidVersion()); |                     Locale.ENGLISH | ||||||
|             sectionTextBuilder.append("\n"); |                 ).getString(R.string.android_version) | ||||||
|  |             ) | ||||||
|  |             sectionTextBuilder.append(": ") | ||||||
|  |             sectionTextBuilder.append(feedback.androidVersion) | ||||||
|  |             sectionTextBuilder.append("\n") | ||||||
|         } |         } | ||||||
|         if (feedback.getDeviceManufacturer() != null) { |         if (feedback.deviceManufacturer != null) { | ||||||
|             sectionTextBuilder.append("* "); |             sectionTextBuilder.append("* ") | ||||||
|             sectionTextBuilder.append(LangCodeUtils.getLocalizedResources(context, |             sectionTextBuilder.append( | ||||||
|                 Locale.ENGLISH).getString(R.string.device_manufacturer)); |                 getLocalizedResources( | ||||||
|             sectionTextBuilder.append(": "); |                     context, | ||||||
|             sectionTextBuilder.append(feedback.getDeviceManufacturer()); |                     Locale.ENGLISH | ||||||
|             sectionTextBuilder.append("\n"); |                 ).getString(R.string.device_manufacturer) | ||||||
|  |             ) | ||||||
|  |             sectionTextBuilder.append(": ") | ||||||
|  |             sectionTextBuilder.append(feedback.deviceManufacturer) | ||||||
|  |             sectionTextBuilder.append("\n") | ||||||
|         } |         } | ||||||
|         if (feedback.getDeviceModel() != null) { |         if (feedback.deviceModel != null) { | ||||||
|             sectionTextBuilder.append("* "); |             sectionTextBuilder.append("* ") | ||||||
|             sectionTextBuilder.append(LangCodeUtils.getLocalizedResources(context, |             sectionTextBuilder.append( | ||||||
|                 Locale.ENGLISH).getString(R.string.device_model)); |                 getLocalizedResources( | ||||||
|             sectionTextBuilder.append(": "); |                     context, | ||||||
|             sectionTextBuilder.append(feedback.getDeviceModel()); |                     Locale.ENGLISH | ||||||
|             sectionTextBuilder.append("\n"); |                 ).getString(R.string.device_model) | ||||||
|  |             ) | ||||||
|  |             sectionTextBuilder.append(": ") | ||||||
|  |             sectionTextBuilder.append(feedback.deviceModel) | ||||||
|  |             sectionTextBuilder.append("\n") | ||||||
|         } |         } | ||||||
|         if (feedback.getDevice() != null) { |         if (feedback.device != null) { | ||||||
|             sectionTextBuilder.append("* "); |             sectionTextBuilder.append("* ") | ||||||
|             sectionTextBuilder.append(LangCodeUtils.getLocalizedResources(context, |             sectionTextBuilder.append( | ||||||
|                 Locale.ENGLISH).getString(R.string.device_name)); |                 getLocalizedResources( | ||||||
|             sectionTextBuilder.append(": "); |                     context, | ||||||
|             sectionTextBuilder.append(feedback.getDevice()); |                     Locale.ENGLISH | ||||||
|             sectionTextBuilder.append("\n"); |                 ).getString(R.string.device_name) | ||||||
|  |             ) | ||||||
|  |             sectionTextBuilder.append(": ") | ||||||
|  |             sectionTextBuilder.append(feedback.device) | ||||||
|  |             sectionTextBuilder.append("\n") | ||||||
|         } |         } | ||||||
|         if (feedback.getNetworkType() != null) { |         if (feedback.networkType != null) { | ||||||
|             sectionTextBuilder.append("* "); |             sectionTextBuilder.append("* ") | ||||||
|             sectionTextBuilder.append(LangCodeUtils.getLocalizedResources(context, |             sectionTextBuilder.append( | ||||||
|                 Locale.ENGLISH).getString(R.string.network_type)); |                 getLocalizedResources( | ||||||
|             sectionTextBuilder.append(": "); |                     context, | ||||||
|             sectionTextBuilder.append(feedback.getNetworkType()); |                     Locale.ENGLISH | ||||||
|             sectionTextBuilder.append("\n"); |                 ).getString(R.string.network_type) | ||||||
|  |             ) | ||||||
|  |             sectionTextBuilder.append(": ") | ||||||
|  |             sectionTextBuilder.append(feedback.networkType) | ||||||
|  |             sectionTextBuilder.append("\n") | ||||||
|         } |         } | ||||||
|         sectionTextBuilder.append("~~~~"); |         sectionTextBuilder.append("~~~~") | ||||||
|         sectionTextBuilder.append("\n"); |         sectionTextBuilder.append("\n") | ||||||
| 
 |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public String getSectionText() { |     fun getSectionText(): String { | ||||||
|         return sectionTextBuilder.toString(); |         return sectionTextBuilder.toString() | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public String getSectionTitle() { |     fun getSectionTitle(): String { | ||||||
|         return sectionTitleBuilder.toString(); |         return sectionTitleBuilder.toString() | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | @ -10,7 +10,6 @@ import android.os.Bundle | ||||||
| import android.view.LayoutInflater | import android.view.LayoutInflater | ||||||
| import android.view.View | import android.view.View | ||||||
| import android.view.ViewGroup | import android.view.ViewGroup | ||||||
| import android.widget.TextView |  | ||||||
| import android.widget.Toast | import android.widget.Toast | ||||||
| import androidx.appcompat.app.AlertDialog | import androidx.appcompat.app.AlertDialog | ||||||
| import com.google.android.material.bottomsheet.BottomSheetDialogFragment | import com.google.android.material.bottomsheet.BottomSheetDialogFragment | ||||||
|  | @ -160,8 +159,10 @@ class MoreBottomSheetFragment : BottomSheetDialogFragment() { | ||||||
| 
 | 
 | ||||||
|         val single = pageEditClient.createNewSection( |         val single = pageEditClient.createNewSection( | ||||||
|             "Commons:Mobile_app/Feedback", |             "Commons:Mobile_app/Feedback", | ||||||
|             feedbackContentCreator.sectionTitle, |             feedbackContentCreator.getSectionTitle(), | ||||||
|             feedbackContentCreator.sectionText, | //            feedbackContentCreator.sectionTitle, | ||||||
|  |             feedbackContentCreator.getSectionText(), | ||||||
|  | //            feedbackContentCreator.sectionText, | ||||||
|             "New feedback on version ${feedback.version} of the app" |             "New feedback on version ${feedback.version} of the app" | ||||||
|         ) |         ) | ||||||
|             .flatMapSingle { Single.just(it) } |             .flatMapSingle { Single.just(it) } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Neel Doshi
						Neel Doshi