mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 12:53:55 +01:00
5115: Fix AdvanceQueryFragmentUnitTests (#5119)
* 5115: Fix AdvanceQueryFragmentUnitTests * 5115: Adding further coverage - removed redundant button.post() methods. - increased code coverage
This commit is contained in:
parent
77bb789f9e
commit
7b18c3eeb7
2 changed files with 136 additions and 73 deletions
|
|
@ -6,6 +6,8 @@ import android.view.LayoutInflater
|
|||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.inputmethod.InputMethodManager
|
||||
import android.widget.Button
|
||||
import android.widget.EditText
|
||||
import androidx.fragment.app.Fragment
|
||||
import fr.free.nrw.commons.databinding.FragmentAdvanceQueryBinding
|
||||
|
||||
|
|
@ -13,16 +15,25 @@ class AdvanceQueryFragment : Fragment() {
|
|||
|
||||
private var _binding: FragmentAdvanceQueryBinding? = null
|
||||
private val binding get() = _binding
|
||||
lateinit var originalQuery: String
|
||||
|
||||
lateinit var callback: Callback
|
||||
|
||||
/**
|
||||
* View Elements
|
||||
*/
|
||||
private var etQuery: EditText? = null
|
||||
private var btnApply: Button? = null
|
||||
private var btnReset: Button? = null
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View? {
|
||||
_binding = FragmentAdvanceQueryBinding.inflate(inflater, container, false)
|
||||
originalQuery = arguments?.getString("query")!!
|
||||
etQuery = binding?.etQuery
|
||||
btnApply = binding?.btnApply
|
||||
btnReset = binding?.btnReset
|
||||
setHasOptionsMenu(false)
|
||||
return binding?.root
|
||||
}
|
||||
|
|
@ -30,25 +41,28 @@ class AdvanceQueryFragment : Fragment() {
|
|||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
with(requireNotNull(binding)) {
|
||||
etQuery.setText(originalQuery)
|
||||
btnReset.setOnClickListener {
|
||||
btnReset.post {
|
||||
etQuery.setText(originalQuery)
|
||||
etQuery.clearFocus()
|
||||
hideKeyBoard()
|
||||
callback.reset()
|
||||
}
|
||||
}
|
||||
setUi()
|
||||
|
||||
btnApply.setOnClickListener {
|
||||
btnApply.post {
|
||||
etQuery.clearFocus()
|
||||
hideKeyBoard()
|
||||
callback.apply(etQuery.text.toString())
|
||||
callback.close()
|
||||
}
|
||||
}
|
||||
setClickListeners()
|
||||
}
|
||||
|
||||
private fun setUi() {
|
||||
etQuery?.setText(arguments?.getString("query")!!)
|
||||
}
|
||||
|
||||
private fun setClickListeners() {
|
||||
btnReset?.setOnClickListener {
|
||||
etQuery?.setText(arguments?.getString("query")!!)
|
||||
etQuery?.clearFocus()
|
||||
hideKeyBoard()
|
||||
callback.reset()
|
||||
}
|
||||
|
||||
btnApply?.setOnClickListener {
|
||||
etQuery?.clearFocus()
|
||||
hideKeyBoard()
|
||||
callback.apply(etQuery?.text.toString())
|
||||
callback.close()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -58,6 +72,11 @@ class AdvanceQueryFragment : Fragment() {
|
|||
inputMethodManager?.hideSoftInputFromWindow(view?.windowToken, 0)
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
_binding = null
|
||||
super.onDestroyView()
|
||||
}
|
||||
|
||||
interface Callback {
|
||||
fun reset()
|
||||
fun apply(query: String)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue