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
4 changes: 4 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,8 @@ dependencies {
// Glide или Picasso для загрузки картинок из БД или интернета
implementation ("com.github.bumptech.glide:glide:4.13.2")
kapt ("com.github.bumptech.glide:compiler:4.13.2")
implementation("androidx.viewpager2:viewpager2:1.1.0")
implementation ("com.google.android.material:material:1.8.0")
implementation ("io.coil-kt:coil:2.2.2") // или Glide для картинок
implementation ("androidx.lifecycle:lifecycle-livedata-ktx:2.6.1")
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,23 @@ class HomeActivity : AppCompatActivity(),
user = userDao.getUserByEmail(email)
}

val items: List<BestSeller> = dao.getAll()
findViewById<RecyclerView>(R.id.rvBestSellers).apply {
val rv = findViewById<RecyclerView>(R.id.rvBestSellers).apply {
layoutManager = LinearLayoutManager(
this@HomeActivity,
LinearLayoutManager.HORIZONTAL,
false
)
adapter = BestSellerAdapter(items) { item ->
adapter = BestSellerAdapter(emptyList()) { item: BestSeller ->
Toast.makeText(
this@HomeActivity,
"Clicked: ${item.price}",
Toast.LENGTH_SHORT
).show()
}.also { this@HomeActivity.adapter = it }
}

dao.getAllV().observe(this) { list ->
adapter.updateList(list)
}
supportFragmentManager
.beginTransaction()
.replace(R.id.buttonPanel, BottomPanelFragment())
Expand Down Expand Up @@ -101,4 +102,4 @@ class HomeActivity : AppCompatActivity(),
super.onBackPressed()
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import com.example.projectfigma.Entites.BestSeller
import com.example.projectfigma.R

class BestSellerAdapter(
private val items: List<BestSeller>,
private var items: List<BestSeller>,
private val onClick: (BestSeller) -> Unit
) : RecyclerView.Adapter<BestSellerAdapter.VH>() {

Expand Down Expand Up @@ -40,5 +40,10 @@ class BestSellerAdapter(
holder.bind(items[position])
}

fun updateList(newItems: List<BestSeller>) {
items = newItems
notifyDataSetChanged()
}

override fun getItemCount() = items.size
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.example.projectfigma.Adapters

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import coil.load
import com.example.projectfigma.Entites.BestSeller
import com.example.projectfigma.R

class PromoAdapter(private var items: List<BestSeller>) :
RecyclerView.Adapter<PromoAdapter.VH>() {

inner class VH(view: View) : RecyclerView.ViewHolder(view) {
private val image: ImageView = view.findViewById(R.id.promo_image)
private val title: TextView = view.findViewById(R.id.title)
private val discount: TextView = view.findViewById(R.id.discount)

fun bind(item: BestSeller) {
title.text = "Experience our delicious new dish"
discount.text = "${30}% OFF"
}
}

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

override fun onBindViewHolder(holder: VH, position: Int) {
holder.bind(items[position])
}

override fun getItemCount(): Int = items.size

/** Вызываем из Activity/Fragment при получении новых данных */
fun updateList(newItems: List<BestSeller>) {
items = newItems
notifyDataSetChanged()
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.projectfigma.DAO

import androidx.lifecycle.LiveData
import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
Expand All @@ -18,4 +19,7 @@ interface BestSellerDao {
// Вставить список объектов
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertAll(items: List<BestSeller>)

@Query("SELECT * FROM best_seller")
fun getAllV(): LiveData<List<BestSeller>>
}
87 changes: 87 additions & 0 deletions app/src/main/java/com/example/projectfigma/Fragments/BannerFood.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package com.example.projectfigma.Fragments

import android.os.Bundle
import android.os.Handler
import android.os.Looper
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.viewpager2.widget.ViewPager2
import com.example.projectfigma.Adapters.PromoAdapter
import com.example.projectfigma.DataBase.DataBase
import com.example.projectfigma.R
import com.example.projectfigma.databinding.FragmentBannerFoodBinding
import com.example.projectfigma.databinding.FragmentBestSellerBinding
import com.google.android.material.tabs.TabLayout
import com.google.android.material.tabs.TabLayoutMediator

class BannerFood : Fragment() {
private var _binding: FragmentBannerFoodBinding? = null
private val binding get() = _binding!!
private lateinit var promoAdapter: PromoAdapter


override fun onCreate(savedInstanceState: Bundle?) {

super.onCreate(savedInstanceState)
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

// 1) Инициализируем адаптер
promoAdapter = PromoAdapter(emptyList())
binding.viewPager.adapter = promoAdapter

// 2) Настраиваем TabLayoutMediator, сразу задаём иконки
TabLayoutMediator(binding.tabLayout, binding.viewPager) { tab, _ ->
tab.setIcon(R.drawable.tab_indicator_unselected)
}.attach()

// 3) Подписываемся на смену вкладки, чтобы менять иконки
binding.tabLayout.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
override fun onTabSelected(tab: TabLayout.Tab) {
tab.setIcon(R.drawable.tab_indicator_selected)
}

override fun onTabUnselected(tab: TabLayout.Tab) {
tab.setIcon(R.drawable.tab_indicator_unselected)
}

override fun onTabReselected(tab: TabLayout.Tab) {}
})

// 4) Тут же можете запустить автопрокрутку, если она нужна в фрагменте
val handler = Handler(Looper.getMainLooper())
handler.postDelayed(object : Runnable {
override fun run() {
if (promoAdapter.itemCount > 1) {
val next = (binding.viewPager.currentItem + 1) % promoAdapter.itemCount
binding.viewPager.setCurrentItem(next, true)
}
handler.postDelayed(this, 4000)
}
}, 4000)

// 5) А обновление списка (LiveData) можно тоже повесить здесь:
val dao = DataBase.getDb(requireContext()).getBestSellerDao()
dao.getAllV().observe(viewLifecycleOwner) { list ->
promoAdapter.updateList(list)
}
}

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
_binding = FragmentBannerFoodBinding.inflate(inflater, container, false)
return binding.root
}

override fun onDestroyView() {
super.onDestroyView()
_binding = null
}
}
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/bg_banner.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">
<solid android:color="#F15A29"/>
<corners android:radius="16dp"/>
</shape>
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/circle_yellow.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="oval">
<size android:width="80dp" android:height="80dp"/>
<solid android:color="#FFDD88"/>
</shape>
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/dot_active.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="oval">
<size android:width="8dp" android:height="8dp"/>
<solid android:color="#F7D046"/>
</shape>
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/dot_inactive.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="oval">
<size android:width="8dp" android:height="8dp"/>
<solid android:color="#FFE8B0"/>
</shape>
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/indicator_selected.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">
<size android:width="16dp" android:height="4dp"/>
<solid android:color="#E64A19"/>
<corners android:radius="2dp"/>
</shape>
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/indicator_unselected.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">
<size android:width="16dp" android:height="4dp"/>
<solid android:color="#FFE082"/>
<corners android:radius="2dp"/>
</shape>
Binary file added app/src/main/res/drawable/pizza_sample.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/tab_indicator_selected.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="oval">
<size android:width="8dp" android:height="8dp"/>
<solid android:color="@color/organe"/>
</shape>
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/tab_indicator_unselected.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="oval">
<size android:width="6dp" android:height="6dp"/>
<solid android:color="@color/dividing_line"/>
</shape>
3 changes: 1 addition & 2 deletions app/src/main/res/layout/activity_home.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
android:layout_width="match_parent"
android:layout_height="match_parent">

<!-- ======= 1. ОРИГИНАЛЬНЫЙ КОНТЕНТ (ваш ConstraintLayout) ======= -->
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/goToSignUp"
android:layout_width="match_parent"
Expand Down Expand Up @@ -161,4 +160,4 @@
android:layout_width="330dp"
android:layout_height="match_parent"
android:layout_gravity="end"/>
</androidx.drawerlayout.widget.DrawerLayout>
</androidx.drawerlayout.widget.DrawerLayout>
24 changes: 24 additions & 0 deletions app/src/main/res/layout/fragment_banner_food.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<androidx.viewpager2.widget.ViewPager2
android:id="@+id/viewPager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>

<com.google.android.material.tabs.TabLayout
android:id="@+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
app:tabMode="fixed"
app:tabGravity="center"
app:tabIndicatorFullWidth="false"
app:layout_constraintTop_toBottomOf="@id/viewPager"/>
</androidx.constraintlayout.widget.ConstraintLayout>
Loading