1
This commit is contained in:
@@ -6,6 +6,7 @@ import android.os.Bundle;
|
||||
|
||||
import com.example.ninefourone.nutritionmaster.bean.Element;
|
||||
import com.example.ninefourone.nutritionmaster.bean.FoodMenu;
|
||||
import com.example.ninefourone.nutritionmaster.bean.Illness;
|
||||
import com.example.ninefourone.nutritionmaster.bean.MyUser;
|
||||
|
||||
import com.example.ninefourone.nutritionmaster.bean.Occupation;
|
||||
@@ -45,7 +46,7 @@ public class NutritionMaster extends Application {
|
||||
public static Physique physique = null;
|
||||
public static Occupation occupation = null;
|
||||
public static Element element = null;
|
||||
|
||||
public static Illness illness = null;
|
||||
|
||||
|
||||
@Override
|
||||
|
||||
@@ -54,4 +54,8 @@ public class HomePagerAdapter extends FragmentPagerAdapter {
|
||||
public CharSequence getPageTitle(int position) {
|
||||
return TITLES[position];
|
||||
}
|
||||
|
||||
public void rereshUI() {
|
||||
((BodyInformationFragment) fragments[1]).refreshUI();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,6 +158,35 @@ public class Element implements Cloneable {
|
||||
}
|
||||
|
||||
|
||||
public Element(Illness.ElementsBean elementsBean) {
|
||||
calorie = elementsBean.getCalorie();
|
||||
carbohydrate = elementsBean.getCarbohydrate();
|
||||
fat = elementsBean.getFat();
|
||||
protein = elementsBean.getProtein();
|
||||
cellulose = elementsBean.getCellulose();
|
||||
vitaminA = elementsBean.getVitaminA();
|
||||
vitaminB1 = elementsBean.getVitaminB1();
|
||||
vitaminB2 = elementsBean.getVitaminB2();
|
||||
vitaminB6 = elementsBean.getVitaminB6();
|
||||
vitaminC = elementsBean.getVitaminC();
|
||||
vitaminE = elementsBean.getVitaminE();
|
||||
carotene = elementsBean.getCarotene();
|
||||
cholesterol = elementsBean.getCholesterol();
|
||||
Mg = elementsBean.getMg();
|
||||
Ca = elementsBean.getCa();
|
||||
Fe = elementsBean.getFe();
|
||||
Zn = elementsBean.getZn();
|
||||
Cu = elementsBean.getCu();
|
||||
Mn = elementsBean.getMn();
|
||||
K = elementsBean.getK();
|
||||
P = elementsBean.getP();
|
||||
Na = elementsBean.getNa();
|
||||
Se = elementsBean.getSe();
|
||||
niacin = elementsBean.getNiacin();
|
||||
thiamine = elementsBean.getThiamine();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ElementsBean{" +
|
||||
|
||||
@@ -42,7 +42,7 @@ public class MyUser {
|
||||
private Boolean is_staff;
|
||||
private Boolean is_active;
|
||||
private String date_joined;
|
||||
private Integer sex;
|
||||
private Integer sex = 1;
|
||||
private Integer age;
|
||||
private Integer height;
|
||||
private Integer weight;
|
||||
|
||||
@@ -30,6 +30,7 @@ import com.example.ninefourone.nutritionmaster.R;
|
||||
import com.example.ninefourone.nutritionmaster.adapter.HomePagerAdapter;
|
||||
import com.example.ninefourone.nutritionmaster.adapter.IllAdapter;
|
||||
import com.example.ninefourone.nutritionmaster.base.BaseActivity;
|
||||
import com.example.ninefourone.nutritionmaster.bean.Illness;
|
||||
import com.example.ninefourone.nutritionmaster.camera.ClassifierCamera;
|
||||
import com.example.ninefourone.nutritionmaster.modules.addinformation.AddInformationActivity;
|
||||
import com.example.ninefourone.nutritionmaster.modules.addinformation.AddPhysiqueActivity;
|
||||
@@ -50,6 +51,7 @@ import com.github.mikephil.charting.data.RadarDataSet;
|
||||
import com.github.mikephil.charting.data.RadarEntry;
|
||||
import com.github.mikephil.charting.formatter.IndexAxisValueFormatter;
|
||||
import com.github.siyamed.shapeimageview.CircularImageView;
|
||||
import com.google.gson.Gson;
|
||||
import com.miguelcatalan.materialsearchview.MaterialSearchView;
|
||||
import com.mxn.soul.flowingdrawer_core.ElasticDrawer;
|
||||
import com.mxn.soul.flowingdrawer_core.FlowingDrawer;
|
||||
@@ -58,12 +60,16 @@ import com.nightonke.boommenu.BoomButtons.OnBMClickListener;
|
||||
import com.nightonke.boommenu.BoomMenuButton;
|
||||
import com.orhanobut.logger.Logger;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.OnClick;
|
||||
import okhttp3.Call;
|
||||
import okhttp3.Callback;
|
||||
import okhttp3.Response;
|
||||
|
||||
|
||||
public class MainActivity extends BaseActivity {
|
||||
@@ -130,6 +136,7 @@ public class MainActivity extends BaseActivity {
|
||||
private ArrayList<String> userIllness = new ArrayList<>();
|
||||
private IllAdapter illAdapter;
|
||||
|
||||
private HomePagerAdapter homePagerAdapter;
|
||||
|
||||
@Override
|
||||
public int getLayoutId() {
|
||||
@@ -146,6 +153,7 @@ public class MainActivity extends BaseActivity {
|
||||
public void onDrawerStateChange(int oldState, int newState) {
|
||||
if (newState == ElasticDrawer.STATE_CLOSED) {
|
||||
titleLayout.setBackgroundColor(getColor(R.color.colorPrimary));
|
||||
homePagerAdapter.rereshUI();
|
||||
} else {
|
||||
titleLayout.setBackgroundColor(getColor(R.color.bar_open));
|
||||
}
|
||||
@@ -167,7 +175,7 @@ public class MainActivity extends BaseActivity {
|
||||
* 初始化ViewPager
|
||||
*/
|
||||
private void initViewPager() {
|
||||
HomePagerAdapter homePagerAdapter = new HomePagerAdapter(getSupportFragmentManager(),
|
||||
homePagerAdapter = new HomePagerAdapter(getSupportFragmentManager(),
|
||||
this);
|
||||
viewPager.setOffscreenPageLimit(3);
|
||||
viewPager.setAdapter(homePagerAdapter);
|
||||
@@ -362,7 +370,7 @@ public class MainActivity extends BaseActivity {
|
||||
private void initInforView() {
|
||||
|
||||
adderInfor.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);
|
||||
changeInformation.getPaint().setFlags(Paint. UNDERLINE_TEXT_FLAG );
|
||||
changeInformation.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);
|
||||
if (NutritionMaster.user.getHeight() != 0) {
|
||||
showInformation.setVisibility(View.VISIBLE);
|
||||
adderInfor.setVisibility(View.INVISIBLE);
|
||||
@@ -395,7 +403,7 @@ public class MainActivity extends BaseActivity {
|
||||
*/
|
||||
|
||||
@OnClick({R.id.navigation_layout, R.id.add_information_button, R.id.information_layout,
|
||||
R.id.user_occupation_text, R.id.adder_infor,R.id.change_information})
|
||||
R.id.user_occupation_text, R.id.adder_infor, R.id.change_information})
|
||||
public void onViewClicked(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.navigation_layout:
|
||||
@@ -537,17 +545,67 @@ public class MainActivity extends BaseActivity {
|
||||
*/
|
||||
@OnClick(R.id.ill_button)
|
||||
public void onViewClicked() {
|
||||
illPicker = new OptionsPickerBuilder(MainActivity.this, new OnOptionsSelectListener() {
|
||||
@Override
|
||||
public void onOptionsSelect(int options1, int options2, int options3, View v) {
|
||||
userIllness.add(illness.get(options1));
|
||||
illAdapter.notifyDataSetChanged();
|
||||
illButton.setBackgroundResource(0);
|
||||
}
|
||||
}).build();
|
||||
illPicker.setPicker(illness);
|
||||
illPicker.show();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
// if (NutritionMaster.occupation==null||NutritionMaster.illness==null){
|
||||
// illButton.setOnClickListener(new View.OnClickListener() {
|
||||
// @Override
|
||||
// public void onClick(View v) {
|
||||
// MessageUtils.MakeToast("请先填写职业信息和体质信息再使用");
|
||||
// }
|
||||
// });
|
||||
// }else{
|
||||
illButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
illPicker = new OptionsPickerBuilder(MainActivity.this, new OnOptionsSelectListener() {
|
||||
@Override
|
||||
public void onOptionsSelect(int options1, int options2, int options3, View v) {
|
||||
final String illname = illness.get(options1);
|
||||
getWebUtil().getIllness(illname, 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();
|
||||
Illness illness = new Gson().fromJson(json, Illness.class);
|
||||
NutritionMaster.illness = illness;
|
||||
Logger.d(NutritionMaster.illness);
|
||||
if (NutritionMaster.physique != null && NutritionMaster.occupation != null) {
|
||||
Thread thread = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
illRecyclerView.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
userIllness.add(illname);
|
||||
illAdapter.notifyDataSetChanged();
|
||||
illAdapter.notifyDataSetChanged();
|
||||
if (NutritionMaster.occupation != null && NutritionMaster.physique != null) {
|
||||
NutritionMaster.element = CalculateUtils.getElementsAddIllness(NutritionMaster.illness,
|
||||
NutritionMaster.user, NutritionMaster.occupation, NutritionMaster.physique);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
thread.start();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}).build();
|
||||
illPicker.setPicker(illness);
|
||||
illPicker.show();
|
||||
}
|
||||
});
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -389,6 +389,9 @@ public class AddPhysiqueActivity extends BaseActivity {
|
||||
}
|
||||
}
|
||||
physique = physiques[maxIndex];
|
||||
if (physique.equals("淤血质")) {
|
||||
physique = "瘀血质";
|
||||
}
|
||||
Logger.d(Arrays.toString(counter) + "\n" + physique);
|
||||
Physique phy = new Physique();
|
||||
phy.setPhysical_name(physique);
|
||||
|
||||
@@ -206,7 +206,7 @@ public class BodyInformationFragment extends BaseFragment {
|
||||
/**
|
||||
* 更新数据
|
||||
*/
|
||||
private void refreshUI() {
|
||||
public void refreshUI() {
|
||||
if (NutritionMaster.user.getBmi() != -1) {
|
||||
weightText.post(new Runnable() {
|
||||
@Override
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.example.ninefourone.nutritionmaster.utils;
|
||||
import com.example.ninefourone.nutritionmaster.bean.ClassifyResult;
|
||||
import com.example.ninefourone.nutritionmaster.bean.Element;
|
||||
import com.example.ninefourone.nutritionmaster.bean.FoodMenu;
|
||||
import com.example.ninefourone.nutritionmaster.bean.Illness;
|
||||
import com.example.ninefourone.nutritionmaster.bean.MyUser;
|
||||
import com.example.ninefourone.nutritionmaster.bean.Occupation;
|
||||
import com.example.ninefourone.nutritionmaster.bean.Physique;
|
||||
@@ -194,20 +195,33 @@ public class CalculateUtils {
|
||||
Element userElement = new Element(user);
|
||||
Element occupationElement = new Element(occupation.getElements());
|
||||
Element physiqueElement = new Element(physique.getElements());
|
||||
occupationElement.add(physiqueElement, 2);
|
||||
userElement.add(occupationElement, -1);
|
||||
physiqueElement.add(occupationElement, 2);
|
||||
userElement.add(physiqueElement, -1);
|
||||
return userElement;
|
||||
}
|
||||
|
||||
public static Element getElementsByOccupation(MyUser user, Occupation occupation) {
|
||||
Element userElement = new Element(user);
|
||||
Element occupationElement = new Element(occupation.getElements());
|
||||
userElement.add(occupationElement, -1);
|
||||
return userElement;
|
||||
}
|
||||
|
||||
public static Element getElementsByPhysique(MyUser user, Physique physique) {
|
||||
Element userElement = new Element(user);
|
||||
Element physiqueElement = new Element(physique.getElements());
|
||||
userElement.add(physiqueElement, -1);
|
||||
return userElement;
|
||||
}
|
||||
|
||||
public static Element getElementsAddIllness(Illness illness, MyUser user, Occupation occupation, Physique physique) {
|
||||
Element userElement = new Element(user);
|
||||
Element occupationElement = new Element(occupation.getElements());
|
||||
Element illnessElement = new Element(occupation.getElements());
|
||||
Element physiqueElement = new Element(physique.getElements());
|
||||
physiqueElement.add(occupationElement, 2);
|
||||
physiqueElement.add(illnessElement, 1);
|
||||
userElement.add(physiqueElement, -1);
|
||||
return userElement;
|
||||
}
|
||||
}
|
||||
|
||||
7
app/src/main/res/drawable/ic_ill_add_button.xml
Normal file
7
app/src/main/res/drawable/ic_ill_add_button.xml
Normal file
@@ -0,0 +1,7 @@
|
||||
<vector android:height="24dp" android:viewportHeight="1024.0"
|
||||
android:viewportWidth="1024.0" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="#ffffff" android:pathData="M596.8,277.8c-45.2,-63 -132.8,-77.2 -195.8,-32s-77.2,132.8 -32,195.8 132.8,77.4 195.8,32.2c63,-45.4 77.4,-133.2 32,-196zM585.2,616c-33,23.6 -40.6,69.6 -16.8,102.6s69.8,40.4 102.6,16.8c33,-23.6 40.6,-69.6 16.8,-102.6 -23.8,-33.2 -69.6,-40.6 -102.6,-16.8zM293.4,584.4c-40.6,29.2 -49.8,85.6 -20.6,126.2 29.2,40.6 85.6,49.8 126.2,20.6 40.6,-29.2 49.8,-85.8 20.6,-126.2 -29.2,-40.6 -85.8,-49.8 -126.2,-20.6zM713.2,460.8c-16.2,11.6 -19.8,34 -8.2,50.2 11.6,16.2 34,19.8 50.2,8.2 16.2,-11.6 19.8,-34 8.2,-50.2 -11.6,-16 -34,-19.8 -50.2,-8.2z"/>
|
||||
<path android:fillColor="#ffffff" android:pathData="M518.6,798m-25,0a25,25 0,1 0,50 0,25 25,0 1,0 -50,0Z"/>
|
||||
<path android:fillColor="#ffffff" android:pathData="M193.6,469.8c-13.2,9.6 -16.4,28 -6.8,41.4 9.6,13.2 28.2,16.4 41.4,6.8 13.2,-9.6 16.4,-28.2 6.8,-41.4 -9.6,-13.4 -28.2,-16.4 -41.4,-6.8zM724.6,276.2c9,-6.6 11.2,-19.2 4.6,-28.4 -6.6,-9 -19.2,-11.2 -28.4,-4.6s-11.2,19.2 -4.6,28.4 19.2,11.2 28.4,4.6z"/>
|
||||
<path android:fillColor="#ffffff" android:pathData="M982.6,472.8l-44,-0.2c-4.4,-45 -15.8,-88.2 -33.2,-128l53.2,-30.8v-0.2c0.4,-0.2 0.6,-0.4 1,-0.4 19.8,-11.6 26.6,-36.8 15.2,-56.6 -11.6,-19.8 -36.8,-26.6 -56.6,-15.2 -0.4,0.2 -0.6,0.4 -0.8,0.6l-52,30c-28.4,-41 -63.8,-76.8 -104.2,-105.8L789,118h-0.2c11.4,-19.8 4.6,-45 -15.2,-56.4 -19.8,-11.4 -45.2,-4.6 -56.6,15.2 -0.2,0.2 -0.2,0.6 -0.4,0.8l-27.4,47.6c-43,-19.4 -89.6,-32 -138.6,-36.2L550.6,42.6C550.6,19.6 532,1.2 509.2,1.2c-22.8,0 -41.4,18.6 -41.4,41.4v47c-45.8,4.8 -89.4,17 -129.6,35.2l-27.6,-48c-11.6,-19.8 -36.8,-26.6 -56.6,-15.2 -19.8,11.6 -26.6,36.8 -15.2,56.6L266.4,166C226.8,194.2 192,228.8 164,268.6l-45.6,-26.4c-19.8,-11.4 -45.2,-4.6 -56.6,15.2 -11.4,19.8 -4.6,45.2 15.2,56.6l46,26.6c-18.4,41 -30.4,85.4 -35.2,132L41,472.6v0.6C18.4,473.4 0,491.8 0,514.6 0,537.6 18.6,556 41.4,556c1.8,0 3.4,-0.2 5,-0.4L88,555.6c4,42.2 14.2,82.6 29.6,120.4l-50.6,29.2c-19.8,11.6 -26.6,36.8 -15.2,56.6 11.6,19.8 36.8,26.6 56.6,15.2L156,749.2c24,36.6 53.6,69.2 87.4,97l-32.6,56.4c-11.4,19.8 -4.6,45.2 15.2,56.6 19.8,11.4 45.2,4.6 56.6,-15.2l29.8,-51.8c47,25.2 99.6,41.8 155.2,47.6v44.4h0.4c1.6,21.4 19.2,38.4 41,38.4s39.4,-17 41,-38.4h0.4v-43.8c57.4,-5 111.6,-21.2 160.2,-46.6l28.8,50c11.6,19.8 36.8,26.6 56.6,15.2 19.8,-11.6 26.6,-36.8 15.2,-56.6l-31,-54c34.2,-27.4 64.4,-60 88.8,-96.6l48,27.6v-0.2c0.4,0.2 0.4,0.4 0.8,0.6 19.8,11.4 45.2,4.6 56.6,-15.2 11.4,-19.8 4.6,-45.2 -15.2,-56.6 -0.4,-0.2 -0.6,-0.2 -1,-0.4v-0.2l-50.4,-29c16.2,-38.6 26.6,-79.8 30.8,-123.2h44c23,0 41.4,-18.6 41.4,-41.4 0,-22.4 -18.6,-41 -41.4,-41zM513.2,884.8c-204.4,0 -370,-165.6 -370,-370 0,-57 13,-111.2 36.2,-159.4l28.4,-49.2c66.6,-97.4 178.6,-161.4 305.4,-161.4 204.4,0 370,165.6 370,370 0.2,204.2 -165.6,370 -370,370z"/>
|
||||
</vector>
|
||||
@@ -179,17 +179,6 @@
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/ill_button"
|
||||
android:layout_width="120dp"
|
||||
android:layout_height="150dp"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_alignParentRight="true"
|
||||
android:alpha="0.3"
|
||||
android:background="@drawable/ic_ill"
|
||||
android:orientation="vertical">
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<ImageView
|
||||
android:layout_width="120dp"
|
||||
@@ -199,6 +188,17 @@
|
||||
android:alpha="0.2"
|
||||
android:src="@drawable/icon_black" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/ill_button"
|
||||
android:layout_width="30dp"
|
||||
android:layout_height="30dp"
|
||||
android:layout_marginTop="15dp"
|
||||
android:layout_marginRight="10dp"
|
||||
android:layout_toLeftOf="@id/add_information_button"
|
||||
android:background="@drawable/ic_ill_add_button"
|
||||
android:orientation="vertical">
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/add_information_button"
|
||||
|
||||
Reference in New Issue
Block a user