mirror of
https://github.com/shaulascr/ecommerce_serang.git
synced 2025-08-09 08:52:21 +00:00
fix search
This commit is contained in:

committed by
Gracia Hotmauli

parent
28b0d5b082
commit
4401daa310
@ -6,7 +6,6 @@ import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.inputmethod.EditorInfo
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.viewModels
|
||||
@ -110,26 +109,16 @@ class HomeFragment : Fragment() {
|
||||
|
||||
private fun setupSearchView() {
|
||||
binding.searchContainer.search.apply {
|
||||
// When user clicks the search box, navigate to search fragment
|
||||
// Make it non-editable so it acts like a button
|
||||
isFocusable = false
|
||||
isFocusableInTouchMode = false
|
||||
isClickable = true
|
||||
|
||||
setOnClickListener {
|
||||
findNavController().navigate(
|
||||
HomeFragmentDirections.actionHomeFragmentToSearchHomeFragment(null)
|
||||
)
|
||||
}
|
||||
|
||||
// Handle search action if user presses search on keyboard
|
||||
setOnEditorActionListener { _, actionId, _ ->
|
||||
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
|
||||
val query = text.toString().trim()
|
||||
if (query.isNotEmpty()) {
|
||||
findNavController().navigate(
|
||||
HomeFragmentDirections.actionHomeFragmentToSearchHomeFragment(query)
|
||||
)
|
||||
}
|
||||
return@setOnEditorActionListener true
|
||||
}
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
// Setup cart and notification buttons
|
||||
|
@ -76,6 +76,7 @@ class SearchHomeFragment : Fragment() {
|
||||
|
||||
// Setup search view
|
||||
binding.searchView.apply {
|
||||
clearFocus()
|
||||
setOnQueryTextListener(object : androidx.appcompat.widget.SearchView.OnQueryTextListener {
|
||||
override fun onQueryTextSubmit(query: String?): Boolean {
|
||||
query?.let {
|
||||
@ -105,13 +106,12 @@ class SearchHomeFragment : Fragment() {
|
||||
}
|
||||
})
|
||||
|
||||
// Request focus and show keyboard
|
||||
if (args.query.isNullOrEmpty()) {
|
||||
requestFocus()
|
||||
postDelayed({
|
||||
post {
|
||||
val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
||||
imm.showSoftInput(findFocus(), InputMethodManager.SHOW_IMPLICIT)
|
||||
}, 200)
|
||||
imm.showSoftInput(this, InputMethodManager.SHOW_IMPLICIT)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ import com.alya.ecommerce_serang.data.api.retrofit.ApiConfig
|
||||
import com.alya.ecommerce_serang.data.repository.ProductRepository
|
||||
import com.alya.ecommerce_serang.data.repository.Result
|
||||
import com.alya.ecommerce_serang.databinding.ActivityListProductBinding
|
||||
import com.alya.ecommerce_serang.ui.cart.CartActivity
|
||||
import com.alya.ecommerce_serang.ui.product.DetailProductActivity
|
||||
import com.alya.ecommerce_serang.ui.product.ProductUserViewModel
|
||||
import com.alya.ecommerce_serang.utils.BaseViewModelFactory
|
||||
@ -60,13 +61,23 @@ class ListProductActivity : AppCompatActivity() {
|
||||
windowInsets
|
||||
}
|
||||
|
||||
|
||||
setupToolbar()
|
||||
setupObserver()
|
||||
setupRecyclerView()
|
||||
viewModel.loadProductsList()
|
||||
|
||||
}
|
||||
|
||||
private fun setupToolbar(){
|
||||
binding.searchContainerList.btnBack.setOnClickListener{
|
||||
finish()
|
||||
}
|
||||
binding.searchContainerList.btnCart.setOnClickListener{
|
||||
val intent = Intent(this, CartActivity::class.java)
|
||||
startActivity(intent)
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupRecyclerView() {
|
||||
|
||||
binding.rvProductsList.apply {
|
||||
|
@ -4,7 +4,6 @@
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/Theme.Ecommerce_serang"
|
||||
tools:context=".ui.product.listproduct.ListProductActivity">
|
||||
|
||||
<include
|
||||
|
@ -30,7 +30,9 @@
|
||||
android:layout_weight="1"
|
||||
android:background="@drawable/search_background"
|
||||
android:iconifiedByDefault="false"
|
||||
android:queryHint="Search products..." />
|
||||
android:queryHint="Search products..."
|
||||
app:iconifiedByDefault="false"
|
||||
app:queryHint="Search products..." />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
Reference in New Issue
Block a user