1
1
package com.frogobox.themealsapi
2
2
3
3
import android.os.Bundle
4
+ import android.view.View
5
+ import android.widget.ImageView
6
+ import android.widget.TextView
4
7
import android.widget.Toast
5
8
import androidx.appcompat.app.AppCompatActivity
9
+ import com.bumptech.glide.Glide
6
10
import com.frogobox.frogothemealdbapi.ConsumeTheMealDbApi
7
11
import com.frogobox.frogothemealdbapi.callback.MealResultCallback
8
- import com.frogobox.frogothemealdbapi.data.model.Category
12
+ import com.frogobox.frogothemealdbapi.data.model.Meal
9
13
import com.frogobox.frogothemealdbapi.data.response.MealResponse
14
+ import com.frogobox.recycler.boilerplate.viewrclass.FrogoViewAdapterCallback
15
+ import kotlinx.android.synthetic.main.activity_main.*
10
16
11
17
class MainActivity : AppCompatActivity () {
12
18
13
19
override fun onCreate (savedInstanceState : Bundle ? ) {
14
20
super .onCreate(savedInstanceState)
15
21
setContentView(R .layout.activity_main)
22
+ setupConsumableMealApi(" b" )
23
+ }
16
24
17
- val consumeMealApi = ConsumeTheMealDbApi (" 1" )
25
+ private fun consumeMealApi (): ConsumeTheMealDbApi {
26
+ val consumeCode = ConsumeTheMealDbApi (" 1" )
27
+ consumeCode.usingChuckInterceptor(this )
28
+ return consumeCode
29
+ }
18
30
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) }
25
35
}
26
36
27
37
override fun failedResult (statusCode : Int , errorMessage : String? ) {
@@ -30,13 +40,44 @@ class MainActivity : AppCompatActivity() {
30
40
31
41
override fun onShowProgress () {
32
42
// Show Your Progress View
43
+ runOnUiThread {
44
+ progress_bar.visibility = View .VISIBLE
45
+ }
33
46
}
34
47
35
48
override fun onHideProgress () {
36
49
// Hide Your Progress View
50
+ runOnUiThread {
51
+ progress_bar.visibility = View .GONE
52
+ }
37
53
}
38
54
})
55
+ }
39
56
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
+ }
40
64
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()
41
81
}
82
+
42
83
}
0 commit comments