Blame view
app/src/main/java/com/dinhcv/lifelogpedometer/activity/TopDateFragment.java
11 KB
7f095a929
|
1 2 3 4 5 |
package com.dinhcv.lifelogpedometer.activity; import android.app.DatePickerDialog; import android.content.Context; import android.content.Intent; |
7f095a929
|
6 7 |
import android.os.Bundle; import android.support.annotation.Nullable; |
7f095a929
|
8 9 10 11 12 13 14 15 16 17 18 |
import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.DatePicker; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; import com.dinhcv.lifelogpedometer.R; import com.dinhcv.lifelogpedometer.adapter.NoticeAdapter; import com.dinhcv.lifelogpedometer.customview.ExpandableListCustomView; |
7f095a929
|
19 |
import com.dinhcv.lifelogpedometer.interfaces.LLAPIManagerListener; |
7f095a929
|
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
import com.dinhcv.lifelogpedometer.model.structure.home.NoticeInfo; import com.dinhcv.lifelogpedometer.model.structure.home.TagetInfo; import com.dinhcv.lifelogpedometer.portal.LLAPIManager; import com.dinhcv.lifelogpedometer.utils.Const; import com.dinhcv.lifelogpedometer.utils.Debug; import com.dinhcv.lifelogpedometer.utils.Utils; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import java.util.List; |
0c1f9bf91
|
35 |
public class TopDateFragment extends FragmentBase implements SettingFragmentPresenter { |
7f095a929
|
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
private TextView tvDate; private TextView tvStep; private TextView tvRemain; private TextView tvRateDone; private ImageView ivBack; private ImageView ivNext; private LinearLayout llBike; private LinearLayout llWalking; private LinearLayout llRunning; private Date mAnaDate; private Calendar mCalendar; private int mAnaDay; private int mAnaMonth; private int mAnaYear; private Context mContext; private Const.STEP_TYPE stepType; private TagetInfo mTagetInfo = new TagetInfo(); |
0c1f9bf91
|
58 |
private ImageView ivToDay; |
7f095a929
|
59 60 |
private ExpandableListCustomView lvNotice; private NoticeAdapter mNoticeAdapter; |
0c1f9bf91
|
61 62 63 64 65 66 |
private View mRootview; private TopFragment mTopFragment; public void setRootFragment(TopFragment frag) { this.mTopFragment = frag; } |
7f095a929
|
67 68 69 70 71 |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment |
0c1f9bf91
|
72 |
mRootview = inflater.inflate(R.layout.fragment_top_date, container, false); |
7f095a929
|
73 |
mContext = getActivity(); |
0c1f9bf91
|
74 |
initView(mRootview); |
7f095a929
|
75 |
initData(); |
0c1f9bf91
|
76 |
return mRootview; |
7f095a929
|
77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
} private void initView(View rootView) { tvDate = (TextView) rootView.findViewById(R.id.tv_date); tvStep = (TextView) rootView.findViewById(R.id.tv_step); tvRemain = (TextView) rootView.findViewById(R.id.tv_remainingStep); tvRateDone = (TextView) rootView.findViewById(R.id.tv_completeRate); ivBack = (ImageView) rootView.findViewById(R.id.iv_back); ivNext = (ImageView) rootView.findViewById(R.id.iv_next); llBike = (LinearLayout) rootView.findViewById(R.id.ll_bike); llWalking = (LinearLayout) rootView.findViewById(R.id.ll_walking); llRunning = (LinearLayout) rootView.findViewById(R.id.ll_running); |
0c1f9bf91
|
91 |
ivToDay = (ImageView) rootView.findViewById(R.id.iv_toDay); |
7f095a929
|
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
lvNotice = (ExpandableListCustomView) rootView.findViewById(R.id.lv_notice); handleEvent(); } private void handleEvent(){ tvDate.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { handleAnaDatePicker(); } }); ivBack.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { mCalendar = Calendar.getInstance(); mCalendar.setTime(mAnaDate); mCalendar.add(Calendar.DAY_OF_MONTH, -1); Date date = mCalendar.getTime(); tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(date)); mAnaDate = date; getHomePage(mAnaDate, stepType); } }); ivNext.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { mCalendar = Calendar.getInstance(); mCalendar.setTime(mAnaDate); mCalendar.add(Calendar.DAY_OF_MONTH, +1); Date date = mCalendar.getTime(); tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(date)); mAnaDate = date; getHomePage(mAnaDate, stepType); } }); llWalking.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { stepType = Const.STEP_TYPE.WALKING; updateUiStepType(false, true, false); // add data getHomePage(mAnaDate, stepType); } }); llRunning.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { stepType = Const.STEP_TYPE.RUNNING; updateUiStepType(false, false, true); // add getHomePage(mAnaDate, stepType); } }); llBike.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { stepType = Const.STEP_TYPE.BIKE; updateUiStepType(true, false, false); // add data getHomePage(mAnaDate, stepType); } }); |
0c1f9bf91
|
161 162 163 164 165 166 |
ivToDay.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { mTopFragment.showDetailFragment(); } }); |
7f095a929
|
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 |
} private void updateUiStepType(boolean b1, boolean b2, boolean b3) { llBike.setSelected(b1); llWalking.setSelected(b2); llRunning.setSelected(b3); } /** * Show date picker dialog */ private void handleAnaDatePicker() { new DatePickerDialog(getActivity(), new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { mCalendar = Calendar.getInstance(); mCalendar.set(year, monthOfYear, dayOfMonth); mAnaYear = year; mAnaMonth = monthOfYear; mAnaDay = dayOfMonth; Date date = mCalendar.getTime(); tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(date)); mAnaDate = date; getHomePage(mAnaDate, stepType); } }, mAnaYear, mAnaMonth, mAnaDay).show(); } /** * init data for */ private void initData() { mCalendar = Calendar.getInstance(); mCalendar.setTime(new Date()); mAnaDate = mCalendar.getTime(); mAnaYear = mCalendar.get(Calendar.YEAR); mAnaMonth = mCalendar.get(Calendar.MONTH); mAnaDay = mCalendar.get(Calendar.DAY_OF_MONTH); tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(mAnaDate)); stepType = Const.STEP_TYPE.WALKING; updateUiStepType(false, true, false); getHomePage(mAnaDate, stepType); } private void getHomePage(Date date, Const.STEP_TYPE stepType){ showDialog(mContext); LLAPIManager.homePage(date, stepType, new LLAPIManagerListener() { @Override public void onError(Error error) { Debug.error("Get data history error"); hiddenDialog(); showDialogNotData(); } @Override public void onSuccess(String json) { Debug.error("Get data history success"); hiddenDialog(); loadDataDone(json); } @Override public void onSuccess(JSONObject object) { Debug.error("Get data history success"); hiddenDialog(); } }); } private void showDialogNotData(){ showAlerDialog(mContext, getResources().getString(R.string.can_not_get_data)); } private void loadDataDone(String jsonString) { JSONObject jsonObject = null; try { jsonObject = new JSONObject(jsonString); int status = jsonObject.optInt("status"); if (status == 1) { JSONObject jsonObject1 = jsonObject.optJSONObject("result"); JSONObject targetInf = jsonObject1.getJSONObject("targetInf"); JSONArray listNotice = jsonObject1.getJSONArray("listNotice"); if (targetInf != null){ String target = targetInf.optString("target_step"); Debug.normal("Target: "+ target); mTagetInfo.setTaget(targetInf.optString("target_step")); mTagetInfo.setSteps(targetInf.optString("num_step")); mTagetInfo.setStepRemain(targetInf.optString("remaining_step")); mTagetInfo.setCompletePercent(targetInf.optString("complete_percent")); } if (listNotice != null && listNotice.length() > 0) { List<NoticeInfo> infoLists = new ArrayList<>(); for (int i = 0; i < listNotice.length(); i++){ NoticeInfo noticeInfo = new NoticeInfo(); JSONObject ob = (JSONObject) listNotice.get(i); noticeInfo.setId(ob.optInt("id")); noticeInfo.setContent(ob.optString("notice_content")); infoLists.add(noticeInfo); } mTagetInfo.setNoticeList(infoLists); } } } catch (JSONException e) { e.printStackTrace(); mTagetInfo = new TagetInfo();; } |
54e5fcd56
|
286 |
loadUI(); |
7f095a929
|
287 |
} |
54e5fcd56
|
288 289 290 |
private void loadUI(){ tvStep.setText(String.valueOf(mTagetInfo.getSteps())); tvRemain.setText(String.valueOf(mTagetInfo.getStepRemain())); |
383e85498
|
291 |
tvRateDone.setText(mContext.getResources().getString(R.string.percent_unit, mTagetInfo.getCompletePercent())); |
7f095a929
|
292 293 294 295 296 297 298 299 300 |
List<NoticeInfo> infoLists = mTagetInfo.getNoticeList(); if (infoLists != null && infoLists.size() >0){ mNoticeAdapter = new NoticeAdapter(mContext, infoLists); lvNotice.setAdapter(mNoticeAdapter); lvNotice.setExpanded(true); } } |
7f095a929
|
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 |
@Override public void onAttach(Context context) { super.onAttach(context); } @Override public void onSaveData() { } @Override public void onInvalidate(boolean isInit) { initData(); } @Override public void onViewStateRestored(@Nullable Bundle savedInstanceState) { super.onViewStateRestored(savedInstanceState); initData(); } @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); } |
54e5fcd56
|
332 |
|
7f095a929
|
333 |
} |