-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainActivity.java
More file actions
58 lines (43 loc) · 1.96 KB
/
MainActivity.java
File metadata and controls
58 lines (43 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
public void getRetrofit() {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(FoodAPI.FOOD_DATA_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
FoodAPI foodAPI = retrofit.create(FoodAPI.class);
Call<MyData> call = foodAPI.getAllData();
call.enqueue(new Callback<MyData>() {
@Override
public void onResponse(@NonNull Call<MyData> call, @NonNull Response<MyData> response) {
Log.d("TAG_JSON_FOOD_DB", "--------: " + response.message());
Log.d("TAG_JSON_FOOD_DB", "--------: " + response.body());
List<Foods> foods=response.body().getMyData();
for (int i=0; i<foods.size(); i++){
Log.d("TAG_JSON_FOOD_DB", "--------: "+"name:" +foods.get(i).getFoodName());
for (int k=0; k<foods.get(i).getUnits().size(); k++){
Log.d("TAG_JSON_FOOD_DB", "--------: " +foods.get(i).getUnits().get(k).getUnit());
}
}
}
@Override
public void onFailure(@NonNull Call<MyData> call, @NonNull Throwable t) {
}
});
}
class SaveTask extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... voids) {
Foods food = new Foods();
// help
FoodDatabaseClient.getInstance(getApplicationContext()).getAppDatabase()
.daoAccess()
.insert(food);
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
finish();
startActivity(new Intent(getApplicationContext(), MainActivity.class));
Toast.makeText(getApplicationContext(), "Saved", Toast.LENGTH_LONG).show();
}
}