mirror of
https://github.com/Nezumi-2711/Foodify.git
synced 2026-09-22 13:38:41 +00:00
Add search view
This commit is contained in:
+4
-2
@@ -30,7 +30,7 @@ android {
|
||||
|
||||
dependencies {
|
||||
|
||||
implementation 'androidx.appcompat:appcompat:1.6.0'
|
||||
implementation 'androidx.appcompat:appcompat:1.6.1'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
|
||||
|
||||
|
||||
@@ -50,5 +50,7 @@ dependencies {
|
||||
implementation 'com.github.bumptech.glide:glide: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();
|
||||
}
|
||||
|
||||
|
||||
private void initComponent() {
|
||||
bottomNavigationView = findViewById(R.id.bottom_nav);
|
||||
viewPager2 = findViewById(R.id.viewPager);
|
||||
|
||||
@@ -31,7 +31,7 @@ import retrofit2.Response;
|
||||
|
||||
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 ImageSlider imageSlider;
|
||||
|
||||
@@ -1,20 +1,99 @@
|
||||
package com.capstone.foodify.Fragment;
|
||||
|
||||
import static com.capstone.foodify.Fragment.HomeFragment.listFood;
|
||||
|
||||
import android.app.Activity;
|
||||
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.View;
|
||||
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.paulrybitskyi.persistentsearchview.PersistentSearchView;
|
||||
import com.paulrybitskyi.persistentsearchview.listeners.OnSearchConfirmedListener;
|
||||
import com.paulrybitskyi.persistentsearchview.utils.VoiceRecognitionDelegate;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class SearchFragment extends Fragment {
|
||||
|
||||
private RecyclerView recycler_view_search;
|
||||
private FoodAdapter foodAdapter;
|
||||
private PersistentSearchView persistentSearchView;
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
// Inflate the layout for this fragment
|
||||
return inflater.inflate(R.layout.fragment_search, container, false);
|
||||
View view = 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;
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.Layout;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@@ -18,7 +19,13 @@ import java.util.List;
|
||||
public class FoodAdapter extends RecyclerView.Adapter<FoodAdapter.FoodViewHolder>{
|
||||
|
||||
private List<Food> listFood;
|
||||
private Context context;
|
||||
|
||||
public FoodAdapter(Context context){
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public FoodAdapter() {}
|
||||
public void setData(List<Food> list) {
|
||||
this.listFood = list;
|
||||
notifyDataSetChanged();
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 8.6 KiB |
@@ -1,14 +1,30 @@
|
||||
<?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"
|
||||
android:layout_width="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 -->
|
||||
<TextView
|
||||
<com.paulrybitskyi.persistentsearchview.PersistentSearchView
|
||||
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_height="match_parent"
|
||||
android:text="@string/hello_blank_fragment" />
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
</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"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="157dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_width="120dp"
|
||||
android:layout_height="190dp"
|
||||
android:layout_marginStart="0dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginBottom="10dp"
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
<androidx.cardview.widget.CardView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="230dp"
|
||||
android:layout_height="189dp"
|
||||
app:cardCornerRadius="10dp"
|
||||
>
|
||||
|
||||
@@ -20,8 +20,8 @@
|
||||
|
||||
<com.makeramen.roundedimageview.RoundedImageView
|
||||
android:id="@+id/image_view"
|
||||
android:layout_width="157dp"
|
||||
android:layout_height="157dp"
|
||||
android:layout_width="120dp"
|
||||
android:layout_height="120dp"
|
||||
android:src="@drawable/food"
|
||||
android:scaleType="centerCrop"
|
||||
app:riv_corner_radius="10dip"
|
||||
@@ -33,10 +33,11 @@
|
||||
<ImageView
|
||||
android:id="@+id/favourite_icon"
|
||||
android:src="@drawable/baseline_favorite_border_24"
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="26dp"
|
||||
android:layout_width="20dp"
|
||||
android:layout_height="22dp"
|
||||
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"
|
||||
@@ -45,13 +46,13 @@
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="22dp"
|
||||
android:layout_height="34dp"
|
||||
android:text="@string/food_title"
|
||||
android:layout_marginStart="6dp"
|
||||
android:textSize="12sp"
|
||||
android:fontFamily="@font/opensans"
|
||||
android:textColor="@color/black"
|
||||
android:layout_marginTop="5dp"
|
||||
android:layout_marginTop="3dp"
|
||||
app:layout_constraintTop_toBottomOf="@+id/image_view"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
/>
|
||||
@@ -61,7 +62,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginTop="5dp"
|
||||
android:layout_marginStart="2dp"
|
||||
app:layout_constraintTop_toBottomOf="@id/title"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
@@ -69,7 +70,7 @@
|
||||
|
||||
<TextView
|
||||
android:id="@+id/price"
|
||||
android:textSize="20sp"
|
||||
android:textSize="18sp"
|
||||
android:textColor="@color/primaryColor"
|
||||
android:fontFamily="@font/bebas"
|
||||
android:layout_marginStart="6dp"
|
||||
@@ -82,9 +83,9 @@
|
||||
android:src="@drawable/basket_icon"
|
||||
android:layout_marginTop="4dp"
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="0.2"
|
||||
android:layout_weight="0.18"
|
||||
android:layout_height="20dp"
|
||||
android:layout_marginEnd="2dp"
|
||||
android:layout_marginEnd="5dp"
|
||||
android:contentDescription="@string/basket_icon"
|
||||
/>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user