Fix UI Layout

This commit is contained in:
Nezumi
2023-02-15 23:04:31 +07:00
parent 9250b0ef59
commit 9225723bb2
8 changed files with 227 additions and 67 deletions
+1
View File
@@ -9,6 +9,7 @@
android:dataExtractionRules="@xml/data_extraction_rules" android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules" android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher" android:icon="@mipmap/ic_launcher"
android:enableOnBackInvokedCallback="true"
android:label="@string/app_name" android:label="@string/app_name"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/Theme.Foodify" android:theme="@style/Theme.Foodify"
@@ -87,7 +87,7 @@ public class HomeFragment extends Fragment {
List<Menu> listMenu = new ArrayList<>(); List<Menu> listMenu = new ArrayList<>();
listMenu.add(new Menu("Recommend Food", listFood)); listMenu.add(new Menu("Recommend Food", listFood));
listMenu.add(new Menu("Drinks", drinkFood)); listMenu.add(new Menu("Popular Food", drinkFood));
return listMenu; return listMenu;
} }
@@ -4,30 +4,28 @@ import static com.capstone.foodify.Fragment.HomeFragment.listFood;
import android.app.Activity; import android.app.Activity;
import android.os.Bundle; import android.os.Bundle;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
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.InputMethodManager; import android.view.inputmethod.InputMethodManager;
import android.widget.Toast; import android.widget.Toast;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.capstone.foodify.API.FoodApi; import com.capstone.foodify.API.FoodApi;
import com.capstone.foodify.Model.Food.Food; import com.capstone.foodify.Model.Food.Food;
import com.capstone.foodify.Model.Food.FoodAdapter; import com.capstone.foodify.Model.Food.FoodAdapter;
import com.capstone.foodify.Model.Food.FoodSearchAdapter;
import com.capstone.foodify.R; import com.capstone.foodify.R;
import com.paulrybitskyi.persistentsearchview.PersistentSearchView; import com.paulrybitskyi.persistentsearchview.PersistentSearchView;
import com.paulrybitskyi.persistentsearchview.listeners.OnSearchConfirmedListener; import com.paulrybitskyi.persistentsearchview.listeners.OnSearchConfirmedListener;
import com.paulrybitskyi.persistentsearchview.listeners.OnSearchQueryChangeListener; import com.paulrybitskyi.persistentsearchview.listeners.OnSearchQueryChangeListener;
import com.paulrybitskyi.persistentsearchview.utils.SuggestionCreationUtil;
import com.paulrybitskyi.persistentsearchview.utils.VoiceRecognitionDelegate; import com.paulrybitskyi.persistentsearchview.utils.VoiceRecognitionDelegate;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects;
import retrofit2.Call; import retrofit2.Call;
import retrofit2.Callback; import retrofit2.Callback;
@@ -36,7 +34,7 @@ import retrofit2.Response;
public class SearchFragment extends Fragment { public class SearchFragment extends Fragment {
private RecyclerView recycler_view_search; private RecyclerView recycler_view_search;
private FoodAdapter foodAdapter; private FoodSearchAdapter foodAdapter;
private PersistentSearchView persistentSearchView; private PersistentSearchView persistentSearchView;
private static List<Food> listFoodSearch = new ArrayList<>(); private static List<Food> listFoodSearch = new ArrayList<>();
@@ -50,7 +48,7 @@ public class SearchFragment extends Fragment {
recycler_view_search = view.findViewById(R.id.recycler_view_search); recycler_view_search = view.findViewById(R.id.recycler_view_search);
persistentSearchView = view.findViewById(R.id.search_view); persistentSearchView = view.findViewById(R.id.search_view);
foodAdapter = new FoodAdapter(getContext()); foodAdapter = new FoodSearchAdapter(getContext());
GridLayoutManager gridLayoutManager = new GridLayoutManager(getContext(), 3); GridLayoutManager gridLayoutManager = new GridLayoutManager(getContext(), 3);
recycler_view_search.setLayoutManager(gridLayoutManager); recycler_view_search.setLayoutManager(gridLayoutManager);
@@ -60,12 +58,6 @@ public class SearchFragment extends Fragment {
persistentSearchView.setLeftButtonDrawable(R.drawable.ic_search); persistentSearchView.setLeftButtonDrawable(R.drawable.ic_search);
// Setting a delegate for the voice recognition input
persistentSearchView.setVoiceRecognitionDelegate(new VoiceRecognitionDelegate(this));
persistentSearchView.setProgressBarEnabled(true);
persistentSearchView.setSuggestionsDisabled(false);
persistentSearchView.setOnSearchConfirmedListener(new OnSearchConfirmedListener() { persistentSearchView.setOnSearchConfirmedListener(new OnSearchConfirmedListener() {
@Override @Override
@@ -111,22 +103,7 @@ public class SearchFragment extends Fragment {
} }
}); });
// Disabling the suggestions since they are unused in
// the simple implementation
persistentSearchView.setSuggestionsDisabled(false);
return view; return view;
} }
public static void hideKeyboard(Activity activity) {
InputMethodManager imm = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
//Find the currently focused view, so we can grab the correct window token from it.
View view = activity.getCurrentFocus();
//If no view currently has focus, create a new one, just so we can grab a window token from it
if (view == null) {
view = new View(activity);
}
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
} }
@@ -0,0 +1,81 @@
package com.capstone.foodify.Model.Food;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.capstone.foodify.R;
import com.squareup.picasso.Picasso;
import java.util.List;
public class FoodSearchAdapter extends RecyclerView.Adapter<FoodSearchAdapter.FoodViewHolder>{
private List<Food> listFood;
private Context context;
public FoodSearchAdapter(Context context){
this.context = context;
}
public FoodSearchAdapter() {}
public void setData(List<Food> list) {
this.listFood = list;
notifyDataSetChanged();
}
@NonNull
@Override
public FoodViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_foods_search, parent, false);
return new FoodViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull FoodViewHolder holder, int position) {
Food food = listFood.get(position);
if(food == null){
return;
}
String foodName = food.getName();
if(foodName.length() >= 19){
StringBuilder stringBuilder = new StringBuilder(food.getName());
stringBuilder.replace(19, food.getName().length(), "..." );
holder.name.setText(stringBuilder);
} else {
holder.name.setText(foodName);
}
Picasso.get().load(food.getImg()).into(holder.image);
holder.price.setText(food.getPrice());
}
@Override
public int getItemCount() {
if(listFood != null) {
return listFood.size();
}
return 0;
}
public class FoodViewHolder extends RecyclerView.ViewHolder{
private ImageView image;
private TextView name, price;
public FoodViewHolder(@NonNull View itemView) {
super(itemView);
image = itemView.findViewById(R.id.image_view);
name = itemView.findViewById(R.id.title);
price = itemView.findViewById(R.id.price);
}
}
}
+23 -18
View File
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" <androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
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="match_parent" android:layout_height="match_parent"
@@ -7,24 +7,29 @@
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
> >
<com.paulrybitskyi.persistentsearchview.PersistentSearchView <androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/search_view"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="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">
<androidx.recyclerview.widget.RecyclerView <com.paulrybitskyi.persistentsearchview.PersistentSearchView
android:id="@+id/recycler_view_search" android:id="@+id/search_view"
tools:listitem="@layout/list_foods" app:layout_constraintTop_toTopOf="parent"
android:layout_marginStart="15dp" app:layout_constraintStart_toStartOf="parent"
android:layout_width="match_parent" app:layout_constraintEnd_toEndOf="parent"
android:layout_height="wrap_content" android:layout_width="match_parent"
app:layout_constraintTop_toBottomOf="@id/search_view" android:layout_height="wrap_content" />
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" <androidx.recyclerview.widget.RecyclerView
/> android:id="@+id/recycler_view_search"
tools:listitem="@layout/list_foods"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
app:layout_constraintTop_toBottomOf="@id/search_view"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.core.widget.NestedScrollView>
+15 -17
View File
@@ -1,16 +1,14 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="120dp" android:layout_width="100dp"
android:layout_height="190dp" android:layout_height="170dp"
android:layout_marginStart="0dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp" android:layout_marginBottom="10dp"
android:layout_marginEnd="10dp" android:layout_marginEnd="10dp"
xmlns:app="http://schemas.android.com/apk/res-auto"> xmlns:app="http://schemas.android.com/apk/res-auto">
<androidx.cardview.widget.CardView <androidx.cardview.widget.CardView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="189dp" android:layout_height="169dp"
app:cardCornerRadius="10dp" app:cardCornerRadius="10dp"
> >
@@ -20,8 +18,8 @@
<com.makeramen.roundedimageview.RoundedImageView <com.makeramen.roundedimageview.RoundedImageView
android:id="@+id/image_view" android:id="@+id/image_view"
android:layout_width="120dp" android:layout_width="100dp"
android:layout_height="120dp" android:layout_height="100dp"
android:src="@drawable/food" android:src="@drawable/food"
android:scaleType="centerCrop" android:scaleType="centerCrop"
app:riv_corner_radius="10dip" app:riv_corner_radius="10dip"
@@ -33,8 +31,8 @@
<ImageView <ImageView
android:id="@+id/favourite_icon" android:id="@+id/favourite_icon"
android:src="@drawable/baseline_favorite_border_24" android:src="@drawable/baseline_favorite_border_24"
android:layout_width="20dp" android:layout_width="15dp"
android:layout_height="22dp" android:layout_height="17dp"
android:layout_marginEnd="5dp" android:layout_marginEnd="5dp"
android:layout_marginBottom="2dp" android:layout_marginBottom="2dp"
android:background="@drawable/transparent_background" android:background="@drawable/transparent_background"
@@ -45,10 +43,11 @@
<TextView <TextView
android:id="@+id/title" android:id="@+id/title"
android:layout_width="wrap_content" android:layout_width="match_parent"
android:layout_height="34dp" android:layout_height="34dp"
android:text="@string/food_title" android:text="@string/food_title"
android:layout_marginStart="6dp" android:layout_marginStart="3dp"
android:layout_marginEnd="3dp"
android:textSize="12sp" android:textSize="12sp"
android:fontFamily="@font/opensans" android:fontFamily="@font/opensans"
android:textColor="@color/black" android:textColor="@color/black"
@@ -75,19 +74,18 @@
android:fontFamily="@font/bebas" android:fontFamily="@font/bebas"
android:layout_marginStart="6dp" android:layout_marginStart="6dp"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_weight="0.7" android:layout_weight="0.8"
android:layout_height="match_parent" /> android:layout_height="match_parent" />
<ImageView <ImageView
android:id="@+id/basket_icon" android:id="@+id/basket_icon"
android:src="@drawable/basket_icon"
android:layout_marginTop="4dp"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_weight="0.18" android:layout_height="match_parent"
android:layout_height="20dp"
android:layout_marginEnd="5dp" android:layout_marginEnd="5dp"
android:layout_weight="0.18"
android:layout_marginTop="3dp"
android:contentDescription="@string/basket_icon" android:contentDescription="@string/basket_icon"
/> android:src="@drawable/basket_icon" />
</LinearLayout> </LinearLayout>
@@ -0,0 +1,98 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="170dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_marginEnd="10dp"
xmlns:app="http://schemas.android.com/apk/res-auto">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="169dp"
app:cardCornerRadius="10dp"
>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.makeramen.roundedimageview.RoundedImageView
android:id="@+id/image_view"
android:layout_width="match_parent"
android:layout_height="100dp"
android:src="@drawable/food"
android:scaleType="centerCrop"
app:riv_corner_radius="10dip"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
/>
<ImageView
android:id="@+id/favourite_icon"
android:src="@drawable/baseline_favorite_border_24"
android:layout_width="15dp"
android:layout_height="17dp"
android:layout_marginEnd="5dp"
android:layout_marginBottom="2dp"
android:background="@drawable/transparent_background"
app:layout_constraintEnd_toEndOf="@id/image_view"
app:layout_constraintBottom_toBottomOf="@id/image_view"
android:contentDescription="@string/favourite_icon"
/>
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="34dp"
android:text="@string/food_title"
android:layout_marginStart="3dp"
android:layout_marginEnd="3dp"
android:textSize="12sp"
android:fontFamily="@font/opensans"
android:textColor="@color/black"
android:layout_marginTop="3dp"
app:layout_constraintTop_toBottomOf="@+id/image_view"
app:layout_constraintStart_toStartOf="parent"
/>
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="5dp"
android:layout_marginStart="2dp"
app:layout_constraintTop_toBottomOf="@id/title"
app:layout_constraintStart_toStartOf="parent"
>
<TextView
android:id="@+id/price"
android:textSize="18sp"
android:textColor="@color/primaryColor"
android:fontFamily="@font/bebas"
android:layout_marginStart="6dp"
android:layout_width="0dp"
android:layout_weight="0.8"
android:layout_height="match_parent" />
<ImageView
android:id="@+id/basket_icon"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginEnd="5dp"
android:layout_weight="0.18"
android:layout_marginTop="3dp"
android:contentDescription="@string/basket_icon"
android:src="@drawable/basket_icon" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
</FrameLayout>
+1 -1
View File
@@ -21,7 +21,7 @@
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view_food" android:id="@+id/recycler_view_food"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="251dp" android:layout_height="wrap_content"
android:layout_marginTop="10dp" android:layout_marginTop="10dp"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
android:orientation="horizontal" android:orientation="horizontal"