--- Класс данных ---
Попытка добавить объект в еду MutableList -------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- ---------------------------------
data class YelpRestaurant(
val name: String,
val rating: Double,
val price: String,
@SerializedName("review_count") val numReviews: Int,
@SerializedName("image_url") val imageUrl: String,
val categories: List<YelpCategory>,
val location: YelpLocation,
val meals: MutableList<UserMeals>
)
- --- РЕДАКЦИОННАЯ ДЕЯТЕЛЬНОСТЬ ----
class ThoughtsActivity : AppCompatActivity() {
lateinit var mealName: String
lateinit var mealPrice: String
lateinit var mealThought: String
lateinit var selected_Restaurant : YelpRestaurant
val meals = mutableListOf<UserMeals>()
@Subscribe(sticky = true)
fun getRest(selectedRestaurant : YelpRestaurant) {
selected_Restaurant = selectedRestaurant
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_thoughts)
thoughtBtn.setOnClickListener() {
mealName = m_name.text.toString()
mealPrice = m_price.text.toString()
mealThought = m_thought.text.toString()
var addedMeal = UserMeals(mealName, mealPrice.toDouble(), mealThought)
if (mealName.isNotEmpty()) {
selected_Restaurant.meals.add(addedMeal)
}
}
}
override fun onStart() {
super.onStart()
EventBus.getDefault().register(this)
}
override fun onStop() {
super.onStop()
EventBus.getDefault().unregister(this)
}
}