mirror of
				https://github.com/commons-app/apps-android-commons.git
				synced 2025-10-31 14:53:59 +01:00 
			
		
		
		
	fix memory leaks (they happened due to hiding keyboard) and lint null pointer warnings in the same code (#1471)
This commit is contained in:
		
							parent
							
								
									6d2c41b91e
								
							
						
					
					
						commit
						35f05be8df
					
				
					 5 changed files with 39 additions and 32 deletions
				
			
		|  | @ -128,7 +128,7 @@ public class LoginActivity extends AccountAuthenticatorActivity { | |||
| 
 | ||||
|         forgotPasswordText.setOnClickListener(view -> forgotPassword()); | ||||
| 
 | ||||
|         if(BuildConfig.FLAVOR == "beta"){ | ||||
|         if(BuildConfig.FLAVOR.equals("beta")){ | ||||
|             loginCredentials.setText(getString(R.string.login_credential)); | ||||
|         } else { | ||||
|             loginCredentials.setVisibility(View.GONE); | ||||
|  | @ -145,8 +145,12 @@ public class LoginActivity extends AccountAuthenticatorActivity { | |||
|     } | ||||
| 
 | ||||
|     public void hideKeyboard(View view) { | ||||
|         InputMethodManager inputMethodManager =(InputMethodManager)this.getSystemService(Activity.INPUT_METHOD_SERVICE); | ||||
|         inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0); | ||||
|         if (view != null) { | ||||
|             InputMethodManager inputMethodManager = (InputMethodManager) this.getSystemService(Activity.INPUT_METHOD_SERVICE); | ||||
|             if (inputMethodManager != null) { | ||||
|                 inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
|  |  | |||
|  | @ -10,7 +10,6 @@ import android.support.v7.widget.RecyclerView; | |||
| import android.text.Editable; | ||||
| import android.text.TextUtils; | ||||
| import android.text.TextWatcher; | ||||
| import android.util.Log; | ||||
| import android.view.LayoutInflater; | ||||
| import android.view.Menu; | ||||
| import android.view.MenuInflater; | ||||
|  | @ -43,7 +42,6 @@ import fr.free.nrw.commons.R; | |||
| import fr.free.nrw.commons.di.CommonsDaggerSupportFragment; | ||||
| import fr.free.nrw.commons.mwapi.MediaWikiApi; | ||||
| import fr.free.nrw.commons.upload.MwVolleyApi; | ||||
| import fr.free.nrw.commons.upload.SingleUploadFragment; | ||||
| import fr.free.nrw.commons.utils.StringSortingUtils; | ||||
| import io.reactivex.Observable; | ||||
| import io.reactivex.android.schedulers.AndroidSchedulers; | ||||
|  | @ -131,8 +129,13 @@ public class CategorizationFragment extends CommonsDaggerSupportFragment { | |||
|     } | ||||
| 
 | ||||
|     public void hideKeyboard(View view) { | ||||
|         InputMethodManager inputMethodManager = (InputMethodManager) getActivity().getSystemService(Activity.INPUT_METHOD_SERVICE); | ||||
|         inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0); | ||||
| 
 | ||||
|         if (view != null) { | ||||
|             InputMethodManager inputMethodManager = (InputMethodManager) getActivity().getSystemService(Activity.INPUT_METHOD_SERVICE); | ||||
|             if (inputMethodManager != null) { | ||||
|                 inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|  |  | |||
|  | @ -166,7 +166,8 @@ public class MultipleShareActivity extends AuthenticatedActivity | |||
|         View target = getCurrentFocus(); | ||||
|         if (target != null) { | ||||
|             InputMethodManager imm = (InputMethodManager) target.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); | ||||
|             imm.hideSoftInputFromWindow(target.getWindowToken(), 0); | ||||
|             if (imm != null) | ||||
|                 imm.hideSoftInputFromWindow(target.getWindowToken(), 0); | ||||
|         } | ||||
|         getSupportFragmentManager().beginTransaction() | ||||
|                 .add(R.id.uploadsFragmentContainer, categorizationFragment, "categorization") | ||||
|  |  | |||
|  | @ -88,9 +88,9 @@ public class MultipleUploadListFragment extends Fragment { | |||
|             if (view == null) { | ||||
|                 view = LayoutInflater.from(getContext()).inflate(R.layout.layout_upload_item, viewGroup, false); | ||||
|                 holder = new UploadHolderView(); | ||||
|                 holder.image = (SimpleDraweeView) view.findViewById(R.id.uploadImage); | ||||
|                 holder.title = (TextView) view.findViewById(R.id.uploadTitle); | ||||
|                 holder.overlay = (RelativeLayout) view.findViewById(R.id.uploadOverlay); | ||||
|                 holder.image = view.findViewById(R.id.uploadImage); | ||||
|                 holder.title = view.findViewById(R.id.uploadTitle); | ||||
|                 holder.overlay = view.findViewById(R.id.uploadOverlay); | ||||
| 
 | ||||
|                 holder.image.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, photoSize.y)); | ||||
|                 holder.image.setHierarchy(GenericDraweeHierarchyBuilder | ||||
|  | @ -128,11 +128,8 @@ public class MultipleUploadListFragment extends Fragment { | |||
|         super.onStop(); | ||||
| 
 | ||||
|         // FIXME: Stops the keyboard from being shown 'stale' while moving out of this fragment into the next | ||||
|         View target = getView().findFocus(); | ||||
|         if (target != null) { | ||||
|             InputMethodManager imm = (InputMethodManager) target.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); | ||||
|             imm.hideSoftInputFromWindow(target.getWindowToken(), 0); | ||||
|         } | ||||
|         View target = getActivity().getCurrentFocus(); | ||||
|         hideKeyboard(target); | ||||
|     } | ||||
| 
 | ||||
|     // FIXME: Wrong result type | ||||
|  | @ -168,8 +165,8 @@ public class MultipleUploadListFragment extends Fragment { | |||
|     @Override | ||||
|     public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { | ||||
|         View view = inflater.inflate(R.layout.fragment_multiple_uploads_list, container, false); | ||||
|         photosGrid = (GridView) view.findViewById(R.id.multipleShareBackground); | ||||
|         baseTitle = (EditText) view.findViewById(R.id.multipleBaseTitle); | ||||
|         photosGrid = view.findViewById(R.id.multipleShareBackground); | ||||
|         baseTitle = view.findViewById(R.id.multipleBaseTitle); | ||||
| 
 | ||||
|         photosAdapter = new PhotoDisplayAdapter(); | ||||
|         photosGrid.setAdapter(photosAdapter); | ||||
|  | @ -189,8 +186,12 @@ public class MultipleUploadListFragment extends Fragment { | |||
|     } | ||||
| 
 | ||||
|     public void hideKeyboard(View view) { | ||||
|         InputMethodManager inputMethodManager =(InputMethodManager)getActivity().getSystemService(Activity.INPUT_METHOD_SERVICE); | ||||
|         inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0); | ||||
|         if (view != null) { | ||||
|             InputMethodManager inputMethodManager = (InputMethodManager) getActivity().getSystemService(Activity.INPUT_METHOD_SERVICE); | ||||
|             if (inputMethodManager != null) { | ||||
|                 inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|  |  | |||
|  | @ -3,22 +3,20 @@ package fr.free.nrw.commons.upload; | |||
| import android.annotation.SuppressLint; | ||||
| import android.app.Activity; | ||||
| 
 | ||||
| import android.content.Context; | ||||
| import android.content.Intent; | ||||
| import android.content.SharedPreferences; | ||||
| import android.graphics.Color; | ||||
| import android.net.Uri; | ||||
| import android.os.Bundle; | ||||
| import android.preference.PreferenceManager; | ||||
| import android.support.annotation.NonNull; | ||||
| import android.support.design.widget.FloatingActionButton; | ||||
| import android.support.v4.view.ViewCompat; | ||||
| import android.support.v7.app.AlertDialog; | ||||
| 
 | ||||
| import android.text.Editable; | ||||
| import android.text.Html; | ||||
| import android.text.TextWatcher; | ||||
| import android.text.method.LinkMovementMethod; | ||||
| import android.util.Log; | ||||
| 
 | ||||
| import android.view.LayoutInflater; | ||||
| import android.view.Menu; | ||||
| import android.view.MenuInflater; | ||||
|  | @ -186,9 +184,12 @@ public class SingleUploadFragment extends CommonsDaggerSupportFragment { | |||
|     } | ||||
| 
 | ||||
|     public void hideKeyboard(View view) { | ||||
|         Log.i("hide", "hideKeyboard: "); | ||||
|         InputMethodManager inputMethodManager =(InputMethodManager)getActivity().getSystemService(Activity.INPUT_METHOD_SERVICE); | ||||
|         inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0); | ||||
|         if (view != null) { | ||||
|             InputMethodManager inputMethodManager = (InputMethodManager) getActivity().getSystemService(Activity.INPUT_METHOD_SERVICE); | ||||
|             if (inputMethodManager != null) { | ||||
|                 inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|  | @ -303,11 +304,8 @@ public class SingleUploadFragment extends CommonsDaggerSupportFragment { | |||
|         super.onStop(); | ||||
| 
 | ||||
|         // FIXME: Stops the keyboard from being shown 'stale' while moving out of this fragment into the next | ||||
|         View target = getView().findFocus(); | ||||
|         if (target != null) { | ||||
|             InputMethodManager imm = (InputMethodManager) target.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); | ||||
|             imm.hideSoftInputFromWindow(target.getWindowToken(), 0); | ||||
|         } | ||||
|         View target = getActivity().getCurrentFocus(); | ||||
|         hideKeyboard(target); | ||||
|     } | ||||
| 
 | ||||
|     @NonNull | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 neslihanturan
						neslihanturan