11package com.frogobox.themealsapi
22
33import android.os.Bundle
4+ import android.view.View
5+ import android.widget.ImageView
6+ import android.widget.TextView
47import android.widget.Toast
58import androidx.appcompat.app.AppCompatActivity
9+ import com.bumptech.glide.Glide
610import com.frogobox.frogothemealdbapi.ConsumeTheMealDbApi
711import com.frogobox.frogothemealdbapi.callback.MealResultCallback
8- import com.frogobox.frogothemealdbapi.data.model.Category
12+ import com.frogobox.frogothemealdbapi.data.model.Meal
913import com.frogobox.frogothemealdbapi.data.response.MealResponse
14+ import com.frogobox.recycler.boilerplate.viewrclass.FrogoViewAdapterCallback
15+ import kotlinx.android.synthetic.main.activity_main.*
1016
1117class MainActivity : AppCompatActivity () {
1218
1319 override fun onCreate (savedInstanceState : Bundle ? ) {
1420 super .onCreate(savedInstanceState)
1521 setContentView(R .layout.activity_main)
22+ setupConsumableMealApi(" b" )
23+ }
1624
17- val consumeMealApi = ConsumeTheMealDbApi (" 1" )
25+ private fun consumeMealApi (): ConsumeTheMealDbApi {
26+ val consumeCode = ConsumeTheMealDbApi (" 1" )
27+ consumeCode.usingChuckInterceptor(this )
28+ return consumeCode
29+ }
1830
19- consumeMealApi.usingChuckInterceptor(this )
20- consumeMealApi.listAllCateories(object : MealResultCallback <MealResponse <Category >> {
21- override fun getResultData (data : MealResponse <Category >) {
22- for (i in data.meals!! .indices) {
23- Toast .makeText(this @MainActivity, data.meals!! [i].strCategory, Toast .LENGTH_SHORT ).show()
24- }
31+ private fun setupConsumableMealApi (firstLetter : String ) {
32+ consumeMealApi().listAllMeal(firstLetter, object : MealResultCallback <MealResponse <Meal >> {
33+ override fun getResultData (data : MealResponse <Meal >) {
34+ data.meals?.let { setupFrogoRecyclerView(it) }
2535 }
2636
2737 override fun failedResult (statusCode : Int , errorMessage : String? ) {
@@ -30,13 +40,44 @@ class MainActivity : AppCompatActivity() {
3040
3141 override fun onShowProgress () {
3242 // Show Your Progress View
43+ runOnUiThread {
44+ progress_bar.visibility = View .VISIBLE
45+ }
3346 }
3447
3548 override fun onHideProgress () {
3649 // Hide Your Progress View
50+ runOnUiThread {
51+ progress_bar.visibility = View .GONE
52+ }
3753 }
3854 })
55+ }
3956
57+ private fun setupFrogoRecyclerView (data : List <Meal >) {
58+ frogo_rv.injector<Meal >()
59+ .addData(data)
60+ .addCustomView(R .layout.frogo_rv_grid_type_13)
61+ .addCallback(object : FrogoViewAdapterCallback <Meal > {
62+ override fun onItemClicked (data : Meal ) {
63+ }
4064
65+ override fun onItemLongClicked (data : Meal ) {
66+
67+ }
68+
69+ override fun setupInitComponent (view : View , data : Meal ) {
70+ val ivPoster = view.findViewById<ImageView >(R .id.frogo_rv_type_13_iv_poster)
71+ val tvTitle = view.findViewById<TextView >(R .id.frogo_rv_type_13_tv_title)
72+ val tvSubTitle = view.findViewById<TextView >(R .id.frogo_rv_type_13_tv_subtitle)
73+
74+ Glide .with (view.context).load(data.strMealThumb).into(ivPoster)
75+ tvTitle.text = data.strMeal
76+ tvSubTitle.text = data.strCategory
77+ }
78+ })
79+ .createLayoutGrid(2 )
80+ .build()
4181 }
82+
4283}
0 commit comments