mirror of
				https://github.com/commons-app/apps-android-commons.git
				synced 2025-10-30 22:34:02 +01:00 
			
		
		
		
	* Fixed issue #2291 * resolved codacy issue * settings * removed unwanted commemts
This commit is contained in:
		
							parent
							
								
									73bb0c52c9
								
							
						
					
					
						commit
						635047ded2
					
				
					 2 changed files with 52 additions and 26 deletions
				
			
		|  | @ -2,12 +2,15 @@ package fr.free.nrw.commons.settings; | |||
| 
 | ||||
| import android.Manifest; | ||||
| import android.app.AlertDialog; | ||||
| import android.content.SharedPreferences; | ||||
| import android.net.Uri; | ||||
| import android.os.Bundle; | ||||
| import android.preference.EditTextPreference; | ||||
| import android.preference.Preference; | ||||
| import android.preference.PreferenceFragment; | ||||
| import android.preference.SwitchPreference; | ||||
| import android.text.Editable; | ||||
| import android.text.TextWatcher; | ||||
| 
 | ||||
| import com.karumi.dexter.Dexter; | ||||
| import com.karumi.dexter.listener.PermissionGrantedResponse; | ||||
|  | @ -24,12 +27,15 @@ import fr.free.nrw.commons.logging.CommonsLogSender; | |||
| import fr.free.nrw.commons.utils.PermissionUtils; | ||||
| import fr.free.nrw.commons.utils.ViewUtil; | ||||
| 
 | ||||
| import static android.R.*; | ||||
| 
 | ||||
| public class SettingsFragment extends PreferenceFragment { | ||||
| 
 | ||||
|     @Inject | ||||
|     @Named("default_preferences") | ||||
|     BasicKvStore defaultKvStore; | ||||
|     @Inject CommonsLogSender commonsLogSender; | ||||
|     @Inject | ||||
|     CommonsLogSender commonsLogSender; | ||||
| 
 | ||||
|     @Override | ||||
|     public void onCreate(Bundle savedInstanceState) { | ||||
|  | @ -61,32 +67,48 @@ public class SettingsFragment extends PreferenceFragment { | |||
|         int uploads = defaultKvStore.getInt(Prefs.UPLOADS_SHOWING, 100); | ||||
|         uploadLimit.setText(uploads + ""); | ||||
|         uploadLimit.setSummary(uploads + ""); | ||||
|         uploadLimit.setOnPreferenceChangeListener((preference, newValue) -> { | ||||
|             int value; | ||||
|             try { | ||||
|                 value = Integer.parseInt(newValue.toString()); | ||||
|             } catch(Exception e) { | ||||
|                 value = 100; //Default number | ||||
|             } | ||||
|             if (value > 500) { | ||||
|                 new AlertDialog.Builder(getActivity()) | ||||
|                         .setTitle(R.string.maximum_limit) | ||||
|                         .setMessage(R.string.maximum_limit_alert) | ||||
|                         .setPositiveButton(android.R.string.yes, (dialog, which) -> {}) | ||||
|                         .setIcon(android.R.drawable.ic_dialog_alert) | ||||
|                         .show(); | ||||
|                 defaultKvStore.putInt(Prefs.UPLOADS_SHOWING, 500); | ||||
|                 defaultKvStore.putBoolean(Prefs.IS_CONTRIBUTION_COUNT_CHANGED, true); | ||||
|                 uploadLimit.setSummary(500 + ""); | ||||
|                 uploadLimit.setText(500 + ""); | ||||
|             } else { | ||||
|                 defaultKvStore.putInt(Prefs.UPLOADS_SHOWING, value); | ||||
|                 defaultKvStore.putBoolean(Prefs.IS_CONTRIBUTION_COUNT_CHANGED, true); | ||||
|                 uploadLimit.setSummary(String.valueOf(value)); | ||||
|             } | ||||
|             return true; | ||||
|         }); | ||||
|         uploadLimit.getEditText().addTextChangedListener(new TextWatcher() { | ||||
|             @Override | ||||
|             public void beforeTextChanged(CharSequence s, int start, int count, int after) { | ||||
| 
 | ||||
|             } | ||||
| 
 | ||||
|             @Override | ||||
|             public void onTextChanged(CharSequence s, int start, int before, int count) { | ||||
|             } | ||||
| 
 | ||||
|             @Override | ||||
|             public void afterTextChanged(Editable s) { | ||||
|                 int value; | ||||
|                 if (s.length()>0) | ||||
|                 try { | ||||
|                     value = Integer.parseInt(s.toString()); | ||||
|                     if (value > 500) { | ||||
|                         uploadLimit.getEditText().setError(getString((R.string.maximum_limit_alert))); | ||||
|                         defaultKvStore.putInt(Prefs.UPLOADS_SHOWING, 500); | ||||
|                         defaultKvStore.putBoolean(Prefs.IS_CONTRIBUTION_COUNT_CHANGED, true); | ||||
|                         uploadLimit.setSummary(500 + ""); | ||||
|                         uploadLimit.setText(500 + ""); | ||||
|                     } else if (value == 0) { | ||||
|                         uploadLimit.getEditText().setError(getString(R.string.cannot_be_zero)); | ||||
|                         defaultKvStore.putInt(Prefs.UPLOADS_SHOWING, 100); | ||||
|                         defaultKvStore.putBoolean(Prefs.IS_CONTRIBUTION_COUNT_CHANGED, true); | ||||
|                         uploadLimit.setSummary(100 + ""); | ||||
|                         uploadLimit.setText(100 + ""); | ||||
|                     } else { | ||||
|                         defaultKvStore.putInt(Prefs.UPLOADS_SHOWING, value); | ||||
|                         defaultKvStore.putBoolean(Prefs.IS_CONTRIBUTION_COUNT_CHANGED, true); | ||||
|                         uploadLimit.setSummary(String.valueOf(value)); | ||||
|                     } | ||||
|                 } catch (Exception e) { | ||||
|                     uploadLimit.getEditText().setError(getString(R.string.enter_valid)); | ||||
|                     defaultKvStore.putInt(Prefs.UPLOADS_SHOWING, 100); | ||||
|                     defaultKvStore.putBoolean(Prefs.IS_CONTRIBUTION_COUNT_CHANGED, true); | ||||
|                     uploadLimit.setSummary(100 + ""); | ||||
|                     uploadLimit.setText(100 + ""); | ||||
|                 } | ||||
|             } | ||||
|         }); | ||||
|         Preference betaTesterPreference = findPreference("becomeBetaTester"); | ||||
|         betaTesterPreference.setOnPreferenceClickListener(preference -> { | ||||
|             Utils.handleWebUrl(getActivity(), Uri.parse(getResources().getString(R.string.beta_opt_in_link))); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Vanshika Arora
						Vanshika Arora