feat: refs #8085 restaurantActivity

This commit is contained in:
Sergio De la torre 2024-12-02 18:14:28 +01:00
parent d4a7789101
commit 969660ae77
2 changed files with 24 additions and 13 deletions

View File

@ -2,14 +2,12 @@ package es.verdnatura.presentation.view.feature.restaurant
import android.view.View
import android.widget.Button
import com.google.gson.Gson
import com.google.zxing.BarcodeFormat
import com.journeyapps.barcodescanner.BarcodeEncoder
import es.verdnatura.R
import es.verdnatura.databinding.ActivityRestaurantViewBinding
import es.verdnatura.domain.toast
import es.verdnatura.presentation.base.BaseActivity
import es.verdnatura.presentation.view.feature.restaurant.model.UserMenu
class RestaurantActivity : BaseActivity<ActivityRestaurantViewBinding>() {
@ -33,16 +31,27 @@ class RestaurantActivity : BaseActivity<ActivityRestaurantViewBinding>() {
binding.imageQr.visibility = View.VISIBLE
binding.txtOption.visibility = View.VISIBLE
binding.txtOption.text = (view as Button).text.toString()
val userMenu = UserMenu(
user = mobileApplication.userId!!,
menu_id = view.tag.toString().toInt(),
menu = view.text.toString(),
name = mobileApplication.userName!!
)
/* val userMenu = UserMenu(
user = mobileApplication.userId!!,
menu_id = view.tag.toString().toInt(),
menu = view.text.toString(),
name = mobileApplication.userName!!
)*/
val userMenuJson = StringBuilder()
.append("{")
.append("\"user\":").append(mobileApplication.userId).append(",") // Sin comillas
.append("\"menu_id\":").append(view.tag.toString().toInt()).append(",") // Sin comillas
.append("\"menu\":\"").append(view.text).append("\",") // Con comillas porque es texto
.append("\"name\":\"").append(mobileApplication.userName)
.append("\"") // Con comillas porque es texto
.append("}")
.toString()
try {
val barcodeEncoder = BarcodeEncoder()
val bitmap = barcodeEncoder.encodeBitmap(
Gson().toJson(userMenu),
userMenuJson,
BarcodeFormat.QR_CODE,
400,
400

View File

@ -1,8 +1,10 @@
package es.verdnatura.presentation.view.feature.restaurant.model
import com.google.gson.annotations.SerializedName
data class UserMenu(
val user: Int,
val menu_id: Int,
val menu: String,
val name: String
@SerializedName("user") val user: Int,
@SerializedName("menu_id") val menu_id: Int,
@SerializedName("menu") val menu: String,
@SerializedName("name") val name: String
)