|
|
@@ -2,31 +2,55 @@ package com.uas.appme.pedometer.view;
|
|
|
|
|
|
import android.content.Intent;
|
|
|
import android.os.Bundle;
|
|
|
-import android.widget.Toast;
|
|
|
+import android.util.Log;
|
|
|
+import android.view.Gravity;
|
|
|
+import android.view.LayoutInflater;
|
|
|
+import android.view.Menu;
|
|
|
+import android.view.MenuItem;
|
|
|
+import android.view.View;
|
|
|
+import android.widget.Button;
|
|
|
+import android.widget.LinearLayout;
|
|
|
+import android.widget.PopupWindow;
|
|
|
+import android.widget.TextView;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.common.LogUtil;
|
|
|
+import com.common.data.DateFormatUtil;
|
|
|
+import com.common.data.ListUtils;
|
|
|
import com.common.data.StringUtil;
|
|
|
+import com.common.system.DisplayUtil;
|
|
|
import com.core.app.MyApplication;
|
|
|
import com.core.base.BaseActivity;
|
|
|
+import com.core.utils.CommonUtil;
|
|
|
+import com.core.utils.TimeUtils;
|
|
|
import com.me.network.app.http.HttpClient;
|
|
|
import com.me.network.app.http.Method;
|
|
|
import com.me.network.app.http.rx.ResultListener;
|
|
|
import com.me.network.app.http.rx.ResultSubscriber;
|
|
|
import com.uas.appme.R;
|
|
|
+import com.uas.appme.pedometer.bean.PersonalStepBean;
|
|
|
import com.uas.appme.pedometer.constant.Constant;
|
|
|
+import com.uas.appme.pedometer.utils.TimeUtil;
|
|
|
+
|
|
|
+import java.text.DecimalFormat;
|
|
|
|
|
|
/**
|
|
|
* Created by FANGlh on 2017/9/21.
|
|
|
* function:
|
|
|
*/
|
|
|
|
|
|
-public class PersonalPageActivity extends BaseActivity {
|
|
|
+public class PersonalPageActivity extends BaseActivity implements View.OnClickListener{
|
|
|
|
|
|
private String title;
|
|
|
private String userid;
|
|
|
private String em_name;
|
|
|
private int type;
|
|
|
+ private TextView mMovementTotalKmTv;
|
|
|
+ private TextView mMovementTotalKmTimeTv;
|
|
|
+ private TextView mMovementTotalStepsTv;
|
|
|
+ private TextView mMovementTotalStepsTimeTv;
|
|
|
+ private PersonalStepBean mPersonalStepBean;
|
|
|
+ private Button mbtnAttention;
|
|
|
|
|
|
@Override
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
@@ -37,29 +61,171 @@ public class PersonalPageActivity extends BaseActivity {
|
|
|
initData();
|
|
|
}
|
|
|
|
|
|
+
|
|
|
private void initView() {
|
|
|
Intent intent = getIntent();
|
|
|
title = intent.getStringExtra("title");
|
|
|
userid = intent.getStringExtra("userid");
|
|
|
em_name = intent.getStringExtra("em_name");
|
|
|
- type = intent.getIntExtra("type",-1);
|
|
|
+ type = intent.getIntExtra("type", -1);
|
|
|
getSupportActionBar().setTitle(title);
|
|
|
+
|
|
|
+ LogUtil.i("userid",userid);
|
|
|
+ mMovementTotalKmTv = (TextView) findViewById(R.id.movement_total_km_tv);
|
|
|
+ mMovementTotalKmTimeTv = (TextView) findViewById(R.id.movement_total_km_time_tv);
|
|
|
+ mMovementTotalStepsTv = (TextView) findViewById(R.id.movement_total_steps_tv);
|
|
|
+ mMovementTotalStepsTimeTv = (TextView) findViewById(R.id.movement_total_steps_time_tv);
|
|
|
+ mbtnAttention = (Button) findViewById(R.id.btn_attention);
|
|
|
+ mbtnAttention.setOnClickListener(this);
|
|
|
+ mPersonalStepBean = new PersonalStepBean();
|
|
|
+
|
|
|
+ if (type == 3) // type 1、2 我、已关注的人
|
|
|
+ mbtnAttention.setVisibility(View.VISIBLE);
|
|
|
+ else
|
|
|
+ mbtnAttention.setVisibility(View.GONE);
|
|
|
}
|
|
|
|
|
|
private void initData() {
|
|
|
+ if (!CommonUtil.isNetWorkConnected(this)) {
|
|
|
+ ToastMessage(getString(R.string.common_notlinknet));
|
|
|
+ return;
|
|
|
+ }
|
|
|
if (StringUtil.isEmpty(userid)) return;
|
|
|
- HttpClient httpClient = new HttpClient.Builder(Constant.BASE_STEP_URL).build();
|
|
|
+ HttpClient httpClient = new HttpClient.Builder(Constant.BASE_STEP_URL).isDebug(true).build(true);
|
|
|
httpClient.Api().send(new HttpClient.Builder()
|
|
|
.url("appSteps")
|
|
|
- .add("userid",userid)
|
|
|
- .add("token",MyApplication.getInstance().mAccessToken)
|
|
|
+ .add("userid", userid)
|
|
|
+ .add("token", MyApplication.getInstance().mAccessToken)
|
|
|
.method(Method.GET)
|
|
|
- .build(),new ResultSubscriber<>(new ResultListener<Object>() {
|
|
|
+ .build(), new ResultSubscriber<>(new ResultListener<Object>() {
|
|
|
@Override
|
|
|
public void onResponse(Object o) {
|
|
|
- LogUtil.prinlnLongMsg("appSteps", JSON.toJSONString(o)+"");
|
|
|
- Toast.makeText(MyApplication.getInstance(),JSON.toJSONString(o)+"",Toast.LENGTH_LONG).show();
|
|
|
+ LogUtil.prinlnLongMsg("appSteps", o.toString());
|
|
|
+ mPersonalStepBean = JSON.parseObject(o.toString(),PersonalStepBean.class);
|
|
|
+ showStepsInfo(); }
|
|
|
+ }));
|
|
|
+ }
|
|
|
+
|
|
|
+ private void showStepsInfo() {
|
|
|
+ if (mPersonalStepBean == null || ListUtils.isEmpty(mPersonalStepBean.getWeekSteps())) return;
|
|
|
+ int weekSteps_size = mPersonalStepBean.getWeekSteps().size();
|
|
|
+ int monthSteps_size = mPersonalStepBean.getMonthSteps().size();
|
|
|
+ String curDate = TimeUtils.s_long_2_str(DateFormatUtil.str2Long(TimeUtil.getCurrentDate(), "yyyy年MM月dd日"));
|
|
|
+ String curSteps = "";
|
|
|
+ Log.i("curDate",curDate);
|
|
|
+ for (int i = 0; i < monthSteps_size; i++) {
|
|
|
+ if (mPersonalStepBean.getWeekSteps().get(i).getAs_date().equals(curDate)){
|
|
|
+ curSteps = mPersonalStepBean.getMonthSteps().get(i).getAs_uusteps();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ mMovementTotalStepsTv.setText(curSteps);
|
|
|
+ mMovementTotalKmTv.setText(countTotalKM(CommonUtil.getNumByString(curSteps)));
|
|
|
+
|
|
|
+ String now_time = TimeUtil.getWeekStr(TimeUtil.getCurrentDate());
|
|
|
+ mMovementTotalKmTimeTv.setText(now_time);
|
|
|
+ mMovementTotalStepsTimeTv.setText(now_time);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void doAttendHandle(int attention_type) {
|
|
|
+ HttpClient httpClient = new HttpClient.Builder(Constant.BASE_STEP_URL).isDebug(true).build(true);
|
|
|
+ httpClient.Api().send(new HttpClient.Builder()
|
|
|
+ .url("appUUSet")
|
|
|
+ .add("userids", userid)
|
|
|
+ .add("id",MyApplication.getInstance().mLoginUser.getUserId())
|
|
|
+ .add("type", attention_type)
|
|
|
+ .add("token", MyApplication.getInstance().mAccessToken)
|
|
|
+ .method(Method.POST)
|
|
|
+ .build(), new ResultSubscriber<>(new ResultListener<Object>() {
|
|
|
+ @Override
|
|
|
+ public void onResponse(Object o) {
|
|
|
+ LogUtil.prinlnLongMsg("appUUSet", o.toString());
|
|
|
+ finish();
|
|
|
}
|
|
|
}));
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean onCreateOptionsMenu(Menu menu) {
|
|
|
+ getMenuInflater().inflate(R.menu.menu_outoffice, menu);
|
|
|
+ return super.onCreateOptionsMenu(menu);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
+ if (item.getItemId() == R.id.title) {
|
|
|
+ showPopupWindow();
|
|
|
+ }
|
|
|
+ return super.onOptionsItemSelected(item);
|
|
|
+ }
|
|
|
+ private PopupWindow setWindow = null;//
|
|
|
+ private void showPopupWindow() {
|
|
|
+ if (setWindow == null) initPopupWindow();
|
|
|
+ setWindow.showAtLocation(getWindow().getDecorView().
|
|
|
+ findViewById(android.R.id.content), Gravity.BOTTOM, 0, 0);
|
|
|
+ DisplayUtil.backgroundAlpha(this, 0.4f);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void initPopupWindow() {
|
|
|
+ View viewContext = LayoutInflater.from(ct).inflate(R.layout.step_person_page_setting, null);
|
|
|
+ if (type == 1){ //自己
|
|
|
+ viewContext.findViewById(R.id.share_friend_tv).setVisibility(View.VISIBLE);
|
|
|
+ viewContext.findViewById(R.id.share_monments_tv).setVisibility(View.VISIBLE);
|
|
|
+ }else if (type == 2){ //关注的人
|
|
|
+ viewContext.findViewById(R.id.cancel_attention_tv).setVisibility(View.VISIBLE);
|
|
|
+ }else if (type == 3){ //普通好友
|
|
|
+ viewContext.findViewById(R.id.not_rankingwith_tv).setVisibility(View.VISIBLE);
|
|
|
+ }
|
|
|
+
|
|
|
+ viewContext.findViewById(R.id.share_friend_tv).setOnClickListener(this);
|
|
|
+ viewContext.findViewById(R.id.share_monments_tv).setOnClickListener(this);
|
|
|
+ viewContext.findViewById(R.id.cancel_attention_tv).setOnClickListener(this);
|
|
|
+ viewContext.findViewById(R.id.not_rankingwith_tv).setOnClickListener(this);
|
|
|
+
|
|
|
+ setWindow = new PopupWindow(viewContext,
|
|
|
+ LinearLayout.LayoutParams.MATCH_PARENT,
|
|
|
+ LinearLayout.LayoutParams.WRAP_CONTENT, true);
|
|
|
+ setWindow.setAnimationStyle(R.style.MenuAnimationFade);
|
|
|
+ setWindow.setBackgroundDrawable(mContext.getResources().getDrawable(R.drawable.bg_popuwin));
|
|
|
+ setWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
|
|
|
+ @Override
|
|
|
+ public void onDismiss() {
|
|
|
+ closePopupWindow();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ private void closePopupWindow() {
|
|
|
+ if (setWindow != null)
|
|
|
+ setWindow.dismiss();
|
|
|
+ DisplayUtil.backgroundAlpha(this, 1f);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 简易计算公里数,假设一步大约有0.7米
|
|
|
+ *
|
|
|
+ * @param steps 用户当前步数
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private String countTotalKM(int steps) {
|
|
|
+ DecimalFormat df = new DecimalFormat("#.##");
|
|
|
+ double totalMeters = steps * 0.7;
|
|
|
+ //保留两位有效数字
|
|
|
+ return df.format(totalMeters / 1000);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ if (v.getId() == R.id.btn_attention){
|
|
|
+ doAttendHandle(1);
|
|
|
+ }else if (v.getId() == R.id.cancel_attention_tv){
|
|
|
+ doAttendHandle(0);
|
|
|
+ }else if (v.getId() == R.id.share_friend_tv){
|
|
|
+ ToastMessage("share_friend_tv");
|
|
|
+ }else if (v.getId() == R.id.share_monments_tv){
|
|
|
+ ToastMessage("share_monments_tv");
|
|
|
+ }else if (v.getId() == R.id.not_rankingwith_tv){
|
|
|
+ ToastMessage("not_rankingwith_tv");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
}
|