Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Activity.RecomendationActivity" />
<activity android:name=".Activity.WelcomeActivity" />
<activity android:name=".Activity.LogActivity" />
<activity android:name=".Activity.RegActivity" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.example.projectfigma.Activity

import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.example.projectfigma.Fragments.BottomPanelFragment
import com.example.projectfigma.R
import com.example.projectfigma.Util.StatusBar
import com.example.projectfigma.databinding.ActivityAdvertisingPageBinding
import com.example.projectfigma.databinding.ActivityRecomendationBinding

class RecomendationActivity : AppCompatActivity() {
private lateinit var binding: ActivityRecomendationBinding

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

binding = ActivityRecomendationBinding.inflate(layoutInflater)
setContentView(binding.root)
StatusBar.hideStatusBar(window)

supportFragmentManager.beginTransaction()
.replace(R.id.buttonPanel, BottomPanelFragment())
.commit()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.example.projectfigma.Adapters

import android.net.Uri
import android.view.View
import android.view.ViewGroup
import android.view.LayoutInflater
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.example.projectfigma.Entites.Dishes
import com.example.projectfigma.R

class MainRecommendAdapter(
private var dishes: List<Dishes>
) : RecyclerView.Adapter<MainRecommendAdapter.ViewHolder>() {

inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
val imgFood: ImageView = view.findViewById(R.id.imgFood)
val imgCategory: ImageView = view.findViewById(R.id.imgCategory)
val tvTitle: TextView = view.findViewById(R.id.tvTitle)
val tvDesc: TextView = view.findViewById(R.id.tvDesc)
val tvPrice: TextView = view.findViewById(R.id.tvPrice)
val tvRating: TextView = view.findViewById(R.id.tvRating)
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val v = LayoutInflater.from(parent.context)
.inflate(R.layout.item_main_recomend, parent, false)
return ViewHolder(v)
}

override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val dish = dishes[position]

Glide.with(holder.itemView.context)
.load(Uri.parse(dish.imageUri))
.into(holder.imgFood)
holder.imgCategory.setImageResource(dish.category.iconRes)
holder.tvTitle.text = dish.name
holder.tvDesc.text = dish.description
holder.tvPrice.text = "$" + dish.price.toString()
holder.tvRating.text = dish.rating.toString()
}

override fun getItemCount(): Int = dishes.size
fun updateData(newItems: List<Dishes>) {
dishes = newItems
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.example.projectfigma.Fragments

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.View
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.example.projectfigma.Adapters.MainBestSellerAdapter
import com.example.projectfigma.Adapters.MainRecommendAdapter
import com.example.projectfigma.DAO.DishesDao
import com.example.projectfigma.DataBase.DataBase
import com.example.projectfigma.R
class RecomandationFragment : Fragment(R.layout.fragment_recomandation_fragemnt) {

private lateinit var dataBase: DataBase
private lateinit var dishesDao: DishesDao

// Создаём адаптер сразу с пустым списком
private val adapter by lazy { MainRecommendAdapter(emptyList()) }

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val rv = view.findViewById<RecyclerView>(R.id.popularRecyclerView)
rv.layoutManager = GridLayoutManager(requireContext(), 2)
rv.adapter = adapter // устанавливаем адаптер сразу

dataBase = DataBase.getDb(requireContext())
dishesDao = dataBase.getDishesDao()

// Наблюдаем за списком рекомендаций
dishesDao.getRecommend().observe(viewLifecycleOwner) { dishList ->
// Если MainRecommendAdapter у вас наследник ListAdapter:
// adapter.submitList(dishList)
// Иначе:
adapter.updateData(dishList)
adapter.notifyDataSetChanged()
}
}
}
15 changes: 12 additions & 3 deletions app/src/main/java/com/example/projectfigma/Fragments/Recommend.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package com.example.projectfigma.Fragments

import android.content.Intent
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.example.projectfigma.Activity.BestSellerActivity
import com.example.projectfigma.Activity.RecomendationActivity
import com.example.projectfigma.Adapters.RecommendAdapter
import com.example.projectfigma.DataBase.DataBase
import com.example.projectfigma.R
Expand All @@ -16,22 +20,27 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

class Recommend : Fragment(R.layout.fragment_recommend) {

private val db by lazy { DataBase.getDb(requireContext()) }

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val rv = view.findViewById<RecyclerView>(R.id.rvRecommend)
val textRecomend = view.findViewById<TextView>(R.id.tvHeader)
rv.layoutManager = GridLayoutManager(requireContext(), 2)

textRecomend.setOnClickListener(){
val intent = Intent(requireContext(), RecomendationActivity::class.java)
startActivity(intent)
requireActivity().finish()
}

viewLifecycleOwner.lifecycleScope.launch {
// 1. Получаем пользователя в IO
val sessionEmail = db.getSessionDao().getSession()?.userEmail.orEmpty()
val user = withContext(Dispatchers.IO) {
db.getUserDao().getUserByEmail(sessionEmail)
}

// 2. Теперь наблюдаем LiveData рекомендаций
// и каждый раз создаём новый адаптер с реальным списком
withContext(Dispatchers.Main) {
db.getDishesDao()
.getRecommend()
Expand Down
Binary file added app/src/main/res/drawable/ic_badge_new.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/rounded_corners.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="16dp"/>
<solid android:color="@android:color/white"/> <!-- цвет фона, если нужно -->
</shape>
71 changes: 71 additions & 0 deletions app/src/main/res/layout/activity_recomendation.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background">

<!-- Заголовок -->
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/headerLayout"
android:layout_width="match_parent"
android:layout_height="140dp"
app:layout_constraintTop_toTopOf="parent">

<TextView
android:id="@+id/loginHeader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Recommendations"
android:textColor="@android:color/white"
android:textSize="28sp"
android:textStyle="bold"
android:textFontWeight="700"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.656" />

<ImageView
android:id="@+id/exitArrow"
android:layout_width="15dp"
android:layout_height="15dp"
android:layout_marginStart="16dp"
android:src="@drawable/exit_arrow"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/loginHeader"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.632" />
</androidx.constraintlayout.widget.ConstraintLayout>

<!-- Нижняя панель -->

<FrameLayout
android:layout_width="match_parent"
android:layout_height="595dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/headerLayout">

<fragment
android:id="@+id/food_favorite_fragment"
android:name="com.example.projectfigma.Fragments.RecomandationFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout="@layout/fragment_recomandation_fragemnt" />

</FrameLayout>

<include
layout="@layout/fragment_bottom_panel"
android:layout_width="wrap_content"
android:layout_height="55dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
55 changes: 55 additions & 0 deletions app/src/main/res/layout/fragment_recomandation_fragemnt.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:id="@+id/titleText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:paddingStart="10dp"
android:paddingEnd="10dp"
android:text="Discover the dishes \n recommended by the chef."
android:textAlignment="center"
android:textAppearance="@style/TextAppearance.AppCompat.Large"
android:textColor="#FF5722"
android:textFontWeight="700"
android:textSize="20dp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/popularRecyclerView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:padding="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/frameLayout3"
app:layout_constraintVertical_bias="1.0" />

<FrameLayout
android:id="@+id/frameLayout3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/titleText">

<include
layout="@layout/item_new_recomend"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
/>

</FrameLayout>


</androidx.constraintlayout.widget.ConstraintLayout>
Loading