diff --git a/app/src/main/java/com/nmc/android/utils/KeyboardUtils.java b/app/src/main/java/com/nmc/android/utils/KeyboardUtils.java new file mode 100644 index 000000000000..ec43ac2dd3a8 --- /dev/null +++ b/app/src/main/java/com/nmc/android/utils/KeyboardUtils.java @@ -0,0 +1,21 @@ +package com.nmc.android.utils; + +import android.app.Activity; +import android.content.Context; +import android.view.View; +import android.view.inputmethod.InputMethodManager; + +public class KeyboardUtils { + + public static void showSoftKeyboard(Context context, View view) { + view.requestFocus(); + InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); + imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT); + } + + public static void hideKeyboardFrom(Context context, View view) { + view.clearFocus(); + InputMethodManager imm = (InputMethodManager) context.getSystemService(Activity.INPUT_METHOD_SERVICE); + imm.hideSoftInputFromWindow(view.getWindowToken(), 0); + } +} \ No newline at end of file diff --git a/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java index 4e7496dc62ec..4ebfba4c994f 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -123,6 +123,7 @@ import com.owncloud.android.utils.MimeTypeUtil; import com.owncloud.android.utils.PermissionUtil; import com.owncloud.android.utils.PushUtils; +import com.nmc.android.utils.KeyboardUtils; import com.owncloud.android.utils.StringUtils; import com.owncloud.android.utils.theme.CapabilityUtils; @@ -1032,6 +1033,8 @@ private void resetSearchAction() { private void popBack() { binding.fabMain.setImageResource(R.drawable.ic_plus); resetScrolling(true); + // hide the keyboard on back press if showing + KeyboardUtils.hideKeyboardFrom(this, binding.getRoot()); showSortListGroup(false); super.onBackPressed(); } diff --git a/app/src/main/java/com/owncloud/android/ui/fragment/UnifiedSearchFragment.kt b/app/src/main/java/com/owncloud/android/ui/fragment/UnifiedSearchFragment.kt index 3b5260af2551..e942de104554 100644 --- a/app/src/main/java/com/owncloud/android/ui/fragment/UnifiedSearchFragment.kt +++ b/app/src/main/java/com/owncloud/android/ui/fragment/UnifiedSearchFragment.kt @@ -26,6 +26,7 @@ import com.nextcloud.client.account.CurrentAccountProvider import com.nextcloud.client.core.AsyncRunner import com.nextcloud.client.di.Injectable import com.nextcloud.client.di.ViewModelFactory +import com.nmc.android.utils.KeyboardUtils import com.nextcloud.client.network.ClientFactory import com.owncloud.android.R import com.owncloud.android.databinding.ListFragmentBinding @@ -208,6 +209,8 @@ class UnifiedSearchFragment : private fun showFile(file: OCFile, showFileActions: Boolean) { activity.let { if (activity is FileDisplayActivity) { + // NMC: hide keyboard when user taps on any file to view + KeyboardUtils.hideKeyboardFrom(requireContext(), binding.root) val fda = activity as FileDisplayActivity fda.file = file @@ -267,6 +270,7 @@ class UnifiedSearchFragment : } override fun onQueryTextSubmit(query: String): Boolean { + KeyboardUtils.hideKeyboardFrom(requireContext(), binding.root) vm.setQuery(query) vm.initialQuery() return true