-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHomeActivity.kt
More file actions
111 lines (91 loc) · 3.55 KB
/
HomeActivity.kt
File metadata and controls
111 lines (91 loc) · 3.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package com.example.projectfigma.Activity
import android.os.Bundle
import android.widget.TextView
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.GravityCompat
import androidx.drawerlayout.widget.DrawerLayout
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.example.projectfigma.Adapters.BestSellerAdapter
import com.example.projectfigma.DAO.DishesDao
import com.example.projectfigma.DAO.UserDao
import com.example.projectfigma.DataBase.DataBase
import com.example.projectfigma.Entites.Dishes
import com.example.projectfigma.Entites.User
import com.example.projectfigma.Fragments.*
import com.example.projectfigma.R
import com.example.projectfigma.Util.StatusBar
class HomeActivity : AppCompatActivity(),
HeaderButtonsFragment.Listener {
private lateinit var adapter: BestSellerAdapter
private lateinit var dao: DishesDao
private lateinit var userDao: UserDao
private lateinit var drawer: DrawerLayout
private var user: User? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_home)
StatusBar.hideStatusBar(window)
drawer = findViewById(R.id.drawer_layout)
val db = DataBase.getDb(this)
dao = db.getDishesDao()
userDao = db.getUserDao()
val email = intent.getStringExtra("user_email")
if (!email.isNullOrBlank()) {
user = userDao.getUserByEmail(email)
}
val rv = findViewById<RecyclerView>(R.id.rvBestSellers).apply {
layoutManager = LinearLayoutManager(
this@HomeActivity,
LinearLayoutManager.HORIZONTAL,
false
)
adapter = BestSellerAdapter(emptyList()) { item: Dishes ->
Toast.makeText(
this@HomeActivity,
"Clicked: ${item.price}",
Toast.LENGTH_SHORT
).show()
}.also { this@HomeActivity.adapter = it }
}
dao.getBestSellersWithLimit(4).observe(this) { list ->
adapter.updateList(list)
}
supportFragmentManager
.beginTransaction()
.replace(R.id.buttonPanel, BottomPanelFragment())
.commit()
}
override fun onCartClicked() {
supportFragmentManager.beginTransaction()
.replace(R.id.right_drawer_container, CartFragment())
.commitNow()
drawer.openDrawer(GravityCompat.END)
}
override fun onNotificationsClicked() {
supportFragmentManager.beginTransaction()
.replace(R.id.right_drawer_container, NotificationFragment())
.commitNow()
drawer.openDrawer(GravityCompat.END)
}
override fun onProfileClicked() {
val profileMenu = SideMenuFragment()
supportFragmentManager.beginTransaction()
.replace(R.id.right_drawer_container, profileMenu)
.commitNow()
profileMenu.setUserData(
name = user?.name.takeUnless { it.isNullOrBlank() } ?: "Гость",
email = user?.gmail.takeUnless { it.isNullOrBlank() } ?: "Не указано",
avatarRes = R.drawable.ic_profile_placeholder
)
drawer.openDrawer(GravityCompat.END)
}
override fun onBackPressed() {
if (drawer.isDrawerOpen(GravityCompat.END)) {
drawer.closeDrawer(GravityCompat.END)
} else {
super.onBackPressed()
}
}
}