This commit is contained in:
ScorpioMiku
2018-10-07 14:08:14 +08:00
parent 74e6d23cd6
commit e424d14565
11 changed files with 168 additions and 108 deletions

View File

@@ -39,17 +39,17 @@ public class RecommendAdapter extends BaseMultiItemQuickAdapter<RecommendFood, B
@Override
protected void convert(BaseViewHolder helper, RecommendFood item) {
ImageView imageView = helper.getView(R.id.recommend_item_imageview);
Glide.with(mContext).load(R.drawable.food_test).into(imageView);
Glide.with(mContext).load(item.getPicture()).into(imageView);
switch (item.getItemType()) {
case RecommendFood.TYPE_BIG:
helper.setText(R.id.recommend_item_title, "红烧肉");
helper.setText(R.id.recommend_item_title, item.getTitle());
break;
case RecommendFood.TYPE_DETAIL:
helper.setText(R.id.recommend_item_title, item.getTitle());
helper.setText(R.id.recommend_item_description, item.getDescription());
break;
case RecommendFood.TYPE_MIDDLE:
helper.setText(R.id.recommend_item_title, "红烧");
helper.setText(R.id.recommend_item_title, item.getTitle());
break;
}
View view = helper.getView(R.id.whole_layout);

View File

@@ -37,6 +37,7 @@ public abstract class BaseFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle state) {
webUtil = WebUtil.getInstance();
parentView = inflater.inflate(getLayoutResId(), container, false);
activity = getSupportActivity();
return parentView;
@@ -47,7 +48,6 @@ public abstract class BaseFragment extends Fragment {
super.onViewCreated(view, savedInstanceState);
unbinder = ButterKnife.bind(this, view);
initView(savedInstanceState);
webUtil = WebUtil.getInstance();
this.user = NutritionMaster.user;
}

View File

@@ -1,44 +0,0 @@
package com.example.ninefourone.nutritionmaster.bean;
import java.util.ArrayList;
/**
* Created by ScorpioMiku on 2018/9/9.
*/
public class Menu {
private String menuName;
private ArrayList<Material> materialArrayList;
private ArrayList<String> makeSteps;
public Menu(String menuName, ArrayList<Material> materialArrayList, ArrayList<String> makeSteps) {
this.menuName = menuName;
this.materialArrayList = materialArrayList;
this.makeSteps = makeSteps;
}
public String getMenuName() {
return menuName;
}
public void setMenuName(String menuName) {
this.menuName = menuName;
}
public ArrayList<Material> getMaterialArrayList() {
return materialArrayList;
}
public void setMaterialArrayList(ArrayList<Material> materialArrayList) {
this.materialArrayList = materialArrayList;
}
public ArrayList<String> getMakeSteps() {
return makeSteps;
}
public void setMakeSteps(ArrayList<String> makeSteps) {
this.makeSteps = makeSteps;
}
}

View File

@@ -47,7 +47,7 @@ public class MyUser {
private Integer height;
private Integer weight;
private Integer bmi = new Integer(-1);
private String occupation_name;
private String occupation_name = "";
private List<?> groups;
private List<?> user_permissions;
private List<?> illness;

View File

@@ -16,35 +16,32 @@ public class RecommendFood implements MultiItemEntity, Serializable {
public static final int TYPE_MIDDLE = 1;
public static final int TYPE_DETAIL = 2;
private int picture;
private String picture;
private String title;
private String description;
private int type;
private Menu menu;
private FoodMenu menu;
public Menu getMenu() {
public FoodMenu getMenu() {
return menu;
}
public void setMenu(Menu menu) {
public void setMenu(FoodMenu menu) {
this.menu = menu;
}
public RecommendFood(int picture, String title, String description, int type) {
this.picture = picture;
this.title = title;
this.description = description;
public RecommendFood(FoodMenu foodMenu, int type) {
menu = foodMenu;
picture = foodMenu.getImage_url();
title = foodMenu.getName();
this.type = type;
if (type > 2) {
Logger.e("混合recycler type不对");
}
}
public int getPicture() {
public String getPicture() {
return picture;
}
public void setPicture(int picture) {
public void setPicture(String picture) {
this.picture = picture;
}

View File

@@ -10,11 +10,8 @@ import com.example.ninefourone.nutritionmaster.adapter.MakeStepAdapter;
import com.example.ninefourone.nutritionmaster.adapter.MaterialAdapter;
import com.example.ninefourone.nutritionmaster.base.BaseActivity;
import com.example.ninefourone.nutritionmaster.bean.Material;
import com.example.ninefourone.nutritionmaster.bean.Menu;
import com.example.ninefourone.nutritionmaster.bean.RecommendFood;
import com.example.ninefourone.nutritionmaster.utils.UiUtils;
import com.github.lzyzsd.circleprogress.ArcProgress;
import com.orhanobut.logger.Logger;
import java.util.ArrayList;
@@ -34,7 +31,7 @@ public class RecipeActivity extends BaseActivity {
@BindView(R.id.detail_way_recycler_view)
RecyclerView detailWayRecyclerView;
private RecommendFood recommendFood;
private Menu menu;
private MaterialAdapter materialAdapter;
private MakeStepAdapter makeStepAdapter;
@@ -67,25 +64,25 @@ public class RecipeActivity extends BaseActivity {
}
private void initList() {
ArrayList<Material> list = new ArrayList<>();
for (int i = 0; i < 7; i++) {
Material material = new Material("毛豆", 100);
list.add(material);
}
ArrayList<String> mList = new ArrayList<>();
for (int i = 0; i < 7; i++) {
String step = "第一步";
mList.add(step);
}
menu = new Menu("毛豆炒肉", list, mList);
makeStepAdapter = new MakeStepAdapter(menu.getMakeSteps(), this);
detailWayRecyclerView.setAdapter(makeStepAdapter);
detailWayRecyclerView.setLayoutManager(new LinearLayoutManager(this));
materialAdapter = new MaterialAdapter(menu.getMaterialArrayList(), this);
materialRecyclerView.setAdapter(materialAdapter);
materialRecyclerView.setLayoutManager(new LinearLayoutManager(this));
// ArrayList<Material> list = new ArrayList<>();
// for (int i = 0; i < 7; i++) {
// Material material = new Material("毛豆", 100);
// list.add(material);
// }
// ArrayList<String> mList = new ArrayList<>();
// for (int i = 0; i < 7; i++) {
// String step = "第一步";
// mList.add(step);
// }
//
//
// makeStepAdapter = new MakeStepAdapter(menu.getMakeSteps(), this);
// detailWayRecyclerView.setAdapter(makeStepAdapter);
// detailWayRecyclerView.setLayoutManager(new LinearLayoutManager(this));
//
// materialAdapter = new MaterialAdapter(menu.getMaterialArrayList(), this);
// materialRecyclerView.setAdapter(materialAdapter);
// materialRecyclerView.setLayoutManager(new LinearLayoutManager(this));
}
}

View File

@@ -9,14 +9,19 @@ import android.view.View;
import android.view.ViewGroup;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.example.ninefourone.nutritionmaster.NutritionMaster;
import com.example.ninefourone.nutritionmaster.R;
import com.example.ninefourone.nutritionmaster.adapter.RecommendAdapter;
import com.example.ninefourone.nutritionmaster.base.BaseFragment;
import com.example.ninefourone.nutritionmaster.bean.FoodMenu;
import com.example.ninefourone.nutritionmaster.bean.RecommendFood;
import com.example.ninefourone.nutritionmaster.bean.Trick;
import com.google.gson.Gson;
import com.orhanobut.logger.Logger;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import android.view.LayoutInflater;
@@ -49,8 +54,8 @@ public class RecommendFragment extends BaseFragment {
@Override
public void initView(Bundle state) {
loadData();
initRecyclerView();
loadData();
}
@@ -129,10 +134,60 @@ public class RecommendFragment extends BaseFragment {
@Override
protected void loadData() {
super.loadData();
for (int i = 0; i < 11; i++) {
int flag = indexs[i % 4];
RecommendFood recommendFood = new RecommendFood(1, "烧肉", "好吃", flag);
datas.add(recommendFood);
if (NutritionMaster.user.getOccupation_name().equals("")) {
getWebUtil().getRandomMenus(20, new Callback() {
@Override
public void onFailure(Call call, IOException e) {
}
@Override
public void onResponse(Call call, Response response) throws IOException {
FoodMenu[] menus = new Gson().fromJson(response.body().string(), FoodMenu[].class);
int count = 0;
for (int i = 0; i < menus.length; i++) {
if (count > 11) {
break;
} else {
int flag = indexs[count % 4];
RecommendFood recommendFood = new RecommendFood(menus[i], flag);
if (!recommendFood.getPicture().equals("0")) {
datas.add(recommendFood);
count++;
}
}
}
/**
* 获取小知识
*/
getWebUtil().getRandomTricks(3, new Callback() {
@Override
public void onFailure(Call call, IOException e) {
}
@Override
public void onResponse(Call call, Response response) throws IOException {
Trick[] tricks = new Gson().fromJson(response.body().string(), Trick[].class);
int index = 0;
for (int i = 0; i < datas.size(); i++) {
if (datas.get(i).getItemType() == RecommendFood.TYPE_DETAIL) {
datas.get(i).setDescription(tricks[index].getContent());
datas.get(i).setTitle(tricks[index].getTitle());
index++;
}
}
recyclerView.post(new Runnable() {
@Override
public void run() {
adapter.notifyDataSetChanged();
}
});
}
});
}
});
}
}
@@ -140,12 +195,62 @@ public class RecommendFragment extends BaseFragment {
* 加载新数据
*/
private void addData() {
for (int i = 0; i < 7; i++) {
int flag = indexs[i % 4];
RecommendFood recommendFood = new RecommendFood(1, "烧肉", "好吃", flag);
adapter.getData().add(recommendFood);
if (NutritionMaster.user.getOccupation_name().equals("")) {
getWebUtil().getRandomMenus(20, new Callback() {
@Override
public void onFailure(Call call, IOException e) {
}
@Override
public void onResponse(Call call, Response response) throws IOException {
final int originsize = datas.size();
FoodMenu[] menus = new Gson().fromJson(response.body().string(), FoodMenu[].class);
int count = 0;
for (int i = 0; i < menus.length; i++) {
if (count > 7) {
break;
} else {
int flag = indexs[count % 4];
RecommendFood recommendFood = new RecommendFood(menus[i], flag);
if (!recommendFood.getPicture().equals("0")) {
datas.add(recommendFood);
count++;
}
}
}
/**
* 获取小知识
*/
getWebUtil().getRandomTricks(3, new Callback() {
@Override
public void onFailure(Call call, IOException e) {
}
@Override
public void onResponse(Call call, Response response) throws IOException {
Trick[] tricks = new Gson().fromJson(response.body().string(), Trick[].class);
int index = 0;
for (int i = originsize; i < datas.size(); i++) {
if (datas.get(i).getItemType() == RecommendFood.TYPE_DETAIL) {
datas.get(i).setDescription(tricks[index].getContent());
datas.get(i).setTitle(tricks[index].getTitle());
index++;
}
}
recyclerView.post(new Runnable() {
@Override
public void run() {
adapter.loadMoreComplete();
}
});
}
});
}
});
}
adapter.loadMoreComplete();
}
/**

View File

@@ -75,7 +75,7 @@ public class CalculateUtils {
// Logger.d( calendar.get(Calendar.DAY_OF_WEEK));
// calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
int week = calendar.get(Calendar.DAY_OF_WEEK) - 1;
Logger.d(week);
// Logger.d(week);
if (week == 0) {
return 7;
}

View File

@@ -25,7 +25,7 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0"
android:layout_weight="1"
android:orientation="vertical">
<TextView
@@ -33,7 +33,8 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:textSize="15sp"
android:textSize="13sp"
android:background="#f3f9de"
android:textStyle="bold"
tools:text="红烧肉" />

View File

@@ -11,9 +11,9 @@
<android.support.v7.widget.CardView
android:layout_width="@dimen/recommend_item_default_hight"
android:layout_height="@dimen/recommend_item_default_hight"
app:cardElevation="0dp"
android:layout_marginRight="5dp"
app:cardCornerRadius="20dp">
app:cardCornerRadius="20dp"
app:cardElevation="0dp">
<ImageView
android:id="@+id/recommend_item_imageview"
@@ -29,23 +29,25 @@
android:layout_marginLeft="5dp"
app:cardCornerRadius="20dp">
<LinearLayout
android:background="#dcffe1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#f3f9de"
android:orientation="vertical"
android:paddingBottom="15dp"
android:paddingBottom="5dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="15dp">
android:paddingTop="5dp">
<TextView
android:id="@+id/recommend_item_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="15sp"
android:textStyle="bold"
tools:text="红烧肉" />
android:gravity="center_horizontal"
android:text="小知识"
android:textSize="13sp"
android:textStyle="bold" />
<TextView
android:id="@+id/recommend_item_description"
@@ -55,5 +57,6 @@
android:textSize="12sp"
tools:text="红烧肉是最美味的菜了!超级好吃!" />
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>

View File

@@ -27,7 +27,7 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0"
android:layout_weight="1"
android:orientation="vertical">
<TextView
@@ -35,8 +35,9 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:textSize="14sp"
android:textSize="13sp"
android:textStyle="bold"
android:background="#f3f9de"
tools:text="红烧肉" />
</LinearLayout>