lab 3
This commit is contained in:
parent
22c0b45ee5
commit
683679737a
29
app/src/main/AndroidManifest.xml
Normal file
29
app/src/main/AndroidManifest.xml
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools">
|
||||||
|
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
|
||||||
|
<application
|
||||||
|
android:allowBackup="true"
|
||||||
|
android:dataExtractionRules="@xml/data_extraction_rules"
|
||||||
|
android:fullBackupContent="@xml/backup_rules"
|
||||||
|
android:icon="@drawable/icon"
|
||||||
|
android:label="@string/app_name"
|
||||||
|
android:roundIcon="@drawable/icon"
|
||||||
|
android:supportsRtl="true"
|
||||||
|
android:theme="@style/Theme.Pizza"
|
||||||
|
tools:targetApi="31">
|
||||||
|
<activity
|
||||||
|
android:name=".MainActivity"
|
||||||
|
android:exported="true">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
|
||||||
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
|
</intent-filter>
|
||||||
|
</activity>
|
||||||
|
<meta-data
|
||||||
|
android:name="preloaded_fonts"
|
||||||
|
android:resource="@array/preloaded_fonts" />
|
||||||
|
</application>
|
||||||
|
|
||||||
|
</manifest>
|
@ -1,33 +1,67 @@
|
|||||||
package com.example.pizza
|
package com.example.pizza
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import androidx.fragment.app.Fragment
|
|
||||||
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.widget.Button
|
import android.widget.Button
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
|
import android.widget.Toast
|
||||||
|
import androidx.fragment.app.Fragment
|
||||||
|
import androidx.fragment.app.activityViewModels
|
||||||
|
import androidx.fragment.app.viewModels
|
||||||
|
import androidx.lifecycle.ViewModelProvider
|
||||||
|
import androidx.lifecycle.ViewModelStore
|
||||||
|
import androidx.lifecycle.ViewModelStoreOwner
|
||||||
import androidx.navigation.Navigation
|
import androidx.navigation.Navigation
|
||||||
|
import com.example.pizza.Model.User.UserDao
|
||||||
|
import com.example.pizza.database.AppDatabase
|
||||||
|
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
|
||||||
|
import io.reactivex.rxjava3.schedulers.Schedulers
|
||||||
|
|
||||||
|
|
||||||
class Auth : Fragment() {
|
class Auth : Fragment() {
|
||||||
|
|
||||||
|
private var userDao: UserDao? = null
|
||||||
override fun onCreateView(
|
override fun onCreateView(
|
||||||
inflater: LayoutInflater, container: ViewGroup?,
|
inflater: LayoutInflater, container: ViewGroup?,
|
||||||
savedInstanceState: Bundle?
|
savedInstanceState: Bundle?
|
||||||
): View? {
|
): View? {
|
||||||
|
|
||||||
// Inflate the layout for this fragment
|
// Inflate the layout for this fragment
|
||||||
|
userDao = context?.let { AppDatabase.getInstance(it).userDao() }
|
||||||
val view = inflater.inflate(R.layout.fragment_auth, container, false)
|
val view = inflater.inflate(R.layout.fragment_auth, container, false)
|
||||||
view.findViewById<Button>(R.id.button_auth).setOnClickListener {buttonClick(view)}
|
view.findViewById<Button>(R.id.button_auth).setOnClickListener {buttonClick(view)}
|
||||||
view.findViewById<TextView>(R.id.link_to_reg).setOnClickListener{TextViewClick(view)}
|
view.findViewById<TextView>(R.id.link_to_reg).setOnClickListener{TextViewClick(view)}
|
||||||
|
|
||||||
return view
|
return view
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("CheckResult", "SuspiciousIndentation")
|
||||||
private fun buttonClick(view: View) {
|
private fun buttonClick(view: View) {
|
||||||
val action = AuthDirections
|
val login = view.findViewById<TextView>(R.id.auth_user_login)?.text.toString().trim()
|
||||||
.actionNavigationAuthToNavigationPizzaList()
|
val pass = view.findViewById<TextView>(R.id.auth_user_pass)?.text.toString().trim()
|
||||||
Navigation.findNavController(view).navigate(action)
|
val viewModel: myViewModel by activityViewModels()
|
||||||
|
if(login.length == 0 || pass.length ==0){
|
||||||
|
Toast.makeText(view.context, "Укажите логин или пароль", Toast.LENGTH_SHORT).show()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
userDao?.getByLoginAndPassword(login, pass)?.subscribeOn(Schedulers.io())
|
||||||
|
?.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
?.doOnError { Toast.makeText(view.context, "Неверный логин или пароль", Toast.LENGTH_SHORT).show() }
|
||||||
|
?.doOnSuccess { Toast.makeText(view.context, "Добро пожаловать", Toast.LENGTH_SHORT).show() }
|
||||||
|
?.onErrorComplete()
|
||||||
|
?.subscribe{user ->
|
||||||
|
viewModel.setId(user.uid!!)
|
||||||
|
if(user.role.equals("admin"))
|
||||||
|
viewModel.setRole(true)
|
||||||
|
val action = AuthDirections
|
||||||
|
.actionNavigationAuthToNavigationPizzaList()
|
||||||
|
Navigation.findNavController(view).navigate(action)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
private fun TextViewClick(view: View) {
|
private fun TextViewClick(view: View) {
|
||||||
val action = AuthDirections
|
val action = AuthDirections
|
||||||
|
@ -1,41 +1,71 @@
|
|||||||
package com.example.pizza
|
package com.example.pizza
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
|
import android.graphics.Bitmap
|
||||||
|
import android.graphics.BitmapFactory
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
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.widget.Button
|
import android.widget.Button
|
||||||
|
import android.widget.TextView
|
||||||
|
import android.widget.Toast
|
||||||
|
import androidx.core.graphics.drawable.toBitmap
|
||||||
|
import androidx.core.graphics.drawable.toDrawable
|
||||||
|
import androidx.fragment.app.activityViewModels
|
||||||
|
import androidx.fragment.app.viewModels
|
||||||
import androidx.navigation.Navigation
|
import androidx.navigation.Navigation
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import com.example.pizza.Model.Pizza.Pizza
|
import com.example.pizza.Model.Pizza.Pizza
|
||||||
|
import com.example.pizza.Model.Pizza.PizzaDao
|
||||||
import com.example.pizza.Model.PizzaAdapter
|
import com.example.pizza.Model.PizzaAdapter
|
||||||
|
import com.example.pizza.Model.User.User
|
||||||
|
import com.example.pizza.Model.User.UserDao
|
||||||
|
import com.example.pizza.database.AppDatabase
|
||||||
|
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
|
||||||
|
import io.reactivex.rxjava3.schedulers.Schedulers
|
||||||
|
|
||||||
class ListPizza : Fragment() {
|
class ListPizza : Fragment() {
|
||||||
|
private var pizzaDao: PizzaDao? = null
|
||||||
|
private var userDao: UserDao? = null
|
||||||
|
private var currentUser: User? = null
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@SuppressLint("CheckResult")
|
||||||
override fun onCreateView(
|
override fun onCreateView(
|
||||||
inflater: LayoutInflater, container: ViewGroup?,
|
inflater: LayoutInflater, container: ViewGroup?,
|
||||||
savedInstanceState: Bundle?
|
savedInstanceState: Bundle?
|
||||||
): View? {
|
|
||||||
|
|
||||||
|
): View? {
|
||||||
|
userDao = context?.let { AppDatabase.getInstance(it).userDao() }
|
||||||
|
pizzaDao = context?.let { AppDatabase.getInstance(it).pizzaDao() }
|
||||||
|
|
||||||
|
val viewModel: myViewModel by activityViewModels()
|
||||||
val view = inflater.inflate(R.layout.fragment_list_pizza, container, false)
|
val view = inflater.inflate(R.layout.fragment_list_pizza, container, false)
|
||||||
val itemsList : RecyclerView = view.findViewById(R.id.pizzasList)
|
val itemsList : RecyclerView = view.findViewById(R.id.pizzasList)
|
||||||
//TODO("Загрузка из БД!!")
|
|
||||||
var p = Pizza("1","1", listOf("1"),1)
|
if(!viewModel.getRole())
|
||||||
var items = p.getTestPizza()
|
view.findViewById<Button>(R.id.button_add).visibility = View.GONE
|
||||||
|
var items = pizzaDao?.getAll()
|
||||||
|
if (items != null) {
|
||||||
|
items.subscribeOn(Schedulers.io())
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.subscribe { pizzas ->
|
||||||
|
itemsList.adapter = PizzaAdapter(pizzas,view.context, viewModel.getId()!!) }
|
||||||
|
}
|
||||||
view.findViewById<Button>(R.id.button_add).setOnClickListener{
|
view.findViewById<Button>(R.id.button_add).setOnClickListener{
|
||||||
val action = ListPizzaDirections
|
val action = ListPizzaDirections
|
||||||
.actionNavigationListToNavigationCreatePizza()
|
.actionNavigationListToNavigationCreatePizza()
|
||||||
Navigation.findNavController(view).navigate(action)
|
Navigation.findNavController(view).navigate(action)
|
||||||
}
|
}
|
||||||
itemsList.layoutManager = LinearLayoutManager(view.context)
|
itemsList.layoutManager = LinearLayoutManager(view.context)
|
||||||
itemsList.adapter = PizzaAdapter(items,view.context)
|
|
||||||
return view
|
return view
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,13 +1,19 @@
|
|||||||
package com.example.pizza
|
package com.example.pizza
|
||||||
|
|
||||||
|
import android.graphics.Bitmap
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import androidx.activity.viewModels
|
||||||
|
import androidx.core.content.ContextCompat
|
||||||
|
import androidx.core.graphics.drawable.toBitmap
|
||||||
|
import androidx.lifecycle.ViewModelProvider
|
||||||
import androidx.navigation.fragment.NavHostFragment
|
import androidx.navigation.fragment.NavHostFragment
|
||||||
import androidx.navigation.ui.AppBarConfiguration
|
import androidx.navigation.ui.AppBarConfiguration
|
||||||
import androidx.navigation.ui.NavigationUI
|
import androidx.navigation.ui.NavigationUI
|
||||||
import androidx.navigation.ui.setupActionBarWithNavController
|
import androidx.navigation.ui.setupActionBarWithNavController
|
||||||
import androidx.navigation.ui.setupWithNavController
|
import androidx.navigation.ui.setupWithNavController
|
||||||
|
import com.example.pizza.Model.Pizza.Singleton
|
||||||
import com.example.pizza.databinding.ActivityMainBinding
|
import com.example.pizza.databinding.ActivityMainBinding
|
||||||
import com.google.android.material.bottomnavigation.BottomNavigationView
|
import com.google.android.material.bottomnavigation.BottomNavigationView
|
||||||
|
|
||||||
@ -18,6 +24,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
binding = ActivityMainBinding.inflate(layoutInflater)
|
binding = ActivityMainBinding.inflate(layoutInflater)
|
||||||
|
val viewModel: myViewModel by viewModels()
|
||||||
setContentView(binding.root)
|
setContentView(binding.root)
|
||||||
|
|
||||||
val navView: BottomNavigationView = binding.navView
|
val navView: BottomNavigationView = binding.navView
|
||||||
@ -43,7 +50,9 @@ class MainActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
val toolbar = binding.toolbar
|
val toolbar = binding.toolbar
|
||||||
setSupportActionBar(toolbar)
|
setSupportActionBar(toolbar)
|
||||||
|
var drawable = ContextCompat.getDrawable(this, R.drawable.pizza)?.toBitmap(200,200, Bitmap.Config.ARGB_8888)
|
||||||
|
val singleTon : Singleton = Singleton
|
||||||
|
singleTon.btm = drawable
|
||||||
setupActionBarWithNavController(navController, appBarConfiguration)
|
setupActionBarWithNavController(navController, appBarConfiguration)
|
||||||
navView.setupWithNavController(navController)
|
navView.setupWithNavController(navController)
|
||||||
NavigationUI.setupWithNavController(toolbar, navController, appBarConfiguration)
|
NavigationUI.setupWithNavController(toolbar, navController, appBarConfiguration)
|
||||||
|
54
app/src/main/java/com/example/pizza/Model/Basket/Basket.kt
Normal file
54
app/src/main/java/com/example/pizza/Model/Basket/Basket.kt
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
package com.example.pizza.Model.Basket
|
||||||
|
|
||||||
|
import androidx.room.ColumnInfo
|
||||||
|
import androidx.room.Entity
|
||||||
|
import androidx.room.ForeignKey
|
||||||
|
import androidx.room.Ignore
|
||||||
|
import androidx.room.PrimaryKey
|
||||||
|
import com.example.pizza.Model.Pizza.Pizza
|
||||||
|
import com.example.pizza.Model.User.User
|
||||||
|
|
||||||
|
@Entity(tableName = "basket", foreignKeys =
|
||||||
|
[
|
||||||
|
ForeignKey(
|
||||||
|
entity = Pizza::class,
|
||||||
|
parentColumns = ["uid"],
|
||||||
|
childColumns = ["pizza_id"],
|
||||||
|
onDelete = ForeignKey.RESTRICT,
|
||||||
|
onUpdate = ForeignKey.RESTRICT),
|
||||||
|
ForeignKey(
|
||||||
|
entity = User::class,
|
||||||
|
parentColumns = ["uid"],
|
||||||
|
childColumns = ["user_id"],
|
||||||
|
onDelete = ForeignKey.RESTRICT,
|
||||||
|
onUpdate = ForeignKey.RESTRICT),
|
||||||
|
],
|
||||||
|
primaryKeys = ["user_id", "pizza_id"])
|
||||||
|
data class Basket(
|
||||||
|
|
||||||
|
@ColumnInfo(name = "user_id")
|
||||||
|
val user: Int,
|
||||||
|
@ColumnInfo(name = "pizza_id")
|
||||||
|
val pizza: Int,
|
||||||
|
@ColumnInfo(name = "count_pizza")
|
||||||
|
val countPizza: Int
|
||||||
|
|
||||||
|
) {
|
||||||
|
@Ignore
|
||||||
|
constructor(
|
||||||
|
User : User,
|
||||||
|
Pizza : Pizza,
|
||||||
|
Count : Int
|
||||||
|
) : this( User.uid!! , Pizza.uid!! , Count)
|
||||||
|
override fun equals(other: Any?): Boolean {
|
||||||
|
if (this === other) return true
|
||||||
|
if (javaClass != other?.javaClass) return false
|
||||||
|
other as Basket
|
||||||
|
if (user != other.user && pizza != other.pizza) return false
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun hashCode(): Int {
|
||||||
|
return user ?: -1
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
package com.example.pizza.Model.Basket
|
||||||
|
|
||||||
|
import androidx.room.Dao
|
||||||
|
import androidx.room.Delete
|
||||||
|
import androidx.room.Insert
|
||||||
|
import androidx.room.Query
|
||||||
|
import androidx.room.Update
|
||||||
|
import io.reactivex.rxjava3.core.Completable
|
||||||
|
import io.reactivex.rxjava3.core.Flowable
|
||||||
|
|
||||||
|
@Dao
|
||||||
|
interface BasketDao {
|
||||||
|
@Query("select * from basket inner join pizzas on basket.pizza_id = pizzas.uid where basket.user_id = :uid")
|
||||||
|
fun getUserBasket(uid: Int): Flowable<List<PizzaBasket>>
|
||||||
|
@Insert
|
||||||
|
fun insert(group: Basket): Completable
|
||||||
|
|
||||||
|
@Update
|
||||||
|
fun update(group: Basket): Completable
|
||||||
|
|
||||||
|
@Delete
|
||||||
|
fun delete(group: Basket): Completable
|
||||||
|
@Query("delete from basket where basket.user_id = :uid")
|
||||||
|
fun deleteByUser(uid : Int): Completable
|
||||||
|
@Query("delete from basket where basket.user_id = :uid and basket.pizza_id = :pid")
|
||||||
|
fun deleteByUserAndPizza(uid : Int, pid:Int): Completable
|
||||||
|
}
|
@ -0,0 +1,4 @@
|
|||||||
|
package com.example.pizza.Model.Basket
|
||||||
|
|
||||||
|
class PizzaBasket(val pizza_title : String, val pizza_price : Int, val count_pizza : Int, val pizza_id : Int, val user_id : Int) {
|
||||||
|
}
|
@ -7,9 +7,10 @@ import android.view.ViewGroup
|
|||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import com.example.pizza.Model.Order.Order
|
import com.example.pizza.Model.Order.Order
|
||||||
|
import com.example.pizza.Model.Order.PizzaOrder
|
||||||
import com.example.pizza.R
|
import com.example.pizza.R
|
||||||
|
|
||||||
class HistoryAdapter(var orders: List<Order>, var context: Context) : RecyclerView.Adapter<HistoryAdapter.MyViewHolder>() {
|
class HistoryAdapter(var orders: List<PizzaOrder>, var context: Context) : RecyclerView.Adapter<HistoryAdapter.MyViewHolder>() {
|
||||||
class MyViewHolder(view: View) : RecyclerView.ViewHolder(view){
|
class MyViewHolder(view: View) : RecyclerView.ViewHolder(view){
|
||||||
val date: TextView = view.findViewById(R.id.date_order)
|
val date: TextView = view.findViewById(R.id.date_order)
|
||||||
val pizzas: TextView = view.findViewById(R.id.pizza_order)
|
val pizzas: TextView = view.findViewById(R.id.pizza_order)
|
||||||
@ -28,7 +29,7 @@ class HistoryAdapter(var orders: List<Order>, var context: Context) : RecyclerVi
|
|||||||
|
|
||||||
override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
|
override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
|
||||||
holder.date.text = orders[position].date
|
holder.date.text = orders[position].date
|
||||||
holder.pizzas.text = orders[position].getPizzas()
|
holder.pizzas.text = orders[position].pizzas
|
||||||
holder.price.text = orders[position].price.toString()
|
holder.price.text = orders[position].price.toString()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,20 +1,59 @@
|
|||||||
package com.example.pizza.Model.Order
|
package com.example.pizza.Model.Order
|
||||||
|
|
||||||
|
import androidx.room.ColumnInfo
|
||||||
|
import androidx.room.Entity
|
||||||
|
import androidx.room.ForeignKey
|
||||||
|
import androidx.room.Ignore
|
||||||
|
import androidx.room.PrimaryKey
|
||||||
import com.example.pizza.Model.Pizza.Pizza
|
import com.example.pizza.Model.Pizza.Pizza
|
||||||
|
import com.example.pizza.Model.User.User
|
||||||
|
import java.util.Date
|
||||||
|
|
||||||
class Order(val date:String, val pizzas: Map<String, Int> , val price : Int ) {
|
@Entity(tableName = "orders", foreignKeys =
|
||||||
fun getOrders() : List<Order>{
|
[
|
||||||
return listOf(
|
ForeignKey(
|
||||||
Order("01.01.2023", mapOf("карбонара" to 5, "гриль" to 3,"гриль2" to 3,"гриль3" to 3), 100),
|
entity = Pizza::class,
|
||||||
Order("02.01.2023", mapOf("карбонара" to 5), 100)
|
parentColumns = ["uid"],
|
||||||
)
|
childColumns = ["pizza_id"],
|
||||||
|
onDelete = ForeignKey.RESTRICT,
|
||||||
|
onUpdate = ForeignKey.RESTRICT),
|
||||||
|
ForeignKey(
|
||||||
|
entity = User::class,
|
||||||
|
parentColumns = ["uid"],
|
||||||
|
childColumns = ["user_id"],
|
||||||
|
onDelete = ForeignKey.RESTRICT,
|
||||||
|
onUpdate = ForeignKey.RESTRICT),
|
||||||
|
])
|
||||||
|
class Order(
|
||||||
|
@PrimaryKey(autoGenerate = true)
|
||||||
|
val uid : Int?,
|
||||||
|
@ColumnInfo(name = "date")
|
||||||
|
val date: String,
|
||||||
|
@ColumnInfo(name = "pizza_id", index = true)
|
||||||
|
val pizza: Int? ,
|
||||||
|
@ColumnInfo(name = "user_id", index = true)
|
||||||
|
val user: Int? ,
|
||||||
|
val price : Int ) {
|
||||||
|
@Ignore
|
||||||
|
constructor(
|
||||||
|
Date : Date,
|
||||||
|
Pizza : Pizza,
|
||||||
|
User : User,
|
||||||
|
Price : Int
|
||||||
|
) : this(null , Date.toString(), Pizza.uid, User.uid, Price)
|
||||||
|
override fun equals(other: Any?): Boolean {
|
||||||
|
if (this === other) return true
|
||||||
|
if (javaClass != other?.javaClass) return false
|
||||||
|
other as Order
|
||||||
|
if (uid != other.uid) return false
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
fun getPizzas() : String {
|
|
||||||
var res = ""
|
override fun hashCode(): Int {
|
||||||
for(pizza in pizzas){
|
return uid ?: -1
|
||||||
res += (pizza.key.toString() + " " + pizza.value.toString() + "x" + '\n')
|
}
|
||||||
}
|
|
||||||
return res
|
override fun toString(): String {
|
||||||
|
return "date: "+ date.toString() + " pizza: " + pizza.toString() + " user: " + user.toString() + " price: " + price
|
||||||
}
|
}
|
||||||
}
|
}
|
30
app/src/main/java/com/example/pizza/Model/Order/OrderDao.kt
Normal file
30
app/src/main/java/com/example/pizza/Model/Order/OrderDao.kt
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
package com.example.pizza.Model.Order
|
||||||
|
|
||||||
|
import androidx.room.Dao
|
||||||
|
import androidx.room.Delete
|
||||||
|
import androidx.room.Insert
|
||||||
|
import androidx.room.Query
|
||||||
|
import androidx.room.Update
|
||||||
|
import com.example.pizza.Model.Basket.Basket
|
||||||
|
import io.reactivex.rxjava3.core.Completable
|
||||||
|
import io.reactivex.rxjava3.core.Flowable
|
||||||
|
|
||||||
|
@Dao
|
||||||
|
interface OrderDao {
|
||||||
|
@Query("select orders.date as date, group_concat(pizzas.pizza_title) as pizzas, Sum(orders.price) as price from orders" +
|
||||||
|
" join pizzas on orders.pizza_id = pizzas.uid where orders.user_id = :uid group by orders.date ")
|
||||||
|
fun getUserHistory(uid: Int): Flowable<List<PizzaOrder>>
|
||||||
|
|
||||||
|
@Query("select * from orders")
|
||||||
|
fun getAll(): Flowable<List<Order>>
|
||||||
|
@Insert
|
||||||
|
fun insert(group: Order): Completable
|
||||||
|
|
||||||
|
@Insert
|
||||||
|
fun insertMany(group: List<Order>): Completable
|
||||||
|
@Update
|
||||||
|
fun update(group: Order): Completable
|
||||||
|
|
||||||
|
@Delete
|
||||||
|
fun delete(group: Order): Completable
|
||||||
|
}
|
@ -0,0 +1,4 @@
|
|||||||
|
package com.example.pizza.Model.Order
|
||||||
|
|
||||||
|
class PizzaOrder(val date: String, val pizzas : String, val price : Int) {
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
package com.example.pizza.Model
|
package com.example.pizza.Model
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
@ -7,19 +8,26 @@ import android.view.ViewGroup
|
|||||||
import android.widget.Button
|
import android.widget.Button
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import com.example.pizza.Model.Basket.Basket
|
||||||
|
import com.example.pizza.Model.Basket.BasketDao
|
||||||
|
import com.example.pizza.Model.Basket.PizzaBasket
|
||||||
import com.example.pizza.Model.Order.Order
|
import com.example.pizza.Model.Order.Order
|
||||||
import com.example.pizza.Model.Pizza.Pizza
|
import com.example.pizza.Model.Pizza.Pizza
|
||||||
import com.example.pizza.R
|
import com.example.pizza.R
|
||||||
|
import com.example.pizza.database.AppDatabase
|
||||||
|
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
|
||||||
|
import io.reactivex.rxjava3.schedulers.Schedulers
|
||||||
import kotlinx.coroutines.flow.combineTransform
|
import kotlinx.coroutines.flow.combineTransform
|
||||||
import java.util.function.ToIntFunction
|
import java.util.function.ToIntFunction
|
||||||
|
|
||||||
class OrderAdapter(var orders: List<Pizza>, var context: Context, val resSum: TextView ) : RecyclerView.Adapter<OrderAdapter.MyViewHolder>() {
|
class OrderAdapter(var orders: List<PizzaBasket>, var context: Context, val resSum: TextView ) : RecyclerView.Adapter<OrderAdapter.MyViewHolder>() {
|
||||||
class MyViewHolder(view: View) : RecyclerView.ViewHolder(view) {
|
class MyViewHolder(view: View) : RecyclerView.ViewHolder(view) {
|
||||||
val title: TextView = view.findViewById(R.id.order_title)
|
val title: TextView = view.findViewById(R.id.order_title)
|
||||||
val btnP: TextView = view.findViewById(R.id.plus)
|
val btnP: TextView = view.findViewById(R.id.plus)
|
||||||
val btnM: TextView = view.findViewById(R.id.minus)
|
val btnM: TextView = view.findViewById(R.id.minus)
|
||||||
val count: TextView = view.findViewById(R.id.order_count)
|
val count: TextView = view.findViewById(R.id.order_count)
|
||||||
val sum: TextView = view.findViewById(R.id.order_sum)
|
val sum: TextView = view.findViewById(R.id.order_sum)
|
||||||
|
val btnTrash : Button = view.findViewById(R.id.button_trash)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
|
||||||
@ -34,17 +42,19 @@ class OrderAdapter(var orders: List<Pizza>, var context: Context, val resSum: Te
|
|||||||
override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
|
override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
|
||||||
holder.btnM.setOnClickListener{btnMinus(holder,position)}
|
holder.btnM.setOnClickListener{btnMinus(holder,position)}
|
||||||
holder.btnP.setOnClickListener{btnPlus(holder,position)}
|
holder.btnP.setOnClickListener{btnPlus(holder,position)}
|
||||||
holder.title.text = orders[position].title
|
holder.title.text = orders[position].pizza_title
|
||||||
holder.count.text = "0"
|
holder.count.text = orders[position].count_pizza.toString()
|
||||||
holder.sum.text = "0"
|
holder.sum.text = orders[position].pizza_price.toString()
|
||||||
|
resSum.text = (resSum.text.toString().toInt() + orders[position].pizza_price).toString()
|
||||||
|
holder.btnTrash.setOnClickListener{deleteFromBasket(holder,position)}
|
||||||
|
|
||||||
}
|
}
|
||||||
fun btnPlus(holder:MyViewHolder,position: Int){
|
fun btnPlus(holder:MyViewHolder,position: Int){
|
||||||
var count = holder.count.text.toString().toInt()
|
var count = holder.count.text.toString().toInt()
|
||||||
count++
|
count++
|
||||||
holder.count.text = count.toString()
|
holder.count.text = count.toString()
|
||||||
holder.sum.text = (count * orders[position].price).toString()
|
holder.sum.text = (count * orders[position].pizza_price).toString()
|
||||||
resSum.text = (resSum.text.toString().toInt() + orders[position].price).toString()
|
resSum.text = (resSum.text.toString().toInt() + orders[position].pizza_price).toString()
|
||||||
|
|
||||||
}
|
}
|
||||||
fun btnMinus(holder:MyViewHolder,position: Int){
|
fun btnMinus(holder:MyViewHolder,position: Int){
|
||||||
@ -53,7 +63,17 @@ class OrderAdapter(var orders: List<Pizza>, var context: Context, val resSum: Te
|
|||||||
return
|
return
|
||||||
count--
|
count--
|
||||||
holder.count.text = count.toString()
|
holder.count.text = count.toString()
|
||||||
holder.sum.text = (count * orders[position].price).toString()
|
holder.sum.text = (count * orders[position].pizza_price).toString()
|
||||||
resSum.text = (resSum.text.toString().toInt() - orders[position].price).toString()
|
resSum.text = (resSum.text.toString().toInt() - orders[position].pizza_price).toString()
|
||||||
|
}
|
||||||
|
@SuppressLint("CheckResult")
|
||||||
|
fun deleteFromBasket(holder: OrderAdapter.MyViewHolder, position: Int){
|
||||||
|
val basketDao : BasketDao? = context?.let { AppDatabase.getInstance(it).basketDao() }
|
||||||
|
basketDao?.deleteByUserAndPizza(orders[position].user_id,orders[position].pizza_id)?.subscribeOn(Schedulers.io())
|
||||||
|
?.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
?.doOnComplete({})
|
||||||
|
?.doOnError({})
|
||||||
|
?.onErrorComplete()
|
||||||
|
?.subscribe({resSum.text = "0"} )
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
package com.example.pizza.Model.Pizza
|
||||||
|
|
||||||
|
import android.graphics.Bitmap
|
||||||
|
import android.graphics.BitmapFactory
|
||||||
|
import androidx.room.TypeConverter
|
||||||
|
import java.io.ByteArrayInputStream
|
||||||
|
import java.io.ByteArrayOutputStream
|
||||||
|
import java.nio.ByteBuffer
|
||||||
|
|
||||||
|
|
||||||
|
class ImageConverter {
|
||||||
|
@TypeConverter
|
||||||
|
fun getByteArrayFromBitmap(bitmap: Bitmap): ByteArray {
|
||||||
|
val outputStream = ByteArrayOutputStream()
|
||||||
|
bitmap.compress(Bitmap.CompressFormat.PNG, 70, outputStream)
|
||||||
|
return outputStream.toByteArray()
|
||||||
|
}
|
||||||
|
@TypeConverter
|
||||||
|
fun getBitmapFromByteArray(byteArray: ByteArray): Bitmap{
|
||||||
|
return BitmapFactory.decodeByteArray(byteArray, 0, byteArray.size)
|
||||||
|
// val imageStream = ByteArrayInputStream(byteArray)
|
||||||
|
// val bmp = BitmapFactory.decodeStream(imageStream)
|
||||||
|
// return bmp
|
||||||
|
}
|
||||||
|
}
|
@ -1,18 +1,43 @@
|
|||||||
package com.example.pizza.Model.Pizza
|
package com.example.pizza.Model.Pizza
|
||||||
|
|
||||||
|
import android.graphics.Bitmap
|
||||||
|
import androidx.room.ColumnInfo
|
||||||
|
import androidx.room.Entity
|
||||||
|
import androidx.room.Ignore
|
||||||
|
import androidx.room.PrimaryKey
|
||||||
|
import androidx.room.TypeConverters
|
||||||
|
import com.example.pizza.Model.User.User
|
||||||
import java.io.Serializable
|
import java.io.Serializable
|
||||||
|
@Entity(tableName = "pizzas")
|
||||||
class Pizza(
|
class Pizza(
|
||||||
|
@PrimaryKey(autoGenerate = true)
|
||||||
|
val uid: Int?,
|
||||||
|
@ColumnInfo(name = "pizza_title")
|
||||||
val title:String,
|
val title:String,
|
||||||
val image : String,
|
|
||||||
val ingredients: List<String>,
|
val image : Bitmap?,
|
||||||
|
@ColumnInfo(name = "pizza_ingredients")
|
||||||
|
val ingredients: String,
|
||||||
|
@ColumnInfo(name = "pizza_price")
|
||||||
val price: Int
|
val price: Int
|
||||||
): Serializable {
|
){
|
||||||
fun getTestPizza(): List<Pizza>{
|
@Ignore
|
||||||
return listOf(
|
constructor(
|
||||||
Pizza("карбонара","pizza", listOf("сыр", "колбаса"), 100),
|
Title : String,
|
||||||
Pizza("гриль", "pizza",listOf("сыр", "курица"), 200),
|
Image : Bitmap,
|
||||||
Pizza("сырная", "pizza",listOf("сыр", "еще сыр"), 300)
|
Ingredients : String,
|
||||||
)
|
Price : Int
|
||||||
|
) : this(null, Title, Image, Ingredients, Price)
|
||||||
|
override fun equals(other: Any?): Boolean {
|
||||||
|
if (this === other) return true
|
||||||
|
if (javaClass != other?.javaClass) return false
|
||||||
|
other as Pizza
|
||||||
|
if (uid != other.uid) return false
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun hashCode(): Int {
|
||||||
|
return uid ?: -1
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
26
app/src/main/java/com/example/pizza/Model/Pizza/PizzaDao.kt
Normal file
26
app/src/main/java/com/example/pizza/Model/Pizza/PizzaDao.kt
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
package com.example.pizza.Model.Pizza
|
||||||
|
|
||||||
|
import androidx.room.Dao
|
||||||
|
import androidx.room.Delete
|
||||||
|
import androidx.room.Insert
|
||||||
|
import androidx.room.OnConflictStrategy
|
||||||
|
import androidx.room.Query
|
||||||
|
import androidx.room.Update
|
||||||
|
import com.example.pizza.Model.Basket.Basket
|
||||||
|
import io.reactivex.rxjava3.core.Completable
|
||||||
|
import io.reactivex.rxjava3.core.Flowable
|
||||||
|
import io.reactivex.rxjava3.core.Single
|
||||||
|
|
||||||
|
@Dao
|
||||||
|
interface PizzaDao {
|
||||||
|
@Query("select * from pizzas")
|
||||||
|
fun getAll(): Flowable<List<Pizza>>
|
||||||
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
|
fun insert(group: Pizza): Completable
|
||||||
|
|
||||||
|
@Update
|
||||||
|
fun update(group: Pizza): Completable
|
||||||
|
|
||||||
|
@Delete
|
||||||
|
fun delete(group: Pizza): Completable
|
||||||
|
}
|
11
app/src/main/java/com/example/pizza/Model/Pizza/Singleton.kt
Normal file
11
app/src/main/java/com/example/pizza/Model/Pizza/Singleton.kt
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
package com.example.pizza.Model.Pizza
|
||||||
|
|
||||||
|
import android.graphics.Bitmap
|
||||||
|
|
||||||
|
object Singleton{
|
||||||
|
|
||||||
|
init {
|
||||||
|
}
|
||||||
|
var btm : Bitmap? = null
|
||||||
|
|
||||||
|
}
|
@ -2,6 +2,7 @@ package com.example.pizza.Model
|
|||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import android.graphics.BitmapFactory
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
@ -10,10 +11,19 @@ import android.widget.ImageView
|
|||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import com.example.pizza.Model.Basket.Basket
|
||||||
|
import com.example.pizza.Model.Basket.BasketDao
|
||||||
import com.example.pizza.Model.Pizza.Pizza
|
import com.example.pizza.Model.Pizza.Pizza
|
||||||
|
import com.example.pizza.Model.Pizza.PizzaDao
|
||||||
|
import com.example.pizza.Model.User.User
|
||||||
import com.example.pizza.R
|
import com.example.pizza.R
|
||||||
|
import com.example.pizza.database.AppDatabase
|
||||||
|
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
|
||||||
|
import io.reactivex.rxjava3.core.Single
|
||||||
|
import io.reactivex.rxjava3.schedulers.Schedulers
|
||||||
|
|
||||||
class PizzaAdapter(var pizzas: List<Pizza>, var context: Context) : RecyclerView.Adapter<PizzaAdapter.MyViewHolder>() {
|
class PizzaAdapter(var pizzas: List<Pizza>, var context: Context, var user : Int) : RecyclerView.Adapter<PizzaAdapter.MyViewHolder>() {
|
||||||
|
val basketDao : BasketDao? = context?.let { AppDatabase.getInstance(it).basketDao() }
|
||||||
class MyViewHolder(view: View) : RecyclerView.ViewHolder(view){
|
class MyViewHolder(view: View) : RecyclerView.ViewHolder(view){
|
||||||
val image: ImageView = view.findViewById(R.id.pizza_list_image)
|
val image: ImageView = view.findViewById(R.id.pizza_list_image)
|
||||||
val title: TextView = view.findViewById(R.id.pizza_list_title)
|
val title: TextView = view.findViewById(R.id.pizza_list_title)
|
||||||
@ -36,14 +46,16 @@ class PizzaAdapter(var pizzas: List<Pizza>, var context: Context) : RecyclerView
|
|||||||
holder.title.text = pizzas[position].title
|
holder.title.text = pizzas[position].title
|
||||||
holder.ingredients.text = pizzas[position].ingredients.toString()
|
holder.ingredients.text = pizzas[position].ingredients.toString()
|
||||||
holder.price.text = pizzas[position].price.toString()
|
holder.price.text = pizzas[position].price.toString()
|
||||||
|
holder.image.setImageBitmap(pizzas[position].image)
|
||||||
|
holder.btn.setOnClickListener { addToBasket(holder, position) }
|
||||||
val imageId = context.resources.getIdentifier(
|
|
||||||
pizzas[position].image,
|
|
||||||
"drawable",
|
|
||||||
context.packageName
|
|
||||||
)
|
|
||||||
holder.image.setImageResource(imageId)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
fun addToBasket(holder: PizzaAdapter.MyViewHolder, position: Int){
|
||||||
|
val pizza : Basket = Basket(user,pizzas[position].uid!!,1)
|
||||||
|
basketDao?.insert(pizza)?.subscribeOn(Schedulers.io())
|
||||||
|
?.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
?.doOnComplete({})
|
||||||
|
?.doOnError({})
|
||||||
|
?.onErrorComplete()
|
||||||
|
?.subscribe()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,4 +1,40 @@
|
|||||||
package com.example.pizza.Model.User
|
package com.example.pizza.Model.User
|
||||||
|
|
||||||
class User(val login:String , val email : String , val pass: String , val role : String ) {
|
import androidx.room.ColumnInfo
|
||||||
|
import androidx.room.Entity
|
||||||
|
import androidx.room.Ignore
|
||||||
|
import androidx.room.Index
|
||||||
|
import androidx.room.PrimaryKey
|
||||||
|
import java.util.logging.StreamHandler
|
||||||
|
|
||||||
|
@Entity(tableName = "users", indices = [(Index(value = ["login"], unique = true))])
|
||||||
|
data class User(
|
||||||
|
@PrimaryKey(autoGenerate = true)
|
||||||
|
public val uid: Int?,
|
||||||
|
@ColumnInfo(name = "login")
|
||||||
|
val login:String ,
|
||||||
|
@ColumnInfo(name = "email")
|
||||||
|
val email : String ,
|
||||||
|
@ColumnInfo(name = "password")
|
||||||
|
val password: String ,
|
||||||
|
@ColumnInfo(name = "role")
|
||||||
|
val role : String ) {
|
||||||
|
@Ignore
|
||||||
|
constructor(
|
||||||
|
Login : String,
|
||||||
|
Email : String,
|
||||||
|
Pass : String,
|
||||||
|
Role : String
|
||||||
|
) : this(null , Login, Email, Pass, Role)
|
||||||
|
override fun equals(other: Any?): Boolean {
|
||||||
|
if (this === other) return true
|
||||||
|
if (javaClass != other?.javaClass) return false
|
||||||
|
other as User
|
||||||
|
if (uid != other.uid) return false
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun hashCode(): Int {
|
||||||
|
return uid ?: -1
|
||||||
|
}
|
||||||
}
|
}
|
31
app/src/main/java/com/example/pizza/Model/User/UserDao.kt
Normal file
31
app/src/main/java/com/example/pizza/Model/User/UserDao.kt
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
package com.example.pizza.Model.User
|
||||||
|
|
||||||
|
import androidx.room.Dao
|
||||||
|
import androidx.room.Delete
|
||||||
|
import androidx.room.Insert
|
||||||
|
import androidx.room.Query
|
||||||
|
import androidx.room.Update
|
||||||
|
import io.reactivex.rxjava3.core.Completable
|
||||||
|
import io.reactivex.rxjava3.core.Flowable
|
||||||
|
import io.reactivex.rxjava3.core.Single
|
||||||
|
|
||||||
|
@Dao
|
||||||
|
interface UserDao {
|
||||||
|
@Query("select * from users where users.uid = :uid ")
|
||||||
|
fun getById(uid : Int): Single<User>
|
||||||
|
|
||||||
|
@Query("select * from users")
|
||||||
|
fun getAll(): Flowable<List<User>>
|
||||||
|
|
||||||
|
@Query("SELECT * FROM users WHERE login = :login AND password = :pass")
|
||||||
|
fun getByLoginAndPassword(login : String, pass : String): Single<User>
|
||||||
|
|
||||||
|
@Insert
|
||||||
|
fun insert(group: User): Completable
|
||||||
|
|
||||||
|
@Update
|
||||||
|
fun update(group: User): Completable
|
||||||
|
|
||||||
|
@Delete
|
||||||
|
fun delete(group: User): Completable
|
||||||
|
}
|
@ -1,32 +1,77 @@
|
|||||||
package com.example.pizza
|
package com.example.pizza
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.util.Log
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
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.widget.Button
|
import android.widget.Button
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
|
import android.widget.Toast
|
||||||
|
import androidx.constraintlayout.widget.StateSet.TAG
|
||||||
|
import androidx.fragment.app.activityViewModels
|
||||||
import androidx.navigation.Navigation
|
import androidx.navigation.Navigation
|
||||||
|
import com.example.pizza.Model.PizzaAdapter
|
||||||
|
import com.example.pizza.Model.User.User
|
||||||
|
import com.example.pizza.Model.User.UserDao
|
||||||
|
import com.example.pizza.database.AppDatabase
|
||||||
|
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
|
||||||
|
import io.reactivex.rxjava3.core.Completable
|
||||||
|
import io.reactivex.rxjava3.schedulers.Schedulers
|
||||||
|
|
||||||
|
|
||||||
class Reg : Fragment() {
|
class Reg : Fragment() {
|
||||||
|
private var userDao: UserDao? = null
|
||||||
|
@SuppressLint("CheckResult")
|
||||||
override fun onCreateView(
|
override fun onCreateView(
|
||||||
inflater: LayoutInflater, container: ViewGroup?,
|
inflater: LayoutInflater, container: ViewGroup?,
|
||||||
savedInstanceState: Bundle?
|
savedInstanceState: Bundle?
|
||||||
): View? {
|
): View? {
|
||||||
|
userDao = context?.let { AppDatabase.getInstance(it).userDao() }
|
||||||
val view = inflater.inflate(R.layout.fragment_reg, container, false)
|
val view = inflater.inflate(R.layout.fragment_reg, container, false)
|
||||||
view.findViewById<Button>(R.id.button_reg).setOnClickListener {buttonClick(view)}
|
view.findViewById<Button>(R.id.button_reg).setOnClickListener {buttonClick(view)}
|
||||||
view.findViewById<TextView>(R.id.link_to_auth).setOnClickListener{TextViewClick(view)}
|
view.findViewById<TextView>(R.id.link_to_auth).setOnClickListener{TextViewClick(view)}
|
||||||
|
|
||||||
return view
|
return view
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("CheckResult", "SuspiciousIndentation")
|
||||||
private fun buttonClick(view: View) {
|
private fun buttonClick(view: View) {
|
||||||
val action = RegDirections
|
val login = view.findViewById<TextView>(R.id.reg_user_login)?.text.toString().trim()
|
||||||
.actionNavigationRegToNavigationPizzaList()
|
val email = view.findViewById<TextView>(R.id.reg_user_email)?.text.toString().trim()
|
||||||
Navigation.findNavController(view).navigate(action)
|
val pass = view.findViewById<TextView>(R.id.reg_user_pass)?.text.toString().trim()
|
||||||
|
val viewModel: myViewModel by activityViewModels()
|
||||||
|
if(login.length == 0 || pass.length ==0 || email.length == 0){
|
||||||
|
Toast.makeText(view.context, "Укажите данные", Toast.LENGTH_SHORT).show()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
val user1 = User(login, email,pass, "user")
|
||||||
|
userDao?.insert(user1)?.subscribeOn(Schedulers.io())
|
||||||
|
?.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
|
||||||
|
?.subscribe(
|
||||||
|
{Toast.makeText(view.context, "Регистрация прошла успешно", Toast.LENGTH_SHORT).show()
|
||||||
|
userDao?.getByLoginAndPassword(login, pass)?.subscribeOn(Schedulers.io())
|
||||||
|
?.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
?.doOnSuccess({})
|
||||||
|
?.onErrorComplete()
|
||||||
|
?.subscribe { user ->
|
||||||
|
viewModel.setId(user.uid!!)
|
||||||
|
if (user.role.equals("admin"))
|
||||||
|
viewModel.setRole(true)
|
||||||
|
val action = RegDirections
|
||||||
|
.actionNavigationRegToNavigationPizzaList()
|
||||||
|
Navigation.findNavController(view).navigate(action)
|
||||||
|
}},
|
||||||
|
{Toast.makeText(view.context, "Данный логин уже занят", Toast.LENGTH_SHORT).show()}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
private fun TextViewClick(view: View) {
|
private fun TextViewClick(view: View) {
|
||||||
val action = RegDirections
|
val action = RegDirections
|
||||||
|
@ -1,34 +1,98 @@
|
|||||||
package com.example.pizza
|
package com.example.pizza
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
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.widget.Button
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
|
import android.widget.Toast
|
||||||
|
import androidx.fragment.app.activityViewModels
|
||||||
|
import androidx.fragment.app.viewModels
|
||||||
|
import androidx.navigation.Navigation
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import androidx.recyclerview.widget.RecyclerView.ViewHolder
|
||||||
|
import com.example.pizza.Model.Basket.BasketDao
|
||||||
|
import com.example.pizza.Model.Basket.PizzaBasket
|
||||||
|
import com.example.pizza.Model.HistoryAdapter
|
||||||
|
import com.example.pizza.Model.Order.Order
|
||||||
|
import com.example.pizza.Model.Order.OrderDao
|
||||||
import com.example.pizza.Model.OrderAdapter
|
import com.example.pizza.Model.OrderAdapter
|
||||||
import com.example.pizza.Model.Pizza.Pizza
|
import com.example.pizza.Model.Pizza.Pizza
|
||||||
import com.example.pizza.Model.PizzaAdapter
|
import com.example.pizza.Model.PizzaAdapter
|
||||||
|
import com.example.pizza.database.AppDatabase
|
||||||
|
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
|
||||||
|
import io.reactivex.rxjava3.schedulers.Schedulers
|
||||||
|
import java.text.SimpleDateFormat
|
||||||
|
import java.util.Date
|
||||||
|
|
||||||
|
|
||||||
class crate : Fragment() {
|
class crate : Fragment() {
|
||||||
|
private var basketDao: BasketDao? = null
|
||||||
|
lateinit var itemsList : RecyclerView
|
||||||
|
lateinit var listPizzas : List<PizzaBasket>
|
||||||
|
val viewModel: myViewModel by activityViewModels()
|
||||||
|
private var orderDao : OrderDao? = null
|
||||||
|
@SuppressLint("CheckResult")
|
||||||
override fun onCreateView(
|
override fun onCreateView(
|
||||||
inflater: LayoutInflater, container: ViewGroup?,
|
inflater: LayoutInflater, container: ViewGroup?,
|
||||||
savedInstanceState: Bundle?
|
savedInstanceState: Bundle?
|
||||||
): View? {
|
): View? {
|
||||||
|
|
||||||
|
basketDao = context?.let { AppDatabase.getInstance(it).basketDao() }
|
||||||
|
orderDao = context?.let { AppDatabase.getInstance(it).orderDao() }
|
||||||
val view = inflater.inflate(R.layout.fragment_crate, container, false)
|
val view = inflater.inflate(R.layout.fragment_crate, container, false)
|
||||||
val itemsList : RecyclerView = view.findViewById(R.id.inOrderList)
|
itemsList = view.findViewById(R.id.inOrderList)
|
||||||
//TODO("Загрузка из БД!!")
|
|
||||||
var p = Pizza("1","1", listOf("1"),1)
|
|
||||||
var items = p.getTestPizza()
|
|
||||||
itemsList.layoutManager = LinearLayoutManager(view.context)
|
|
||||||
var resSum = view.findViewById<TextView>(R.id.sum_pizzas)
|
var resSum = view.findViewById<TextView>(R.id.sum_pizzas)
|
||||||
itemsList.adapter = OrderAdapter(items,view.context, resSum)
|
val button : Button = view.findViewById<Button>(R.id.button_buy)
|
||||||
|
basketDao?.getUserBasket(viewModel.getId()!!)?.subscribeOn(Schedulers.io())
|
||||||
|
?.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
?.subscribe { pizzas ->
|
||||||
|
listPizzas = pizzas
|
||||||
|
itemsList.layoutManager = LinearLayoutManager(view.context)
|
||||||
|
itemsList.adapter = OrderAdapter(pizzas,view.context, resSum)
|
||||||
|
}
|
||||||
|
button.setOnClickListener{buttonClick(view)}
|
||||||
|
|
||||||
|
|
||||||
return view
|
return view
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("CheckResult")
|
||||||
|
private fun buttonClick(view : View){
|
||||||
|
var list = arrayListOf<Order>()
|
||||||
|
val sdf = SimpleDateFormat("dd.M.yyyy")
|
||||||
|
val currentDate = sdf.format(Date())
|
||||||
|
val x = itemsList.childCount
|
||||||
|
if(x == 0){
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for(i in 0..<x){
|
||||||
|
var child = itemsList.getChildAt(i)
|
||||||
|
var price = child.findViewById<TextView>(R.id.order_sum).text.toString().toInt()
|
||||||
|
list.add(Order(null, currentDate, listPizzas[i].pizza_id,
|
||||||
|
viewModel.getId(), price))
|
||||||
|
}
|
||||||
|
basketDao?.deleteByUser(viewModel.getId()!!)?.subscribeOn(Schedulers.io())
|
||||||
|
?.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
?.doOnError({ Toast.makeText(view.context, "Error", Toast.LENGTH_SHORT).show()})
|
||||||
|
?.doOnComplete({})
|
||||||
|
?.onErrorComplete()
|
||||||
|
?.subscribe {}
|
||||||
|
orderDao?.insertMany(list)?.subscribeOn(Schedulers.io())
|
||||||
|
?.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
?.doOnComplete({})
|
||||||
|
?.doOnError({ Toast.makeText(view.context, "Error", Toast.LENGTH_SHORT).show()})
|
||||||
|
?.onErrorComplete()
|
||||||
|
?.subscribe {
|
||||||
|
Toast.makeText(view.context, "Заказ прошел успешно ", Toast.LENGTH_SHORT).show()
|
||||||
|
val action = crateDirections
|
||||||
|
.actionNavigationCretePizzaToListNavigation()
|
||||||
|
Navigation.findNavController(view).navigate(action)
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,28 +1,43 @@
|
|||||||
package com.example.pizza
|
package com.example.pizza
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import android.graphics.Bitmap
|
||||||
|
import android.graphics.drawable.BitmapDrawable
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.provider.MediaStore
|
import android.provider.MediaStore
|
||||||
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.widget.Button
|
||||||
|
import android.widget.EditText
|
||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
|
import android.widget.Toast
|
||||||
import androidx.activity.result.contract.ActivityResultContracts
|
import androidx.activity.result.contract.ActivityResultContracts
|
||||||
import androidx.appcompat.widget.AppCompatImageView
|
import androidx.appcompat.widget.AppCompatImageView
|
||||||
import androidx.core.view.drawToBitmap
|
import androidx.core.graphics.drawable.toBitmap
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import com.google.android.material.floatingactionbutton.FloatingActionButton
|
import androidx.navigation.Navigation
|
||||||
|
import com.example.pizza.Model.Pizza.Pizza
|
||||||
|
import com.example.pizza.Model.Pizza.PizzaDao
|
||||||
|
import com.example.pizza.Model.User.UserDao
|
||||||
|
import com.example.pizza.database.AppDatabase
|
||||||
|
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
|
||||||
|
import io.reactivex.rxjava3.schedulers.Schedulers
|
||||||
|
|
||||||
|
|
||||||
private lateinit var selectedImage: AppCompatImageView
|
private lateinit var selectedImage: AppCompatImageView
|
||||||
class create_pizza : Fragment() {
|
class create_pizza : Fragment() {
|
||||||
|
private var pizzaDao: PizzaDao? = null
|
||||||
override fun onCreateView(
|
override fun onCreateView(
|
||||||
inflater: LayoutInflater, container: ViewGroup?,
|
inflater: LayoutInflater, container: ViewGroup?,
|
||||||
savedInstanceState: Bundle?
|
savedInstanceState: Bundle?
|
||||||
): View? {
|
): View? {
|
||||||
|
pizzaDao = context?.let { AppDatabase.getInstance(it).pizzaDao() }
|
||||||
val view = inflater.inflate(R.layout.fragment_create_pizza, container, false)
|
val view = inflater.inflate(R.layout.fragment_create_pizza, container, false)
|
||||||
|
val button = view.findViewById<Button>(R.id.button_save)
|
||||||
|
button.setOnClickListener {buttonClick(view)}
|
||||||
selectedImage = view.findViewById<AppCompatImageView>(R.id.pizza_image)
|
selectedImage = view.findViewById<AppCompatImageView>(R.id.pizza_image)
|
||||||
selectedImage.setOnClickListener{
|
selectedImage.setOnClickListener{
|
||||||
val pickImg = Intent(Intent.ACTION_PICK, MediaStore.Images.Media.INTERNAL_CONTENT_URI)
|
val pickImg = Intent(Intent.ACTION_PICK, MediaStore.Images.Media.INTERNAL_CONTENT_URI)
|
||||||
@ -31,7 +46,32 @@ class create_pizza : Fragment() {
|
|||||||
//TODO добавление в бд
|
//TODO добавление в бд
|
||||||
return view
|
return view
|
||||||
}
|
}
|
||||||
|
@SuppressLint("CheckResult")
|
||||||
|
private fun buttonClick(view: View){
|
||||||
|
val title : String = view.findViewById<EditText>(R.id.pizza_title).text.toString()
|
||||||
|
val ingredients : String = view.findViewById<EditText>(R.id.pizza_ingredients).text.toString()
|
||||||
|
val price : Int = view.findViewById<EditText>(R.id.pizza_price).text.toString().toInt()
|
||||||
|
val image = view.findViewById<ImageView>(R.id.pizza_image)
|
||||||
|
val bitmap = (image.drawable as BitmapDrawable).toBitmap(200,200, Bitmap.Config.ARGB_8888)
|
||||||
|
var pizza1 : Pizza = Pizza(title,bitmap, ingredients,price)
|
||||||
|
if(title.length == 0 || ingredients.length == 0 || price == 0){
|
||||||
|
Toast.makeText(view.context, "Укажите данные", Toast.LENGTH_SHORT).show()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
pizzaDao?.insert(pizza1)?.subscribeOn(Schedulers.io())
|
||||||
|
?.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
?.doOnComplete({})
|
||||||
|
?.doOnError({ Toast.makeText(view.context, "Error", Toast.LENGTH_SHORT).show()})
|
||||||
|
?.onErrorComplete()
|
||||||
|
?.subscribe {
|
||||||
|
Toast.makeText(view.context, "Пицца успешно добавлена", Toast.LENGTH_SHORT).show()
|
||||||
|
val action = create_pizzaDirections
|
||||||
|
.actionNavigationCreatePizzaToListNavigation()
|
||||||
|
Navigation.findNavController(view).navigate(action)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
private val changeImage =
|
private val changeImage =
|
||||||
registerForActivityResult(
|
registerForActivityResult(
|
||||||
ActivityResultContracts.StartActivityForResult()
|
ActivityResultContracts.StartActivityForResult()
|
||||||
|
112
app/src/main/java/com/example/pizza/database/AppDatabase.kt
Normal file
112
app/src/main/java/com/example/pizza/database/AppDatabase.kt
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
package com.example.pizza.database
|
||||||
|
|
||||||
|
import android.R
|
||||||
|
import android.annotation.SuppressLint
|
||||||
|
import android.content.Context
|
||||||
|
import android.graphics.Bitmap
|
||||||
|
import android.graphics.BitmapFactory
|
||||||
|
import android.graphics.drawable.BitmapDrawable
|
||||||
|
import android.graphics.drawable.Drawable
|
||||||
|
import androidx.core.graphics.drawable.toBitmap
|
||||||
|
import androidx.core.graphics.drawable.toBitmapOrNull
|
||||||
|
import androidx.core.graphics.drawable.toDrawable
|
||||||
|
import androidx.room.Database
|
||||||
|
import androidx.room.Room
|
||||||
|
import androidx.room.RoomDatabase
|
||||||
|
import androidx.room.TypeConverters
|
||||||
|
import androidx.sqlite.db.SupportSQLiteDatabase
|
||||||
|
import com.example.pizza.Model.Basket.Basket
|
||||||
|
import com.example.pizza.Model.Basket.BasketDao
|
||||||
|
import com.example.pizza.Model.Order.Order
|
||||||
|
import com.example.pizza.Model.Order.OrderDao
|
||||||
|
import com.example.pizza.Model.Pizza.ImageConverter
|
||||||
|
import com.example.pizza.Model.Pizza.Pizza
|
||||||
|
import com.example.pizza.Model.Pizza.PizzaDao
|
||||||
|
import com.example.pizza.Model.Pizza.Singleton
|
||||||
|
import com.example.pizza.Model.User.User
|
||||||
|
import com.example.pizza.Model.User.UserDao
|
||||||
|
import java.io.ByteArrayOutputStream
|
||||||
|
import java.text.SimpleDateFormat
|
||||||
|
import java.util.Date
|
||||||
|
import java.util.concurrent.Executors
|
||||||
|
|
||||||
|
|
||||||
|
@Database(entities = [User::class, Pizza::class,Basket::class,Order::class], version = 1, exportSchema = false)
|
||||||
|
@TypeConverters(ImageConverter::class)
|
||||||
|
abstract class AppDatabase : RoomDatabase() {
|
||||||
|
abstract fun userDao(): UserDao
|
||||||
|
abstract fun pizzaDao(): PizzaDao
|
||||||
|
abstract fun basketDao(): BasketDao
|
||||||
|
abstract fun orderDao(): OrderDao
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private const val DB_NAME: String = "dp7"
|
||||||
|
|
||||||
|
@Volatile
|
||||||
|
private var INSTANCE: AppDatabase? = null
|
||||||
|
|
||||||
|
@SuppressLint("SimpleDateFormat")
|
||||||
|
private fun populateDatabase() {
|
||||||
|
INSTANCE?.let { database ->
|
||||||
|
//User
|
||||||
|
val userDao = database.userDao()
|
||||||
|
val user0 = User(1,"1", "1","1", "user")
|
||||||
|
val user1 = User(2,"vova", "vova@mail.ru","1234", "admin")
|
||||||
|
val user2 = User(3,"egor", "egor@mail.ru","1234", "admin")
|
||||||
|
userDao.insert(user0).subscribe().dispose()
|
||||||
|
userDao.insert(user1).subscribe().dispose()
|
||||||
|
userDao.insert(user2).subscribe().dispose()
|
||||||
|
//pizza
|
||||||
|
val pizzaDao = database.pizzaDao()
|
||||||
|
var f = Drawable.createFromPath("//drawable")
|
||||||
|
val st : Singleton = Singleton
|
||||||
|
var ff : Bitmap = st.btm!!
|
||||||
|
|
||||||
|
val pizza1 = Pizza(1,"пеперони", ff, "сыр, колбаса", 100)
|
||||||
|
val pizza2 = Pizza(2,"гриль", ff, "сыр, курица, соус", 200)
|
||||||
|
val pizza3 = Pizza(3,"черизо", ff, "сыр, перец, специи", 300)
|
||||||
|
pizzaDao.insert(pizza1).subscribe().dispose()
|
||||||
|
pizzaDao.insert(pizza2).subscribe().dispose()
|
||||||
|
pizzaDao.insert(pizza3).subscribe().dispose()
|
||||||
|
//basket
|
||||||
|
val basketDao = database.basketDao()
|
||||||
|
val basket1 = Basket( user1.uid!!,pizza1.uid!!, 1)
|
||||||
|
val basket2 = Basket( user1.uid!!,pizza2.uid!!, 1)
|
||||||
|
val basket3 = Basket( user2.uid!!,pizza1.uid!!, 1)
|
||||||
|
basketDao.insert(basket1).subscribe().dispose()
|
||||||
|
basketDao.insert(basket2).subscribe().dispose()
|
||||||
|
basketDao.insert(basket3).subscribe().dispose()
|
||||||
|
//order
|
||||||
|
val orderDao = database.orderDao()
|
||||||
|
|
||||||
|
val sdf = SimpleDateFormat("dd.M.yyyy")
|
||||||
|
val currentDate = sdf.format(Date())
|
||||||
|
|
||||||
|
val order1 = Order(1,currentDate.toString(),pizza1.uid,user1.uid,300)
|
||||||
|
val order2 = Order(2,currentDate.toString(),pizza2.uid,user1.uid,300)
|
||||||
|
val order3 = Order(3,currentDate.toString(),pizza1.uid,user2.uid,300)
|
||||||
|
orderDao.insert(order1).subscribe().dispose()
|
||||||
|
orderDao.insert(order2).subscribe().dispose()
|
||||||
|
orderDao.insert(order3).subscribe().dispose()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fun getInstance(appContext: Context): AppDatabase {
|
||||||
|
return INSTANCE ?: synchronized(this) {
|
||||||
|
Room.databaseBuilder(
|
||||||
|
appContext,
|
||||||
|
AppDatabase::class.java,
|
||||||
|
DB_NAME
|
||||||
|
)
|
||||||
|
.addCallback(object : Callback() {
|
||||||
|
override fun onCreate(db: SupportSQLiteDatabase) {
|
||||||
|
super.onCreate(db)
|
||||||
|
Executors.newSingleThreadExecutor().execute { populateDatabase() }
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.build()
|
||||||
|
.also { INSTANCE = it }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
20
app/src/main/java/com/example/pizza/myViewModel.kt
Normal file
20
app/src/main/java/com/example/pizza/myViewModel.kt
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
package com.example.pizza
|
||||||
|
|
||||||
|
import androidx.lifecycle.ViewModel
|
||||||
|
|
||||||
|
class myViewModel : ViewModel() {
|
||||||
|
private var id : Int? = null
|
||||||
|
private var admin : Boolean = false
|
||||||
|
public fun setId(Item : Int?){
|
||||||
|
id = Item
|
||||||
|
}
|
||||||
|
public fun getId() : Int?{
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
public fun setRole(Item : Boolean){
|
||||||
|
admin = Item
|
||||||
|
}
|
||||||
|
public fun getRole() : Boolean{
|
||||||
|
return admin
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
package com.example.pizza
|
package com.example.pizza
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
@ -7,34 +8,67 @@ import android.view.View
|
|||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.Button
|
import android.widget.Button
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
|
import androidx.fragment.app.activityViewModels
|
||||||
import androidx.navigation.Navigation
|
import androidx.navigation.Navigation
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import com.example.pizza.Model.Order.Order
|
import com.example.pizza.Model.Order.Order
|
||||||
import com.example.pizza.Model.HistoryAdapter
|
import com.example.pizza.Model.HistoryAdapter
|
||||||
|
import com.example.pizza.Model.Order.OrderDao
|
||||||
|
import com.example.pizza.Model.Order.PizzaOrder
|
||||||
|
import com.example.pizza.Model.OrderAdapter
|
||||||
|
import com.example.pizza.Model.Pizza.PizzaDao
|
||||||
|
import com.example.pizza.Model.PizzaAdapter
|
||||||
|
import com.example.pizza.Model.User.UserDao
|
||||||
|
import com.example.pizza.database.AppDatabase
|
||||||
|
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
|
||||||
|
import io.reactivex.rxjava3.schedulers.Schedulers
|
||||||
|
|
||||||
class user : Fragment() {
|
class user : Fragment() {
|
||||||
|
private var orderDao: OrderDao? = null
|
||||||
|
private var userDao: UserDao? = null
|
||||||
|
private val viewModel: myViewModel by activityViewModels()
|
||||||
|
@SuppressLint("CheckResult", "SetTextI18n")
|
||||||
override fun onCreateView(
|
override fun onCreateView(
|
||||||
inflater: LayoutInflater, container: ViewGroup?,
|
inflater: LayoutInflater, container: ViewGroup?,
|
||||||
savedInstanceState: Bundle?
|
savedInstanceState: Bundle?
|
||||||
|
|
||||||
): View? {
|
): View? {
|
||||||
|
|
||||||
|
userDao = context?.let { AppDatabase.getInstance(it).userDao() }
|
||||||
|
orderDao = context?.let { AppDatabase.getInstance(it).orderDao() }
|
||||||
|
|
||||||
val view = inflater.inflate(R.layout.fragment_user, container, false)
|
val view = inflater.inflate(R.layout.fragment_user, container, false)
|
||||||
val itemsList : RecyclerView = view.findViewById(R.id.historyList)
|
val itemsList : RecyclerView = view.findViewById(R.id.historyList)
|
||||||
view.findViewById<Button>(R.id.button_exit).setOnClickListener {buttonClick(view)}
|
|
||||||
view.findViewById<TextView>(R.id.user_login).text = view.findViewById<TextView>(R.id.user_login).text.toString() + "VOVA"
|
|
||||||
view.findViewById<TextView>(R.id.user_email).text = view.findViewById<TextView>(R.id.user_email).text.toString() + "VOVA@MAIL"
|
|
||||||
|
|
||||||
//TODO("Загрузка из БД!!")
|
userDao?.getById(viewModel.getId()!!)
|
||||||
var p = Order("1", mapOf<String,Int>("1" to 2), 1)
|
?.subscribeOn(Schedulers.io())
|
||||||
var items = p.getOrders()
|
?.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
?.doOnError { }
|
||||||
|
?.doOnSuccess { }
|
||||||
|
?.onErrorComplete()
|
||||||
|
?.subscribe { user ->
|
||||||
|
view.findViewById<TextView>(R.id.user_login).text = "Логин: "+ user.login
|
||||||
|
view.findViewById<TextView>(R.id.user_email).text = "Почта: " + user.email
|
||||||
|
}
|
||||||
|
orderDao?.getUserHistory(viewModel.getId()!!)?.subscribeOn(Schedulers.io())
|
||||||
|
?.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
?.subscribe { pizzas ->
|
||||||
|
itemsList.adapter = HistoryAdapter(pizzas,view.context)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
itemsList.layoutManager = LinearLayoutManager(view.context)
|
itemsList.layoutManager = LinearLayoutManager(view.context)
|
||||||
itemsList.adapter = HistoryAdapter(items,view.context)
|
view.findViewById<Button>(R.id.button_exit).setOnClickListener {buttonClick(view)}
|
||||||
|
|
||||||
|
|
||||||
return view
|
return view
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@SuppressLint("ResourceType")
|
||||||
private fun buttonClick(view: View) {
|
private fun buttonClick(view: View) {
|
||||||
|
viewModel.setRole(false)
|
||||||
|
viewModel.setId(null)
|
||||||
val action = userDirections
|
val action = userDirections
|
||||||
.actionNavigationUserToNavigationAuth()
|
.actionNavigationUserToNavigationAuth()
|
||||||
Navigation.findNavController(view).navigate(action)
|
Navigation.findNavController(view).navigate(action)
|
||||||
|
BIN
app/src/main/res/drawable/pizza2.jpg
Normal file
BIN
app/src/main/res/drawable/pizza2.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 293 KiB |
BIN
app/src/main/res/drawable/trash.png
Normal file
BIN
app/src/main/res/drawable/trash.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 535 B |
@ -16,6 +16,7 @@
|
|||||||
>
|
>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
|
android:id="@+id/rrrr"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center"
|
android:layout_gravity="center"
|
||||||
@ -23,7 +24,7 @@
|
|||||||
android:text="Авторизируйтесь" />
|
android:text="Авторизируйтесь" />
|
||||||
|
|
||||||
<EditText
|
<EditText
|
||||||
android:id="@+id/user_login"
|
android:id="@+id/auth_user_login"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center"
|
android:layout_gravity="center"
|
||||||
@ -34,7 +35,7 @@
|
|||||||
android:inputType="text" />
|
android:inputType="text" />
|
||||||
|
|
||||||
<EditText
|
<EditText
|
||||||
android:id="@+id/user_pass"
|
android:id="@+id/auth_user_pass"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center"
|
android:layout_gravity="center"
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
<TextView
|
<TextView
|
||||||
|
android:id="@+id/crateText"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center"
|
android:layout_gravity="center"
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
>
|
>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
|
android:id="@+id/tttt"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center"
|
android:layout_gravity="center"
|
||||||
@ -36,7 +37,7 @@
|
|||||||
android:id="@+id/button_add"
|
android:id="@+id/button_add"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_marginBottom="70dp"
|
android:layout_marginBottom="70dp"
|
||||||
android:backgroundTint="#BD350A"
|
android:backgroundTint="#F1810C"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="bottom|end"
|
android:layout_gravity="bottom|end"
|
||||||
android:text="+"/>
|
android:text="+"/>
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
android:layout_margin="30dp"
|
android:layout_margin="30dp"
|
||||||
>
|
>
|
||||||
<TextView
|
<TextView
|
||||||
|
android:id="@+id/rrr"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center"
|
android:layout_gravity="center"
|
||||||
@ -24,7 +25,7 @@
|
|||||||
android:text="Зарегистрируйтесь" />
|
android:text="Зарегистрируйтесь" />
|
||||||
|
|
||||||
<EditText
|
<EditText
|
||||||
android:id="@+id/user_login"
|
android:id="@+id/reg_user_login"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center"
|
android:layout_gravity="center"
|
||||||
@ -35,7 +36,7 @@
|
|||||||
android:hint="Логин"/>
|
android:hint="Логин"/>
|
||||||
|
|
||||||
<EditText
|
<EditText
|
||||||
android:id="@+id/user_email"
|
android:id="@+id/reg_user_email"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:fontFamily="@font/inter_bold"
|
android:fontFamily="@font/inter_bold"
|
||||||
@ -46,7 +47,7 @@
|
|||||||
android:hint="Почта"/>
|
android:hint="Почта"/>
|
||||||
|
|
||||||
<EditText
|
<EditText
|
||||||
android:id="@+id/user_pass"
|
android:id="@+id/reg_user_pass"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:fontFamily="@font/inter_bold"
|
android:fontFamily="@font/inter_bold"
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
android:fontFamily="@font/inter_bold"
|
android:fontFamily="@font/inter_bold"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="15dp"
|
android:layout_margin="15dp"
|
||||||
android:layout_gravity="left"
|
android:layout_gravity="left"
|
||||||
android:text="Логин: "
|
android:text="Логин: "
|
||||||
/>
|
/>
|
||||||
@ -31,7 +31,7 @@
|
|||||||
android:id="@+id/user_email"
|
android:id="@+id/user_email"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="15dp"
|
android:layout_margin="15dp"
|
||||||
android:layout_gravity="left"
|
android:layout_gravity="left"
|
||||||
android:text="Почта: "
|
android:text="Почта: "
|
||||||
/>
|
/>
|
||||||
|
@ -11,34 +11,35 @@
|
|||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/date_order"
|
android:id="@+id/date_order"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="25dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:layout_gravity="center"
|
android:layout_gravity="center"
|
||||||
android:gravity="center_horizontal"
|
android:gravity="center_horizontal"
|
||||||
android:fontFamily="@font/inter_bold"
|
android:fontFamily="@font/inter_bold"
|
||||||
android:text="TextView" />
|
android:text="11.11.2023" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/pizza_order"
|
android:id="@+id/pizza_order"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="80dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center"
|
android:layout_gravity="center"
|
||||||
android:fontFamily="@font/inter_bold"
|
android:fontFamily="@font/inter_bold"
|
||||||
android:gravity="center_horizontal"
|
android:gravity="center_horizontal"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:inputType="textMultiLine"
|
android:inputType="textMultiLine"
|
||||||
android:text="MultiAutoCompleteTextView" />
|
android:text="Pizzas"
|
||||||
|
tools:ignore="TextViewEdits" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/price_order"
|
android:id="@+id/price_order"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="15dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:fontFamily="@font/inter_bold"
|
android:fontFamily="@font/inter_bold"
|
||||||
android:layout_gravity="center"
|
android:layout_gravity="center"
|
||||||
android:gravity="center_horizontal"
|
android:gravity="center_horizontal"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:text="TextView" />
|
android:text="7000" />
|
||||||
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
@ -1,10 +1,11 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<TableLayout 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_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginVertical="20dp"
|
android:layout_marginVertical="20dp"
|
||||||
>
|
>
|
||||||
<TableRow>
|
<TableRow >
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/order_title"
|
android:id="@+id/order_title"
|
||||||
android:fontFamily="@font/inter_bold"
|
android:fontFamily="@font/inter_bold"
|
||||||
@ -32,7 +33,7 @@
|
|||||||
android:fontFamily="@font/inter_bold"
|
android:fontFamily="@font/inter_bold"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:text="TextView" />
|
android:text="1" />
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/plus"
|
android:id="@+id/plus"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
@ -46,12 +47,19 @@
|
|||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/order_sum"
|
android:id="@+id/order_sum"
|
||||||
android:layout_width="50dp"
|
android:layout_width="30dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:layout_marginRight="10dp"
|
|
||||||
android:gravity="right"
|
|
||||||
android:fontFamily="@font/inter_bold"
|
android:fontFamily="@font/inter_bold"
|
||||||
android:text="TextView" />
|
android:text="TextView" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/button_trash"
|
||||||
|
android:layout_width="50dp"
|
||||||
|
android:layout_height="50dp"
|
||||||
|
android:backgroundTint="#BD350A"
|
||||||
|
android:layout_marginHorizontal="20dp"
|
||||||
|
android:gravity="right"
|
||||||
|
android:background="@drawable/trash" />
|
||||||
</TableRow>
|
</TableRow>
|
||||||
</TableLayout>
|
</TableLayout>
|
@ -11,10 +11,14 @@
|
|||||||
tools:layout="@layout/fragment_auth">
|
tools:layout="@layout/fragment_auth">
|
||||||
<action
|
<action
|
||||||
android:id="@+id/action_navigation_auth_to_navigation_pizza_list"
|
android:id="@+id/action_navigation_auth_to_navigation_pizza_list"
|
||||||
app:destination="@id/navigation_pizza_list" />
|
app:destination="@id/navigation_pizza_list"
|
||||||
|
app:popUpTo="@id/nav_graph"
|
||||||
|
app:popUpToInclusive="true" />
|
||||||
<action
|
<action
|
||||||
android:id="@+id/action_navigation_auth_to_navigation_reg"
|
android:id="@+id/action_navigation_auth_to_navigation_reg"
|
||||||
app:destination="@id/navigation_reg" />
|
app:destination="@id/navigation_reg"
|
||||||
|
app:popUpTo="@id/nav_graph"
|
||||||
|
app:popUpToInclusive="true" />
|
||||||
</fragment>
|
</fragment>
|
||||||
|
|
||||||
<fragment
|
<fragment
|
||||||
@ -24,10 +28,14 @@
|
|||||||
tools:layout="@layout/fragment_reg">
|
tools:layout="@layout/fragment_reg">
|
||||||
<action
|
<action
|
||||||
android:id="@+id/action_navigation_reg_to_navigation_pizza_list"
|
android:id="@+id/action_navigation_reg_to_navigation_pizza_list"
|
||||||
app:destination="@id/navigation_pizza_list" />
|
app:destination="@id/navigation_pizza_list"
|
||||||
|
app:popUpTo="@id/nav_graph"
|
||||||
|
app:popUpToInclusive="true" />
|
||||||
<action
|
<action
|
||||||
android:id="@+id/action_navigation_reg_to_navigation_auth"
|
android:id="@+id/action_navigation_reg_to_navigation_auth"
|
||||||
app:destination="@id/navigation_auth" />
|
app:destination="@id/navigation_auth"
|
||||||
|
app:popUpTo="@id/nav_graph"
|
||||||
|
app:popUpToInclusive="true" />
|
||||||
</fragment>
|
</fragment>
|
||||||
|
|
||||||
<fragment
|
<fragment
|
||||||
@ -38,12 +46,18 @@
|
|||||||
<action
|
<action
|
||||||
android:id="@+id/action_navigation_list_to_navigation_create_pizza"
|
android:id="@+id/action_navigation_list_to_navigation_create_pizza"
|
||||||
app:destination="@id/navigation_create_pizza" />
|
app:destination="@id/navigation_create_pizza" />
|
||||||
|
|
||||||
</fragment>
|
</fragment>
|
||||||
<fragment
|
<fragment
|
||||||
android:id="@+id/navigation_crate"
|
android:id="@+id/navigation_crate"
|
||||||
android:name="com.example.pizza.crate"
|
android:name="com.example.pizza.crate"
|
||||||
android:label="crate"
|
android:label="crate"
|
||||||
tools:layout="@layout/fragment_crate">
|
tools:layout="@layout/fragment_crate">
|
||||||
|
<action
|
||||||
|
android:id="@+id/action_navigation_crete_pizza_to_list_navigation_"
|
||||||
|
app:destination="@id/navigation_pizza_list"
|
||||||
|
app:popUpTo="@id/nav_graph"
|
||||||
|
app:popUpToInclusive="true" />
|
||||||
|
|
||||||
</fragment>
|
</fragment>
|
||||||
<fragment
|
<fragment
|
||||||
@ -51,7 +65,11 @@
|
|||||||
android:name="com.example.pizza.create_pizza"
|
android:name="com.example.pizza.create_pizza"
|
||||||
android:label="create_pizza"
|
android:label="create_pizza"
|
||||||
tools:layout="@layout/fragment_create_pizza">
|
tools:layout="@layout/fragment_create_pizza">
|
||||||
|
<action
|
||||||
|
android:id="@+id/action_navigation_create_pizza_to_list_navigation_"
|
||||||
|
app:destination="@id/navigation_pizza_list"
|
||||||
|
app:popUpTo="@id/nav_graph"
|
||||||
|
app:popUpToInclusive="true" />
|
||||||
</fragment>
|
</fragment>
|
||||||
|
|
||||||
<fragment
|
<fragment
|
||||||
@ -61,7 +79,9 @@
|
|||||||
tools:layout="@layout/fragment_user">
|
tools:layout="@layout/fragment_user">
|
||||||
<action
|
<action
|
||||||
android:id="@+id/action_navigation_user_to_navigation_auth"
|
android:id="@+id/action_navigation_user_to_navigation_auth"
|
||||||
app:destination="@id/navigation_auth" />
|
app:destination="@id/navigation_auth"
|
||||||
|
app:popUpTo="@id/nav_graph"
|
||||||
|
app:popUpToInclusive="true" />
|
||||||
|
|
||||||
</fragment>
|
</fragment>
|
||||||
</navigation>
|
</navigation>
|
Loading…
Reference in New Issue
Block a user