From a4160372c8e036a74dea3b9c23ee8a189de16a78 Mon Sep 17 00:00:00 2001 From: A117870935 Date: Wed, 12 Apr 2023 20:28:31 +0530 Subject: [PATCH] Update UnifiedSearchFragment.kt. Commit id: 4fb3fb3 from branch bug/NMC-1652. --- .../com/nmc/android/utils/KeyboardUtils.java | 21 +++++++++++++++++++ .../ui/activity/FileDisplayActivity.java | 3 +++ .../ui/fragment/UnifiedSearchFragment.kt | 4 ++++ 3 files changed, 28 insertions(+) create mode 100644 app/src/main/java/com/nmc/android/utils/KeyboardUtils.java 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 b9105cb833f9..73643ee195ed 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 @@ -128,6 +128,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; @@ -1059,6 +1060,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 a158c8052948..b9ed0199af30 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 @@ -29,6 +29,7 @@ import com.nextcloud.client.account.UserAccountManager 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 @@ -238,6 +239,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 @@ -298,6 +301,7 @@ class UnifiedSearchFragment : } override fun onQueryTextSubmit(query: String): Boolean { + KeyboardUtils.hideKeyboardFrom(requireContext(), binding.root) vm.setQuery(query) vm.initialQuery() return true