diff --git a/.idea/misc.xml b/.idea/misc.xml
index 5d19981..ba7052b 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -1,8 +1,5 @@
-
-
-
@@ -27,17 +24,7 @@
-
-
-
-
-
-
-
-
-
-
-
+
diff --git a/.idea/modules.xml b/.idea/modules.xml
index a6e86a8..d71fbf4 100644
--- a/.idea/modules.xml
+++ b/.idea/modules.xml
@@ -4,7 +4,7 @@
-
+
\ No newline at end of file
diff --git a/app/build.gradle b/app/build.gradle
index 2f03cb9..e40219c 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -2,7 +2,7 @@ apply plugin: 'com.android.application'
android {
compileSdkVersion 25
- buildToolsVersion "25.0.3"
+ buildToolsVersion '26.0.2'
defaultConfig {
applicationId "com.dinhcv.lifelogpedometer"
minSdkVersion 19
@@ -13,6 +13,9 @@ android {
// Enabling multidex support.
multiDexEnabled true
}
+
+ flavorDimensions "default"
+
buildTypes {
release {
minifyEnabled false
diff --git a/app/src/main/java/com/dinhcv/lifelogpedometer/activity/HistoryContentFragment.java b/app/src/main/java/com/dinhcv/lifelogpedometer/activity/HistoryContentFragment.java
index dbcfa30..77e887f 100644
--- a/app/src/main/java/com/dinhcv/lifelogpedometer/activity/HistoryContentFragment.java
+++ b/app/src/main/java/com/dinhcv/lifelogpedometer/activity/HistoryContentFragment.java
@@ -17,6 +17,7 @@ import android.widget.TextView;
import com.dinhcv.lifelogpedometer.R;
import com.dinhcv.lifelogpedometer.interfaces.LLAPIManagerListener;
import com.dinhcv.lifelogpedometer.model.structure.history.HistoryInfo;
+import com.dinhcv.lifelogpedometer.portal.ApiServices;
import com.dinhcv.lifelogpedometer.portal.LLAPIManager;
import com.dinhcv.lifelogpedometer.utils.Const;
import com.dinhcv.lifelogpedometer.utils.DayAxisValueFormatter;
@@ -228,7 +229,7 @@ public class HistoryContentFragment extends FragmentBase {
Date fromDate = Utils.getFromDate(mAnaDate, dataType);
showDialog(mContext);
- LLAPIManager.history(fromDate, toDate, new LLAPIManagerListener() {
+ ApiServices.history(fromDate, toDate, new LLAPIManagerListener() {
@Override
public void onError(Error error) {
Debug.error("Get data history error");
diff --git a/app/src/main/java/com/dinhcv/lifelogpedometer/activity/HistoryDetailFragment.java b/app/src/main/java/com/dinhcv/lifelogpedometer/activity/HistoryDetailFragment.java
index f920529..31f10ad 100644
--- a/app/src/main/java/com/dinhcv/lifelogpedometer/activity/HistoryDetailFragment.java
+++ b/app/src/main/java/com/dinhcv/lifelogpedometer/activity/HistoryDetailFragment.java
@@ -20,6 +20,7 @@ import com.dinhcv.lifelogpedometer.customview.ExpandableListCustomView;
import com.dinhcv.lifelogpedometer.interfaces.LLAPIManagerListener;
import com.dinhcv.lifelogpedometer.model.structure.history.HistoryInfo;
import com.dinhcv.lifelogpedometer.model.structure.history.HistoryItemInfo;
+import com.dinhcv.lifelogpedometer.portal.ApiServices;
import com.dinhcv.lifelogpedometer.portal.LLAPIManager;
import com.dinhcv.lifelogpedometer.utils.Const;
import com.dinhcv.lifelogpedometer.utils.Debug;
@@ -200,7 +201,7 @@ public class HistoryDetailFragment extends FragmentBase {
Date fromDate = Utils.getFromDate(mAnaDate, dataType);
showDialog(mContext);
- LLAPIManager.historyDetail(fromDate, toDate, new LLAPIManagerListener() {
+ ApiServices.historyDetail(fromDate, toDate, new LLAPIManagerListener() {
@Override
public void onError(Error error) {
Debug.error("Get data history error");
diff --git a/app/src/main/java/com/dinhcv/lifelogpedometer/activity/InputConfirmCodeActivity.java b/app/src/main/java/com/dinhcv/lifelogpedometer/activity/InputConfirmCodeActivity.java
index f8d0642..a0add76 100644
--- a/app/src/main/java/com/dinhcv/lifelogpedometer/activity/InputConfirmCodeActivity.java
+++ b/app/src/main/java/com/dinhcv/lifelogpedometer/activity/InputConfirmCodeActivity.java
@@ -13,6 +13,7 @@ import android.widget.TextView;
import com.dinhcv.lifelogpedometer.R;
import com.dinhcv.lifelogpedometer.interfaces.LLAPIManagerListener;
import com.dinhcv.lifelogpedometer.model.Shareprefer.Setting;
+import com.dinhcv.lifelogpedometer.portal.ApiServices;
import com.dinhcv.lifelogpedometer.portal.LLAPIManager;
import com.dinhcv.lifelogpedometer.utils.Const;
import com.dinhcv.lifelogpedometer.utils.Debug;
@@ -60,7 +61,7 @@ public class InputConfirmCodeActivity extends ActivityBase {
progressDialog.setCancelable(false);
progressDialog.show();
- LLAPIManager.forgetPassConfirm(mEmail, code, new LLAPIManagerListener() {
+ ApiServices.forgetPassConfirm(mEmail, code, new LLAPIManagerListener() {
@Override
public void onError(Error error) {
progressDialog.dismiss();
diff --git a/app/src/main/java/com/dinhcv/lifelogpedometer/activity/LoginActivity.java b/app/src/main/java/com/dinhcv/lifelogpedometer/activity/LoginActivity.java
index 98adad4..4397fee 100644
--- a/app/src/main/java/com/dinhcv/lifelogpedometer/activity/LoginActivity.java
+++ b/app/src/main/java/com/dinhcv/lifelogpedometer/activity/LoginActivity.java
@@ -13,6 +13,7 @@ import android.widget.TextView;
import com.dinhcv.lifelogpedometer.R;
import com.dinhcv.lifelogpedometer.interfaces.LLAPIManagerListener;
import com.dinhcv.lifelogpedometer.model.Shareprefer.Setting;
+import com.dinhcv.lifelogpedometer.portal.ApiServices;
import com.dinhcv.lifelogpedometer.portal.LLAPIManager;
import com.dinhcv.lifelogpedometer.utils.Const;
import com.dinhcv.lifelogpedometer.utils.Debug;
@@ -84,7 +85,7 @@ public class LoginActivity extends ActivityBase {
progressDialog.setCancelable(false);
progressDialog.show();
- LLAPIManager.login(LoginActivity.this, user, pass, new LLAPIManagerListener() {
+ ApiServices.login(LoginActivity.this, user, pass, new LLAPIManagerListener() {
@Override
public void onError(Error error) {
progressDialog.dismiss();
@@ -130,7 +131,7 @@ public class LoginActivity extends ActivityBase {
progressDialog.setCancelable(false);
progressDialog.show();
- LLAPIManager.forgetPass(email, new LLAPIManagerListener() {
+ ApiServices.forgetPass(email, new LLAPIManagerListener() {
@Override
public void onError(Error error) {
progressDialog.dismiss();
diff --git a/app/src/main/java/com/dinhcv/lifelogpedometer/activity/RegisterActivity.java b/app/src/main/java/com/dinhcv/lifelogpedometer/activity/RegisterActivity.java
index 0280b13..295857b 100644
--- a/app/src/main/java/com/dinhcv/lifelogpedometer/activity/RegisterActivity.java
+++ b/app/src/main/java/com/dinhcv/lifelogpedometer/activity/RegisterActivity.java
@@ -26,6 +26,7 @@ import com.dinhcv.lifelogpedometer.interfaces.OnSelectResultListener;
import com.dinhcv.lifelogpedometer.model.Shareprefer.Setting;
import com.dinhcv.lifelogpedometer.model.structure.RegisterInfo;
import com.dinhcv.lifelogpedometer.model.structure.SelectItemInfo;
+import com.dinhcv.lifelogpedometer.portal.ApiServices;
import com.dinhcv.lifelogpedometer.portal.LLAPIManager;
import com.dinhcv.lifelogpedometer.utils.Debug;
import com.dinhcv.lifelogpedometer.utils.Utils;
@@ -261,7 +262,7 @@ public class RegisterActivity extends ActivityBase {
progressDialog.setCancelable(false);
progressDialog.show();
- LLAPIManager.register(mRegisterInfo, new LLAPIManagerListener() {
+ ApiServices.register(mRegisterInfo, new LLAPIManagerListener() {
@Override
public void onError(Error error) {
progressDialog.dismiss();
@@ -310,7 +311,7 @@ public class RegisterActivity extends ActivityBase {
progressDialog.setCancelable(false);
progressDialog.show();
- LLAPIManager.uploadImage(bitmap, new LLAPIManagerListener() {
+ ApiServices.uploadImage(bitmap, new LLAPIManagerListener() {
@Override
public void onError(Error error) {
progressDialog.dismiss();
diff --git a/app/src/main/java/com/dinhcv/lifelogpedometer/activity/TopDateFragment.java b/app/src/main/java/com/dinhcv/lifelogpedometer/activity/TopDateFragment.java
index 8d83e30..88c6d90 100644
--- a/app/src/main/java/com/dinhcv/lifelogpedometer/activity/TopDateFragment.java
+++ b/app/src/main/java/com/dinhcv/lifelogpedometer/activity/TopDateFragment.java
@@ -19,6 +19,7 @@ import com.dinhcv.lifelogpedometer.customview.ExpandableListCustomView;
import com.dinhcv.lifelogpedometer.interfaces.LLAPIManagerListener;
import com.dinhcv.lifelogpedometer.model.structure.home.NoticeInfo;
import com.dinhcv.lifelogpedometer.model.structure.home.TagetInfo;
+import com.dinhcv.lifelogpedometer.portal.ApiServices;
import com.dinhcv.lifelogpedometer.portal.LLAPIManager;
import com.dinhcv.lifelogpedometer.utils.Const;
import com.dinhcv.lifelogpedometer.utils.Debug;
@@ -114,6 +115,7 @@ public class TopDateFragment extends FragmentBase implements SettingFragmentPres
tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(date));
mAnaDate = date;
getHomePage(mAnaDate, stepType);
+ getNews(mAnaDate);
}
});
@@ -127,6 +129,7 @@ public class TopDateFragment extends FragmentBase implements SettingFragmentPres
tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(date));
mAnaDate = date;
getHomePage(mAnaDate, stepType);
+ getNews(mAnaDate);
}
});
@@ -195,6 +198,7 @@ public class TopDateFragment extends FragmentBase implements SettingFragmentPres
mAnaDate = date;
getHomePage(mAnaDate, stepType);
+ getNews(mAnaDate);
}
}, mAnaYear, mAnaMonth, mAnaDay).show();
@@ -217,13 +221,14 @@ public class TopDateFragment extends FragmentBase implements SettingFragmentPres
stepType = Const.STEP_TYPE.WALKING;
updateUiStepType(false, true, false);
getHomePage(mAnaDate, stepType);
+ getNews(mAnaDate);
}
private void getHomePage(Date date, Const.STEP_TYPE stepType){
showDialog(mContext);
- LLAPIManager.homePage(date, stepType, new LLAPIManagerListener() {
+ ApiServices.homePage(date, stepType, new LLAPIManagerListener() {
@Override
public void onError(Error error) {
Debug.error("Get data history error");
@@ -296,17 +301,70 @@ public class TopDateFragment extends FragmentBase implements SettingFragmentPres
tvStep.setText(String.valueOf(mTagetInfo.getSteps()));
tvRemain.setText(String.valueOf(mTagetInfo.getStepRemain()));
tvRateDone.setText(mContext.getResources().getString(R.string.percent_unit, mTagetInfo.getCompletePercent()));
+ }
+
+ private void getNews(Date date){
+
+ ApiServices.getNews(date, new LLAPIManagerListener() {
+ @Override
+ public void onError(Error error) {
+ Debug.error("Get data news error");
+ }
+
+ @Override
+ public void onSuccess(String json) {
+ Debug.error("Get data news success");
+ loadNewsDone(json);
+ }
+
+ @Override
+ public void onSuccess(JSONObject object) {
+ Debug.error("Get data news success");
+ }
+ });
+ }
+
+ private void loadNewsDone(String jsonString) {
+
+ List contentList = new ArrayList<>();
+ JSONObject jsonObject = null;
+ try {
+ jsonObject = new JSONObject(jsonString);
+ int status = jsonObject.optInt("status");
+ if (status == 1) {
+ JSONObject jsonResult = jsonObject.optJSONObject("result");
+ JSONArray listNotice = jsonResult.getJSONArray("listNotice");
+
+ if (listNotice != null) {
- List infoLists = mTagetInfo.getNoticeList();
- if (infoLists != null && infoLists.size() >0){
- mNoticeAdapter = new NoticeAdapter(mContext, infoLists);
+ for (int i = 0; i < listNotice.length(); i++) {
+ JSONObject obContent = (JSONObject) listNotice.get(i);
+ String content = obContent.optString("notice_content");
+ Debug.normal("Content: " + content);
+ contentList.add(new NoticeInfo(i+1,content));
+ }
+ }
+
+ }
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+
+ addNews(contentList);
+ }
+
+ private void addNews(List noticeInfos){
+ if (noticeInfos != null && noticeInfos.size() >0){
+ mNoticeAdapter = new NoticeAdapter(mContext, noticeInfos);
lvNotice.setAdapter(mNoticeAdapter);
lvNotice.setExpanded(true);
+ }else {
+ lvNotice.setAdapter(null);
}
-
}
+
@Override
public void onAttach(Context context) {
super.onAttach(context);
@@ -338,4 +396,6 @@ public class TopDateFragment extends FragmentBase implements SettingFragmentPres
}
+
+
}
diff --git a/app/src/main/java/com/dinhcv/lifelogpedometer/activity/TopTodayFragment.java b/app/src/main/java/com/dinhcv/lifelogpedometer/activity/TopTodayFragment.java
index fd45acf..fdd87f5 100644
--- a/app/src/main/java/com/dinhcv/lifelogpedometer/activity/TopTodayFragment.java
+++ b/app/src/main/java/com/dinhcv/lifelogpedometer/activity/TopTodayFragment.java
@@ -26,6 +26,7 @@ import com.dinhcv.lifelogpedometer.interfaces.LLAPIManagerListener;
import com.dinhcv.lifelogpedometer.model.StepModel;
import com.dinhcv.lifelogpedometer.model.structure.top.StepItemInfo;
import com.dinhcv.lifelogpedometer.model.structure.top.TopInfo;
+import com.dinhcv.lifelogpedometer.portal.ApiServices;
import com.dinhcv.lifelogpedometer.portal.LLAPIManager;
import com.dinhcv.lifelogpedometer.utils.Const;
import com.dinhcv.lifelogpedometer.utils.DayAxisValueFormatter;
@@ -135,8 +136,11 @@ public class TopTodayFragment extends FragmentBase implements SettingFragmentPre
// slice for the "missing" steps until reaching the goal
sliceGoal = new PieModel("", Const.STEP_GOAL, Color.parseColor("#B7B8B6"));
pg.addPieSlice(sliceGoal);
+
pg.setDrawValueInPie(false);
pg.setUsePieRotation(false);
+ pg.setInnerPadding(93);
+ pg.setInnerPaddingColor(R.color.background_main);
pg.startAnimation();
pg.setAutoCenterInSlice(false);
@@ -222,7 +226,7 @@ public class TopTodayFragment extends FragmentBase implements SettingFragmentPre
progress.setMessage(getString(R.string.loading));
progress.setCancelable(false);
progress.show();
- LLAPIManager.topInfo(date, stepType, new LLAPIManagerListener() {
+ ApiServices.topInfo(date, stepType, new LLAPIManagerListener() {
@Override
public void onError(Error error) {
Debug.error("Get data history error");
@@ -587,10 +591,13 @@ public class TopTodayFragment extends FragmentBase implements SettingFragmentPre
public void onResume() {
super.onResume();
activityRunning = true;
+ Debug.normal("Today: "+ "Onresume ");
Sensor countSensor = sensorManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER);
if (countSensor != null) {
+ Debug.normal("Today: "+ "countSensor not null ");
sensorManager.registerListener(this, countSensor, SensorManager.SENSOR_DELAY_UI);
} else {
+ Debug.normal("Today: "+ "countSensor is null ");
Toast.makeText(mContext, getResources().getString(R.string.sensor_available), Toast.LENGTH_SHORT).show();
}
}
@@ -631,8 +638,9 @@ public class TopTodayFragment extends FragmentBase implements SettingFragmentPre
}
private void creatLogStep(){
+ Debug.normal("Today: "+ "Create log "+ stepCount);
- LLAPIManager.createLog(stepType, stepCount, mFromDate, mToDate, new LLAPIManagerListener() {
+ ApiServices.createLog(stepType, stepCount, mFromDate, mToDate, new LLAPIManagerListener() {
@Override
public void onError(Error error) {
Debug.error("Get data history error");
@@ -650,4 +658,6 @@ public class TopTodayFragment extends FragmentBase implements SettingFragmentPre
});
}
+
+
}
diff --git a/app/src/main/java/com/dinhcv/lifelogpedometer/activity/WelcomeActivity.java b/app/src/main/java/com/dinhcv/lifelogpedometer/activity/WelcomeActivity.java
index f01d670..36f6dae 100644
--- a/app/src/main/java/com/dinhcv/lifelogpedometer/activity/WelcomeActivity.java
+++ b/app/src/main/java/com/dinhcv/lifelogpedometer/activity/WelcomeActivity.java
@@ -11,6 +11,7 @@ import android.support.v7.app.AlertDialog;
import com.dinhcv.lifelogpedometer.R;
import com.dinhcv.lifelogpedometer.interfaces.LLAPIManagerListener;
import com.dinhcv.lifelogpedometer.model.Shareprefer.Setting;
+import com.dinhcv.lifelogpedometer.portal.ApiServices;
import com.dinhcv.lifelogpedometer.portal.LLAPIManager;
import com.dinhcv.lifelogpedometer.utils.Debug;
@@ -40,7 +41,7 @@ public class WelcomeActivity extends ActivityBase implements Runnable {
private void handleRefreshToken(int id) {
- LLAPIManager.refreshToken(WelcomeActivity.this, id, new LLAPIManagerListener() {
+ ApiServices.refreshToken(WelcomeActivity.this, id, new LLAPIManagerListener() {
@Override
public void onError(Error error) {
Debug.error("Version JSON result: ERROR " + error);
diff --git a/app/src/main/java/com/dinhcv/lifelogpedometer/model/structure/home/NoticeInfo.java b/app/src/main/java/com/dinhcv/lifelogpedometer/model/structure/home/NoticeInfo.java
index 3addb39..875c212 100644
--- a/app/src/main/java/com/dinhcv/lifelogpedometer/model/structure/home/NoticeInfo.java
+++ b/app/src/main/java/com/dinhcv/lifelogpedometer/model/structure/home/NoticeInfo.java
@@ -4,6 +4,15 @@ public class NoticeInfo {
private int id;
private String content;
+ public NoticeInfo(){
+
+ }
+
+ public NoticeInfo(int id, String content){
+ this.id = id;
+ this.content = content;
+ }
+
public int getId() {
return id;
}
diff --git a/app/src/main/java/com/dinhcv/lifelogpedometer/portal/ApiServices.java b/app/src/main/java/com/dinhcv/lifelogpedometer/portal/ApiServices.java
new file mode 100644
index 0000000..8dfcb9a
--- /dev/null
+++ b/app/src/main/java/com/dinhcv/lifelogpedometer/portal/ApiServices.java
@@ -0,0 +1,76 @@
+package com.dinhcv.lifelogpedometer.portal;
+
+import android.content.Context;
+import android.graphics.Bitmap;
+
+import com.dinhcv.lifelogpedometer.interfaces.LLAPIManagerListener;
+import com.dinhcv.lifelogpedometer.model.structure.RegisterInfo;
+import com.dinhcv.lifelogpedometer.utils.Const;
+
+import java.util.Date;
+
+/**
+ * Created by Administrator on 16/11/2017.
+ */
+
+public class ApiServices {
+
+ public static void topInfo(final Date date, final Const.STEP_TYPE stepType, final LLAPIManagerListener action){
+ new LLAPIManager.TopInfo(date, stepType, action).execute();
+ }
+
+ public static void homePage(final Date date, final Const.STEP_TYPE stepType, final LLAPIManagerListener action) {
+ new LLAPIManager.HomePage(date, stepType, action).execute();
+ }
+
+
+ public static void historyDetail(final Date fromDate, final Date toDate, final LLAPIManagerListener action) {
+ new LLAPIManager.HistoryDetail(fromDate, toDate, action).execute();
+ }
+
+
+ public static void history(final Date fromDate, final Date toDate, final LLAPIManagerListener action) {
+ new LLAPIManager.History(fromDate, toDate, action).execute();
+ }
+
+
+ public static void forgetPassConfirm(final String email, final String codeConfirm, final LLAPIManagerListener action) {
+ new LLAPIManager.ForgetPassConfirm(email, codeConfirm, action).execute();
+ }
+
+
+ public static void forgetPass(final String email, final LLAPIManagerListener action) {
+ new LLAPIManager.ForgetPass(email, action).execute();
+ }
+
+
+ public static void register(final RegisterInfo registerInfo, final LLAPIManagerListener action) {
+ new LLAPIManager.Register(registerInfo, action).execute();
+ }
+
+
+ public static void uploadImage(final Bitmap bitmap, final LLAPIManagerListener action) {
+ new LLAPIManager.UploadImage(bitmap, action).execute();
+ }
+
+
+ public static void login(final Context context, final String email, final String pass, final LLAPIManagerListener action) {
+ new LLAPIManager.Login(context, email, pass, action).execute();
+ }
+
+ public static void createLog(final Const.STEP_TYPE stepType, final int stepCount, final Date startTime,
+ final Date endTime, final LLAPIManagerListener action) {
+ new LLAPIManager.CreateLog(stepType, stepCount, startTime, endTime, action).execute();
+ }
+
+
+ public static void refreshToken(final Context context, final int userId, final LLAPIManagerListener action) {
+ new LLAPIManager.RefreshToken(context, userId, action).execute();
+ }
+
+ public static void getNews(final Date date, final LLAPIManagerListener action) {
+ new LLAPIManager.GetNews(date, action).execute();
+ }
+
+
+}
diff --git a/app/src/main/java/com/dinhcv/lifelogpedometer/portal/LLAPIManager.java b/app/src/main/java/com/dinhcv/lifelogpedometer/portal/LLAPIManager.java
index 48ed021..e68914d 100644
--- a/app/src/main/java/com/dinhcv/lifelogpedometer/portal/LLAPIManager.java
+++ b/app/src/main/java/com/dinhcv/lifelogpedometer/portal/LLAPIManager.java
@@ -23,16 +23,9 @@ import org.json.JSONObject;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.UUID;
import java.util.concurrent.TimeUnit;
-import okhttp3.Call;
-import okhttp3.Callback;
import okhttp3.HttpUrl;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
@@ -42,36 +35,48 @@ import okhttp3.Response;
import okhttp3.ResponseBody;
public class LLAPIManager {
- public static String URL_ROOT = "http://clover.timesfun.jp:9001/";
+ private static String URL_ROOT = "http://clover.timesfun.jp:9001/";
//login info
- public static String URL_LOGIN_INFO = "login";
+ private static String URL_LOGIN_INFO = "login";
//register info
- public static String URL_REGISTER_INFO = "register";
+ private static String URL_REGISTER_INFO = "register";
//upload image info
- public static String URL_UPLOAD_IMAGE_INFO = "upload-image";
+ private static String URL_UPLOAD_IMAGE_INFO = "upload-image";
//Search zipcode
- public static String URL_FORGET_PASS_INFO = "forgetPass";
+ private static String URL_FORGET_PASS_INFO = "forgetPass";
//history
- public static String URL_HISTORE_INFO = "api/history";
+ private static String URL_HISTORE_INFO = "api/history";
//history detail
- public static String URL_HISTORE_DETAIL_INFO = "api/history/detail";
+ private static String URL_HISTORE_DETAIL_INFO = "api/history/detail";
// home
- public static String URL_HOME_INFO = "api/home";
+ private static String URL_HOME_INFO = "api/home";
//Search zipcode
- public static String URL_FORGET_PASS_CONFIRM_INFO = "forgetPass/confirm";
+ private static String URL_FORGET_PASS_CONFIRM_INFO = "forgetPass/confirm";
// Refesh Token
- public static String URL_REFESH_TOKEN_INFO = "refreshToken";
+ private static String URL_REFESH_TOKEN_INFO = "refreshToken";
// Top info
- public static String URL_TOP_INFO = "api/top";
+ private static String URL_TOP_INFO = "api/top";
// Refesh Token
- public static String URL_CREATE_LOG_INFO = "api/createLog";
-
+ private static String URL_CREATE_LOG_INFO = "api/createLog";
+ // Get news
+ private static String URL_GET_NEWS_INFO = "api/getnoticesbydate";
private static int deviationValue = 1;
- public static void login(final Context context, final String email, final String pass, final LLAPIManagerListener action) {
- new AsyncTask() {
+ public static class Login extends AsyncTask{
+ private Context context;
+ private String email;
+ private String pass;
+ private LLAPIManagerListener action;
+
+ public Login(Context context, String email, String pass, LLAPIManagerListener action) {
+ this.context = context;
+ this.email = email;
+ this.pass = pass;
+ this.action = action;
+ }
+
@Override
protected void onPreExecute() {
super.onPreExecute();
@@ -159,11 +164,17 @@ public class LLAPIManager {
e.printStackTrace();
}
}
- }.execute();
}
- public static void uploadImage(final Bitmap bitmap, final LLAPIManagerListener action) {
- new AsyncTask() {
+ public static class UploadImage extends AsyncTask{
+ private Bitmap bitmap;
+ private LLAPIManagerListener action;
+
+ public UploadImage(Bitmap bitmap, LLAPIManagerListener action) {
+ this.bitmap = bitmap;
+ this.action = action;
+ }
+
@Override
protected void onPreExecute() {
super.onPreExecute();
@@ -249,11 +260,17 @@ public class LLAPIManager {
e.printStackTrace();
}
}
- }.execute();
}
- public static void register(final RegisterInfo registerInfo, final LLAPIManagerListener action) {
- new AsyncTask() {
+ public static class Register extends AsyncTask{
+ private RegisterInfo registerInfo;
+ private LLAPIManagerListener action;
+
+ public Register(RegisterInfo registerInfo, LLAPIManagerListener action) {
+ this.registerInfo = registerInfo;
+ this.action = action;
+ }
+
@Override
protected void onPreExecute() {
super.onPreExecute();
@@ -356,7 +373,6 @@ public class LLAPIManager {
}
}
- }.execute();
}
private static byte[] convertBitmapToByteArray(Bitmap bitmap) {
@@ -366,9 +382,14 @@ public class LLAPIManager {
return byteArray;
}
- public static void forgetPass(final String email, final LLAPIManagerListener action) {
- new AsyncTask() {
+ public static class ForgetPass extends AsyncTask{
+ private String email;
+ private LLAPIManagerListener action;
+ public ForgetPass(String email, LLAPIManagerListener action) {
+ this.email = email;
+ this.action = action;
+ }
@Override
protected void onPreExecute() {
@@ -447,12 +468,19 @@ public class LLAPIManager {
action.onError(null);
}
}
- }.execute();
+
}
- public static void forgetPassConfirm(final String email, final String codeConfirm, final LLAPIManagerListener action) {
- new AsyncTask() {
+ public static class ForgetPassConfirm extends AsyncTask{
+ private String email;
+ private String codeConfirm;
+ private LLAPIManagerListener action;
+ public ForgetPassConfirm(String email, String codeConfirm, LLAPIManagerListener action) {
+ this.email = email;
+ this.codeConfirm = codeConfirm;
+ this.action = action;
+ }
@Override
protected void onPreExecute() {
@@ -531,12 +559,18 @@ public class LLAPIManager {
action.onError(null);
}
}
- }.execute();
}
- public static void history(final Date fromDate, final Date toDate, final LLAPIManagerListener action) {
- new AsyncTask() {
+ public static class History extends AsyncTask{
+ private Date fromDate;
+ private Date toDate;
+ private LLAPIManagerListener action;
+ public History(Date fromDate, Date toDate, LLAPIManagerListener action) {
+ this.fromDate = fromDate;
+ this.toDate = toDate;
+ this.action = action;
+ }
@Override
protected void onPreExecute() {
@@ -607,12 +641,18 @@ public class LLAPIManager {
action.onError(null);
}
}
- }.execute();
}
- public static void historyDetail(final Date fromDate, final Date toDate, final LLAPIManagerListener action) {
- new AsyncTask() {
+ public static class HistoryDetail extends AsyncTask{
+ private Date fromDate;
+ private Date toDate;
+ private LLAPIManagerListener action;
+ public HistoryDetail(Date fromDate, Date toDate, LLAPIManagerListener action) {
+ this.fromDate = fromDate;
+ this.toDate = toDate;
+ this.action = action;
+ }
@Override
protected void onPreExecute() {
@@ -683,12 +723,19 @@ public class LLAPIManager {
action.onError(null);
}
}
- }.execute();
+
}
- public static void homePage(final Date date, final Const.STEP_TYPE stepType, final LLAPIManagerListener action) {
- new AsyncTask() {
+ public static class HomePage extends AsyncTask{
+ private Date date;
+ private Const.STEP_TYPE stepType;
+ private LLAPIManagerListener action;
+ public HomePage(Date date, Const.STEP_TYPE stepType, LLAPIManagerListener action) {
+ this.date = date;
+ this.stepType = stepType;
+ this.action = action;
+ }
@Override
protected void onPreExecute() {
@@ -758,12 +805,19 @@ public class LLAPIManager {
action.onError(null);
}
}
- }.execute();
+
}
- public static void topInfo(final Date date, final Const.STEP_TYPE stepType, final LLAPIManagerListener action) {
- new AsyncTask() {
+ public static class TopInfo extends AsyncTask{
+ private Date date;
+ private Const.STEP_TYPE stepType;
+ private LLAPIManagerListener action;
+ public TopInfo(Date date, Const.STEP_TYPE stepType, LLAPIManagerListener action) {
+ this.date = date;
+ this.stepType = stepType;
+ this.action = action;
+ }
@Override
protected void onPreExecute() {
@@ -833,12 +887,23 @@ public class LLAPIManager {
action.onError(null);
}
}
- }.execute();
+
}
- public static void createLog(final Const.STEP_TYPE stepType, final int stepCount, final Date startTime,
- final Date endTime, final LLAPIManagerListener action) {
- new AsyncTask() {
+ public static class CreateLog extends AsyncTask{
+ private int stepCount;
+ private Const.STEP_TYPE stepType;
+ private Date startTime;
+ private Date endTime;
+ private LLAPIManagerListener action;
+
+ public CreateLog(Const.STEP_TYPE stepType, int stepCount, Date startTime, Date endTime, LLAPIManagerListener action) {
+ this.stepCount = stepCount;
+ this.stepType = stepType;
+ this.startTime = startTime;
+ this.endTime = endTime;
+ this.action = action;
+ }
@Override
@@ -923,12 +988,18 @@ public class LLAPIManager {
action.onError(null);
}
}
- }.execute();
}
- public static void refreshToken(final Context context, final int userId, final LLAPIManagerListener action) {
- new AsyncTask() {
+ public static class RefreshToken extends AsyncTask{
+ private Context context;
+ private int userId;
+ private LLAPIManagerListener action;
+ public RefreshToken(Context context, int userId, LLAPIManagerListener action) {
+ this.context = context;
+ this.userId = userId;
+ this.action = action;
+ }
@Override
protected void onPreExecute() {
@@ -1013,7 +1084,85 @@ public class LLAPIManager {
action.onError(null);
}
}
- }.execute();
+ }
+
+ public static class GetNews extends AsyncTask{
+ private Date date;
+ private LLAPIManagerListener action;
+
+ public GetNews(Date date, LLAPIManagerListener action) {
+ this.date = date;
+ this.action = action;
+ }
+
+ @Override
+ protected void onPreExecute() {
+ super.onPreExecute();
+ }
+
+ @Override
+ protected String doInBackground(Void... voids) {
+ String fromStr = Utils.dateToStringFormatDayMonthYear(date);
+ Debug.normal("Token: "+ APIResponse.getInstance().getToken());
+ HttpUrl baseUrl = HttpUrl.parse(URL_ROOT + URL_GET_NEWS_INFO + "/"+ fromStr);
+ Debug.normal("URL: "+baseUrl.toString());
+ final Request.Builder request = new Request.Builder()
+ .url(baseUrl)
+ .header("User-Agent", Utils.getCustomUA())
+ .header("Content-Type", "application/json")
+ .addHeader("token", APIResponse.getInstance().getToken())
+ .get();
+
+ OkHttpClient httpClient = new OkHttpClient.Builder()
+ .readTimeout(30, TimeUnit.SECONDS)
+ .writeTimeout(30, TimeUnit.SECONDS)
+ .connectTimeout(30, TimeUnit.SECONDS)
+ .build();
+
+ String jsonString = null;
+ try {
+ Response response = httpClient.newCall(request.build()).execute();
+ if (response == null) {
+ action.onError(null);
+ Debug.error("Response is null");
+ return null;
+ }
+ jsonString = getResponseData(response.body());
+
+ } catch (IOException e) {
+ Debug.normal("Error %s", e.getMessage());
+ }
+ return jsonString;
+ }
+
+ @Override
+ protected void onCancelled() {
+ super.onCancelled();
+ action.onError(null);
+ }
+
+ @Override
+ protected void onPostExecute(String jsonString) {
+ super.onPostExecute(jsonString);
+ if ((jsonString == null) || (jsonString.isEmpty())) {
+ action.onError(null);
+ return;
+ }
+ Debug.normal("String body: "+jsonString);
+
+ try {
+ JSONObject jsonObject = new JSONObject(jsonString);
+ int status = jsonObject.optInt("status");
+ if (status == 1) {
+ // save data
+ action.onSuccess(jsonString);
+ } else {
+ action.onError(new Error(jsonObject.getString("message")));
+ }
+ } catch (JSONException e) {
+ action.onError(null);
+ }
+ }
}
public static Bitmap getBitmapFromAsset(Context context, String filePath) {
diff --git a/app/src/main/res/layout/fragment_history_content.xml b/app/src/main/res/layout/fragment_history_content.xml
index f7d3635..3013950 100644
--- a/app/src/main/res/layout/fragment_history_content.xml
+++ b/app/src/main/res/layout/fragment_history_content.xml
@@ -184,6 +184,7 @@
android:layout_weight="1"
android:background="@drawable/button_background"
android:lines="2"
+ android:layout_margin="2dp"
android:text="@string/facebook" />
diff --git a/build.gradle b/build.gradle
index 0a26ece..36a2f9d 100644
--- a/build.gradle
+++ b/build.gradle
@@ -3,9 +3,13 @@
buildscript {
repositories {
jcenter()
+ maven {
+ url 'https://maven.google.com/'
+ name 'Google'
+ }
}
dependencies {
- classpath 'com.android.tools.build:gradle:2.3.3'
+ classpath 'com.android.tools.build:gradle:3.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
@@ -16,6 +20,10 @@ allprojects {
repositories {
jcenter()
maven { url "https://jitpack.io" }
+ maven {
+ url 'https://maven.google.com/'
+ name 'Google'
+ }
}
}
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index 81fecd4..4239f2c 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
-#Thu Jul 27 00:11:14 ICT 2017
+#Thu Nov 16 22:05:25 ICT 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip