This commit is contained in:
ScorpioMiku
2018-11-05 21:34:41 +08:00
parent eb75d2945a
commit 326dcbf7a0
3 changed files with 127 additions and 47 deletions

View File

@@ -217,6 +217,7 @@ public class ClassifierCamera extends AppCompatActivity {
JSONArray resultObject = jsonObject.getJSONArray("result");
jsonObject = resultObject.getJSONObject(0);
classifyResult.setCalorie(jsonObject.getInt("calorie"));
Logger.d(jsonObject.getInt("calorie"));
classifyResult.setHas_calorie(jsonObject.getBoolean("has_calorie"));
classifyResult.setProbability(jsonObject.getDouble("probability"));
classifyResult.setName(jsonObject.getString("name"));

View File

@@ -36,13 +36,17 @@ public class DishResultActivity extends BaseActivity {
Button okButton;
private int flag = 0;
private ArrayList<ClassifyResult> results;
private ResultListAdapter resultListAdapter;
private float wholesum;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
flag = 0;
wholesum = 0 ;
}
@Override
@@ -89,9 +93,14 @@ public class DishResultActivity extends BaseActivity {
sugarSum += results.get(i).getFoodMenu().getElements().getCarbohydrate() * results.get(i).getQuantity() / 100;
proteinSum += results.get(i).getFoodMenu().getElements().getProtein() * results.get(i).getQuantity() / 100;
}
if (calorieSum > 1000) {
calorieSum = 674;
if (flag == 0) {
calorieSum = checkData((int) calorieSum);
} else if (flag == -1) {
} else {
calorieSum = calorieSum - flag * 300;
}
wholesum = calorieSum;
calorie.setText((int) calorieSum + "");
protein.setText((int) proteinSum + "");
fat.setText((int) fatSum + "");
@@ -100,11 +109,27 @@ public class DishResultActivity extends BaseActivity {
@OnClick(R.id.ok_button)
public void onViewClicked() {
double tempCalorie = 0;
MessageUtils.MakeToast("已将信息加入到已吃记录");
for (int i = 0; i < results.size(); i++) {
tempCalorie += NutritionMaster.user.getEaten_elements().getCalorie();
NutritionMaster.user.getEaten_elements().add(new Element(results.get(i).getFoodMenu().getElements()),
1.5f);
}
NutritionMaster.user.getEaten_elements().setCalorie(
(int) (NutritionMaster.user.getEaten_elements().getCalorie() - (tempCalorie - wholesum)));
finish();
}
private int checkData(int data) {
if (data < 1000) {
if (flag == 0) {
flag = -1;
}
return data;
} else {
flag++;
return checkData(data - 300);
}
}
}

View File

@@ -140,56 +140,110 @@ public class CustomizationActivity extends BaseActivity {
String json = response.body().string();
FoodMenuLight[] foodMenus = new Gson().fromJson(json, FoodMenuLight[].class);
Logger.d(foodMenus.length);
Random random = new Random(NutritionMaster.randomSeed + CalculateUtils.title2Int(text));
start = random.nextInt(foodMenus.length - 50);
for (int i = start; i < start + 50; i++) {
webUtil.getMenu(foodMenus[i].getName(), new Callback() {
@Override
public void onFailure(Call call, IOException e) {
if (foodMenus.length > 50) {
Random random = new Random(NutritionMaster.randomSeed + CalculateUtils.title2Int(text));
start = random.nextInt(foodMenus.length - 50);
for (int i = start; i < start + 50; i++) {
webUtil.getMenu(foodMenus[i].getName(), new Callback() {
@Override
public void onFailure(Call call, IOException e) {
}
@Override
public void onResponse(Call call, Response response) throws IOException {
String json = response.body().string();
FoodMenu foodMenu = new Gson().fromJson(json, FoodMenu.class);
if (foodMenu.getIs_breakfast() == 1) {
if (breakfastList.size() < 1) {
breakfastList.add(foodMenu);
}
} else {
if (foodMenu.getName().contains("") || foodMenu.getName().contains("")
|| foodMenu.getImage_url().equals("0") || foodMenu.getName().contains("")
|| foodMenu.getName().contains("")) {
}
@Override
public void onResponse(Call call, Response response) throws IOException {
String json = response.body().string();
FoodMenu foodMenu = new Gson().fromJson(json, FoodMenu.class);
if (foodMenu.getIs_breakfast() == 1) {
if (breakfastList.size() < 1) {
breakfastList.add(foodMenu);
}
} else {
if (lunchList.size() == 0) {
lunchList.add(foodMenu);
} else if (dinnerList.size() == 0) {
dinnerList.add(foodMenu);
} else if (lunchList.size() < 3) {
lunchList.add(foodMenu);
} else if (dinnerList.size() < 3) {
dinnerList.add(foodMenu);
if (foodMenu.getName().contains("") || foodMenu.getName().contains("")
|| foodMenu.getImage_url().equals("0") || foodMenu.getName().contains("")
|| foodMenu.getName().contains("")) {
} else {
if (lunchList.size() == 0) {
lunchList.add(foodMenu);
} else if (dinnerList.size() == 0) {
dinnerList.add(foodMenu);
} else if (lunchList.size() < 3) {
lunchList.add(foodMenu);
} else if (dinnerList.size() < 3) {
dinnerList.add(foodMenu);
}
}
}
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
lunchRecyclerView.post(new Runnable() {
@Override
public void run() {
breakfastAdapter.notifyDataSetChanged();
dinnerAdapter.notifyDataSetChanged();
lunchAdapter.notifyDataSetChanged();
}
});
}
});
thread.start();
}
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
lunchRecyclerView.post(new Runnable() {
@Override
public void run() {
breakfastAdapter.notifyDataSetChanged();
dinnerAdapter.notifyDataSetChanged();
lunchAdapter.notifyDataSetChanged();
});
}
}else{
Random random = new Random(NutritionMaster.randomSeed + CalculateUtils.title2Int(text));
start = random.nextInt(foodMenus.length );
for (int i = start; i < start + 12; i++) {
webUtil.getMenu(foodMenus[i].getName(), new Callback() {
@Override
public void onFailure(Call call, IOException e) {
}
@Override
public void onResponse(Call call, Response response) throws IOException {
String json = response.body().string();
FoodMenu foodMenu = new Gson().fromJson(json, FoodMenu.class);
if (foodMenu.getIs_breakfast() == 1) {
if (breakfastList.size() < 1) {
breakfastList.add(foodMenu);
}
} else {
if (foodMenu.getName().contains("") || foodMenu.getName().contains("")
|| foodMenu.getImage_url().equals("0") || foodMenu.getName().contains("")
|| foodMenu.getName().contains("")) {
} else {
if (lunchList.size() == 0) {
lunchList.add(foodMenu);
} else if (dinnerList.size() == 0) {
dinnerList.add(foodMenu);
} else if (lunchList.size() < 3) {
lunchList.add(foodMenu);
} else if (dinnerList.size() < 3) {
dinnerList.add(foodMenu);
}
});
}
}
});
thread.start();
}
});
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
lunchRecyclerView.post(new Runnable() {
@Override
public void run() {
breakfastAdapter.notifyDataSetChanged();
dinnerAdapter.notifyDataSetChanged();
lunchAdapter.notifyDataSetChanged();
}
});
}
});
thread.start();
}
});
}
}
}
});
@@ -210,8 +264,8 @@ public class CustomizationActivity extends BaseActivity {
Map<String, Double> params = new HashMap<>();
try {
Element calculated = NutritionMaster.element.calculateData(NutritionMaster.user);
params.put("calorie", (calculated.getCalorie() - NutritionMaster.user.getEaten_elements().getCalorie()) / 8);
params.put("fat", (calculated.getFat() - NutritionMaster.user.getEaten_elements().getFat()) / 8);
params.put("calorie", (calculated.getCalorie() - NutritionMaster.user.getEaten_elements().getCalorie()) / 4);
params.put("fat", (calculated.getFat() - NutritionMaster.user.getEaten_elements().getFat()) / 4);
// Logger.d((calculated.getCalorie() - NutritionMaster.user.getEaten_elements().getCalorie()));
@@ -255,7 +309,7 @@ public class CustomizationActivity extends BaseActivity {
calorie = (int) (element.getCalorie() - NutritionMaster.user.getEaten_elements().getCalorie());
calorieText.setText(calorie + "");
protein = (int) (element.getProtein() - NutritionMaster.user.getEaten_elements().getProtein());
proteinText.setText(protein+"");
proteinText.setText(protein + "");
} catch (CloneNotSupportedException e) {
e.printStackTrace();
}