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 280e814 commit 5533905
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 @@ -1037,6 +1038,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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -267,6 +270,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 5533905

Please sign in to comment.