Skip to content
This repository was archived by the owner on Aug 18, 2021. It is now read-only.

Commit a6a25a6

Browse files
committed
add: sample code
1 parent 60e4f67 commit a6a25a6

File tree

2 files changed

+65
-9
lines changed

2 files changed

+65
-9
lines changed
Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,37 @@
11
package com.frogobox.themealsapi
22

33
import android.os.Bundle
4+
import android.view.View
5+
import android.widget.ImageView
6+
import android.widget.TextView
47
import android.widget.Toast
58
import androidx.appcompat.app.AppCompatActivity
9+
import com.bumptech.glide.Glide
610
import com.frogobox.frogothemealdbapi.ConsumeTheMealDbApi
711
import com.frogobox.frogothemealdbapi.callback.MealResultCallback
8-
import com.frogobox.frogothemealdbapi.data.model.Category
12+
import com.frogobox.frogothemealdbapi.data.model.Meal
913
import com.frogobox.frogothemealdbapi.data.response.MealResponse
14+
import com.frogobox.recycler.boilerplate.viewrclass.FrogoViewAdapterCallback
15+
import kotlinx.android.synthetic.main.activity_main.*
1016

1117
class 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
}

app/src/main/res/layout/activity_main.xml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,27 @@
44
xmlns:tools="http://schemas.android.com/tools"
55
android:layout_width="match_parent"
66
android:layout_height="match_parent"
7+
android:background="@color/frogoRvColorWhite"
78
tools:context=".MainActivity">
89

9-
<TextView
10+
<com.frogobox.recycler.FrogoRecyclerView
11+
android:id="@+id/frogo_rv"
12+
android:layout_width="0dp"
13+
android:layout_height="0dp"
14+
android:clipToPadding="false"
15+
android:paddingStart="@dimen/frogo_rv_dimen_16dp"
16+
android:paddingTop="@dimen/frogo_rv_dimen_16dp"
17+
app:layout_constraintBottom_toBottomOf="parent"
18+
app:layout_constraintLeft_toLeftOf="parent"
19+
app:layout_constraintRight_toRightOf="parent"
20+
app:layout_constraintTop_toTopOf="parent" />
21+
22+
<ProgressBar
23+
android:id="@+id/progress_bar"
1024
android:layout_width="wrap_content"
1125
android:layout_height="wrap_content"
1226
android:text="Hello World!"
27+
android:visibility="gone"
1328
app:layout_constraintBottom_toBottomOf="parent"
1429
app:layout_constraintLeft_toLeftOf="parent"
1530
app:layout_constraintRight_toRightOf="parent"

0 commit comments

Comments
 (0)