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

Commit e93cd6e

Browse files
committed
add: List Meals
1 parent a032990 commit e93cd6e

File tree

16 files changed

+442
-9
lines changed

16 files changed

+442
-9
lines changed

app/src/main/java/com/frogobox/themealsapi/MainActivity.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import android.os.Bundle
44
import androidx.appcompat.app.AppCompatActivity
55
import com.frogobox.frogothemealdbapi.ConsumeMealApi
66
import com.frogobox.frogothemealdbapi.callback.MealResultCallback
7+
import com.frogobox.frogothemealdbapi.data.response.CategoriesList
78
import com.frogobox.frogothemealdbapi.data.response.Meals
89

910
class MainActivity : AppCompatActivity() {
@@ -17,8 +18,8 @@ class MainActivity : AppCompatActivity() {
1718
val consumeMealApi = ConsumeMealApi("1")
1819

1920
consumeMealApi.usingChuckInterceptor(this)
20-
consumeMealApi.lookupRandomMeal(object : MealResultCallback<Meals> {
21-
override fun getResultData(data: Meals) {
21+
consumeMealApi.listAllCateories(object : MealResultCallback<CategoriesList> {
22+
override fun getResultData(data: CategoriesList) {
2223
for (i in data.meals!!.indices) {
2324

2425
}

frogothemealdbapi/src/main/java/com/frogobox/frogothemealdbapi/ConsumeMealApi.kt

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package com.frogobox.frogothemealdbapi
22

33
import android.content.Context
44
import com.frogobox.frogothemealdbapi.callback.MealResultCallback
5-
import com.frogobox.frogothemealdbapi.data.response.Meals
5+
import com.frogobox.frogothemealdbapi.data.response.*
66
import com.frogobox.frogothemealdbapi.data.source.MealDataSource
77
import com.frogobox.frogothemealdbapi.data.source.MealRemoteDataSource
88
import com.frogobox.frogothemealdbapi.data.source.MealRepository
@@ -82,4 +82,52 @@ class ConsumeMealApi(private val apiKey: String) : ConsumeMealApiView {
8282
}
8383
})
8484
}
85+
86+
override fun listMealCategories(callback: MealResultCallback<Categories>) {
87+
repository.listMealCategories(apiKey, object : MealDataSource.GetRemoteCallback<Categories> {
88+
override fun onSuccess(data: Categories) {
89+
callback.getResultData(data)
90+
}
91+
92+
override fun onFailed(statusCode: Int, errorMessage: String?) {
93+
callback.failedResult(statusCode, errorMessage)
94+
}
95+
})
96+
}
97+
98+
override fun listAllCateories(callback: MealResultCallback<CategoriesList>) {
99+
repository.listAllCateories(apiKey, object : MealDataSource.GetRemoteCallback<CategoriesList> {
100+
override fun onSuccess(data: CategoriesList) {
101+
callback.getResultData(data)
102+
}
103+
104+
override fun onFailed(statusCode: Int, errorMessage: String?) {
105+
callback.failedResult(statusCode, errorMessage)
106+
}
107+
})
108+
}
109+
110+
override fun listAllArea(callback: MealResultCallback<Areas>) {
111+
repository.listAllArea(apiKey, object : MealDataSource.GetRemoteCallback<Areas> {
112+
override fun onSuccess(data: Areas) {
113+
callback.getResultData(data)
114+
}
115+
116+
override fun onFailed(statusCode: Int, errorMessage: String?) {
117+
callback.failedResult(statusCode, errorMessage)
118+
}
119+
})
120+
}
121+
122+
override fun listAllIngredients(callback: MealResultCallback<Ingredients>) {
123+
repository.listAllIngredients(apiKey, object : MealDataSource.GetRemoteCallback<Ingredients> {
124+
override fun onSuccess(data: Ingredients) {
125+
callback.getResultData(data)
126+
}
127+
128+
override fun onFailed(statusCode: Int, errorMessage: String?) {
129+
callback.failedResult(statusCode, errorMessage)
130+
}
131+
})
132+
}
85133
}

frogothemealdbapi/src/main/java/com/frogobox/frogothemealdbapi/ConsumeMealApiView.kt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ package com.frogobox.frogothemealdbapi
22

33
import android.content.Context
44
import com.frogobox.frogothemealdbapi.callback.MealResultCallback
5-
import com.frogobox.frogothemealdbapi.data.response.Meals
5+
import com.frogobox.frogothemealdbapi.data.response.*
6+
import com.frogobox.frogothemealdbapi.data.source.MealDataSource
67

78
/**
89
* Created by Faisal Amir
@@ -38,4 +39,17 @@ interface ConsumeMealApiView {
3839
// Lookup a single random meal
3940
fun lookupRandomMeal(callback: MealResultCallback<Meals>)
4041

42+
// List all meal categories
43+
fun listMealCategories(callback: MealResultCallback<Categories>)
44+
45+
// List all Categories
46+
fun listAllCateories(callback: MealResultCallback<CategoriesList>)
47+
48+
// List all Area
49+
fun listAllArea(callback: MealResultCallback<Areas>)
50+
51+
// List all Ingredients
52+
fun listAllIngredients(callback: MealResultCallback<Ingredients>)
53+
54+
4155
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.frogobox.frogothemealdbapi.data.model
2+
3+
import com.google.gson.annotations.SerializedName
4+
5+
/**
6+
* Created by Faisal Amir
7+
* FrogoBox Inc License
8+
* =========================================
9+
* TheMealsAPI
10+
* Copyright (C) 15/03/2020.
11+
* All rights reserved
12+
* -----------------------------------------
13+
* Name : Muhammad Faisal Amir
14+
* E-mail : [email protected]
15+
* Github : github.com/amirisback
16+
* LinkedIn : linkedin.com/in/faisalamircs
17+
* -----------------------------------------
18+
* FrogoBox Software Industries
19+
* com.frogobox.frogothemealdbapi.data.model
20+
*
21+
*/
22+
data class Area(
23+
24+
@SerializedName("strArea")
25+
var strArea: String? = null
26+
27+
)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.frogobox.frogothemealdbapi.data.model
2+
3+
import com.google.gson.annotations.SerializedName
4+
5+
/**
6+
* Created by Faisal Amir
7+
* FrogoBox Inc License
8+
* =========================================
9+
* TheMealsAPI
10+
* Copyright (C) 15/03/2020.
11+
* All rights reserved
12+
* -----------------------------------------
13+
* Name : Muhammad Faisal Amir
14+
* E-mail : [email protected]
15+
* Github : github.com/amirisback
16+
* LinkedIn : linkedin.com/in/faisalamircs
17+
* -----------------------------------------
18+
* FrogoBox Software Industries
19+
* com.frogobox.frogothemealdbapi.data.model
20+
*
21+
*/
22+
data class Category(
23+
24+
@SerializedName("idCategory")
25+
var idCategory: String? = null,
26+
27+
@SerializedName("strCategory")
28+
var strCategory: String? = null,
29+
30+
@SerializedName("strCategoryThumb")
31+
var strCategoryThumb: String? = null,
32+
33+
@SerializedName("strCategoryDescription")
34+
var strCategoryDescription: String? = null
35+
36+
)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.frogobox.frogothemealdbapi.data.model
2+
3+
import com.google.gson.annotations.SerializedName
4+
5+
/**
6+
* Created by Faisal Amir
7+
* FrogoBox Inc License
8+
* =========================================
9+
* TheMealsAPI
10+
* Copyright (C) 15/03/2020.
11+
* All rights reserved
12+
* -----------------------------------------
13+
* Name : Muhammad Faisal Amir
14+
* E-mail : [email protected]
15+
* Github : github.com/amirisback
16+
* LinkedIn : linkedin.com/in/faisalamircs
17+
* -----------------------------------------
18+
* FrogoBox Software Industries
19+
* com.frogobox.frogothemealdbapi.data.model
20+
*
21+
*/
22+
data class Ingredient(
23+
24+
@SerializedName("idIngredient")
25+
var idIngredient: String? = null,
26+
27+
@SerializedName("strIngredient")
28+
var strIngredient: String? = null,
29+
30+
@SerializedName("strDescription")
31+
var strDescription: String? = null,
32+
33+
@SerializedName("strType")
34+
var strType: String? = null
35+
36+
)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.frogobox.frogothemealdbapi.data.response
2+
3+
import com.frogobox.frogothemealdbapi.data.model.Area
4+
import com.frogobox.frogothemealdbapi.data.model.Category
5+
import com.google.gson.annotations.SerializedName
6+
7+
/**
8+
* Created by Faisal Amir
9+
* FrogoBox Inc License
10+
* =========================================
11+
* TheMealsAPI
12+
* Copyright (C) 15/03/2020.
13+
* All rights reserved
14+
* -----------------------------------------
15+
* Name : Muhammad Faisal Amir
16+
* E-mail : [email protected]
17+
* Github : github.com/amirisback
18+
* LinkedIn : linkedin.com/in/faisalamircs
19+
* -----------------------------------------
20+
* FrogoBox Software Industries
21+
* com.frogobox.frogothemealdbapi.data.response
22+
*
23+
*/
24+
data class Areas(
25+
26+
@SerializedName("meals")
27+
var meals: List<Area>? = null
28+
29+
)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.frogobox.frogothemealdbapi.data.response
2+
3+
import com.frogobox.frogothemealdbapi.data.model.Category
4+
import com.google.gson.annotations.SerializedName
5+
6+
/**
7+
* Created by Faisal Amir
8+
* FrogoBox Inc License
9+
* =========================================
10+
* TheMealsAPI
11+
* Copyright (C) 15/03/2020.
12+
* All rights reserved
13+
* -----------------------------------------
14+
* Name : Muhammad Faisal Amir
15+
* E-mail : [email protected]
16+
* Github : github.com/amirisback
17+
* LinkedIn : linkedin.com/in/faisalamircs
18+
* -----------------------------------------
19+
* FrogoBox Software Industries
20+
* com.frogobox.frogothemealdbapi.data.response
21+
*
22+
*/
23+
data class Categories(
24+
25+
@SerializedName("categories")
26+
var categories: List<Category>? = null
27+
28+
)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.frogobox.frogothemealdbapi.data.response
2+
3+
import com.frogobox.frogothemealdbapi.data.model.Category
4+
import com.google.gson.annotations.SerializedName
5+
6+
/**
7+
* Created by Faisal Amir
8+
* FrogoBox Inc License
9+
* =========================================
10+
* TheMealsAPI
11+
* Copyright (C) 15/03/2020.
12+
* All rights reserved
13+
* -----------------------------------------
14+
* Name : Muhammad Faisal Amir
15+
* E-mail : [email protected]
16+
* Github : github.com/amirisback
17+
* LinkedIn : linkedin.com/in/faisalamircs
18+
* -----------------------------------------
19+
* FrogoBox Software Industries
20+
* com.frogobox.frogothemealdbapi.data.response
21+
*
22+
*/
23+
data class CategoriesList(
24+
25+
@SerializedName("meals")
26+
var meals: List<Category>? = null
27+
28+
)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.frogobox.frogothemealdbapi.data.response
2+
3+
import com.frogobox.frogothemealdbapi.data.model.Ingredient
4+
import com.google.gson.annotations.SerializedName
5+
6+
/**
7+
* Created by Faisal Amir
8+
* FrogoBox Inc License
9+
* =========================================
10+
* TheMealsAPI
11+
* Copyright (C) 15/03/2020.
12+
* All rights reserved
13+
* -----------------------------------------
14+
* Name : Muhammad Faisal Amir
15+
* E-mail : [email protected]
16+
* Github : github.com/amirisback
17+
* LinkedIn : linkedin.com/in/faisalamircs
18+
* -----------------------------------------
19+
* FrogoBox Software Industries
20+
* com.frogobox.frogothemealdbapi.data.response
21+
*
22+
*/
23+
data class Ingredients(
24+
25+
@SerializedName("meals")
26+
var meals: List<Ingredient>? = null
27+
28+
)

0 commit comments

Comments
 (0)