Skip to content

Commit

Permalink
Fix issue PatilShreyas#535 for hiding the keyboard
Browse files Browse the repository at this point in the history
  • Loading branch information
Varsha-Kulkarni committed Oct 5, 2022
1 parent 117739a commit 85aa28b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import dagger.hilt.android.AndroidEntryPoint
import dev.shreyaspatil.noty.simpleapp.databinding.AddNoteFragmentBinding
import dev.shreyaspatil.noty.simpleapp.view.base.BaseFragment
import dev.shreyaspatil.noty.simpleapp.view.hiltNotyMainNavGraphViewModels
import dev.shreyaspatil.noty.utils.ext.hideKeyboard
import dev.shreyaspatil.noty.utils.ext.toStringOrEmpty
import dev.shreyaspatil.noty.view.state.AddNoteState
import dev.shreyaspatil.noty.view.viewmodel.AddNoteViewModel
Expand All @@ -50,6 +51,7 @@ class AddNoteFragment : BaseFragment<AddNoteFragmentBinding, AddNoteState, AddNo
showProgressDialog(state.isAdding)

if (state.added) {
hideKeyboard()
findNavController().navigateUp()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import dagger.hilt.android.AndroidEntryPoint
import dev.shreyaspatil.noty.simpleapp.R
import dev.shreyaspatil.noty.simpleapp.databinding.NoteDetailFragmentBinding
import dev.shreyaspatil.noty.simpleapp.view.base.BaseFragment
import dev.shreyaspatil.noty.utils.ext.hideKeyboard
import dev.shreyaspatil.noty.utils.ext.showDialog
import dev.shreyaspatil.noty.utils.ext.toStringOrEmpty
import dev.shreyaspatil.noty.utils.saveBitmap
Expand Down Expand Up @@ -109,6 +110,7 @@ class NoteDetailFragment :
}

if (state.finished) {
hideKeyboard()
findNavController().navigateUp()
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright 2020 Shreyas Patil
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package dev.shreyaspatil.noty.utils.ext

import android.app.Activity
import android.content.Context
import android.view.View
import android.view.inputmethod.InputMethodManager
import androidx.fragment.app.Fragment

fun Fragment.hideKeyboard() {
view?.let { activity?.hideKeyboard(it) }
}

fun Context.hideKeyboard(view: View) {
val inputMethodManager = getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager
inputMethodManager.hideSoftInputFromWindow(view.windowToken, 0)
}

0 comments on commit 85aa28b

Please sign in to comment.