Commit 5520a4b27df178a212e405aeaad6b3bbda41cd3d

Authored by Dinh Chu
1 parent 13594f58ae
Exists in master and in 1 other branch development

update

Showing 17 changed files with 401 additions and 88 deletions Inline Diff

1 <?xml version="1.0" encoding="UTF-8"?> 1 <?xml version="1.0" encoding="UTF-8"?>
2 <project version="4"> 2 <project version="4">
3 <component name="EntryPointsManager">
4 <entry_points version="2.0" />
5 </component>
6 <component name="NullableNotNullManager"> 3 <component name="NullableNotNullManager">
7 <option name="myDefaultNullable" value="android.support.annotation.Nullable" /> 4 <option name="myDefaultNullable" value="android.support.annotation.Nullable" />
8 <option name="myDefaultNotNull" value="android.support.annotation.NonNull" /> 5 <option name="myDefaultNotNull" value="android.support.annotation.NonNull" />
9 <option name="myNullables"> 6 <option name="myNullables">
10 <value> 7 <value>
11 <list size="4"> 8 <list size="4">
12 <item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" /> 9 <item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" />
13 <item index="1" class="java.lang.String" itemvalue="javax.annotation.Nullable" /> 10 <item index="1" class="java.lang.String" itemvalue="javax.annotation.Nullable" />
14 <item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.Nullable" /> 11 <item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.Nullable" />
15 <item index="3" class="java.lang.String" itemvalue="android.support.annotation.Nullable" /> 12 <item index="3" class="java.lang.String" itemvalue="android.support.annotation.Nullable" />
16 </list> 13 </list>
17 </value> 14 </value>
18 </option> 15 </option>
19 <option name="myNotNulls"> 16 <option name="myNotNulls">
20 <value> 17 <value>
21 <list size="4"> 18 <list size="4">
22 <item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.NotNull" /> 19 <item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.NotNull" />
23 <item index="1" class="java.lang.String" itemvalue="javax.annotation.Nonnull" /> 20 <item index="1" class="java.lang.String" itemvalue="javax.annotation.Nonnull" />
24 <item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.NonNull" /> 21 <item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.NonNull" />
25 <item index="3" class="java.lang.String" itemvalue="android.support.annotation.NonNull" /> 22 <item index="3" class="java.lang.String" itemvalue="android.support.annotation.NonNull" />
26 </list> 23 </list>
27 </value> 24 </value>
28 </option> 25 </option>
29 </component> 26 </component>
30 <component name="ProjectLevelVcsManager" settingsEditedManually="false"> 27 <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
31 <OptionsSetting value="true" id="Add" />
32 <OptionsSetting value="true" id="Remove" />
33 <OptionsSetting value="true" id="Checkout" />
34 <OptionsSetting value="true" id="Update" />
35 <OptionsSetting value="true" id="Status" />
36 <OptionsSetting value="true" id="Edit" />
37 <ConfirmationsSetting value="0" id="Add" />
38 <ConfirmationsSetting value="0" id="Remove" />
39 </component>
40 <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
41 <output url="file://$PROJECT_DIR$/build/classes" /> 28 <output url="file://$PROJECT_DIR$/build/classes" />
42 </component> 29 </component>
43 <component name="ProjectType"> 30 <component name="ProjectType">
44 <option name="id" value="Android" /> 31 <option name="id" value="Android" />
45 </component> 32 </component>
46 </project> 33 </project>
1 <?xml version="1.0" encoding="UTF-8"?> 1 <?xml version="1.0" encoding="UTF-8"?>
2 <project version="4"> 2 <project version="4">
3 <component name="ProjectModuleManager"> 3 <component name="ProjectModuleManager">
4 <modules> 4 <modules>
5 <module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" /> 5 <module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
6 <module fileurl="file://$PROJECT_DIR$/lifelog_android.iml" filepath="$PROJECT_DIR$/lifelog_android.iml" /> 6 <module fileurl="file://$PROJECT_DIR$/lifelog_android.iml" filepath="$PROJECT_DIR$/lifelog_android.iml" />
7 <module fileurl="file://$PROJECT_DIR$/lifelogpedometer.iml" filepath="$PROJECT_DIR$/lifelogpedometer.iml" /> 7 <module fileurl="file://D:\Project\Git\lifelog_android\lifelogpedometer.iml" filepath="D:\Project\Git\lifelog_android\lifelogpedometer.iml" />
8 </modules> 8 </modules>
9 </component> 9 </component>
10 </project> 10 </project>
1 apply plugin: 'com.android.application' 1 apply plugin: 'com.android.application'
2 2
3 android { 3 android {
4 compileSdkVersion 25 4 compileSdkVersion 25
5 buildToolsVersion "25.0.3" 5 buildToolsVersion '26.0.2'
6 defaultConfig { 6 defaultConfig {
7 applicationId "com.dinhcv.lifelogpedometer" 7 applicationId "com.dinhcv.lifelogpedometer"
8 minSdkVersion 19 8 minSdkVersion 19
9 targetSdkVersion 25 9 targetSdkVersion 25
10 versionCode 1 10 versionCode 1
11 versionName "1.0" 11 versionName "1.0"
12 testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 12 testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13 // Enabling multidex support. 13 // Enabling multidex support.
14 multiDexEnabled true 14 multiDexEnabled true
15 } 15 }
16
17 flavorDimensions "default"
18
16 buildTypes { 19 buildTypes {
17 release { 20 release {
18 minifyEnabled false 21 minifyEnabled false
19 proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 22 proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20 } 23 }
21 } 24 }
22 25
23 signingConfigs { 26 signingConfigs {
24 dev { 27 dev {
25 storeFile file("../keystores/...") 28 storeFile file("../keystores/...")
26 storePassword 'android' 29 storePassword 'android'
27 keyAlias 'androiddebugkey' 30 keyAlias 'androiddebugkey'
28 keyPassword 'android' 31 keyPassword 'android'
29 } 32 }
30 33
31 product { 34 product {
32 storeFile file("..keystores/...") 35 storeFile file("..keystores/...")
33 storePassword 'android' 36 storePassword 'android'
34 keyAlias 'androiddebugkey' 37 keyAlias 'androiddebugkey'
35 keyPassword 'android' 38 keyPassword 'android'
36 } 39 }
37 } 40 }
38 41
39 productFlavors { 42 productFlavors {
40 43
41 dev { 44 dev {
42 applicationId "com.dinhcv.lifelogpedometer" 45 applicationId "com.dinhcv.lifelogpedometer"
43 applicationIdSuffix "dev" 46 applicationIdSuffix "dev"
44 minSdkVersion 19 47 minSdkVersion 19
45 buildConfigField 'String', 'BASE_URL', '"http://clover.timesfun.jp:9001/"' 48 buildConfigField 'String', 'BASE_URL', '"http://clover.timesfun.jp:9001/"'
46 } 49 }
47 50
48 product { 51 product {
49 applicationId "com.dinhcv.lifelogpedometer" 52 applicationId "com.dinhcv.lifelogpedometer"
50 minSdkVersion 19 53 minSdkVersion 19
51 buildConfigField 'String', 'BASE_URL', '"http://clover.timesfun.jp:9001/"' 54 buildConfigField 'String', 'BASE_URL', '"http://clover.timesfun.jp:9001/"'
52 } 55 }
53 } 56 }
54 } 57 }
55 58
56 dependencies { 59 dependencies {
57 compile fileTree(include: ['*.jar'], dir: 'libs') 60 compile fileTree(include: ['*.jar'], dir: 'libs')
58 androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 61 androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
59 exclude group: 'com.android.support', module: 'support-annotations' 62 exclude group: 'com.android.support', module: 'support-annotations'
60 }) 63 })
61 64
62 // Retrofit 65 // Retrofit
63 // JSON Parsing 66 // JSON Parsing
64 compile 'com.squareup.retrofit2:converter-gson:2.1.0' 67 compile 'com.squareup.retrofit2:converter-gson:2.1.0'
65 compile 'com.android.support:appcompat-v7:25.3.1' 68 compile 'com.android.support:appcompat-v7:25.3.1'
66 compile 'com.github.j4velin.colorpicker:colorpicker:1.2.3' 69 compile 'com.github.j4velin.colorpicker:colorpicker:1.2.3'
67 compile 'com.github.j4velin.EazeGraph:EazeGraph:1.0.2' 70 compile 'com.github.j4velin.EazeGraph:EazeGraph:1.0.2'
68 compile 'com.google.android.apps.dashclock:dashclock-api:2.0.0' 71 compile 'com.google.android.apps.dashclock:dashclock-api:2.0.0'
69 compile 'com.android.support:design:25.3.1' 72 compile 'com.android.support:design:25.3.1'
70 compile 'com.github.PhilJay:MPAndroidChart:v3.0.2' 73 compile 'com.github.PhilJay:MPAndroidChart:v3.0.2'
71 compile 'com.google.android.gms:play-services:11.0.4' 74 compile 'com.google.android.gms:play-services:11.0.4'
72 compile 'com.google.code.gson:gson:2.7' 75 compile 'com.google.code.gson:gson:2.7'
73 compile 'com.squareup.retrofit2:converter-gson:2.1.0' 76 compile 'com.squareup.retrofit2:converter-gson:2.1.0'
74 compile 'de.hdodenhof:circleimageview:2.1.0' 77 compile 'de.hdodenhof:circleimageview:2.1.0'
75 compile 'com.jakewharton:butterknife:8.6.0' 78 compile 'com.jakewharton:butterknife:8.6.0'
76 testCompile 'junit:junit:4.12' 79 testCompile 'junit:junit:4.12'
77 // Retrofit 80 // Retrofit
78 compile 'com.squareup.retrofit2:retrofit:2.1.0' 81 compile 'com.squareup.retrofit2:retrofit:2.1.0'
79 compile 'com.squareup.picasso:picasso:2.5.2' 82 compile 'com.squareup.picasso:picasso:2.5.2'
80 compile 'de.hdodenhof:circleimageview:2.1.0' 83 compile 'de.hdodenhof:circleimageview:2.1.0'
81 compile 'com.jakewharton:butterknife:8.6.0' 84 compile 'com.jakewharton:butterknife:8.6.0'
82 compile 'com.squareup.retrofit2:retrofit:2.1.0' 85 compile 'com.squareup.retrofit2:retrofit:2.1.0'
83 compile 'com.squareup.picasso:picasso:2.5.2' 86 compile 'com.squareup.picasso:picasso:2.5.2'
84 compile 'com.android.support:support-v4:25.3.1' 87 compile 'com.android.support:support-v4:25.3.1'
85 testCompile 'junit:junit:4.12' 88 testCompile 'junit:junit:4.12'
86 89
87 compile 'com.android.support:multidex:1.0.1' 90 compile 'com.android.support:multidex:1.0.1'
88 91
89 annotationProcessor 'com.jakewharton:butterknife-compiler:8.6.0' 92 annotationProcessor 'com.jakewharton:butterknife-compiler:8.6.0'
90 } 93 }
91 94
app/src/main/java/com/dinhcv/lifelogpedometer/activity/HistoryContentFragment.java
1 package com.dinhcv.lifelogpedometer.activity; 1 package com.dinhcv.lifelogpedometer.activity;
2 2
3 import android.app.DatePickerDialog; 3 import android.app.DatePickerDialog;
4 import android.content.Context; 4 import android.content.Context;
5 import android.content.Intent; 5 import android.content.Intent;
6 import android.graphics.Color; 6 import android.graphics.Color;
7 import android.os.Bundle; 7 import android.os.Bundle;
8 import android.view.LayoutInflater; 8 import android.view.LayoutInflater;
9 import android.view.View; 9 import android.view.View;
10 import android.view.ViewGroup; 10 import android.view.ViewGroup;
11 import android.widget.Button; 11 import android.widget.Button;
12 import android.widget.DatePicker; 12 import android.widget.DatePicker;
13 import android.widget.ImageButton; 13 import android.widget.ImageButton;
14 import android.widget.LinearLayout; 14 import android.widget.LinearLayout;
15 import android.widget.TextView; 15 import android.widget.TextView;
16 16
17 import com.dinhcv.lifelogpedometer.R; 17 import com.dinhcv.lifelogpedometer.R;
18 import com.dinhcv.lifelogpedometer.interfaces.LLAPIManagerListener; 18 import com.dinhcv.lifelogpedometer.interfaces.LLAPIManagerListener;
19 import com.dinhcv.lifelogpedometer.model.structure.history.HistoryInfo; 19 import com.dinhcv.lifelogpedometer.model.structure.history.HistoryInfo;
20 import com.dinhcv.lifelogpedometer.portal.ApiServices;
20 import com.dinhcv.lifelogpedometer.portal.LLAPIManager; 21 import com.dinhcv.lifelogpedometer.portal.LLAPIManager;
21 import com.dinhcv.lifelogpedometer.utils.Const; 22 import com.dinhcv.lifelogpedometer.utils.Const;
22 import com.dinhcv.lifelogpedometer.utils.DayAxisValueFormatter; 23 import com.dinhcv.lifelogpedometer.utils.DayAxisValueFormatter;
23 import com.dinhcv.lifelogpedometer.utils.Debug; 24 import com.dinhcv.lifelogpedometer.utils.Debug;
24 import com.dinhcv.lifelogpedometer.utils.Utils; 25 import com.dinhcv.lifelogpedometer.utils.Utils;
25 import com.github.mikephil.charting.charts.BarChart; 26 import com.github.mikephil.charting.charts.BarChart;
26 import com.github.mikephil.charting.components.XAxis; 27 import com.github.mikephil.charting.components.XAxis;
27 import com.github.mikephil.charting.components.YAxis; 28 import com.github.mikephil.charting.components.YAxis;
28 import com.github.mikephil.charting.data.BarData; 29 import com.github.mikephil.charting.data.BarData;
29 import com.github.mikephil.charting.data.BarDataSet; 30 import com.github.mikephil.charting.data.BarDataSet;
30 import com.github.mikephil.charting.data.BarEntry; 31 import com.github.mikephil.charting.data.BarEntry;
31 import com.github.mikephil.charting.interfaces.datasets.IBarDataSet; 32 import com.github.mikephil.charting.interfaces.datasets.IBarDataSet;
32 33
33 import org.json.JSONException; 34 import org.json.JSONException;
34 import org.json.JSONObject; 35 import org.json.JSONObject;
35 36
36 import java.util.ArrayList; 37 import java.util.ArrayList;
37 import java.util.Calendar; 38 import java.util.Calendar;
38 import java.util.Date; 39 import java.util.Date;
39 import java.util.List; 40 import java.util.List;
40 41
41 import butterknife.BindView; 42 import butterknife.BindView;
42 import butterknife.ButterKnife; 43 import butterknife.ButterKnife;
43 import butterknife.OnClick; 44 import butterknife.OnClick;
44 45
45 import static com.github.mikephil.charting.utils.ColorTemplate.rgb; 46 import static com.github.mikephil.charting.utils.ColorTemplate.rgb;
46 47
47 public class HistoryContentFragment extends FragmentBase { 48 public class HistoryContentFragment extends FragmentBase {
48 49
49 @BindView(R.id.btn_left_date) 50 @BindView(R.id.btn_left_date)
50 ImageButton btnLeftDate; 51 ImageButton btnLeftDate;
51 @BindView(R.id.btn_right_date) 52 @BindView(R.id.btn_right_date)
52 ImageButton btnRightDate; 53 ImageButton btnRightDate;
53 @BindView(R.id.tv_date) 54 @BindView(R.id.tv_date)
54 TextView tvDate; 55 TextView tvDate;
55 @BindView(R.id.tv_week_day) 56 @BindView(R.id.tv_week_day)
56 TextView tvWeekDay; 57 TextView tvWeekDay;
57 private Button btnFace; 58 private Button btnFace;
58 private Button btnTwitter; 59 private Button btnTwitter;
59 private Button btnLine; 60 private Button btnLine;
60 private Button btnEmail; 61 private Button btnEmail;
61 private Button btnOther; 62 private Button btnOther;
62 @BindView(R.id.tv_steps) 63 @BindView(R.id.tv_steps)
63 TextView tvStep; 64 TextView tvStep;
64 @BindView(R.id.tv_remainingStep) 65 @BindView(R.id.tv_remainingStep)
65 TextView tvRemain; 66 TextView tvRemain;
66 @BindView(R.id.tv_stepRateDone) 67 @BindView(R.id.tv_stepRateDone)
67 TextView tvRateDone; 68 TextView tvRateDone;
68 @BindView(R.id.tv_smallRemain) 69 @BindView(R.id.tv_smallRemain)
69 TextView tvSmallRemain; 70 TextView tvSmallRemain;
70 @BindView(R.id.tv_stepGoal) 71 @BindView(R.id.tv_stepGoal)
71 TextView tvGoal; 72 TextView tvGoal;
72 73
73 @BindView(R.id.tv_caloConsumned) 74 @BindView(R.id.tv_caloConsumned)
74 TextView tvCaloConsumned; 75 TextView tvCaloConsumned;
75 @BindView(R.id.tv_distance) 76 @BindView(R.id.tv_distance)
76 TextView tvDistance; 77 TextView tvDistance;
77 @BindView(R.id.tv_time) 78 @BindView(R.id.tv_time)
78 TextView tvTime; 79 TextView tvTime;
79 80
80 @BindView(R.id.ll_bike) 81 @BindView(R.id.ll_bike)
81 LinearLayout llBike; 82 LinearLayout llBike;
82 @BindView(R.id.ll_walking) 83 @BindView(R.id.ll_walking)
83 LinearLayout llWalking; 84 LinearLayout llWalking;
84 @BindView(R.id.ll_running) 85 @BindView(R.id.ll_running)
85 LinearLayout llRunning; 86 LinearLayout llRunning;
86 @BindView(R.id.btn_oneDay) 87 @BindView(R.id.btn_oneDay)
87 Button btnOneDay; 88 Button btnOneDay;
88 @BindView(R.id.btn_oneWeek) 89 @BindView(R.id.btn_oneWeek)
89 Button btnOneWeek; 90 Button btnOneWeek;
90 @BindView(R.id.btn_oneMonth) 91 @BindView(R.id.btn_oneMonth)
91 Button btnOneMonth; 92 Button btnOneMonth;
92 @BindView(R.id.btn_threeMonth) 93 @BindView(R.id.btn_threeMonth)
93 Button btnThreeMonth; 94 Button btnThreeMonth;
94 @BindView(R.id.btn_sixMonth) 95 @BindView(R.id.btn_sixMonth)
95 Button btnSixMonth; 96 Button btnSixMonth;
96 97
97 // bar chart 98 // bar chart
98 private BarChart mBarChart; 99 private BarChart mBarChart;
99 private List<String> dateList; 100 private List<String> dateList;
100 private String[] mParties; 101 private String[] mParties;
101 private Integer[] mStep; 102 private Integer[] mStep;
102 103
103 private Date mAnaDate; 104 private Date mAnaDate;
104 private Calendar mCalendar; 105 private Calendar mCalendar;
105 106
106 private int mAnaDay; 107 private int mAnaDay;
107 private int mAnaMonth; 108 private int mAnaMonth;
108 private int mAnaYear; 109 private int mAnaYear;
109 110
110 private HistoryInfo mDataModWalking = new HistoryInfo(); 111 private HistoryInfo mDataModWalking = new HistoryInfo();
111 private HistoryInfo mDataModRunning = new HistoryInfo(); 112 private HistoryInfo mDataModRunning = new HistoryInfo();
112 private HistoryInfo mDataModBike = new HistoryInfo(); 113 private HistoryInfo mDataModBike = new HistoryInfo();
113 private HistoryInfo mDataCurrent = new HistoryInfo(); 114 private HistoryInfo mDataCurrent = new HistoryInfo();
114 115
115 private Const.DATA_TYPE dataType; 116 private Const.DATA_TYPE dataType;
116 private Const.STEP_TYPE stepType; 117 private Const.STEP_TYPE stepType;
117 118
118 private Context mContext; 119 private Context mContext;
119 private View mRootView; 120 private View mRootView;
120 121
121 private HistoryFragment mHistoryFragment; 122 private HistoryFragment mHistoryFragment;
122 123
123 public void setRootFragment(HistoryFragment frag) { 124 public void setRootFragment(HistoryFragment frag) {
124 this.mHistoryFragment = frag; 125 this.mHistoryFragment = frag;
125 } 126 }
126 127
127 @Override 128 @Override
128 public View onCreateView(final LayoutInflater inflater, final ViewGroup container, 129 public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
129 final Bundle savedInstanceState) { 130 final Bundle savedInstanceState) {
130 mRootView = inflater.inflate(R.layout.fragment_history_content, null); 131 mRootView = inflater.inflate(R.layout.fragment_history_content, null);
131 ButterKnife.bind(this, mRootView); 132 ButterKnife.bind(this, mRootView);
132 mContext = getActivity(); 133 mContext = getActivity();
133 initView(mRootView); 134 initView(mRootView);
134 initData(); 135 initData();
135 136
136 return mRootView; 137 return mRootView;
137 } 138 }
138 139
139 140
140 private void initView(View view) { 141 private void initView(View view) {
141 btnFace = (Button) view.findViewById(R.id.btn_face); 142 btnFace = (Button) view.findViewById(R.id.btn_face);
142 btnTwitter = (Button) view.findViewById(R.id.btn_twitter); 143 btnTwitter = (Button) view.findViewById(R.id.btn_twitter);
143 btnLine = (Button) view.findViewById(R.id.btn_line); 144 btnLine = (Button) view.findViewById(R.id.btn_line);
144 btnEmail = (Button) view.findViewById(R.id.btn_email); 145 btnEmail = (Button) view.findViewById(R.id.btn_email);
145 btnOther = (Button) view.findViewById(R.id.btn_other); 146 btnOther = (Button) view.findViewById(R.id.btn_other);
146 147
147 mBarChart = (BarChart) view.findViewById(R.id.chart); 148 mBarChart = (BarChart) view.findViewById(R.id.chart);
148 } 149 }
149 150
150 151
151 /** 152 /**
152 * Show date picker dialog 153 * Show date picker dialog
153 */ 154 */
154 private void handleAnaDatePicker() { 155 private void handleAnaDatePicker() {
155 156
156 new DatePickerDialog(mContext, new DatePickerDialog.OnDateSetListener() { 157 new DatePickerDialog(mContext, new DatePickerDialog.OnDateSetListener() {
157 @Override 158 @Override
158 public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { 159 public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
159 160
160 mCalendar = Calendar.getInstance(); 161 mCalendar = Calendar.getInstance();
161 mCalendar.set(year, monthOfYear, dayOfMonth); 162 mCalendar.set(year, monthOfYear, dayOfMonth);
162 mAnaYear = year; 163 mAnaYear = year;
163 mAnaMonth = monthOfYear; 164 mAnaMonth = monthOfYear;
164 mAnaDay = dayOfMonth; 165 mAnaDay = dayOfMonth;
165 Date date = mCalendar.getTime(); 166 Date date = mCalendar.getTime();
166 tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(date)); 167 tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(date));
167 tvWeekDay.setText(Utils.getWeekdayFromDate(date)); 168 tvWeekDay.setText(Utils.getWeekdayFromDate(date));
168 mAnaDate = date; 169 mAnaDate = date;
169 getHistoryData(dataType, mAnaDate); 170 getHistoryData(dataType, mAnaDate);
170 } 171 }
171 }, mAnaYear, mAnaMonth, mAnaDay).show(); 172 }, mAnaYear, mAnaMonth, mAnaDay).show();
172 173
173 } 174 }
174 175
175 176
176 /** 177 /**
177 * init data for 178 * init data for
178 */ 179 */
179 private void initData() { 180 private void initData() {
180 mCalendar = Calendar.getInstance(); 181 mCalendar = Calendar.getInstance();
181 mCalendar.setTime(new Date()); 182 mCalendar.setTime(new Date());
182 mAnaDate = mCalendar.getTime(); 183 mAnaDate = mCalendar.getTime();
183 mAnaYear = mCalendar.get(Calendar.YEAR); 184 mAnaYear = mCalendar.get(Calendar.YEAR);
184 mAnaMonth = mCalendar.get(Calendar.MONTH); 185 mAnaMonth = mCalendar.get(Calendar.MONTH);
185 mAnaDay = mCalendar.get(Calendar.DAY_OF_MONTH); 186 mAnaDay = mCalendar.get(Calendar.DAY_OF_MONTH);
186 187
187 tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(mAnaDate)); 188 tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(mAnaDate));
188 tvWeekDay.setText(Utils.getWeekdayFromDate(mAnaDate)); 189 tvWeekDay.setText(Utils.getWeekdayFromDate(mAnaDate));
189 190
190 dataType = Const.DATA_TYPE.ONE_DAY; 191 dataType = Const.DATA_TYPE.ONE_DAY;
191 stepType = Const.STEP_TYPE.WALKING; 192 stepType = Const.STEP_TYPE.WALKING;
192 updateUiType(); 193 updateUiType();
193 updateUiStepType(false, true, false); 194 updateUiStepType(false, true, false);
194 195
195 getHistoryData(dataType, mAnaDate); 196 getHistoryData(dataType, mAnaDate);
196 } 197 }
197 198
198 private void updateUiType() { 199 private void updateUiType() {
199 if (dataType == Const.DATA_TYPE.ONE_DAY) { 200 if (dataType == Const.DATA_TYPE.ONE_DAY) {
200 setButtonSelected(true, false, false, false, false); 201 setButtonSelected(true, false, false, false, false);
201 } else if (dataType == Const.DATA_TYPE.ONE_WEEK) { 202 } else if (dataType == Const.DATA_TYPE.ONE_WEEK) {
202 setButtonSelected(false, true, false, false, false); 203 setButtonSelected(false, true, false, false, false);
203 } else if (dataType == Const.DATA_TYPE.ONE_MONTH) { 204 } else if (dataType == Const.DATA_TYPE.ONE_MONTH) {
204 setButtonSelected(false, false, true, false, false); 205 setButtonSelected(false, false, true, false, false);
205 } else if (dataType == Const.DATA_TYPE.THREE_MONTH){ 206 } else if (dataType == Const.DATA_TYPE.THREE_MONTH){
206 setButtonSelected(false, false, false, true, false); 207 setButtonSelected(false, false, false, true, false);
207 } else if (dataType == Const.DATA_TYPE.SIX_MONTH){ 208 } else if (dataType == Const.DATA_TYPE.SIX_MONTH){
208 setButtonSelected(false, false, false, false, true); 209 setButtonSelected(false, false, false, false, true);
209 } 210 }
210 } 211 }
211 212
212 private void setButtonSelected(boolean b1, boolean b2, boolean b3, boolean b4, boolean b5 ) { 213 private void setButtonSelected(boolean b1, boolean b2, boolean b3, boolean b4, boolean b5 ) {
213 btnOneDay.setSelected(b1); 214 btnOneDay.setSelected(b1);
214 btnOneWeek.setSelected(b2); 215 btnOneWeek.setSelected(b2);
215 btnOneMonth.setSelected(b3); 216 btnOneMonth.setSelected(b3);
216 btnThreeMonth.setSelected(b4); 217 btnThreeMonth.setSelected(b4);
217 btnSixMonth.setSelected(b5); 218 btnSixMonth.setSelected(b5);
218 } 219 }
219 220
220 private void updateUiStepType(boolean b1, boolean b2, boolean b3) { 221 private void updateUiStepType(boolean b1, boolean b2, boolean b3) {
221 llBike.setSelected(b1); 222 llBike.setSelected(b1);
222 llWalking.setSelected(b2); 223 llWalking.setSelected(b2);
223 llRunning.setSelected(b3); 224 llRunning.setSelected(b3);
224 } 225 }
225 226
226 private void getHistoryData(Const.DATA_TYPE dataType, Date toDate){ 227 private void getHistoryData(Const.DATA_TYPE dataType, Date toDate){
227 228
228 Date fromDate = Utils.getFromDate(mAnaDate, dataType); 229 Date fromDate = Utils.getFromDate(mAnaDate, dataType);
229 230
230 showDialog(mContext); 231 showDialog(mContext);
231 LLAPIManager.history(fromDate, toDate, new LLAPIManagerListener() { 232 ApiServices.history(fromDate, toDate, new LLAPIManagerListener() {
232 @Override 233 @Override
233 public void onError(Error error) { 234 public void onError(Error error) {
234 Debug.error("Get data history error"); 235 Debug.error("Get data history error");
235 hiddenDialog(); 236 hiddenDialog();
236 showDialogNotData(); 237 showDialogNotData();
237 } 238 }
238 239
239 @Override 240 @Override
240 public void onSuccess(String json) { 241 public void onSuccess(String json) {
241 Debug.error("Get data history success"); 242 Debug.error("Get data history success");
242 hiddenDialog(); 243 hiddenDialog();
243 loadDataDone(json); 244 loadDataDone(json);
244 } 245 }
245 246
246 @Override 247 @Override
247 public void onSuccess(JSONObject object) { 248 public void onSuccess(JSONObject object) {
248 Debug.error("Get data history success"); 249 Debug.error("Get data history success");
249 hiddenDialog(); 250 hiddenDialog();
250 } 251 }
251 }); 252 });
252 } 253 }
253 254
254 private void showDialogNotData(){ 255 private void showDialogNotData(){
255 showAlerDialog(mContext, getResources().getString(R.string.can_not_get_data)); 256 showAlerDialog(mContext, getResources().getString(R.string.can_not_get_data));
256 } 257 }
257 258
258 private void loadDataDone(String jsonString) { 259 private void loadDataDone(String jsonString) {
259 JSONObject jsonObject = null; 260 JSONObject jsonObject = null;
260 try { 261 try {
261 jsonObject = new JSONObject(jsonString); 262 jsonObject = new JSONObject(jsonString);
262 int status = jsonObject.optInt("status"); 263 int status = jsonObject.optInt("status");
263 if (status == 1) { 264 if (status == 1) {
264 JSONObject jsonObject1 = jsonObject.optJSONObject("result"); 265 JSONObject jsonObject1 = jsonObject.optJSONObject("result");
265 JSONObject jsonMod1 = jsonObject1.getJSONObject("mode_1"); 266 JSONObject jsonMod1 = jsonObject1.getJSONObject("mode_1");
266 JSONObject jsonMod2 = jsonObject1.getJSONObject("mode_2"); 267 JSONObject jsonMod2 = jsonObject1.getJSONObject("mode_2");
267 JSONObject jsonMod3 = jsonObject1.getJSONObject("mode_3"); 268 JSONObject jsonMod3 = jsonObject1.getJSONObject("mode_3");
268 addDataModWalking(jsonMod1); 269 addDataModWalking(jsonMod1);
269 addDataModRunning(jsonMod2); 270 addDataModRunning(jsonMod2);
270 addDataModBike(jsonMod3); 271 addDataModBike(jsonMod3);
271 272
272 } 273 }
273 } catch (JSONException e) { 274 } catch (JSONException e) {
274 e.printStackTrace(); 275 e.printStackTrace();
275 mDataModWalking = new HistoryInfo(); 276 mDataModWalking = new HistoryInfo();
276 mDataModRunning = new HistoryInfo();; 277 mDataModRunning = new HistoryInfo();;
277 mDataModBike = new HistoryInfo();; 278 mDataModBike = new HistoryInfo();;
278 } 279 }
279 280
280 if (stepType == Const.STEP_TYPE.WALKING){ 281 if (stepType == Const.STEP_TYPE.WALKING){
281 mDataCurrent = mDataModWalking; 282 mDataCurrent = mDataModWalking;
282 }else if (stepType == Const.STEP_TYPE.RUNNING){ 283 }else if (stepType == Const.STEP_TYPE.RUNNING){
283 mDataCurrent = mDataModRunning; 284 mDataCurrent = mDataModRunning;
284 }else { 285 }else {
285 mDataCurrent = mDataModBike; 286 mDataCurrent = mDataModBike;
286 } 287 }
287 288
288 updateUI(); 289 updateUI();
289 } 290 }
290 291
291 private void updateUI(){ 292 private void updateUI(){
292 // get data server 293 // get data server
293 tvGoal.setText(getResources().getString(R.string.step_unit, mDataCurrent.getTaget())); 294 tvGoal.setText(getResources().getString(R.string.step_unit, mDataCurrent.getTaget()));
294 tvStep.setText(getResources().getString(R.string.step_unit, mDataCurrent.getSteps())); 295 tvStep.setText(getResources().getString(R.string.step_unit, mDataCurrent.getSteps()));
295 tvSmallRemain.setText(getResources().getString(R.string.step_unit_1, mDataCurrent.getStepRemain())); 296 tvSmallRemain.setText(getResources().getString(R.string.step_unit_1, mDataCurrent.getStepRemain()));
296 tvRemain.setText(getResources().getString(R.string.step_unit, mDataCurrent.getStepRemain())); 297 tvRemain.setText(getResources().getString(R.string.step_unit, mDataCurrent.getStepRemain()));
297 tvRateDone.setText(getResources().getString(R.string.percent_unit, Utils.convert2String2Decimal(mDataCurrent.getCompletePercent()))); 298 tvRateDone.setText(getResources().getString(R.string.percent_unit, Utils.convert2String2Decimal(mDataCurrent.getCompletePercent())));
298 tvCaloConsumned.setText(getResources().getString(R.string.kcal_unit, Utils.convert2String2Decimal(mDataCurrent.getKcal()))); 299 tvCaloConsumned.setText(getResources().getString(R.string.kcal_unit, Utils.convert2String2Decimal(mDataCurrent.getKcal())));
299 tvDistance.setText(getResources().getString(R.string.distance_unit, Utils.convert2String2Decimal(mDataCurrent.getDistance()))); 300 tvDistance.setText(getResources().getString(R.string.distance_unit, Utils.convert2String2Decimal(mDataCurrent.getDistance())));
300 tvTime.setText(getResources().getString(R.string.time_unit, Utils.convertTimeStringFromString(mDataCurrent.getTime()))); 301 tvTime.setText(getResources().getString(R.string.time_unit, Utils.convertTimeStringFromString(mDataCurrent.getTime())));
301 302
302 // update bar 303 // update bar
303 if (mDataCurrent.getDataChart() != null && mDataCurrent.getDataChart().size() == 24) { 304 if (mDataCurrent.getDataChart() != null && mDataCurrent.getDataChart().size() == 24) {
304 updateBars(); 305 updateBars();
305 } 306 }
306 307
307 } 308 }
308 309
309 private void updateBars() { 310 private void updateBars() {
310 dateList = new ArrayList<>(); 311 dateList = new ArrayList<>();
311 List<Integer> stepList = new ArrayList<>(); 312 List<Integer> stepList = new ArrayList<>();
312 313
313 stepList = mDataCurrent.getDataChart(); 314 stepList = mDataCurrent.getDataChart();
314 for (int i = 0; i < 24; i++){ 315 for (int i = 0; i < 24; i++){
315 dateList.add(String.valueOf(i)); 316 dateList.add(String.valueOf(i));
316 } 317 }
317 318
318 mStep = stepList.toArray(new Integer[0]); 319 mStep = stepList.toArray(new Integer[0]);
319 mParties = dateList.toArray(new String[0]); 320 mParties = dateList.toArray(new String[0]);
320 321
321 initGraph(); 322 initGraph();
322 } 323 }
323 324
324 private void initGraph(){ 325 private void initGraph(){
325 326
326 mBarChart.setDrawBarShadow(false); 327 mBarChart.setDrawBarShadow(false);
327 mBarChart.setDrawValueAboveBar(true); 328 mBarChart.setDrawValueAboveBar(true);
328 329
329 // if more than 60 entries are displayed in the chart, no values will be 330 // if more than 60 entries are displayed in the chart, no values will be
330 // drawn 331 // drawn
331 mBarChart.setMaxVisibleValueCount(60); 332 mBarChart.setMaxVisibleValueCount(60);
332 333
333 mBarChart.getDescription().setEnabled(false); 334 mBarChart.getDescription().setEnabled(false);
334 // scaling can now only be done on x- and y-axis separately 335 // scaling can now only be done on x- and y-axis separately
335 mBarChart.setPinchZoom(false); 336 mBarChart.setPinchZoom(false);
336 337
337 mBarChart.setDrawGridBackground(false); 338 mBarChart.setDrawGridBackground(false);
338 // mChart.setDrawYLabels(false); 339 // mChart.setDrawYLabels(false);
339 340
340 DayAxisValueFormatter xValueFormatter = new DayAxisValueFormatter(dateList); 341 DayAxisValueFormatter xValueFormatter = new DayAxisValueFormatter(dateList);
341 342
342 XAxis xAxis = mBarChart.getXAxis(); 343 XAxis xAxis = mBarChart.getXAxis();
343 xAxis.setLabelRotationAngle(0); 344 xAxis.setLabelRotationAngle(0);
344 xAxis.setPosition(XAxis.XAxisPosition.TOP); 345 xAxis.setPosition(XAxis.XAxisPosition.TOP);
345 xAxis.setDrawGridLines(true); 346 xAxis.setDrawGridLines(true);
346 xAxis.setLabelCount(10); 347 xAxis.setLabelCount(10);
347 xAxis.setTextColor(Color.WHITE); 348 xAxis.setTextColor(Color.WHITE);
348 xAxis.setValueFormatter(xValueFormatter); 349 xAxis.setValueFormatter(xValueFormatter);
349 350
350 351
351 YAxis leftAxis = mBarChart.getAxisLeft(); 352 YAxis leftAxis = mBarChart.getAxisLeft();
352 leftAxis.setDrawLabels(false); 353 leftAxis.setDrawLabels(false);
353 leftAxis.setDrawGridLines(false); 354 leftAxis.setDrawGridLines(false);
354 leftAxis.setAxisMinimum(0f); 355 leftAxis.setAxisMinimum(0f);
355 leftAxis.setAxisMaximum(10000f); 356 leftAxis.setAxisMaximum(10000f);
356 leftAxis.setDrawZeroLine(false); 357 leftAxis.setDrawZeroLine(false);
357 358
358 leftAxis.setEnabled(false); 359 leftAxis.setEnabled(false);
359 mBarChart.setDrawValueAboveBar(false); 360 mBarChart.setDrawValueAboveBar(false);
360 mBarChart.getAxisRight().setEnabled(false); 361 mBarChart.getAxisRight().setEnabled(false);
361 362
362 // set auto scale min max 363 // set auto scale min max
363 mBarChart.setAutoScaleMinMaxEnabled(true); 364 mBarChart.setAutoScaleMinMaxEnabled(true);
364 mBarChart.notifyDataSetChanged(); 365 mBarChart.notifyDataSetChanged();
365 366
366 // Set enimate y 367 // Set enimate y
367 mBarChart.animateY(2000); 368 mBarChart.animateY(2000);
368 369
369 setData(); 370 setData();
370 371
371 mBarChart.getLegend().setEnabled(false); 372 mBarChart.getLegend().setEnabled(false);
372 } 373 }
373 374
374 375
375 private void setData() { 376 private void setData() {
376 377
377 ArrayList<String> xVals = new ArrayList<>(); 378 ArrayList<String> xVals = new ArrayList<>();
378 for (int i = 0; i < mStep.length; i++) { 379 for (int i = 0; i < mStep.length; i++) {
379 xVals.add(mParties[i % mStep.length]); 380 xVals.add(mParties[i % mStep.length]);
380 } 381 }
381 382
382 ArrayList<BarEntry> yVals1 = new ArrayList<>(); 383 ArrayList<BarEntry> yVals1 = new ArrayList<>();
383 for (int i = 0; i < mStep.length; i++) { 384 for (int i = 0; i < mStep.length; i++) {
384 float val = (float) (mStep[i]*1); 385 float val = (float) (mStep[i]*1);
385 yVals1.add(new BarEntry(i, val)); 386 yVals1.add(new BarEntry(i, val));
386 } 387 }
387 388
388 BarDataSet set1; 389 BarDataSet set1;
389 390
390 if (mBarChart.getData() != null && mBarChart.getData().getDataSetCount() > 0) { 391 if (mBarChart.getData() != null && mBarChart.getData().getDataSetCount() > 0) {
391 set1 = (BarDataSet)mBarChart.getData().getDataSetByIndex(0); 392 set1 = (BarDataSet)mBarChart.getData().getDataSetByIndex(0);
392 set1.setValues(yVals1); 393 set1.setValues(yVals1);
393 mBarChart.getData().notifyDataChanged(); 394 mBarChart.getData().notifyDataChanged();
394 mBarChart.notifyDataSetChanged(); 395 mBarChart.notifyDataSetChanged();
395 } else { 396 } else {
396 ArrayList<Integer> colors = new ArrayList<>(); 397 ArrayList<Integer> colors = new ArrayList<>();
397 398
398 399
399 int[] MATERIAL_COLORS = {rgb("#40CDEF")}; 400 int[] MATERIAL_COLORS = {rgb("#40CDEF")};
400 401
401 for (int c : MATERIAL_COLORS) 402 for (int c : MATERIAL_COLORS)
402 colors.add(c); 403 colors.add(c);
403 404
404 set1 = new BarDataSet(yVals1, null); 405 set1 = new BarDataSet(yVals1, null);
405 406
406 set1.setColors(colors); 407 set1.setColors(colors);
407 408
408 ArrayList<IBarDataSet> dataSets = new ArrayList<>(); 409 ArrayList<IBarDataSet> dataSets = new ArrayList<>();
409 dataSets.add(set1); 410 dataSets.add(set1);
410 411
411 BarData data = new BarData(dataSets); 412 BarData data = new BarData(dataSets);
412 data.setValueTextSize(10f); 413 data.setValueTextSize(10f);
413 414
414 mBarChart.setData(data); 415 mBarChart.setData(data);
415 } 416 }
416 } 417 }
417 418
418 private void addDataModWalking(JSONObject jsonObject){ 419 private void addDataModWalking(JSONObject jsonObject){
419 if (jsonObject == null) return; 420 if (jsonObject == null) return;
420 mDataModWalking.setTaget(jsonObject.optInt("target")); 421 mDataModWalking.setTaget(jsonObject.optInt("target"));
421 mDataModWalking.setSteps(jsonObject.optInt("steps")); 422 mDataModWalking.setSteps(jsonObject.optInt("steps"));
422 mDataModWalking.setStepRemain(jsonObject.optInt("step_remain")); 423 mDataModWalking.setStepRemain(jsonObject.optInt("step_remain"));
423 mDataModWalking.setCompletePercent(jsonObject.optDouble("complete_percent")); 424 mDataModWalking.setCompletePercent(jsonObject.optDouble("complete_percent"));
424 mDataModWalking.setTime(jsonObject.optInt("time")); 425 mDataModWalking.setTime(jsonObject.optInt("time"));
425 mDataModWalking.setDistance(jsonObject.optInt("distance")); 426 mDataModWalking.setDistance(jsonObject.optInt("distance"));
426 mDataModWalking.setKcal(jsonObject.optInt("kcal")); 427 mDataModWalking.setKcal(jsonObject.optInt("kcal"));
427 428
428 JSONObject dataChart = jsonObject.optJSONObject("data_chart"); 429 JSONObject dataChart = jsonObject.optJSONObject("data_chart");
429 ArrayList<Integer> dataChartList = new ArrayList<>(); 430 ArrayList<Integer> dataChartList = new ArrayList<>();
430 dataChartList.add(dataChart.optInt("0")); 431 dataChartList.add(dataChart.optInt("0"));
431 dataChartList.add(dataChart.optInt("1")); 432 dataChartList.add(dataChart.optInt("1"));
432 dataChartList.add(dataChart.optInt("2")); 433 dataChartList.add(dataChart.optInt("2"));
433 dataChartList.add(dataChart.optInt("3")); 434 dataChartList.add(dataChart.optInt("3"));
434 dataChartList.add(dataChart.optInt("4")); 435 dataChartList.add(dataChart.optInt("4"));
435 dataChartList.add(dataChart.optInt("5")); 436 dataChartList.add(dataChart.optInt("5"));
436 dataChartList.add(dataChart.optInt("6")); 437 dataChartList.add(dataChart.optInt("6"));
437 dataChartList.add(dataChart.optInt("7")); 438 dataChartList.add(dataChart.optInt("7"));
438 dataChartList.add(dataChart.optInt("8")); 439 dataChartList.add(dataChart.optInt("8"));
439 dataChartList.add(dataChart.optInt("9")); 440 dataChartList.add(dataChart.optInt("9"));
440 dataChartList.add(dataChart.optInt("10")); 441 dataChartList.add(dataChart.optInt("10"));
441 dataChartList.add(dataChart.optInt("11")); 442 dataChartList.add(dataChart.optInt("11"));
442 dataChartList.add(dataChart.optInt("12")); 443 dataChartList.add(dataChart.optInt("12"));
443 dataChartList.add(dataChart.optInt("13")); 444 dataChartList.add(dataChart.optInt("13"));
444 dataChartList.add(dataChart.optInt("14")); 445 dataChartList.add(dataChart.optInt("14"));
445 dataChartList.add(dataChart.optInt("15")); 446 dataChartList.add(dataChart.optInt("15"));
446 dataChartList.add(dataChart.optInt("16")); 447 dataChartList.add(dataChart.optInt("16"));
447 dataChartList.add(dataChart.optInt("17")); 448 dataChartList.add(dataChart.optInt("17"));
448 dataChartList.add(dataChart.optInt("18")); 449 dataChartList.add(dataChart.optInt("18"));
449 dataChartList.add(dataChart.optInt("19")); 450 dataChartList.add(dataChart.optInt("19"));
450 dataChartList.add(dataChart.optInt("20")); 451 dataChartList.add(dataChart.optInt("20"));
451 dataChartList.add(dataChart.optInt("21")); 452 dataChartList.add(dataChart.optInt("21"));
452 dataChartList.add(dataChart.optInt("22")); 453 dataChartList.add(dataChart.optInt("22"));
453 dataChartList.add(dataChart.optInt("23")); 454 dataChartList.add(dataChart.optInt("23"));
454 455
455 mDataModWalking.setDataChart(dataChartList); 456 mDataModWalking.setDataChart(dataChartList);
456 } 457 }
457 458
458 private void addDataModRunning(JSONObject jsonObject){ 459 private void addDataModRunning(JSONObject jsonObject){
459 if (jsonObject == null) return; 460 if (jsonObject == null) return;
460 mDataModRunning.setTaget(jsonObject.optInt("target")); 461 mDataModRunning.setTaget(jsonObject.optInt("target"));
461 mDataModRunning.setSteps(jsonObject.optInt("steps")); 462 mDataModRunning.setSteps(jsonObject.optInt("steps"));
462 mDataModRunning.setStepRemain(jsonObject.optInt("step_remain")); 463 mDataModRunning.setStepRemain(jsonObject.optInt("step_remain"));
463 mDataModRunning.setCompletePercent(jsonObject.optDouble("complete_percent")); 464 mDataModRunning.setCompletePercent(jsonObject.optDouble("complete_percent"));
464 mDataModRunning.setTime(jsonObject.optInt("time")); 465 mDataModRunning.setTime(jsonObject.optInt("time"));
465 mDataModRunning.setDistance(jsonObject.optInt("distance")); 466 mDataModRunning.setDistance(jsonObject.optInt("distance"));
466 mDataModRunning.setKcal(jsonObject.optInt("kcal")); 467 mDataModRunning.setKcal(jsonObject.optInt("kcal"));
467 468
468 JSONObject dataChart = jsonObject.optJSONObject("data_chart"); 469 JSONObject dataChart = jsonObject.optJSONObject("data_chart");
469 ArrayList<Integer> dataChartList = new ArrayList<>(); 470 ArrayList<Integer> dataChartList = new ArrayList<>();
470 dataChartList.add(dataChart.optInt("0")); 471 dataChartList.add(dataChart.optInt("0"));
471 dataChartList.add(dataChart.optInt("1")); 472 dataChartList.add(dataChart.optInt("1"));
472 dataChartList.add(dataChart.optInt("2")); 473 dataChartList.add(dataChart.optInt("2"));
473 dataChartList.add(dataChart.optInt("3")); 474 dataChartList.add(dataChart.optInt("3"));
474 dataChartList.add(dataChart.optInt("4")); 475 dataChartList.add(dataChart.optInt("4"));
475 dataChartList.add(dataChart.optInt("5")); 476 dataChartList.add(dataChart.optInt("5"));
476 dataChartList.add(dataChart.optInt("6")); 477 dataChartList.add(dataChart.optInt("6"));
477 dataChartList.add(dataChart.optInt("7")); 478 dataChartList.add(dataChart.optInt("7"));
478 dataChartList.add(dataChart.optInt("8")); 479 dataChartList.add(dataChart.optInt("8"));
479 dataChartList.add(dataChart.optInt("9")); 480 dataChartList.add(dataChart.optInt("9"));
480 dataChartList.add(dataChart.optInt("10")); 481 dataChartList.add(dataChart.optInt("10"));
481 dataChartList.add(dataChart.optInt("11")); 482 dataChartList.add(dataChart.optInt("11"));
482 dataChartList.add(dataChart.optInt("12")); 483 dataChartList.add(dataChart.optInt("12"));
483 dataChartList.add(dataChart.optInt("13")); 484 dataChartList.add(dataChart.optInt("13"));
484 dataChartList.add(dataChart.optInt("14")); 485 dataChartList.add(dataChart.optInt("14"));
485 dataChartList.add(dataChart.optInt("15")); 486 dataChartList.add(dataChart.optInt("15"));
486 dataChartList.add(dataChart.optInt("16")); 487 dataChartList.add(dataChart.optInt("16"));
487 dataChartList.add(dataChart.optInt("17")); 488 dataChartList.add(dataChart.optInt("17"));
488 dataChartList.add(dataChart.optInt("18")); 489 dataChartList.add(dataChart.optInt("18"));
489 dataChartList.add(dataChart.optInt("19")); 490 dataChartList.add(dataChart.optInt("19"));
490 dataChartList.add(dataChart.optInt("20")); 491 dataChartList.add(dataChart.optInt("20"));
491 dataChartList.add(dataChart.optInt("21")); 492 dataChartList.add(dataChart.optInt("21"));
492 dataChartList.add(dataChart.optInt("22")); 493 dataChartList.add(dataChart.optInt("22"));
493 dataChartList.add(dataChart.optInt("23")); 494 dataChartList.add(dataChart.optInt("23"));
494 495
495 mDataModRunning.setDataChart(dataChartList); 496 mDataModRunning.setDataChart(dataChartList);
496 } 497 }
497 498
498 private void addDataModBike(JSONObject jsonObject){ 499 private void addDataModBike(JSONObject jsonObject){
499 if (jsonObject == null) return; 500 if (jsonObject == null) return;
500 mDataModBike.setTaget(jsonObject.optInt("target")); 501 mDataModBike.setTaget(jsonObject.optInt("target"));
501 mDataModBike.setSteps(jsonObject.optInt("steps")); 502 mDataModBike.setSteps(jsonObject.optInt("steps"));
502 mDataModBike.setStepRemain(jsonObject.optInt("step_remain")); 503 mDataModBike.setStepRemain(jsonObject.optInt("step_remain"));
503 mDataModBike.setCompletePercent(jsonObject.optDouble("complete_percent")); 504 mDataModBike.setCompletePercent(jsonObject.optDouble("complete_percent"));
504 mDataModBike.setTime(jsonObject.optInt("time")); 505 mDataModBike.setTime(jsonObject.optInt("time"));
505 mDataModBike.setDistance(jsonObject.optInt("distance")); 506 mDataModBike.setDistance(jsonObject.optInt("distance"));
506 mDataModBike.setKcal(jsonObject.optInt("kcal")); 507 mDataModBike.setKcal(jsonObject.optInt("kcal"));
507 508
508 JSONObject dataChart = jsonObject.optJSONObject("data_chart"); 509 JSONObject dataChart = jsonObject.optJSONObject("data_chart");
509 ArrayList<Integer> dataChartList = new ArrayList<>(); 510 ArrayList<Integer> dataChartList = new ArrayList<>();
510 dataChartList.add(dataChart.optInt("0")); 511 dataChartList.add(dataChart.optInt("0"));
511 dataChartList.add(dataChart.optInt("1")); 512 dataChartList.add(dataChart.optInt("1"));
512 dataChartList.add(dataChart.optInt("2")); 513 dataChartList.add(dataChart.optInt("2"));
513 dataChartList.add(dataChart.optInt("3")); 514 dataChartList.add(dataChart.optInt("3"));
514 dataChartList.add(dataChart.optInt("4")); 515 dataChartList.add(dataChart.optInt("4"));
515 dataChartList.add(dataChart.optInt("5")); 516 dataChartList.add(dataChart.optInt("5"));
516 dataChartList.add(dataChart.optInt("6")); 517 dataChartList.add(dataChart.optInt("6"));
517 dataChartList.add(dataChart.optInt("7")); 518 dataChartList.add(dataChart.optInt("7"));
518 dataChartList.add(dataChart.optInt("8")); 519 dataChartList.add(dataChart.optInt("8"));
519 dataChartList.add(dataChart.optInt("9")); 520 dataChartList.add(dataChart.optInt("9"));
520 dataChartList.add(dataChart.optInt("10")); 521 dataChartList.add(dataChart.optInt("10"));
521 dataChartList.add(dataChart.optInt("11")); 522 dataChartList.add(dataChart.optInt("11"));
522 dataChartList.add(dataChart.optInt("12")); 523 dataChartList.add(dataChart.optInt("12"));
523 dataChartList.add(dataChart.optInt("13")); 524 dataChartList.add(dataChart.optInt("13"));
524 dataChartList.add(dataChart.optInt("14")); 525 dataChartList.add(dataChart.optInt("14"));
525 dataChartList.add(dataChart.optInt("15")); 526 dataChartList.add(dataChart.optInt("15"));
526 dataChartList.add(dataChart.optInt("16")); 527 dataChartList.add(dataChart.optInt("16"));
527 dataChartList.add(dataChart.optInt("17")); 528 dataChartList.add(dataChart.optInt("17"));
528 dataChartList.add(dataChart.optInt("18")); 529 dataChartList.add(dataChart.optInt("18"));
529 dataChartList.add(dataChart.optInt("19")); 530 dataChartList.add(dataChart.optInt("19"));
530 dataChartList.add(dataChart.optInt("20")); 531 dataChartList.add(dataChart.optInt("20"));
531 dataChartList.add(dataChart.optInt("21")); 532 dataChartList.add(dataChart.optInt("21"));
532 dataChartList.add(dataChart.optInt("22")); 533 dataChartList.add(dataChart.optInt("22"));
533 dataChartList.add(dataChart.optInt("23")); 534 dataChartList.add(dataChart.optInt("23"));
534 535
535 mDataModBike.setDataChart(dataChartList); 536 mDataModBike.setDataChart(dataChartList);
536 } 537 }
537 538
538 @OnClick({R.id.btn_oneDay, R.id.btn_oneWeek, R.id.btn_oneMonth, R.id.btn_threeMonth, 539 @OnClick({R.id.btn_oneDay, R.id.btn_oneWeek, R.id.btn_oneMonth, R.id.btn_threeMonth,
539 R.id.btn_sixMonth, R.id.btn_left_date, R.id.btn_right_date, R.id.ll_bike, 540 R.id.btn_sixMonth, R.id.btn_left_date, R.id.btn_right_date, R.id.ll_bike,
540 R.id.ll_walking, R.id.ll_running, R.id.rl_stepView}) 541 R.id.ll_walking, R.id.ll_running, R.id.rl_stepView})
541 public void onClick(View v){ 542 public void onClick(View v){
542 switch (v.getId()){ 543 switch (v.getId()){
543 case R.id.btn_left_date: 544 case R.id.btn_left_date:
544 mCalendar = Calendar.getInstance(); 545 mCalendar = Calendar.getInstance();
545 mCalendar.setTime(mAnaDate); 546 mCalendar.setTime(mAnaDate);
546 mCalendar.add(Calendar.DAY_OF_MONTH, -1); 547 mCalendar.add(Calendar.DAY_OF_MONTH, -1);
547 Date date = mCalendar.getTime(); 548 Date date = mCalendar.getTime();
548 tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(date)); 549 tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(date));
549 tvWeekDay.setText(Utils.getWeekdayFromDate(date)); 550 tvWeekDay.setText(Utils.getWeekdayFromDate(date));
550 mAnaDate = date; 551 mAnaDate = date;
551 getHistoryData(dataType, mAnaDate); 552 getHistoryData(dataType, mAnaDate);
552 break; 553 break;
553 554
554 case R.id.btn_right_date: 555 case R.id.btn_right_date:
555 mCalendar = Calendar.getInstance(); 556 mCalendar = Calendar.getInstance();
556 mCalendar.setTime(mAnaDate); 557 mCalendar.setTime(mAnaDate);
557 mCalendar.add(Calendar.DAY_OF_MONTH, +1); 558 mCalendar.add(Calendar.DAY_OF_MONTH, +1);
558 Date date1 = mCalendar.getTime(); 559 Date date1 = mCalendar.getTime();
559 tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(date1)); 560 tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(date1));
560 tvWeekDay.setText(Utils.getWeekdayFromDate(date1)); 561 tvWeekDay.setText(Utils.getWeekdayFromDate(date1));
561 mAnaDate = date1; 562 mAnaDate = date1;
562 getHistoryData(dataType, mAnaDate); 563 getHistoryData(dataType, mAnaDate);
563 break; 564 break;
564 565
565 case R.id.btn_oneDay: 566 case R.id.btn_oneDay:
566 dataType = Const.DATA_TYPE.ONE_DAY; 567 dataType = Const.DATA_TYPE.ONE_DAY;
567 updateUiType(); 568 updateUiType();
568 getHistoryData(dataType, mAnaDate); 569 getHistoryData(dataType, mAnaDate);
569 break; 570 break;
570 571
571 case R.id.btn_oneWeek: 572 case R.id.btn_oneWeek:
572 dataType = Const.DATA_TYPE.ONE_WEEK; 573 dataType = Const.DATA_TYPE.ONE_WEEK;
573 updateUiType(); 574 updateUiType();
574 getHistoryData(dataType, mAnaDate); 575 getHistoryData(dataType, mAnaDate);
575 break; 576 break;
576 577
577 case R.id.btn_oneMonth: 578 case R.id.btn_oneMonth:
578 dataType = Const.DATA_TYPE.ONE_MONTH; 579 dataType = Const.DATA_TYPE.ONE_MONTH;
579 updateUiType(); 580 updateUiType();
580 getHistoryData(dataType, mAnaDate); 581 getHistoryData(dataType, mAnaDate);
581 break; 582 break;
582 583
583 case R.id.btn_threeMonth: 584 case R.id.btn_threeMonth:
584 dataType = Const.DATA_TYPE.THREE_MONTH; 585 dataType = Const.DATA_TYPE.THREE_MONTH;
585 updateUiType(); 586 updateUiType();
586 getHistoryData(dataType, mAnaDate); 587 getHistoryData(dataType, mAnaDate);
587 break; 588 break;
588 589
589 case R.id.btn_sixMonth: 590 case R.id.btn_sixMonth:
590 dataType = Const.DATA_TYPE.SIX_MONTH; 591 dataType = Const.DATA_TYPE.SIX_MONTH;
591 updateUiType(); 592 updateUiType();
592 getHistoryData(dataType, mAnaDate); 593 getHistoryData(dataType, mAnaDate);
593 break; 594 break;
594 595
595 case R.id.tv_date: 596 case R.id.tv_date:
596 handleAnaDatePicker(); 597 handleAnaDatePicker();
597 break; 598 break;
598 599
599 case R.id.ll_bike: 600 case R.id.ll_bike:
600 stepType = Const.STEP_TYPE.BIKE; 601 stepType = Const.STEP_TYPE.BIKE;
601 updateUiStepType(true, false, false); 602 updateUiStepType(true, false, false);
602 // add data 603 // add data
603 mDataCurrent = mDataModBike; 604 mDataCurrent = mDataModBike;
604 updateUI(); 605 updateUI();
605 break; 606 break;
606 607
607 case R.id.ll_walking: 608 case R.id.ll_walking:
608 stepType = Const.STEP_TYPE.WALKING; 609 stepType = Const.STEP_TYPE.WALKING;
609 updateUiStepType(false, true, false); 610 updateUiStepType(false, true, false);
610 // add data 611 // add data
611 mDataCurrent = mDataModWalking; 612 mDataCurrent = mDataModWalking;
612 updateUI(); 613 updateUI();
613 break; 614 break;
614 615
615 case R.id.ll_running: 616 case R.id.ll_running:
616 stepType = Const.STEP_TYPE.RUNNING; 617 stepType = Const.STEP_TYPE.RUNNING;
617 updateUiStepType(false, false, true); 618 updateUiStepType(false, false, true);
618 // add 619 // add
619 mDataCurrent = mDataModRunning; 620 mDataCurrent = mDataModRunning;
620 updateUI(); 621 updateUI();
621 break; 622 break;
622 623
623 case R.id.rl_stepView: 624 case R.id.rl_stepView:
624 mHistoryFragment.showDetailFragment(); 625 mHistoryFragment.showDetailFragment();
625 break; 626 break;
626 627
627 default: 628 default:
628 break; 629 break;
629 } 630 }
630 } 631 }
631 632
632 @Override 633 @Override
633 public void onActivityResult(int requestCode, int resultCode, Intent data) { 634 public void onActivityResult(int requestCode, int resultCode, Intent data) {
634 super.onActivityResult(requestCode, resultCode, data); 635 super.onActivityResult(requestCode, resultCode, data);
635 636
636 } 637 }
637 } 638 }
638 639
app/src/main/java/com/dinhcv/lifelogpedometer/activity/HistoryDetailFragment.java
1 package com.dinhcv.lifelogpedometer.activity; 1 package com.dinhcv.lifelogpedometer.activity;
2 2
3 import android.app.DatePickerDialog; 3 import android.app.DatePickerDialog;
4 import android.content.Context; 4 import android.content.Context;
5 import android.os.Bundle; 5 import android.os.Bundle;
6 import android.view.LayoutInflater; 6 import android.view.LayoutInflater;
7 import android.view.View; 7 import android.view.View;
8 import android.view.ViewGroup; 8 import android.view.ViewGroup;
9 import android.widget.Button; 9 import android.widget.Button;
10 import android.widget.DatePicker; 10 import android.widget.DatePicker;
11 import android.widget.EditText; 11 import android.widget.EditText;
12 import android.widget.ImageButton; 12 import android.widget.ImageButton;
13 import android.widget.LinearLayout; 13 import android.widget.LinearLayout;
14 import android.widget.ProgressBar; 14 import android.widget.ProgressBar;
15 import android.widget.TextView; 15 import android.widget.TextView;
16 16
17 import com.dinhcv.lifelogpedometer.R; 17 import com.dinhcv.lifelogpedometer.R;
18 import com.dinhcv.lifelogpedometer.adapter.HistoryAdapter; 18 import com.dinhcv.lifelogpedometer.adapter.HistoryAdapter;
19 import com.dinhcv.lifelogpedometer.customview.ExpandableListCustomView; 19 import com.dinhcv.lifelogpedometer.customview.ExpandableListCustomView;
20 import com.dinhcv.lifelogpedometer.interfaces.LLAPIManagerListener; 20 import com.dinhcv.lifelogpedometer.interfaces.LLAPIManagerListener;
21 import com.dinhcv.lifelogpedometer.model.structure.history.HistoryInfo; 21 import com.dinhcv.lifelogpedometer.model.structure.history.HistoryInfo;
22 import com.dinhcv.lifelogpedometer.model.structure.history.HistoryItemInfo; 22 import com.dinhcv.lifelogpedometer.model.structure.history.HistoryItemInfo;
23 import com.dinhcv.lifelogpedometer.portal.ApiServices;
23 import com.dinhcv.lifelogpedometer.portal.LLAPIManager; 24 import com.dinhcv.lifelogpedometer.portal.LLAPIManager;
24 import com.dinhcv.lifelogpedometer.utils.Const; 25 import com.dinhcv.lifelogpedometer.utils.Const;
25 import com.dinhcv.lifelogpedometer.utils.Debug; 26 import com.dinhcv.lifelogpedometer.utils.Debug;
26 import com.dinhcv.lifelogpedometer.utils.Utils; 27 import com.dinhcv.lifelogpedometer.utils.Utils;
27 28
28 import org.json.JSONException; 29 import org.json.JSONException;
29 import org.json.JSONObject; 30 import org.json.JSONObject;
30 31
31 import java.util.ArrayList; 32 import java.util.ArrayList;
32 import java.util.Calendar; 33 import java.util.Calendar;
33 import java.util.Date; 34 import java.util.Date;
34 import java.util.HashMap; 35 import java.util.HashMap;
35 import java.util.List; 36 import java.util.List;
36 import java.util.Map; 37 import java.util.Map;
37 38
38 import butterknife.BindView; 39 import butterknife.BindView;
39 import butterknife.ButterKnife; 40 import butterknife.ButterKnife;
40 import butterknife.OnClick; 41 import butterknife.OnClick;
41 import retrofit2.Callback; 42 import retrofit2.Callback;
42 43
43 44
44 public class HistoryDetailFragment extends FragmentBase { 45 public class HistoryDetailFragment extends FragmentBase {
45 private View mRootView; 46 private View mRootView;
46 47
47 @BindView(R.id.btn_left_date) 48 @BindView(R.id.btn_left_date)
48 ImageButton btnLeftDate; 49 ImageButton btnLeftDate;
49 @BindView(R.id.btn_right_date) 50 @BindView(R.id.btn_right_date)
50 ImageButton btnRightDate; 51 ImageButton btnRightDate;
51 @BindView(R.id.tv_date) 52 @BindView(R.id.tv_date)
52 TextView tvDate; 53 TextView tvDate;
53 @BindView(R.id.tv_week_day) 54 @BindView(R.id.tv_week_day)
54 TextView tvWeekDay; 55 TextView tvWeekDay;
55 @BindView(R.id.ll_bike) 56 @BindView(R.id.ll_bike)
56 LinearLayout llBike; 57 LinearLayout llBike;
57 @BindView(R.id.ll_walking) 58 @BindView(R.id.ll_walking)
58 LinearLayout llWalking; 59 LinearLayout llWalking;
59 @BindView(R.id.ll_running) 60 @BindView(R.id.ll_running)
60 LinearLayout llRunning; 61 LinearLayout llRunning;
61 @BindView(R.id.lv_history) 62 @BindView(R.id.lv_history)
62 ExpandableListCustomView lvHistory; 63 ExpandableListCustomView lvHistory;
63 private HistoryAdapter mHistoreAdapter; 64 private HistoryAdapter mHistoreAdapter;
64 65
65 66
66 @BindView(R.id.btn_sixMonth) 67 @BindView(R.id.btn_sixMonth)
67 Button btnSixMonth; 68 Button btnSixMonth;
68 @BindView(R.id.btn_oneDay) 69 @BindView(R.id.btn_oneDay)
69 Button btnOneDay; 70 Button btnOneDay;
70 @BindView(R.id.btn_oneWeek) 71 @BindView(R.id.btn_oneWeek)
71 Button btnOneWeek; 72 Button btnOneWeek;
72 @BindView(R.id.btn_oneMonth) 73 @BindView(R.id.btn_oneMonth)
73 Button btnOneMonth; 74 Button btnOneMonth;
74 @BindView(R.id.btn_threeMonth) 75 @BindView(R.id.btn_threeMonth)
75 Button btnThreeMonth; 76 Button btnThreeMonth;
76 77
77 private Date mAnaDate; 78 private Date mAnaDate;
78 private Calendar mCalendar; 79 private Calendar mCalendar;
79 80
80 private int mAnaDay; 81 private int mAnaDay;
81 private int mAnaMonth; 82 private int mAnaMonth;
82 private int mAnaYear; 83 private int mAnaYear;
83 private Context mContext; 84 private Context mContext;
84 private Const.DATA_TYPE dataType; 85 private Const.DATA_TYPE dataType;
85 private Const.STEP_TYPE stepType; 86 private Const.STEP_TYPE stepType;
86 87
87 private List<HistoryItemInfo> mDataModWalking = new ArrayList<>(); 88 private List<HistoryItemInfo> mDataModWalking = new ArrayList<>();
88 private List<HistoryItemInfo> mDataModRunning = new ArrayList<>(); 89 private List<HistoryItemInfo> mDataModRunning = new ArrayList<>();
89 private List<HistoryItemInfo> mDataModBike = new ArrayList<>(); 90 private List<HistoryItemInfo> mDataModBike = new ArrayList<>();
90 private List<HistoryItemInfo> mDataCurrent = new ArrayList<>(); 91 private List<HistoryItemInfo> mDataCurrent = new ArrayList<>();
91 92
92 private HistoryFragment mHistoryFragment; 93 private HistoryFragment mHistoryFragment;
93 94
94 public void setRootFragment(HistoryFragment frag) { 95 public void setRootFragment(HistoryFragment frag) {
95 this.mHistoryFragment = frag; 96 this.mHistoryFragment = frag;
96 } 97 }
97 98
98 @Override 99 @Override
99 public View onCreateView(final LayoutInflater inflater,final ViewGroup container, 100 public View onCreateView(final LayoutInflater inflater,final ViewGroup container,
100 final Bundle savedInstanceState) { 101 final Bundle savedInstanceState) {
101 // Inflate the layout for this fragment 102 // Inflate the layout for this fragment
102 mRootView = inflater.inflate(R.layout.fragment_history_detail, null); 103 mRootView = inflater.inflate(R.layout.fragment_history_detail, null);
103 ButterKnife.bind(this, mRootView); 104 ButterKnife.bind(this, mRootView);
104 mContext = getActivity(); 105 mContext = getActivity();
105 initView(); 106 initView();
106 initData(); 107 initData();
107 108
108 return mRootView; 109 return mRootView;
109 } 110 }
110 111
111 private void initView() { 112 private void initView() {
112 113
113 } 114 }
114 115
115 /** 116 /**
116 * init data for 117 * init data for
117 */ 118 */
118 private void initData() { 119 private void initData() {
119 mCalendar = Calendar.getInstance(); 120 mCalendar = Calendar.getInstance();
120 mCalendar.setTime(new Date()); 121 mCalendar.setTime(new Date());
121 mAnaDate = mCalendar.getTime(); 122 mAnaDate = mCalendar.getTime();
122 mAnaYear = mCalendar.get(Calendar.YEAR); 123 mAnaYear = mCalendar.get(Calendar.YEAR);
123 mAnaMonth = mCalendar.get(Calendar.MONTH); 124 mAnaMonth = mCalendar.get(Calendar.MONTH);
124 mAnaDay = mCalendar.get(Calendar.DAY_OF_MONTH); 125 mAnaDay = mCalendar.get(Calendar.DAY_OF_MONTH);
125 126
126 tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(mAnaDate)); 127 tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(mAnaDate));
127 tvWeekDay.setText(Utils.getWeekdayFromDate(mAnaDate)); 128 tvWeekDay.setText(Utils.getWeekdayFromDate(mAnaDate));
128 129
129 dataType = Const.DATA_TYPE.ONE_DAY; 130 dataType = Const.DATA_TYPE.ONE_DAY;
130 stepType = Const.STEP_TYPE.WALKING; 131 stepType = Const.STEP_TYPE.WALKING;
131 updateUiType(); 132 updateUiType();
132 updateUiStepType(false, true, false); 133 updateUiStepType(false, true, false);
133 134
134 getHistoryDetail(dataType, mAnaDate); 135 getHistoryDetail(dataType, mAnaDate);
135 } 136 }
136 137
137 138
138 /** 139 /**
139 * Show date picker dialog 140 * Show date picker dialog
140 */ 141 */
141 private void handleAnaDatePicker() { 142 private void handleAnaDatePicker() {
142 143
143 new DatePickerDialog(mContext, new DatePickerDialog.OnDateSetListener() { 144 new DatePickerDialog(mContext, new DatePickerDialog.OnDateSetListener() {
144 @Override 145 @Override
145 public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { 146 public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
146 147
147 mCalendar = Calendar.getInstance(); 148 mCalendar = Calendar.getInstance();
148 mCalendar.set(year, monthOfYear, dayOfMonth); 149 mCalendar.set(year, monthOfYear, dayOfMonth);
149 mAnaYear = year; 150 mAnaYear = year;
150 mAnaMonth = monthOfYear; 151 mAnaMonth = monthOfYear;
151 mAnaDay = dayOfMonth; 152 mAnaDay = dayOfMonth;
152 Date date = mCalendar.getTime(); 153 Date date = mCalendar.getTime();
153 tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(date)); 154 tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(date));
154 tvWeekDay.setText(Utils.getWeekdayFromDate(date)); 155 tvWeekDay.setText(Utils.getWeekdayFromDate(date));
155 mAnaDate = date; 156 mAnaDate = date;
156 getHistoryDetail(dataType, mAnaDate); 157 getHistoryDetail(dataType, mAnaDate);
157 } 158 }
158 }, mAnaYear, mAnaMonth, mAnaDay).show(); 159 }, mAnaYear, mAnaMonth, mAnaDay).show();
159 160
160 } 161 }
161 162
162 private void updateUiType() { 163 private void updateUiType() {
163 if (dataType == Const.DATA_TYPE.ONE_DAY) { 164 if (dataType == Const.DATA_TYPE.ONE_DAY) {
164 setButtonSelected(true, false, false, false, false); 165 setButtonSelected(true, false, false, false, false);
165 } else if (dataType == Const.DATA_TYPE.ONE_WEEK) { 166 } else if (dataType == Const.DATA_TYPE.ONE_WEEK) {
166 setButtonSelected(false, true, false, false, false); 167 setButtonSelected(false, true, false, false, false);
167 } else if (dataType == Const.DATA_TYPE.ONE_MONTH) { 168 } else if (dataType == Const.DATA_TYPE.ONE_MONTH) {
168 setButtonSelected(false, false, true, false, false); 169 setButtonSelected(false, false, true, false, false);
169 } else if (dataType == Const.DATA_TYPE.THREE_MONTH){ 170 } else if (dataType == Const.DATA_TYPE.THREE_MONTH){
170 setButtonSelected(false, false, false, true, false); 171 setButtonSelected(false, false, false, true, false);
171 } else if (dataType == Const.DATA_TYPE.SIX_MONTH){ 172 } else if (dataType == Const.DATA_TYPE.SIX_MONTH){
172 setButtonSelected(false, false, false, false, true); 173 setButtonSelected(false, false, false, false, true);
173 } 174 }
174 } 175 }
175 176
176 private void setButtonSelected(boolean b1, boolean b2, boolean b3, boolean b4, boolean b5 ) { 177 private void setButtonSelected(boolean b1, boolean b2, boolean b3, boolean b4, boolean b5 ) {
177 btnOneDay.setSelected(b1); 178 btnOneDay.setSelected(b1);
178 btnOneWeek.setSelected(b2); 179 btnOneWeek.setSelected(b2);
179 btnOneMonth.setSelected(b3); 180 btnOneMonth.setSelected(b3);
180 btnThreeMonth.setSelected(b4); 181 btnThreeMonth.setSelected(b4);
181 btnSixMonth.setSelected(b5); 182 btnSixMonth.setSelected(b5);
182 } 183 }
183 184
184 private void updateUiStepType(boolean b1, boolean b2, boolean b3) { 185 private void updateUiStepType(boolean b1, boolean b2, boolean b3) {
185 llBike.setSelected(b1); 186 llBike.setSelected(b1);
186 llWalking.setSelected(b2); 187 llWalking.setSelected(b2);
187 llRunning.setSelected(b3); 188 llRunning.setSelected(b3);
188 } 189 }
189 190
190 private void updateUI(){ 191 private void updateUI(){
191 // get data server 192 // get data server
192 if (mDataCurrent != null && mDataCurrent.size() >0){ 193 if (mDataCurrent != null && mDataCurrent.size() >0){
193 mHistoreAdapter = new HistoryAdapter(mContext, mDataCurrent); 194 mHistoreAdapter = new HistoryAdapter(mContext, mDataCurrent);
194 lvHistory.setAdapter(mHistoreAdapter); 195 lvHistory.setAdapter(mHistoreAdapter);
195 lvHistory.setExpanded(true); 196 lvHistory.setExpanded(true);
196 } 197 }
197 } 198 }
198 199
199 private void getHistoryDetail(Const.DATA_TYPE dataType, Date toDate){ 200 private void getHistoryDetail(Const.DATA_TYPE dataType, Date toDate){
200 Date fromDate = Utils.getFromDate(mAnaDate, dataType); 201 Date fromDate = Utils.getFromDate(mAnaDate, dataType);
201 202
202 showDialog(mContext); 203 showDialog(mContext);
203 LLAPIManager.historyDetail(fromDate, toDate, new LLAPIManagerListener() { 204 ApiServices.historyDetail(fromDate, toDate, new LLAPIManagerListener() {
204 @Override 205 @Override
205 public void onError(Error error) { 206 public void onError(Error error) {
206 Debug.error("Get data history error"); 207 Debug.error("Get data history error");
207 hiddenDialog(); 208 hiddenDialog();
208 showDialogNotData(); 209 showDialogNotData();
209 } 210 }
210 211
211 @Override 212 @Override
212 public void onSuccess(String json) { 213 public void onSuccess(String json) {
213 Debug.error("Get data history success"); 214 Debug.error("Get data history success");
214 hiddenDialog(); 215 hiddenDialog();
215 loadDataDone(json); 216 loadDataDone(json);
216 } 217 }
217 218
218 @Override 219 @Override
219 public void onSuccess(JSONObject object) { 220 public void onSuccess(JSONObject object) {
220 Debug.error("Get data history success"); 221 Debug.error("Get data history success");
221 hiddenDialog(); 222 hiddenDialog();
222 } 223 }
223 }); 224 });
224 } 225 }
225 226
226 private void showDialogNotData(){ 227 private void showDialogNotData(){
227 showAlerDialog(mContext, getResources().getString(R.string.can_not_get_data)); 228 showAlerDialog(mContext, getResources().getString(R.string.can_not_get_data));
228 } 229 }
229 230
230 private void loadDataDone(String jsonString) { 231 private void loadDataDone(String jsonString) {
231 JSONObject jsonObject = null; 232 JSONObject jsonObject = null;
232 try { 233 try {
233 jsonObject = new JSONObject(jsonString); 234 jsonObject = new JSONObject(jsonString);
234 int status = jsonObject.optInt("status"); 235 int status = jsonObject.optInt("status");
235 if (status == 1) { 236 if (status == 1) {
236 JSONObject jsonObject1 = jsonObject.optJSONObject("result"); 237 JSONObject jsonObject1 = jsonObject.optJSONObject("result");
237 JSONObject jsonMod1 = jsonObject1.getJSONObject("mode_1"); 238 JSONObject jsonMod1 = jsonObject1.getJSONObject("mode_1");
238 JSONObject jsonMod2 = jsonObject1.getJSONObject("mode_2"); 239 JSONObject jsonMod2 = jsonObject1.getJSONObject("mode_2");
239 JSONObject jsonMod3 = jsonObject1.getJSONObject("mode_3"); 240 JSONObject jsonMod3 = jsonObject1.getJSONObject("mode_3");
240 //addDataModWalking(jsonMod1); 241 //addDataModWalking(jsonMod1);
241 //addDataModRunning(jsonMod2); 242 //addDataModRunning(jsonMod2);
242 //addDataModBike(jsonMod3); 243 //addDataModBike(jsonMod3);
243 244
244 } 245 }
245 } catch (JSONException e) { 246 } catch (JSONException e) {
246 e.printStackTrace(); 247 e.printStackTrace();
247 mDataModWalking.clear(); 248 mDataModWalking.clear();
248 mDataModRunning.clear();; 249 mDataModRunning.clear();;
249 mDataModBike.clear();; 250 mDataModBike.clear();;
250 } 251 }
251 252
252 if (stepType == Const.STEP_TYPE.WALKING){ 253 if (stepType == Const.STEP_TYPE.WALKING){
253 mDataCurrent = mDataModWalking; 254 mDataCurrent = mDataModWalking;
254 }else if (stepType == Const.STEP_TYPE.RUNNING){ 255 }else if (stepType == Const.STEP_TYPE.RUNNING){
255 mDataCurrent = mDataModRunning; 256 mDataCurrent = mDataModRunning;
256 }else { 257 }else {
257 mDataCurrent = mDataModBike; 258 mDataCurrent = mDataModBike;
258 } 259 }
259 260
260 updateUI(); 261 updateUI();
261 } 262 }
262 263
263 @OnClick({R.id.tv_date, R.id.btn_left_date, R.id.btn_right_date, R.id.btn_oneDay, R.id.btn_oneWeek, 264 @OnClick({R.id.tv_date, R.id.btn_left_date, R.id.btn_right_date, R.id.btn_oneDay, R.id.btn_oneWeek,
264 R.id.btn_oneMonth, R.id.btn_threeMonth, R.id.btn_sixMonth, R.id.ll_walking, R.id.ll_bike, 265 R.id.btn_oneMonth, R.id.btn_threeMonth, R.id.btn_sixMonth, R.id.ll_walking, R.id.ll_bike,
265 R.id.ll_running}) 266 R.id.ll_running})
266 public void onClick(View view){ 267 public void onClick(View view){
267 Date date; 268 Date date;
268 switch (view.getId()){ 269 switch (view.getId()){
269 case R.id.tv_date: 270 case R.id.tv_date:
270 handleAnaDatePicker(); 271 handleAnaDatePicker();
271 break; 272 break;
272 case R.id.btn_left_date: 273 case R.id.btn_left_date:
273 mCalendar = Calendar.getInstance(); 274 mCalendar = Calendar.getInstance();
274 mCalendar.setTime(mAnaDate); 275 mCalendar.setTime(mAnaDate);
275 mCalendar.add(Calendar.DAY_OF_MONTH, -1); 276 mCalendar.add(Calendar.DAY_OF_MONTH, -1);
276 date = mCalendar.getTime(); 277 date = mCalendar.getTime();
277 tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(date)); 278 tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(date));
278 tvWeekDay.setText(Utils.getWeekdayFromDate(date)); 279 tvWeekDay.setText(Utils.getWeekdayFromDate(date));
279 mAnaDate = date; 280 mAnaDate = date;
280 getHistoryDetail(dataType, mAnaDate); 281 getHistoryDetail(dataType, mAnaDate);
281 break; 282 break;
282 283
283 case R.id.btn_right_date: 284 case R.id.btn_right_date:
284 mCalendar = Calendar.getInstance(); 285 mCalendar = Calendar.getInstance();
285 mCalendar.setTime(mAnaDate); 286 mCalendar.setTime(mAnaDate);
286 mCalendar.add(Calendar.DAY_OF_MONTH, +1); 287 mCalendar.add(Calendar.DAY_OF_MONTH, +1);
287 date = mCalendar.getTime(); 288 date = mCalendar.getTime();
288 tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(date)); 289 tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(date));
289 tvWeekDay.setText(Utils.getWeekdayFromDate(date)); 290 tvWeekDay.setText(Utils.getWeekdayFromDate(date));
290 mAnaDate = date; 291 mAnaDate = date;
291 getHistoryDetail(dataType, mAnaDate); 292 getHistoryDetail(dataType, mAnaDate);
292 break; 293 break;
293 294
294 case R.id.btn_oneDay: 295 case R.id.btn_oneDay:
295 dataType = Const.DATA_TYPE.ONE_DAY; 296 dataType = Const.DATA_TYPE.ONE_DAY;
296 updateUiType(); 297 updateUiType();
297 getHistoryDetail(dataType, mAnaDate); 298 getHistoryDetail(dataType, mAnaDate);
298 break; 299 break;
299 300
300 case R.id.btn_oneWeek: 301 case R.id.btn_oneWeek:
301 dataType = Const.DATA_TYPE.ONE_WEEK; 302 dataType = Const.DATA_TYPE.ONE_WEEK;
302 updateUiType(); 303 updateUiType();
303 getHistoryDetail(dataType, mAnaDate); 304 getHistoryDetail(dataType, mAnaDate);
304 break; 305 break;
305 306
306 case R.id.btn_oneMonth: 307 case R.id.btn_oneMonth:
307 dataType = Const.DATA_TYPE.ONE_MONTH; 308 dataType = Const.DATA_TYPE.ONE_MONTH;
308 updateUiType(); 309 updateUiType();
309 getHistoryDetail(dataType, mAnaDate); 310 getHistoryDetail(dataType, mAnaDate);
310 break; 311 break;
311 312
312 case R.id.btn_threeMonth: 313 case R.id.btn_threeMonth:
313 dataType = Const.DATA_TYPE.THREE_MONTH; 314 dataType = Const.DATA_TYPE.THREE_MONTH;
314 updateUiType(); 315 updateUiType();
315 getHistoryDetail(dataType, mAnaDate); 316 getHistoryDetail(dataType, mAnaDate);
316 break; 317 break;
317 318
318 case R.id.btn_sixMonth: 319 case R.id.btn_sixMonth:
319 dataType = Const.DATA_TYPE.SIX_MONTH; 320 dataType = Const.DATA_TYPE.SIX_MONTH;
320 updateUiType(); 321 updateUiType();
321 getHistoryDetail(dataType, mAnaDate); 322 getHistoryDetail(dataType, mAnaDate);
322 break; 323 break;
323 324
324 case R.id.ll_walking: 325 case R.id.ll_walking:
325 stepType = Const.STEP_TYPE.WALKING; 326 stepType = Const.STEP_TYPE.WALKING;
326 updateUiStepType(false, true, false); 327 updateUiStepType(false, true, false);
327 // add data 328 // add data
328 mDataCurrent = mDataModWalking; 329 mDataCurrent = mDataModWalking;
329 updateUI(); 330 updateUI();
330 break; 331 break;
331 332
332 case R.id.ll_running: 333 case R.id.ll_running:
333 stepType = Const.STEP_TYPE.RUNNING; 334 stepType = Const.STEP_TYPE.RUNNING;
334 updateUiStepType(false, false, true); 335 updateUiStepType(false, false, true);
335 // add 336 // add
336 mDataCurrent = mDataModRunning; 337 mDataCurrent = mDataModRunning;
337 updateUI(); 338 updateUI();
338 break; 339 break;
339 340
340 case R.id.ll_bike: 341 case R.id.ll_bike:
341 stepType = Const.STEP_TYPE.BIKE; 342 stepType = Const.STEP_TYPE.BIKE;
342 updateUiStepType(true, false, false); 343 updateUiStepType(true, false, false);
343 // add data 344 // add data
344 mDataCurrent = mDataModBike; 345 mDataCurrent = mDataModBike;
345 updateUI(); 346 updateUI();
346 break; 347 break;
347 348
348 default: 349 default:
349 break; 350 break;
350 351
351 } 352 }
352 } 353 }
353 354
354 355
355 } 356 }
356 357
app/src/main/java/com/dinhcv/lifelogpedometer/activity/InputConfirmCodeActivity.java
1 package com.dinhcv.lifelogpedometer.activity; 1 package com.dinhcv.lifelogpedometer.activity;
2 2
3 import android.app.AlertDialog; 3 import android.app.AlertDialog;
4 import android.app.ProgressDialog; 4 import android.app.ProgressDialog;
5 import android.content.DialogInterface; 5 import android.content.DialogInterface;
6 import android.content.Intent; 6 import android.content.Intent;
7 import android.os.Bundle; 7 import android.os.Bundle;
8 import android.view.View; 8 import android.view.View;
9 import android.view.WindowManager; 9 import android.view.WindowManager;
10 import android.widget.Button; 10 import android.widget.Button;
11 import android.widget.TextView; 11 import android.widget.TextView;
12 12
13 import com.dinhcv.lifelogpedometer.R; 13 import com.dinhcv.lifelogpedometer.R;
14 import com.dinhcv.lifelogpedometer.interfaces.LLAPIManagerListener; 14 import com.dinhcv.lifelogpedometer.interfaces.LLAPIManagerListener;
15 import com.dinhcv.lifelogpedometer.model.Shareprefer.Setting; 15 import com.dinhcv.lifelogpedometer.model.Shareprefer.Setting;
16 import com.dinhcv.lifelogpedometer.portal.ApiServices;
16 import com.dinhcv.lifelogpedometer.portal.LLAPIManager; 17 import com.dinhcv.lifelogpedometer.portal.LLAPIManager;
17 import com.dinhcv.lifelogpedometer.utils.Const; 18 import com.dinhcv.lifelogpedometer.utils.Const;
18 import com.dinhcv.lifelogpedometer.utils.Debug; 19 import com.dinhcv.lifelogpedometer.utils.Debug;
19 20
20 import org.json.JSONObject; 21 import org.json.JSONObject;
21 22
22 import butterknife.BindView; 23 import butterknife.BindView;
23 import butterknife.ButterKnife; 24 import butterknife.ButterKnife;
24 import butterknife.OnClick; 25 import butterknife.OnClick;
25 26
26 public class InputConfirmCodeActivity extends ActivityBase { 27 public class InputConfirmCodeActivity extends ActivityBase {
27 28
28 @BindView(R.id.edt_confirmCode) 29 @BindView(R.id.edt_confirmCode)
29 TextView edtConfirmCode; 30 TextView edtConfirmCode;
30 @BindView(R.id.btn_confirm) 31 @BindView(R.id.btn_confirm)
31 Button btnConfirm; 32 Button btnConfirm;
32 33
33 private ProgressDialog progressDialog; 34 private ProgressDialog progressDialog;
34 private String mEmail; 35 private String mEmail;
35 36
36 @Override 37 @Override
37 protected void onCreate(Bundle savedInstanceState) { 38 protected void onCreate(Bundle savedInstanceState) {
38 super.onCreate(savedInstanceState); 39 super.onCreate(savedInstanceState);
39 setContentView(R.layout.activity_input_confirm_code); 40 setContentView(R.layout.activity_input_confirm_code);
40 ButterKnife.bind(this); 41 ButterKnife.bind(this);
41 getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN); 42 getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
42 Intent intent = getIntent(); 43 Intent intent = getIntent();
43 if (intent != null) { 44 if (intent != null) {
44 mEmail = intent.getStringExtra(Const.EMAIL); 45 mEmail = intent.getStringExtra(Const.EMAIL);
45 Debug.normal("Email request: "+mEmail); 46 Debug.normal("Email request: "+mEmail);
46 if(mEmail == null){ 47 if(mEmail == null){
47 Debug.error("Email is null"); 48 Debug.error("Email is null");
48 return; 49 return;
49 } 50 }
50 }else { 51 }else {
51 Debug.error("Email is null"); 52 Debug.error("Email is null");
52 return; 53 return;
53 } 54 }
54 55
55 } 56 }
56 57
57 private void handleGetNewPass(String code){ 58 private void handleGetNewPass(String code){
58 progressDialog = new ProgressDialog(InputConfirmCodeActivity.this); 59 progressDialog = new ProgressDialog(InputConfirmCodeActivity.this);
59 progressDialog.setMessage(getResources().getString(R.string.waite_some_minute)); 60 progressDialog.setMessage(getResources().getString(R.string.waite_some_minute));
60 progressDialog.setCancelable(false); 61 progressDialog.setCancelable(false);
61 progressDialog.show(); 62 progressDialog.show();
62 63
63 LLAPIManager.forgetPassConfirm(mEmail, code, new LLAPIManagerListener() { 64 ApiServices.forgetPassConfirm(mEmail, code, new LLAPIManagerListener() {
64 @Override 65 @Override
65 public void onError(Error error) { 66 public void onError(Error error) {
66 progressDialog.dismiss(); 67 progressDialog.dismiss();
67 Debug.error("Send confirm JSON result: ERROR " + error); 68 Debug.error("Send confirm JSON result: ERROR " + error);
68 String err = getResources().getString(R.string.request_pass_error); 69 String err = getResources().getString(R.string.request_pass_error);
69 notifyErr(err); 70 notifyErr(err);
70 } 71 }
71 72
72 @Override 73 @Override