mirror of
https://github.com/shaulascr/ecommerce_serang.git
synced 2025-08-10 09:22: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.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.view.inputmethod.EditorInfo
|
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.fragment.app.viewModels
|
import androidx.fragment.app.viewModels
|
||||||
@ -110,26 +109,16 @@ class HomeFragment : Fragment() {
|
|||||||
|
|
||||||
private fun setupSearchView() {
|
private fun setupSearchView() {
|
||||||
binding.searchContainer.search.apply {
|
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 {
|
setOnClickListener {
|
||||||
findNavController().navigate(
|
findNavController().navigate(
|
||||||
HomeFragmentDirections.actionHomeFragmentToSearchHomeFragment(null)
|
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
|
// Setup cart and notification buttons
|
||||||
|
@ -76,6 +76,7 @@ class SearchHomeFragment : Fragment() {
|
|||||||
|
|
||||||
// Setup search view
|
// Setup search view
|
||||||
binding.searchView.apply {
|
binding.searchView.apply {
|
||||||
|
clearFocus()
|
||||||
setOnQueryTextListener(object : androidx.appcompat.widget.SearchView.OnQueryTextListener {
|
setOnQueryTextListener(object : androidx.appcompat.widget.SearchView.OnQueryTextListener {
|
||||||
override fun onQueryTextSubmit(query: String?): Boolean {
|
override fun onQueryTextSubmit(query: String?): Boolean {
|
||||||
query?.let {
|
query?.let {
|
||||||
@ -105,13 +106,12 @@ class SearchHomeFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// Request focus and show keyboard
|
|
||||||
if (args.query.isNullOrEmpty()) {
|
if (args.query.isNullOrEmpty()) {
|
||||||
requestFocus()
|
requestFocus()
|
||||||
postDelayed({
|
post {
|
||||||
val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
||||||
imm.showSoftInput(findFocus(), InputMethodManager.SHOW_IMPLICIT)
|
imm.showSoftInput(this, InputMethodManager.SHOW_IMPLICIT)
|
||||||
}, 200)
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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.ProductRepository
|
||||||
import com.alya.ecommerce_serang.data.repository.Result
|
import com.alya.ecommerce_serang.data.repository.Result
|
||||||
import com.alya.ecommerce_serang.databinding.ActivityListProductBinding
|
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.DetailProductActivity
|
||||||
import com.alya.ecommerce_serang.ui.product.ProductUserViewModel
|
import com.alya.ecommerce_serang.ui.product.ProductUserViewModel
|
||||||
import com.alya.ecommerce_serang.utils.BaseViewModelFactory
|
import com.alya.ecommerce_serang.utils.BaseViewModelFactory
|
||||||
@ -60,13 +61,23 @@ class ListProductActivity : AppCompatActivity() {
|
|||||||
windowInsets
|
windowInsets
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setupToolbar()
|
||||||
setupObserver()
|
setupObserver()
|
||||||
setupRecyclerView()
|
setupRecyclerView()
|
||||||
viewModel.loadProductsList()
|
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() {
|
private fun setupRecyclerView() {
|
||||||
|
|
||||||
binding.rvProductsList.apply {
|
binding.rvProductsList.apply {
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
style="@style/Theme.Ecommerce_serang"
|
|
||||||
tools:context=".ui.product.listproduct.ListProductActivity">
|
tools:context=".ui.product.listproduct.ListProductActivity">
|
||||||
|
|
||||||
<include
|
<include
|
||||||
|
@ -30,7 +30,9 @@
|
|||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:background="@drawable/search_background"
|
android:background="@drawable/search_background"
|
||||||
android:iconifiedByDefault="false"
|
android:iconifiedByDefault="false"
|
||||||
android:queryHint="Search products..." />
|
android:queryHint="Search products..."
|
||||||
|
app:iconifiedByDefault="false"
|
||||||
|
app:queryHint="Search products..." />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user