1
This commit is contained in:
@@ -6,8 +6,11 @@ import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.example.ninefourone.nutritionmaster.NutritionMaster;
|
||||
import com.example.ninefourone.nutritionmaster.R;
|
||||
import com.example.ninefourone.nutritionmaster.bean.ClassifyResult;
|
||||
import com.example.ninefourone.nutritionmaster.modules.classifyresult.DishResultActivity;
|
||||
import com.example.ninefourone.nutritionmaster.utils.CalculateUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -26,6 +29,7 @@ public class ResultListAdapter extends RecyclerView.Adapter<ResultListHolder> {
|
||||
super();
|
||||
mList = list;
|
||||
this.context = context;
|
||||
mList = CalculateUtils.getDishQuantity(mList, NutritionMaster.user);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -37,7 +41,7 @@ public class ResultListAdapter extends RecyclerView.Adapter<ResultListHolder> {
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(ResultListHolder holder, int position) {
|
||||
holder.bindView(mList.get(position), pickerLayoutManager);
|
||||
holder.bindView(mList.get(position), pickerLayoutManager, (DishResultActivity) context, position);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package com.example.ninefourone.nutritionmaster.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.widget.LinearSnapHelper;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.SnapHelper;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
@@ -9,6 +11,9 @@ import android.widget.TextView;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.example.ninefourone.nutritionmaster.R;
|
||||
import com.example.ninefourone.nutritionmaster.bean.ClassifyResult;
|
||||
import com.example.ninefourone.nutritionmaster.modules.classifyresult.DishResultActivity;
|
||||
import com.example.ninefourone.nutritionmaster.utils.ConstantUtils;
|
||||
import com.example.ninefourone.nutritionmaster.utils.MessageUtils;
|
||||
import com.github.siyamed.shapeimageview.CircularImageView;
|
||||
|
||||
import butterknife.BindView;
|
||||
@@ -27,6 +32,7 @@ public class ResultListHolder extends RecyclerView.ViewHolder {
|
||||
@BindView(R.id.picker)
|
||||
RecyclerView picker;
|
||||
|
||||
private PickerAdapter pickerAdapter;
|
||||
private Context context;
|
||||
|
||||
public ResultListHolder(View itemView) {
|
||||
@@ -35,11 +41,30 @@ public class ResultListHolder extends RecyclerView.ViewHolder {
|
||||
context = itemView.getContext();
|
||||
}
|
||||
|
||||
public void bindView(ClassifyResult classifyResult, PickerLayoutManager pickerLayoutManager) {
|
||||
public void bindView(ClassifyResult classifyResult, PickerLayoutManager pickerLayoutManager,
|
||||
final DishResultActivity dishResultActivity,final int position) {
|
||||
pickerLayoutManager.setChangeAlpha(true);
|
||||
pickerLayoutManager.setScaleDownBy(0.99f);
|
||||
pickerLayoutManager.setScaleDownDistance(0.8f);
|
||||
picker.setLayoutManager(pickerLayoutManager);
|
||||
SnapHelper snapHelper = new LinearSnapHelper();
|
||||
snapHelper.attachToRecyclerView(picker);
|
||||
pickerAdapter = new PickerAdapter(ConstantUtils.dishPicerData, context);
|
||||
picker.setAdapter(pickerAdapter);
|
||||
picker.setNestedScrollingEnabled(false);
|
||||
picker.scrollToPosition(48);
|
||||
picker.smoothScrollBy(10, 0);
|
||||
|
||||
pickerLayoutManager.setOnScrollStopListener(new PickerLayoutManager.onScrollStopListener() {
|
||||
@Override
|
||||
public void selectedView(View view) {
|
||||
String text = ((TextView) view).getText().toString();
|
||||
// MessageUtils.MakeToast(text);
|
||||
dishResultActivity.refreshData(Integer.valueOf(text),position);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
name.setText(classifyResult.getName());
|
||||
Glide.with(context).load("http://s2.boohee.cn/house/food_big/big_photo20155149534910631.jpg").into(image);
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import com.example.ninefourone.nutritionmaster.utils.ConstantUtils;
|
||||
import com.orhanobut.logger.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import butterknife.BindView;
|
||||
|
||||
@@ -32,7 +33,8 @@ public class DishResultActivity extends BaseActivity {
|
||||
TextView protein;
|
||||
@BindView(R.id.ok_button)
|
||||
Button okButton;
|
||||
// private ResultList results;
|
||||
|
||||
|
||||
private ArrayList<ClassifyResult> results;
|
||||
private ResultListAdapter resultListAdapter;
|
||||
|
||||
@@ -54,7 +56,8 @@ public class DishResultActivity extends BaseActivity {
|
||||
// for (int i = 0; i < results.size(); i++) {
|
||||
// Logger.d(results.get(i));
|
||||
// }
|
||||
resultListAdapter = new ResultListAdapter(ConstantUtils.testData, this);
|
||||
results = ConstantUtils.testData;
|
||||
resultListAdapter = new ResultListAdapter(results, this);
|
||||
recyclerView.setAdapter(resultListAdapter);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(this));
|
||||
}
|
||||
@@ -68,4 +71,30 @@ public class DishResultActivity extends BaseActivity {
|
||||
public void onPointerCaptureChanged(boolean hasCapture) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 能量根据选择的来变
|
||||
*
|
||||
* @param quantity
|
||||
*/
|
||||
public void refreshData(int quantity, int positon) {
|
||||
float calorieSum = 0;
|
||||
float fatSum = 0;
|
||||
float sugarSum = 0;
|
||||
float proteinSum = 0;
|
||||
ClassifyResult temp = results.get(positon);
|
||||
temp.setQuantity(quantity);
|
||||
results.set(positon, temp);
|
||||
for (int i = 0; i < results.size(); i++) {
|
||||
calorieSum += results.get(i).getCalorie() * results.get(i).getQuantity() / 100;
|
||||
fatSum += results.get(i).getCalorie() * results.get(i).getQuantity() / 100;
|
||||
calorieSum += results.get(i).getCalorie() * results.get(i).getQuantity() / 100;
|
||||
calorieSum += results.get(i).getCalorie() * results.get(i).getQuantity() / 100;
|
||||
}
|
||||
calorie.setText((int)calorieSum + "");
|
||||
protein.setText((int)proteinSum + "");
|
||||
fat.setText((int)fatSum + "");
|
||||
suger.setText((int)sugarSum + "");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -288,4 +288,14 @@ public class ConstantUtils {
|
||||
testData.add(classifyResult);
|
||||
}
|
||||
}
|
||||
|
||||
public static ArrayList<String> dishPicerData = new ArrayList<>();
|
||||
|
||||
static {
|
||||
for (int i = 0; i <= 700; i++) {
|
||||
if (i % 2 == 0) {
|
||||
dishPicerData.add(i + "");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/picker_item"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_margin="13dp"
|
||||
android:gravity="center"
|
||||
android:textSize="15sp" />
|
||||
Reference in New Issue
Block a user