diff --git a/app/build.gradle b/app/build.gradle index 6c6609c..ce04b2a 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -78,7 +78,6 @@ dependencies { //picker implementation 'com.contrarywind:Android-PickerView:4.1.6' - //okhttp 网络通信库 implementation 'com.squareup.okhttp3:okhttp:3.11.0' // json解析库 diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index e2f9356..dc01f5b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -57,7 +57,8 @@ + android:label="@string/title_activity_login" /> + \ No newline at end of file diff --git a/app/src/main/java/com/example/ninefourone/nutritionmaster/NutritionMaster.java b/app/src/main/java/com/example/ninefourone/nutritionmaster/NutritionMaster.java index 738d7d5..9846f69 100644 --- a/app/src/main/java/com/example/ninefourone/nutritionmaster/NutritionMaster.java +++ b/app/src/main/java/com/example/ninefourone/nutritionmaster/NutritionMaster.java @@ -6,9 +6,18 @@ import android.os.Bundle; import com.example.ninefourone.nutritionmaster.bean.MyUser; +import com.example.ninefourone.nutritionmaster.bean.Occupation; +import com.example.ninefourone.nutritionmaster.utils.ConstantUtils; +import com.example.ninefourone.nutritionmaster.utils.WebUtils; +import com.google.gson.Gson; import com.orhanobut.logger.AndroidLogAdapter; import com.orhanobut.logger.Logger; +import java.io.IOException; + +import okhttp3.Call; +import okhttp3.Callback; +import okhttp3.Response; /** @@ -70,6 +79,7 @@ public class NutritionMaster extends Application { } }); + initOccupations(); } public static NutritionMaster getInstance() { @@ -94,6 +104,27 @@ public class NutritionMaster extends Application { user.setNickName("ScorpioMiku"); } + /** + * 初始化职业常量 + */ + private void initOccupations() { + + WebUtils.getAllOccupations(new Callback() { + @Override + public void onFailure(Call call, IOException e) { + e.printStackTrace(); + } + + @Override + public void onResponse(Call call, Response response) throws IOException { + Occupation[] occupations = new Gson().fromJson(response.body().string(), Occupation[].class); + for (int i = 0; i < occupations.length; i++) { + ConstantUtils.occupationList.add(occupations[i].getOccupation_name()); + } + } + }); + + } } diff --git a/app/src/main/java/com/example/ninefourone/nutritionmaster/adapter/CardAdapter.java b/app/src/main/java/com/example/ninefourone/nutritionmaster/adapter/CardAdapter.java index a2dd942..70c5404 100644 --- a/app/src/main/java/com/example/ninefourone/nutritionmaster/adapter/CardAdapter.java +++ b/app/src/main/java/com/example/ninefourone/nutritionmaster/adapter/CardAdapter.java @@ -51,13 +51,13 @@ public class CardAdapter extends RecyclerView.Adapter { * 右划 */ public void swipe2Right() { - Logger.d("右划"); +// Logger.d("右划"); } /** * 左划 */ public void swipe2left() { - Logger.d("左划"); +// Logger.d("左划"); } } diff --git a/app/src/main/java/com/example/ninefourone/nutritionmaster/base/BaseActivity.java b/app/src/main/java/com/example/ninefourone/nutritionmaster/base/BaseActivity.java index a65a2b0..336029b 100644 --- a/app/src/main/java/com/example/ninefourone/nutritionmaster/base/BaseActivity.java +++ b/app/src/main/java/com/example/ninefourone/nutritionmaster/base/BaseActivity.java @@ -6,6 +6,7 @@ import android.support.v7.app.AppCompatActivity; import com.example.ninefourone.nutritionmaster.NutritionMaster; import com.example.ninefourone.nutritionmaster.bean.MyUser; +import com.orhanobut.logger.Logger; import butterknife.ButterKnife; import butterknife.Unbinder; @@ -91,4 +92,17 @@ public abstract class BaseActivity extends AppCompatActivity { protected void upUser(MyUser user) { NutritionMaster.user = user; } + + @Override + protected void onResume() { + super.onResume(); + backChangeData(); + } + + /** + * 填写完信息返回Activity调用 + */ + protected void backChangeData() { + + } } diff --git a/app/src/main/java/com/example/ninefourone/nutritionmaster/base/BaseDialog.java b/app/src/main/java/com/example/ninefourone/nutritionmaster/base/BaseDialog.java new file mode 100644 index 0000000..ccb41a6 --- /dev/null +++ b/app/src/main/java/com/example/ninefourone/nutritionmaster/base/BaseDialog.java @@ -0,0 +1,30 @@ +package com.example.ninefourone.nutritionmaster.base; + +import android.content.Context; +import android.support.annotation.NonNull; +import android.support.v7.app.AlertDialog; + +import com.example.ninefourone.nutritionmaster.NutritionMaster; +import com.example.ninefourone.nutritionmaster.bean.MyUser; + +/** + * Created by ScorpioMiku on 2018/10/1. + */ + +public abstract class BaseDialog extends AlertDialog.Builder { + + protected AlertDialog dialog; + + public BaseDialog(@NonNull Context context) { + super(context); + } + + protected void upUser(MyUser user) { + NutritionMaster.user = user; + } + + public void showDialog() { + dialog.show(); + } + +} diff --git a/app/src/main/java/com/example/ninefourone/nutritionmaster/bean/MyUser.java b/app/src/main/java/com/example/ninefourone/nutritionmaster/bean/MyUser.java index 4facf15..acc43bb 100644 --- a/app/src/main/java/com/example/ninefourone/nutritionmaster/bean/MyUser.java +++ b/app/src/main/java/com/example/ninefourone/nutritionmaster/bean/MyUser.java @@ -39,10 +39,19 @@ public class MyUser { private String occupation_name; private List groups; private List user_permissions; + private int age; private float weight = 0; private float height = 0; + public int getAge() { + return age; + } + + public void setAge(int age) { + this.age = age; + } + public float getWeight() { return weight; } @@ -163,6 +172,14 @@ public class MyUser { this.sex = sex; } + public void setSex(String sex) { + if (sex.equals("男")) { + this.sex = 1; + } else { + this.sex = 0; + } + } + public String getOccupation_name() { return occupation_name; } @@ -206,6 +223,10 @@ public class MyUser { ", occupation_name='" + occupation_name + '\'' + ", groups=" + groups + ", user_permissions=" + user_permissions + + ", user_age=" + age + + ", user_sex=" + sex + + ", user_height=" + height + + ", user_weight=" + weight + '}'; } } diff --git a/app/src/main/java/com/example/ninefourone/nutritionmaster/modules/MainActivity.java b/app/src/main/java/com/example/ninefourone/nutritionmaster/modules/MainActivity.java index e7eb436..66e94ef 100644 --- a/app/src/main/java/com/example/ninefourone/nutritionmaster/modules/MainActivity.java +++ b/app/src/main/java/com/example/ninefourone/nutritionmaster/modules/MainActivity.java @@ -29,6 +29,9 @@ import com.example.ninefourone.nutritionmaster.base.BaseActivity; import com.example.ninefourone.nutritionmaster.bean.Occupation; import com.example.ninefourone.nutritionmaster.camera.FoodMaterialCamera; import com.example.ninefourone.nutritionmaster.modules.addinformation.AddActivity; +import com.example.ninefourone.nutritionmaster.modules.addinformation.AddInformationActivity; +import com.example.ninefourone.nutritionmaster.modules.information.InformationActivity; +import com.example.ninefourone.nutritionmaster.ui.InformationDialog; import com.example.ninefourone.nutritionmaster.ui.NoScrollViewPager; import com.example.ninefourone.nutritionmaster.utils.ConstantUtils; import com.example.ninefourone.nutritionmaster.utils.MessageUtils; @@ -52,6 +55,7 @@ import com.mxn.soul.flowingdrawer_core.FlowingDrawer; import com.nightonke.boommenu.BoomButtons.HamButton; import com.nightonke.boommenu.BoomButtons.OnBMClickListener; import com.nightonke.boommenu.BoomMenuButton; +import com.orhanobut.logger.Logger; import java.io.IOException; import java.util.ArrayList; @@ -109,7 +113,6 @@ public class MainActivity extends BaseActivity { @BindView(R.id.show_information) LinearLayout showInformation; - private OptionsPickerView pickerView; @Override public int getLayoutId() { @@ -137,13 +140,12 @@ public class MainActivity extends BaseActivity { // Logger.i("openRatio=" + openRatio + " ,offsetPixels=" + offsetPixels); } }); - initInforView(); - initPicker(); +// initInforView(); initSpiderView(); initViewPager(); initSearchView(); initBMB(); - initOccupations(); +// initOccupations(); } @@ -305,23 +307,6 @@ public class MainActivity extends BaseActivity { } - /** - * 初始化picker - */ - private void initPicker() { - pickerView = new OptionsPickerBuilder(MainActivity.this, new OnOptionsSelectListener() { - @Override - public void onOptionsSelect(int options1, int options2, int options3, View v) { - final int option = options1; - userOccupationText.post(new Runnable() { - @Override - public void run() { - userOccupationText.setText(ConstantUtils.occupationList.get(option)); - } - }); - } - }).build(); - } /** * 初始化悬浮按钮 @@ -349,6 +334,7 @@ public class MainActivity extends BaseActivity { * 初始化个人信息界面(UI) */ private void initInforView() { +// Logger.d(NutritionMaster.user.toString()); adderInfor.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG); if (NutritionMaster.user.getHeight() != 0) { showInformation.setVisibility(View.VISIBLE); @@ -358,13 +344,6 @@ public class MainActivity extends BaseActivity { adderInfor.setVisibility(View.VISIBLE); } - adderInfor.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - - } - }); - } /** @@ -400,36 +379,25 @@ public class MainActivity extends BaseActivity { case R.id.information_layout: break; case R.id.user_occupation_text: - pickerView.show(); + break; case R.id.adder_infor: + Intent i = new Intent(MainActivity.this, AddInformationActivity.class); + startActivity(i); break; } } - /** - * 初始化职业常量 - */ - private void initOccupations() { - if (userOccupationText.getText().equals("请选择您的职业")) { - WebUtils.getAllOccupations(new Callback() { - @Override - public void onFailure(Call call, IOException e) { - e.printStackTrace(); - } - @Override - public void onResponse(Call call, Response response) throws IOException { - Occupation[] occupations = new Gson().fromJson(response.body().string(), Occupation[].class); - for (int i = 0; i < occupations.length; i++) { -// Logger.d(occupations[i].getOccupation_name()); - ConstantUtils.occupationList.add(occupations[i].getOccupation_name()); - } - pickerView.setPicker(ConstantUtils.occupationList); - } - }); + @Override + protected void backChangeData() { + super.backChangeData(); + initInforView(); + if (NutritionMaster.user.getOccupation_name() == null) { + + } else { + userOccupationText.setText("职业: " + NutritionMaster.user.getOccupation_name()); } + } - - } diff --git a/app/src/main/java/com/example/ninefourone/nutritionmaster/modules/addinformation/AddInformationActivity.java b/app/src/main/java/com/example/ninefourone/nutritionmaster/modules/addinformation/AddInformationActivity.java new file mode 100644 index 0000000..d2e0b2b --- /dev/null +++ b/app/src/main/java/com/example/ninefourone/nutritionmaster/modules/addinformation/AddInformationActivity.java @@ -0,0 +1,180 @@ +package com.example.ninefourone.nutritionmaster.modules.addinformation; + +import android.content.Context; +import android.os.Bundle; +import android.view.View; +import android.widget.Button; +import android.widget.ImageView; +import android.widget.TextView; + +import com.bigkoo.pickerview.builder.OptionsPickerBuilder; +import com.bigkoo.pickerview.listener.OnOptionsSelectListener; +import com.bigkoo.pickerview.view.OptionsPickerView; +import com.example.ninefourone.nutritionmaster.NutritionMaster; +import com.example.ninefourone.nutritionmaster.R; +import com.example.ninefourone.nutritionmaster.base.BaseActivity; +import com.example.ninefourone.nutritionmaster.bean.MyUser; +import com.example.ninefourone.nutritionmaster.modules.MainActivity; +import com.example.ninefourone.nutritionmaster.utils.ConstantUtils; +import com.example.ninefourone.nutritionmaster.utils.MessageUtils; + +public class AddInformationActivity extends BaseActivity { + private TextView ageTextView; + private TextView heightTextView; + private TextView weightTextView; + private TextView sexTextView; + private TextView occupationTextView; + + private ImageView ageImageView; + private ImageView sexImageView; + private ImageView heightImageView; + private ImageView weightImageView; + private ImageView occupationImageView; + + private Button okButton; + + private OptionsPickerView agePicker; + private OptionsPickerView weightPicker; + private OptionsPickerView heightPicker; + private OptionsPickerView sexPicker; + private OptionsPickerView occupationPicker; + + private Context context; + + @Override + public int getLayoutId() { + return R.layout.add_information_activity; + } + + @Override + public void initViews(Bundle savedInstanceState) { + + context = this; + ageImageView = findViewById(R.id.age_image_view); + sexImageView = findViewById(R.id.sex_image_view); + heightImageView = findViewById(R.id.height_image_view); + weightImageView = findViewById(R.id.weight_image_view); + occupationImageView = findViewById(R.id.occupation_image_view); + + + ageTextView = findViewById(R.id.age_text_view); + sexTextView = findViewById(R.id.sex_text_view); + weightTextView = findViewById(R.id.weight_text_view); + heightTextView = findViewById(R.id.height_text_view); + occupationTextView = findViewById(R.id.occupation_text_view); + + okButton = findViewById(R.id.ok_button); + + occupationPicker = new OptionsPickerBuilder(context, new OnOptionsSelectListener() { + @Override + public void onOptionsSelect(int options1, int options2, int options3, View v) { + occupationTextView.setText(ConstantUtils.occupationList.get(options1)); + } + }).build(); + occupationPicker.setPicker(ConstantUtils.occupationList); + + agePicker = new OptionsPickerBuilder(context, new OnOptionsSelectListener() { + @Override + public void onOptionsSelect(int options1, int options2, int options3, View v) { + ageTextView.setText(ConstantUtils.ageList.get(options1)); + } + }).build(); + agePicker.setPicker(ConstantUtils.ageList); + agePicker.setSelectOptions(25); + + + sexPicker = new OptionsPickerBuilder(context, new OnOptionsSelectListener() { + @Override + public void onOptionsSelect(int options1, int options2, int options3, View v) { + sexTextView.setText(ConstantUtils.sexList.get(options1)); + } + }).build(); + sexPicker.setPicker(ConstantUtils.sexList); + + + heightPicker = new OptionsPickerBuilder(context, new OnOptionsSelectListener() { + @Override + public void onOptionsSelect(int options1, int options2, int options3, View v) { + heightTextView.setText(ConstantUtils.heightList.get(options1)); + } + }).build(); + heightPicker.setPicker(ConstantUtils.heightList); + heightPicker.setSelectOptions(119); + + weightPicker = new OptionsPickerBuilder(context, new OnOptionsSelectListener() { + @Override + public void onOptionsSelect(int options1, int options2, int options3, View v) { + weightTextView.setText(ConstantUtils.weightList.get(options1)); + } + }).build(); + weightPicker.setPicker(ConstantUtils.weightList); + weightPicker.setSelectOptions(59); + + + occupationImageView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + occupationPicker.show(); + } + }); + + ageImageView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + agePicker.show(); + } + }); + sexImageView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + sexPicker.show(); + } + }); + heightImageView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + heightPicker.show(); + } + }); + weightImageView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + weightPicker.show(); + } + }); + + okButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + MyUser user = NutritionMaster.user; + if (ageTextView.getText().toString().equals("年龄") || weightTextView.getText().toString().equals("体重") + || sexTextView.getText().toString().equals("性别") || heightTextView.getText().toString().equals("身高")|| + occupationTextView.getText().toString().equals("职业")) { + MessageUtils.MakeToast("请点击图片填写所有信息"); + } else { + user.setHeight(Integer.valueOf(heightTextView.getText().toString().split("c")[0])); + user.setWeight(Integer.valueOf(weightTextView.getText().toString().split("k")[0])); + user.setAge(Integer.valueOf(ageTextView.getText().toString().split("岁")[0])); + user.setSex(sexTextView.getText().toString()); + user.setOccupation_name(occupationTextView.getText().toString()); +// Logger.d(user.toString()); + upUser(user); + MessageUtils.MakeToast("信息填写成功"); + finish(); + } + + } + }); + + } + + @Override + public void initToolBar() { + + } + + @Override + public void onPointerCaptureChanged(boolean hasCapture) { + + } +} diff --git a/app/src/main/java/com/example/ninefourone/nutritionmaster/ui/InformationDialog.java b/app/src/main/java/com/example/ninefourone/nutritionmaster/ui/InformationDialog.java new file mode 100644 index 0000000..6b9cf5e --- /dev/null +++ b/app/src/main/java/com/example/ninefourone/nutritionmaster/ui/InformationDialog.java @@ -0,0 +1,128 @@ +package com.example.ninefourone.nutritionmaster.ui; + +import android.content.Context; +import android.support.annotation.NonNull; +import android.view.View; +import android.widget.Button; +import android.widget.ImageView; + + +import android.widget.TextView; + +import com.bigkoo.pickerview.builder.OptionsPickerBuilder; +import com.bigkoo.pickerview.listener.OnOptionsSelectListener; +import com.bigkoo.pickerview.view.OptionsPickerView; +import com.example.ninefourone.nutritionmaster.R; +import com.example.ninefourone.nutritionmaster.base.BaseDialog; +import com.example.ninefourone.nutritionmaster.utils.ConstantUtils; + +/** + * Created by ScorpioMiku on 2018/10/1. + */ + +public class InformationDialog extends BaseDialog { + + + private TextView ageTextView; + private TextView heightTextView; + private TextView weightTextView; + private TextView sexTextView; + + private ImageView ageImageView; + private ImageView sexImageView; + private ImageView heightImageView; + private ImageView weightImageView; + + private Button okButton; + + private OptionsPickerView agePicker; + private OptionsPickerView weightPicker; + private OptionsPickerView heightPicker; + private OptionsPickerView sexPicker; + + + public InformationDialog(@NonNull Context context) { + super(context); + dialog = create(); + + + View view = View.inflate(context, R.layout.add_information_activity, null); + dialog.setView(view); + + ageImageView = view.findViewById(R.id.age_image_view); + sexImageView = view.findViewById(R.id.sex_image_view); + heightImageView = view.findViewById(R.id.height_image_view); + weightImageView = view.findViewById(R.id.weight_image_view); + + + ageTextView = view.findViewById(R.id.age_text_view); + sexTextView = view.findViewById(R.id.sex_text_view); + weightTextView = view.findViewById(R.id.weight_text_view); + heightTextView = view.findViewById(R.id.height_text_view); + + okButton = view.findViewById(R.id.ok_button); + + agePicker = new OptionsPickerBuilder(context, new OnOptionsSelectListener() { + @Override + public void onOptionsSelect(int options1, int options2, int options3, View v) { + ageTextView.setText(ConstantUtils.ageList.get(options1)); + } + }).build(); + agePicker.setPicker(ConstantUtils.ageList); + + + sexPicker = new OptionsPickerBuilder(context, new OnOptionsSelectListener() { + @Override + public void onOptionsSelect(int options1, int options2, int options3, View v) { + sexTextView.setText(ConstantUtils.ageList.get(options1)); + } + }).build(); + sexPicker.setPicker(ConstantUtils.sexList); + + + heightPicker = new OptionsPickerBuilder(context, new OnOptionsSelectListener() { + @Override + public void onOptionsSelect(int options1, int options2, int options3, View v) { + heightTextView.setText(ConstantUtils.ageList.get(options1)); + } + }).build(); + heightPicker.setPicker(ConstantUtils.heightList); + + + weightPicker = new OptionsPickerBuilder(context, new OnOptionsSelectListener() { + @Override + public void onOptionsSelect(int options1, int options2, int options3, View v) { + weightTextView.setText(ConstantUtils.ageList.get(options1)); + } + }).build(); + weightPicker.setPicker(ConstantUtils.weightList); + + + ageImageView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + agePicker.show(); + } + }); + sexImageView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + sexPicker.show(); + } + }); + heightImageView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + heightPicker.show(); + } + }); + weightImageView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + weightPicker.show(); + } + }); + + + } +} diff --git a/app/src/main/java/com/example/ninefourone/nutritionmaster/utils/ConstantUtils.java b/app/src/main/java/com/example/ninefourone/nutritionmaster/utils/ConstantUtils.java index daa6229..8468b4c 100644 --- a/app/src/main/java/com/example/ninefourone/nutritionmaster/utils/ConstantUtils.java +++ b/app/src/main/java/com/example/ninefourone/nutritionmaster/utils/ConstantUtils.java @@ -54,4 +54,26 @@ public class ConstantUtils { public static ArrayList occupationList = new ArrayList<>(); + public static ArrayList ageList = new ArrayList<>(); + + public static ArrayList sexList = new ArrayList<>(); + + public static ArrayList heightList = new ArrayList<>(); + + public static ArrayList weightList = new ArrayList<>(); + + static { + for (int i = 1; i <= 200; i++) { + if (i < 100) { + ageList.add(i + "岁"); + } + heightList.add(i + 50 + "cm"); + if (i < 150) { + weightList.add(i + "kg"); + } + } + sexList.add("男"); + sexList.add("女"); + } + } diff --git a/app/src/main/res/drawable/ic_dialog_age.xml b/app/src/main/res/drawable/ic_dialog_age.xml new file mode 100644 index 0000000..a3f5f27 --- /dev/null +++ b/app/src/main/res/drawable/ic_dialog_age.xml @@ -0,0 +1,11 @@ + + + + + + + + + + diff --git a/app/src/main/res/drawable/ic_dialog_sex.xml b/app/src/main/res/drawable/ic_dialog_sex.xml new file mode 100644 index 0000000..ab68bd5 --- /dev/null +++ b/app/src/main/res/drawable/ic_dialog_sex.xml @@ -0,0 +1,9 @@ + + + + + + + + diff --git a/app/src/main/res/drawable/ic_occupation.xml b/app/src/main/res/drawable/ic_occupation.xml new file mode 100644 index 0000000..4319ce9 --- /dev/null +++ b/app/src/main/res/drawable/ic_occupation.xml @@ -0,0 +1,11 @@ + + + + + + + + + + diff --git a/app/src/main/res/layout/activity_add_information.xml b/app/src/main/res/layout/activity_add_information.xml new file mode 100644 index 0000000..a37234e --- /dev/null +++ b/app/src/main/res/layout/activity_add_information.xml @@ -0,0 +1,9 @@ + + + + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 1eca8ff..415ffc5 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -167,7 +167,7 @@ android:layout_width="wrap_content" android:layout_height="20dp" android:gravity="center" - android:text="请选择您的职业" + android:text="请完善信息" android:textColor="#FFF" /> diff --git a/app/src/main/res/layout/add_information_activity.xml b/app/src/main/res/layout/add_information_activity.xml new file mode 100644 index 0000000..49565ba --- /dev/null +++ b/app/src/main/res/layout/add_information_activity.xml @@ -0,0 +1,136 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +