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