Commit 5520a4b27df178a212e405aeaad6b3bbda41cd3d
1 parent
13594f58ae
Exists in
master
and in
1 other branch
update
Showing 17 changed files with 401 additions and 88 deletions Inline Diff
- .idea/misc.xml
- .idea/modules.xml
- app/build.gradle
- app/src/main/java/com/dinhcv/lifelogpedometer/activity/HistoryContentFragment.java
- app/src/main/java/com/dinhcv/lifelogpedometer/activity/HistoryDetailFragment.java
- app/src/main/java/com/dinhcv/lifelogpedometer/activity/InputConfirmCodeActivity.java
- app/src/main/java/com/dinhcv/lifelogpedometer/activity/LoginActivity.java
- app/src/main/java/com/dinhcv/lifelogpedometer/activity/RegisterActivity.java
- app/src/main/java/com/dinhcv/lifelogpedometer/activity/TopDateFragment.java
- app/src/main/java/com/dinhcv/lifelogpedometer/activity/TopTodayFragment.java
- app/src/main/java/com/dinhcv/lifelogpedometer/activity/WelcomeActivity.java
- app/src/main/java/com/dinhcv/lifelogpedometer/model/structure/home/NoticeInfo.java
- app/src/main/java/com/dinhcv/lifelogpedometer/portal/ApiServices.java
- app/src/main/java/com/dinhcv/lifelogpedometer/portal/LLAPIManager.java
- app/src/main/res/layout/fragment_history_content.xml
- build.gradle
- gradle/wrapper/gradle-wrapper.properties
.idea/misc.xml
| 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> |
.idea/modules.xml
| 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> |
app/build.gradle
| 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 |
| 73 | public void onSuccess(String json) { | 74 | public void onSuccess(String json) { |
| 74 | Debug.warn("Send confirm JSON result: " + json.toString()); | 75 | Debug.warn("Send confirm JSON result: " + json.toString()); |
| 75 | progressDialog.dismiss(); | 76 | progressDialog.dismiss(); |
| 76 | 77 | ||
| 77 | confirmDone(); | 78 | confirmDone(); |
| 78 | } | 79 | } |
| 79 | 80 | ||
| 80 | @Override | 81 | @Override |
| 81 | public void onSuccess(JSONObject object) { | 82 | public void onSuccess(JSONObject object) { |
| 82 | Debug.warn("Send confirm JSON object result: Success"); | 83 | Debug.warn("Send confirm JSON object result: Success"); |
| 83 | progressDialog.dismiss(); | 84 | progressDialog.dismiss(); |
| 84 | } | 85 | } |
| 85 | }); | 86 | }); |
| 86 | } | 87 | } |
| 87 | 88 | ||
| 88 | private void confirmDone(){ | 89 | private void confirmDone(){ |
| 89 | AlertDialog.Builder alertDialog = new AlertDialog.Builder(InputConfirmCodeActivity.this); | 90 | AlertDialog.Builder alertDialog = new AlertDialog.Builder(InputConfirmCodeActivity.this); |
| 90 | alertDialog.setMessage(getResources().getString(R.string.password_have_send)); | 91 | alertDialog.setMessage(getResources().getString(R.string.password_have_send)); |
| 91 | alertDialog.setCancelable(false); | 92 | alertDialog.setCancelable(false); |
| 92 | alertDialog.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { | 93 | alertDialog.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { |
| 93 | @Override | 94 | @Override |
| 94 | public void onClick(DialogInterface dialog, int which) { | 95 | public void onClick(DialogInterface dialog, int which) { |
| 95 | finish(); | 96 | finish(); |
| 96 | } | 97 | } |
| 97 | }); | 98 | }); |
| 98 | alertDialog.show(); | 99 | alertDialog.show(); |
| 99 | } | 100 | } |
| 100 | 101 | ||
| 101 | private void notifyErr(String err) { | 102 | private void notifyErr(String err) { |
| 102 | AlertDialog.Builder alertDialog = new AlertDialog.Builder(InputConfirmCodeActivity.this); | 103 | AlertDialog.Builder alertDialog = new AlertDialog.Builder(InputConfirmCodeActivity.this); |
| 103 | alertDialog.setMessage(err); | 104 | alertDialog.setMessage(err); |
| 104 | alertDialog.setCancelable(false); | 105 | alertDialog.setCancelable(false); |
| 105 | alertDialog.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { | 106 | alertDialog.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { |
| 106 | @Override | 107 | @Override |
| 107 | public void onClick(DialogInterface dialog, int which) { | 108 | public void onClick(DialogInterface dialog, int which) { |
| 108 | finish(); | 109 | finish(); |
| 109 | } | 110 | } |
| 110 | }); | 111 | }); |
| 111 | alertDialog.show(); | 112 | alertDialog.show(); |
| 112 | } | 113 | } |
| 113 | 114 | ||
| 114 | @OnClick({R.id.btn_confirm}) | 115 | @OnClick({R.id.btn_confirm}) |
| 115 | public void onClick(View v) { | 116 | public void onClick(View v) { |
| 116 | switch (v.getId()) { | 117 | switch (v.getId()) { |
| 117 | case R.id.btn_confirm: | 118 | case R.id.btn_confirm: |
| 118 | // handle login | 119 | // handle login |
| 119 | String code = edtConfirmCode.getText().toString(); | 120 | String code = edtConfirmCode.getText().toString(); |
| 120 | if (code.isEmpty()){ | 121 | if (code.isEmpty()){ |
| 121 | showAlerDialog(InputConfirmCodeActivity.this, getResources().getString(R.string.please_input_confirm)); | 122 | showAlerDialog(InputConfirmCodeActivity.this, getResources().getString(R.string.please_input_confirm)); |
| 122 | return; | 123 | return; |
| 123 | } | 124 | } |
| 124 | 125 | ||
| 125 | handleGetNewPass(code); | 126 | handleGetNewPass(code); |
| 126 | break; | 127 | break; |
| 127 | 128 | ||
| 128 | default: | 129 | default: |
| 129 | break; | 130 | break; |
| 130 | } | 131 | } |
| 131 | } | 132 | } |
| 132 | } | 133 | } |
| 133 | 134 |
app/src/main/java/com/dinhcv/lifelogpedometer/activity/LoginActivity.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 LoginActivity extends ActivityBase { | 27 | public class LoginActivity extends ActivityBase { |
| 27 | 28 | ||
| 28 | @BindView(R.id.edt_user) | 29 | @BindView(R.id.edt_user) |
| 29 | TextView edtUser; | 30 | TextView edtUser; |
| 30 | @BindView(R.id.edt_password) | 31 | @BindView(R.id.edt_password) |
| 31 | TextView edtPassword; | 32 | TextView edtPassword; |
| 32 | @BindView(R.id.btn_login) | 33 | @BindView(R.id.btn_login) |
| 33 | Button btnLogin; | 34 | Button btnLogin; |
| 34 | @BindView(R.id.btn_register) | 35 | @BindView(R.id.btn_register) |
| 35 | Button btnRegister; | 36 | Button btnRegister; |
| 36 | @BindView(R.id.tv_forgetPass) | 37 | @BindView(R.id.tv_forgetPass) |
| 37 | TextView tvForgetPass; | 38 | TextView tvForgetPass; |
| 38 | 39 | ||
| 39 | 40 | ||
| 40 | private ProgressDialog progressDialog; | 41 | private ProgressDialog progressDialog; |
| 41 | 42 | ||
| 42 | @Override | 43 | @Override |
| 43 | protected void onCreate(Bundle savedInstanceState) { | 44 | protected void onCreate(Bundle savedInstanceState) { |
| 44 | super.onCreate(savedInstanceState); | 45 | super.onCreate(savedInstanceState); |
| 45 | setContentView(R.layout.activity_login); | 46 | setContentView(R.layout.activity_login); |
| 46 | ButterKnife.bind(this); | 47 | ButterKnife.bind(this); |
| 47 | getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN); | 48 | getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN); |
| 48 | 49 | ||
| 49 | initData(); | 50 | initData(); |
| 50 | 51 | ||
| 51 | } | 52 | } |
| 52 | 53 | ||
| 53 | 54 | ||
| 54 | private void initData() { | 55 | private void initData() { |
| 55 | 56 | ||
| 56 | } | 57 | } |
| 57 | 58 | ||
| 58 | private boolean verifyData(String user, String pass) { | 59 | private boolean verifyData(String user, String pass) { |
| 59 | if (user.isEmpty()) { | 60 | if (user.isEmpty()) { |
| 60 | showAlerDialog(LoginActivity.this, getResources().getString(R.string.account_is_null)); | 61 | showAlerDialog(LoginActivity.this, getResources().getString(R.string.account_is_null)); |
| 61 | return false; | 62 | return false; |
| 62 | } | 63 | } |
| 63 | 64 | ||
| 64 | if (pass.isEmpty()) { | 65 | if (pass.isEmpty()) { |
| 65 | showAlerDialog(LoginActivity.this, getResources().getString(R.string.password_is_null)); | 66 | showAlerDialog(LoginActivity.this, getResources().getString(R.string.password_is_null)); |
| 66 | return false; | 67 | return false; |
| 67 | } | 68 | } |
| 68 | 69 | ||
| 69 | return true; | 70 | return true; |
| 70 | } | 71 | } |
| 71 | 72 | ||
| 72 | private void handleLogin() { | 73 | private void handleLogin() { |
| 73 | final String user = edtUser.getText().toString(); | 74 | final String user = edtUser.getText().toString(); |
| 74 | String pass = edtPassword.getText().toString(); | 75 | String pass = edtPassword.getText().toString(); |
| 75 | 76 | ||
| 76 | // verify | 77 | // verify |
| 77 | boolean isOk = verifyData(user, pass); | 78 | boolean isOk = verifyData(user, pass); |
| 78 | if (!isOk) { | 79 | if (!isOk) { |
| 79 | return; | 80 | return; |
| 80 | } | 81 | } |
| 81 | 82 | ||
| 82 | progressDialog = new ProgressDialog(LoginActivity.this); | 83 | progressDialog = new ProgressDialog(LoginActivity.this); |
| 83 | progressDialog.setMessage(getResources().getString(R.string.waite_some_minute)); | 84 | progressDialog.setMessage(getResources().getString(R.string.waite_some_minute)); |
| 84 | progressDialog.setCancelable(false); | 85 | progressDialog.setCancelable(false); |
| 85 | progressDialog.show(); | 86 | progressDialog.show(); |
| 86 | 87 | ||
| 87 | LLAPIManager.login(LoginActivity.this, user, pass, new LLAPIManagerListener() { | 88 | ApiServices.login(LoginActivity.this, user, pass, new LLAPIManagerListener() { |
| 88 | @Override | 89 | @Override |
| 89 | public void onError(Error error) { | 90 | public void onError(Error error) { |
| 90 | progressDialog.dismiss(); | 91 | progressDialog.dismiss(); |
| 91 | Debug.error("Version JSON result: ERROR " + error); | 92 | Debug.error("Version JSON result: ERROR " + error); |
| 92 | String err = getResources().getString(R.string.login_error); | 93 | String err = getResources().getString(R.string.login_error); |
| 93 | notifyErr(err); | 94 | notifyErr(err); |
| 94 | } | 95 | } |
| 95 | 96 | ||
| 96 | @Override | 97 | @Override |
| 97 | public void onSuccess(String json) { | 98 | public void onSuccess(String json) { |
| 98 | Debug.warn("Version JSON result: " + json.toString()); | 99 | Debug.warn("Version JSON result: " + json.toString()); |
| 99 | progressDialog.dismiss(); | 100 | progressDialog.dismiss(); |
| 100 | } | 101 | } |
| 101 | 102 | ||
| 102 | @Override | 103 | @Override |
| 103 | public void onSuccess(JSONObject object) { | 104 | public void onSuccess(JSONObject object) { |
| 104 | Debug.warn("Version JSON object result: Success"); | 105 | Debug.warn("Version JSON object result: Success"); |
| 105 | progressDialog.dismiss(); | 106 | progressDialog.dismiss(); |
| 106 | 107 | ||
| 107 | String email = object.optString("email"); | 108 | String email = object.optString("email"); |
| 108 | String username = object.optString("username"); | 109 | String username = object.optString("username"); |
| 109 | String pass = object.optString("password"); | 110 | String pass = object.optString("password"); |
| 110 | int id = object.optInt("id"); | 111 | int id = object.optInt("id"); |
| 111 | Debug.normal("Email: "+email +"\n"+ "Username: "+username); | 112 | Debug.normal("Email: "+email +"\n"+ "Username: "+username); |
| 112 | // save data | 113 | // save data |
| 113 | Setting.setUserIdSharepre(LoginActivity.this, id); | 114 | Setting.setUserIdSharepre(LoginActivity.this, id); |
| 114 | Setting.setUserDataSharepre(LoginActivity.this, Setting.EMAIL_SHAREPRE, email); | 115 | Setting.setUserDataSharepre(LoginActivity.this, Setting.EMAIL_SHAREPRE, email); |
| 115 | Setting.setUserDataSharepre(LoginActivity.this, Setting.USER_SHAREPRE, username); | 116 | Setting.setUserDataSharepre(LoginActivity.this, Setting.USER_SHAREPRE, username); |
| 116 | Setting.setUserDataSharepre(LoginActivity.this, Setting.PASS_SHAREPRE, pass); | 117 | Setting.setUserDataSharepre(LoginActivity.this, Setting.PASS_SHAREPRE, pass); |
| 117 | loginDone(); | 118 | loginDone(); |
| 118 | } | 119 | } |
| 119 | }); | 120 | }); |
| 120 | } | 121 | } |
| 121 | 122 | ||
| 122 | private void loginDone(){ | 123 | private void loginDone(){ |
| 123 | Intent intent = new Intent(LoginActivity.this, PedometerActivity.class); | 124 | Intent intent = new Intent(LoginActivity.this, PedometerActivity.class); |
| 124 | startActivity(intent); | 125 | startActivity(intent); |
| 125 | } | 126 | } |
| 126 | 127 | ||
| 127 | private void handleSendConfirm(final String email){ | 128 | private void handleSendConfirm(final String email){ |
| 128 | progressDialog = new ProgressDialog(LoginActivity.this); | 129 | progressDialog = new ProgressDialog(LoginActivity.this); |
| 129 | progressDialog.setMessage(getResources().getString(R.string.waite_some_minute)); | 130 | progressDialog.setMessage(getResources().getString(R.string.waite_some_minute)); |
| 130 | progressDialog.setCancelable(false); | 131 | progressDialog.setCancelable(false); |
| 131 | progressDialog.show(); | 132 | progressDialog.show(); |
| 132 | 133 | ||
| 133 | LLAPIManager.forgetPass(email, new LLAPIManagerListener() { | 134 | ApiServices.forgetPass(email, new LLAPIManagerListener() { |
| 134 | @Override | 135 | @Override |
| 135 | public void onError(Error error) { | 136 | public void onError(Error error) { |
| 136 | progressDialog.dismiss(); | 137 | progressDialog.dismiss(); |
| 137 | Debug.error("Send confirm JSON result: ERROR " + error); | 138 | Debug.error("Send confirm JSON result: ERROR " + error); |
| 138 | String err = getResources().getString(R.string.request_pass_error); | 139 | String err = getResources().getString(R.string.request_pass_error); |
| 139 | notifyErr(err); | 140 | notifyErr(err); |
| 140 | } | 141 | } |
| 141 | 142 | ||
| 142 | @Override | 143 | @Override |
| 143 | public void onSuccess(String json) { | 144 | public void onSuccess(String json) { |
| 144 | Debug.warn("Send confirm JSON result: " + json.toString()); | 145 | Debug.warn("Send confirm JSON result: " + json.toString()); |
| 145 | progressDialog.dismiss(); | 146 | progressDialog.dismiss(); |
| 146 | 147 | ||
| 147 | confirmDone(email); | 148 | confirmDone(email); |
| 148 | } | 149 | } |
| 149 | 150 | ||
| 150 | @Override | 151 | @Override |
| 151 | public void onSuccess(JSONObject object) { | 152 | public void onSuccess(JSONObject object) { |
| 152 | Debug.warn("Send confirm JSON object result: Success"); | 153 | Debug.warn("Send confirm JSON object result: Success"); |
| 153 | progressDialog.dismiss(); | 154 | progressDialog.dismiss(); |
| 154 | } | 155 | } |
| 155 | }); | 156 | }); |
| 156 | } | 157 | } |
| 157 | 158 | ||
| 158 | private void confirmDone(String email){ | 159 | private void confirmDone(String email){ |
| 159 | Intent intent = new Intent(LoginActivity.this, InputConfirmCodeActivity.class); | 160 | Intent intent = new Intent(LoginActivity.this, InputConfirmCodeActivity.class); |
| 160 | intent.putExtra(Const.EMAIL, email ); | 161 | intent.putExtra(Const.EMAIL, email ); |
| 161 | startActivity(intent); | 162 | startActivity(intent); |
| 162 | } | 163 | } |
| 163 | 164 | ||
| 164 | private void notifyErr(String err) { | 165 | private void notifyErr(String err) { |
| 165 | AlertDialog.Builder alertDialog = new AlertDialog.Builder(LoginActivity.this); | 166 | AlertDialog.Builder alertDialog = new AlertDialog.Builder(LoginActivity.this); |
| 166 | alertDialog.setMessage(err); | 167 | alertDialog.setMessage(err); |
| 167 | alertDialog.setCancelable(false); | 168 | alertDialog.setCancelable(false); |
| 168 | alertDialog.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { | 169 | alertDialog.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { |
| 169 | @Override | 170 | @Override |
| 170 | public void onClick(DialogInterface dialog, int which) { | 171 | public void onClick(DialogInterface dialog, int which) { |
| 171 | //finish(); | 172 | //finish(); |
| 172 | edtUser.setText(""); | 173 | edtUser.setText(""); |
| 173 | edtPassword.setText(""); | 174 | edtPassword.setText(""); |
| 174 | } | 175 | } |
| 175 | }); | 176 | }); |
| 176 | alertDialog.show(); | 177 | alertDialog.show(); |
| 177 | } | 178 | } |
| 178 | 179 | ||
| 179 | @OnClick({R.id.btn_login, R.id.btn_register, R.id.tv_forgetPass}) | 180 | @OnClick({R.id.btn_login, R.id.btn_register, R.id.tv_forgetPass}) |
| 180 | public void onClick(View v) { | 181 | public void onClick(View v) { |
| 181 | switch (v.getId()) { | 182 | switch (v.getId()) { |
| 182 | case R.id.btn_login: | 183 | case R.id.btn_login: |
| 183 | // handle login | 184 | // handle login |
| 184 | handleLogin(); | 185 | handleLogin(); |
| 185 | break; | 186 | break; |
| 186 | case R.id.btn_register: | 187 | case R.id.btn_register: |
| 187 | // hanle register | 188 | // hanle register |
| 188 | Intent intent = new Intent(LoginActivity.this, RegisterActivity.class); | 189 | Intent intent = new Intent(LoginActivity.this, RegisterActivity.class); |
| 189 | startActivity(intent); | 190 | startActivity(intent); |
| 190 | break; | 191 | break; |
| 191 | 192 | ||
| 192 | case R.id.tv_forgetPass: | 193 | case R.id.tv_forgetPass: |
| 193 | // hanle register | 194 | // hanle register |
| 194 | String email = edtUser.getText().toString(); | 195 | String email = edtUser.getText().toString(); |
| 195 | if (email.isEmpty()){ | 196 | if (email.isEmpty()){ |
| 196 | showAlerDialog(LoginActivity.this, getResources().getString(R.string.please_input_email)); | 197 | showAlerDialog(LoginActivity.this, getResources().getString(R.string.please_input_email)); |
| 197 | return; | 198 | return; |
| 198 | } | 199 | } |
| 199 | 200 | ||
| 200 | handleSendConfirm(email); | 201 | handleSendConfirm(email); |
| 201 | 202 | ||
| 202 | break; | 203 | break; |
| 203 | 204 | ||
| 204 | default: | 205 | default: |
| 205 | break; | 206 | break; |
| 206 | } | 207 | } |
| 207 | } | 208 | } |
| 208 | } | 209 | } |
| 209 | 210 |
app/src/main/java/com/dinhcv/lifelogpedometer/activity/RegisterActivity.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.DatePickerDialog; | 4 | import android.app.DatePickerDialog; |
| 5 | import android.app.ProgressDialog; | 5 | import android.app.ProgressDialog; |
| 6 | import android.content.DialogInterface; | 6 | import android.content.DialogInterface; |
| 7 | import android.content.Intent; | 7 | import android.content.Intent; |
| 8 | import android.graphics.Bitmap; | 8 | import android.graphics.Bitmap; |
| 9 | import android.graphics.BitmapFactory; | 9 | import android.graphics.BitmapFactory; |
| 10 | import android.net.Uri; | 10 | import android.net.Uri; |
| 11 | import android.os.AsyncTask; | 11 | import android.os.AsyncTask; |
| 12 | import android.os.Bundle; | 12 | import android.os.Bundle; |
| 13 | import android.view.View; | 13 | import android.view.View; |
| 14 | import android.view.WindowManager; | 14 | import android.view.WindowManager; |
| 15 | import android.widget.DatePicker; | 15 | import android.widget.DatePicker; |
| 16 | import android.widget.EditText; | 16 | import android.widget.EditText; |
| 17 | import android.widget.LinearLayout; | 17 | import android.widget.LinearLayout; |
| 18 | import android.widget.TextView; | 18 | import android.widget.TextView; |
| 19 | import android.widget.Toast; | 19 | import android.widget.Toast; |
| 20 | 20 | ||
| 21 | import com.dinhcv.lifelogpedometer.LifeLogApplication; | 21 | import com.dinhcv.lifelogpedometer.LifeLogApplication; |
| 22 | import com.dinhcv.lifelogpedometer.R; | 22 | import com.dinhcv.lifelogpedometer.R; |
| 23 | import com.dinhcv.lifelogpedometer.customview.SimpleSelectBoxDialogBuilder; | 23 | import com.dinhcv.lifelogpedometer.customview.SimpleSelectBoxDialogBuilder; |
| 24 | import com.dinhcv.lifelogpedometer.interfaces.LLAPIManagerListener; | 24 | import com.dinhcv.lifelogpedometer.interfaces.LLAPIManagerListener; |
| 25 | import com.dinhcv.lifelogpedometer.interfaces.OnSelectResultListener; | 25 | import com.dinhcv.lifelogpedometer.interfaces.OnSelectResultListener; |
| 26 | import com.dinhcv.lifelogpedometer.model.Shareprefer.Setting; | 26 | import com.dinhcv.lifelogpedometer.model.Shareprefer.Setting; |
| 27 | import com.dinhcv.lifelogpedometer.model.structure.RegisterInfo; | 27 | import com.dinhcv.lifelogpedometer.model.structure.RegisterInfo; |
| 28 | import com.dinhcv.lifelogpedometer.model.structure.SelectItemInfo; | 28 | import com.dinhcv.lifelogpedometer.model.structure.SelectItemInfo; |
| 29 | import com.dinhcv.lifelogpedometer.portal.ApiServices; | ||
| 29 | import com.dinhcv.lifelogpedometer.portal.LLAPIManager; | 30 | import com.dinhcv.lifelogpedometer.portal.LLAPIManager; |
| 30 | import com.dinhcv.lifelogpedometer.utils.Debug; | 31 | import com.dinhcv.lifelogpedometer.utils.Debug; |
| 31 | import com.dinhcv.lifelogpedometer.utils.Utils; | 32 | import com.dinhcv.lifelogpedometer.utils.Utils; |
| 32 | 33 | ||
| 33 | import org.json.JSONArray; | 34 | import org.json.JSONArray; |
| 34 | import org.json.JSONObject; | 35 | import org.json.JSONObject; |
| 35 | 36 | ||
| 36 | import java.io.FileNotFoundException; | 37 | import java.io.FileNotFoundException; |
| 37 | import java.io.InputStream; | 38 | import java.io.InputStream; |
| 38 | import java.util.Calendar; | 39 | import java.util.Calendar; |
| 39 | import java.util.Date; | 40 | import java.util.Date; |
| 40 | import java.util.List; | 41 | import java.util.List; |
| 41 | 42 | ||
| 42 | import butterknife.BindView; | 43 | import butterknife.BindView; |
| 43 | import butterknife.ButterKnife; | 44 | import butterknife.ButterKnife; |
| 44 | import butterknife.OnClick; | 45 | import butterknife.OnClick; |
| 45 | import de.hdodenhof.circleimageview.CircleImageView; | 46 | import de.hdodenhof.circleimageview.CircleImageView; |
| 46 | 47 | ||
| 47 | public class RegisterActivity extends ActivityBase { | 48 | public class RegisterActivity extends ActivityBase { |
| 48 | 49 | ||
| 49 | @BindView(R.id.edt_user) | 50 | @BindView(R.id.edt_user) |
| 50 | EditText edtUsername; | 51 | EditText edtUsername; |
| 51 | @BindView(R.id.edt_name) | 52 | @BindView(R.id.edt_name) |
| 52 | EditText edtName; | 53 | EditText edtName; |
| 53 | @BindView(R.id.edt_nickName) | 54 | @BindView(R.id.edt_nickName) |
| 54 | EditText edtNickName; | 55 | EditText edtNickName; |
| 55 | @BindView(R.id.edt_email) | 56 | @BindView(R.id.edt_email) |
| 56 | EditText edtEmail; | 57 | EditText edtEmail; |
| 57 | @BindView(R.id.edt_password) | 58 | @BindView(R.id.edt_password) |
| 58 | EditText edtPassword; | 59 | EditText edtPassword; |
| 59 | @BindView(R.id.edt_confirmPass) | 60 | @BindView(R.id.edt_confirmPass) |
| 60 | EditText edtConfirmPass; | 61 | EditText edtConfirmPass; |
| 61 | @BindView(R.id.tv_sex) | 62 | @BindView(R.id.tv_sex) |
| 62 | TextView tvSex; | 63 | TextView tvSex; |
| 63 | @BindView(R.id.tv_birthday) | 64 | @BindView(R.id.tv_birthday) |
| 64 | TextView tvBirthday; | 65 | TextView tvBirthday; |
| 65 | @BindView(R.id.edt_height) | 66 | @BindView(R.id.edt_height) |
| 66 | EditText edtHeight; | 67 | EditText edtHeight; |
| 67 | @BindView(R.id.edt_weight) | 68 | @BindView(R.id.edt_weight) |
| 68 | EditText edtWeight; | 69 | EditText edtWeight; |
| 69 | @BindView(R.id.edt_bodyFat) | 70 | @BindView(R.id.edt_bodyFat) |
| 70 | EditText edtBodyFat; | 71 | EditText edtBodyFat; |
| 71 | @BindView(R.id.tv_address) | 72 | @BindView(R.id.tv_address) |
| 72 | TextView tvAddress; | 73 | TextView tvAddress; |
| 73 | @BindView(R.id.edt_comment) | 74 | @BindView(R.id.edt_comment) |
| 74 | EditText edtComment; | 75 | EditText edtComment; |
| 75 | 76 | ||
| 76 | @BindView(R.id.ll_low) | 77 | @BindView(R.id.ll_low) |
| 77 | LinearLayout llLow; | 78 | LinearLayout llLow; |
| 78 | @BindView(R.id.tv_low) | 79 | @BindView(R.id.tv_low) |
| 79 | TextView tvLow; | 80 | TextView tvLow; |
| 80 | @BindView(R.id.ll_mid) | 81 | @BindView(R.id.ll_mid) |
| 81 | LinearLayout llMid; | 82 | LinearLayout llMid; |
| 82 | @BindView(R.id.tv_mid) | 83 | @BindView(R.id.tv_mid) |
| 83 | TextView tvMid; | 84 | TextView tvMid; |
| 84 | @BindView(R.id.ll_hight) | 85 | @BindView(R.id.ll_hight) |
| 85 | LinearLayout llHight; | 86 | LinearLayout llHight; |
| 86 | @BindView(R.id.tv_hight) | 87 | @BindView(R.id.tv_hight) |
| 87 | TextView tvHight; | 88 | TextView tvHight; |
| 88 | @BindView(R.id.profile_image) | 89 | @BindView(R.id.profile_image) |
| 89 | CircleImageView profileImage; | 90 | CircleImageView profileImage; |
| 90 | 91 | ||
| 91 | private List<SelectItemInfo> sexList; | 92 | private List<SelectItemInfo> sexList; |
| 92 | private List<SelectItemInfo> provinceList; | 93 | private List<SelectItemInfo> provinceList; |
| 93 | private LifeLogApplication mLifeLogApplication; | 94 | private LifeLogApplication mLifeLogApplication; |
| 94 | private SelectItemInfo sexInfo; | 95 | private SelectItemInfo sexInfo; |
| 95 | private SelectItemInfo provinceInfo; | 96 | private SelectItemInfo provinceInfo; |
| 96 | 97 | ||
| 97 | private Calendar mCalendar; | 98 | private Calendar mCalendar; |
| 98 | private int mDay; | 99 | private int mDay; |
| 99 | private int mMonth; | 100 | private int mMonth; |
| 100 | private int mYear; | 101 | private int mYear; |
| 101 | private Date mBirthDay; | 102 | private Date mBirthDay; |
| 102 | 103 | ||
| 103 | private int level = 0; | 104 | private int level = 0; |
| 104 | private static final int RESULT_LOAD_IMG = 99; | 105 | private static final int RESULT_LOAD_IMG = 99; |
| 105 | private RegisterInfo mRegisterInfo; | 106 | private RegisterInfo mRegisterInfo; |
| 106 | private String profileImagePath; | 107 | private String profileImagePath; |
| 107 | private ProgressDialog progressDialog; | 108 | private ProgressDialog progressDialog; |
| 108 | 109 | ||
| 109 | @Override | 110 | @Override |
| 110 | protected void onCreate(Bundle savedInstanceState) { | 111 | protected void onCreate(Bundle savedInstanceState) { |
| 111 | super.onCreate(savedInstanceState); | 112 | super.onCreate(savedInstanceState); |
| 112 | setContentView(R.layout.activity_register); | 113 | setContentView(R.layout.activity_register); |
| 113 | getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN); | 114 | getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN); |
| 114 | 115 | ||
| 115 | ButterKnife.bind(this); | 116 | ButterKnife.bind(this); |
| 116 | mLifeLogApplication = (LifeLogApplication) getApplication(); | 117 | mLifeLogApplication = (LifeLogApplication) getApplication(); |
| 117 | 118 | ||
| 118 | initData(); | 119 | initData(); |
| 119 | 120 | ||
| 120 | initView(); | 121 | initView(); |
| 121 | 122 | ||
| 122 | } | 123 | } |
| 123 | 124 | ||
| 124 | private void initData() { | 125 | private void initData() { |
| 125 | sexList = mLifeLogApplication.getSexList(); | 126 | sexList = mLifeLogApplication.getSexList(); |
| 126 | provinceList = mLifeLogApplication.getProvinceList(); | 127 | provinceList = mLifeLogApplication.getProvinceList(); |
| 127 | 128 | ||
| 128 | mCalendar = Calendar.getInstance(); | 129 | mCalendar = Calendar.getInstance(); |
| 129 | mDay = mCalendar.get(Calendar.DAY_OF_MONTH); | 130 | mDay = mCalendar.get(Calendar.DAY_OF_MONTH); |
| 130 | mMonth = mCalendar.get(Calendar.MONTH); | 131 | mMonth = mCalendar.get(Calendar.MONTH); |
| 131 | mYear = mCalendar.get(Calendar.YEAR); | 132 | mYear = mCalendar.get(Calendar.YEAR); |
| 132 | } | 133 | } |
| 133 | 134 | ||
| 134 | 135 | ||
| 135 | private void initView() { | 136 | private void initView() { |
| 136 | 137 | ||
| 137 | 138 | ||
| 138 | } | 139 | } |
| 139 | 140 | ||
| 140 | private boolean checkData() { | 141 | private boolean checkData() { |
| 141 | String userName = edtUsername.getText().toString(); | 142 | String userName = edtUsername.getText().toString(); |
| 142 | String name = edtName.getText().toString(); | 143 | String name = edtName.getText().toString(); |
| 143 | String nickName = edtNickName.getText().toString(); | 144 | String nickName = edtNickName.getText().toString(); |
| 144 | String email = edtEmail.getText().toString(); | 145 | String email = edtEmail.getText().toString(); |
| 145 | String pass = edtPassword.getText().toString(); | 146 | String pass = edtPassword.getText().toString(); |
| 146 | String confirmPass = edtConfirmPass.getText().toString(); | 147 | String confirmPass = edtConfirmPass.getText().toString(); |
| 147 | //sexInfo | 148 | //sexInfo |
| 148 | //birthday | 149 | //birthday |
| 149 | String height = edtHeight.getText().toString(); | 150 | String height = edtHeight.getText().toString(); |
| 150 | String weight = edtWeight.getText().toString(); | 151 | String weight = edtWeight.getText().toString(); |
| 151 | String bodyFat = edtBodyFat.getText().toString(); | 152 | String bodyFat = edtBodyFat.getText().toString(); |
| 152 | // address | 153 | // address |
| 153 | String comment = edtComment.getText().toString(); | 154 | String comment = edtComment.getText().toString(); |
| 154 | 155 | ||
| 155 | 156 | ||
| 156 | if (userName.isEmpty()) { | 157 | if (userName.isEmpty()) { |
| 157 | showAlerDialog(RegisterActivity.this, getResources().getString(R.string.username_null)); | 158 | showAlerDialog(RegisterActivity.this, getResources().getString(R.string.username_null)); |
| 158 | return false; | 159 | return false; |
| 159 | } | 160 | } |
| 160 | 161 | ||
| 161 | if (name.isEmpty()) { | 162 | if (name.isEmpty()) { |
| 162 | showAlerDialog(RegisterActivity.this, getResources().getString(R.string.name_null)); | 163 | showAlerDialog(RegisterActivity.this, getResources().getString(R.string.name_null)); |
| 163 | return false; | 164 | return false; |
| 164 | } | 165 | } |
| 165 | 166 | ||
| 166 | if (nickName.isEmpty()) { | 167 | if (nickName.isEmpty()) { |
| 167 | showAlerDialog(RegisterActivity.this, getResources().getString(R.string.nickname_null)); | 168 | showAlerDialog(RegisterActivity.this, getResources().getString(R.string.nickname_null)); |
| 168 | return false; | 169 | return false; |
| 169 | } | 170 | } |
| 170 | 171 | ||
| 171 | if (email.isEmpty()) { | 172 | if (email.isEmpty()) { |
| 172 | showAlerDialog(RegisterActivity.this, getResources().getString(R.string.mail_null)); | 173 | showAlerDialog(RegisterActivity.this, getResources().getString(R.string.mail_null)); |
| 173 | return false; | 174 | return false; |
| 174 | } else { | 175 | } else { |
| 175 | if (!Utils.checkMailFormat(email)) { | 176 | if (!Utils.checkMailFormat(email)) { |
| 176 | showAlerDialog(RegisterActivity.this, getResources().getString(R.string.mail_invalid)); | 177 | showAlerDialog(RegisterActivity.this, getResources().getString(R.string.mail_invalid)); |
| 177 | return false; | 178 | return false; |
| 178 | } | 179 | } |
| 179 | } | 180 | } |
| 180 | 181 | ||
| 181 | if (pass.isEmpty()) { | 182 | if (pass.isEmpty()) { |
| 182 | showAlerDialog(RegisterActivity.this, getResources().getString(R.string.password_null)); | 183 | showAlerDialog(RegisterActivity.this, getResources().getString(R.string.password_null)); |
| 183 | return false; | 184 | return false; |
| 184 | }else { | 185 | }else { |
| 185 | if (pass.length() < 6) { | 186 | if (pass.length() < 6) { |
| 186 | showAlerDialog(RegisterActivity.this, getResources().getString(R.string.password_less_6)); | 187 | showAlerDialog(RegisterActivity.this, getResources().getString(R.string.password_less_6)); |
| 187 | return false; | 188 | return false; |
| 188 | } | 189 | } |
| 189 | } | 190 | } |
| 190 | 191 | ||
| 191 | if (confirmPass.isEmpty()) { | 192 | if (confirmPass.isEmpty()) { |
| 192 | showAlerDialog(RegisterActivity.this, getResources().getString(R.string.confirm_pass_null)); | 193 | showAlerDialog(RegisterActivity.this, getResources().getString(R.string.confirm_pass_null)); |
| 193 | return false; | 194 | return false; |
| 194 | } | 195 | } |
| 195 | 196 | ||
| 196 | if (!pass.equals(confirmPass)) { | 197 | if (!pass.equals(confirmPass)) { |
| 197 | showAlerDialog(RegisterActivity.this, getResources().getString(R.string.confirm_pass_wrong)); | 198 | showAlerDialog(RegisterActivity.this, getResources().getString(R.string.confirm_pass_wrong)); |
| 198 | return false; | 199 | return false; |
| 199 | } | 200 | } |
| 200 | 201 | ||
| 201 | if (sexInfo == null) { | 202 | if (sexInfo == null) { |
| 202 | showAlerDialog(RegisterActivity.this, getResources().getString(R.string.sex_not_select)); | 203 | showAlerDialog(RegisterActivity.this, getResources().getString(R.string.sex_not_select)); |
| 203 | return false; | 204 | return false; |
| 204 | } | 205 | } |
| 205 | 206 | ||
| 206 | if (mBirthDay == null) { | 207 | if (mBirthDay == null) { |
| 207 | showAlerDialog(RegisterActivity.this, getResources().getString(R.string.birthday_not_select)); | 208 | showAlerDialog(RegisterActivity.this, getResources().getString(R.string.birthday_not_select)); |
| 208 | return false; | 209 | return false; |
| 209 | } | 210 | } |
| 210 | 211 | ||
| 211 | if (height.isEmpty()) { | 212 | if (height.isEmpty()) { |
| 212 | showAlerDialog(RegisterActivity.this, getResources().getString(R.string.height_null)); | 213 | showAlerDialog(RegisterActivity.this, getResources().getString(R.string.height_null)); |
| 213 | return false; | 214 | return false; |
| 214 | } | 215 | } |
| 215 | 216 | ||
| 216 | if (weight.isEmpty()) { | 217 | if (weight.isEmpty()) { |
| 217 | showAlerDialog(RegisterActivity.this, getResources().getString(R.string.weight_null)); | 218 | showAlerDialog(RegisterActivity.this, getResources().getString(R.string.weight_null)); |
| 218 | return false; | 219 | return false; |
| 219 | } | 220 | } |
| 220 | 221 | ||
| 221 | if (bodyFat.isEmpty()) { | 222 | if (bodyFat.isEmpty()) { |
| 222 | showAlerDialog(RegisterActivity.this, getResources().getString(R.string.body_fat_percent_null)); | 223 | showAlerDialog(RegisterActivity.this, getResources().getString(R.string.body_fat_percent_null)); |
| 223 | return false; | 224 | return false; |
| 224 | } | 225 | } |
| 225 | 226 | ||
| 226 | if (provinceInfo == null) { | 227 | if (provinceInfo == null) { |
| 227 | showAlerDialog(RegisterActivity.this, getResources().getString(R.string.province_not_select)); | 228 | showAlerDialog(RegisterActivity.this, getResources().getString(R.string.province_not_select)); |
| 228 | return false; | 229 | return false; |
| 229 | } | 230 | } |
| 230 | 231 | ||
| 231 | if (level == 0) { | 232 | if (level == 0) { |
| 232 | showAlerDialog(RegisterActivity.this, getResources().getString(R.string.level_not_select)); | 233 | showAlerDialog(RegisterActivity.this, getResources().getString(R.string.level_not_select)); |
| 233 | return false; | 234 | return false; |
| 234 | } | 235 | } |
| 235 | 236 | ||
| 236 | if (comment.isEmpty()) { | 237 | if (comment.isEmpty()) { |
| 237 | showAlerDialog(RegisterActivity.this, getResources().getString(R.string.comment_null)); | 238 | showAlerDialog(RegisterActivity.this, getResources().getString(R.string.comment_null)); |
| 238 | return false; | 239 | return false; |
| 239 | } | 240 | } |
| 240 | 241 | ||
| 241 | mRegisterInfo = new RegisterInfo(); | 242 | mRegisterInfo = new RegisterInfo(); |
| 242 | mRegisterInfo.setUsername(userName); | 243 | mRegisterInfo.setUsername(userName); |
| 243 | mRegisterInfo.setFullName(name); | 244 | mRegisterInfo.setFullName(name); |
| 244 | mRegisterInfo.setNickname(nickName); | 245 | mRegisterInfo.setNickname(nickName); |
| 245 | mRegisterInfo.setPassword(pass); | 246 | mRegisterInfo.setPassword(pass); |
| 246 | mRegisterInfo.setBirthday(mBirthDay); | 247 | mRegisterInfo.setBirthday(mBirthDay); |
| 247 | mRegisterInfo.setHeight(Integer.valueOf(height)); | 248 | mRegisterInfo.setHeight(Integer.valueOf(height)); |
| 248 | mRegisterInfo.setWeight(Integer.valueOf(weight)); | 249 | mRegisterInfo.setWeight(Integer.valueOf(weight)); |
| 249 | mRegisterInfo.setFatRate(Integer.valueOf(bodyFat)); | 250 | mRegisterInfo.setFatRate(Integer.valueOf(bodyFat)); |
| 250 | mRegisterInfo.setGender(sexInfo.getId()); | 251 | mRegisterInfo.setGender(sexInfo.getId()); |
| 251 | mRegisterInfo.setAddress(provinceInfo.getName()); | 252 | mRegisterInfo.setAddress(provinceInfo.getName()); |
| 252 | mRegisterInfo.setEmail(email); | 253 | mRegisterInfo.setEmail(email); |
| 253 | mRegisterInfo.setProfileImage(profileImagePath); | 254 | mRegisterInfo.setProfileImage(profileImagePath); |
| 254 | 255 | ||
| 255 | return true; | 256 | return true; |
| 256 | } | 257 | } |
| 257 | 258 | ||
| 258 | private void handleRegister() { | 259 | private void handleRegister() { |
| 259 | progressDialog = new ProgressDialog(RegisterActivity.this); | 260 | progressDialog = new ProgressDialog(RegisterActivity.this); |
| 260 | progressDialog.setMessage(getResources().getString(R.string.uploading)); | 261 | progressDialog.setMessage(getResources().getString(R.string.uploading)); |
| 261 | progressDialog.setCancelable(false); | 262 | progressDialog.setCancelable(false); |
| 262 | progressDialog.show(); | 263 | progressDialog.show(); |
| 263 | 264 | ||
| 264 | LLAPIManager.register(mRegisterInfo, new LLAPIManagerListener() { | 265 | ApiServices.register(mRegisterInfo, new LLAPIManagerListener() { |
| 265 | @Override | 266 | @Override |
| 266 | public void onError(Error error) { | 267 | public void onError(Error error) { |
| 267 | progressDialog.dismiss(); | 268 | progressDialog.dismiss(); |
| 268 | Debug.error(" Can not upload data"); | 269 | Debug.error(" Can not upload data"); |
| 269 | if (error != null) { | 270 | if (error != null) { |
| 270 | String err = getResources().getString(R.string.register_err); | 271 | String err = getResources().getString(R.string.register_err); |
| 271 | notifyErr(err); | 272 | notifyErr(err); |
| 272 | } | 273 | } |
| 273 | } | 274 | } |
| 274 | 275 | ||
| 275 | @Override | 276 | @Override |
| 276 | public void onSuccess(String json) { | 277 | public void onSuccess(String json) { |
| 277 | progressDialog.dismiss(); | 278 | progressDialog.dismiss(); |
| 278 | if (json != null) { | 279 | if (json != null) { |
| 279 | Debug.warn(" Upload data success success"); | 280 | Debug.warn(" Upload data success success"); |
| 280 | Debug.warn("DATA JSON result: " + json.toString()); | 281 | Debug.warn("DATA JSON result: " + json.toString()); |
| 281 | registerDone(); | 282 | registerDone(); |
| 282 | } else { | 283 | } else { |
| 283 | Debug.warn(" Upload data fail: response null"); | 284 | Debug.warn(" Upload data fail: response null"); |
| 284 | String err = getResources().getString(R.string.err_exception); | 285 | String err = getResources().getString(R.string.err_exception); |
| 285 | notifyErr(err); | 286 | notifyErr(err); |
| 286 | } | 287 | } |
| 287 | } | 288 | } |
| 288 | 289 | ||
| 289 | @Override | 290 | @Override |
| 290 | public void onSuccess(JSONObject object) { | 291 | public void onSuccess(JSONObject object) { |
| 291 | Debug.warn("Version JSON object result: Success"); | 292 | Debug.warn("Version JSON object result: Success"); |
| 292 | progressDialog.dismiss(); | 293 | progressDialog.dismiss(); |
| 293 | 294 | ||
| 294 | String email = object.optString("email"); | 295 | String email = object.optString("email"); |
| 295 | String username = object.optString("username"); | 296 | String username = object.optString("username"); |
| 296 | String pass = object.optString("password"); | 297 | String pass = object.optString("password"); |
| 297 | Debug.normal("Email: "+email +"\n"+ "Username: "+username); | 298 | Debug.normal("Email: "+email +"\n"+ "Username: "+username); |
| 298 | // save data | 299 | // save data |
| 299 | Setting.setUserDataSharepre(RegisterActivity.this, Setting.EMAIL_SHAREPRE, email); | 300 | Setting.setUserDataSharepre(RegisterActivity.this, Setting.EMAIL_SHAREPRE, email); |
| 300 | Setting.setUserDataSharepre(RegisterActivity.this, Setting.USER_SHAREPRE, username); | 301 | Setting.setUserDataSharepre(RegisterActivity.this, Setting.USER_SHAREPRE, username); |
| 301 | Setting.setUserDataSharepre(RegisterActivity.this, Setting.PASS_SHAREPRE, pass); | 302 | Setting.setUserDataSharepre(RegisterActivity.this, Setting.PASS_SHAREPRE, pass); |
| 302 | registerDone(); | 303 | registerDone(); |
| 303 | } | 304 | } |
| 304 | }); | 305 | }); |
| 305 | } | 306 | } |
| 306 | 307 | ||
| 307 | private void hanleGetImagePath(Bitmap bitmap){ | 308 | private void hanleGetImagePath(Bitmap bitmap){ |
| 308 | progressDialog = new ProgressDialog(RegisterActivity.this); | 309 | progressDialog = new ProgressDialog(RegisterActivity.this); |
| 309 | progressDialog.setMessage(getResources().getString(R.string.uploading)); | 310 | progressDialog.setMessage(getResources().getString(R.string.uploading)); |
| 310 | progressDialog.setCancelable(false); | 311 | progressDialog.setCancelable(false); |
| 311 | progressDialog.show(); | 312 | progressDialog.show(); |
| 312 | 313 | ||
| 313 | LLAPIManager.uploadImage(bitmap, new LLAPIManagerListener() { | 314 | ApiServices.uploadImage(bitmap, new LLAPIManagerListener() { |
| 314 | @Override | 315 | @Override |
| 315 | public void onError(Error error) { | 316 | public void onError(Error error) { |
| 316 | progressDialog.dismiss(); | 317 | progressDialog.dismiss(); |
| 317 | Debug.error(" Can not upload data"); | 318 | Debug.error(" Can not upload data"); |
| 318 | if (error != null) { | 319 | if (error != null) { |
| 319 | String err = getResources().getString(R.string.register_err); | 320 | String err = getResources().getString(R.string.register_err); |
| 320 | notifyErr(err); | 321 | notifyErr(err); |
| 321 | } | 322 | } |
| 322 | } | 323 | } |
| 323 | 324 | ||
| 324 | @Override | 325 | @Override |
| 325 | public void onSuccess(String json) { | 326 | public void onSuccess(String json) { |
| 326 | if (json != null) { | 327 | if (json != null) { |
| 327 | Debug.warn(" Upload data success success"); | 328 | Debug.warn(" Upload data success success"); |
| 328 | Debug.warn("DATA JSON result: " + json.toString()); | 329 | Debug.warn("DATA JSON result: " + json.toString()); |
| 329 | uploadImageDone(json); | 330 | uploadImageDone(json); |
| 330 | } else { | 331 | } else { |
| 331 | progressDialog.dismiss(); | 332 | progressDialog.dismiss(); |
| 332 | Debug.warn(" Upload data fail: response null"); | 333 | Debug.warn(" Upload data fail: response null"); |
| 333 | String err = getResources().getString(R.string.err_exception); | 334 | String err = getResources().getString(R.string.err_exception); |
| 334 | notifyErr(err); | 335 | notifyErr(err); |
| 335 | } | 336 | } |
| 336 | } | 337 | } |
| 337 | 338 | ||
| 338 | @Override | 339 | @Override |
| 339 | public void onSuccess(JSONObject array) { | 340 | public void onSuccess(JSONObject array) { |
| 340 | progressDialog.dismiss(); | 341 | progressDialog.dismiss(); |
| 341 | Debug.warn(" Upload data success array"); | 342 | Debug.warn(" Upload data success array"); |
| 342 | } | 343 | } |
| 343 | }); | 344 | }); |
| 344 | } | 345 | } |
| 345 | 346 | ||
| 346 | private void registerDone(){ | 347 | private void registerDone(){ |
| 347 | Toast.makeText(RegisterActivity.this, R.string.register_success, Toast.LENGTH_SHORT).show(); | 348 | Toast.makeText(RegisterActivity.this, R.string.register_success, Toast.LENGTH_SHORT).show(); |
| 348 | finish(); | 349 | finish(); |
| 349 | } | 350 | } |
| 350 | 351 | ||
| 351 | private void uploadImageDone(String path){ | 352 | private void uploadImageDone(String path){ |
| 352 | profileImagePath = path; | 353 | profileImagePath = path; |
| 353 | } | 354 | } |
| 354 | 355 | ||
| 355 | private void notifyErr(String err) { | 356 | private void notifyErr(String err) { |
| 356 | AlertDialog.Builder alertDialog = new AlertDialog.Builder(RegisterActivity.this); | 357 | AlertDialog.Builder alertDialog = new AlertDialog.Builder(RegisterActivity.this); |
| 357 | alertDialog.setMessage(err); | 358 | alertDialog.setMessage(err); |
| 358 | alertDialog.setCancelable(false); | 359 | alertDialog.setCancelable(false); |
| 359 | alertDialog.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { | 360 | alertDialog.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { |
| 360 | @Override | 361 | @Override |
| 361 | public void onClick(DialogInterface dialog, int which) { | 362 | public void onClick(DialogInterface dialog, int which) { |
| 362 | finish(); | 363 | finish(); |
| 363 | } | 364 | } |
| 364 | }); | 365 | }); |
| 365 | alertDialog.show(); | 366 | alertDialog.show(); |
| 366 | } | 367 | } |
| 367 | 368 | ||
| 368 | private void doSelectSex() { | 369 | private void doSelectSex() { |
| 369 | String title = getResources().getString(R.string.sex); | 370 | String title = getResources().getString(R.string.sex); |
| 370 | new SimpleSelectBoxDialogBuilder().create(RegisterActivity.this, title, sexList, new OnSelectResultListener() { | 371 | new SimpleSelectBoxDialogBuilder().create(RegisterActivity.this, title, sexList, new OnSelectResultListener() { |
| 371 | @Override | 372 | @Override |
| 372 | public void onSelectedItem(SelectItemInfo selectItemInfo) { | 373 | public void onSelectedItem(SelectItemInfo selectItemInfo) { |
| 373 | if (selectItemInfo != null) { | 374 | if (selectItemInfo != null) { |
| 374 | Debug.normal("Item selected: " + selectItemInfo.getName()); | 375 | Debug.normal("Item selected: " + selectItemInfo.getName()); |
| 375 | sexInfo = selectItemInfo; | 376 | sexInfo = selectItemInfo; |
| 376 | tvSex.setText(sexInfo.getName()); | 377 | tvSex.setText(sexInfo.getName()); |
| 377 | } else { | 378 | } else { |
| 378 | Debug.normal("Have not item selected"); | 379 | Debug.normal("Have not item selected"); |
| 379 | } | 380 | } |
| 380 | } | 381 | } |
| 381 | }).show(); | 382 | }).show(); |
| 382 | } | 383 | } |
| 383 | 384 | ||
| 384 | private void doSelectProvince() { | 385 | private void doSelectProvince() { |
| 385 | String title = getResources().getString(R.string.prefecture); | 386 | String title = getResources().getString(R.string.prefecture); |
| 386 | new SimpleSelectBoxDialogBuilder().create(RegisterActivity.this, title, provinceList, new OnSelectResultListener() { | 387 | new SimpleSelectBoxDialogBuilder().create(RegisterActivity.this, title, provinceList, new OnSelectResultListener() { |
| 387 | @Override | 388 | @Override |
| 388 | public void onSelectedItem(SelectItemInfo selectItemInfo) { | 389 | public void onSelectedItem(SelectItemInfo selectItemInfo) { |
| 389 | if (selectItemInfo != null) { | 390 | if (selectItemInfo != null) { |
| 390 | Debug.normal("Item selected: " + selectItemInfo.getName()); | 391 | Debug.normal("Item selected: " + selectItemInfo.getName()); |
| 391 | provinceInfo = selectItemInfo; | 392 | provinceInfo = selectItemInfo; |
| 392 | tvAddress.setText(provinceInfo.getName()); | 393 | tvAddress.setText(provinceInfo.getName()); |
| 393 | } else { | 394 | } else { |
| 394 | Debug.normal("Have not item selected"); | 395 | Debug.normal("Have not item selected"); |
| 395 | } | 396 | } |
| 396 | } | 397 | } |
| 397 | }).show(); | 398 | }).show(); |
| 398 | } | 399 | } |
| 399 | 400 | ||
| 400 | private void hanleSelectDate() { | 401 | private void hanleSelectDate() { |
| 401 | 402 | ||
| 402 | DatePickerDialog datePicker = new DatePickerDialog(RegisterActivity.this, new DatePickerDialog.OnDateSetListener() { | 403 | DatePickerDialog datePicker = new DatePickerDialog(RegisterActivity.this, new DatePickerDialog.OnDateSetListener() { |
| 403 | @Override | 404 | @Override |
| 404 | public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) { | 405 | public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) { |
| 405 | 406 | ||
| 406 | mDay = dayOfMonth; | 407 | mDay = dayOfMonth; |
| 407 | mMonth = month; | 408 | mMonth = month; |
| 408 | mYear = year; | 409 | mYear = year; |
| 409 | mCalendar = Calendar.getInstance(); | 410 | mCalendar = Calendar.getInstance(); |
| 410 | mCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth); | 411 | mCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth); |
| 411 | mCalendar.set(Calendar.MONTH, month); | 412 | mCalendar.set(Calendar.MONTH, month); |
| 412 | mCalendar.set(Calendar.YEAR, year); | 413 | mCalendar.set(Calendar.YEAR, year); |
| 413 | mBirthDay = mCalendar.getTime(); | 414 | mBirthDay = mCalendar.getTime(); |
| 414 | 415 | ||
| 415 | String dateStr = Utils.convertDateToStringDialogSelect(mBirthDay); | 416 | String dateStr = Utils.convertDateToStringDialogSelect(mBirthDay); |
| 416 | tvBirthday.setText(dateStr); | 417 | tvBirthday.setText(dateStr); |
| 417 | } | 418 | } |
| 418 | }, mYear, mMonth, mDay); | 419 | }, mYear, mMonth, mDay); |
| 419 | datePicker.getDatePicker().setMaxDate(new Date().getTime()); | 420 | datePicker.getDatePicker().setMaxDate(new Date().getTime()); |
| 420 | datePicker.show(); | 421 | datePicker.show(); |
| 421 | } | 422 | } |
| 422 | 423 | ||
| 423 | private void updateUILevel() { | 424 | private void updateUILevel() { |
| 424 | if (level == 1) { | 425 | if (level == 1) { |
| 425 | setLowButtonSelected(true); | 426 | setLowButtonSelected(true); |
| 426 | setMidButtonSelected(false); | 427 | setMidButtonSelected(false); |
| 427 | setHightButtonSelected(false); | 428 | setHightButtonSelected(false); |
| 428 | } else if (level == 2) { | 429 | } else if (level == 2) { |
| 429 | setLowButtonSelected(false); | 430 | setLowButtonSelected(false); |
| 430 | setMidButtonSelected(true); | 431 | setMidButtonSelected(true); |
| 431 | setHightButtonSelected(false); | 432 | setHightButtonSelected(false); |
| 432 | } else if (level == 3) { | 433 | } else if (level == 3) { |
| 433 | setLowButtonSelected(false); | 434 | setLowButtonSelected(false); |
| 434 | setMidButtonSelected(false); | 435 | setMidButtonSelected(false); |
| 435 | setHightButtonSelected(true); | 436 | setHightButtonSelected(true); |
| 436 | } else { | 437 | } else { |
| 437 | setLowButtonSelected(false); | 438 | setLowButtonSelected(false); |
| 438 | setMidButtonSelected(false); | 439 | setMidButtonSelected(false); |
| 439 | setHightButtonSelected(false); | 440 | setHightButtonSelected(false); |
| 440 | } | 441 | } |
| 441 | } | 442 | } |
| 442 | 443 | ||
| 443 | private void setLowButtonSelected(boolean b) { | 444 | private void setLowButtonSelected(boolean b) { |
| 444 | if (b) { | 445 | if (b) { |
| 445 | llLow.setBackgroundResource(R.drawable.left_selected_lev_bg); | 446 | llLow.setBackgroundResource(R.drawable.left_selected_lev_bg); |
| 446 | tvLow.setTextColor(getResources().getColor(R.color.white)); | 447 | tvLow.setTextColor(getResources().getColor(R.color.white)); |
| 447 | } else { | 448 | } else { |
| 448 | llLow.setBackgroundResource(R.drawable.left_unselected_lev_bg); | 449 | llLow.setBackgroundResource(R.drawable.left_unselected_lev_bg); |
| 449 | tvLow.setTextColor(getResources().getColor(R.color.black)); | 450 | tvLow.setTextColor(getResources().getColor(R.color.black)); |
| 450 | } | 451 | } |
| 451 | } | 452 | } |
| 452 | 453 | ||
| 453 | private void setMidButtonSelected(boolean b) { | 454 | private void setMidButtonSelected(boolean b) { |
| 454 | if (b) { | 455 | if (b) { |
| 455 | llMid.setBackgroundResource(R.drawable.mid_selected_lev_bg); | 456 | llMid.setBackgroundResource(R.drawable.mid_selected_lev_bg); |
| 456 | tvMid.setTextColor(getResources().getColor(R.color.white)); | 457 | tvMid.setTextColor(getResources().getColor(R.color.white)); |
| 457 | } else { | 458 | } else { |
| 458 | llMid.setBackgroundResource(R.drawable.mid_unselected_lev_bg); | 459 | llMid.setBackgroundResource(R.drawable.mid_unselected_lev_bg); |
| 459 | tvMid.setTextColor(getResources().getColor(R.color.black)); | 460 | tvMid.setTextColor(getResources().getColor(R.color.black)); |
| 460 | } | 461 | } |
| 461 | } | 462 | } |
| 462 | 463 | ||
| 463 | private void setHightButtonSelected(boolean b) { | 464 | private void setHightButtonSelected(boolean b) { |
| 464 | if (b) { | 465 | if (b) { |
| 465 | llHight.setBackgroundResource(R.drawable.right_selected_lev_bg); | 466 | llHight.setBackgroundResource(R.drawable.right_selected_lev_bg); |
| 466 | tvHight.setTextColor(getResources().getColor(R.color.white)); | 467 | tvHight.setTextColor(getResources().getColor(R.color.white)); |
| 467 | } else { | 468 | } else { |
| 468 | llHight.setBackgroundResource(R.drawable.right_unselected_lev_bg); | 469 | llHight.setBackgroundResource(R.drawable.right_unselected_lev_bg); |
| 469 | tvHight.setTextColor(getResources().getColor(R.color.black)); | 470 | tvHight.setTextColor(getResources().getColor(R.color.black)); |
| 470 | } | 471 | } |
| 471 | } | 472 | } |
| 472 | 473 | ||
| 473 | private void getImageBrower() { | 474 | private void getImageBrower() { |
| 474 | Intent intent = new Intent(Intent.ACTION_PICK); | 475 | Intent intent = new Intent(Intent.ACTION_PICK); |
| 475 | intent.setType("image/*"); | 476 | intent.setType("image/*"); |
| 476 | startActivityForResult(intent, RESULT_LOAD_IMG); | 477 | startActivityForResult(intent, RESULT_LOAD_IMG); |
| 477 | } | 478 | } |
| 478 | 479 | ||
| 479 | 480 | ||
| 480 | @OnClick({R.id.btn_register, R.id.rl_sex, R.id.rl_birthday, R.id.rl_address, R.id.ll_low, | 481 | @OnClick({R.id.btn_register, R.id.rl_sex, R.id.rl_birthday, R.id.rl_address, R.id.ll_low, |
| 481 | R.id.ll_mid, R.id.ll_hight, R.id.profile_image}) | 482 | R.id.ll_mid, R.id.ll_hight, R.id.profile_image}) |
| 482 | public void onClick(View v) { | 483 | public void onClick(View v) { |
| 483 | switch (v.getId()) { | 484 | switch (v.getId()) { |
| 484 | case R.id.btn_register: | 485 | case R.id.btn_register: |
| 485 | if (checkData()) { | 486 | if (checkData()) { |
| 486 | handleRegister(); | 487 | handleRegister(); |
| 487 | } | 488 | } |
| 488 | break; | 489 | break; |
| 489 | 490 | ||
| 490 | case R.id.rl_sex: | 491 | case R.id.rl_sex: |
| 491 | doSelectSex(); | 492 | doSelectSex(); |
| 492 | break; | 493 | break; |
| 493 | 494 | ||
| 494 | 495 | ||
| 495 | case R.id.rl_birthday: | 496 | case R.id.rl_birthday: |
| 496 | hanleSelectDate(); | 497 | hanleSelectDate(); |
| 497 | break; | 498 | break; |
| 498 | 499 | ||
| 499 | case R.id.rl_address: | 500 | case R.id.rl_address: |
| 500 | doSelectProvince(); | 501 | doSelectProvince(); |
| 501 | break; | 502 | break; |
| 502 | 503 | ||
| 503 | case R.id.ll_low: | 504 | case R.id.ll_low: |
| 504 | level = 1; | 505 | level = 1; |
| 505 | updateUILevel(); | 506 | updateUILevel(); |
| 506 | break; | 507 | break; |
| 507 | case R.id.ll_mid: | 508 | case R.id.ll_mid: |
| 508 | level = 2; | 509 | level = 2; |
| 509 | updateUILevel(); | 510 | updateUILevel(); |
| 510 | break; | 511 | break; |
| 511 | case R.id.ll_hight: | 512 | case R.id.ll_hight: |
| 512 | level = 3; | 513 | level = 3; |
| 513 | updateUILevel(); | 514 | updateUILevel(); |
| 514 | break; | 515 | break; |
| 515 | case R.id.profile_image: | 516 | case R.id.profile_image: |
| 516 | getImageBrower(); | 517 | getImageBrower(); |
| 517 | break; | 518 | break; |
| 518 | 519 | ||
| 519 | default: | 520 | default: |
| 520 | break; | 521 | break; |
| 521 | } | 522 | } |
| 522 | } | 523 | } |
| 523 | 524 | ||
| 524 | @Override | 525 | @Override |
| 525 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { | 526 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { |
| 526 | super.onActivityResult(requestCode, resultCode, data); | 527 | super.onActivityResult(requestCode, resultCode, data); |
| 527 | 528 | ||
| 528 | if (resultCode == RESULT_OK) { | 529 | if (resultCode == RESULT_OK) { |
| 529 | if (requestCode == RESULT_LOAD_IMG) { | 530 | if (requestCode == RESULT_LOAD_IMG) { |
| 530 | try { | 531 | try { |
| 531 | final Uri imageUri = data.getData(); | 532 | final Uri imageUri = data.getData(); |
| 532 | final InputStream imageStream = getContentResolver().openInputStream(imageUri); | 533 | final InputStream imageStream = getContentResolver().openInputStream(imageUri); |
| 533 | final Bitmap selectedImage = BitmapFactory.decodeStream(imageStream); | 534 | final Bitmap selectedImage = BitmapFactory.decodeStream(imageStream); |
| 534 | hanleGetImagePath(selectedImage); | 535 | hanleGetImagePath(selectedImage); |
| 535 | profileImage.setImageBitmap(selectedImage); | 536 | profileImage.setImageBitmap(selectedImage); |
| 536 | } catch (FileNotFoundException e) { | 537 | } catch (FileNotFoundException e) { |
| 537 | e.printStackTrace(); | 538 | e.printStackTrace(); |
| 538 | Toast.makeText(RegisterActivity.this, "Something went wrong", Toast.LENGTH_LONG).show(); | 539 | Toast.makeText(RegisterActivity.this, "Something went wrong", Toast.LENGTH_LONG).show(); |
| 539 | } | 540 | } |
| 540 | 541 | ||
| 541 | } else { | 542 | } else { |
| 542 | Toast.makeText(RegisterActivity.this, "You haven't picked Image", Toast.LENGTH_LONG).show(); | 543 | Toast.makeText(RegisterActivity.this, "You haven't picked Image", Toast.LENGTH_LONG).show(); |
| 543 | } | 544 | } |
| 544 | 545 | ||
| 545 | } | 546 | } |
| 546 | } | 547 | } |
| 547 | } | 548 | } |
app/src/main/java/com/dinhcv/lifelogpedometer/activity/TopDateFragment.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.os.Bundle; | 6 | import android.os.Bundle; |
| 7 | import android.support.annotation.Nullable; | 7 | import android.support.annotation.Nullable; |
| 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.DatePicker; | 11 | import android.widget.DatePicker; |
| 12 | import android.widget.ImageView; | 12 | import android.widget.ImageView; |
| 13 | import android.widget.LinearLayout; | 13 | import android.widget.LinearLayout; |
| 14 | import android.widget.TextView; | 14 | import android.widget.TextView; |
| 15 | 15 | ||
| 16 | import com.dinhcv.lifelogpedometer.R; | 16 | import com.dinhcv.lifelogpedometer.R; |
| 17 | import com.dinhcv.lifelogpedometer.adapter.NoticeAdapter; | 17 | import com.dinhcv.lifelogpedometer.adapter.NoticeAdapter; |
| 18 | import com.dinhcv.lifelogpedometer.customview.ExpandableListCustomView; | 18 | import com.dinhcv.lifelogpedometer.customview.ExpandableListCustomView; |
| 19 | import com.dinhcv.lifelogpedometer.interfaces.LLAPIManagerListener; | 19 | import com.dinhcv.lifelogpedometer.interfaces.LLAPIManagerListener; |
| 20 | import com.dinhcv.lifelogpedometer.model.structure.home.NoticeInfo; | 20 | import com.dinhcv.lifelogpedometer.model.structure.home.NoticeInfo; |
| 21 | import com.dinhcv.lifelogpedometer.model.structure.home.TagetInfo; | 21 | import com.dinhcv.lifelogpedometer.model.structure.home.TagetInfo; |
| 22 | import com.dinhcv.lifelogpedometer.portal.ApiServices; | ||
| 22 | import com.dinhcv.lifelogpedometer.portal.LLAPIManager; | 23 | import com.dinhcv.lifelogpedometer.portal.LLAPIManager; |
| 23 | import com.dinhcv.lifelogpedometer.utils.Const; | 24 | import com.dinhcv.lifelogpedometer.utils.Const; |
| 24 | import com.dinhcv.lifelogpedometer.utils.Debug; | 25 | import com.dinhcv.lifelogpedometer.utils.Debug; |
| 25 | import com.dinhcv.lifelogpedometer.utils.Utils; | 26 | import com.dinhcv.lifelogpedometer.utils.Utils; |
| 26 | 27 | ||
| 27 | import org.json.JSONArray; | 28 | import org.json.JSONArray; |
| 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.List; | 35 | import java.util.List; |
| 35 | 36 | ||
| 36 | public class TopDateFragment extends FragmentBase implements SettingFragmentPresenter { | 37 | public class TopDateFragment extends FragmentBase implements SettingFragmentPresenter { |
| 37 | 38 | ||
| 38 | private TextView tvDate; | 39 | private TextView tvDate; |
| 39 | private TextView tvStep; | 40 | private TextView tvStep; |
| 40 | private TextView tvRemain; | 41 | private TextView tvRemain; |
| 41 | private TextView tvRateDone; | 42 | private TextView tvRateDone; |
| 42 | private ImageView ivBack; | 43 | private ImageView ivBack; |
| 43 | private ImageView ivNext; | 44 | private ImageView ivNext; |
| 44 | 45 | ||
| 45 | private LinearLayout llBike; | 46 | private LinearLayout llBike; |
| 46 | private LinearLayout llWalking; | 47 | private LinearLayout llWalking; |
| 47 | private LinearLayout llRunning; | 48 | private LinearLayout llRunning; |
| 48 | 49 | ||
| 49 | private Date mAnaDate; | 50 | private Date mAnaDate; |
| 50 | private Calendar mCalendar; | 51 | private Calendar mCalendar; |
| 51 | 52 | ||
| 52 | private int mAnaDay; | 53 | private int mAnaDay; |
| 53 | private int mAnaMonth; | 54 | private int mAnaMonth; |
| 54 | private int mAnaYear; | 55 | private int mAnaYear; |
| 55 | private Context mContext; | 56 | private Context mContext; |
| 56 | 57 | ||
| 57 | private Const.STEP_TYPE stepType; | 58 | private Const.STEP_TYPE stepType; |
| 58 | private TagetInfo mTagetInfo = new TagetInfo(); | 59 | private TagetInfo mTagetInfo = new TagetInfo(); |
| 59 | private ImageView ivToDay; | 60 | private ImageView ivToDay; |
| 60 | private ExpandableListCustomView lvNotice; | 61 | private ExpandableListCustomView lvNotice; |
| 61 | private NoticeAdapter mNoticeAdapter; | 62 | private NoticeAdapter mNoticeAdapter; |
| 62 | private View mRootview; | 63 | private View mRootview; |
| 63 | private TopFragment mTopFragment; | 64 | private TopFragment mTopFragment; |
| 64 | 65 | ||
| 65 | public void setRootFragment(TopFragment frag) { | 66 | public void setRootFragment(TopFragment frag) { |
| 66 | this.mTopFragment = frag; | 67 | this.mTopFragment = frag; |
| 67 | } | 68 | } |
| 68 | 69 | ||
| 69 | @Override | 70 | @Override |
| 70 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle | 71 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle |
| 71 | savedInstanceState) { | 72 | savedInstanceState) { |
| 72 | // Inflate the layout for this fragment | 73 | // Inflate the layout for this fragment |
| 73 | mRootview = inflater.inflate(R.layout.fragment_top_date, container, false); | 74 | mRootview = inflater.inflate(R.layout.fragment_top_date, container, false); |
| 74 | mContext = getActivity(); | 75 | mContext = getActivity(); |
| 75 | initView(mRootview); | 76 | initView(mRootview); |
| 76 | initData(); | 77 | initData(); |
| 77 | return mRootview; | 78 | return mRootview; |
| 78 | } | 79 | } |
| 79 | 80 | ||
| 80 | 81 | ||
| 81 | private void initView(View rootView) { | 82 | private void initView(View rootView) { |
| 82 | tvDate = (TextView) rootView.findViewById(R.id.tv_date); | 83 | tvDate = (TextView) rootView.findViewById(R.id.tv_date); |
| 83 | tvStep = (TextView) rootView.findViewById(R.id.tv_step); | 84 | tvStep = (TextView) rootView.findViewById(R.id.tv_step); |
| 84 | tvRemain = (TextView) rootView.findViewById(R.id.tv_remainingStep); | 85 | tvRemain = (TextView) rootView.findViewById(R.id.tv_remainingStep); |
| 85 | tvRateDone = (TextView) rootView.findViewById(R.id.tv_completeRate); | 86 | tvRateDone = (TextView) rootView.findViewById(R.id.tv_completeRate); |
| 86 | ivBack = (ImageView) rootView.findViewById(R.id.iv_back); | 87 | ivBack = (ImageView) rootView.findViewById(R.id.iv_back); |
| 87 | ivNext = (ImageView) rootView.findViewById(R.id.iv_next); | 88 | ivNext = (ImageView) rootView.findViewById(R.id.iv_next); |
| 88 | 89 | ||
| 89 | llBike = (LinearLayout) rootView.findViewById(R.id.ll_bike); | 90 | llBike = (LinearLayout) rootView.findViewById(R.id.ll_bike); |
| 90 | llWalking = (LinearLayout) rootView.findViewById(R.id.ll_walking); | 91 | llWalking = (LinearLayout) rootView.findViewById(R.id.ll_walking); |
| 91 | llRunning = (LinearLayout) rootView.findViewById(R.id.ll_running); | 92 | llRunning = (LinearLayout) rootView.findViewById(R.id.ll_running); |
| 92 | 93 | ||
| 93 | ivToDay = (ImageView) rootView.findViewById(R.id.iv_toDay); | 94 | ivToDay = (ImageView) rootView.findViewById(R.id.iv_toDay); |
| 94 | lvNotice = (ExpandableListCustomView) rootView.findViewById(R.id.lv_notice); | 95 | lvNotice = (ExpandableListCustomView) rootView.findViewById(R.id.lv_notice); |
| 95 | 96 | ||
| 96 | handleEvent(); | 97 | handleEvent(); |
| 97 | } | 98 | } |
| 98 | 99 | ||
| 99 | private void handleEvent(){ | 100 | private void handleEvent(){ |
| 100 | tvDate.setOnClickListener(new View.OnClickListener() { | 101 | tvDate.setOnClickListener(new View.OnClickListener() { |
| 101 | @Override | 102 | @Override |
| 102 | public void onClick(View view) { | 103 | public void onClick(View view) { |
| 103 | handleAnaDatePicker(); | 104 | handleAnaDatePicker(); |
| 104 | } | 105 | } |
| 105 | }); | 106 | }); |
| 106 | 107 | ||
| 107 | ivBack.setOnClickListener(new View.OnClickListener() { | 108 | ivBack.setOnClickListener(new View.OnClickListener() { |
| 108 | @Override | 109 | @Override |
| 109 | public void onClick(View view) { | 110 | public void onClick(View view) { |
| 110 | mCalendar = Calendar.getInstance(); | 111 | mCalendar = Calendar.getInstance(); |
| 111 | mCalendar.setTime(mAnaDate); | 112 | mCalendar.setTime(mAnaDate); |
| 112 | mCalendar.add(Calendar.DAY_OF_MONTH, -1); | 113 | mCalendar.add(Calendar.DAY_OF_MONTH, -1); |
| 113 | Date date = mCalendar.getTime(); | 114 | Date date = mCalendar.getTime(); |
| 114 | tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(date)); | 115 | tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(date)); |
| 115 | mAnaDate = date; | 116 | mAnaDate = date; |
| 116 | getHomePage(mAnaDate, stepType); | 117 | getHomePage(mAnaDate, stepType); |
| 118 | getNews(mAnaDate); | ||
| 117 | } | 119 | } |
| 118 | }); | 120 | }); |
| 119 | 121 | ||
| 120 | ivNext.setOnClickListener(new View.OnClickListener() { | 122 | ivNext.setOnClickListener(new View.OnClickListener() { |
| 121 | @Override | 123 | @Override |
| 122 | public void onClick(View view) { | 124 | public void onClick(View view) { |
| 123 | mCalendar = Calendar.getInstance(); | 125 | mCalendar = Calendar.getInstance(); |
| 124 | mCalendar.setTime(mAnaDate); | 126 | mCalendar.setTime(mAnaDate); |
| 125 | mCalendar.add(Calendar.DAY_OF_MONTH, +1); | 127 | mCalendar.add(Calendar.DAY_OF_MONTH, +1); |
| 126 | Date date = mCalendar.getTime(); | 128 | Date date = mCalendar.getTime(); |
| 127 | tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(date)); | 129 | tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(date)); |
| 128 | mAnaDate = date; | 130 | mAnaDate = date; |
| 129 | getHomePage(mAnaDate, stepType); | 131 | getHomePage(mAnaDate, stepType); |
| 132 | getNews(mAnaDate); | ||
| 130 | } | 133 | } |
| 131 | }); | 134 | }); |
| 132 | 135 | ||
| 133 | 136 | ||
| 134 | llWalking.setOnClickListener(new View.OnClickListener() { | 137 | llWalking.setOnClickListener(new View.OnClickListener() { |
| 135 | @Override | 138 | @Override |
| 136 | public void onClick(View view) { | 139 | public void onClick(View view) { |
| 137 | stepType = Const.STEP_TYPE.WALKING; | 140 | stepType = Const.STEP_TYPE.WALKING; |
| 138 | updateUiStepType(false, true, false); | 141 | updateUiStepType(false, true, false); |
| 139 | // add data | 142 | // add data |
| 140 | getHomePage(mAnaDate, stepType); | 143 | getHomePage(mAnaDate, stepType); |
| 141 | } | 144 | } |
| 142 | }); | 145 | }); |
| 143 | 146 | ||
| 144 | llRunning.setOnClickListener(new View.OnClickListener() { | 147 | llRunning.setOnClickListener(new View.OnClickListener() { |
| 145 | @Override | 148 | @Override |
| 146 | public void onClick(View view) { | 149 | public void onClick(View view) { |
| 147 | stepType = Const.STEP_TYPE.RUNNING; | 150 | stepType = Const.STEP_TYPE.RUNNING; |
| 148 | updateUiStepType(false, false, true); | 151 | updateUiStepType(false, false, true); |
| 149 | // add | 152 | // add |
| 150 | getHomePage(mAnaDate, stepType); | 153 | getHomePage(mAnaDate, stepType); |
| 151 | } | 154 | } |
| 152 | }); | 155 | }); |
| 153 | 156 | ||
| 154 | llBike.setOnClickListener(new View.OnClickListener() { | 157 | llBike.setOnClickListener(new View.OnClickListener() { |
| 155 | @Override | 158 | @Override |
| 156 | public void onClick(View view) { | 159 | public void onClick(View view) { |
| 157 | stepType = Const.STEP_TYPE.BIKE; | 160 | stepType = Const.STEP_TYPE.BIKE; |
| 158 | updateUiStepType(true, false, false); | 161 | updateUiStepType(true, false, false); |
| 159 | // add data | 162 | // add data |
| 160 | getHomePage(mAnaDate, stepType); | 163 | getHomePage(mAnaDate, stepType); |
| 161 | } | 164 | } |
| 162 | }); | 165 | }); |
| 163 | 166 | ||
| 164 | ivToDay.setOnClickListener(new View.OnClickListener() { | 167 | ivToDay.setOnClickListener(new View.OnClickListener() { |
| 165 | @Override | 168 | @Override |
| 166 | public void onClick(View view) { | 169 | public void onClick(View view) { |
| 167 | mTopFragment.showDetailFragment(); | 170 | mTopFragment.showDetailFragment(); |
| 168 | } | 171 | } |
| 169 | }); | 172 | }); |
| 170 | 173 | ||
| 171 | } | 174 | } |
| 172 | 175 | ||
| 173 | private void updateUiStepType(boolean b1, boolean b2, boolean b3) { | 176 | private void updateUiStepType(boolean b1, boolean b2, boolean b3) { |
| 174 | llBike.setSelected(b1); | 177 | llBike.setSelected(b1); |
| 175 | llWalking.setSelected(b2); | 178 | llWalking.setSelected(b2); |
| 176 | llRunning.setSelected(b3); | 179 | llRunning.setSelected(b3); |
| 177 | } | 180 | } |
| 178 | 181 | ||
| 179 | /** | 182 | /** |
| 180 | * Show date picker dialog | 183 | * Show date picker dialog |
| 181 | */ | 184 | */ |
| 182 | private void handleAnaDatePicker() { | 185 | private void handleAnaDatePicker() { |
| 183 | 186 | ||
| 184 | new DatePickerDialog(getActivity(), new DatePickerDialog.OnDateSetListener() { | 187 | new DatePickerDialog(getActivity(), new DatePickerDialog.OnDateSetListener() { |
| 185 | @Override | 188 | @Override |
| 186 | public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { | 189 | public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { |
| 187 | 190 | ||
| 188 | mCalendar = Calendar.getInstance(); | 191 | mCalendar = Calendar.getInstance(); |
| 189 | mCalendar.set(year, monthOfYear, dayOfMonth); | 192 | mCalendar.set(year, monthOfYear, dayOfMonth); |
| 190 | mAnaYear = year; | 193 | mAnaYear = year; |
| 191 | mAnaMonth = monthOfYear; | 194 | mAnaMonth = monthOfYear; |
| 192 | mAnaDay = dayOfMonth; | 195 | mAnaDay = dayOfMonth; |
| 193 | Date date = mCalendar.getTime(); | 196 | Date date = mCalendar.getTime(); |
| 194 | tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(date)); | 197 | tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(date)); |
| 195 | mAnaDate = date; | 198 | mAnaDate = date; |
| 196 | 199 | ||
| 197 | getHomePage(mAnaDate, stepType); | 200 | getHomePage(mAnaDate, stepType); |
| 201 | getNews(mAnaDate); | ||
| 198 | } | 202 | } |
| 199 | }, mAnaYear, mAnaMonth, mAnaDay).show(); | 203 | }, mAnaYear, mAnaMonth, mAnaDay).show(); |
| 200 | 204 | ||
| 201 | } | 205 | } |
| 202 | 206 | ||
| 203 | 207 | ||
| 204 | /** | 208 | /** |
| 205 | * init data for | 209 | * init data for |
| 206 | */ | 210 | */ |
| 207 | private void initData() { | 211 | private void initData() { |
| 208 | mCalendar = Calendar.getInstance(); | 212 | mCalendar = Calendar.getInstance(); |
| 209 | mCalendar.setTime(new Date()); | 213 | mCalendar.setTime(new Date()); |
| 210 | mAnaDate = mCalendar.getTime(); | 214 | mAnaDate = mCalendar.getTime(); |
| 211 | mAnaYear = mCalendar.get(Calendar.YEAR); | 215 | mAnaYear = mCalendar.get(Calendar.YEAR); |
| 212 | mAnaMonth = mCalendar.get(Calendar.MONTH); | 216 | mAnaMonth = mCalendar.get(Calendar.MONTH); |
| 213 | mAnaDay = mCalendar.get(Calendar.DAY_OF_MONTH); | 217 | mAnaDay = mCalendar.get(Calendar.DAY_OF_MONTH); |
| 214 | 218 | ||
| 215 | tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(mAnaDate)); | 219 | tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(mAnaDate)); |
| 216 | 220 | ||
| 217 | stepType = Const.STEP_TYPE.WALKING; | 221 | stepType = Const.STEP_TYPE.WALKING; |
| 218 | updateUiStepType(false, true, false); | 222 | updateUiStepType(false, true, false); |
| 219 | getHomePage(mAnaDate, stepType); | 223 | getHomePage(mAnaDate, stepType); |
| 224 | getNews(mAnaDate); | ||
| 220 | } | 225 | } |
| 221 | 226 | ||
| 222 | 227 | ||
| 223 | private void getHomePage(Date date, Const.STEP_TYPE stepType){ | 228 | private void getHomePage(Date date, Const.STEP_TYPE stepType){ |
| 224 | 229 | ||
| 225 | showDialog(mContext); | 230 | showDialog(mContext); |
| 226 | LLAPIManager.homePage(date, stepType, new LLAPIManagerListener() { | 231 | ApiServices.homePage(date, stepType, new LLAPIManagerListener() { |
| 227 | @Override | 232 | @Override |
| 228 | public void onError(Error error) { | 233 | public void onError(Error error) { |
| 229 | Debug.error("Get data history error"); | 234 | Debug.error("Get data history error"); |
| 230 | hiddenDialog(); | 235 | hiddenDialog(); |
| 231 | showDialogNotData(); | 236 | showDialogNotData(); |
| 232 | } | 237 | } |
| 233 | 238 | ||
| 234 | @Override | 239 | @Override |
| 235 | public void onSuccess(String json) { | 240 | public void onSuccess(String json) { |
| 236 | Debug.error("Get data history success"); | 241 | Debug.error("Get data history success"); |
| 237 | hiddenDialog(); | 242 | hiddenDialog(); |
| 238 | loadDataDone(json); | 243 | loadDataDone(json); |
| 239 | } | 244 | } |
| 240 | 245 | ||
| 241 | @Override | 246 | @Override |
| 242 | public void onSuccess(JSONObject object) { | 247 | public void onSuccess(JSONObject object) { |
| 243 | Debug.error("Get data history success"); | 248 | Debug.error("Get data history success"); |
| 244 | hiddenDialog(); | 249 | hiddenDialog(); |
| 245 | } | 250 | } |
| 246 | }); | 251 | }); |
| 247 | } | 252 | } |
| 248 | 253 | ||
| 249 | private void showDialogNotData(){ | 254 | private void showDialogNotData(){ |
| 250 | showAlerDialog(mContext, getResources().getString(R.string.can_not_get_data)); | 255 | showAlerDialog(mContext, getResources().getString(R.string.can_not_get_data)); |
| 251 | } | 256 | } |
| 252 | 257 | ||
| 253 | private void loadDataDone(String jsonString) { | 258 | private void loadDataDone(String jsonString) { |
| 254 | JSONObject jsonObject = null; | 259 | JSONObject jsonObject = null; |
| 255 | try { | 260 | try { |
| 256 | jsonObject = new JSONObject(jsonString); | 261 | jsonObject = new JSONObject(jsonString); |
| 257 | int status = jsonObject.optInt("status"); | 262 | int status = jsonObject.optInt("status"); |
| 258 | if (status == 1) { | 263 | if (status == 1) { |
| 259 | JSONObject jsonObject1 = jsonObject.optJSONObject("result"); | 264 | JSONObject jsonObject1 = jsonObject.optJSONObject("result"); |
| 260 | JSONObject targetInf = jsonObject1.getJSONObject("targetInf"); | 265 | JSONObject targetInf = jsonObject1.getJSONObject("targetInf"); |
| 261 | JSONArray listNotice = jsonObject1.getJSONArray("listNotice"); | 266 | JSONArray listNotice = jsonObject1.getJSONArray("listNotice"); |
| 262 | 267 | ||
| 263 | if (targetInf != null){ | 268 | if (targetInf != null){ |
| 264 | String target = targetInf.optString("target_step"); | 269 | String target = targetInf.optString("target_step"); |
| 265 | Debug.normal("Target: "+ target); | 270 | Debug.normal("Target: "+ target); |
| 266 | mTagetInfo.setTaget(targetInf.optString("target_step")); | 271 | mTagetInfo.setTaget(targetInf.optString("target_step")); |
| 267 | mTagetInfo.setSteps(targetInf.optString("num_step")); | 272 | mTagetInfo.setSteps(targetInf.optString("num_step")); |
| 268 | mTagetInfo.setStepRemain(targetInf.optString("remaining_step")); | 273 | mTagetInfo.setStepRemain(targetInf.optString("remaining_step")); |
| 269 | mTagetInfo.setCompletePercent(targetInf.optString("complete_percent")); | 274 | mTagetInfo.setCompletePercent(targetInf.optString("complete_percent")); |
| 270 | } | 275 | } |
| 271 | 276 | ||
| 272 | if (listNotice != null && listNotice.length() > 0) { | 277 | if (listNotice != null && listNotice.length() > 0) { |
| 273 | List<NoticeInfo> infoLists = new ArrayList<>(); | 278 | List<NoticeInfo> infoLists = new ArrayList<>(); |
| 274 | for (int i = 0; i < listNotice.length(); i++){ | 279 | for (int i = 0; i < listNotice.length(); i++){ |
| 275 | NoticeInfo noticeInfo = new NoticeInfo(); | 280 | NoticeInfo noticeInfo = new NoticeInfo(); |
| 276 | JSONObject ob = (JSONObject) listNotice.get(i); | 281 | JSONObject ob = (JSONObject) listNotice.get(i); |
| 277 | noticeInfo.setId(ob.optInt("id")); | 282 | noticeInfo.setId(ob.optInt("id")); |
| 278 | noticeInfo.setContent(ob.optString("notice_content")); | 283 | noticeInfo.setContent(ob.optString("notice_content")); |
| 279 | infoLists.add(noticeInfo); | 284 | infoLists.add(noticeInfo); |
| 280 | } | 285 | } |
| 281 | 286 | ||
| 282 | mTagetInfo.setNoticeList(infoLists); | 287 | mTagetInfo.setNoticeList(infoLists); |
| 283 | } | 288 | } |
| 284 | 289 | ||
| 285 | } | 290 | } |
| 286 | } catch (JSONException e) { | 291 | } catch (JSONException e) { |
| 287 | e.printStackTrace(); | 292 | e.printStackTrace(); |
| 288 | mTagetInfo = new TagetInfo();; | 293 | mTagetInfo = new TagetInfo();; |
| 289 | } | 294 | } |
| 290 | 295 | ||
| 291 | loadUI(); | 296 | loadUI(); |
| 292 | } | 297 | } |
| 293 | 298 | ||
| 294 | 299 | ||
| 295 | private void loadUI(){ | 300 | private void loadUI(){ |
| 296 | tvStep.setText(String.valueOf(mTagetInfo.getSteps())); | 301 | tvStep.setText(String.valueOf(mTagetInfo.getSteps())); |
| 297 | tvRemain.setText(String.valueOf(mTagetInfo.getStepRemain())); | 302 | tvRemain.setText(String.valueOf(mTagetInfo.getStepRemain())); |
| 298 | tvRateDone.setText(mContext.getResources().getString(R.string.percent_unit, mTagetInfo.getCompletePercent())); | 303 | tvRateDone.setText(mContext.getResources().getString(R.string.percent_unit, mTagetInfo.getCompletePercent())); |
| 304 | } | ||
| 299 | 305 | ||
| 300 | List<NoticeInfo> infoLists = mTagetInfo.getNoticeList(); | 306 | private void getNews(Date date){ |
| 301 | if (infoLists != null && infoLists.size() >0){ | 307 | |
| 302 | mNoticeAdapter = new NoticeAdapter(mContext, infoLists); | 308 | ApiServices.getNews(date, new LLAPIManagerListener() { |
| 309 | @Override | ||
| 310 | public void onError(Error error) { | ||
| 311 | Debug.error("Get data news error"); | ||
| 312 | } | ||
| 313 | |||
| 314 | @Override | ||
| 315 | public void onSuccess(String json) { | ||
| 316 | Debug.error("Get data news success"); | ||
| 317 | loadNewsDone(json); | ||
| 318 | } | ||
| 319 | |||
| 320 | @Override | ||
| 321 | public void onSuccess(JSONObject object) { | ||
| 322 | Debug.error("Get data news success"); | ||
| 323 | } | ||
| 324 | }); | ||
| 325 | } | ||
| 326 | |||
| 327 | private void loadNewsDone(String jsonString) { | ||
| 328 | |||
| 329 | List<NoticeInfo> contentList = new ArrayList<>(); | ||
| 330 | JSONObject jsonObject = null; | ||
| 331 | try { | ||
| 332 | jsonObject = new JSONObject(jsonString); | ||
| 333 | int status = jsonObject.optInt("status"); | ||
| 334 | if (status == 1) { | ||
| 335 | JSONObject jsonResult = jsonObject.optJSONObject("result"); | ||
| 336 | JSONArray listNotice = jsonResult.getJSONArray("listNotice"); | ||
| 337 | |||
| 338 | if (listNotice != null) { | ||
| 339 | |||
| 340 | for (int i = 0; i < listNotice.length(); i++) { | ||
| 341 | JSONObject obContent = (JSONObject) listNotice.get(i); | ||
| 342 | String content = obContent.optString("notice_content"); | ||
| 343 | Debug.normal("Content: " + content); | ||
| 344 | contentList.add(new NoticeInfo(i+1,content)); | ||
| 345 | } | ||
| 346 | } | ||
| 347 | |||
| 348 | } | ||
| 349 | } catch (JSONException e) { | ||
| 350 | e.printStackTrace(); | ||
| 351 | } | ||
| 352 | |||
| 353 | addNews(contentList); | ||
| 354 | } | ||
| 355 | |||
| 356 | private void addNews(List<NoticeInfo> noticeInfos){ | ||
| 357 | if (noticeInfos != null && noticeInfos.size() >0){ | ||
| 358 | mNoticeAdapter = new NoticeAdapter(mContext, noticeInfos); | ||
| 303 | lvNotice.setAdapter(mNoticeAdapter); | 359 | lvNotice.setAdapter(mNoticeAdapter); |
| 304 | lvNotice.setExpanded(true); | 360 | lvNotice.setExpanded(true); |
| 361 | }else { | ||
| 362 | lvNotice.setAdapter(null); | ||
| 305 | } | 363 | } |
| 306 | |||
| 307 | } | 364 | } |
| 308 | 365 | ||
| 309 | 366 | ||
| 367 | |||
| 310 | @Override | 368 | @Override |
| 311 | public void onAttach(Context context) { | 369 | public void onAttach(Context context) { |
| 312 | super.onAttach(context); | 370 | super.onAttach(context); |
| 313 | 371 | ||
| 314 | } | 372 | } |
| 315 | 373 | ||
| 316 | 374 | ||
| 317 | @Override | 375 | @Override |
| 318 | public void onSaveData() { | 376 | public void onSaveData() { |
| 319 | 377 | ||
| 320 | } | 378 | } |
| 321 | 379 | ||
| 322 | @Override | 380 | @Override |
| 323 | public void onInvalidate(boolean isInit) { | 381 | public void onInvalidate(boolean isInit) { |
| 324 | initData(); | 382 | initData(); |
| 325 | } | 383 | } |
| 326 | 384 | ||
| 327 | @Override | 385 | @Override |
| 328 | public void onViewStateRestored(@Nullable Bundle savedInstanceState) { | 386 | public void onViewStateRestored(@Nullable Bundle savedInstanceState) { |
| 329 | super.onViewStateRestored(savedInstanceState); | 387 | super.onViewStateRestored(savedInstanceState); |
| 330 | 388 | ||
| 331 | initData(); | 389 | initData(); |
| 332 | } | 390 | } |
| 333 | 391 | ||
| 334 | 392 | ||
| 335 | @Override | 393 | @Override |
| 336 | public void onActivityResult(int requestCode, int resultCode, Intent data) { | 394 | public void onActivityResult(int requestCode, int resultCode, Intent data) { |
| 337 | super.onActivityResult(requestCode, resultCode, data); | 395 | super.onActivityResult(requestCode, resultCode, data); |
| 338 | 396 | ||
| 339 | } | 397 | } |
| 398 | |||
| 399 | |||
| 340 | 400 | ||
| 341 | } | 401 | } |
app/src/main/java/com/dinhcv/lifelogpedometer/activity/TopTodayFragment.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.app.ProgressDialog; | 4 | import android.app.ProgressDialog; |
| 5 | import android.content.Context; | 5 | import android.content.Context; |
| 6 | import android.graphics.Color; | 6 | import android.graphics.Color; |
| 7 | import android.hardware.Sensor; | 7 | import android.hardware.Sensor; |
| 8 | import android.hardware.SensorEvent; | 8 | import android.hardware.SensorEvent; |
| 9 | import android.hardware.SensorEventListener; | 9 | import android.hardware.SensorEventListener; |
| 10 | import android.hardware.SensorManager; | 10 | import android.hardware.SensorManager; |
| 11 | import android.os.Bundle; | 11 | import android.os.Bundle; |
| 12 | import android.support.annotation.Nullable; | 12 | import android.support.annotation.Nullable; |
| 13 | import android.view.LayoutInflater; | 13 | import android.view.LayoutInflater; |
| 14 | import android.view.Menu; | 14 | import android.view.Menu; |
| 15 | import android.view.MenuInflater; | 15 | import android.view.MenuInflater; |
| 16 | import android.view.View; | 16 | import android.view.View; |
| 17 | import android.view.ViewGroup; | 17 | import android.view.ViewGroup; |
| 18 | import android.widget.DatePicker; | 18 | import android.widget.DatePicker; |
| 19 | import android.widget.ImageView; | 19 | import android.widget.ImageView; |
| 20 | import android.widget.LinearLayout; | 20 | import android.widget.LinearLayout; |
| 21 | import android.widget.TextView; | 21 | import android.widget.TextView; |
| 22 | import android.widget.Toast; | 22 | import android.widget.Toast; |
| 23 | 23 | ||
| 24 | import com.dinhcv.lifelogpedometer.R; | 24 | import com.dinhcv.lifelogpedometer.R; |
| 25 | import com.dinhcv.lifelogpedometer.interfaces.LLAPIManagerListener; | 25 | import com.dinhcv.lifelogpedometer.interfaces.LLAPIManagerListener; |
| 26 | import com.dinhcv.lifelogpedometer.model.StepModel; | 26 | import com.dinhcv.lifelogpedometer.model.StepModel; |
| 27 | import com.dinhcv.lifelogpedometer.model.structure.top.StepItemInfo; | 27 | import com.dinhcv.lifelogpedometer.model.structure.top.StepItemInfo; |
| 28 | import com.dinhcv.lifelogpedometer.model.structure.top.TopInfo; | 28 | import com.dinhcv.lifelogpedometer.model.structure.top.TopInfo; |
| 29 | import com.dinhcv.lifelogpedometer.portal.ApiServices; | ||
| 29 | import com.dinhcv.lifelogpedometer.portal.LLAPIManager; | 30 | import com.dinhcv.lifelogpedometer.portal.LLAPIManager; |
| 30 | import com.dinhcv.lifelogpedometer.utils.Const; | 31 | import com.dinhcv.lifelogpedometer.utils.Const; |
| 31 | import com.dinhcv.lifelogpedometer.utils.DayAxisValueFormatter; | 32 | import com.dinhcv.lifelogpedometer.utils.DayAxisValueFormatter; |
| 32 | import com.dinhcv.lifelogpedometer.utils.Debug; | 33 | import com.dinhcv.lifelogpedometer.utils.Debug; |
| 33 | import com.dinhcv.lifelogpedometer.utils.Utils; | 34 | import com.dinhcv.lifelogpedometer.utils.Utils; |
| 34 | import com.github.mikephil.charting.components.XAxis; | 35 | import com.github.mikephil.charting.components.XAxis; |
| 35 | import com.github.mikephil.charting.components.YAxis; | 36 | import com.github.mikephil.charting.components.YAxis; |
| 36 | 37 | ||
| 37 | import com.github.mikephil.charting.charts.BarChart; | 38 | import com.github.mikephil.charting.charts.BarChart; |
| 38 | import com.github.mikephil.charting.data.BarData; | 39 | import com.github.mikephil.charting.data.BarData; |
| 39 | import com.github.mikephil.charting.data.BarDataSet; | 40 | import com.github.mikephil.charting.data.BarDataSet; |
| 40 | import com.github.mikephil.charting.data.BarEntry; | 41 | import com.github.mikephil.charting.data.BarEntry; |
| 41 | import com.github.mikephil.charting.interfaces.datasets.IBarDataSet; | 42 | import com.github.mikephil.charting.interfaces.datasets.IBarDataSet; |
| 42 | 43 | ||
| 43 | import org.eazegraph.lib.charts.PieChart; | 44 | import org.eazegraph.lib.charts.PieChart; |
| 44 | import org.eazegraph.lib.models.PieModel; | 45 | import org.eazegraph.lib.models.PieModel; |
| 45 | import org.json.JSONArray; | 46 | import org.json.JSONArray; |
| 46 | import org.json.JSONException; | 47 | import org.json.JSONException; |
| 47 | import org.json.JSONObject; | 48 | import org.json.JSONObject; |
| 48 | 49 | ||
| 49 | import java.text.NumberFormat; | 50 | import java.text.NumberFormat; |
| 50 | import java.util.ArrayList; | 51 | import java.util.ArrayList; |
| 51 | import java.util.Arrays; | 52 | import java.util.Arrays; |
| 52 | import java.util.Calendar; | 53 | import java.util.Calendar; |
| 53 | import java.util.Date; | 54 | import java.util.Date; |
| 54 | import java.util.List; | 55 | import java.util.List; |
| 55 | import java.util.Locale; | 56 | import java.util.Locale; |
| 56 | 57 | ||
| 57 | import static com.github.mikephil.charting.utils.ColorTemplate.rgb; | 58 | import static com.github.mikephil.charting.utils.ColorTemplate.rgb; |
| 58 | 59 | ||
| 59 | 60 | ||
| 60 | public class TopTodayFragment extends FragmentBase implements SettingFragmentPresenter, SensorEventListener { | 61 | public class TopTodayFragment extends FragmentBase implements SettingFragmentPresenter, SensorEventListener { |
| 61 | 62 | ||
| 62 | private TextView stepsView; | 63 | private TextView stepsView; |
| 63 | private TextView tvStepGoal; | 64 | private TextView tvStepGoal; |
| 64 | private TextView tvDistance; | 65 | private TextView tvDistance; |
| 65 | private TextView tvTime; | 66 | private TextView tvTime; |
| 66 | private TextView tvStepRemain; | 67 | private TextView tvStepRemain; |
| 67 | private TextView tvStepRateDone; | 68 | private TextView tvStepRateDone; |
| 68 | private boolean showSteps = true; | 69 | private boolean showSteps = true; |
| 69 | private PieModel sliceGoal, sliceCurrent; | 70 | private PieModel sliceGoal, sliceCurrent; |
| 70 | private PieChart pg; | 71 | private PieChart pg; |
| 71 | private TextView tvDate; | 72 | private TextView tvDate; |
| 72 | private ImageView ivBack; | 73 | private ImageView ivBack; |
| 73 | private ImageView ivNext; | 74 | private ImageView ivNext; |
| 74 | 75 | ||
| 75 | private LinearLayout llBike; | 76 | private LinearLayout llBike; |
| 76 | private LinearLayout llWalking; | 77 | private LinearLayout llWalking; |
| 77 | private LinearLayout llRunning; | 78 | private LinearLayout llRunning; |
| 78 | private Const.STEP_TYPE stepType; | 79 | private Const.STEP_TYPE stepType; |
| 79 | 80 | ||
| 80 | private Date mAnaDate; | 81 | private Date mAnaDate; |
| 81 | private Calendar mCalendar; | 82 | private Calendar mCalendar; |
| 82 | 83 | ||
| 83 | private int mAnaDay; | 84 | private int mAnaDay; |
| 84 | private int mAnaMonth; | 85 | private int mAnaMonth; |
| 85 | private int mAnaYear; | 86 | private int mAnaYear; |
| 86 | 87 | ||
| 87 | public static int STEP_SIZE = 75; | 88 | public static int STEP_SIZE = 75; |
| 88 | private StepModel mStepModel; | 89 | private StepModel mStepModel; |
| 89 | private TextView tvSmallStepGoal; | 90 | private TextView tvSmallStepGoal; |
| 90 | private TextView tvSmallRemain; | 91 | private TextView tvSmallRemain; |
| 91 | private Context mContext; | 92 | private Context mContext; |
| 92 | 93 | ||
| 93 | public final static NumberFormat formatter = NumberFormat.getInstance(Locale.getDefault()); | 94 | public final static NumberFormat formatter = NumberFormat.getInstance(Locale.getDefault()); |
| 94 | private SensorManager sensorManager; | 95 | private SensorManager sensorManager; |
| 95 | private boolean activityRunning; | 96 | private boolean activityRunning; |
| 96 | private int stepTotal = 0; | 97 | private int stepTotal = 0; |
| 97 | private int stepGoal = 0; | 98 | private int stepGoal = 0; |
| 98 | private int stepCount = 0; | 99 | private int stepCount = 0; |
| 99 | 100 | ||
| 100 | private Date mFromDate; | 101 | private Date mFromDate; |
| 101 | private Date mToDate; | 102 | private Date mToDate; |
| 102 | 103 | ||
| 103 | private TopInfo mTopInfo = new TopInfo(); | 104 | private TopInfo mTopInfo = new TopInfo(); |
| 104 | private BarChart mChart; | 105 | private BarChart mChart; |
| 105 | 106 | ||
| 106 | private List<String> dateList; | 107 | private List<String> dateList; |
| 107 | private String[] mParties; | 108 | private String[] mParties; |
| 108 | private Integer[] mStep; | 109 | private Integer[] mStep; |
| 109 | private ProgressDialog progress; | 110 | private ProgressDialog progress; |
| 110 | 111 | ||
| 111 | private TopFragment mTopFragment; | 112 | private TopFragment mTopFragment; |
| 112 | public void setRootFragment(TopFragment frag) { | 113 | public void setRootFragment(TopFragment frag) { |
| 113 | this.mTopFragment = frag; | 114 | this.mTopFragment = frag; |
| 114 | } | 115 | } |
| 115 | 116 | ||
| 116 | @Override | 117 | @Override |
| 117 | public void onCreate(final Bundle savedInstanceState) { | 118 | public void onCreate(final Bundle savedInstanceState) { |
| 118 | super.onCreate(savedInstanceState); | 119 | super.onCreate(savedInstanceState); |
| 119 | setHasOptionsMenu(true); | 120 | setHasOptionsMenu(true); |
| 120 | } | 121 | } |
| 121 | 122 | ||
| 122 | @Override | 123 | @Override |
| 123 | public View onCreateView(final LayoutInflater inflater, final ViewGroup container, | 124 | public View onCreateView(final LayoutInflater inflater, final ViewGroup container, |
| 124 | final Bundle savedInstanceState) { | 125 | final Bundle savedInstanceState) { |
| 125 | final View v = inflater.inflate(R.layout.fragment_top_today, null); | 126 | final View v = inflater.inflate(R.layout.fragment_top_today, null); |
| 126 | mContext = getActivity(); | 127 | mContext = getActivity(); |
| 127 | sensorManager = (SensorManager) mContext.getSystemService(Context.SENSOR_SERVICE); | 128 | sensorManager = (SensorManager) mContext.getSystemService(Context.SENSOR_SERVICE); |
| 128 | 129 | ||
| 129 | initView(v); | 130 | initView(v); |
| 130 | 131 | ||
| 131 | // slice for the steps taken today | 132 | // slice for the steps taken today |
| 132 | sliceCurrent = new PieModel("", 0, Color.parseColor("#6FE7F7")); | 133 | sliceCurrent = new PieModel("", 0, Color.parseColor("#6FE7F7")); |
| 133 | pg.addPieSlice(sliceCurrent); | 134 | pg.addPieSlice(sliceCurrent); |
| 134 | 135 | ||
| 135 | // slice for the "missing" steps until reaching the goal | 136 | // slice for the "missing" steps until reaching the goal |
| 136 | sliceGoal = new PieModel("", Const.STEP_GOAL, Color.parseColor("#B7B8B6")); | 137 | sliceGoal = new PieModel("", Const.STEP_GOAL, Color.parseColor("#B7B8B6")); |
| 137 | pg.addPieSlice(sliceGoal); | 138 | pg.addPieSlice(sliceGoal); |
| 139 | |||
| 138 | pg.setDrawValueInPie(false); | 140 | pg.setDrawValueInPie(false); |
| 139 | pg.setUsePieRotation(false); | 141 | pg.setUsePieRotation(false); |
| 142 | pg.setInnerPadding(93); | ||
| 143 | pg.setInnerPaddingColor(R.color.background_main); | ||
| 140 | pg.startAnimation(); | 144 | pg.startAnimation(); |
| 141 | pg.setAutoCenterInSlice(false); | 145 | pg.setAutoCenterInSlice(false); |
| 142 | 146 | ||
| 143 | mCalendar = Calendar.getInstance(); | 147 | mCalendar = Calendar.getInstance(); |
| 144 | mCalendar.setTime(new Date()); | 148 | mCalendar.setTime(new Date()); |
| 145 | mAnaDate = mCalendar.getTime(); | 149 | mAnaDate = mCalendar.getTime(); |
| 146 | mAnaYear = mCalendar.get(Calendar.YEAR); | 150 | mAnaYear = mCalendar.get(Calendar.YEAR); |
| 147 | mAnaMonth = mCalendar.get(Calendar.MONTH); | 151 | mAnaMonth = mCalendar.get(Calendar.MONTH); |
| 148 | mAnaDay = mCalendar.get(Calendar.DAY_OF_MONTH); | 152 | mAnaDay = mCalendar.get(Calendar.DAY_OF_MONTH); |
| 149 | 153 | ||
| 150 | mFromDate = new Date(); | 154 | mFromDate = new Date(); |
| 151 | 155 | ||
| 152 | tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(mAnaDate)); | 156 | tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(mAnaDate)); |
| 153 | 157 | ||
| 154 | initData(); | 158 | initData(); |
| 155 | 159 | ||
| 156 | handleEvent(); | 160 | handleEvent(); |
| 157 | 161 | ||
| 158 | getTopPage(mAnaDate, stepType); | 162 | getTopPage(mAnaDate, stepType); |
| 159 | 163 | ||
| 160 | return v; | 164 | return v; |
| 161 | } | 165 | } |
| 162 | 166 | ||
| 163 | private void initView(View v){ | 167 | private void initView(View v){ |
| 164 | stepsView = (TextView) v.findViewById(R.id.steps); | 168 | stepsView = (TextView) v.findViewById(R.id.steps); |
| 165 | tvDistance = (TextView) v.findViewById(R.id.tv_distance); | 169 | tvDistance = (TextView) v.findViewById(R.id.tv_distance); |
| 166 | tvStepGoal = (TextView) v.findViewById(R.id.tv_stepGoal); | 170 | tvStepGoal = (TextView) v.findViewById(R.id.tv_stepGoal); |
| 167 | tvStepRemain = (TextView) v.findViewById(R.id.tv_stepRemain); | 171 | tvStepRemain = (TextView) v.findViewById(R.id.tv_stepRemain); |
| 168 | tvStepRateDone = (TextView) v.findViewById(R.id.tv_stepRateDone); | 172 | tvStepRateDone = (TextView) v.findViewById(R.id.tv_stepRateDone); |
| 169 | tvSmallStepGoal = (TextView) v.findViewById(R.id.tv_smallStepGoal); | 173 | tvSmallStepGoal = (TextView) v.findViewById(R.id.tv_smallStepGoal); |
| 170 | tvSmallRemain = (TextView) v.findViewById(R.id.tv_smallRemain); | 174 | tvSmallRemain = (TextView) v.findViewById(R.id.tv_smallRemain); |
| 171 | tvTime = (TextView) v.findViewById(R.id.tv_time); | 175 | tvTime = (TextView) v.findViewById(R.id.tv_time); |
| 172 | tvDate = (TextView) v.findViewById(R.id.tv_date); | 176 | tvDate = (TextView) v.findViewById(R.id.tv_date); |
| 173 | ivBack = (ImageView) v.findViewById(R.id.iv_back); | 177 | ivBack = (ImageView) v.findViewById(R.id.iv_back); |
| 174 | ivNext = (ImageView) v.findViewById(R.id.iv_next); | 178 | ivNext = (ImageView) v.findViewById(R.id.iv_next); |
| 175 | 179 | ||
| 176 | mChart = (BarChart) v.findViewById(R.id.chart); | 180 | mChart = (BarChart) v.findViewById(R.id.chart); |
| 177 | pg = (PieChart) v.findViewById(R.id.graph); | 181 | pg = (PieChart) v.findViewById(R.id.graph); |
| 178 | 182 | ||
| 179 | llRunning = (LinearLayout) v.findViewById(R.id.ll_running); | 183 | llRunning = (LinearLayout) v.findViewById(R.id.ll_running); |
| 180 | llWalking = (LinearLayout) v.findViewById(R.id.ll_walking); | 184 | llWalking = (LinearLayout) v.findViewById(R.id.ll_walking); |
| 181 | llBike = (LinearLayout) v.findViewById(R.id.ll_bike); | 185 | llBike = (LinearLayout) v.findViewById(R.id.ll_bike); |
| 182 | } | 186 | } |
| 183 | 187 | ||
| 184 | private void initData(){ | 188 | private void initData(){ |
| 185 | mCalendar = Calendar.getInstance(); | 189 | mCalendar = Calendar.getInstance(); |
| 186 | mCalendar.setTime(new Date()); | 190 | mCalendar.setTime(new Date()); |
| 187 | mAnaDate = mCalendar.getTime(); | 191 | mAnaDate = mCalendar.getTime(); |
| 188 | mAnaYear = mCalendar.get(Calendar.YEAR); | 192 | mAnaYear = mCalendar.get(Calendar.YEAR); |
| 189 | mAnaMonth = mCalendar.get(Calendar.MONTH); | 193 | mAnaMonth = mCalendar.get(Calendar.MONTH); |
| 190 | mAnaDay = mCalendar.get(Calendar.DAY_OF_MONTH); | 194 | mAnaDay = mCalendar.get(Calendar.DAY_OF_MONTH); |
| 191 | 195 | ||
| 192 | 196 | ||
| 193 | stepType = Const.STEP_TYPE.WALKING; | 197 | stepType = Const.STEP_TYPE.WALKING; |
| 194 | updateUiStepType(false, true, false); | 198 | updateUiStepType(false, true, false); |
| 195 | 199 | ||
| 196 | tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(mAnaDate)); | 200 | tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(mAnaDate)); |
| 197 | } | 201 | } |
| 198 | 202 | ||
| 199 | private void updateUiStepType(boolean b1, boolean b2, boolean b3) { | 203 | private void updateUiStepType(boolean b1, boolean b2, boolean b3) { |
| 200 | llBike.setSelected(b1); | 204 | llBike.setSelected(b1); |
| 201 | llWalking.setSelected(b2); | 205 | llWalking.setSelected(b2); |
| 202 | llRunning.setSelected(b3); | 206 | llRunning.setSelected(b3); |
| 203 | } | 207 | } |
| 204 | 208 | ||
| 205 | private void stepsDistanceChanged() { | 209 | private void stepsDistanceChanged() { |
| 206 | if (progress != null){ | 210 | if (progress != null){ |
| 207 | progress.dismiss(); | 211 | progress.dismiss(); |
| 208 | } | 212 | } |
| 209 | updatePie(); | 213 | updatePie(); |
| 210 | updateBars(); | 214 | updateBars(); |
| 211 | } | 215 | } |
| 212 | 216 | ||
| 213 | 217 | ||
| 214 | @Override | 218 | @Override |
| 215 | public void onCreateOptionsMenu(final Menu menu, final MenuInflater inflater) { | 219 | public void onCreateOptionsMenu(final Menu menu, final MenuInflater inflater) { |
| 216 | inflater.inflate(R.menu.main, menu); | 220 | inflater.inflate(R.menu.main, menu); |
| 217 | } | 221 | } |
| 218 | 222 | ||
| 219 | private void getTopPage(Date date, Const.STEP_TYPE stepType){ | 223 | private void getTopPage(Date date, Const.STEP_TYPE stepType){ |
| 220 | 224 | ||
| 221 | progress = new ProgressDialog(mContext); | 225 | progress = new ProgressDialog(mContext); |
| 222 | progress.setMessage(getString(R.string.loading)); | 226 | progress.setMessage(getString(R.string.loading)); |
| 223 | progress.setCancelable(false); | 227 | progress.setCancelable(false); |
| 224 | progress.show(); | 228 | progress.show(); |
| 225 | LLAPIManager.topInfo(date, stepType, new LLAPIManagerListener() { | 229 | ApiServices.topInfo(date, stepType, new LLAPIManagerListener() { |
| 226 | @Override | 230 | @Override |
| 227 | public void onError(Error error) { | 231 | public void onError(Error error) { |
| 228 | Debug.error("Get data history error"); | 232 | Debug.error("Get data history error"); |
| 229 | hiddenDialog(); | 233 | hiddenDialog(); |
| 230 | showDialogNotData(); | 234 | showDialogNotData(); |
| 231 | } | 235 | } |
| 232 | 236 | ||
| 233 | @Override | 237 | @Override |
| 234 | public void onSuccess(String json) { | 238 | public void onSuccess(String json) { |
| 235 | Debug.error("Get data history success"); | 239 | Debug.error("Get data history success"); |
| 236 | loadDataDone(json); | 240 | loadDataDone(json); |
| 237 | } | 241 | } |
| 238 | 242 | ||
| 239 | @Override | 243 | @Override |
| 240 | public void onSuccess(JSONObject object) { | 244 | public void onSuccess(JSONObject object) { |
| 241 | Debug.error("Get data history success"); | 245 | Debug.error("Get data history success"); |
| 242 | hiddenDialog(); | 246 | hiddenDialog(); |
| 243 | } | 247 | } |
| 244 | }); | 248 | }); |
| 245 | } | 249 | } |
| 246 | 250 | ||
| 247 | private void showDialogNotData(){ | 251 | private void showDialogNotData(){ |
| 248 | showAlerDialog(mContext, getResources().getString(R.string.can_not_get_data)); | 252 | showAlerDialog(mContext, getResources().getString(R.string.can_not_get_data)); |
| 249 | } | 253 | } |
| 250 | 254 | ||
| 251 | private void loadDataDone(String jsonString) { | 255 | private void loadDataDone(String jsonString) { |
| 252 | JSONObject jsonObject = null; | 256 | JSONObject jsonObject = null; |
| 253 | try { | 257 | try { |
| 254 | jsonObject = new JSONObject(jsonString); | 258 | jsonObject = new JSONObject(jsonString); |
| 255 | int status = jsonObject.optInt("status"); | 259 | int status = jsonObject.optInt("status"); |
| 256 | if (status == 1) { | 260 | if (status == 1) { |
| 257 | JSONObject jsonObject1 = jsonObject.optJSONObject("result"); | 261 | JSONObject jsonObject1 = jsonObject.optJSONObject("result"); |
| 258 | JSONObject targetInf = jsonObject1.getJSONObject("targetInf"); | 262 | JSONObject targetInf = jsonObject1.getJSONObject("targetInf"); |
| 259 | 263 | ||
| 260 | if (targetInf != null){ | 264 | if (targetInf != null){ |
| 261 | String target = targetInf.optString("target_step"); | 265 | String target = targetInf.optString("target_step"); |
| 262 | Debug.normal("Target: "+ target); | 266 | Debug.normal("Target: "+ target); |
| 263 | mTopInfo.setTaget(targetInf.optString("target_step")); | 267 | mTopInfo.setTaget(targetInf.optString("target_step")); |
| 264 | mTopInfo.setSteps(targetInf.optString("num_step")); | 268 | mTopInfo.setSteps(targetInf.optString("num_step")); |
| 265 | mTopInfo.setStepRemain(targetInf.optString("remaining_step")); | 269 | mTopInfo.setStepRemain(targetInf.optString("remaining_step")); |
| 266 | mTopInfo.setCompletePercent(targetInf.optString("complete_percent")); | 270 | mTopInfo.setCompletePercent(targetInf.optString("complete_percent")); |
| 267 | } | 271 | } |
| 268 | 272 | ||
| 269 | mTopInfo.setKcalo(jsonObject1.optString("kcal")); | 273 | mTopInfo.setKcalo(jsonObject1.optString("kcal")); |
| 270 | mTopInfo.setDistance(jsonObject1.optString("distance")); | 274 | mTopInfo.setDistance(jsonObject1.optString("distance")); |
| 271 | mTopInfo.setTime(jsonObject1.optString("time")); | 275 | mTopInfo.setTime(jsonObject1.optString("time")); |
| 272 | JSONArray stepArr = jsonObject1.optJSONArray("dataChart"); | 276 | JSONArray stepArr = jsonObject1.optJSONArray("dataChart"); |
| 273 | 277 | ||
| 274 | 278 | ||
| 275 | if (stepArr != null && stepArr.length() > 0) { | 279 | if (stepArr != null && stepArr.length() > 0) { |
| 276 | List<StepItemInfo> infoLists = new ArrayList<>(); | 280 | List<StepItemInfo> infoLists = new ArrayList<>(); |
| 277 | for (int i = 0; i < stepArr.length(); i++){ | 281 | for (int i = 0; i < stepArr.length(); i++){ |
| 278 | StepItemInfo stepItemInfo = new StepItemInfo(); | 282 | StepItemInfo stepItemInfo = new StepItemInfo(); |
| 279 | JSONObject ob = (JSONObject) stepArr.get(i); | 283 | JSONObject ob = (JSONObject) stepArr.get(i); |
| 280 | stepItemInfo.setHour(ob.optInt("hour")); | 284 | stepItemInfo.setHour(ob.optInt("hour")); |
| 281 | stepItemInfo.setNumStep(ob.optInt("numStep")); | 285 | stepItemInfo.setNumStep(ob.optInt("numStep")); |
| 282 | infoLists.add(stepItemInfo); | 286 | infoLists.add(stepItemInfo); |
| 283 | } | 287 | } |
| 284 | 288 | ||
| 285 | mTopInfo.setStepList(infoLists); | 289 | mTopInfo.setStepList(infoLists); |
| 286 | } | 290 | } |
| 287 | 291 | ||
| 288 | } | 292 | } |
| 289 | } catch (JSONException e) { | 293 | } catch (JSONException e) { |
| 290 | e.printStackTrace(); | 294 | e.printStackTrace(); |
| 291 | mTopInfo = new TopInfo();; | 295 | mTopInfo = new TopInfo();; |
| 292 | } | 296 | } |
| 293 | 297 | ||
| 294 | stepsDistanceChanged(); | 298 | stepsDistanceChanged(); |
| 295 | } | 299 | } |
| 296 | 300 | ||
| 297 | private void updatePie() { | 301 | private void updatePie() { |
| 298 | // todayOffset might still be Integer.MIN_VALUE on first start | 302 | // todayOffset might still be Integer.MIN_VALUE on first start |
| 299 | int stepsToday = 0; | 303 | int stepsToday = 0; |
| 300 | int stepTarget = 0; | 304 | int stepTarget = 0; |
| 301 | if (mTopInfo != null) { | 305 | if (mTopInfo != null) { |
| 302 | if (mTopInfo.getSteps().contains(",")){ | 306 | if (mTopInfo.getSteps().contains(",")){ |
| 303 | stepsToday = Integer.valueOf(mTopInfo.getSteps().replace(",", "")); | 307 | stepsToday = Integer.valueOf(mTopInfo.getSteps().replace(",", "")); |
| 304 | }else { | 308 | }else { |
| 305 | stepsToday = Integer.valueOf(mTopInfo.getSteps()); | 309 | stepsToday = Integer.valueOf(mTopInfo.getSteps()); |
| 306 | } | 310 | } |
| 307 | 311 | ||
| 308 | if (mTopInfo.getTaget().contains(",")) { | 312 | if (mTopInfo.getTaget().contains(",")) { |
| 309 | stepTarget = Integer.valueOf(mTopInfo.getTaget().replace(",", "")); | 313 | stepTarget = Integer.valueOf(mTopInfo.getTaget().replace(",", "")); |
| 310 | }else { | 314 | }else { |
| 311 | stepTarget = Integer.valueOf(mTopInfo.getTaget()); | 315 | stepTarget = Integer.valueOf(mTopInfo.getTaget()); |
| 312 | } | 316 | } |
| 313 | } | 317 | } |
| 314 | sliceCurrent.setValue(stepsToday); | 318 | sliceCurrent.setValue(stepsToday); |
| 315 | if (stepTarget - stepsToday > 0) { | 319 | if (stepTarget - stepsToday > 0) { |
| 316 | // goal not reached yet | 320 | // goal not reached yet |
| 317 | if (pg.getData().size() == 1) { | 321 | if (pg.getData().size() == 1) { |
| 318 | pg.addPieSlice(sliceGoal); | 322 | pg.addPieSlice(sliceGoal); |
| 319 | } | 323 | } |
| 320 | sliceGoal.setValue(stepTarget - stepsToday); | 324 | sliceGoal.setValue(stepTarget - stepsToday); |
| 321 | } else { | 325 | } else { |
| 322 | // goal reached | 326 | // goal reached |
| 323 | pg.clearChart(); | 327 | pg.clearChart(); |
| 324 | pg.addPieSlice(sliceCurrent); | 328 | pg.addPieSlice(sliceCurrent); |
| 325 | } | 329 | } |
| 326 | pg.update(); | 330 | pg.update(); |
| 327 | stepGoal = stepTarget; | 331 | stepGoal = stepTarget; |
| 328 | stepTotal = stepsToday; | 332 | stepTotal = stepsToday; |
| 329 | stepsView.setText(formatter.format(stepsToday)); | 333 | stepsView.setText(formatter.format(stepsToday)); |
| 330 | int stepRemain = stepTarget - stepsToday; | 334 | int stepRemain = stepTarget - stepsToday; |
| 331 | tvStepRemain.setText(String.valueOf(stepRemain)); | 335 | tvStepRemain.setText(String.valueOf(stepRemain)); |
| 332 | tvStepRateDone.setText(getResources().getString(R.string.percent_unit, Utils.convert2String2Decimal(stepsToday *100/ stepTarget))); | 336 | tvStepRateDone.setText(getResources().getString(R.string.percent_unit, Utils.convert2String2Decimal(stepsToday *100/ stepTarget))); |
| 333 | tvSmallRemain.setText(getResources().getString(R.string.pie_text_content3a, stepRemain)); | 337 | tvSmallRemain.setText(getResources().getString(R.string.pie_text_content3a, stepRemain)); |
| 334 | tvStepGoal.setText(mTopInfo.getTaget()); | 338 | tvStepGoal.setText(mTopInfo.getTaget()); |
| 335 | tvSmallStepGoal.setText(mTopInfo.getTaget()); | 339 | tvSmallStepGoal.setText(mTopInfo.getTaget()); |
| 336 | 340 | ||
| 337 | tvDistance.setText(mTopInfo.getDistance()); | 341 | tvDistance.setText(mTopInfo.getDistance()); |
| 338 | tvTime.setText(mTopInfo.getTime()); | 342 | tvTime.setText(mTopInfo.getTime()); |
| 339 | 343 | ||
| 340 | double distanceToday = stepsToday * STEP_SIZE; | 344 | double distanceToday = stepsToday * STEP_SIZE; |
| 341 | distanceToday /= 100000; | 345 | distanceToday /= 100000; |
| 342 | tvDistance.setText(Utils.convert2String2Decimal(distanceToday)); | 346 | tvDistance.setText(Utils.convert2String2Decimal(distanceToday)); |
| 343 | 347 | ||
| 344 | } | 348 | } |
| 345 | 349 | ||
| 346 | /** | 350 | /** |
| 347 | * Updates the bar graph to show the steps/distance of the last week. Should | 351 | * Updates the bar graph to show the steps/distance of the last week. Should |
| 348 | * be called when switching from step count to distance. | 352 | * be called when switching from step count to distance. |
| 349 | */ | 353 | */ |
| 350 | private void updateBars() { | 354 | private void updateBars() { |
| 351 | 355 | ||
| 352 | dateList = new ArrayList<>(); | 356 | dateList = new ArrayList<>(); |
| 353 | List<String> dateList = new ArrayList<>(); | 357 | List<String> dateList = new ArrayList<>(); |
| 354 | List<Integer> stepList = new ArrayList<>(); | 358 | List<Integer> stepList = new ArrayList<>(); |
| 355 | List<StepItemInfo> stepItemInfos = mTopInfo.getStepList(); | 359 | List<StepItemInfo> stepItemInfos = mTopInfo.getStepList(); |
| 356 | if (stepItemInfos != null && stepItemInfos.size() >0) { | 360 | if (stepItemInfos != null && stepItemInfos.size() >0) { |
| 357 | for (int i = 0; i < stepItemInfos.size(); i++){ | 361 | for (int i = 0; i < stepItemInfos.size(); i++){ |
| 358 | dateList.add(String.valueOf(stepItemInfos.get(i).getHour())); | 362 | dateList.add(String.valueOf(stepItemInfos.get(i).getHour())); |
| 359 | stepList.add(stepItemInfos.get(i).getNumStep()); | 363 | stepList.add(stepItemInfos.get(i).getNumStep()); |
| 360 | } | 364 | } |
| 361 | } | 365 | } |
| 362 | 366 | ||
| 363 | mStep = stepList.toArray(new Integer[0]); | 367 | mStep = stepList.toArray(new Integer[0]); |
| 364 | mParties = dateList.toArray(new String[0]); | 368 | mParties = dateList.toArray(new String[0]); |
| 365 | 369 | ||
| 366 | initGraph(); | 370 | initGraph(); |
| 367 | } | 371 | } |
| 368 | 372 | ||
| 369 | private void initGraph(){ | 373 | private void initGraph(){ |
| 370 | 374 | ||
| 371 | mChart.setDrawBarShadow(false); | 375 | mChart.setDrawBarShadow(false); |
| 372 | mChart.setDrawValueAboveBar(true); | 376 | mChart.setDrawValueAboveBar(true); |
| 373 | 377 | ||
| 374 | // if more than 60 entries are displayed in the chart, no values will be | 378 | // if more than 60 entries are displayed in the chart, no values will be |
| 375 | // drawn | 379 | // drawn |
| 376 | mChart.setMaxVisibleValueCount(60); | 380 | mChart.setMaxVisibleValueCount(60); |
| 377 | 381 | ||
| 378 | mChart.getDescription().setEnabled(false); | 382 | mChart.getDescription().setEnabled(false); |
| 379 | // scaling can now only be done on x- and y-axis separately | 383 | // scaling can now only be done on x- and y-axis separately |
| 380 | mChart.setPinchZoom(false); | 384 | mChart.setPinchZoom(false); |
| 381 | 385 | ||
| 382 | mChart.setDrawGridBackground(false); | 386 | mChart.setDrawGridBackground(false); |
| 383 | // mChart.setDrawYLabels(false); | 387 | // mChart.setDrawYLabels(false); |
| 384 | List<String> listx = Arrays.asList(mParties); | 388 | List<String> listx = Arrays.asList(mParties); |
| 385 | DayAxisValueFormatter xValueFormatter = new DayAxisValueFormatter(listx); | 389 | DayAxisValueFormatter xValueFormatter = new DayAxisValueFormatter(listx); |
| 386 | 390 | ||
| 387 | XAxis xAxis = mChart.getXAxis(); | 391 | XAxis xAxis = mChart.getXAxis(); |
| 388 | xAxis.setLabelRotationAngle(0); | 392 | xAxis.setLabelRotationAngle(0); |
| 389 | xAxis.setPosition(XAxis.XAxisPosition.TOP); | 393 | xAxis.setPosition(XAxis.XAxisPosition.TOP); |
| 390 | xAxis.setDrawGridLines(true); | 394 | xAxis.setDrawGridLines(true); |
| 391 | xAxis.setLabelCount(10); | 395 | xAxis.setLabelCount(10); |
| 392 | xAxis.setTextColor(Color.WHITE); | 396 | xAxis.setTextColor(Color.WHITE); |
| 393 | xAxis.setValueFormatter(xValueFormatter); | 397 | xAxis.setValueFormatter(xValueFormatter); |
| 394 | 398 | ||
| 395 | 399 | ||
| 396 | YAxis leftAxis = mChart.getAxisLeft(); | 400 | YAxis leftAxis = mChart.getAxisLeft(); |
| 397 | leftAxis.setDrawLabels(false); | 401 | leftAxis.setDrawLabels(false); |
| 398 | leftAxis.setDrawGridLines(false); | 402 | leftAxis.setDrawGridLines(false); |
| 399 | leftAxis.setAxisMinimum(0f); | 403 | leftAxis.setAxisMinimum(0f); |
| 400 | leftAxis.setAxisMaximum(10000f); | 404 | leftAxis.setAxisMaximum(10000f); |
| 401 | leftAxis.setDrawZeroLine(false); | 405 | leftAxis.setDrawZeroLine(false); |
| 402 | 406 | ||
| 403 | leftAxis.setEnabled(false); | 407 | leftAxis.setEnabled(false); |
| 404 | mChart.setDrawValueAboveBar(false); | 408 | mChart.setDrawValueAboveBar(false); |
| 405 | mChart.getAxisRight().setEnabled(false); | 409 | mChart.getAxisRight().setEnabled(false); |
| 406 | 410 | ||
| 407 | // set auto scale min max | 411 | // set auto scale min max |
| 408 | mChart.setAutoScaleMinMaxEnabled(true); | 412 | mChart.setAutoScaleMinMaxEnabled(true); |
| 409 | mChart.notifyDataSetChanged(); | 413 | mChart.notifyDataSetChanged(); |
| 410 | 414 | ||
| 411 | // Set enimate y | 415 | // Set enimate y |
| 412 | mChart.animateY(2000); | 416 | mChart.animateY(2000); |
| 413 | 417 | ||
| 414 | setData(); | 418 | setData(); |
| 415 | 419 | ||
| 416 | mChart.getLegend().setEnabled(false); | 420 | mChart.getLegend().setEnabled(false); |
| 417 | } | 421 | } |
| 418 | 422 | ||
| 419 | 423 | ||
| 420 | private void setData() { | 424 | private void setData() { |
| 421 | 425 | ||
| 422 | ArrayList<String> xVals = new ArrayList<>(); | 426 | ArrayList<String> xVals = new ArrayList<>(); |
| 423 | for (int i = 0; i < mStep.length; i++) { | 427 | for (int i = 0; i < mStep.length; i++) { |
| 424 | xVals.add(mParties[i % mStep.length]); | 428 | xVals.add(mParties[i % mStep.length]); |
| 425 | } | 429 | } |
| 426 | 430 | ||
| 427 | ArrayList<BarEntry> yVals1 = new ArrayList<>(); | 431 | ArrayList<BarEntry> yVals1 = new ArrayList<>(); |
| 428 | for (int i = 0; i < mStep.length; i++) { | 432 | for (int i = 0; i < mStep.length; i++) { |
| 429 | float val = (float) (mStep[i]*1); | 433 | float val = (float) (mStep[i]*1); |
| 430 | yVals1.add(new BarEntry(i, val)); | 434 | yVals1.add(new BarEntry(i, val)); |
| 431 | } | 435 | } |
| 432 | 436 | ||
| 433 | BarDataSet set1; | 437 | BarDataSet set1; |
| 434 | 438 | ||
| 435 | if (mChart.getData() != null && mChart.getData().getDataSetCount() > 0) { | 439 | if (mChart.getData() != null && mChart.getData().getDataSetCount() > 0) { |
| 436 | set1 = (BarDataSet)mChart.getData().getDataSetByIndex(0); | 440 | set1 = (BarDataSet)mChart.getData().getDataSetByIndex(0); |
| 437 | set1.setValues(yVals1); | 441 | set1.setValues(yVals1); |
| 438 | mChart.getData().notifyDataChanged(); | 442 | mChart.getData().notifyDataChanged(); |
| 439 | mChart.notifyDataSetChanged(); | 443 | mChart.notifyDataSetChanged(); |
| 440 | } else { | 444 | } else { |
| 441 | ArrayList<Integer> colors = new ArrayList<>(); | 445 | ArrayList<Integer> colors = new ArrayList<>(); |
| 442 | 446 | ||
| 443 | 447 | ||
| 444 | int[] MATERIAL_COLORS = {rgb("#40CDEF")}; | 448 | int[] MATERIAL_COLORS = {rgb("#40CDEF")}; |
| 445 | 449 | ||
| 446 | for (int c : MATERIAL_COLORS) | 450 | for (int c : MATERIAL_COLORS) |
| 447 | colors.add(c); | 451 | colors.add(c); |
| 448 | 452 | ||
| 449 | set1 = new BarDataSet(yVals1, null); | 453 | set1 = new BarDataSet(yVals1, null); |
| 450 | 454 | ||
| 451 | set1.setColors(colors); | 455 | set1.setColors(colors); |
| 452 | 456 | ||
| 453 | ArrayList<IBarDataSet> dataSets = new ArrayList<>(); | 457 | ArrayList<IBarDataSet> dataSets = new ArrayList<>(); |
| 454 | dataSets.add(set1); | 458 | dataSets.add(set1); |
| 455 | 459 | ||
| 456 | BarData data = new BarData(dataSets); | 460 | BarData data = new BarData(dataSets); |
| 457 | data.setValueTextSize(10f); | 461 | data.setValueTextSize(10f); |
| 458 | 462 | ||
| 459 | mChart.setData(data); | 463 | mChart.setData(data); |
| 460 | } | 464 | } |
| 461 | } | 465 | } |
| 462 | 466 | ||
| 463 | 467 | ||
| 464 | 468 | ||
| 465 | private void handleEvent(){ | 469 | private void handleEvent(){ |
| 466 | tvDate.setOnClickListener(new View.OnClickListener() { | 470 | tvDate.setOnClickListener(new View.OnClickListener() { |
| 467 | @Override | 471 | @Override |
| 468 | public void onClick(View view) { | 472 | public void onClick(View view) { |
| 469 | handleAnaDatePicker(); | 473 | handleAnaDatePicker(); |
| 470 | } | 474 | } |
| 471 | }); | 475 | }); |
| 472 | 476 | ||
| 473 | ivBack.setOnClickListener(new View.OnClickListener() { | 477 | ivBack.setOnClickListener(new View.OnClickListener() { |
| 474 | @Override | 478 | @Override |
| 475 | public void onClick(View view) { | 479 | public void onClick(View view) { |
| 476 | mCalendar = Calendar.getInstance(); | 480 | mCalendar = Calendar.getInstance(); |
| 477 | mCalendar.setTime(mAnaDate); | 481 | mCalendar.setTime(mAnaDate); |
| 478 | mCalendar.add(Calendar.DAY_OF_MONTH, -1); | 482 | mCalendar.add(Calendar.DAY_OF_MONTH, -1); |
| 479 | Date date = mCalendar.getTime(); | 483 | Date date = mCalendar.getTime(); |
| 480 | tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(date)); | 484 | tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(date)); |
| 481 | mAnaDate = date; | 485 | mAnaDate = date; |
| 482 | } | 486 | } |
| 483 | }); | 487 | }); |
| 484 | 488 | ||
| 485 | ivNext.setOnClickListener(new View.OnClickListener() { | 489 | ivNext.setOnClickListener(new View.OnClickListener() { |
| 486 | @Override | 490 | @Override |
| 487 | public void onClick(View view) { | 491 | public void onClick(View view) { |
| 488 | mCalendar = Calendar.getInstance(); | 492 | mCalendar = Calendar.getInstance(); |
| 489 | mCalendar.setTime(mAnaDate); | 493 | mCalendar.setTime(mAnaDate); |
| 490 | mCalendar.add(Calendar.DAY_OF_MONTH, +1); | 494 | mCalendar.add(Calendar.DAY_OF_MONTH, +1); |
| 491 | Date date = mCalendar.getTime(); | 495 | Date date = mCalendar.getTime(); |
| 492 | tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(date)); | 496 | tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(date)); |
| 493 | mAnaDate = date; | 497 | mAnaDate = date; |
| 494 | } | 498 | } |
| 495 | }); | 499 | }); |
| 496 | 500 | ||
| 497 | llBike.setOnClickListener(new View.OnClickListener() { | 501 | llBike.setOnClickListener(new View.OnClickListener() { |
| 498 | @Override | 502 | @Override |
| 499 | public void onClick(View view) { | 503 | public void onClick(View view) { |
| 500 | stepType = Const.STEP_TYPE.BIKE; | 504 | stepType = Const.STEP_TYPE.BIKE; |
| 501 | updateUiStepType(true, false, false); | 505 | updateUiStepType(true, false, false); |
| 502 | getTopPage(mAnaDate, stepType); | 506 | getTopPage(mAnaDate, stepType); |
| 503 | } | 507 | } |
| 504 | }); | 508 | }); |
| 505 | 509 | ||
| 506 | llRunning.setOnClickListener(new View.OnClickListener() { | 510 | llRunning.setOnClickListener(new View.OnClickListener() { |
| 507 | @Override | 511 | @Override |
| 508 | public void onClick(View view) { | 512 | public void onClick(View view) { |
| 509 | stepType = Const.STEP_TYPE.RUNNING; | 513 | stepType = Const.STEP_TYPE.RUNNING; |
| 510 | updateUiStepType(false, false, true); | 514 | updateUiStepType(false, false, true); |
| 511 | getTopPage(mAnaDate, stepType); | 515 | getTopPage(mAnaDate, stepType); |
| 512 | } | 516 | } |
| 513 | }); | 517 | }); |
| 514 | 518 | ||
| 515 | llWalking.setOnClickListener(new View.OnClickListener() { | 519 | llWalking.setOnClickListener(new View.OnClickListener() { |
| 516 | @Override | 520 | @Override |
| 517 | public void onClick(View view) { | 521 | public void onClick(View view) { |
| 518 | stepType = Const.STEP_TYPE.WALKING; | 522 | stepType = Const.STEP_TYPE.WALKING; |
| 519 | updateUiStepType(false, true, false); | 523 | updateUiStepType(false, true, false); |
| 520 | getTopPage(mAnaDate, stepType); | 524 | getTopPage(mAnaDate, stepType); |
| 521 | } | 525 | } |
| 522 | }); | 526 | }); |
| 523 | 527 | ||
| 524 | 528 | ||
| 525 | } | 529 | } |
| 526 | 530 | ||
| 527 | 531 | ||
| 528 | /** | 532 | /** |
| 529 | * Show date picker dialog | 533 | * Show date picker dialog |
| 530 | */ | 534 | */ |
| 531 | private void handleAnaDatePicker() { | 535 | private void handleAnaDatePicker() { |
| 532 | 536 | ||
| 533 | new DatePickerDialog(getActivity(), new DatePickerDialog.OnDateSetListener() { | 537 | new DatePickerDialog(getActivity(), new DatePickerDialog.OnDateSetListener() { |
| 534 | @Override | 538 | @Override |
| 535 | public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { | 539 | public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { |
| 536 | 540 | ||
| 537 | mCalendar = Calendar.getInstance(); | 541 | mCalendar = Calendar.getInstance(); |
| 538 | mCalendar.set(year, monthOfYear, dayOfMonth); | 542 | mCalendar.set(year, monthOfYear, dayOfMonth); |
| 539 | mAnaYear = year; | 543 | mAnaYear = year; |
| 540 | mAnaMonth = monthOfYear; | 544 | mAnaMonth = monthOfYear; |
| 541 | mAnaDay = dayOfMonth; | 545 | mAnaDay = dayOfMonth; |
| 542 | Date date = mCalendar.getTime(); | 546 | Date date = mCalendar.getTime(); |
| 543 | tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(date)); | 547 | tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(date)); |
| 544 | mAnaDate = date; | 548 | mAnaDate = date; |
| 545 | getTopPage(mAnaDate, stepType); | 549 | getTopPage(mAnaDate, stepType); |
| 546 | } | 550 | } |
| 547 | }, mAnaYear, mAnaMonth, mAnaDay).show(); | 551 | }, mAnaYear, mAnaMonth, mAnaDay).show(); |
| 548 | 552 | ||
| 549 | } | 553 | } |
| 550 | 554 | ||
| 551 | 555 | ||
| 552 | private void updateUI(){ | 556 | private void updateUI(){ |
| 553 | Debug.normal("Step total================ "+ stepTotal); | 557 | Debug.normal("Step total================ "+ stepTotal); |
| 554 | int stepRemain = stepGoal - stepTotal; | 558 | int stepRemain = stepGoal - stepTotal; |
| 555 | double percentDone = stepTotal *100.0 / stepGoal; | 559 | double percentDone = stepTotal *100.0 / stepGoal; |
| 556 | stepsView.setText(String.valueOf(stepTotal)); | 560 | stepsView.setText(String.valueOf(stepTotal)); |
| 557 | tvStepRemain.setText(String.valueOf(stepRemain)); | 561 | tvStepRemain.setText(String.valueOf(stepRemain)); |
| 558 | tvStepRateDone.setText(getResources().getString(R.string.percent_unit, Utils.convert2String2Decimal(percentDone))); | 562 | tvStepRateDone.setText(getResources().getString(R.string.percent_unit, Utils.convert2String2Decimal(percentDone))); |
| 559 | tvSmallRemain.setText(String.valueOf(stepRemain)); | 563 | tvSmallRemain.setText(String.valueOf(stepRemain)); |
| 560 | } | 564 | } |
| 561 | 565 | ||
| 562 | @Override | 566 | @Override |
| 563 | public void onAttach(Context context) { | 567 | public void onAttach(Context context) { |
| 564 | super.onAttach(context); | 568 | super.onAttach(context); |
| 565 | 569 | ||
| 566 | } | 570 | } |
| 567 | 571 | ||
| 568 | @Override | 572 | @Override |
| 569 | public void onSaveData() { | 573 | public void onSaveData() { |
| 570 | 574 | ||
| 571 | } | 575 | } |
| 572 | 576 | ||
| 573 | @Override | 577 | @Override |
| 574 | public void onInvalidate(boolean isInit) { | 578 | public void onInvalidate(boolean isInit) { |
| 575 | initData(); | 579 | initData(); |
| 576 | } | 580 | } |
| 577 | 581 | ||
| 578 | @Override | 582 | @Override |
| 579 | public void onViewStateRestored(@Nullable Bundle savedInstanceState) { | 583 | public void onViewStateRestored(@Nullable Bundle savedInstanceState) { |
| 580 | super.onViewStateRestored(savedInstanceState); | 584 | super.onViewStateRestored(savedInstanceState); |
| 581 | 585 | ||
| 582 | initData(); | 586 | initData(); |
| 583 | } | 587 | } |
| 584 | 588 | ||
| 585 | 589 | ||
| 586 | @Override | 590 | @Override |
| 587 | public void onResume() { | 591 | public void onResume() { |
| 588 | super.onResume(); | 592 | super.onResume(); |
| 589 | activityRunning = true; | 593 | activityRunning = true; |
| 594 | Debug.normal("Today: "+ "Onresume "); | ||
| 590 | Sensor countSensor = sensorManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER); | 595 | Sensor countSensor = sensorManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER); |
| 591 | if (countSensor != null) { | 596 | if (countSensor != null) { |
| 597 | Debug.normal("Today: "+ "countSensor not null "); | ||
| 592 | sensorManager.registerListener(this, countSensor, SensorManager.SENSOR_DELAY_UI); | 598 | sensorManager.registerListener(this, countSensor, SensorManager.SENSOR_DELAY_UI); |
| 593 | } else { | 599 | } else { |
| 600 | Debug.normal("Today: "+ "countSensor is null "); | ||
| 594 | Toast.makeText(mContext, getResources().getString(R.string.sensor_available), Toast.LENGTH_SHORT).show(); | 601 | Toast.makeText(mContext, getResources().getString(R.string.sensor_available), Toast.LENGTH_SHORT).show(); |
| 595 | } | 602 | } |
| 596 | } | 603 | } |
| 597 | 604 | ||
| 598 | @Override | 605 | @Override |
| 599 | public void onSensorChanged(SensorEvent event) { | 606 | public void onSensorChanged(SensorEvent event) { |
| 600 | Debug.normal("Sensor count step active"); | 607 | Debug.normal("Sensor count step active"); |
| 601 | if (activityRunning){ | 608 | if (activityRunning){ |
| 602 | stepCount = (int) event.values[0]; | 609 | stepCount = (int) event.values[0]; |
| 603 | Debug.normal("Step change: "+ stepCount); | 610 | Debug.normal("Step change: "+ stepCount); |
| 604 | stepTotal++; | 611 | stepTotal++; |
| 605 | // update UI | 612 | // update UI |
| 606 | updateUI(); | 613 | updateUI(); |
| 607 | } | 614 | } |
| 608 | } | 615 | } |
| 609 | 616 | ||
| 610 | @Override | 617 | @Override |
| 611 | public void onAccuracyChanged(Sensor sensor, int accuracy) { | 618 | public void onAccuracyChanged(Sensor sensor, int accuracy) { |
| 612 | 619 | ||
| 613 | } | 620 | } |
| 614 | 621 | ||
| 615 | @Override | 622 | @Override |
| 616 | public void onPause() { | 623 | public void onPause() { |
| 617 | super.onPause(); | 624 | super.onPause(); |
| 618 | activityRunning = false; | 625 | activityRunning = false; |
| 619 | Debug.normal("Start create log"); | 626 | Debug.normal("Start create log"); |
| 620 | mToDate = new Date(); | 627 | mToDate = new Date(); |
| 621 | if (sensorManager != null) { | 628 | if (sensorManager != null) { |
| 622 | sensorManager.unregisterListener(this); | 629 | sensorManager.unregisterListener(this); |
| 623 | } | 630 | } |
| 624 | // create log step | 631 | // create log step |
| 625 | creatLogStep(); | 632 | creatLogStep(); |
| 626 | } | 633 | } |
| 627 | 634 | ||
| 628 | @Override | 635 | @Override |
| 629 | public void onDestroy() { | 636 | public void onDestroy() { |
| 630 | super.onDestroy(); | 637 | super.onDestroy(); |
| 631 | } | 638 | } |
| 632 | 639 | ||
| 633 | private void creatLogStep(){ | 640 | private void creatLogStep(){ |
| 641 | Debug.normal("Today: "+ "Create log "+ stepCount); | ||
| 634 | 642 | ||
| 635 | LLAPIManager.createLog(stepType, stepCount, mFromDate, mToDate, new LLAPIManagerListener() { | 643 | ApiServices.createLog(stepType, stepCount, mFromDate, mToDate, new LLAPIManagerListener() { |
| 636 | @Override | 644 | @Override |
| 637 | public void onError(Error error) { | 645 | public void onError(Error error) { |
| 638 | Debug.error("Get data history error"); | 646 | Debug.error("Get data history error"); |
| 639 | } | 647 | } |
| 640 | 648 | ||
| 641 | @Override | 649 | @Override |
| 642 | public void onSuccess(String json) { | 650 | public void onSuccess(String json) { |
| 643 | Debug.error("Get data history success"); | 651 | Debug.error("Get data history success"); |
| 644 | } | 652 | } |
| 645 | 653 | ||
| 646 | @Override | 654 | @Override |
| 647 | public void onSuccess(JSONObject object) { | 655 | public void onSuccess(JSONObject object) { |
| 648 | Debug.error("Get data history success"); | 656 | Debug.error("Get data history success"); |
| 649 | } | 657 | } |
| 650 | }); | 658 | }); |
| 651 | } | 659 | } |
| 660 | |||
| 661 | |||
| 652 | 662 | ||
| 653 | } | 663 | } |
| 654 | 664 |
app/src/main/java/com/dinhcv/lifelogpedometer/activity/WelcomeActivity.java
| 1 | package com.dinhcv.lifelogpedometer.activity; | 1 | package com.dinhcv.lifelogpedometer.activity; |
| 2 | 2 | ||
| 3 | import android.app.ProgressDialog; | 3 | import android.app.ProgressDialog; |
| 4 | import android.content.DialogInterface; | 4 | import android.content.DialogInterface; |
| 5 | import android.content.Intent; | 5 | import android.content.Intent; |
| 6 | import android.net.Uri; | 6 | import android.net.Uri; |
| 7 | import android.os.Bundle; | 7 | import android.os.Bundle; |
| 8 | import android.os.Handler; | 8 | import android.os.Handler; |
| 9 | import android.support.v7.app.AlertDialog; | 9 | import android.support.v7.app.AlertDialog; |
| 10 | 10 | ||
| 11 | import com.dinhcv.lifelogpedometer.R; | 11 | import com.dinhcv.lifelogpedometer.R; |
| 12 | import com.dinhcv.lifelogpedometer.interfaces.LLAPIManagerListener; | 12 | import com.dinhcv.lifelogpedometer.interfaces.LLAPIManagerListener; |
| 13 | import com.dinhcv.lifelogpedometer.model.Shareprefer.Setting; | 13 | import com.dinhcv.lifelogpedometer.model.Shareprefer.Setting; |
| 14 | import com.dinhcv.lifelogpedometer.portal.ApiServices; | ||
| 14 | import com.dinhcv.lifelogpedometer.portal.LLAPIManager; | 15 | import com.dinhcv.lifelogpedometer.portal.LLAPIManager; |
| 15 | import com.dinhcv.lifelogpedometer.utils.Debug; | 16 | import com.dinhcv.lifelogpedometer.utils.Debug; |
| 16 | 17 | ||
| 17 | import org.json.JSONArray; | 18 | import org.json.JSONArray; |
| 18 | import org.json.JSONObject; | 19 | import org.json.JSONObject; |
| 19 | 20 | ||
| 20 | 21 | ||
| 21 | public class WelcomeActivity extends ActivityBase implements Runnable { | 22 | public class WelcomeActivity extends ActivityBase implements Runnable { |
| 22 | private boolean isRefresh = false; | 23 | private boolean isRefresh = false; |
| 23 | @Override | 24 | @Override |
| 24 | protected void onCreate(Bundle savedInstanceState) { | 25 | protected void onCreate(Bundle savedInstanceState) { |
| 25 | super.onCreate(savedInstanceState); | 26 | super.onCreate(savedInstanceState); |
| 26 | setContentView(R.layout.activity_welcome); | 27 | setContentView(R.layout.activity_welcome); |
| 27 | checkRefreshToken(); | 28 | checkRefreshToken(); |
| 28 | } | 29 | } |
| 29 | 30 | ||
| 30 | private void checkRefreshToken(){ | 31 | private void checkRefreshToken(){ |
| 31 | int id = Setting.getUserIdSharepre(WelcomeActivity.this); | 32 | int id = Setting.getUserIdSharepre(WelcomeActivity.this); |
| 32 | Debug.normal("String id: "+ id); | 33 | Debug.normal("String id: "+ id); |
| 33 | if (id != 0){ | 34 | if (id != 0){ |
| 34 | handleRefreshToken(id); | 35 | handleRefreshToken(id); |
| 35 | }else { | 36 | }else { |
| 36 | refeshDone(); | 37 | refeshDone(); |
| 37 | } | 38 | } |
| 38 | } | 39 | } |
| 39 | 40 | ||
| 40 | 41 | ||
| 41 | private void handleRefreshToken(int id) { | 42 | private void handleRefreshToken(int id) { |
| 42 | 43 | ||
| 43 | LLAPIManager.refreshToken(WelcomeActivity.this, id, new LLAPIManagerListener() { | 44 | ApiServices.refreshToken(WelcomeActivity.this, id, new LLAPIManagerListener() { |
| 44 | @Override | 45 | @Override |
| 45 | public void onError(Error error) { | 46 | public void onError(Error error) { |
| 46 | Debug.error("Version JSON result: ERROR " + error); | 47 | Debug.error("Version JSON result: ERROR " + error); |
| 47 | String err = getResources().getString(R.string.login_error); | 48 | String err = getResources().getString(R.string.login_error); |
| 48 | isRefresh = false; | 49 | isRefresh = false; |
| 49 | refeshDone(); | 50 | refeshDone(); |
| 50 | } | 51 | } |
| 51 | 52 | ||
| 52 | @Override | 53 | @Override |
| 53 | public void onSuccess(String json) { | 54 | public void onSuccess(String json) { |
| 54 | Debug.warn("Version JSON result: " + json.toString()); | 55 | Debug.warn("Version JSON result: " + json.toString()); |
| 55 | isRefresh = true; | 56 | isRefresh = true; |
| 56 | refeshDone(); | 57 | refeshDone(); |
| 57 | } | 58 | } |
| 58 | 59 | ||
| 59 | @Override | 60 | @Override |
| 60 | public void onSuccess(JSONObject object) { | 61 | public void onSuccess(JSONObject object) { |
| 61 | Debug.warn("Version JSON object result: Success"); | 62 | Debug.warn("Version JSON object result: Success"); |
| 62 | isRefresh = true; | 63 | isRefresh = true; |
| 63 | refeshDone(); | 64 | refeshDone(); |
| 64 | } | 65 | } |
| 65 | }); | 66 | }); |
| 66 | } | 67 | } |
| 67 | 68 | ||
| 68 | private void refeshDone(){ | 69 | private void refeshDone(){ |
| 69 | Handler handler = new Handler(); | 70 | Handler handler = new Handler(); |
| 70 | handler.postDelayed(WelcomeActivity.this, 2000); | 71 | handler.postDelayed(WelcomeActivity.this, 2000); |
| 71 | } | 72 | } |
| 72 | 73 | ||
| 73 | private void notifyErr(String err){ | 74 | private void notifyErr(String err){ |
| 74 | AlertDialog.Builder alertDialog = new AlertDialog.Builder(WelcomeActivity.this); | 75 | AlertDialog.Builder alertDialog = new AlertDialog.Builder(WelcomeActivity.this); |
| 75 | alertDialog.setMessage(err); | 76 | alertDialog.setMessage(err); |
| 76 | alertDialog.setCancelable(false); | 77 | alertDialog.setCancelable(false); |
| 77 | alertDialog.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { | 78 | alertDialog.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { |
| 78 | @Override | 79 | @Override |
| 79 | public void onClick(DialogInterface dialog, int which) { | 80 | public void onClick(DialogInterface dialog, int which) { |
| 80 | finish(); | 81 | finish(); |
| 81 | } | 82 | } |
| 82 | }); | 83 | }); |
| 83 | AlertDialog alert = alertDialog.create(); | 84 | AlertDialog alert = alertDialog.create(); |
| 84 | alert.show(); | 85 | alert.show(); |
| 85 | } | 86 | } |
| 86 | 87 | ||
| 87 | @Override | 88 | @Override |
| 88 | public void run() { | 89 | public void run() { |
| 89 | // go to main screen | 90 | // go to main screen |
| 90 | if ( isRefresh) { | 91 | if ( isRefresh) { |
| 91 | gotoActivity(PedometerActivity.class); | 92 | gotoActivity(PedometerActivity.class); |
| 92 | } else { | 93 | } else { |
| 93 | // Bundle bundle = new Bundle(); | 94 | // Bundle bundle = new Bundle(); |
| 94 | // bundle.putString(Const.URL, url); | 95 | // bundle.putString(Const.URL, url); |
| 95 | gotoActivity(LoginActivity.class); | 96 | gotoActivity(LoginActivity.class); |
| 96 | } | 97 | } |
| 97 | finish(); | 98 | finish(); |
| 98 | } | 99 | } |
| 99 | 100 | ||
| 100 | @Override | 101 | @Override |
| 101 | protected void onResume() { | 102 | protected void onResume() { |
| 102 | super.onResume(); | 103 | super.onResume(); |
| 103 | } | 104 | } |
| 104 | } | 105 | } |
| 105 | 106 |
app/src/main/java/com/dinhcv/lifelogpedometer/model/structure/home/NoticeInfo.java
| 1 | package com.dinhcv.lifelogpedometer.model.structure.home; | 1 | package com.dinhcv.lifelogpedometer.model.structure.home; |
| 2 | 2 | ||
| 3 | public class NoticeInfo { | 3 | public class NoticeInfo { |
| 4 | private int id; | 4 | private int id; |
| 5 | private String content; | 5 | private String content; |
| 6 | 6 | ||
| 7 | public NoticeInfo(){ | ||
| 8 | |||
| 9 | } | ||
| 10 | |||
| 11 | public NoticeInfo(int id, String content){ | ||
| 12 | this.id = id; | ||
| 13 | this.content = content; | ||
| 14 | } | ||
| 15 | |||
| 7 | public int getId() { | 16 | public int getId() { |
| 8 | return id; | 17 | return id; |
| 9 | } | 18 | } |
| 10 | 19 | ||
| 11 | public void setId(int id) { | 20 | public void setId(int id) { |
| 12 | this.id = id; | 21 | this.id = id; |
| 13 | } | 22 | } |
| 14 | 23 | ||
| 15 | public String getContent() { | 24 | public String getContent() { |
| 16 | return content; | 25 | return content; |
| 17 | } | 26 | } |
| 18 | 27 | ||
| 19 | public void setContent(String content) { | 28 | public void setContent(String content) { |
| 20 | this.content = content; | 29 | this.content = content; |
| 21 | } | 30 | } |
| 22 | 31 | ||
| 23 | } | 32 | } |
| 24 | 33 |
app/src/main/java/com/dinhcv/lifelogpedometer/portal/ApiServices.java
| File was created | 1 | package com.dinhcv.lifelogpedometer.portal; | |
| 2 | |||
| 3 | import android.content.Context; | ||
| 4 | import android.graphics.Bitmap; | ||
| 5 | |||
| 6 | import com.dinhcv.lifelogpedometer.interfaces.LLAPIManagerListener; | ||
| 7 | import com.dinhcv.lifelogpedometer.model.structure.RegisterInfo; | ||
| 8 | import com.dinhcv.lifelogpedometer.utils.Const; | ||
| 9 | |||
| 10 | import java.util.Date; | ||
| 11 | |||
| 12 | /** | ||
| 13 | * Created by Administrator on 16/11/2017. | ||
| 14 | */ | ||
| 15 | |||
| 16 | public class ApiServices { | ||
| 17 | |||
| 18 | public static void topInfo(final Date date, final Const.STEP_TYPE stepType, final LLAPIManagerListener action){ | ||
| 19 | new LLAPIManager.TopInfo(date, stepType, action).execute(); | ||
| 20 | } | ||
| 21 | |||
| 22 | public static void homePage(final Date date, final Const.STEP_TYPE stepType, final LLAPIManagerListener action) { | ||
| 23 | new LLAPIManager.HomePage(date, stepType, action).execute(); | ||
| 24 | } | ||
| 25 | |||
| 26 | |||
| 27 | public static void historyDetail(final Date fromDate, final Date toDate, final LLAPIManagerListener action) { | ||
| 28 | new LLAPIManager.HistoryDetail(fromDate, toDate, action).execute(); | ||
| 29 | } | ||
| 30 | |||
| 31 | |||
| 32 | public static void history(final Date fromDate, final Date toDate, final LLAPIManagerListener action) { | ||
| 33 | new LLAPIManager.History(fromDate, toDate, action).execute(); | ||
| 34 | } | ||
| 35 | |||
| 36 | |||
| 37 | public static void forgetPassConfirm(final String email, final String codeConfirm, final LLAPIManagerListener action) { | ||
| 38 | new LLAPIManager.ForgetPassConfirm(email, codeConfirm, action).execute(); | ||
| 39 | } | ||
| 40 | |||
| 41 | |||
| 42 | public static void forgetPass(final String email, final LLAPIManagerListener action) { | ||
| 43 | new LLAPIManager.ForgetPass(email, action).execute(); | ||
| 44 | } | ||
| 45 | |||
| 46 | |||
| 47 | public static void register(final RegisterInfo registerInfo, final LLAPIManagerListener action) { | ||
| 48 | new LLAPIManager.Register(registerInfo, action).execute(); | ||
| 49 | } | ||
| 50 | |||
| 51 | |||
| 52 | public static void uploadImage(final Bitmap bitmap, final LLAPIManagerListener action) { | ||
| 53 | new LLAPIManager.UploadImage(bitmap, action).execute(); | ||
| 54 | } | ||
| 55 | |||
| 56 | |||
| 57 | public static void login(final Context context, final String email, final String pass, final LLAPIManagerListener action) { | ||
| 58 | new LLAPIManager.Login(context, email, pass, action).execute(); | ||
| 59 | } | ||
| 60 | |||
| 61 | public static void createLog(final Const.STEP_TYPE stepType, final int stepCount, final Date startTime, | ||
| 62 | final Date endTime, final LLAPIManagerListener action) { | ||
| 63 | new LLAPIManager.CreateLog(stepType, stepCount, startTime, endTime, action).execute(); | ||
| 64 | } | ||
| 65 | |||
| 66 | |||
| 67 | public static void refreshToken(final Context context, final int userId, final LLAPIManagerListener action) { | ||
| 68 | new LLAPIManager.RefreshToken(context, userId, action).execute(); | ||
| 69 | } | ||
| 70 | |||
| 71 | public static void getNews(final Date date, final LLAPIManagerListener action) { | ||
| 72 | new LLAPIManager.GetNews(date, action).execute(); | ||
| 73 | } | ||
| 74 | |||
| 75 | |||
| 76 | } | ||
| 77 |
app/src/main/java/com/dinhcv/lifelogpedometer/portal/LLAPIManager.java
| 1 | package com.dinhcv.lifelogpedometer.portal; | 1 | package com.dinhcv.lifelogpedometer.portal; |
| 2 | 2 | ||
| 3 | import android.content.Context; | 3 | import android.content.Context; |
| 4 | import android.content.res.AssetManager; | 4 | import android.content.res.AssetManager; |
| 5 | import android.graphics.Bitmap; | 5 | import android.graphics.Bitmap; |
| 6 | import android.graphics.BitmapFactory; | 6 | import android.graphics.BitmapFactory; |
| 7 | import android.os.AsyncTask; | 7 | import android.os.AsyncTask; |
| 8 | import android.provider.Settings; | 8 | import android.provider.Settings; |
| 9 | import android.support.annotation.NonNull; | 9 | import android.support.annotation.NonNull; |
| 10 | import android.util.Base64; | 10 | import android.util.Base64; |
| 11 | 11 | ||
| 12 | import com.dinhcv.lifelogpedometer.interfaces.LLAPIManagerListener; | 12 | import com.dinhcv.lifelogpedometer.interfaces.LLAPIManagerListener; |
| 13 | import com.dinhcv.lifelogpedometer.model.Shareprefer.Setting; | 13 | import com.dinhcv.lifelogpedometer.model.Shareprefer.Setting; |
| 14 | import com.dinhcv.lifelogpedometer.model.structure.RegisterInfo; | 14 | import com.dinhcv.lifelogpedometer.model.structure.RegisterInfo; |
| 15 | import com.dinhcv.lifelogpedometer.utils.Const; | 15 | import com.dinhcv.lifelogpedometer.utils.Const; |
| 16 | import com.dinhcv.lifelogpedometer.utils.Debug; | 16 | import com.dinhcv.lifelogpedometer.utils.Debug; |
| 17 | import com.dinhcv.lifelogpedometer.utils.Utils; | 17 | import com.dinhcv.lifelogpedometer.utils.Utils; |
| 18 | 18 | ||
| 19 | import org.json.JSONArray; | 19 | import org.json.JSONArray; |
| 20 | import org.json.JSONException; | 20 | import org.json.JSONException; |
| 21 | import org.json.JSONObject; | 21 | import org.json.JSONObject; |
| 22 | 22 | ||
| 23 | import java.io.ByteArrayOutputStream; | 23 | import java.io.ByteArrayOutputStream; |
| 24 | import java.io.IOException; | 24 | import java.io.IOException; |
| 25 | import java.io.InputStream; | 25 | import java.io.InputStream; |
| 26 | import java.util.ArrayList; | ||
| 27 | import java.util.Arrays; | ||
| 28 | import java.util.Date; | 26 | import java.util.Date; |
| 29 | import java.util.HashMap; | ||
| 30 | import java.util.List; | ||
| 31 | import java.util.UUID; | ||
| 32 | import java.util.concurrent.TimeUnit; | 27 | import java.util.concurrent.TimeUnit; |
| 33 | 28 | ||
| 34 | import okhttp3.Call; | ||
| 35 | import okhttp3.Callback; | ||
| 36 | import okhttp3.HttpUrl; | 29 | import okhttp3.HttpUrl; |
| 37 | import okhttp3.MediaType; | 30 | import okhttp3.MediaType; |
| 38 | import okhttp3.OkHttpClient; | 31 | import okhttp3.OkHttpClient; |
| 39 | import okhttp3.Request; | 32 | import okhttp3.Request; |
| 40 | import okhttp3.RequestBody; | 33 | import okhttp3.RequestBody; |
| 41 | import okhttp3.Response; | 34 | import okhttp3.Response; |
| 42 | import okhttp3.ResponseBody; | 35 | import okhttp3.ResponseBody; |
| 43 | 36 | ||
| 44 | public class LLAPIManager { | 37 | public class LLAPIManager { |
| 45 | public static String URL_ROOT = "http://clover.timesfun.jp:9001/"; | 38 | private static String URL_ROOT = "http://clover.timesfun.jp:9001/"; |
| 46 | //login info | 39 | //login info |
| 47 | public static String URL_LOGIN_INFO = "login"; | 40 | private static String URL_LOGIN_INFO = "login"; |
| 48 | //register info | 41 | //register info |
| 49 | public static String URL_REGISTER_INFO = "register"; | 42 | private static String URL_REGISTER_INFO = "register"; |
| 50 | //upload image info | 43 | //upload image info |
| 51 | public static String URL_UPLOAD_IMAGE_INFO = "upload-image"; | 44 | private static String URL_UPLOAD_IMAGE_INFO = "upload-image"; |
| 52 | //Search zipcode | 45 | //Search zipcode |
| 53 | public static String URL_FORGET_PASS_INFO = "forgetPass"; | 46 | private static String URL_FORGET_PASS_INFO = "forgetPass"; |
| 54 | //history | 47 | //history |
| 55 | public static String URL_HISTORE_INFO = "api/history"; | 48 | private static String URL_HISTORE_INFO = "api/history"; |
| 56 | //history detail | 49 | //history detail |
| 57 | public static String URL_HISTORE_DETAIL_INFO = "api/history/detail"; | 50 | private static String URL_HISTORE_DETAIL_INFO = "api/history/detail"; |
| 58 | // home | 51 | // home |
| 59 | public static String URL_HOME_INFO = "api/home"; | 52 | private static String URL_HOME_INFO = "api/home"; |
| 60 | //Search zipcode | 53 | //Search zipcode |
| 61 | public static String URL_FORGET_PASS_CONFIRM_INFO = "forgetPass/confirm"; | 54 | private static String URL_FORGET_PASS_CONFIRM_INFO = "forgetPass/confirm"; |
| 62 | // Refesh Token | 55 | // Refesh Token |
| 63 | public static String URL_REFESH_TOKEN_INFO = "refreshToken"; | 56 | private static String URL_REFESH_TOKEN_INFO = "refreshToken"; |
| 64 | // Top info | 57 | // Top info |
| 65 | public static String URL_TOP_INFO = "api/top"; | 58 | private static String URL_TOP_INFO = "api/top"; |
| 66 | // Refesh Token | 59 | // Refesh Token |
| 67 | public static String URL_CREATE_LOG_INFO = "api/createLog"; | 60 | private static String URL_CREATE_LOG_INFO = "api/createLog"; |
| 61 | // Get news | ||
| 62 | private static String URL_GET_NEWS_INFO = "api/getnoticesbydate"; | ||
| 68 | 63 | ||
| 69 | 64 | ||
| 70 | |||
| 71 | private static int deviationValue = 1; | 65 | private static int deviationValue = 1; |
| 72 | 66 | ||
| 73 | public static void login(final Context context, final String email, final String pass, final LLAPIManagerListener action) { | 67 | public static class Login extends AsyncTask<Void, Void, String>{ |
| 74 | new AsyncTask<Void, Void, String>() { | 68 | private Context context; |
| 69 | private String email; | ||
| 70 | private String pass; | ||
| 71 | private LLAPIManagerListener action; | ||
| 72 | |||
| 73 | public Login(Context context, String email, String pass, LLAPIManagerListener action) { | ||
| 74 | this.context = context; | ||
| 75 | this.email = email; | ||
| 76 | this.pass = pass; | ||
| 77 | this.action = action; | ||
| 78 | } | ||
| 79 | |||
| 75 | @Override | 80 | @Override |
| 76 | protected void onPreExecute() { | 81 | protected void onPreExecute() { |
| 77 | super.onPreExecute(); | 82 | super.onPreExecute(); |
| 78 | } | 83 | } |
| 79 | 84 | ||
| 80 | @Override | 85 | @Override |
| 81 | protected String doInBackground(Void... voids) { | 86 | protected String doInBackground(Void... voids) { |
| 82 | HttpUrl baseUrl = HttpUrl.parse(URL_ROOT + URL_LOGIN_INFO); | 87 | HttpUrl baseUrl = HttpUrl.parse(URL_ROOT + URL_LOGIN_INFO); |
| 83 | JSONObject jsonObject = new JSONObject(); | 88 | JSONObject jsonObject = new JSONObject(); |
| 84 | 89 | ||
| 85 | try { | 90 | try { |
| 86 | jsonObject.put("email", email); | 91 | jsonObject.put("email", email); |
| 87 | jsonObject.put("password", pass); | 92 | jsonObject.put("password", pass); |
| 88 | 93 | ||
| 89 | Debug.warn("Json data: " + jsonObject.toString()); | 94 | Debug.warn("Json data: " + jsonObject.toString()); |
| 90 | } catch (JSONException e) { | 95 | } catch (JSONException e) { |
| 91 | Debug.normal("Error ", e.getMessage()); | 96 | Debug.normal("Error ", e.getMessage()); |
| 92 | } | 97 | } |
| 93 | 98 | ||
| 94 | MediaType JSON | 99 | MediaType JSON |
| 95 | = MediaType.parse("application/json"); | 100 | = MediaType.parse("application/json"); |
| 96 | Debug.normal("JSON STRING: %s", jsonObject.toString()); | 101 | Debug.normal("JSON STRING: %s", jsonObject.toString()); |
| 97 | RequestBody requestBody = RequestBody.create(JSON, jsonObject.toString()); | 102 | RequestBody requestBody = RequestBody.create(JSON, jsonObject.toString()); |
| 98 | 103 | ||
| 99 | final Request.Builder request = new Request.Builder() | 104 | final Request.Builder request = new Request.Builder() |
| 100 | .url(baseUrl) | 105 | .url(baseUrl) |
| 101 | .header("User-Agent", Utils.getCustomUA()) | 106 | .header("User-Agent", Utils.getCustomUA()) |
| 102 | .header("Content-Type", "application/json") | 107 | .header("Content-Type", "application/json") |
| 103 | .post(requestBody); | 108 | .post(requestBody); |
| 104 | 109 | ||
| 105 | OkHttpClient httpClient = new OkHttpClient.Builder() | 110 | OkHttpClient httpClient = new OkHttpClient.Builder() |
| 106 | .readTimeout(30, TimeUnit.SECONDS) | 111 | .readTimeout(30, TimeUnit.SECONDS) |
| 107 | .writeTimeout(30, TimeUnit.SECONDS) | 112 | .writeTimeout(30, TimeUnit.SECONDS) |
| 108 | .connectTimeout(30, TimeUnit.SECONDS) | 113 | .connectTimeout(30, TimeUnit.SECONDS) |
| 109 | .build(); | 114 | .build(); |
| 110 | 115 | ||
| 111 | String jsonString = null; | 116 | String jsonString = null; |
| 112 | try { | 117 | try { |
| 113 | Response response = httpClient.newCall(request.build()).execute(); | 118 | Response response = httpClient.newCall(request.build()).execute(); |
| 114 | if (response == null) { | 119 | if (response == null) { |
| 115 | action.onError(null); | 120 | action.onError(null); |
| 116 | Debug.error("Response is null"); | 121 | Debug.error("Response is null"); |
| 117 | return null; | 122 | return null; |
| 118 | } | 123 | } |
| 119 | jsonString = getResponseData(response.body()); | 124 | jsonString = getResponseData(response.body()); |
| 120 | 125 | ||
| 121 | } catch (IOException e) { | 126 | } catch (IOException e) { |
| 122 | Debug.normal("Error %s", e.getMessage()); | 127 | Debug.normal("Error %s", e.getMessage()); |
| 123 | } | 128 | } |
| 124 | return jsonString; | 129 | return jsonString; |
| 125 | } | 130 | } |
| 126 | 131 | ||
| 127 | @Override | 132 | @Override |
| 128 | protected void onCancelled() { | 133 | protected void onCancelled() { |
| 129 | super.onCancelled(); | 134 | super.onCancelled(); |
| 130 | action.onError(null); | 135 | action.onError(null); |
| 131 | } | 136 | } |
| 132 | 137 | ||
| 133 | @Override | 138 | @Override |
| 134 | protected void onPostExecute(String jsonString) { | 139 | protected void onPostExecute(String jsonString) { |
| 135 | super.onPostExecute(jsonString); | 140 | super.onPostExecute(jsonString); |
| 136 | 141 | ||
| 137 | if ((jsonString == null) || (jsonString.isEmpty())) { | 142 | if ((jsonString == null) || (jsonString.isEmpty())) { |
| 138 | action.onError(null); | 143 | action.onError(null); |
| 139 | return; | 144 | return; |
| 140 | } | 145 | } |
| 141 | Debug.normal("String body: "+jsonString); | 146 | Debug.normal("String body: "+jsonString); |
| 142 | 147 | ||
| 143 | try { | 148 | try { |
| 144 | JSONObject jsonObject = new JSONObject(jsonString); | 149 | JSONObject jsonObject = new JSONObject(jsonString); |
| 145 | int status = jsonObject.optInt("status"); | 150 | int status = jsonObject.optInt("status"); |
| 146 | if (status == 1){ | 151 | if (status == 1){ |
| 147 | JSONObject object = jsonObject.optJSONObject("result"); | 152 | JSONObject object = jsonObject.optJSONObject("result"); |
| 148 | JSONObject objUser = object.getJSONObject("user"); | 153 | JSONObject objUser = object.getJSONObject("user"); |
| 149 | String token = object.optString("token"); | 154 | String token = object.optString("token"); |
| 150 | // save data | 155 | // save data |
| 151 | Setting.setUserDataSharepre(context, Setting.TOKEN_SHAREPRE, token); | 156 | Setting.setUserDataSharepre(context, Setting.TOKEN_SHAREPRE, token); |
| 152 | APIResponse.getInstance().setToken(token); | 157 | APIResponse.getInstance().setToken(token); |
| 153 | Debug.normal("Token: "+ token); | 158 | Debug.normal("Token: "+ token); |
| 154 | action.onSuccess(objUser); | 159 | action.onSuccess(objUser); |
| 155 | }else { | 160 | }else { |
| 156 | action.onError(new Error(jsonObject.optString("message"))); | 161 | action.onError(new Error(jsonObject.optString("message"))); |
| 157 | } | 162 | } |
| 158 | } catch (JSONException e) { | 163 | } catch (JSONException e) { |
| 159 | e.printStackTrace(); | 164 | e.printStackTrace(); |
| 160 | } | 165 | } |
| 161 | } | 166 | } |
| 162 | }.execute(); | ||
| 163 | } | 167 | } |
| 164 | 168 | ||
| 165 | public static void uploadImage(final Bitmap bitmap, final LLAPIManagerListener action) { | 169 | public static class UploadImage extends AsyncTask<Void, Void, String>{ |
| 166 | new AsyncTask<Void, Void, String>() { | 170 | private Bitmap bitmap; |
| 171 | private LLAPIManagerListener action; | ||
| 172 | |||
| 173 | public UploadImage(Bitmap bitmap, LLAPIManagerListener action) { | ||
| 174 | this.bitmap = bitmap; | ||
| 175 | this.action = action; | ||
| 176 | } | ||
| 177 | |||
| 167 | @Override | 178 | @Override |
| 168 | protected void onPreExecute() { | 179 | protected void onPreExecute() { |
| 169 | super.onPreExecute(); | 180 | super.onPreExecute(); |
| 170 | } | 181 | } |
| 171 | 182 | ||
| 172 | @Override | 183 | @Override |
| 173 | protected String doInBackground(Void... voids) { | 184 | protected String doInBackground(Void... voids) { |
| 174 | HttpUrl baseUrl = HttpUrl.parse(URL_ROOT + URL_UPLOAD_IMAGE_INFO); | 185 | HttpUrl baseUrl = HttpUrl.parse(URL_ROOT + URL_UPLOAD_IMAGE_INFO); |
| 175 | JSONObject jsonObject = new JSONObject(); | 186 | JSONObject jsonObject = new JSONObject(); |
| 176 | byte[] bitmapByte = convertBitmapToByteArray(bitmap); | 187 | byte[] bitmapByte = convertBitmapToByteArray(bitmap); |
| 177 | String imageBase64 = Base64.encodeToString(bitmapByte, Base64.DEFAULT); | 188 | String imageBase64 = Base64.encodeToString(bitmapByte, Base64.DEFAULT); |
| 178 | String imageStr = imageBase64.replace("\n",""); | 189 | String imageStr = imageBase64.replace("\n",""); |
| 179 | 190 | ||
| 180 | String token = APIResponse.getInstance().getToken(); | 191 | String token = APIResponse.getInstance().getToken(); |
| 181 | try { | 192 | try { |
| 182 | if (token != null && !token.isEmpty()) { | 193 | if (token != null && !token.isEmpty()) { |
| 183 | Debug.normal("Token is not null"); | 194 | Debug.normal("Token is not null"); |
| 184 | jsonObject.put("token", token); | 195 | jsonObject.put("token", token); |
| 185 | } | 196 | } |
| 186 | jsonObject.put("img", imageStr); | 197 | jsonObject.put("img", imageStr); |
| 187 | 198 | ||
| 188 | Debug.warn("Json data: " + jsonObject.toString()); | 199 | Debug.warn("Json data: " + jsonObject.toString()); |
| 189 | } catch (JSONException e) { | 200 | } catch (JSONException e) { |
| 190 | Debug.normal("Error ", e.getMessage()); | 201 | Debug.normal("Error ", e.getMessage()); |
| 191 | } | 202 | } |
| 192 | 203 | ||
| 193 | MediaType JSON | 204 | MediaType JSON |
| 194 | = MediaType.parse("application/json; charset=utf-8"); | 205 | = MediaType.parse("application/json; charset=utf-8"); |
| 195 | RequestBody requestBody = RequestBody.create(JSON, jsonObject.toString()); | 206 | RequestBody requestBody = RequestBody.create(JSON, jsonObject.toString()); |
| 196 | 207 | ||
| 197 | final Request.Builder request = new Request.Builder() | 208 | final Request.Builder request = new Request.Builder() |
| 198 | .url(baseUrl) | 209 | .url(baseUrl) |
| 199 | .header("User-Agent", Utils.getCustomUA()) | 210 | .header("User-Agent", Utils.getCustomUA()) |
| 200 | .header("Content-Type", "application/json") | 211 | .header("Content-Type", "application/json") |
| 201 | .post(requestBody); | 212 | .post(requestBody); |
| 202 | 213 | ||
| 203 | OkHttpClient httpClient = new OkHttpClient.Builder() | 214 | OkHttpClient httpClient = new OkHttpClient.Builder() |
| 204 | .readTimeout(30, TimeUnit.SECONDS) | 215 | .readTimeout(30, TimeUnit.SECONDS) |
| 205 | .writeTimeout(30, TimeUnit.SECONDS) | 216 | .writeTimeout(30, TimeUnit.SECONDS) |
| 206 | .connectTimeout(30, TimeUnit.SECONDS) | 217 | .connectTimeout(30, TimeUnit.SECONDS) |
| 207 | .build(); | 218 | .build(); |
| 208 | String jsonString = null; | 219 | String jsonString = null; |
| 209 | try { | 220 | try { |
| 210 | Response response = httpClient.newCall(request.build()).execute(); | 221 | Response response = httpClient.newCall(request.build()).execute(); |
| 211 | if (response == null) { | 222 | if (response == null) { |
| 212 | action.onError(null); | 223 | action.onError(null); |
| 213 | Debug.error("Response is null"); | 224 | Debug.error("Response is null"); |
| 214 | return null; | 225 | return null; |
| 215 | } | 226 | } |
| 216 | jsonString = getResponseData(response.body()); | 227 | jsonString = getResponseData(response.body()); |
| 217 | 228 | ||
| 218 | } catch (IOException e) { | 229 | } catch (IOException e) { |
| 219 | Debug.normal("Error %s", e.getMessage()); | 230 | Debug.normal("Error %s", e.getMessage()); |
| 220 | } | 231 | } |
| 221 | 232 | ||
| 222 | return jsonString; | 233 | return jsonString; |
| 223 | } | 234 | } |
| 224 | 235 | ||
| 225 | @Override | 236 | @Override |
| 226 | protected void onCancelled() { | 237 | protected void onCancelled() { |
| 227 | super.onCancelled(); | 238 | super.onCancelled(); |
| 228 | action.onError(null); | 239 | action.onError(null); |
| 229 | } | 240 | } |
| 230 | 241 | ||
| 231 | @Override | 242 | @Override |
| 232 | protected void onPostExecute(String jsonString) { | 243 | protected void onPostExecute(String jsonString) { |
| 233 | super.onPostExecute(jsonString); | 244 | super.onPostExecute(jsonString); |
| 234 | if ((jsonString == null) || (jsonString.isEmpty())) { | 245 | if ((jsonString == null) || (jsonString.isEmpty())) { |
| 235 | action.onError(null); | 246 | action.onError(null); |
| 236 | return; | 247 | return; |
| 237 | } | 248 | } |
| 238 | Debug.normal("String body: "+jsonString); | 249 | Debug.normal("String body: "+jsonString); |
| 239 | 250 | ||
| 240 | try { | 251 | try { |
| 241 | JSONObject jsonObject = new JSONObject(jsonString); | 252 | JSONObject jsonObject = new JSONObject(jsonString); |
| 242 | int status = jsonObject.optInt("status"); | 253 | int status = jsonObject.optInt("status"); |
| 243 | if (status == 1){ | 254 | if (status == 1){ |
| 244 | action.onSuccess(new JSONObject()); | 255 | action.onSuccess(new JSONObject()); |
| 245 | }else { | 256 | }else { |
| 246 | action.onError(new Error(jsonObject.optString("message"))); | 257 | action.onError(new Error(jsonObject.optString("message"))); |
| 247 | } | 258 | } |
| 248 | } catch (JSONException e) { | 259 | } catch (JSONException e) { |
| 249 | e.printStackTrace(); | 260 | e.printStackTrace(); |
| 250 | } | 261 | } |
| 251 | } | 262 | } |
| 252 | }.execute(); | ||
| 253 | } | 263 | } |
| 254 | 264 | ||
| 255 | public static void register(final RegisterInfo registerInfo, final LLAPIManagerListener action) { | 265 | public static class Register extends AsyncTask<Void, Void, String>{ |
| 256 | new AsyncTask<Void, Void, String>() { | 266 | private RegisterInfo registerInfo; |
| 267 | private LLAPIManagerListener action; | ||
| 268 | |||
| 269 | public Register(RegisterInfo registerInfo, LLAPIManagerListener action) { | ||
| 270 | this.registerInfo = registerInfo; | ||
| 271 | this.action = action; | ||
| 272 | } | ||
| 273 | |||
| 257 | @Override | 274 | @Override |
| 258 | protected void onPreExecute() { | 275 | protected void onPreExecute() { |
| 259 | super.onPreExecute(); | 276 | super.onPreExecute(); |
| 260 | } | 277 | } |
| 261 | 278 | ||
| 262 | @Override | 279 | @Override |
| 263 | protected String doInBackground(Void... voids) { | 280 | protected String doInBackground(Void... voids) { |
| 264 | HttpUrl baseUrl = HttpUrl.parse(URL_ROOT + URL_REGISTER_INFO); | 281 | HttpUrl baseUrl = HttpUrl.parse(URL_ROOT + URL_REGISTER_INFO); |
| 265 | JSONObject jsonObject = new JSONObject(); | 282 | JSONObject jsonObject = new JSONObject(); |
| 266 | 283 | ||
| 267 | String token = APIResponse.getInstance().getToken(); | 284 | String token = APIResponse.getInstance().getToken(); |
| 268 | try { | 285 | try { |
| 269 | jsonObject.put("username", registerInfo.getUsername()); | 286 | jsonObject.put("username", registerInfo.getUsername()); |
| 270 | jsonObject.put("password", registerInfo.getPassword()); | 287 | jsonObject.put("password", registerInfo.getPassword()); |
| 271 | jsonObject.put("full_name", registerInfo.getFullName()); | 288 | jsonObject.put("full_name", registerInfo.getFullName()); |
| 272 | jsonObject.put("nickname", registerInfo.getNickname()); | 289 | jsonObject.put("nickname", registerInfo.getNickname()); |
| 273 | jsonObject.put("birthday", Utils.dateToStringFormatDayMonthYear(registerInfo.getBirthday())); | 290 | jsonObject.put("birthday", Utils.dateToStringFormatDayMonthYear(registerInfo.getBirthday())); |
| 274 | jsonObject.put("height", ""+registerInfo.getHeight()); | 291 | jsonObject.put("height", ""+registerInfo.getHeight()); |
| 275 | jsonObject.put("weight", ""+registerInfo.getWeight()); | 292 | jsonObject.put("weight", ""+registerInfo.getWeight()); |
| 276 | jsonObject.put("fat_rate", ""+registerInfo.getFatRate()); | 293 | jsonObject.put("fat_rate", ""+registerInfo.getFatRate()); |
| 277 | jsonObject.put("gender", ""+registerInfo.getGender()); | 294 | jsonObject.put("gender", ""+registerInfo.getGender()); |
| 278 | jsonObject.put("address", registerInfo.getAddress()); | 295 | jsonObject.put("address", registerInfo.getAddress()); |
| 279 | jsonObject.put("desciption", ""); | 296 | jsonObject.put("desciption", ""); |
| 280 | jsonObject.put("receive_notification", "0"); | 297 | jsonObject.put("receive_notification", "0"); |
| 281 | //jsonObject.put("phone", "+84986940999"); | 298 | //jsonObject.put("phone", "+84986940999"); |
| 282 | jsonObject.put("share_data", "1"); | 299 | jsonObject.put("share_data", "1"); |
| 283 | jsonObject.put("profile_image", ""+registerInfo.getProfileImage()); | 300 | jsonObject.put("profile_image", ""+registerInfo.getProfileImage()); |
| 284 | jsonObject.put("delete_flag", "0"); | 301 | jsonObject.put("delete_flag", "0"); |
| 285 | jsonObject.put("email", registerInfo.getEmail()); | 302 | jsonObject.put("email", registerInfo.getEmail()); |
| 286 | jsonObject.put("physical_activity", "0"); | 303 | jsonObject.put("physical_activity", "0"); |
| 287 | jsonObject.put("remember_me", "1"); | 304 | jsonObject.put("remember_me", "1"); |
| 288 | 305 | ||
| 289 | Debug.warn("Json data: " + jsonObject.toString()); | 306 | Debug.warn("Json data: " + jsonObject.toString()); |
| 290 | } catch (JSONException e) { | 307 | } catch (JSONException e) { |
| 291 | Debug.normal("Error ", e.getMessage()); | 308 | Debug.normal("Error ", e.getMessage()); |
| 292 | } | 309 | } |
| 293 | 310 | ||
| 294 | MediaType JSON | 311 | MediaType JSON |
| 295 | = MediaType.parse("application/json; charset=utf-8"); | 312 | = MediaType.parse("application/json; charset=utf-8"); |
| 296 | RequestBody requestBody = RequestBody.create(JSON, jsonObject.toString()); | 313 | RequestBody requestBody = RequestBody.create(JSON, jsonObject.toString()); |
| 297 | 314 | ||
| 298 | final Request.Builder request = new Request.Builder() | 315 | final Request.Builder request = new Request.Builder() |
| 299 | .url(baseUrl) | 316 | .url(baseUrl) |
| 300 | .header("User-Agent", Utils.getCustomUA()) | 317 | .header("User-Agent", Utils.getCustomUA()) |
| 301 | .header("Content-Type", "application/json") | 318 | .header("Content-Type", "application/json") |
| 302 | .post(requestBody); | 319 | .post(requestBody); |
| 303 | 320 | ||
| 304 | OkHttpClient httpClient = new OkHttpClient.Builder() | 321 | OkHttpClient httpClient = new OkHttpClient.Builder() |
| 305 | .readTimeout(30, TimeUnit.SECONDS) | 322 | .readTimeout(30, TimeUnit.SECONDS) |
| 306 | .writeTimeout(30, TimeUnit.SECONDS) | 323 | .writeTimeout(30, TimeUnit.SECONDS) |
| 307 | .connectTimeout(30, TimeUnit.SECONDS) | 324 | .connectTimeout(30, TimeUnit.SECONDS) |
| 308 | .build(); | 325 | .build(); |
| 309 | 326 | ||
| 310 | String jsonString = null; | 327 | String jsonString = null; |
| 311 | try { | 328 | try { |
| 312 | Response response = httpClient.newCall(request.build()).execute(); | 329 | Response response = httpClient.newCall(request.build()).execute(); |
| 313 | if (response == null) { | 330 | if (response == null) { |
| 314 | action.onError(null); | 331 | action.onError(null); |
| 315 | Debug.error("Response is null"); | 332 | Debug.error("Response is null"); |
| 316 | return null; | 333 | return null; |
| 317 | } | 334 | } |
| 318 | jsonString = getResponseData(response.body()); | 335 | jsonString = getResponseData(response.body()); |
| 319 | 336 | ||
| 320 | } catch (IOException e) { | 337 | } catch (IOException e) { |
| 321 | Debug.normal("Error %s", e.getMessage()); | 338 | Debug.normal("Error %s", e.getMessage()); |
| 322 | } | 339 | } |
| 323 | return jsonString; | 340 | return jsonString; |
| 324 | } | 341 | } |
| 325 | 342 | ||
| 326 | @Override | 343 | @Override |
| 327 | protected void onCancelled() { | 344 | protected void onCancelled() { |
| 328 | super.onCancelled(); | 345 | super.onCancelled(); |
| 329 | action.onError(null); | 346 | action.onError(null); |
| 330 | } | 347 | } |
| 331 | 348 | ||
| 332 | @Override | 349 | @Override |
| 333 | protected void onPostExecute(String jsonString) { | 350 | protected void onPostExecute(String jsonString) { |
| 334 | super.onPostExecute(jsonString); | 351 | super.onPostExecute(jsonString); |
| 335 | if ((jsonString == null) || (jsonString.isEmpty())) { | 352 | if ((jsonString == null) || (jsonString.isEmpty())) { |
| 336 | action.onError(null); | 353 | action.onError(null); |
| 337 | return; | 354 | return; |
| 338 | } | 355 | } |
| 339 | Debug.normal("String body: "+jsonString); | 356 | Debug.normal("String body: "+jsonString); |
| 340 | 357 | ||
| 341 | try { | 358 | try { |
| 342 | JSONObject jsonObject = new JSONObject(jsonString); | 359 | JSONObject jsonObject = new JSONObject(jsonString); |
| 343 | int status = jsonObject.optInt("status"); | 360 | int status = jsonObject.optInt("status"); |
| 344 | if (status == 1){ | 361 | if (status == 1){ |
| 345 | JSONObject object = jsonObject.optJSONObject("result"); | 362 | JSONObject object = jsonObject.optJSONObject("result"); |
| 346 | JSONObject objUser = object.getJSONObject("user"); | 363 | JSONObject objUser = object.getJSONObject("user"); |
| 347 | String token = object.optString("token"); | 364 | String token = object.optString("token"); |
| 348 | APIResponse.getInstance().setToken(token); | 365 | APIResponse.getInstance().setToken(token); |
| 349 | Debug.normal("Token: "+ token); | 366 | Debug.normal("Token: "+ token); |
| 350 | action.onSuccess(objUser); | 367 | action.onSuccess(objUser); |
| 351 | }else { | 368 | }else { |
| 352 | action.onError(new Error(jsonObject.optString("message"))); | 369 | action.onError(new Error(jsonObject.optString("message"))); |
| 353 | } | 370 | } |
| 354 | } catch (JSONException e) { | 371 | } catch (JSONException e) { |
| 355 | e.printStackTrace(); | 372 | e.printStackTrace(); |
| 356 | } | 373 | } |
| 357 | 374 | ||
| 358 | } | 375 | } |
| 359 | }.execute(); | ||
| 360 | } | 376 | } |
| 361 | 377 | ||
| 362 | private static byte[] convertBitmapToByteArray(Bitmap bitmap) { | 378 | private static byte[] convertBitmapToByteArray(Bitmap bitmap) { |
| 363 | ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); | 379 | ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); |
| 364 | bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream); | 380 | bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream); |
| 365 | byte[] byteArray = byteArrayOutputStream.toByteArray(); | 381 | byte[] byteArray = byteArrayOutputStream.toByteArray(); |
| 366 | return byteArray; | 382 | return byteArray; |
| 367 | } | 383 | } |
| 368 | 384 | ||
| 369 | public static void forgetPass(final String email, final LLAPIManagerListener action) { | 385 | public static class ForgetPass extends AsyncTask<Void, Void, String>{ |
| 370 | new AsyncTask<Void, Void, String>() { | 386 | private String email; |
| 387 | private LLAPIManagerListener action; | ||
| 371 | 388 | ||
| 389 | public ForgetPass(String email, LLAPIManagerListener action) { | ||
| 390 | this.email = email; | ||
| 391 | this.action = action; | ||
| 392 | } | ||
| 372 | 393 | ||
| 373 | @Override | 394 | @Override |
| 374 | protected void onPreExecute() { | 395 | protected void onPreExecute() { |
| 375 | super.onPreExecute(); | 396 | super.onPreExecute(); |
| 376 | } | 397 | } |
| 377 | 398 | ||
| 378 | @Override | 399 | @Override |
| 379 | protected String doInBackground(Void... voids) { | 400 | protected String doInBackground(Void... voids) { |
| 380 | HttpUrl baseUrl = HttpUrl.parse(URL_ROOT + URL_FORGET_PASS_INFO); | 401 | HttpUrl baseUrl = HttpUrl.parse(URL_ROOT + URL_FORGET_PASS_INFO); |
| 381 | JSONObject jsonObject = new JSONObject(); | 402 | JSONObject jsonObject = new JSONObject(); |
| 382 | try { | 403 | try { |
| 383 | //Personal info | 404 | //Personal info |
| 384 | jsonObject.put("email", email); | 405 | jsonObject.put("email", email); |
| 385 | 406 | ||
| 386 | Debug.warn("Json data: " + jsonObject.toString()); | 407 | Debug.warn("Json data: " + jsonObject.toString()); |
| 387 | } catch (JSONException e) { | 408 | } catch (JSONException e) { |
| 388 | Debug.normal("Error ", e.getMessage()); | 409 | Debug.normal("Error ", e.getMessage()); |
| 389 | } | 410 | } |
| 390 | 411 | ||
| 391 | MediaType JSON | 412 | MediaType JSON |
| 392 | = MediaType.parse("application/json"); | 413 | = MediaType.parse("application/json"); |
| 393 | RequestBody requestBody = RequestBody.create(JSON, jsonObject.toString()); | 414 | RequestBody requestBody = RequestBody.create(JSON, jsonObject.toString()); |
| 394 | 415 | ||
| 395 | final Request.Builder request = new Request.Builder() | 416 | final Request.Builder request = new Request.Builder() |
| 396 | .url(baseUrl) | 417 | .url(baseUrl) |
| 397 | .header("User-Agent", Utils.getCustomUA()) | 418 | .header("User-Agent", Utils.getCustomUA()) |
| 398 | .header("Content-Type", "application/json") | 419 | .header("Content-Type", "application/json") |
| 399 | .post(requestBody); | 420 | .post(requestBody); |
| 400 | 421 | ||
| 401 | OkHttpClient httpClient = new OkHttpClient.Builder() | 422 | OkHttpClient httpClient = new OkHttpClient.Builder() |
| 402 | .readTimeout(30, TimeUnit.SECONDS) | 423 | .readTimeout(30, TimeUnit.SECONDS) |
| 403 | .writeTimeout(30, TimeUnit.SECONDS) | 424 | .writeTimeout(30, TimeUnit.SECONDS) |
| 404 | .connectTimeout(30, TimeUnit.SECONDS) | 425 | .connectTimeout(30, TimeUnit.SECONDS) |
| 405 | .build(); | 426 | .build(); |
| 406 | 427 | ||
| 407 | String jsonString = null; | 428 | String jsonString = null; |
| 408 | try { | 429 | try { |
| 409 | Response response = httpClient.newCall(request.build()).execute(); | 430 | Response response = httpClient.newCall(request.build()).execute(); |
| 410 | if (response == null) { | 431 | if (response == null) { |
| 411 | action.onError(null); | 432 | action.onError(null); |
| 412 | Debug.error("Response is null"); | 433 | Debug.error("Response is null"); |
| 413 | return null; | 434 | return null; |
| 414 | } | 435 | } |
| 415 | jsonString = getResponseData(response.body()); | 436 | jsonString = getResponseData(response.body()); |
| 416 | 437 | ||
| 417 | } catch (IOException e) { | 438 | } catch (IOException e) { |
| 418 | Debug.normal("Error %s", e.getMessage()); | 439 | Debug.normal("Error %s", e.getMessage()); |
| 419 | } | 440 | } |
| 420 | return jsonString; | 441 | return jsonString; |
| 421 | } | 442 | } |
| 422 | 443 | ||
| 423 | @Override | 444 | @Override |
| 424 | protected void onCancelled() { | 445 | protected void onCancelled() { |
| 425 | super.onCancelled(); | 446 | super.onCancelled(); |
| 426 | action.onError(null); | 447 | action.onError(null); |
| 427 | } | 448 | } |
| 428 | 449 | ||
| 429 | @Override | 450 | @Override |
| 430 | protected void onPostExecute(String jsonString) { | 451 | protected void onPostExecute(String jsonString) { |
| 431 | super.onPostExecute(jsonString); | 452 | super.onPostExecute(jsonString); |
| 432 | if ((jsonString == null) || (jsonString.isEmpty())) { | 453 | if ((jsonString == null) || (jsonString.isEmpty())) { |
| 433 | action.onError(null); | 454 | action.onError(null); |
| 434 | return; | 455 | return; |
| 435 | } | 456 | } |
| 436 | Debug.normal("String body: "+jsonString); | 457 | Debug.normal("String body: "+jsonString); |
| 437 | 458 | ||
| 438 | try { | 459 | try { |
| 439 | JSONObject jsonObject = new JSONObject(jsonString); | 460 | JSONObject jsonObject = new JSONObject(jsonString); |
| 440 | int status = jsonObject.optInt("status"); | 461 | int status = jsonObject.optInt("status"); |
| 441 | if (status == 1) { | 462 | if (status == 1) { |
| 442 | action.onSuccess(jsonString); | 463 | action.onSuccess(jsonString); |
| 443 | } else { | 464 | } else { |
| 444 | action.onError(new Error(jsonObject.getString("message"))); | 465 | action.onError(new Error(jsonObject.getString("message"))); |
| 445 | } | 466 | } |
| 446 | } catch (JSONException e) { | 467 | } catch (JSONException e) { |
| 447 | action.onError(null); | 468 | action.onError(null); |
| 448 | } | 469 | } |
| 449 | } | 470 | } |
| 450 | }.execute(); | 471 | |
| 451 | } | 472 | } |
| 452 | 473 | ||
| 453 | public static void forgetPassConfirm(final String email, final String codeConfirm, final LLAPIManagerListener action) { | 474 | public static class ForgetPassConfirm extends AsyncTask<Void, Void, String>{ |
| 454 | new AsyncTask<Void, Void, String>() { | 475 | private String email; |
| 476 | private String codeConfirm; | ||
| 477 | private LLAPIManagerListener action; | ||
| 455 | 478 | ||
| 479 | public ForgetPassConfirm(String email, String codeConfirm, LLAPIManagerListener action) { | ||
| 480 | this.email = email; | ||
| 481 | this.codeConfirm = codeConfirm; | ||
| 482 | this.action = action; | ||
| 483 | } | ||
| 456 | 484 | ||
| 457 | @Override | 485 | @Override |
| 458 | protected void onPreExecute() { | 486 | protected void onPreExecute() { |
| 459 | super.onPreExecute(); | 487 | super.onPreExecute(); |
| 460 | } | 488 | } |
| 461 | 489 | ||
| 462 | @Override | 490 | @Override |
| 463 | protected String doInBackground(Void... voids) { | 491 | protected String doInBackground(Void... voids) { |
| 464 | HttpUrl baseUrl = HttpUrl.parse(URL_ROOT + URL_FORGET_PASS_CONFIRM_INFO); | 492 | HttpUrl baseUrl = HttpUrl.parse(URL_ROOT + URL_FORGET_PASS_CONFIRM_INFO); |
| 465 | JSONObject jsonObject = new JSONObject(); | 493 | JSONObject jsonObject = new JSONObject(); |
| 466 | try { | 494 | try { |
| 467 | //Personal info | 495 | //Personal info |
| 468 | jsonObject.put("email", email); | 496 | jsonObject.put("email", email); |
| 469 | jsonObject.put("code_confirm", codeConfirm); | 497 | jsonObject.put("code_confirm", codeConfirm); |
| 470 | 498 | ||
| 471 | Debug.warn("Json data: " + jsonObject.toString()); | 499 | Debug.warn("Json data: " + jsonObject.toString()); |
| 472 | } catch (JSONException e) { | 500 | } catch (JSONException e) { |
| 473 | Debug.normal("Error ", e.getMessage()); | 501 | Debug.normal("Error ", e.getMessage()); |
| 474 | } | 502 | } |
| 475 | 503 | ||
| 476 | MediaType JSON | 504 | MediaType JSON |
| 477 | = MediaType.parse("application/json"); | 505 | = MediaType.parse("application/json"); |
| 478 | RequestBody requestBody = RequestBody.create(JSON, jsonObject.toString()); | 506 | RequestBody requestBody = RequestBody.create(JSON, jsonObject.toString()); |
| 479 | 507 | ||
| 480 | final Request.Builder request = new Request.Builder() | 508 | final Request.Builder request = new Request.Builder() |
| 481 | .url(baseUrl) | 509 | .url(baseUrl) |
| 482 | .header("User-Agent", Utils.getCustomUA()) | 510 | .header("User-Agent", Utils.getCustomUA()) |
| 483 | .header("Content-Type", "application/json") | 511 | .header("Content-Type", "application/json") |
| 484 | .post(requestBody); | 512 | .post(requestBody); |
| 485 | 513 | ||
| 486 | OkHttpClient httpClient = new OkHttpClient.Builder() | 514 | OkHttpClient httpClient = new OkHttpClient.Builder() |
| 487 | .readTimeout(30, TimeUnit.SECONDS) | 515 | .readTimeout(30, TimeUnit.SECONDS) |
| 488 | .writeTimeout(30, TimeUnit.SECONDS) | 516 | .writeTimeout(30, TimeUnit.SECONDS) |
| 489 | .connectTimeout(30, TimeUnit.SECONDS) | 517 | .connectTimeout(30, TimeUnit.SECONDS) |
| 490 | .build(); | 518 | .build(); |
| 491 | String jsonString = null; | 519 | String jsonString = null; |
| 492 | try { | 520 | try { |
| 493 | Response response = httpClient.newCall(request.build()).execute(); | 521 | Response response = httpClient.newCall(request.build()).execute(); |
| 494 | if (response == null) { | 522 | if (response == null) { |
| 495 | action.onError(null); | 523 | action.onError(null); |
| 496 | Debug.error("Response is null"); | 524 | Debug.error("Response is null"); |
| 497 | return null; | 525 | return null; |
| 498 | } | 526 | } |
| 499 | jsonString = getResponseData(response.body()); | 527 | jsonString = getResponseData(response.body()); |
| 500 | 528 | ||
| 501 | } catch (IOException e) { | 529 | } catch (IOException e) { |
| 502 | Debug.normal("Error %s", e.getMessage()); | 530 | Debug.normal("Error %s", e.getMessage()); |
| 503 | } | 531 | } |
| 504 | return jsonString; | 532 | return jsonString; |
| 505 | } | 533 | } |
| 506 | 534 | ||
| 507 | @Override | 535 | @Override |
| 508 | protected void onCancelled() { | 536 | protected void onCancelled() { |
| 509 | super.onCancelled(); | 537 | super.onCancelled(); |
| 510 | action.onError(null); | 538 | action.onError(null); |
| 511 | } | 539 | } |
| 512 | 540 | ||
| 513 | @Override | 541 | @Override |
| 514 | protected void onPostExecute(String jsonString) { | 542 | protected void onPostExecute(String jsonString) { |
| 515 | super.onPostExecute(jsonString); | 543 | super.onPostExecute(jsonString); |
| 516 | if ((jsonString == null) || (jsonString.isEmpty())) { | 544 | if ((jsonString == null) || (jsonString.isEmpty())) { |
| 517 | action.onError(null); | 545 | action.onError(null); |
| 518 | return; | 546 | return; |
| 519 | } | 547 | } |
| 520 | Debug.normal("String body: "+jsonString); | 548 | Debug.normal("String body: "+jsonString); |
| 521 | 549 | ||
| 522 | try { | 550 | try { |
| 523 | JSONObject jsonObject = new JSONObject(jsonString); | 551 | JSONObject jsonObject = new JSONObject(jsonString); |
| 524 | int status = jsonObject.optInt("status"); | 552 | int status = jsonObject.optInt("status"); |
| 525 | if (status == 1) { | 553 | if (status == 1) { |
| 526 | action.onSuccess(jsonString); | 554 | action.onSuccess(jsonString); |
| 527 | } else { | 555 | } else { |
| 528 | action.onError(new Error(jsonObject.getString("message"))); | 556 | action.onError(new Error(jsonObject.getString("message"))); |
| 529 | } | 557 | } |
| 530 | } catch (JSONException e) { | 558 | } catch (JSONException e) { |
| 531 | action.onError(null); | 559 | action.onError(null); |
| 532 | } | 560 | } |
| 533 | } | 561 | } |
| 534 | }.execute(); | ||
| 535 | } | 562 | } |
| 536 | 563 | ||
| 537 | public static void history(final Date fromDate, final Date toDate, final LLAPIManagerListener action) { | 564 | public static class History extends AsyncTask<Void, Void, String>{ |
| 538 | new AsyncTask<Void, Void, String>() { | 565 | private Date fromDate; |
| 566 | private Date toDate; | ||
| 567 | private LLAPIManagerListener action; | ||
| 539 | 568 | ||
| 569 | public History(Date fromDate, Date toDate, LLAPIManagerListener action) { | ||
| 570 | this.fromDate = fromDate; | ||
| 571 | this.toDate = toDate; | ||
| 572 | this.action = action; | ||
| 573 | } | ||
| 540 | 574 | ||
| 541 | @Override | 575 | @Override |
| 542 | protected void onPreExecute() { | 576 | protected void onPreExecute() { |
| 543 | super.onPreExecute(); | 577 | super.onPreExecute(); |
| 544 | } | 578 | } |
| 545 | 579 | ||
| 546 | @Override | 580 | @Override |
| 547 | protected String doInBackground(Void... voids) { | 581 | protected String doInBackground(Void... voids) { |
| 548 | 582 | ||
| 549 | String fromStr = Utils.dateToStringFormatYearMonthDay(fromDate); | 583 | String fromStr = Utils.dateToStringFormatYearMonthDay(fromDate); |
| 550 | String toStr = Utils.dateToStringFormatYearMonthDay(toDate); | 584 | String toStr = Utils.dateToStringFormatYearMonthDay(toDate); |
| 551 | Debug.normal("Token: "+ APIResponse.getInstance().getToken()); | 585 | Debug.normal("Token: "+ APIResponse.getInstance().getToken()); |
| 552 | HttpUrl baseUrl = HttpUrl.parse(URL_ROOT + URL_HISTORE_INFO + "/"+ fromStr +"/"+ toStr); | 586 | HttpUrl baseUrl = HttpUrl.parse(URL_ROOT + URL_HISTORE_INFO + "/"+ fromStr +"/"+ toStr); |
| 553 | Debug.normal("URL: "+baseUrl.toString()); | 587 | Debug.normal("URL: "+baseUrl.toString()); |
| 554 | final Request.Builder request = new Request.Builder() | 588 | final Request.Builder request = new Request.Builder() |
| 555 | .url(baseUrl) | 589 | .url(baseUrl) |
| 556 | .header("User-Agent", Utils.getCustomUA()) | 590 | .header("User-Agent", Utils.getCustomUA()) |
| 557 | .header("Content-Type", "application/json") | 591 | .header("Content-Type", "application/json") |
| 558 | .addHeader("token", APIResponse.getInstance().getToken()) | 592 | .addHeader("token", APIResponse.getInstance().getToken()) |
| 559 | .get(); | 593 | .get(); |
| 560 | 594 | ||
| 561 | OkHttpClient httpClient = new OkHttpClient.Builder() | 595 | OkHttpClient httpClient = new OkHttpClient.Builder() |
| 562 | .readTimeout(30, TimeUnit.SECONDS) | 596 | .readTimeout(30, TimeUnit.SECONDS) |
| 563 | .writeTimeout(30, TimeUnit.SECONDS) | 597 | .writeTimeout(30, TimeUnit.SECONDS) |
| 564 | .connectTimeout(30, TimeUnit.SECONDS) | 598 | .connectTimeout(30, TimeUnit.SECONDS) |
| 565 | .build(); | 599 | .build(); |
| 566 | 600 | ||
| 567 | String jsonString = null; | 601 | String jsonString = null; |
| 568 | try { | 602 | try { |
| 569 | Response response = httpClient.newCall(request.build()).execute(); | 603 | Response response = httpClient.newCall(request.build()).execute(); |
| 570 | if (response == null) { | 604 | if (response == null) { |
| 571 | action.onError(null); | 605 | action.onError(null); |
| 572 | Debug.error("Response is null"); | 606 | Debug.error("Response is null"); |
| 573 | return null; | 607 | return null; |
| 574 | } | 608 | } |
| 575 | jsonString = getResponseData(response.body()); | 609 | jsonString = getResponseData(response.body()); |
| 576 | 610 | ||
| 577 | } catch (IOException e) { | 611 | } catch (IOException e) { |
| 578 | Debug.normal("Error %s", e.getMessage()); | 612 | Debug.normal("Error %s", e.getMessage()); |
| 579 | } | 613 | } |
| 580 | return jsonString; | 614 | return jsonString; |
| 581 | } | 615 | } |
| 582 | 616 | ||
| 583 | @Override | 617 | @Override |
| 584 | protected void onCancelled() { | 618 | protected void onCancelled() { |
| 585 | super.onCancelled(); | 619 | super.onCancelled(); |
| 586 | action.onError(null); | 620 | action.onError(null); |
| 587 | } | 621 | } |
| 588 | 622 | ||
| 589 | @Override | 623 | @Override |
| 590 | protected void onPostExecute(String jsonString) { | 624 | protected void onPostExecute(String jsonString) { |
| 591 | super.onPostExecute(jsonString); | 625 | super.onPostExecute(jsonString); |
| 592 | if ((jsonString == null) || (jsonString.isEmpty())) { | 626 | if ((jsonString == null) || (jsonString.isEmpty())) { |
| 593 | action.onError(null); | 627 | action.onError(null); |
| 594 | return; | 628 | return; |
| 595 | } | 629 | } |
| 596 | Debug.normal("String body: "+jsonString); | 630 | Debug.normal("String body: "+jsonString); |
| 597 | 631 | ||
| 598 | try { | 632 | try { |
| 599 | JSONObject jsonObject = new JSONObject(jsonString); | 633 | JSONObject jsonObject = new JSONObject(jsonString); |
| 600 | int status = jsonObject.optInt("status"); | 634 | int status = jsonObject.optInt("status"); |
| 601 | if (status == 1) { | 635 | if (status == 1) { |
| 602 | action.onSuccess(jsonString); | 636 | action.onSuccess(jsonString); |
| 603 | } else { | 637 | } else { |
| 604 | action.onError(new Error(jsonObject.getString("message"))); | 638 | action.onError(new Error(jsonObject.getString("message"))); |
| 605 | } | 639 | } |
| 606 | } catch (JSONException e) { | 640 | } catch (JSONException e) { |
| 607 | action.onError(null); | 641 | action.onError(null); |
| 608 | } | 642 | } |
| 609 | } | 643 | } |
| 610 | }.execute(); | ||
| 611 | } | 644 | } |
| 612 | 645 | ||
| 613 | public static void historyDetail(final Date fromDate, final Date toDate, final LLAPIManagerListener action) { | 646 | public static class HistoryDetail extends AsyncTask<Void, Void, String>{ |
| 614 | new AsyncTask<Void, Void, String>() { | 647 | private Date fromDate; |
| 648 | private Date toDate; | ||
| 649 | private LLAPIManagerListener action; | ||
| 615 | 650 | ||
| 651 | public HistoryDetail(Date fromDate, Date toDate, LLAPIManagerListener action) { | ||
| 652 | this.fromDate = fromDate; | ||
| 653 | this.toDate = toDate; | ||
| 654 | this.action = action; | ||
| 655 | } | ||
| 616 | 656 | ||
| 617 | @Override | 657 | @Override |
| 618 | protected void onPreExecute() { | 658 | protected void onPreExecute() { |
| 619 | super.onPreExecute(); | 659 | super.onPreExecute(); |
| 620 | } | 660 | } |
| 621 | 661 | ||
| 622 | @Override | 662 | @Override |
| 623 | protected String doInBackground(Void... voids) { | 663 | protected String doInBackground(Void... voids) { |
| 624 | 664 | ||
| 625 | String fromStr = Utils.dateToStringFormatDayMonthYear(fromDate); | 665 | String fromStr = Utils.dateToStringFormatDayMonthYear(fromDate); |
| 626 | String toStr = Utils.dateToStringFormatDayMonthYear(toDate); | 666 | String toStr = Utils.dateToStringFormatDayMonthYear(toDate); |
| 627 | Debug.normal("Token: "+ APIResponse.getInstance().getToken()); | 667 | Debug.normal("Token: "+ APIResponse.getInstance().getToken()); |
| 628 | HttpUrl baseUrl = HttpUrl.parse(URL_ROOT + URL_HISTORE_DETAIL_INFO + "/"+ fromStr +"/"+ toStr); | 668 | HttpUrl baseUrl = HttpUrl.parse(URL_ROOT + URL_HISTORE_DETAIL_INFO + "/"+ fromStr +"/"+ toStr); |
| 629 | Debug.normal("URL: "+baseUrl.toString()); | 669 | Debug.normal("URL: "+baseUrl.toString()); |
| 630 | final Request.Builder request = new Request.Builder() | 670 | final Request.Builder request = new Request.Builder() |
| 631 | .url(baseUrl) | 671 | .url(baseUrl) |
| 632 | .header("User-Agent", Utils.getCustomUA()) | 672 | .header("User-Agent", Utils.getCustomUA()) |
| 633 | .header("Content-Type", "application/json") | 673 | .header("Content-Type", "application/json") |
| 634 | .addHeader("token", APIResponse.getInstance().getToken()) | 674 | .addHeader("token", APIResponse.getInstance().getToken()) |
| 635 | .get(); | 675 | .get(); |
| 636 | 676 | ||
| 637 | OkHttpClient httpClient = new OkHttpClient.Builder() | 677 | OkHttpClient httpClient = new OkHttpClient.Builder() |
| 638 | .readTimeout(30, TimeUnit.SECONDS) | 678 | .readTimeout(30, TimeUnit.SECONDS) |
| 639 | .writeTimeout(30, TimeUnit.SECONDS) | 679 | .writeTimeout(30, TimeUnit.SECONDS) |
| 640 | .connectTimeout(30, TimeUnit.SECONDS) | 680 | .connectTimeout(30, TimeUnit.SECONDS) |
| 641 | .build(); | 681 | .build(); |
| 642 | 682 | ||
| 643 | String jsonString = null; | 683 | String jsonString = null; |
| 644 | try { | 684 | try { |
| 645 | Response response = httpClient.newCall(request.build()).execute(); | 685 | Response response = httpClient.newCall(request.build()).execute(); |
| 646 | if (response == null) { | 686 | if (response == null) { |
| 647 | action.onError(null); | 687 | action.onError(null); |
| 648 | Debug.error("Response is null"); | 688 | Debug.error("Response is null"); |
| 649 | return null; | 689 | return null; |
| 650 | } | 690 | } |
| 651 | jsonString = getResponseData(response.body()); | 691 | jsonString = getResponseData(response.body()); |
| 652 | 692 | ||
| 653 | } catch (IOException e) { | 693 | } catch (IOException e) { |
| 654 | Debug.normal("Error %s", e.getMessage()); | 694 | Debug.normal("Error %s", e.getMessage()); |
| 655 | } | 695 | } |
| 656 | return jsonString; | 696 | return jsonString; |
| 657 | } | 697 | } |
| 658 | 698 | ||
| 659 | @Override | 699 | @Override |
| 660 | protected void onCancelled() { | 700 | protected void onCancelled() { |
| 661 | super.onCancelled(); | 701 | super.onCancelled(); |
| 662 | action.onError(null); | 702 | action.onError(null); |
| 663 | } | 703 | } |
| 664 | 704 | ||
| 665 | @Override | 705 | @Override |
| 666 | protected void onPostExecute(String jsonString) { | 706 | protected void onPostExecute(String jsonString) { |
| 667 | super.onPostExecute(jsonString); | 707 | super.onPostExecute(jsonString); |
| 668 | if ((jsonString == null) || (jsonString.isEmpty())) { | 708 | if ((jsonString == null) || (jsonString.isEmpty())) { |
| 669 | action.onError(null); | 709 | action.onError(null); |
| 670 | return; | 710 | return; |
| 671 | } | 711 | } |
| 672 | Debug.normal("String body: "+jsonString); | 712 | Debug.normal("String body: "+jsonString); |
| 673 | 713 | ||
| 674 | try { | 714 | try { |
| 675 | JSONObject jsonObject = new JSONObject(jsonString); | 715 | JSONObject jsonObject = new JSONObject(jsonString); |
| 676 | int status = jsonObject.optInt("status"); | 716 | int status = jsonObject.optInt("status"); |
| 677 | if (status == 1) { | 717 | if (status == 1) { |
| 678 | action.onSuccess(jsonString); | 718 | action.onSuccess(jsonString); |
| 679 | } else { | 719 | } else { |
| 680 | action.onError(new Error(jsonObject.getString("message"))); | 720 | action.onError(new Error(jsonObject.getString("message"))); |
| 681 | } | 721 | } |
| 682 | } catch (JSONException e) { | 722 | } catch (JSONException e) { |
| 683 | action.onError(null); | 723 | action.onError(null); |
| 684 | } | 724 | } |
| 685 | } | 725 | } |
| 686 | }.execute(); | 726 | |
| 687 | } | 727 | } |
| 688 | 728 | ||
| 689 | public static void homePage(final Date date, final Const.STEP_TYPE stepType, final LLAPIManagerListener action) { | 729 | public static class HomePage extends AsyncTask<Void, Void, String>{ |
| 690 | new AsyncTask<Void, Void, String>() { | 730 | private Date date; |
| 731 | private Const.STEP_TYPE stepType; | ||
| 732 | private LLAPIManagerListener action; | ||
| 691 | 733 | ||
| 734 | public HomePage(Date date, Const.STEP_TYPE stepType, LLAPIManagerListener action) { | ||
| 735 | this.date = date; | ||
| 736 | this.stepType = stepType; | ||
| 737 | this.action = action; | ||
| 738 | } | ||
| 692 | 739 | ||
| 693 | @Override | 740 | @Override |
| 694 | protected void onPreExecute() { | 741 | protected void onPreExecute() { |
| 695 | super.onPreExecute(); | 742 | super.onPreExecute(); |
| 696 | } | 743 | } |
| 697 | 744 | ||
| 698 | @Override | 745 | @Override |
| 699 | protected String doInBackground(Void... voids) { | 746 | protected String doInBackground(Void... voids) { |
| 700 | 747 | ||
| 701 | String dateStr = Utils.dateToStringFormatDayMonthYear(date); | 748 | String dateStr = Utils.dateToStringFormatDayMonthYear(date); |
| 702 | Debug.normal("Token: "+ APIResponse.getInstance().getToken()); | 749 | Debug.normal("Token: "+ APIResponse.getInstance().getToken()); |
| 703 | HttpUrl baseUrl = HttpUrl.parse(URL_ROOT + URL_HOME_INFO + "/"+ stepType.value +"/"+ dateStr); | 750 | HttpUrl baseUrl = HttpUrl.parse(URL_ROOT + URL_HOME_INFO + "/"+ stepType.value +"/"+ dateStr); |
| 704 | Debug.normal("URL: "+baseUrl.toString()); | 751 | Debug.normal("URL: "+baseUrl.toString()); |
| 705 | final Request.Builder request = new Request.Builder() | 752 | final Request.Builder request = new Request.Builder() |
| 706 | .url(baseUrl) | 753 | .url(baseUrl) |
| 707 | .header("User-Agent", Utils.getCustomUA()) | 754 | .header("User-Agent", Utils.getCustomUA()) |
| 708 | .header("Content-Type", "application/json") | 755 | .header("Content-Type", "application/json") |
| 709 | .addHeader("token", APIResponse.getInstance().getToken()) | 756 | .addHeader("token", APIResponse.getInstance().getToken()) |
| 710 | .get(); | 757 | .get(); |
| 711 | 758 | ||
| 712 | OkHttpClient httpClient = new OkHttpClient.Builder() | 759 | OkHttpClient httpClient = new OkHttpClient.Builder() |
| 713 | .readTimeout(30, TimeUnit.SECONDS) | 760 | .readTimeout(30, TimeUnit.SECONDS) |
| 714 | .writeTimeout(30, TimeUnit.SECONDS) | 761 | .writeTimeout(30, TimeUnit.SECONDS) |
| 715 | .connectTimeout(30, TimeUnit.SECONDS) | 762 | .connectTimeout(30, TimeUnit.SECONDS) |
| 716 | .build(); | 763 | .build(); |
| 717 | 764 | ||
| 718 | String jsonString = null; | 765 | String jsonString = null; |
| 719 | try { | 766 | try { |
| 720 | Response response = httpClient.newCall(request.build()).execute(); | 767 | Response response = httpClient.newCall(request.build()).execute(); |
| 721 | if (response == null) { | 768 | if (response == null) { |
| 722 | action.onError(null); | 769 | action.onError(null); |
| 723 | Debug.error("Response is null"); | 770 | Debug.error("Response is null"); |
| 724 | return null; | 771 | return null; |
| 725 | } | 772 | } |
| 726 | jsonString = getResponseData(response.body()); | 773 | jsonString = getResponseData(response.body()); |
| 727 | 774 | ||
| 728 | } catch (IOException e) { | 775 | } catch (IOException e) { |
| 729 | Debug.normal("Error %s", e.getMessage()); | 776 | Debug.normal("Error %s", e.getMessage()); |
| 730 | } | 777 | } |
| 731 | return jsonString; | 778 | return jsonString; |
| 732 | } | 779 | } |
| 733 | 780 | ||
| 734 | @Override | 781 | @Override |
| 735 | protected void onCancelled() { | 782 | protected void onCancelled() { |
| 736 | super.onCancelled(); | 783 | super.onCancelled(); |
| 737 | action.onError(null); | 784 | action.onError(null); |
| 738 | } | 785 | } |
| 739 | 786 | ||
| 740 | @Override | 787 | @Override |
| 741 | protected void onPostExecute(String jsonString) { | 788 | protected void onPostExecute(String jsonString) { |
| 742 | super.onPostExecute(jsonString); | 789 | super.onPostExecute(jsonString); |
| 743 | if ((jsonString == null) || (jsonString.isEmpty())) { | 790 | if ((jsonString == null) || (jsonString.isEmpty())) { |
| 744 | action.onError(null); | 791 | action.onError(null); |
| 745 | return; | 792 | return; |
| 746 | } | 793 | } |
| 747 | Debug.normal("String body: "+jsonString); | 794 | Debug.normal("String body: "+jsonString); |
| 748 | 795 | ||
| 749 | try { | 796 | try { |
| 750 | JSONObject jsonObject = new JSONObject(jsonString); | 797 | JSONObject jsonObject = new JSONObject(jsonString); |
| 751 | int status = jsonObject.optInt("status"); | 798 | int status = jsonObject.optInt("status"); |
| 752 | if (status == 1) { | 799 | if (status == 1) { |
| 753 | action.onSuccess(jsonString); | 800 | action.onSuccess(jsonString); |
| 754 | } else { | 801 | } else { |
| 755 | action.onError(new Error(jsonObject.getString("message"))); | 802 | action.onError(new Error(jsonObject.getString("message"))); |
| 756 | } | 803 | } |
| 757 | } catch (JSONException e) { | 804 | } catch (JSONException e) { |
| 758 | action.onError(null); | 805 | action.onError(null); |
| 759 | } | 806 | } |
| 760 | } | 807 | } |
| 761 | }.execute(); | 808 | |
| 762 | } | 809 | } |
| 763 | 810 | ||
| 764 | public static void topInfo(final Date date, final Const.STEP_TYPE stepType, final LLAPIManagerListener action) { | 811 | public static class TopInfo extends AsyncTask<Void, Void, String>{ |
| 765 | new AsyncTask<Void, Void, String>() { | 812 | private Date date; |
| 813 | private Const.STEP_TYPE stepType; | ||
| 814 | private LLAPIManagerListener action; | ||
| 766 | 815 | ||
| 816 | public TopInfo(Date date, Const.STEP_TYPE stepType, LLAPIManagerListener action) { | ||
| 817 | this.date = date; | ||
| 818 | this.stepType = stepType; | ||
| 819 | this.action = action; | ||
| 820 | } | ||
| 767 | 821 | ||
| 768 | @Override | 822 | @Override |
| 769 | protected void onPreExecute() { | 823 | protected void onPreExecute() { |
| 770 | super.onPreExecute(); | 824 | super.onPreExecute(); |
| 771 | } | 825 | } |
| 772 | 826 | ||
| 773 | @Override | 827 | @Override |
| 774 | protected String doInBackground(Void... voids) { | 828 | protected String doInBackground(Void... voids) { |
| 775 | 829 | ||
| 776 | String dateStr = Utils.dateToStringFormatDayMonthYear(date); | 830 | String dateStr = Utils.dateToStringFormatDayMonthYear(date); |
| 777 | Debug.normal("Token: "+ APIResponse.getInstance().getToken()); | 831 | Debug.normal("Token: "+ APIResponse.getInstance().getToken()); |
| 778 | HttpUrl baseUrl = HttpUrl.parse(URL_ROOT + URL_TOP_INFO + "/"+ stepType.value +"/"+ dateStr); | 832 | HttpUrl baseUrl = HttpUrl.parse(URL_ROOT + URL_TOP_INFO + "/"+ stepType.value +"/"+ dateStr); |
| 779 | Debug.normal("URL: "+baseUrl.toString()); | 833 | Debug.normal("URL: "+baseUrl.toString()); |
| 780 | final Request.Builder request = new Request.Builder() | 834 | final Request.Builder request = new Request.Builder() |
| 781 | .url(baseUrl) | 835 | .url(baseUrl) |
| 782 | .header("User-Agent", Utils.getCustomUA()) | 836 | .header("User-Agent", Utils.getCustomUA()) |
| 783 | .header("Content-Type", "application/json") | 837 | .header("Content-Type", "application/json") |
| 784 | .addHeader("token", APIResponse.getInstance().getToken()) | 838 | .addHeader("token", APIResponse.getInstance().getToken()) |
| 785 | .get(); | 839 | .get(); |
| 786 | 840 | ||
| 787 | OkHttpClient httpClient = new OkHttpClient.Builder() | 841 | OkHttpClient httpClient = new OkHttpClient.Builder() |
| 788 | .readTimeout(30, TimeUnit.SECONDS) | 842 | .readTimeout(30, TimeUnit.SECONDS) |
| 789 | .writeTimeout(30, TimeUnit.SECONDS) | 843 | .writeTimeout(30, TimeUnit.SECONDS) |
| 790 | .connectTimeout(30, TimeUnit.SECONDS) | 844 | .connectTimeout(30, TimeUnit.SECONDS) |
| 791 | .build(); | 845 | .build(); |
| 792 | 846 | ||
| 793 | String jsonString = null; | 847 | String jsonString = null; |
| 794 | try { | 848 | try { |
| 795 | Response response = httpClient.newCall(request.build()).execute(); | 849 | Response response = httpClient.newCall(request.build()).execute(); |
| 796 | if (response == null) { | 850 | if (response == null) { |
| 797 | action.onError(null); | 851 | action.onError(null); |
| 798 | Debug.error("Response is null"); | 852 | Debug.error("Response is null"); |
| 799 | return null; | 853 | return null; |
| 800 | } | 854 | } |
| 801 | jsonString = getResponseData(response.body()); | 855 | jsonString = getResponseData(response.body()); |
| 802 | 856 | ||
| 803 | } catch (IOException e) { | 857 | } catch (IOException e) { |
| 804 | Debug.normal("Error %s", e.getMessage()); | 858 | Debug.normal("Error %s", e.getMessage()); |
| 805 | } | 859 | } |
| 806 | return jsonString; | 860 | return jsonString; |
| 807 | } | 861 | } |
| 808 | 862 | ||
| 809 | @Override | 863 | @Override |
| 810 | protected void onCancelled() { | 864 | protected void onCancelled() { |
| 811 | super.onCancelled(); | 865 | super.onCancelled(); |
| 812 | action.onError(null); | 866 | action.onError(null); |
| 813 | } | 867 | } |
| 814 | 868 | ||
| 815 | @Override | 869 | @Override |
| 816 | protected void onPostExecute(String jsonString) { | 870 | protected void onPostExecute(String jsonString) { |
| 817 | super.onPostExecute(jsonString); | 871 | super.onPostExecute(jsonString); |
| 818 | if ((jsonString == null) || (jsonString.isEmpty())) { | 872 | if ((jsonString == null) || (jsonString.isEmpty())) { |
| 819 | action.onError(null); | 873 | action.onError(null); |
| 820 | return; | 874 | return; |
| 821 | } | 875 | } |
| 822 | Debug.normal("String body: "+jsonString); | 876 | Debug.normal("String body: "+jsonString); |
| 823 | 877 | ||
| 824 | try { | 878 | try { |
| 825 | JSONObject jsonObject = new JSONObject(jsonString); | 879 | JSONObject jsonObject = new JSONObject(jsonString); |
| 826 | int status = jsonObject.optInt("status"); | 880 | int status = jsonObject.optInt("status"); |
| 827 | if (status == 1) { | 881 | if (status == 1) { |
| 828 | action.onSuccess(jsonString); | 882 | action.onSuccess(jsonString); |
| 829 | } else { | 883 | } else { |
| 830 | action.onError(new Error(jsonObject.getString("message"))); | 884 | action.onError(new Error(jsonObject.getString("message"))); |
| 831 | } | 885 | } |
| 832 | } catch (JSONException e) { | 886 | } catch (JSONException e) { |
| 833 | action.onError(null); | 887 | action.onError(null); |
| 834 | } | 888 | } |
| 835 | } | 889 | } |
| 836 | }.execute(); | 890 | |
| 837 | } | 891 | } |
| 838 | 892 | ||
| 839 | public static void createLog(final Const.STEP_TYPE stepType, final int stepCount, final Date startTime, | 893 | public static class CreateLog extends AsyncTask<Void, Void, String>{ |
| 840 | final Date endTime, final LLAPIManagerListener action) { | 894 | private int stepCount; |
| 841 | new AsyncTask<Void, Void, String>() { | 895 | private Const.STEP_TYPE stepType; |
| 896 | private Date startTime; | ||
| 897 | private Date endTime; | ||
| 898 | private LLAPIManagerListener action; | ||
| 842 | 899 | ||
| 900 | public CreateLog(Const.STEP_TYPE stepType, int stepCount, Date startTime, Date endTime, LLAPIManagerListener action) { | ||
| 901 | this.stepCount = stepCount; | ||
| 902 | this.stepType = stepType; | ||
| 903 | this.startTime = startTime; | ||
| 904 | this.endTime = endTime; | ||
| 905 | this.action = action; | ||
| 906 | } | ||
| 843 | 907 | ||
| 908 | |||
| 844 | @Override | 909 | @Override |
| 845 | protected void onPreExecute() { | 910 | protected void onPreExecute() { |
| 846 | super.onPreExecute(); | 911 | super.onPreExecute(); |
| 847 | } | 912 | } |
| 848 | 913 | ||
| 849 | @Override | 914 | @Override |
| 850 | protected String doInBackground(Void... voids) { | 915 | protected String doInBackground(Void... voids) { |
| 851 | HttpUrl baseUrl = HttpUrl.parse(URL_ROOT + URL_CREATE_LOG_INFO); | 916 | HttpUrl baseUrl = HttpUrl.parse(URL_ROOT + URL_CREATE_LOG_INFO); |
| 852 | JSONObject jsonObject = new JSONObject(); | 917 | JSONObject jsonObject = new JSONObject(); |
| 853 | String startT = Utils.convertDate2DateTimeString(startTime); | 918 | String startT = Utils.convertDate2DateTimeString(startTime); |
| 854 | String endT = Utils.convertDate2DateTimeString(endTime); | 919 | String endT = Utils.convertDate2DateTimeString(endTime); |
| 855 | try { | 920 | try { |
| 856 | jsonObject.put("mode", stepType.value); | 921 | jsonObject.put("mode", stepType.value); |
| 857 | jsonObject.put("numStep", stepCount); | 922 | jsonObject.put("numStep", stepCount); |
| 858 | jsonObject.put("startTime", startT); | 923 | jsonObject.put("startTime", startT); |
| 859 | jsonObject.put("endTime", endT); | 924 | jsonObject.put("endTime", endT); |
| 860 | 925 | ||
| 861 | Debug.warn("Json data: " + jsonObject.toString()); | 926 | Debug.warn("Json data: " + jsonObject.toString()); |
| 862 | } catch (JSONException e) { | 927 | } catch (JSONException e) { |
| 863 | Debug.normal("Error ", e.getMessage()); | 928 | Debug.normal("Error ", e.getMessage()); |
| 864 | } | 929 | } |
| 865 | 930 | ||
| 866 | MediaType JSON | 931 | MediaType JSON |
| 867 | = MediaType.parse("application/json"); | 932 | = MediaType.parse("application/json"); |
| 868 | RequestBody requestBody = RequestBody.create(JSON, jsonObject.toString()); | 933 | RequestBody requestBody = RequestBody.create(JSON, jsonObject.toString()); |
| 869 | 934 | ||
| 870 | final Request.Builder request = new Request.Builder() | 935 | final Request.Builder request = new Request.Builder() |
| 871 | .url(baseUrl) | 936 | .url(baseUrl) |
| 872 | .header("User-Agent", Utils.getCustomUA()) | 937 | .header("User-Agent", Utils.getCustomUA()) |
| 873 | .header("Content-Type", "application/json") | 938 | .header("Content-Type", "application/json") |
| 874 | .addHeader("token", APIResponse.getInstance().getToken()) | 939 | .addHeader("token", APIResponse.getInstance().getToken()) |
| 875 | .post(requestBody); | 940 | .post(requestBody); |
| 876 | 941 | ||
| 877 | OkHttpClient httpClient = new OkHttpClient.Builder() | 942 | OkHttpClient httpClient = new OkHttpClient.Builder() |
| 878 | .readTimeout(30, TimeUnit.SECONDS) | 943 | .readTimeout(30, TimeUnit.SECONDS) |
| 879 | .writeTimeout(30, TimeUnit.SECONDS) | 944 | .writeTimeout(30, TimeUnit.SECONDS) |
| 880 | .connectTimeout(30, TimeUnit.SECONDS) | 945 | .connectTimeout(30, TimeUnit.SECONDS) |
| 881 | .build(); | 946 | .build(); |
| 882 | 947 | ||
| 883 | String jsonString = null; | 948 | String jsonString = null; |
| 884 | try { | 949 | try { |
| 885 | Response response = httpClient.newCall(request.build()).execute(); | 950 | Response response = httpClient.newCall(request.build()).execute(); |
| 886 | if (response == null) { | 951 | if (response == null) { |
| 887 | action.onError(null); | 952 | action.onError(null); |
| 888 | Debug.error("Response is null"); | 953 | Debug.error("Response is null"); |
| 889 | return null; | 954 | return null; |
| 890 | } | 955 | } |
| 891 | jsonString = getResponseData(response.body()); | 956 | jsonString = getResponseData(response.body()); |
| 892 | 957 | ||
| 893 | } catch (IOException e) { | 958 | } catch (IOException e) { |
| 894 | Debug.normal("Error %s", e.getMessage()); | 959 | Debug.normal("Error %s", e.getMessage()); |
| 895 | } | 960 | } |
| 896 | return jsonString; | 961 | return jsonString; |
| 897 | } | 962 | } |
| 898 | 963 | ||
| 899 | @Override | 964 | @Override |
| 900 | protected void onCancelled() { | 965 | protected void onCancelled() { |
| 901 | super.onCancelled(); | 966 | super.onCancelled(); |
| 902 | action.onError(null); | 967 | action.onError(null); |
| 903 | } | 968 | } |
| 904 | 969 | ||
| 905 | @Override | 970 | @Override |
| 906 | protected void onPostExecute(String jsonString) { | 971 | protected void onPostExecute(String jsonString) { |
| 907 | super.onPostExecute(jsonString); | 972 | super.onPostExecute(jsonString); |
| 908 | if ((jsonString == null) || (jsonString.isEmpty())) { | 973 | if ((jsonString == null) || (jsonString.isEmpty())) { |
| 909 | action.onError(null); | 974 | action.onError(null); |
| 910 | return; | 975 | return; |
| 911 | } | 976 | } |
| 912 | Debug.normal("String body: "+jsonString); | 977 | Debug.normal("String body: "+jsonString); |
| 913 | 978 | ||
| 914 | try { | 979 | try { |
| 915 | JSONObject jsonObject = new JSONObject(jsonString); | 980 | JSONObject jsonObject = new JSONObject(jsonString); |
| 916 | int status = jsonObject.optInt("status"); | 981 | int status = jsonObject.optInt("status"); |
| 917 | if (status == 1) { | 982 | if (status == 1) { |
| 918 | action.onSuccess(jsonString); | 983 | action.onSuccess(jsonString); |
| 919 | } else { | 984 | } else { |
| 920 | action.onError(new Error(jsonObject.getString("message"))); | 985 | action.onError(new Error(jsonObject.getString("message"))); |
| 921 | } | 986 | } |
| 922 | } catch (JSONException e) { | 987 | } catch (JSONException e) { |
| 923 | action.onError(null); | 988 | action.onError(null); |
| 924 | } | 989 | } |
| 925 | } | 990 | } |
| 926 | }.execute(); | ||
| 927 | } | 991 | } |
| 928 | 992 | ||
| 929 | public static void refreshToken(final Context context, final int userId, final LLAPIManagerListener action) { | 993 | public static class RefreshToken extends AsyncTask<Void, Void, String>{ |
| 930 | new AsyncTask<Void, Void, String>() { | 994 | private Context context; |
| 995 | private int userId; | ||
| 996 | private LLAPIManagerListener action; | ||
| 931 | 997 | ||
| 998 | public RefreshToken(Context context, int userId, LLAPIManagerListener action) { | ||
| 999 | this.context = context; | ||
| 1000 | this.userId = userId; | ||
| 1001 | this.action = action; | ||
| 1002 | } | ||
| 932 | 1003 | ||
| 933 | @Override | 1004 | @Override |
| 934 | protected void onPreExecute() { | 1005 | protected void onPreExecute() { |
| 935 | super.onPreExecute(); | 1006 | super.onPreExecute(); |
| 936 | } | 1007 | } |
| 937 | 1008 | ||
| 938 | @Override | 1009 | @Override |
| 939 | protected String doInBackground(Void... voids) { | 1010 | protected String doInBackground(Void... voids) { |
| 940 | HttpUrl baseUrl = HttpUrl.parse(URL_ROOT + URL_REFESH_TOKEN_INFO); | 1011 | HttpUrl baseUrl = HttpUrl.parse(URL_ROOT + URL_REFESH_TOKEN_INFO); |
| 941 | JSONObject jsonObject = new JSONObject(); | 1012 | JSONObject jsonObject = new JSONObject(); |
| 942 | try { | 1013 | try { |
| 943 | //Personal info | 1014 | //Personal info |
| 944 | jsonObject.put("userId", userId); | 1015 | jsonObject.put("userId", userId); |
| 945 | 1016 | ||
| 946 | Debug.warn("Json data: " + jsonObject.toString()); | 1017 | Debug.warn("Json data: " + jsonObject.toString()); |
| 947 | } catch (JSONException e) { | 1018 | } catch (JSONException e) { |
| 948 | Debug.normal("Error ", e.getMessage()); | 1019 | Debug.normal("Error ", e.getMessage()); |
| 949 | } | 1020 | } |
| 950 | 1021 | ||
| 951 | MediaType JSON | 1022 | MediaType JSON |
| 952 | = MediaType.parse("application/json"); | 1023 | = MediaType.parse("application/json"); |
| 953 | RequestBody requestBody = RequestBody.create(JSON, jsonObject.toString()); | 1024 | RequestBody requestBody = RequestBody.create(JSON, jsonObject.toString()); |
| 954 | 1025 | ||
| 955 | final Request.Builder request = new Request.Builder() | 1026 | final Request.Builder request = new Request.Builder() |
| 956 | .url(baseUrl) | 1027 | .url(baseUrl) |
| 957 | .header("User-Agent", Utils.getCustomUA()) | 1028 | .header("User-Agent", Utils.getCustomUA()) |
| 958 | .header("Content-Type", "application/json") | 1029 | .header("Content-Type", "application/json") |
| 959 | .post(requestBody); | 1030 | .post(requestBody); |
| 960 | 1031 | ||
| 961 | OkHttpClient httpClient = new OkHttpClient.Builder() | 1032 | OkHttpClient httpClient = new OkHttpClient.Builder() |
| 962 | .readTimeout(30, TimeUnit.SECONDS) | 1033 | .readTimeout(30, TimeUnit.SECONDS) |
| 963 | .writeTimeout(30, TimeUnit.SECONDS) | 1034 | .writeTimeout(30, TimeUnit.SECONDS) |
| 964 | .connectTimeout(30, TimeUnit.SECONDS) | 1035 | .connectTimeout(30, TimeUnit.SECONDS) |
| 965 | .build(); | 1036 | .build(); |
| 966 | 1037 | ||
| 967 | String jsonString = null; | 1038 | String jsonString = null; |
| 968 | try { | 1039 | try { |
| 969 | Response response = httpClient.newCall(request.build()).execute(); | 1040 | Response response = httpClient.newCall(request.build()).execute(); |
| 970 | if (response == null) { | 1041 | if (response == null) { |
| 971 | action.onError(null); | 1042 | action.onError(null); |
| 972 | Debug.error("Response is null"); | 1043 | Debug.error("Response is null"); |
| 973 | return null; | 1044 | return null; |
| 974 | } | 1045 | } |
| 975 | jsonString = getResponseData(response.body()); | 1046 | jsonString = getResponseData(response.body()); |
| 976 | 1047 | ||
| 977 | } catch (IOException e) { | 1048 | } catch (IOException e) { |
| 978 | Debug.normal("Error %s", e.getMessage()); | 1049 | Debug.normal("Error %s", e.getMessage()); |
| 979 | } | 1050 | } |
| 980 | return jsonString; | 1051 | return jsonString; |
| 981 | } | 1052 | } |
| 982 | 1053 | ||
| 983 | @Override | 1054 | @Override |
| 984 | protected void onCancelled() { | 1055 | protected void onCancelled() { |
| 985 | super.onCancelled(); | 1056 | super.onCancelled(); |
| 986 | action.onError(null); | 1057 | action.onError(null); |
| 987 | } | 1058 | } |
| 988 | 1059 | ||
| 989 | @Override | 1060 | @Override |
| 990 | protected void onPostExecute(String jsonString) { | 1061 | protected void onPostExecute(String jsonString) { |
| 991 | super.onPostExecute(jsonString); | 1062 | super.onPostExecute(jsonString); |
| 992 | if ((jsonString == null) || (jsonString.isEmpty())) { | 1063 | if ((jsonString == null) || (jsonString.isEmpty())) { |
| 993 | action.onError(null); | 1064 | action.onError(null); |
| 994 | return; | 1065 | return; |
| 995 | } | 1066 | } |
| 996 | Debug.normal("String body: "+jsonString); | 1067 | Debug.normal("String body: "+jsonString); |
| 997 | 1068 | ||
| 998 | try { | 1069 | try { |
| 999 | JSONObject jsonObject = new JSONObject(jsonString); | 1070 | JSONObject jsonObject = new JSONObject(jsonString); |
| 1000 | int status = jsonObject.optInt("status"); | 1071 | int status = jsonObject.optInt("status"); |
| 1001 | if (status == 1) { | 1072 | if (status == 1) { |
| 1002 | JSONArray tokenArr = jsonObject.optJSONArray("result"); | 1073 | JSONArray tokenArr = jsonObject.optJSONArray("result"); |
| 1003 | String token = tokenArr.get(0).toString(); | 1074 | String token = tokenArr.get(0).toString(); |
| 1004 | Debug.normal("Refresh Token: "+ token); | 1075 | Debug.normal("Refresh Token: "+ token); |
| 1005 | // save data | 1076 | // save data |
| 1006 | Setting.setUserDataSharepre(context, Setting.TOKEN_SHAREPRE, token); | 1077 | Setting.setUserDataSharepre(context, Setting.TOKEN_SHAREPRE, token); |
| 1007 | APIResponse.getInstance().setToken(token); | 1078 | APIResponse.getInstance().setToken(token); |
| 1008 | action.onSuccess(jsonString); | 1079 | action.onSuccess(jsonString); |
| 1009 | } else { | 1080 | } else { |
| 1010 | action.onError(new Error(jsonObject.getString("message"))); | 1081 | action.onError(new Error(jsonObject.getString("message"))); |
| 1011 | } | 1082 | } |
| 1012 | } catch (JSONException e) { | 1083 | } catch (JSONException e) { |
| 1013 | action.onError(null); | 1084 | action.onError(null); |
| 1014 | } | 1085 | } |
| 1015 | } | 1086 | } |
| 1016 | }.execute(); | 1087 | } |
| 1088 | |||
| 1089 | public static class GetNews extends AsyncTask<Void, Void, String>{ | ||
| 1090 | private Date date; | ||
| 1091 | private LLAPIManagerListener action; | ||
| 1092 | |||
| 1093 | public GetNews(Date date, LLAPIManagerListener action) { | ||
| 1094 | this.date = date; | ||
| 1095 | this.action = action; | ||
| 1096 | } | ||
| 1097 | |||
| 1098 | @Override | ||
| 1099 | protected void onPreExecute() { | ||
| 1100 | super.onPreExecute(); | ||
| 1101 | } | ||
| 1102 | |||
| 1103 | @Override | ||
| 1104 | protected String doInBackground(Void... voids) { | ||
| 1105 | String fromStr = Utils.dateToStringFormatDayMonthYear(date); | ||
| 1106 | Debug.normal("Token: "+ APIResponse.getInstance().getToken()); | ||
| 1107 | HttpUrl baseUrl = HttpUrl.parse(URL_ROOT + URL_GET_NEWS_INFO + "/"+ fromStr); | ||
| 1108 | Debug.normal("URL: "+baseUrl.toString()); | ||
| 1109 | final Request.Builder request = new Request.Builder() | ||
| 1110 | .url(baseUrl) | ||
| 1111 | .header("User-Agent", Utils.getCustomUA()) | ||
| 1112 | .header("Content-Type", "application/json") | ||
| 1113 | .addHeader("token", APIResponse.getInstance().getToken()) | ||
| 1114 | .get(); | ||
| 1115 | |||
| 1116 | OkHttpClient httpClient = new OkHttpClient.Builder() | ||
| 1117 | .readTimeout(30, TimeUnit.SECONDS) | ||
| 1118 | .writeTimeout(30, TimeUnit.SECONDS) | ||
| 1119 | .connectTimeout(30, TimeUnit.SECONDS) | ||
| 1120 | .build(); | ||
| 1121 | |||
| 1122 | String jsonString = null; | ||
| 1123 | try { | ||
| 1124 | Response response = httpClient.newCall(request.build()).execute(); | ||
| 1125 | if (response == null) { | ||
| 1126 | action.onError(null); | ||
| 1127 | Debug.error("Response is null"); | ||
| 1128 | return null; | ||
| 1129 | } | ||
| 1130 | jsonString = getResponseData(response.body()); | ||
| 1131 | |||
| 1132 | } catch (IOException e) { | ||
| 1133 | Debug.normal("Error %s", e.getMessage()); | ||
| 1134 | } | ||
| 1135 | return jsonString; | ||
| 1136 | } | ||
| 1137 | |||
| 1138 | @Override | ||
| 1139 | protected void onCancelled() { | ||
| 1140 | super.onCancelled(); | ||
| 1141 | action.onError(null); | ||
| 1142 | } | ||
| 1143 | |||
| 1144 | @Override | ||
| 1145 | protected void onPostExecute(String jsonString) { | ||
| 1146 | super.onPostExecute(jsonString); | ||
| 1147 | if ((jsonString == null) || (jsonString.isEmpty())) { | ||
| 1148 | action.onError(null); | ||
| 1149 | return; | ||
| 1150 | } | ||
| 1151 | Debug.normal("String body: "+jsonString); | ||
| 1152 | |||
| 1153 | try { | ||
| 1154 | JSONObject jsonObject = new JSONObject(jsonString); | ||
| 1155 | int status = jsonObject.optInt("status"); | ||
| 1156 | if (status == 1) { | ||
| 1157 | // save data | ||
| 1158 | action.onSuccess(jsonString); | ||
| 1159 | } else { | ||
| 1160 | action.onError(new Error(jsonObject.getString("message"))); | ||
| 1161 | } | ||
| 1162 | } catch (JSONException e) { | ||
| 1163 | action.onError(null); | ||
| 1164 | } | ||
| 1165 | } | ||
| 1017 | } | 1166 | } |
| 1018 | 1167 | ||
| 1019 | public static Bitmap getBitmapFromAsset(Context context, String filePath) { | 1168 | public static Bitmap getBitmapFromAsset(Context context, String filePath) { |
| 1020 | AssetManager assetManager = context.getAssets(); | 1169 | AssetManager assetManager = context.getAssets(); |
| 1021 | InputStream istr; | 1170 | InputStream istr; |
| 1022 | Bitmap bitmap = null; | 1171 | Bitmap bitmap = null; |
| 1023 | try { | 1172 | try { |
| 1024 | istr = assetManager.open(filePath); | 1173 | istr = assetManager.open(filePath); |
| 1025 | bitmap = BitmapFactory.decodeStream(istr); | 1174 | bitmap = BitmapFactory.decodeStream(istr); |
| 1026 | } catch (IOException e) { | 1175 | } catch (IOException e) { |
| 1027 | Debug.normal("error: %s", e.getMessage()); | 1176 | Debug.normal("error: %s", e.getMessage()); |
| 1028 | } | 1177 | } |
| 1029 | return bitmap; | 1178 | return bitmap; |
| 1030 | } | 1179 | } |
| 1031 | 1180 |
app/src/main/res/layout/fragment_history_content.xml
| 1 | <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | 1 | <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" |
| 2 | xmlns:appNs="http://schemas.android.com/apk/res-auto" | 2 | xmlns:appNs="http://schemas.android.com/apk/res-auto" |
| 3 | android:layout_width="match_parent" | 3 | android:layout_width="match_parent" |
| 4 | android:layout_height="match_parent" | 4 | android:layout_height="match_parent" |
| 5 | android:background="@color/background_main"> | 5 | android:background="@color/background_main"> |
| 6 | 6 | ||
| 7 | <ScrollView | 7 | <ScrollView |
| 8 | android:layout_width="match_parent" | 8 | android:layout_width="match_parent" |
| 9 | android:layout_height="wrap_content" | 9 | android:layout_height="wrap_content" |
| 10 | android:layout_above="@+id/ll_stepType" | 10 | android:layout_above="@+id/ll_stepType" |
| 11 | android:layout_alignParentStart="true" | 11 | android:layout_alignParentStart="true" |
| 12 | android:layout_alignParentTop="true"> | 12 | android:layout_alignParentTop="true"> |
| 13 | 13 | ||
| 14 | 14 | ||
| 15 | <LinearLayout | 15 | <LinearLayout |
| 16 | android:layout_width="match_parent" | 16 | android:layout_width="match_parent" |
| 17 | android:layout_height="wrap_content" | 17 | android:layout_height="wrap_content" |
| 18 | android:orientation="vertical"> | 18 | android:orientation="vertical"> |
| 19 | 19 | ||
| 20 | <LinearLayout | 20 | <LinearLayout |
| 21 | android:id="@+id/layout_top" | 21 | android:id="@+id/layout_top" |
| 22 | android:layout_width="match_parent" | 22 | android:layout_width="match_parent" |
| 23 | android:layout_height="wrap_content" | 23 | android:layout_height="wrap_content" |
| 24 | android:orientation="vertical"> | 24 | android:orientation="vertical"> |
| 25 | 25 | ||
| 26 | <RelativeLayout | 26 | <RelativeLayout |
| 27 | android:id="@+id/layout_date_controll" | 27 | android:id="@+id/layout_date_controll" |
| 28 | android:layout_width="match_parent" | 28 | android:layout_width="match_parent" |
| 29 | android:layout_height="44dp" | 29 | android:layout_height="44dp" |
| 30 | android:layout_alignParentTop="true" | 30 | android:layout_alignParentTop="true" |
| 31 | android:gravity="center_vertical"> | 31 | android:gravity="center_vertical"> |
| 32 | 32 | ||
| 33 | <ImageButton | 33 | <ImageButton |
| 34 | android:id="@+id/btn_left_date" | 34 | android:id="@+id/btn_left_date" |
| 35 | android:layout_width="44dp" | 35 | android:layout_width="44dp" |
| 36 | android:layout_height="44dp" | 36 | android:layout_height="44dp" |
| 37 | android:layout_alignParentLeft="true" | 37 | android:layout_alignParentLeft="true" |
| 38 | android:layout_centerVertical="true" | 38 | android:layout_centerVertical="true" |
| 39 | android:layout_marginLeft="16dp" | 39 | android:layout_marginLeft="16dp" |
| 40 | android:background="@android:color/darker_gray" | 40 | android:background="@android:color/darker_gray" |
| 41 | android:padding="8dp" | 41 | android:padding="8dp" |
| 42 | android:scaleType="fitCenter" | 42 | android:scaleType="fitCenter" |
| 43 | android:src="@drawable/ic_left_arrow" /> | 43 | android:src="@drawable/ic_left_arrow" /> |
| 44 | 44 | ||
| 45 | <TextView | 45 | <TextView |
| 46 | android:id="@+id/tv_date" | 46 | android:id="@+id/tv_date" |
| 47 | android:layout_width="wrap_content" | 47 | android:layout_width="wrap_content" |
| 48 | android:layout_height="match_parent" | 48 | android:layout_height="match_parent" |
| 49 | android:layout_toRightOf="@+id/btn_left_date" | 49 | android:layout_toRightOf="@+id/btn_left_date" |
| 50 | android:background="@android:color/white" | 50 | android:background="@android:color/white" |
| 51 | android:gravity="center_vertical" | 51 | android:gravity="center_vertical" |
| 52 | android:padding="8dp" | 52 | android:padding="8dp" |
| 53 | android:text="2017年1月1日" | 53 | android:text="2017年1月1日" |
| 54 | android:textColor="@android:color/black" | 54 | android:textColor="@android:color/black" |
| 55 | android:textSize="18sp" /> | 55 | android:textSize="18sp" /> |
| 56 | 56 | ||
| 57 | <TextView | 57 | <TextView |
| 58 | android:id="@+id/tv_week_day" | 58 | android:id="@+id/tv_week_day" |
| 59 | android:layout_width="match_parent" | 59 | android:layout_width="match_parent" |
| 60 | android:layout_height="match_parent" | 60 | android:layout_height="match_parent" |
| 61 | android:layout_toLeftOf="@+id/btn_right_date" | 61 | android:layout_toLeftOf="@+id/btn_right_date" |
| 62 | android:layout_toRightOf="@+id/tv_date" | 62 | android:layout_toRightOf="@+id/tv_date" |
| 63 | android:background="@android:color/white" | 63 | android:background="@android:color/white" |
| 64 | android:gravity="center" | 64 | android:gravity="center" |
| 65 | android:text="日曜日" | 65 | android:text="日曜日" |
| 66 | android:textColor="@android:color/black" | 66 | android:textColor="@android:color/black" |
| 67 | android:textSize="18sp" /> | 67 | android:textSize="18sp" /> |
| 68 | 68 | ||
| 69 | <ImageButton | 69 | <ImageButton |
| 70 | android:id="@+id/btn_right_date" | 70 | android:id="@+id/btn_right_date" |
| 71 | android:layout_width="44dp" | 71 | android:layout_width="44dp" |
| 72 | android:layout_height="44dp" | 72 | android:layout_height="44dp" |
| 73 | android:layout_alignParentRight="true" | 73 | android:layout_alignParentRight="true" |
| 74 | android:layout_centerVertical="true" | 74 | android:layout_centerVertical="true" |
| 75 | android:layout_marginRight="16dp" | 75 | android:layout_marginRight="16dp" |
| 76 | android:background="@android:color/darker_gray" | 76 | android:background="@android:color/darker_gray" |
| 77 | android:padding="8dp" | 77 | android:padding="8dp" |
| 78 | android:scaleType="fitCenter" | 78 | android:scaleType="fitCenter" |
| 79 | android:src="@drawable/ic_right_arrow" /> | 79 | android:src="@drawable/ic_right_arrow" /> |
| 80 | </RelativeLayout> | 80 | </RelativeLayout> |
| 81 | 81 | ||
| 82 | <LinearLayout | 82 | <LinearLayout |
| 83 | android:layout_width="match_parent" | 83 | android:layout_width="match_parent" |
| 84 | android:layout_height="wrap_content" | 84 | android:layout_height="wrap_content" |
| 85 | android:layout_marginTop="20dp" | 85 | android:layout_marginTop="20dp" |
| 86 | android:orientation="horizontal" | 86 | android:orientation="horizontal" |
| 87 | android:weightSum="5"> | 87 | android:weightSum="5"> |
| 88 | 88 | ||
| 89 | <Button | 89 | <Button |
| 90 | android:id="@+id/btn_oneDay" | 90 | android:id="@+id/btn_oneDay" |
| 91 | style="@style/button_normal_style" | 91 | style="@style/button_normal_style" |
| 92 | android:layout_width="0dp" | 92 | android:layout_width="0dp" |
| 93 | android:layout_height="match_parent" | 93 | android:layout_height="match_parent" |
| 94 | android:layout_weight="1" | 94 | android:layout_weight="1" |
| 95 | android:background="@drawable/button_background" | 95 | android:background="@drawable/button_background" |
| 96 | android:text="@string/one_day" /> | 96 | android:text="@string/one_day" /> |
| 97 | 97 | ||
| 98 | <Button | 98 | <Button |
| 99 | android:id="@+id/btn_oneWeek" | 99 | android:id="@+id/btn_oneWeek" |
| 100 | style="@style/button_normal_style" | 100 | style="@style/button_normal_style" |
| 101 | android:layout_width="0dp" | 101 | android:layout_width="0dp" |
| 102 | android:layout_height="match_parent" | 102 | android:layout_height="match_parent" |
| 103 | android:layout_weight="1" | 103 | android:layout_weight="1" |
| 104 | android:background="@drawable/button_background" | 104 | android:background="@drawable/button_background" |
| 105 | android:text="@string/one_week" /> | 105 | android:text="@string/one_week" /> |
| 106 | 106 | ||
| 107 | <Button | 107 | <Button |
| 108 | android:id="@+id/btn_oneMonth" | 108 | android:id="@+id/btn_oneMonth" |
| 109 | style="@style/button_normal_style" | 109 | style="@style/button_normal_style" |
| 110 | android:layout_width="0dp" | 110 | android:layout_width="0dp" |
| 111 | android:layout_height="match_parent" | 111 | android:layout_height="match_parent" |
| 112 | android:layout_weight="1" | 112 | android:layout_weight="1" |
| 113 | android:background="@drawable/button_background" | 113 | android:background="@drawable/button_background" |
| 114 | android:text="@string/one_month" /> | 114 | android:text="@string/one_month" /> |
| 115 | 115 | ||
| 116 | <Button | 116 | <Button |
| 117 | android:id="@+id/btn_threeMonth" | 117 | android:id="@+id/btn_threeMonth" |
| 118 | style="@style/button_normal_style" | 118 | style="@style/button_normal_style" |
| 119 | android:layout_width="0dp" | 119 | android:layout_width="0dp" |
| 120 | android:layout_height="match_parent" | 120 | android:layout_height="match_parent" |
| 121 | android:layout_weight="1" | 121 | android:layout_weight="1" |
| 122 | android:background="@drawable/button_background" | 122 | android:background="@drawable/button_background" |
| 123 | android:text="@string/three_month" /> | 123 | android:text="@string/three_month" /> |
| 124 | 124 | ||
| 125 | <Button | 125 | <Button |
| 126 | android:id="@+id/btn_sixMonth" | 126 | android:id="@+id/btn_sixMonth" |
| 127 | style="@style/button_normal_style" | 127 | style="@style/button_normal_style" |
| 128 | android:layout_width="0dp" | 128 | android:layout_width="0dp" |
| 129 | android:layout_height="match_parent" | 129 | android:layout_height="match_parent" |
| 130 | android:layout_weight="1" | 130 | android:layout_weight="1" |
| 131 | android:background="@drawable/button_background" | 131 | android:background="@drawable/button_background" |
| 132 | android:text="@string/six_month" /> | 132 | android:text="@string/six_month" /> |
| 133 | 133 | ||
| 134 | </LinearLayout> | 134 | </LinearLayout> |
| 135 | </LinearLayout> | 135 | </LinearLayout> |
| 136 | 136 | ||
| 137 | <LinearLayout | 137 | <LinearLayout |
| 138 | android:id="@+id/rcv_rank" | 138 | android:id="@+id/rcv_rank" |
| 139 | android:layout_width="match_parent" | 139 | android:layout_width="match_parent" |
| 140 | android:layout_height="match_parent" | 140 | android:layout_height="match_parent" |
| 141 | android:layout_above="@+id/layout_bottom" | 141 | android:layout_above="@+id/layout_bottom" |
| 142 | android:layout_below="@+id/layout_top" | 142 | android:layout_below="@+id/layout_top" |
| 143 | android:orientation="vertical"> | 143 | android:orientation="vertical"> |
| 144 | 144 | ||
| 145 | <include layout="@layout/history_page_7_content"/> | 145 | <include layout="@layout/history_page_7_content"/> |
| 146 | 146 | ||
| 147 | <LinearLayout | 147 | <LinearLayout |
| 148 | android:layout_width="match_parent" | 148 | android:layout_width="match_parent" |
| 149 | android:layout_height="120dp" | 149 | android:layout_height="120dp" |
| 150 | android:orientation="vertical" | 150 | android:orientation="vertical" |
| 151 | android:layout_marginTop="10dp"> | 151 | android:layout_marginTop="10dp"> |
| 152 | 152 | ||
| 153 | <!--<org.eazegraph.lib.charts.BarChart--> | 153 | <!--<org.eazegraph.lib.charts.BarChart--> |
| 154 | <!--xmlns:eaze="http://schemas.android.com/apk/res-auto"--> | 154 | <!--xmlns:eaze="http://schemas.android.com/apk/res-auto"--> |
| 155 | <!--android:id="@+id/bargraph"--> | 155 | <!--android:id="@+id/bargraph"--> |
| 156 | <!--android:layout_width="match_parent"--> | 156 | <!--android:layout_width="match_parent"--> |
| 157 | <!--android:layout_height="120dp"--> | 157 | <!--android:layout_height="120dp"--> |
| 158 | <!--android:layout_below="@+id/averageandtotaltext"--> | 158 | <!--android:layout_below="@+id/averageandtotaltext"--> |
| 159 | <!--eaze:egLegendHeight="0dp"--> | 159 | <!--eaze:egLegendHeight="0dp"--> |
| 160 | <!--eaze:egShowValues="false" />--> | 160 | <!--eaze:egShowValues="false" />--> |
| 161 | <com.github.mikephil.charting.charts.BarChart | 161 | <com.github.mikephil.charting.charts.BarChart |
| 162 | android:id="@+id/chart" | 162 | android:id="@+id/chart" |
| 163 | android:layout_width="match_parent" | 163 | android:layout_width="match_parent" |
| 164 | android:layout_height="match_parent" /> | 164 | android:layout_height="match_parent" /> |
| 165 | 165 | ||
| 166 | 166 | ||
| 167 | </LinearLayout> | 167 | </LinearLayout> |
| 168 | 168 | ||
| 169 | 169 | ||
| 170 | </LinearLayout> | 170 | </LinearLayout> |
| 171 | 171 | ||
| 172 | <LinearLayout | 172 | <LinearLayout |
| 173 | android:id="@+id/layout_bottom" | 173 | android:id="@+id/layout_bottom" |
| 174 | android:layout_width="match_parent" | 174 | android:layout_width="match_parent" |
| 175 | android:layout_height="56dp" | 175 | android:layout_height="56dp" |
| 176 | android:orientation="horizontal" | 176 | android:orientation="horizontal" |
| 177 | android:weightSum="5"> | 177 | android:weightSum="5"> |
| 178 | 178 | ||
| 179 | <Button | 179 | <Button |
| 180 | android:id="@+id/btn_face" | 180 | android:id="@+id/btn_face" |
| 181 | style="@style/button_bot_page_7_style" | 181 | style="@style/button_bot_page_7_style" |
| 182 | android:layout_width="0dp" | 182 | android:layout_width="0dp" |
| 183 | android:layout_height="match_parent" | 183 | android:layout_height="match_parent" |
| 184 | android:layout_weight="1" | 184 | android:layout_weight="1" |
| 185 | android:background="@drawable/button_background" | 185 | android:background="@drawable/button_background" |
| 186 | android:lines="2" | 186 | android:lines="2" |
| 187 | android:layout_margin="2dp" | ||
| 187 | android:text="@string/facebook" /> | 188 | android:text="@string/facebook" /> |
| 188 | 189 | ||
| 189 | <Button | 190 | <Button |
| 190 | android:id="@+id/btn_twitter" | 191 | android:id="@+id/btn_twitter" |
| 191 | style="@style/button_bot_page_7_style" | 192 | style="@style/button_bot_page_7_style" |
| 192 | android:layout_width="0dp" | 193 | android:layout_width="0dp" |
| 193 | android:layout_height="match_parent" | 194 | android:layout_height="match_parent" |
| 194 | android:layout_weight="1" | 195 | android:layout_weight="1" |
| 195 | android:background="@drawable/button_background" | 196 | android:background="@drawable/button_background" |
| 196 | android:lines="2" | 197 | android:lines="2" |
| 198 | android:layout_margin="2dp" | ||
| 197 | android:text="@string/twitter" /> | 199 | android:text="@string/twitter" /> |
| 198 | 200 | ||
| 199 | <Button | 201 | <Button |
| 200 | android:id="@+id/btn_line" | 202 | android:id="@+id/btn_line" |
| 201 | style="@style/button_bot_page_7_style" | 203 | style="@style/button_bot_page_7_style" |
| 202 | android:layout_width="0dp" | 204 | android:layout_width="0dp" |
| 203 | android:layout_height="match_parent" | 205 | android:layout_height="match_parent" |
| 204 | android:layout_weight="1" | 206 | android:layout_weight="1" |
| 205 | android:background="@drawable/button_background" | 207 | android:background="@drawable/button_background" |
| 206 | android:lines="2" | 208 | android:lines="2" |
| 209 | android:layout_margin="2dp" | ||
| 207 | android:text="@string/line" /> | 210 | android:text="@string/line" /> |
| 208 | 211 | ||
| 209 | <Button | 212 | <Button |
| 210 | android:id="@+id/btn_email" | 213 | android:id="@+id/btn_email" |
| 211 | style="@style/button_bot_page_7_style" | 214 | style="@style/button_bot_page_7_style" |
| 212 | android:layout_width="0dp" | 215 | android:layout_width="0dp" |
| 213 | android:layout_height="match_parent" | 216 | android:layout_height="match_parent" |
| 214 | android:layout_weight="1" | 217 | android:layout_weight="1" |
| 215 | android:background="@drawable/button_background" | 218 | android:background="@drawable/button_background" |
| 216 | android:lines="2" | 219 | android:lines="2" |
| 220 | android:layout_margin="2dp" | ||
| 217 | android:text="@string/mail" /> | 221 | android:text="@string/mail" /> |
| 218 | 222 | ||
| 219 | <Button | 223 | <Button |
| 220 | android:id="@+id/btn_other" | 224 | android:id="@+id/btn_other" |
| 221 | style="@style/button_bot_page_7_style" | 225 | style="@style/button_bot_page_7_style" |
| 222 | android:layout_width="0dp" | 226 | android:layout_width="0dp" |
| 223 | android:layout_height="match_parent" | 227 | android:layout_height="match_parent" |
| 224 | android:layout_weight="1" | 228 | android:layout_weight="1" |
| 225 | android:background="@drawable/button_background" | 229 | android:background="@drawable/button_background" |
| 226 | android:lines="2" | 230 | android:lines="2" |
| 231 | android:layout_margin="2dp" | ||
| 227 | android:text="@string/other" /> | 232 | android:text="@string/other" /> |
| 228 | 233 | ||
| 229 | </LinearLayout> | 234 | </LinearLayout> |
| 230 | 235 | ||
| 231 | </LinearLayout> | 236 | </LinearLayout> |
| 232 | </ScrollView> | 237 | </ScrollView> |
| 233 | 238 | ||
| 234 | <include layout="@layout/type_step" /> | 239 | <include layout="@layout/type_step" /> |
| 235 | </RelativeLayout> | 240 | </RelativeLayout> |
| 236 | 241 |
build.gradle
| 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. | 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. |
| 2 | 2 | ||
| 3 | buildscript { | 3 | buildscript { |
| 4 | repositories { | 4 | repositories { |
| 5 | jcenter() | 5 | jcenter() |
| 6 | maven { | ||
| 7 | url 'https://maven.google.com/' | ||
| 8 | name 'Google' | ||
| 9 | } | ||
| 6 | } | 10 | } |
| 7 | dependencies { | 11 | dependencies { |
| 8 | classpath 'com.android.tools.build:gradle:2.3.3' | 12 | classpath 'com.android.tools.build:gradle:3.0.0' |
| 9 | 13 | ||
| 10 | // NOTE: Do not place your application dependencies here; they belong | 14 | // NOTE: Do not place your application dependencies here; they belong |
| 11 | // in the individual module build.gradle files | 15 | // in the individual module build.gradle files |
| 12 | } | 16 | } |
| 13 | } | 17 | } |
| 14 | 18 | ||
| 15 | allprojects { | 19 | allprojects { |
| 16 | repositories { | 20 | repositories { |
| 17 | jcenter() | 21 | jcenter() |
| 18 | maven { url "https://jitpack.io" } | 22 | maven { url "https://jitpack.io" } |
| 23 | maven { | ||
| 24 | url 'https://maven.google.com/' | ||
| 25 | name 'Google' | ||
| 26 | } | ||
| 19 | } | 27 | } |
| 20 | } | 28 | } |
| 21 | 29 | ||
| 22 | task clean(type: Delete) { | 30 | task clean(type: Delete) { |
| 23 | delete rootProject.buildDir | 31 | delete rootProject.buildDir |
| 24 | } | 32 | } |
| 25 | 33 |
gradle/wrapper/gradle-wrapper.properties
| 1 | #Thu Jul 27 00:11:14 ICT 2017 | 1 | #Thu Nov 16 22:05:25 ICT 2017 |
| 2 | distributionBase=GRADLE_USER_HOME | 2 | distributionBase=GRADLE_USER_HOME |
| 3 | distributionPath=wrapper/dists | 3 | distributionPath=wrapper/dists |
| 4 | zipStoreBase=GRADLE_USER_HOME | 4 | zipStoreBase=GRADLE_USER_HOME |
| 5 | zipStorePath=wrapper/dists | 5 | zipStorePath=wrapper/dists |
| 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip | 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip |
| 7 | 7 |