My addMeal function expects a restaurant/YelpRestaurant (that was previously selected by the user… see images)
How do I pass that selected restaurant in?? Hope this is very simple and I am overthinking it
This is my first kotlin android project so apologies for stupidity.
----Data classes----
data class YelpSearchResult(
@SerializedName ("total") val total: Int,
@SerializedName ("businesses") val restaurants: List<YelpRestaurant>
)
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: ArrayList<UserMeals> = ArrayList()
)
data class UserMeals (
val mealName: String,
val mealPrice: Double,
val mealThoughts: String
)
I’m only interested in the meals list and the UserMeals data class
---- Activity ----
class ThoughtsActivity : AppCompatActivity() {
lateinit var mealName : String
lateinit var mealPrice : String
lateinit var mealThought : String
lateinit var addedMeal : UserMeals
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()
val addedMeal = UserMeals(mealName,mealPrice.toDouble(),mealThought)
if(mealName.isNotEmpty()){
addMeal()
}
val intent = Intent(this, RestaurantActivity::class.java)
intent.putExtra("MEALNAME", mealName)
intent.putExtra("PRICE", mealPrice)
intent.putExtra("MEALTHOUGHT", mealThought)
}
}
fun addMeal(restaurant: YelpRestaurant){
restaurant.meals.add(addedMeal)
}