mirror of
https://github.com/Nezumi-2711/Foodify.git
synced 2026-09-22 20:00:50 +00:00
Fix bug search
This commit is contained in:
@@ -52,6 +52,5 @@ dependencies {
|
|||||||
annotationProcessor 'com.github.bumptech.glide:compiler:4.14.2'
|
annotationProcessor 'com.github.bumptech.glide:compiler:4.14.2'
|
||||||
implementation "com.github.kojofosu:Quantitizer:1.6.7"
|
implementation "com.github.kojofosu:Quantitizer:1.6.7"
|
||||||
implementation 'com.squareup.picasso:picasso:2.71828'
|
implementation 'com.squareup.picasso:picasso:2.71828'
|
||||||
implementation "com.paulrybitskyi.persistentsearchview:persistentsearchview:1.1.4"
|
|
||||||
implementation 'com.github.ome450901:SimpleRatingBar:1.5.1'
|
implementation 'com.github.ome450901:SimpleRatingBar:1.5.1'
|
||||||
}
|
}
|
||||||
@@ -12,6 +12,7 @@ import android.widget.TextView;
|
|||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.appcompat.widget.SearchView;
|
||||||
import androidx.core.widget.NestedScrollView;
|
import androidx.core.widget.NestedScrollView;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.recyclerview.widget.GridLayoutManager;
|
import androidx.recyclerview.widget.GridLayoutManager;
|
||||||
@@ -59,7 +60,7 @@ public class SearchFragment extends Fragment {
|
|||||||
View view = inflater.inflate(R.layout.fragment_search, container, false);
|
View view = inflater.inflate(R.layout.fragment_search, container, false);
|
||||||
|
|
||||||
//Init Component
|
//Init Component
|
||||||
PersistentSearchView persistentSearchView = view.findViewById(R.id.search_view);
|
SearchView searchView = view.findViewById(R.id.search_view);
|
||||||
recycler_view_search = view.findViewById(R.id.recycler_view_search);
|
recycler_view_search = view.findViewById(R.id.recycler_view_search);
|
||||||
list_Category = view.findViewById(R.id.list_category);
|
list_Category = view.findViewById(R.id.list_category);
|
||||||
nestedScrollView = view.findViewById(R.id.search_fragment);
|
nestedScrollView = view.findViewById(R.id.search_fragment);
|
||||||
@@ -75,7 +76,7 @@ public class SearchFragment extends Fragment {
|
|||||||
recycler_view_search.setAdapter(foodAdapter);
|
recycler_view_search.setAdapter(foodAdapter);
|
||||||
|
|
||||||
getListFoodByPagination(1);
|
getListFoodByPagination(1);
|
||||||
if(nestedScrollView != null){
|
if (nestedScrollView != null) {
|
||||||
nestedScrollView.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
|
nestedScrollView.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onScrollChange(@NonNull NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
|
public void onScrollChange(@NonNull NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
|
||||||
@@ -86,38 +87,30 @@ public class SearchFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
|
||||||
persistentSearchView.setLeftButtonDrawable(R.drawable.ic_search);
|
|
||||||
persistentSearchView.setOnSearchConfirmedListener(new OnSearchConfirmedListener() {
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSearchConfirmed(PersistentSearchView searchView, String query) {
|
public boolean onQueryTextSubmit(String query) {
|
||||||
// Handle a search confirmation. This is the place where you'd
|
|
||||||
// want to perform a search against your data provider.
|
|
||||||
ACTION_CODE = SEARCH_FOOD;
|
ACTION_CODE = SEARCH_FOOD;
|
||||||
CURRENT_PAGE = 1;
|
CURRENT_PAGE = 1;
|
||||||
showProgressBarAndHideEndOfListText();
|
showProgressBarAndHideEndOfListText();
|
||||||
listFoodSearch.clear();
|
listFoodSearch.clear();
|
||||||
if(!query.isEmpty()){
|
if (!query.isEmpty()) {
|
||||||
searchQuery = query;
|
searchQuery = query;
|
||||||
getListFoodBySearch(searchQuery, CURRENT_PAGE);
|
getListFoodBySearch(searchQuery, CURRENT_PAGE);
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
searchView.collapse();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
persistentSearchView.setOnSearchQueryChangeListener(new OnSearchQueryChangeListener() {
|
|
||||||
@Override
|
@Override
|
||||||
public void onSearchQueryChanged(PersistentSearchView searchView, String oldQuery, String newQuery) {
|
public boolean onQueryTextChange(String newText) {
|
||||||
if(searchView.isInputQueryEmpty()){
|
if (searchView.getQuery().length() == 0) {
|
||||||
CURRENT_PAGE = 1;
|
CURRENT_PAGE = 1;
|
||||||
ACTION_CODE = LIST_FOOD;
|
ACTION_CODE = LIST_FOOD;
|
||||||
showProgressBarAndHideEndOfListText();
|
showProgressBarAndHideEndOfListText();
|
||||||
foodAdapter.setData(listFood);
|
foodAdapter.setData(listFood);
|
||||||
foodAdapter.notifyDataSetChanged();
|
foodAdapter.notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -12,17 +12,33 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
<com.paulrybitskyi.persistentsearchview.PersistentSearchView
|
<androidx.cardview.widget.CardView
|
||||||
android:id="@+id/search_view"
|
android:id="@+id/card_view"
|
||||||
app:layout_constraintTop_toTopOf="parent"
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content" />
|
android:layout_height="wrap_content"
|
||||||
|
app:cardCornerRadius="5dp"
|
||||||
|
app:cardElevation="5dp"
|
||||||
|
android:layout_marginBottom="5dp"
|
||||||
|
>
|
||||||
|
|
||||||
|
<androidx.appcompat.widget.SearchView
|
||||||
|
android:id="@+id/search_view"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
app:queryBackground="@android:color/transparent"
|
||||||
|
app:queryHint="Search here..."
|
||||||
|
android:background="@color/white"
|
||||||
|
app:iconifiedByDefault="false"
|
||||||
|
/>
|
||||||
|
|
||||||
|
</androidx.cardview.widget.CardView>
|
||||||
|
|
||||||
<com.google.android.material.chip.ChipGroup
|
<com.google.android.material.chip.ChipGroup
|
||||||
android:id="@+id/list_category"
|
android:id="@+id/list_category"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/search_view"
|
app:layout_constraintTop_toBottomOf="@+id/card_view"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
|||||||
@@ -30,4 +30,5 @@
|
|||||||
<item name="android:color">@color/primaryColor</item>
|
<item name="android:color">@color/primaryColor</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
Reference in New Issue
Block a user