mirror of
https://github.com/Nezumi-2711/Foodify.git
synced 2026-09-22 20:00:50 +00:00
Add search view
This commit is contained in:
+4
-2
@@ -30,7 +30,7 @@ android {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
|
||||||
implementation 'androidx.appcompat:appcompat:1.6.0'
|
implementation 'androidx.appcompat:appcompat:1.6.1'
|
||||||
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
|
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
|
||||||
|
|
||||||
|
|
||||||
@@ -50,5 +50,7 @@ dependencies {
|
|||||||
implementation 'com.github.bumptech.glide:glide:4.14.2'
|
implementation 'com.github.bumptech.glide:glide:4.14.2'
|
||||||
annotationProcessor 'com.github.bumptech.glide:compiler:4.14.2'
|
annotationProcessor 'com.github.bumptech.glide:compiler:4.14.2'
|
||||||
|
|
||||||
implementation 'com.squareup.picasso:picasso:2.8'
|
implementation 'com.squareup.picasso:picasso:2.71828'
|
||||||
|
|
||||||
|
implementation "com.paulrybitskyi.persistentsearchview:persistentsearchview:1.1.4"
|
||||||
}
|
}
|
||||||
@@ -30,8 +30,6 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
bottomNavigation();
|
bottomNavigation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void initComponent() {
|
private void initComponent() {
|
||||||
bottomNavigationView = findViewById(R.id.bottom_nav);
|
bottomNavigationView = findViewById(R.id.bottom_nav);
|
||||||
viewPager2 = findViewById(R.id.viewPager);
|
viewPager2 = findViewById(R.id.viewPager);
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ import retrofit2.Response;
|
|||||||
|
|
||||||
public class HomeFragment extends Fragment {
|
public class HomeFragment extends Fragment {
|
||||||
|
|
||||||
private static List<Food> listFood = new ArrayList<>();
|
public static List<Food> listFood = new ArrayList<>();
|
||||||
private static List<Food> drinkFood = new ArrayList<>();
|
private static List<Food> drinkFood = new ArrayList<>();
|
||||||
|
|
||||||
private ImageSlider imageSlider;
|
private ImageSlider imageSlider;
|
||||||
|
|||||||
@@ -1,20 +1,99 @@
|
|||||||
package com.capstone.foodify.Fragment;
|
package com.capstone.foodify.Fragment;
|
||||||
|
|
||||||
|
import static com.capstone.foodify.Fragment.HomeFragment.listFood;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
import androidx.fragment.app.Fragment;
|
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.widget.Toast;
|
||||||
|
|
||||||
|
import com.capstone.foodify.Model.Food.FoodAdapter;
|
||||||
import com.capstone.foodify.R;
|
import com.capstone.foodify.R;
|
||||||
|
import com.paulrybitskyi.persistentsearchview.PersistentSearchView;
|
||||||
|
import com.paulrybitskyi.persistentsearchview.listeners.OnSearchConfirmedListener;
|
||||||
|
import com.paulrybitskyi.persistentsearchview.utils.VoiceRecognitionDelegate;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
public class SearchFragment extends Fragment {
|
public class SearchFragment extends Fragment {
|
||||||
|
|
||||||
|
private RecyclerView recycler_view_search;
|
||||||
|
private FoodAdapter foodAdapter;
|
||||||
|
private PersistentSearchView persistentSearchView;
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
// Inflate the layout for this fragment
|
View view = inflater.inflate(R.layout.fragment_search, container, false);
|
||||||
return inflater.inflate(R.layout.fragment_search, container, false);
|
|
||||||
|
//Init Component
|
||||||
|
recycler_view_search = view.findViewById(R.id.recycler_view_search);
|
||||||
|
persistentSearchView = view.findViewById(R.id.search_view);
|
||||||
|
|
||||||
|
foodAdapter = new FoodAdapter(getContext());
|
||||||
|
|
||||||
|
GridLayoutManager gridLayoutManager = new GridLayoutManager(getContext(), 3);
|
||||||
|
recycler_view_search.setLayoutManager(gridLayoutManager);
|
||||||
|
|
||||||
|
foodAdapter.setData(listFood);
|
||||||
|
recycler_view_search.setAdapter(foodAdapter);
|
||||||
|
|
||||||
|
|
||||||
|
persistentSearchView.setOnLeftBtnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
Toast.makeText(getContext(), "Left Btn", Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
persistentSearchView.setOnClearInputBtnClickListener(new View.OnClickListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
// Handle the clear input button click
|
||||||
|
Toast.makeText(getContext(), "Clear Btn", Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
// Setting a delegate for the voice recognition input
|
||||||
|
persistentSearchView.setVoiceRecognitionDelegate(new VoiceRecognitionDelegate(this));
|
||||||
|
|
||||||
|
persistentSearchView.setOnSearchConfirmedListener(new OnSearchConfirmedListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSearchConfirmed(PersistentSearchView searchView, String query) {
|
||||||
|
// Handle a search confirmation. This is the place where you'd
|
||||||
|
// want to perform a search against your data provider.
|
||||||
|
Toast.makeText(getContext(), "setOnSearchConfirmedListener", Toast.LENGTH_SHORT).show();
|
||||||
|
|
||||||
|
searchView.collapse();
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
// Disabling the suggestions since they are unused in
|
||||||
|
// the simple implementation
|
||||||
|
persistentSearchView.setSuggestionsDisabled(false);
|
||||||
|
|
||||||
|
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,5 @@
|
|||||||
|
package com.capstone.foodify;
|
||||||
|
|
||||||
|
public interface IOnBackPressed {
|
||||||
|
boolean onBackPressed();
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.capstone.foodify.Model.Food;
|
package com.capstone.foodify.Model.Food;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
import android.text.Layout;
|
import android.text.Layout;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@@ -18,7 +19,13 @@ import java.util.List;
|
|||||||
public class FoodAdapter extends RecyclerView.Adapter<FoodAdapter.FoodViewHolder>{
|
public class FoodAdapter extends RecyclerView.Adapter<FoodAdapter.FoodViewHolder>{
|
||||||
|
|
||||||
private List<Food> listFood;
|
private List<Food> listFood;
|
||||||
|
private Context context;
|
||||||
|
|
||||||
|
public FoodAdapter(Context context){
|
||||||
|
this.context = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FoodAdapter() {}
|
||||||
public void setData(List<Food> list) {
|
public void setData(List<Food> list) {
|
||||||
this.listFood = list;
|
this.listFood = list;
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 8.6 KiB |
@@ -1,14 +1,30 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<androidx.constraintlayout.widget.ConstraintLayout 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"
|
||||||
tools:context=".Fragment.SearchFragment">
|
tools:context=".Fragment.SearchFragment"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
>
|
||||||
|
|
||||||
<!-- TODO: Update blank fragment layout -->
|
<com.paulrybitskyi.persistentsearchview.PersistentSearchView
|
||||||
<TextView
|
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="match_parent"
|
android:layout_height="wrap_content" />
|
||||||
android:text="@string/hello_blank_fragment" />
|
|
||||||
|
|
||||||
</FrameLayout>
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
|
android:id="@+id/recycler_view_search"
|
||||||
|
tools:listitem="@layout/list_foods"
|
||||||
|
android:layout_marginStart="15dp"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/search_view"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
/>
|
||||||
|
|
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
<?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="157dp"
|
android:layout_width="120dp"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="190dp"
|
||||||
android:layout_marginStart="0dp"
|
android:layout_marginStart="0dp"
|
||||||
android:layout_marginTop="10dp"
|
android:layout_marginTop="10dp"
|
||||||
android:layout_marginBottom="10dp"
|
android:layout_marginBottom="10dp"
|
||||||
@@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
<androidx.cardview.widget.CardView
|
<androidx.cardview.widget.CardView
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="230dp"
|
android:layout_height="189dp"
|
||||||
app:cardCornerRadius="10dp"
|
app:cardCornerRadius="10dp"
|
||||||
>
|
>
|
||||||
|
|
||||||
@@ -20,8 +20,8 @@
|
|||||||
|
|
||||||
<com.makeramen.roundedimageview.RoundedImageView
|
<com.makeramen.roundedimageview.RoundedImageView
|
||||||
android:id="@+id/image_view"
|
android:id="@+id/image_view"
|
||||||
android:layout_width="157dp"
|
android:layout_width="120dp"
|
||||||
android:layout_height="157dp"
|
android:layout_height="120dp"
|
||||||
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,10 +33,11 @@
|
|||||||
<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="24dp"
|
android:layout_width="20dp"
|
||||||
android:layout_height="26dp"
|
android:layout_height="22dp"
|
||||||
android:layout_marginEnd="5dp"
|
android:layout_marginEnd="5dp"
|
||||||
android:layout_marginBottom="2dp"
|
android:layout_marginBottom="2dp"
|
||||||
|
android:background="@drawable/transparent_background"
|
||||||
app:layout_constraintEnd_toEndOf="@id/image_view"
|
app:layout_constraintEnd_toEndOf="@id/image_view"
|
||||||
app:layout_constraintBottom_toBottomOf="@id/image_view"
|
app:layout_constraintBottom_toBottomOf="@id/image_view"
|
||||||
android:contentDescription="@string/favourite_icon"
|
android:contentDescription="@string/favourite_icon"
|
||||||
@@ -45,13 +46,13 @@
|
|||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/title"
|
android:id="@+id/title"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="22dp"
|
android:layout_height="34dp"
|
||||||
android:text="@string/food_title"
|
android:text="@string/food_title"
|
||||||
android:layout_marginStart="6dp"
|
android:layout_marginStart="6dp"
|
||||||
android:textSize="12sp"
|
android:textSize="12sp"
|
||||||
android:fontFamily="@font/opensans"
|
android:fontFamily="@font/opensans"
|
||||||
android:textColor="@color/black"
|
android:textColor="@color/black"
|
||||||
android:layout_marginTop="5dp"
|
android:layout_marginTop="3dp"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/image_view"
|
app:layout_constraintTop_toBottomOf="@+id/image_view"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
/>
|
/>
|
||||||
@@ -61,7 +62,7 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
android:layout_marginTop="10dp"
|
android:layout_marginTop="5dp"
|
||||||
android:layout_marginStart="2dp"
|
android:layout_marginStart="2dp"
|
||||||
app:layout_constraintTop_toBottomOf="@id/title"
|
app:layout_constraintTop_toBottomOf="@id/title"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
@@ -69,7 +70,7 @@
|
|||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/price"
|
android:id="@+id/price"
|
||||||
android:textSize="20sp"
|
android:textSize="18sp"
|
||||||
android:textColor="@color/primaryColor"
|
android:textColor="@color/primaryColor"
|
||||||
android:fontFamily="@font/bebas"
|
android:fontFamily="@font/bebas"
|
||||||
android:layout_marginStart="6dp"
|
android:layout_marginStart="6dp"
|
||||||
@@ -82,9 +83,9 @@
|
|||||||
android:src="@drawable/basket_icon"
|
android:src="@drawable/basket_icon"
|
||||||
android:layout_marginTop="4dp"
|
android:layout_marginTop="4dp"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_weight="0.2"
|
android:layout_weight="0.18"
|
||||||
android:layout_height="20dp"
|
android:layout_height="20dp"
|
||||||
android:layout_marginEnd="2dp"
|
android:layout_marginEnd="5dp"
|
||||||
android:contentDescription="@string/basket_icon"
|
android:contentDescription="@string/basket_icon"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user