Commit 5520a4b27df178a212e405aeaad6b3bbda41cd3d

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

update

Showing 17 changed files with 401 additions and 88 deletions Side-by-side Diff

1 1 <?xml version="1.0" encoding="UTF-8"?>
2 2 <project version="4">
3   - <component name="EntryPointsManager">
4   - <entry_points version="2.0" />
5   - </component>
6 3 <component name="NullableNotNullManager">
7 4 <option name="myDefaultNullable" value="android.support.annotation.Nullable" />
8 5 <option name="myDefaultNotNull" value="android.support.annotation.NonNull" />
... ... @@ -27,17 +24,7 @@
27 24 </value>
28 25 </option>
29 26 </component>
30   - <component name="ProjectLevelVcsManager" settingsEditedManually="false">
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">
  27 + <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
41 28 <output url="file://$PROJECT_DIR$/build/classes" />
42 29 </component>
43 30 <component name="ProjectType">
... ... @@ -4,7 +4,7 @@
4 4 <modules>
5 5 <module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
6 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 8 </modules>
9 9 </component>
10 10 </project>
... ... @@ -2,7 +2,7 @@
2 2  
3 3 android {
4 4 compileSdkVersion 25
5   - buildToolsVersion "25.0.3"
  5 + buildToolsVersion '26.0.2'
6 6 defaultConfig {
7 7 applicationId "com.dinhcv.lifelogpedometer"
8 8 minSdkVersion 19
... ... @@ -13,6 +13,9 @@
13 13 // Enabling multidex support.
14 14 multiDexEnabled true
15 15 }
  16 +
  17 + flavorDimensions "default"
  18 +
16 19 buildTypes {
17 20 release {
18 21 minifyEnabled false
app/src/main/java/com/dinhcv/lifelogpedometer/activity/HistoryContentFragment.java
... ... @@ -17,6 +17,7 @@
17 17 import com.dinhcv.lifelogpedometer.R;
18 18 import com.dinhcv.lifelogpedometer.interfaces.LLAPIManagerListener;
19 19 import com.dinhcv.lifelogpedometer.model.structure.history.HistoryInfo;
  20 +import com.dinhcv.lifelogpedometer.portal.ApiServices;
20 21 import com.dinhcv.lifelogpedometer.portal.LLAPIManager;
21 22 import com.dinhcv.lifelogpedometer.utils.Const;
22 23 import com.dinhcv.lifelogpedometer.utils.DayAxisValueFormatter;
... ... @@ -228,7 +229,7 @@
228 229 Date fromDate = Utils.getFromDate(mAnaDate, dataType);
229 230  
230 231 showDialog(mContext);
231   - LLAPIManager.history(fromDate, toDate, new LLAPIManagerListener() {
  232 + ApiServices.history(fromDate, toDate, new LLAPIManagerListener() {
232 233 @Override
233 234 public void onError(Error error) {
234 235 Debug.error("Get data history error");
app/src/main/java/com/dinhcv/lifelogpedometer/activity/HistoryDetailFragment.java
... ... @@ -20,6 +20,7 @@
20 20 import com.dinhcv.lifelogpedometer.interfaces.LLAPIManagerListener;
21 21 import com.dinhcv.lifelogpedometer.model.structure.history.HistoryInfo;
22 22 import com.dinhcv.lifelogpedometer.model.structure.history.HistoryItemInfo;
  23 +import com.dinhcv.lifelogpedometer.portal.ApiServices;
23 24 import com.dinhcv.lifelogpedometer.portal.LLAPIManager;
24 25 import com.dinhcv.lifelogpedometer.utils.Const;
25 26 import com.dinhcv.lifelogpedometer.utils.Debug;
... ... @@ -200,7 +201,7 @@
200 201 Date fromDate = Utils.getFromDate(mAnaDate, dataType);
201 202  
202 203 showDialog(mContext);
203   - LLAPIManager.historyDetail(fromDate, toDate, new LLAPIManagerListener() {
  204 + ApiServices.historyDetail(fromDate, toDate, new LLAPIManagerListener() {
204 205 @Override
205 206 public void onError(Error error) {
206 207 Debug.error("Get data history error");
app/src/main/java/com/dinhcv/lifelogpedometer/activity/InputConfirmCodeActivity.java
... ... @@ -13,6 +13,7 @@
13 13 import com.dinhcv.lifelogpedometer.R;
14 14 import com.dinhcv.lifelogpedometer.interfaces.LLAPIManagerListener;
15 15 import com.dinhcv.lifelogpedometer.model.Shareprefer.Setting;
  16 +import com.dinhcv.lifelogpedometer.portal.ApiServices;
16 17 import com.dinhcv.lifelogpedometer.portal.LLAPIManager;
17 18 import com.dinhcv.lifelogpedometer.utils.Const;
18 19 import com.dinhcv.lifelogpedometer.utils.Debug;
... ... @@ -60,7 +61,7 @@
60 61 progressDialog.setCancelable(false);
61 62 progressDialog.show();
62 63  
63   - LLAPIManager.forgetPassConfirm(mEmail, code, new LLAPIManagerListener() {
  64 + ApiServices.forgetPassConfirm(mEmail, code, new LLAPIManagerListener() {
64 65 @Override
65 66 public void onError(Error error) {
66 67 progressDialog.dismiss();
app/src/main/java/com/dinhcv/lifelogpedometer/activity/LoginActivity.java
... ... @@ -13,6 +13,7 @@
13 13 import com.dinhcv.lifelogpedometer.R;
14 14 import com.dinhcv.lifelogpedometer.interfaces.LLAPIManagerListener;
15 15 import com.dinhcv.lifelogpedometer.model.Shareprefer.Setting;
  16 +import com.dinhcv.lifelogpedometer.portal.ApiServices;
16 17 import com.dinhcv.lifelogpedometer.portal.LLAPIManager;
17 18 import com.dinhcv.lifelogpedometer.utils.Const;
18 19 import com.dinhcv.lifelogpedometer.utils.Debug;
... ... @@ -84,7 +85,7 @@
84 85 progressDialog.setCancelable(false);
85 86 progressDialog.show();
86 87  
87   - LLAPIManager.login(LoginActivity.this, user, pass, new LLAPIManagerListener() {
  88 + ApiServices.login(LoginActivity.this, user, pass, new LLAPIManagerListener() {
88 89 @Override
89 90 public void onError(Error error) {
90 91 progressDialog.dismiss();
... ... @@ -130,7 +131,7 @@
130 131 progressDialog.setCancelable(false);
131 132 progressDialog.show();
132 133  
133   - LLAPIManager.forgetPass(email, new LLAPIManagerListener() {
  134 + ApiServices.forgetPass(email, new LLAPIManagerListener() {
134 135 @Override
135 136 public void onError(Error error) {
136 137 progressDialog.dismiss();
app/src/main/java/com/dinhcv/lifelogpedometer/activity/RegisterActivity.java
... ... @@ -26,6 +26,7 @@
26 26 import com.dinhcv.lifelogpedometer.model.Shareprefer.Setting;
27 27 import com.dinhcv.lifelogpedometer.model.structure.RegisterInfo;
28 28 import com.dinhcv.lifelogpedometer.model.structure.SelectItemInfo;
  29 +import com.dinhcv.lifelogpedometer.portal.ApiServices;
29 30 import com.dinhcv.lifelogpedometer.portal.LLAPIManager;
30 31 import com.dinhcv.lifelogpedometer.utils.Debug;
31 32 import com.dinhcv.lifelogpedometer.utils.Utils;
... ... @@ -261,7 +262,7 @@
261 262 progressDialog.setCancelable(false);
262 263 progressDialog.show();
263 264  
264   - LLAPIManager.register(mRegisterInfo, new LLAPIManagerListener() {
  265 + ApiServices.register(mRegisterInfo, new LLAPIManagerListener() {
265 266 @Override
266 267 public void onError(Error error) {
267 268 progressDialog.dismiss();
... ... @@ -310,7 +311,7 @@
310 311 progressDialog.setCancelable(false);
311 312 progressDialog.show();
312 313  
313   - LLAPIManager.uploadImage(bitmap, new LLAPIManagerListener() {
  314 + ApiServices.uploadImage(bitmap, new LLAPIManagerListener() {
314 315 @Override
315 316 public void onError(Error error) {
316 317 progressDialog.dismiss();
app/src/main/java/com/dinhcv/lifelogpedometer/activity/TopDateFragment.java
... ... @@ -19,6 +19,7 @@
19 19 import com.dinhcv.lifelogpedometer.interfaces.LLAPIManagerListener;
20 20 import com.dinhcv.lifelogpedometer.model.structure.home.NoticeInfo;
21 21 import com.dinhcv.lifelogpedometer.model.structure.home.TagetInfo;
  22 +import com.dinhcv.lifelogpedometer.portal.ApiServices;
22 23 import com.dinhcv.lifelogpedometer.portal.LLAPIManager;
23 24 import com.dinhcv.lifelogpedometer.utils.Const;
24 25 import com.dinhcv.lifelogpedometer.utils.Debug;
... ... @@ -114,6 +115,7 @@
114 115 tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(date));
115 116 mAnaDate = date;
116 117 getHomePage(mAnaDate, stepType);
  118 + getNews(mAnaDate);
117 119 }
118 120 });
119 121  
... ... @@ -127,6 +129,7 @@
127 129 tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(date));
128 130 mAnaDate = date;
129 131 getHomePage(mAnaDate, stepType);
  132 + getNews(mAnaDate);
130 133 }
131 134 });
132 135  
... ... @@ -195,6 +198,7 @@
195 198 mAnaDate = date;
196 199  
197 200 getHomePage(mAnaDate, stepType);
  201 + getNews(mAnaDate);
198 202 }
199 203 }, mAnaYear, mAnaMonth, mAnaDay).show();
200 204  
201 205  
... ... @@ -217,13 +221,14 @@
217 221 stepType = Const.STEP_TYPE.WALKING;
218 222 updateUiStepType(false, true, false);
219 223 getHomePage(mAnaDate, stepType);
  224 + getNews(mAnaDate);
220 225 }
221 226  
222 227  
223 228 private void getHomePage(Date date, Const.STEP_TYPE stepType){
224 229  
225 230 showDialog(mContext);
226   - LLAPIManager.homePage(date, stepType, new LLAPIManagerListener() {
  231 + ApiServices.homePage(date, stepType, new LLAPIManagerListener() {
227 232 @Override
228 233 public void onError(Error error) {
229 234 Debug.error("Get data history error");
230 235  
231 236  
232 237  
233 238  
... ... @@ -296,17 +301,70 @@
296 301 tvStep.setText(String.valueOf(mTagetInfo.getSteps()));
297 302 tvRemain.setText(String.valueOf(mTagetInfo.getStepRemain()));
298 303 tvRateDone.setText(mContext.getResources().getString(R.string.percent_unit, mTagetInfo.getCompletePercent()));
  304 + }
299 305  
300   - List<NoticeInfo> infoLists = mTagetInfo.getNoticeList();
301   - if (infoLists != null && infoLists.size() >0){
302   - mNoticeAdapter = new NoticeAdapter(mContext, infoLists);
  306 + private void getNews(Date date){
  307 +
  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 359 lvNotice.setAdapter(mNoticeAdapter);
304 360 lvNotice.setExpanded(true);
  361 + }else {
  362 + lvNotice.setAdapter(null);
305 363 }
306   -
307 364 }
308 365  
309 366  
  367 +
310 368 @Override
311 369 public void onAttach(Context context) {
312 370 super.onAttach(context);
... ... @@ -337,6 +395,8 @@
337 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
... ... @@ -26,6 +26,7 @@
26 26 import com.dinhcv.lifelogpedometer.model.StepModel;
27 27 import com.dinhcv.lifelogpedometer.model.structure.top.StepItemInfo;
28 28 import com.dinhcv.lifelogpedometer.model.structure.top.TopInfo;
  29 +import com.dinhcv.lifelogpedometer.portal.ApiServices;
29 30 import com.dinhcv.lifelogpedometer.portal.LLAPIManager;
30 31 import com.dinhcv.lifelogpedometer.utils.Const;
31 32 import com.dinhcv.lifelogpedometer.utils.DayAxisValueFormatter;
32 33  
... ... @@ -135,8 +136,11 @@
135 136 // slice for the "missing" steps until reaching the goal
136 137 sliceGoal = new PieModel("", Const.STEP_GOAL, Color.parseColor("#B7B8B6"));
137 138 pg.addPieSlice(sliceGoal);
  139 +
138 140 pg.setDrawValueInPie(false);
139 141 pg.setUsePieRotation(false);
  142 + pg.setInnerPadding(93);
  143 + pg.setInnerPaddingColor(R.color.background_main);
140 144 pg.startAnimation();
141 145 pg.setAutoCenterInSlice(false);
142 146  
... ... @@ -222,7 +226,7 @@
222 226 progress.setMessage(getString(R.string.loading));
223 227 progress.setCancelable(false);
224 228 progress.show();
225   - LLAPIManager.topInfo(date, stepType, new LLAPIManagerListener() {
  229 + ApiServices.topInfo(date, stepType, new LLAPIManagerListener() {
226 230 @Override
227 231 public void onError(Error error) {
228 232 Debug.error("Get data history error");
229 233  
230 234  
... ... @@ -587,10 +591,13 @@
587 591 public void onResume() {
588 592 super.onResume();
589 593 activityRunning = true;
  594 + Debug.normal("Today: "+ "Onresume ");
590 595 Sensor countSensor = sensorManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER);
591 596 if (countSensor != null) {
  597 + Debug.normal("Today: "+ "countSensor not null ");
592 598 sensorManager.registerListener(this, countSensor, SensorManager.SENSOR_DELAY_UI);
593 599 } else {
  600 + Debug.normal("Today: "+ "countSensor is null ");
594 601 Toast.makeText(mContext, getResources().getString(R.string.sensor_available), Toast.LENGTH_SHORT).show();
595 602 }
596 603 }
597 604  
... ... @@ -631,8 +638,9 @@
631 638 }
632 639  
633 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 644 @Override
637 645 public void onError(Error error) {
638 646 Debug.error("Get data history error");
... ... @@ -649,6 +657,8 @@
649 657 }
650 658 });
651 659 }
  660 +
  661 +
652 662  
653 663 }
app/src/main/java/com/dinhcv/lifelogpedometer/activity/WelcomeActivity.java
... ... @@ -11,6 +11,7 @@
11 11 import com.dinhcv.lifelogpedometer.R;
12 12 import com.dinhcv.lifelogpedometer.interfaces.LLAPIManagerListener;
13 13 import com.dinhcv.lifelogpedometer.model.Shareprefer.Setting;
  14 +import com.dinhcv.lifelogpedometer.portal.ApiServices;
14 15 import com.dinhcv.lifelogpedometer.portal.LLAPIManager;
15 16 import com.dinhcv.lifelogpedometer.utils.Debug;
16 17  
... ... @@ -40,7 +41,7 @@
40 41  
41 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 45 @Override
45 46 public void onError(Error error) {
46 47 Debug.error("Version JSON result: ERROR " + error);
app/src/main/java/com/dinhcv/lifelogpedometer/model/structure/home/NoticeInfo.java
... ... @@ -4,6 +4,15 @@
4 4 private int id;
5 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 16 public int getId() {
8 17 return id;
9 18 }
app/src/main/java/com/dinhcv/lifelogpedometer/portal/ApiServices.java
  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 +}
app/src/main/java/com/dinhcv/lifelogpedometer/portal/LLAPIManager.java
... ... @@ -23,16 +23,9 @@
23 23 import java.io.ByteArrayOutputStream;
24 24 import java.io.IOException;
25 25 import java.io.InputStream;
26   -import java.util.ArrayList;
27   -import java.util.Arrays;
28 26 import java.util.Date;
29   -import java.util.HashMap;
30   -import java.util.List;
31   -import java.util.UUID;
32 27 import java.util.concurrent.TimeUnit;
33 28  
34   -import okhttp3.Call;
35   -import okhttp3.Callback;
36 29 import okhttp3.HttpUrl;
37 30 import okhttp3.MediaType;
38 31 import okhttp3.OkHttpClient;
39 32  
40 33  
41 34  
42 35  
43 36  
44 37  
45 38  
46 39  
47 40  
48 41  
49 42  
50 43  
51 44  
... ... @@ -42,36 +35,48 @@
42 35 import okhttp3.ResponseBody;
43 36  
44 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 39 //login info
47   - public static String URL_LOGIN_INFO = "login";
  40 + private static String URL_LOGIN_INFO = "login";
48 41 //register info
49   - public static String URL_REGISTER_INFO = "register";
  42 + private static String URL_REGISTER_INFO = "register";
50 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 45 //Search zipcode
53   - public static String URL_FORGET_PASS_INFO = "forgetPass";
  46 + private static String URL_FORGET_PASS_INFO = "forgetPass";
54 47 //history
55   - public static String URL_HISTORE_INFO = "api/history";
  48 + private static String URL_HISTORE_INFO = "api/history";
56 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 51 // home
59   - public static String URL_HOME_INFO = "api/home";
  52 + private static String URL_HOME_INFO = "api/home";
60 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 55 // Refesh Token
63   - public static String URL_REFESH_TOKEN_INFO = "refreshToken";
  56 + private static String URL_REFESH_TOKEN_INFO = "refreshToken";
64 57 // Top info
65   - public static String URL_TOP_INFO = "api/top";
  58 + private static String URL_TOP_INFO = "api/top";
66 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 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) {
74   - new AsyncTask<Void, Void, String>() {
  67 + public static class Login extends 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 80 @Override
76 81 protected void onPreExecute() {
77 82 super.onPreExecute();
78 83  
... ... @@ -159,11 +164,17 @@
159 164 e.printStackTrace();
160 165 }
161 166 }
162   - }.execute();
163 167 }
164 168  
165   - public static void uploadImage(final Bitmap bitmap, final LLAPIManagerListener action) {
166   - new AsyncTask<Void, Void, String>() {
  169 + public static class UploadImage extends 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 178 @Override
168 179 protected void onPreExecute() {
169 180 super.onPreExecute();
170 181  
... ... @@ -249,11 +260,17 @@
249 260 e.printStackTrace();
250 261 }
251 262 }
252   - }.execute();
253 263 }
254 264  
255   - public static void register(final RegisterInfo registerInfo, final LLAPIManagerListener action) {
256   - new AsyncTask<Void, Void, String>() {
  265 + public static class Register extends 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 274 @Override
258 275 protected void onPreExecute() {
259 276 super.onPreExecute();
... ... @@ -356,7 +373,6 @@
356 373 }
357 374  
358 375 }
359   - }.execute();
360 376 }
361 377  
362 378 private static byte[] convertBitmapToByteArray(Bitmap bitmap) {
363 379  
... ... @@ -366,9 +382,14 @@
366 382 return byteArray;
367 383 }
368 384  
369   - public static void forgetPass(final String email, final LLAPIManagerListener action) {
370   - new AsyncTask<Void, Void, String>() {
  385 + public static class ForgetPass extends 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 394 @Override
374 395 protected void onPreExecute() {
375 396  
376 397  
... ... @@ -447,12 +468,19 @@
447 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) {
454   - new AsyncTask<Void, Void, String>() {
  474 + public static class ForgetPassConfirm extends 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 485 @Override
458 486 protected void onPreExecute() {
459 487  
460 488  
... ... @@ -531,12 +559,18 @@
531 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) {
538   - new AsyncTask<Void, Void, String>() {
  564 + public static class History extends 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 575 @Override
542 576 protected void onPreExecute() {
543 577  
544 578  
... ... @@ -607,12 +641,18 @@
607 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) {
614   - new AsyncTask<Void, Void, String>() {
  646 + public static class HistoryDetail extends 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 657 @Override
618 658 protected void onPreExecute() {
619 659  
620 660  
... ... @@ -683,12 +723,19 @@
683 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) {
690   - new AsyncTask<Void, Void, String>() {
  729 + public static class HomePage extends 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 740 @Override
694 741 protected void onPreExecute() {
695 742  
696 743  
... ... @@ -758,12 +805,19 @@
758 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) {
765   - new AsyncTask<Void, Void, String>() {
  811 + public static class TopInfo extends 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 822 @Override
769 823 protected void onPreExecute() {
770 824  
771 825  
772 826  
... ... @@ -833,14 +887,25 @@
833 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,
840   - final Date endTime, final LLAPIManagerListener action) {
841   - new AsyncTask<Void, Void, String>() {
  893 + public static class CreateLog extends AsyncTask<Void, Void, String>{
  894 + private int stepCount;
  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 909 @Override
845 910 protected void onPreExecute() {
846 911 super.onPreExecute();
847 912  
848 913  
... ... @@ -923,12 +988,18 @@
923 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) {
930   - new AsyncTask<Void, Void, String>() {
  993 + public static class RefreshToken extends 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 1004 @Override
934 1005 protected void onPreExecute() {
... ... @@ -1013,7 +1084,85 @@
1013 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 1168 public static Bitmap getBitmapFromAsset(Context context, String filePath) {
app/src/main/res/layout/fragment_history_content.xml
... ... @@ -184,6 +184,7 @@
184 184 android:layout_weight="1"
185 185 android:background="@drawable/button_background"
186 186 android:lines="2"
  187 + android:layout_margin="2dp"
187 188 android:text="@string/facebook" />
188 189  
189 190 <Button
... ... @@ -194,6 +195,7 @@
194 195 android:layout_weight="1"
195 196 android:background="@drawable/button_background"
196 197 android:lines="2"
  198 + android:layout_margin="2dp"
197 199 android:text="@string/twitter" />
198 200  
199 201 <Button
... ... @@ -204,6 +206,7 @@
204 206 android:layout_weight="1"
205 207 android:background="@drawable/button_background"
206 208 android:lines="2"
  209 + android:layout_margin="2dp"
207 210 android:text="@string/line" />
208 211  
209 212 <Button
... ... @@ -214,6 +217,7 @@
214 217 android:layout_weight="1"
215 218 android:background="@drawable/button_background"
216 219 android:lines="2"
  220 + android:layout_margin="2dp"
217 221 android:text="@string/mail" />
218 222  
219 223 <Button
... ... @@ -224,6 +228,7 @@
224 228 android:layout_weight="1"
225 229 android:background="@drawable/button_background"
226 230 android:lines="2"
  231 + android:layout_margin="2dp"
227 232 android:text="@string/other" />
228 233  
229 234 </LinearLayout>
... ... @@ -3,9 +3,13 @@
3 3 buildscript {
4 4 repositories {
5 5 jcenter()
  6 + maven {
  7 + url 'https://maven.google.com/'
  8 + name 'Google'
  9 + }
6 10 }
7 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 14 // NOTE: Do not place your application dependencies here; they belong
11 15 // in the individual module build.gradle files
... ... @@ -16,6 +20,10 @@
16 20 repositories {
17 21 jcenter()
18 22 maven { url "https://jitpack.io" }
  23 + maven {
  24 + url 'https://maven.google.com/'
  25 + name 'Google'
  26 + }
19 27 }
20 28 }
21 29  
gradle/wrapper/gradle-wrapper.properties
1   -#Thu Jul 27 00:11:14 ICT 2017
  1 +#Thu Nov 16 22:05:25 ICT 2017
2 2 distributionBase=GRADLE_USER_HOME
3 3 distributionPath=wrapper/dists
4 4 zipStoreBase=GRADLE_USER_HOME
5 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