Skip to content

Commit

Permalink
Update UnifiedSearchFragment.kt.
Browse files Browse the repository at this point in the history
Commit id: 4fb3fb3 from branch bug/NMC-1652.
  • Loading branch information
surinder-tsys committed Apr 2, 2024
1 parent f580c64 commit 6174db2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
21 changes: 21 additions & 0 deletions app/src/main/java/com/nmc/android/utils/KeyboardUtils.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,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;

Expand Down Expand Up @@ -1045,6 +1046,8 @@ private void popBack() {
// pop back fragment
binding.fabMain.setImageResource(R.drawable.ic_plus);
resetScrolling(true);
// hide the keyboard on back press if showing
KeyboardUtils.hideKeyboardFrom(this, binding.getRoot());
popSortListGroupVisibility();
super.onBackPressed();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,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
Expand Down Expand Up @@ -221,6 +222,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

Expand Down Expand Up @@ -280,6 +283,7 @@ class UnifiedSearchFragment :
}

override fun onQueryTextSubmit(query: String): Boolean {
KeyboardUtils.hideKeyboardFrom(requireContext(), binding.root)
vm.setQuery(query)
vm.initialQuery()
return true
Expand Down

0 comments on commit 6174db2

Please sign in to comment.