Fix UI search layout

This commit is contained in:
Nezumi
2023-03-09 10:05:33 +07:00
parent 0e0965209d
commit e100a0cf5a
10 changed files with 97 additions and 81 deletions
@@ -120,12 +120,14 @@ public class HomeFragment extends Fragment {
@Override
public void onFailure(Call<List<Food>> call, Throwable t) {
//Check internet connection
if(Common.checkInternetConnection(getContext())){
//Has internet connection
Toast.makeText(getContext(), "Error: " + t, Toast.LENGTH_SHORT).show();
} else {
//No internet, show notification
Common.showErrorInternetConnectionNotification(getActivity());
if(getContext() != null){
if(Common.checkInternetConnection(getContext())){
//Has internet connection
Toast.makeText(getContext(), "Error: " + t, Toast.LENGTH_SHORT).show();
} else {
//No internet, show notification
Common.showErrorInternetConnectionNotification(getActivity());
}
}
}
});
@@ -15,7 +15,9 @@ import androidx.annotation.NonNull;
import androidx.appcompat.widget.SearchView;
import androidx.core.widget.NestedScrollView;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.capstone.foodify.API.FoodApi;
@@ -68,8 +70,12 @@ public class SearchFragment extends Fragment {
getListCategory();
GridLayoutManager gridLayoutManager = new GridLayoutManager(getContext(), 3);
recycler_view_search.setLayoutManager(gridLayoutManager);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext());
recycler_view_search.setLayoutManager(linearLayoutManager);
RecyclerView.ItemDecoration itemDecoration = new DividerItemDecoration(requireContext(), DividerItemDecoration.VERTICAL);
recycler_view_search.addItemDecoration(itemDecoration);
recycler_view_search.setNestedScrollingEnabled(false);
recycler_view_search.setAdapter(foodAdapter);
@@ -90,6 +96,7 @@ public class SearchFragment extends Fragment {
public boolean onQueryTextSubmit(String query) {
ACTION_CODE = SEARCH_FOOD;
CURRENT_PAGE = 1;
listFoodSearch.clear();
showProgressBarAndHideEndOfListText();
if (!query.isEmpty()) {
searchQuery = query;
@@ -101,6 +108,8 @@ public class SearchFragment extends Fragment {
@Override
public boolean onQueryTextChange(String newText) {
if (searchView.getQuery().length() == 0) {
listFoodSearch.clear();
CURRENT_PAGE = 1;
ACTION_CODE = LIST_FOOD;
showProgressBarAndHideEndOfListText();
@@ -142,8 +151,6 @@ public class SearchFragment extends Fragment {
private void loadFoodAdapter(Response<List<Food>> response) {
List<Food> foodData = response.body();
listFoodSearch.clear();
listFoodSearch.addAll(foodData);
foodAdapter.setData(listFoodSearch);
foodAdapter.notifyDataSetChanged();
@@ -76,8 +76,8 @@ public class FoodSearchAdapter extends RecyclerView.Adapter<FoodSearchAdapter.Fo
super(itemView);
image = itemView.findViewById(R.id.image_view);
name = itemView.findViewById(R.id.title);
price = itemView.findViewById(R.id.price);
name = itemView.findViewById(R.id.food_name_text_view);
price = itemView.findViewById(R.id.price_text_view);
}
}