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. User selects a restaurant User decides to add a thought for that particular restaurant User clicks button and thought/UserMeal is added to the "meals" arraylist of the selected restaurant
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: MutableList<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
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)
}
-----EDIT-----
----My Activity for the middle screen where restaurant is passed in----
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_restaurant)
val button = findViewById<Button>(R.id.addBtn)
// rvThoughts.adapter = adapter
// rvThoughts.layoutManager = LinearLayoutManager(this)
button.setOnClickListener{
val intent = Intent(this, ThoughtsActivity::class.java)
intent.putExtra("restaurantObject", <??>)
startActivity(intent)
}
var intent = intent
val aName = intent.getStringExtra("iName")
val aRating = intent.getDoubleExtra("iRating",0.0)
val aPrice = intent.getStringExtra("iPrice")
val aReviews = intent.getStringExtra("iReviews")
val aImageUrl = intent.getStringExtra("iImageUrl")
val aCategory = intent.getStringExtra("iCategory")
val aLocation = intent.getStringExtra("iLocation")
r_name.text = aName
r_reviews.text = aReviews
r_rating.rating = aRating.toFloat()
r_price.text = aPrice
r_reviews.text = aReviews.toString()
Glide.with(applicationContext).load(aImageUrl).into(r_image)
r_category.text = aCategory
r_address.text = aLocation
}