Skip to content

Commit 491d1f2

Browse files
committed
Fixed soft keyboard bug
1 parent fdbe53d commit 491d1f2

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

app/src/main/java/fr/free/nrw/commons/contributions/MainActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ public void onPageSelected(int position) {
180180
Timber.d("Contributions tab selected");
181181
tabLayout.getTabAt(CONTRIBUTIONS_TAB_POSITION).select();
182182
isContributionsFragmentVisible = true;
183-
ViewUtil.hideKeyboard(tabLayout.getRootView());
183+
((NearbyParentFragment)contributionsActivityPagerAdapter.getItem(NEARBY_TAB_POSITION)).hideKeyboard();
184184
updateMenuItem();
185185
break;
186186
case NEARBY_TAB_POSITION:

app/src/main/java/fr/free/nrw/commons/nearby/fragments/NearbyParentFragment.java

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package fr.free.nrw.commons.nearby.fragments;
22

33
import android.Manifest;
4+
import android.app.Activity;
45
import android.app.AlertDialog;
56
import android.content.BroadcastReceiver;
67
import android.content.Context;
@@ -9,14 +10,15 @@
910
import android.content.res.Configuration;
1011
import android.graphics.Bitmap;
1112
import android.os.Bundle;
12-
import android.text.TextUtils;
13+
import android.os.IBinder;
1314
import android.util.Log;
1415
import android.view.Gravity;
1516
import android.view.LayoutInflater;
1617
import android.view.View;
1718
import android.view.ViewGroup;
1819
import android.view.animation.Animation;
1920
import android.view.animation.AnimationUtils;
21+
import android.view.inputmethod.InputMethodManager;
2022
import android.widget.Button;
2123
import android.widget.ImageView;
2224
import android.widget.LinearLayout;
@@ -598,9 +600,34 @@ public void centerMapToPlace(Place place) {
598600
}
599601
}
600602

601-
@Override
602-
public void updateListFragment(List<Place> placeList) {
603-
adapterFactory.updateAdapterData(placeList, (RVRendererAdapter<Place>) rvNearbyList.getAdapter());
603+
/**
604+
* Hides the keyboard in case the tab is switched
605+
*/
606+
public void hideKeyboard(){
607+
if(!searchView.isIconified()) {
608+
searchView.clearFocus();
609+
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Activity.INPUT_METHOD_SERVICE);
610+
final IBinder windowToken = this.getView().getRootView().getWindowToken();
611+
if (view != null) {
612+
imm.hideSoftInputFromWindow(windowToken, InputMethodManager.HIDE_NOT_ALWAYS);
613+
}
614+
}
615+
}
616+
617+
618+
/**
619+
* Thanks to this method we make sure NearbyMapFragment is ready and attached. So that we can
620+
* prevent NPE caused by null child fragment. This method is called from child fragment when
621+
* it is attached.
622+
*/
623+
private void childMapFragmentAttached() {
624+
Timber.d("Child map fragment attached");
625+
nearbyParentFragmentPresenter = NearbyParentFragmentPresenter.getInstance
626+
(nearbyListFragment,this, nearbyMapFragment, locationManager);
627+
nearbyParentFragmentPresenter.nearbyFragmentsAreReady();
628+
initViews();
629+
nearbyParentFragmentPresenter.setActionListeners(applicationKvStore);
630+
initNearbyFilter();
604631
}
605632

606633
@Override

0 commit comments

Comments
 (0)