1
This commit is contained in:
@@ -19,15 +19,20 @@ public class MaterialResultAdapter extends RecyclerView.Adapter<MaterialResultHo
|
||||
private ArrayList<FoodMenu> foodMenus;
|
||||
private Context context;
|
||||
|
||||
public MaterialResultAdapter(ArrayList<FoodMenu> foodMenus, Context context) {
|
||||
this.foodMenus = foodMenus;
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MaterialResultHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
View view = LayoutInflater.from(context).inflate(R.layout.recommend_item_middle, parent, false);
|
||||
View view = LayoutInflater.from(context).inflate(R.layout.material_result_item, parent, false);
|
||||
return new MaterialResultHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(MaterialResultHolder holder, int position) {
|
||||
|
||||
holder.bindView(foodMenus.get(position));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.example.ninefourone.nutritionmaster.adapter;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
@@ -9,6 +10,8 @@ import android.widget.TextView;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.example.ninefourone.nutritionmaster.R;
|
||||
import com.example.ninefourone.nutritionmaster.bean.FoodMenu;
|
||||
import com.example.ninefourone.nutritionmaster.bean.RecommendFood;
|
||||
import com.example.ninefourone.nutritionmaster.modules.RecipeActivity.RecipeActivity;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
@@ -18,10 +21,10 @@ import butterknife.ButterKnife;
|
||||
*/
|
||||
|
||||
public class MaterialResultHolder extends RecyclerView.ViewHolder {
|
||||
@BindView(R.id.recommend_item_imageview)
|
||||
ImageView recommendItemImageview;
|
||||
@BindView(R.id.recommend_item_title)
|
||||
TextView recommendItemTitle;
|
||||
@BindView(R.id.image)
|
||||
ImageView image;
|
||||
@BindView(R.id.name)
|
||||
TextView name;
|
||||
@BindView(R.id.whole_layout)
|
||||
LinearLayout wholeLayout;
|
||||
|
||||
@@ -30,8 +33,17 @@ public class MaterialResultHolder extends RecyclerView.ViewHolder {
|
||||
ButterKnife.bind(this, itemView);
|
||||
}
|
||||
|
||||
public void bindView(FoodMenu foodMenu) {
|
||||
Glide.with(itemView.getContext()).load(foodMenu.getImage_url()).into(recommendItemImageview);
|
||||
recommendItemTitle.setText(foodMenu.getName());
|
||||
public void bindView(final FoodMenu foodMenu) {
|
||||
Glide.with(itemView.getContext()).load(foodMenu.getImage_url()).into(image);
|
||||
name.setText(foodMenu.getName());
|
||||
wholeLayout.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent(itemView.getContext().getApplicationContext(), RecipeActivity.class);
|
||||
RecommendFood recommendFood = new RecommendFood(foodMenu, 1);
|
||||
intent.putExtra("SEND_OBJECT", recommendFood);
|
||||
itemView.getContext().getApplicationContext().startActivity(intent);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,14 +64,12 @@ public class ClassifyResult implements Serializable {
|
||||
public void onFailure(Call call, IOException e) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(Call call, Response response) throws IOException {
|
||||
String json = response.body().string();
|
||||
FoodMaterial material = new Gson().fromJson(json, FoodMaterial.class);
|
||||
foodMaterial = new Material();
|
||||
foodMaterial.setFoodMaterial(material);
|
||||
|
||||
}
|
||||
});
|
||||
} else {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.example.ninefourone.nutritionmaster.bean;
|
||||
|
||||
import com.example.ninefourone.nutritionmaster.utils.MessageUtils;
|
||||
import com.example.ninefourone.nutritionmaster.utils.WebUtil;
|
||||
import com.google.gson.Gson;
|
||||
import com.orhanobut.logger.Logger;
|
||||
@@ -26,26 +27,38 @@ public class Material implements Serializable {
|
||||
|
||||
public void setFoodMaterial(FoodMaterial foodMaterial) {
|
||||
this.foodMaterial = foodMaterial;
|
||||
int max = foodMaterial.getCook_quantity().size() > 30 ? 30 : foodMaterial.getCook_quantity().size();
|
||||
int index = 0;
|
||||
// addMenu(index, max);
|
||||
for (int i = 0; i < max; i++) {
|
||||
WebUtil webUtil = WebUtil.getInstance();
|
||||
FoodMaterial.CookQuantityBean temp = foodMaterial.getCook_quantity().get(i);
|
||||
String menuName = temp.getMenu();
|
||||
webUtil.getMenu(menuName, new Callback() {
|
||||
@Override
|
||||
public void onFailure(Call call, IOException e) {
|
||||
try {
|
||||
int max = foodMaterial.getCook_quantity().size() > 30 ? 30 : foodMaterial.getCook_quantity().size();
|
||||
for (int i = 0; i < max; i++) {
|
||||
WebUtil webUtil = WebUtil.getInstance();
|
||||
FoodMaterial.CookQuantityBean temp = foodMaterial.getCook_quantity().get(i);
|
||||
String menuName = temp.getMenu();
|
||||
webUtil.getMenu(menuName, new Callback() {
|
||||
@Override
|
||||
public void onFailure(Call call, IOException e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(Call call, Response response) throws IOException {
|
||||
Logger.d(response.body().string());
|
||||
FoodMenu menu = new Gson().fromJson(response.body().string(), FoodMenu.class);
|
||||
menus.add(menu);
|
||||
}
|
||||
});
|
||||
@Override
|
||||
public void onResponse(Call call, Response response) throws IOException {
|
||||
String json = response.body().string();
|
||||
try {
|
||||
FoodMenu menu = new Gson().fromJson(json, FoodMenu.class);
|
||||
if (!menu.getImage_url().equals("0")) {
|
||||
menus.add(menu);
|
||||
// Logger.d(menu);
|
||||
}
|
||||
}catch (Exception e){
|
||||
// Logger.e(json);
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
// MessageUtils.MakeToast("您当前拍摄的食材没有录入服务器");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -82,7 +82,7 @@ public class RecipeActivity extends BaseActivity {
|
||||
proteinText.setText(new Double(recommendFood.getMenu().getElements().getProtein()).intValue() + "克");
|
||||
fatText.setText(new Double(recommendFood.getMenu().getElements().getFat()).intValue() + "克");
|
||||
sugerText.setText(new Double(recommendFood.getMenu().getElements().getCarbohydrate()).intValue() + "克");
|
||||
Logger.d(recommendFood.getMenu().getPractice());
|
||||
// Logger.d(recommendFood.getMenu().getPractice());
|
||||
initList();
|
||||
initBMB();
|
||||
}
|
||||
|
||||
@@ -1,10 +1,21 @@
|
||||
package com.example.ninefourone.nutritionmaster.modules.classifyresult;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
|
||||
import com.example.ninefourone.nutritionmaster.R;
|
||||
import com.example.ninefourone.nutritionmaster.adapter.MaterialResultAdapter;
|
||||
import com.example.ninefourone.nutritionmaster.adapter.MaterialResultHolder;
|
||||
import com.example.ninefourone.nutritionmaster.base.BaseActivity;
|
||||
import com.example.ninefourone.nutritionmaster.bean.ClassifyResult;
|
||||
import com.example.ninefourone.nutritionmaster.bean.FoodMenu;
|
||||
import com.example.ninefourone.nutritionmaster.bean.Material;
|
||||
import com.orhanobut.logger.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
@@ -14,7 +25,9 @@ public class MaterialResultActivity extends BaseActivity {
|
||||
|
||||
@BindView(R.id.recycler_view)
|
||||
RecyclerView recyclerView;
|
||||
|
||||
ArrayList<ClassifyResult> classifyResults;
|
||||
ArrayList<FoodMenu> list;
|
||||
private MaterialResultAdapter adapter;
|
||||
|
||||
@Override
|
||||
public int getLayoutId() {
|
||||
@@ -23,7 +36,13 @@ public class MaterialResultActivity extends BaseActivity {
|
||||
|
||||
@Override
|
||||
public void initViews(Bundle savedInstanceState) {
|
||||
|
||||
Intent intent = getIntent();
|
||||
classifyResults = (ArrayList<ClassifyResult>) intent.getSerializableExtra("LIST");
|
||||
list = classifyResults.get(0).getFoodMaterial().getMenus();
|
||||
adapter = new MaterialResultAdapter(list, MaterialResultActivity.this);
|
||||
recyclerView.setAdapter(adapter);
|
||||
recyclerView.setNestedScrollingEnabled(false);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(MaterialResultActivity.this));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -157,8 +157,8 @@ public class CalculateUtils {
|
||||
map.put("suger", suger.intValue());
|
||||
map.put("fat", fat.intValue());
|
||||
map.put("protein", protein.intValue());
|
||||
Logger.d(elementsBean);
|
||||
Logger.d(map.toString());
|
||||
// Logger.d(elementsBean);
|
||||
// Logger.d(map.toString());
|
||||
return map;
|
||||
}
|
||||
|
||||
@@ -171,7 +171,7 @@ public class CalculateUtils {
|
||||
public static ArrayList<String> getStepArray(String whole) {
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
String[] array = whole.split("'");
|
||||
Logger.d(Arrays.toString(array));
|
||||
// Logger.d(Arrays.toString(array));
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
if (array[i].equals("[") || array[i].equals("]") || array[i].equals(", ") ||
|
||||
array[i].equals(",")||array[i].equals(" ")) {
|
||||
@@ -180,7 +180,7 @@ public class CalculateUtils {
|
||||
list.add(array[i]);
|
||||
}
|
||||
}
|
||||
Logger.d(Arrays.toString(list.toArray()));
|
||||
// Logger.d(Arrays.toString(list.toArray()));
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/recycler_view"
|
||||
android:background="#ededed"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
|
||||
32
app/src/main/res/layout/material_result_item.xml
Normal file
32
app/src/main/res/layout/material_result_item.xml
Normal file
@@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="100dp"
|
||||
android:background="#fff"
|
||||
android:layout_margin="5dp"
|
||||
android:id="@+id/whole_layout"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<android.support.v7.widget.CardView
|
||||
android:layout_width="90dp"
|
||||
android:layout_height="90dp"
|
||||
android:layout_gravity="center_vertical"
|
||||
app:cardCornerRadius="10dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/image"
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="100dp"
|
||||
android:scaleType="centerCrop" />
|
||||
</android.support.v7.widget.CardView>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/name"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="15dp"
|
||||
android:text="哈哈哈"
|
||||
android:textSize="15sp" />
|
||||
|
||||
</LinearLayout>
|
||||
@@ -1,46 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/recommend_item_big_height"
|
||||
android:layout_margin="@dimen/recommend_margin"
|
||||
app:cardElevation="0dp"
|
||||
app:cardCornerRadius="20dp">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/whole_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/recommend_item_imageview"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="3"
|
||||
android:scaleType="centerCrop"
|
||||
tools:src="@drawable/food_test" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/recommend_item_title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
android:textSize="13sp"
|
||||
android:background="#f3f9de"
|
||||
android:textStyle="bold"
|
||||
tools:text="红烧肉" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
</android.support.v7.widget.CardView>
|
||||
Reference in New Issue
Block a user