Commit 089d8270 authored by DESKTOP-NFGF3PG\zxa01's avatar DESKTOP-NFGF3PG\zxa01

update

parent f9b3e5d7
......@@ -11,7 +11,7 @@
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application
android:allowBackup="true"
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
......
......@@ -3,7 +3,6 @@ package com.example.zxa01.iotclient.common.bindings;
import android.databinding.BindingAdapter;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
public class CustomViewBindings {
......
......@@ -15,23 +15,26 @@ public class PrivacyChoiceResponse {
return id;
}
public void setId(long id) {
public PrivacyChoiceResponse setId(long id) {
this.id = id;
return this;
}
public String getLocalDateTime() {
return localDateTime;
}
public void setLocalDateTime(String localDateTime) {
public PrivacyChoiceResponse setLocalDateTime(String localDateTime) {
this.localDateTime = localDateTime;
return this;
}
public PrivacyChoice getPrivacyChoice() {
return privacyChoice;
}
public void setPrivacyChoice(PrivacyChoice privacyChoice) {
public PrivacyChoiceResponse setPrivacyChoice(PrivacyChoice privacyChoice) {
this.privacyChoice = privacyChoice;
return this;
}
}
package com.example.zxa01.iotclient.common.shared;
package com.example.zxa01.iotclient.common.singleton;
import com.example.zxa01.iotclient.common.pojo.Setting;
......
package com.example.zxa01.iotclient.common.shared;
package com.example.zxa01.iotclient.common.singleton;
import com.example.zxa01.iotclient.common.pojo.auth.LoginMessage;
......@@ -8,7 +8,7 @@ public class DefaultData {
private LoginMessage loginMessage;
private DefaultData() {
loginMessage = new LoginMessage("192.168.2.90:8080", "user", "1234");
loginMessage = new LoginMessage("192.168.2.69:8080", "user", "1234");
}
public static DefaultData getDefaultData() {
......
package com.example.zxa01.iotclient.common.http;
package com.example.zxa01.iotclient.common.tools;
import com.example.zxa01.iotclient.common.pojo.device.Device;
import com.example.zxa01.iotclient.common.pojo.index.PrivacyChoiceResponse;
import com.example.zxa01.iotclient.common.pojo.privacy.PrivacyChoice;
import com.example.zxa01.iotclient.common.pojo.privacy.PrivacyPolicyReport;
import com.example.zxa01.iotclient.common.shared.Config;
import com.example.zxa01.iotclient.common.singleton.Config;
import com.google.gson.GsonBuilder;
import java.util.List;
import java.util.concurrent.TimeUnit;
import okhttp3.OkHttpClient;
import retrofit2.Call;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
......@@ -21,17 +22,19 @@ import retrofit2.http.Path;
public class Api {
private static ApiInterface api;
private static Retrofit retrofit = null;
public static ApiInterface getApi() {
Retrofit retrofit = new Retrofit.Builder()
retrofit = new Retrofit.Builder()
.baseUrl("http://" + Config.getConfig().getGateway())
.client(new OkHttpClient.Builder()
.connectTimeout(10, TimeUnit.SECONDS)
.cache(null)
.build())
.addConverterFactory(
GsonConverterFactory.create(new GsonBuilder()
.create()))
.build();
api = retrofit.create(ApiInterface.class);
return api;
}
......@@ -56,7 +59,7 @@ public class Api {
// 表達隱私偏好
@POST("/choice")
Call<PrivacyChoiceResponse> setPrivacyChoice(@Body String privacyChoice);
Call<PrivacyChoiceResponse> setPrivacyChoice(@Body PrivacyChoice privacyChoice);
// 取得隱私偏好記錄
@GET("/choice")
......
package com.example.zxa01.iotclient.common.http;
package com.example.zxa01.iotclient.common.tools;
import android.Manifest;
import android.app.Activity;
......@@ -29,7 +29,7 @@ import java.nio.charset.StandardCharsets;
import static android.support.v4.app.ActivityCompat.requestPermissions;
public class DownloadTask {
public class DownloadFile {
private static final String TAG = "Download File";
public static final String CHANNELID = "118";
......@@ -42,7 +42,7 @@ public class DownloadTask {
private AlertDialog dialog;
public DownloadTask(Context context, String downloadUrl) {
public DownloadFile(Context context, String downloadUrl) {
this.context = context;
this.downloadUrl = downloadUrl;
this.dialog = new AlertDialog.Builder(context)
......
......@@ -5,7 +5,7 @@ import android.databinding.BaseObservable;
import android.support.annotation.NonNull;
import android.util.Log;
import com.example.zxa01.iotclient.common.http.Api;
import com.example.zxa01.iotclient.common.tools.Api;
import com.example.zxa01.iotclient.common.pojo.device.Device;
import com.example.zxa01.iotclient.common.pojo.privacy.PrivacyPolicyReport;
......@@ -32,6 +32,7 @@ public class DetailModel extends BaseObservable {
Api.getApi().readPrivacyPolicyReportByDevice(udn).enqueue(new Callback<PrivacyPolicyReport>() {
@Override
public void onResponse(Call<PrivacyPolicyReport> call, Response<PrivacyPolicyReport> response) {
Log.i("readDevices - onResponse()", "success");
setDeviceMLD(response == null || response.body() == null ?
null : response.body().getDevice());
}
......
package com.example.zxa01.iotclient.component.detail;
import com.example.zxa01.iotclient.R;
import com.example.zxa01.iotclient.common.http.DownloadTask;
import com.example.zxa01.iotclient.common.pojo.device.Device;
import com.example.zxa01.iotclient.common.tools.DownloadFile;
import com.example.zxa01.iotclient.component.privacy.PrivacyActivity;
import android.arch.lifecycle.MutableLiveData;
import android.arch.lifecycle.ViewModel;
......@@ -10,20 +9,9 @@ import android.content.Context;
import android.content.Intent;
import android.databinding.ObservableBoolean;
import android.databinding.ObservableField;
import android.os.AsyncTask;
import android.os.Environment;
import android.support.annotation.NonNull;
import android.util.Log;
import android.view.Gravity;
import android.widget.Toast;
import java.io.BufferedInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.net.URLConnection;
public class DetailViewModel extends ViewModel {
public ObservableBoolean isLoading = new ObservableBoolean(true);
......@@ -62,6 +50,6 @@ public class DetailViewModel extends ViewModel {
public void downloadPrivacyReport() {
// fake file just for test
String url = "https://www.ey.gov.tw/File/4EBD1D15E6556A04?A=C";
new DownloadTask(context, url);
new DownloadFile(context, url);
}
}
......@@ -13,6 +13,9 @@ import com.example.zxa01.iotclient.R;
import com.example.zxa01.iotclient.databinding.FragmentDeviceBinding;
import com.example.zxa01.iotclient.component.home.device.bind.DeviceBindFragment;
import java.io.File;
import java.util.Arrays;
public class DeviceFragment extends Fragment {
......
package com.example.zxa01.iotclient.component.home.device;
import com.example.zxa01.iotclient.common.http.Api;
import com.example.zxa01.iotclient.common.tools.Api;
import com.example.zxa01.iotclient.common.pojo.device.Device;
import android.arch.lifecycle.MutableLiveData;
......@@ -10,7 +10,6 @@ import android.util.Log;
import java.util.List;
import java.util.stream.Collectors;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
......@@ -31,14 +30,15 @@ public class DeviceModel extends BaseObservable {
new Callback<List<Device>>() {
@Override
public void onResponse(Call<List<Device>> call, @NonNull Response<List<Device>> response) {
Log.i("readDevices - onResponse()", response.body().toString());
devicesMLD.setValue(response.body() == null ?
null : response.body().stream().collect(Collectors.toList()));
}
@Override
public void onFailure(Call<List<Device>> call, Throwable t) {
devicesMLD.setValue(null);
Log.e("readDevices - onFailure()", t.getMessage(), t);
devicesMLD.setValue(null);
}
}
);
......
package com.example.zxa01.iotclient.component.home.device.bind;
import android.arch.lifecycle.MutableLiveData;
import android.databinding.BaseObservable;
import android.support.annotation.NonNull;
import android.util.Log;
import com.example.zxa01.iotclient.common.http.Api;
import com.example.zxa01.iotclient.common.tools.Api;
import com.example.zxa01.iotclient.common.pojo.device.Device;
import retrofit2.Call;
......
......@@ -5,8 +5,9 @@ import android.databinding.BaseObservable;
import android.support.annotation.NonNull;
import android.util.Log;
import com.example.zxa01.iotclient.common.http.Api;
import com.example.zxa01.iotclient.common.tools.Api;
import com.example.zxa01.iotclient.common.pojo.index.PrivacyChoiceResponse;
import java.util.List;
import java.util.stream.Collectors;
......@@ -29,14 +30,15 @@ public class RecordModel extends BaseObservable {
Api.getApi().readPrivacyChoiceRecordsByUser().enqueue(new Callback<List<PrivacyChoiceResponse>>() {
@Override
public void onResponse(Call<List<PrivacyChoiceResponse>> call, @NonNull Response<List<PrivacyChoiceResponse>> response) {
Log.i("fetchRecord - onResponse()", response.body().toString());
privacyChoiceResponsesMLD.setValue(response.body() == null ?
null : response.body().stream().collect(Collectors.toList()));
}
@Override
public void onFailure(Call<List<PrivacyChoiceResponse>> call, Throwable t) {
privacyChoiceResponsesMLD.setValue(null);
Log.e("fetchRecord - onFailure()", t.getMessage(), t);
privacyChoiceResponsesMLD.setValue(null);
}
});
......
......@@ -6,12 +6,18 @@ import android.content.Context;
import android.content.Intent;
import android.databinding.ObservableBoolean;
import android.support.annotation.NonNull;
import android.text.format.DateFormat;
import com.example.zxa01.iotclient.R;
import com.example.zxa01.iotclient.common.pojo.index.PrivacyChoiceResponse;
import com.example.zxa01.iotclient.common.pojo.privacy.p3p.Collector;
import com.example.zxa01.iotclient.component.privacy.PrivacyActivity;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
public class RecordViewModel extends ViewModel {
......@@ -71,7 +77,23 @@ public class RecordViewModel extends ViewModel {
public void setAdapter(List<PrivacyChoiceResponse> privacyChoiceResponses) {
isLoading.set(false);
isNoContent.set(privacyChoiceResponses == null);
adapter.setPrivacyChoiceResponses(privacyChoiceResponses);
privacyChoiceResponses.sort((pre, post) -> post.getLocalDateTime().compareTo(pre.getLocalDateTime()));
adapter.setPrivacyChoiceResponses(privacyChoiceResponses.stream()
.map(choice -> choice.setLocalDateTime(convertDateTime(choice.getLocalDateTime())))
.collect(Collectors.toList())
);
}
private String convertDateTime(String dateTime) {
SimpleDateFormat preConvert = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.mmm");
SimpleDateFormat postConvert = new SimpleDateFormat("yyyy-MM-dd HH:mm");
String convertDateTime = "";
try {
convertDateTime = postConvert.format(preConvert.parse(dateTime));
} catch (ParseException e) {
e.printStackTrace();
}
return convertDateTime;
}
}
......@@ -4,7 +4,7 @@ import android.arch.lifecycle.MutableLiveData;
import android.databinding.BaseObservable;
import com.example.zxa01.iotclient.common.pojo.Setting;
import com.example.zxa01.iotclient.common.shared.Config;
import com.example.zxa01.iotclient.common.singleton.Config;
import java.util.List;
......
......@@ -5,11 +5,10 @@ import android.arch.lifecycle.ViewModel;
import android.content.Context;
import android.content.Intent;
import android.databinding.ObservableBoolean;
import android.support.annotation.NonNull;
import com.example.zxa01.iotclient.R;
import com.example.zxa01.iotclient.common.pojo.Setting;
import com.example.zxa01.iotclient.common.shared.Config;
import com.example.zxa01.iotclient.common.singleton.Config;
import com.example.zxa01.iotclient.component.login.LoginActivity;
import java.util.List;
......
package com.example.zxa01.iotclient.component.login;
import com.example.zxa01.iotclient.common.pojo.Setting;
import com.example.zxa01.iotclient.common.pojo.auth.User;
import com.example.zxa01.iotclient.common.shared.Config;
import com.example.zxa01.iotclient.common.singleton.Config;
import com.example.zxa01.iotclient.common.pojo.auth.LoginMessage;
import android.arch.lifecycle.MutableLiveData;
......
package com.example.zxa01.iotclient.component.login;
import com.example.zxa01.iotclient.common.shared.DefaultData;
import com.example.zxa01.iotclient.common.singleton.DefaultData;
import com.example.zxa01.iotclient.component.home.HomeActivity;
import com.example.zxa01.iotclient.common.pojo.auth.LoginMessage;
import android.arch.lifecycle.MutableLiveData;
......
......@@ -6,13 +6,12 @@ import android.os.Handler;
import android.support.annotation.NonNull;
import android.util.Log;
import com.example.zxa01.iotclient.common.http.Api;
import com.example.zxa01.iotclient.common.tools.Api;
import com.example.zxa01.iotclient.common.pojo.index.PrivacyChoiceResponse;
import com.example.zxa01.iotclient.common.pojo.privacy.PrivacyChoice;
import com.example.zxa01.iotclient.common.pojo.privacy.PrivacyContent;
import com.example.zxa01.iotclient.common.pojo.privacy.PrivacyPolicyReport;
import com.example.zxa01.iotclient.common.shared.Config;
import com.google.gson.Gson;
import com.example.zxa01.iotclient.common.singleton.Config;
import retrofit2.Call;
import retrofit2.Callback;
......@@ -54,20 +53,21 @@ public class PrivacyModel extends BaseObservable {
public void setPrivacyChoice(@NonNull PrivacyContent privacyContent, @NonNull boolean isAccepted) {
isUploadMLD.setValue(true);
Api.getApi().setPrivacyChoice(new Gson().toJson(
new PrivacyChoice().setPrivacyContent(
Api.getApi().setPrivacyChoice(new PrivacyChoice()
.setPrivacyContent(
privacyContent.setUser(Config.getConfig().getUser()))
.setAccepted(isAccepted)))
.setAccepted(isAccepted))
.enqueue(new Callback<PrivacyChoiceResponse>() {
@Override
public void onResponse(Call<PrivacyChoiceResponse> call, Response<PrivacyChoiceResponse> response) {
Log.i("setPrivacyChoice - onResponse()", "success");
dialogDelay();
}
@Override
public void onFailure(Call<PrivacyChoiceResponse> call, Throwable t) {
dialogDelay();
Log.e("setPrivacyChoice - onFailure()", t.getMessage(), t);
dialogDelay();
}
});
}
......
......@@ -4,7 +4,7 @@ import com.example.zxa01.iotclient.R;
import com.example.zxa01.iotclient.common.pojo.privacy.PrivacyContent;
import com.example.zxa01.iotclient.common.pojo.privacy.PrivacyPolicy;
import com.example.zxa01.iotclient.common.pojo.privacy.PrivacyPolicyReport;
import com.example.zxa01.iotclient.common.shared.Config;
import com.example.zxa01.iotclient.common.singleton.Config;
import android.arch.lifecycle.MutableLiveData;
import android.arch.lifecycle.ViewModel;
......
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="@color/colorPrimaryDark"
android:endColor="@color/colorAccent"
android:angle="180"/>
</shape>
\ No newline at end of file
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M12,22c1.1,0 2,-0.9 2,-2h-4c0,1.1 0.89,2 2,2zM18,16v-5c0,-3.07 -1.64,-5.64 -4.5,-6.32L13.5,4c0,-0.83 -0.67,-1.5 -1.5,-1.5s-1.5,0.67 -1.5,1.5v0.68C7.63,5.36 6,7.92 6,11v5l-2,2v1h16v-1l-2,-2z" />
</vector>
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
......@@ -45,9 +46,9 @@
android:layout_height="wrap_content"
android:paddingTop="@dimen/padding_xs"
android:paddingBottom="@dimen/padding_xs"
android:text='@{@string/privacy_version+" "+String.valueOf(position+1)}'
android:text='@{@string/privacy_title+" "+viewModel.getPrivacyChoiceAt(position).privacyChoice.privacyContent.policy.id}'
android:textSize="@dimen/font_sm"
tools:text="版本1" />
tools:text="隱私政策 1" />
<TextView
android:layout_width="wrap_content"
......@@ -66,12 +67,12 @@
android:layout_marginTop="@dimen/margin_sm"
android:layout_marginBottom="@dimen/margin_sm"
android:textColor="@color/colorWhite"
android:background="@{true ? @drawable/green_radius_background : @drawable/red_radius_background }"
android:background="@{viewModel.getPrivacyChoiceAt(position).privacyChoice.accepted ? @drawable/green_radius_background : @drawable/red_radius_background }"
android:paddingLeft="@dimen/padding_sm"
android:paddingTop="@dimen/padding_xs"
android:paddingRight="@dimen/padding_sm"
android:paddingBottom="@dimen/padding_xs"
android:text="@{true ? @string/record_accept : @string/record_reject }"
android:text="@{viewModel.getPrivacyChoiceAt(position).privacyChoice.accepted ? @string/record_accept : @string/record_reject }"
android:textSize="@dimen/font_sm"
tools:text="同意" />
<TextView
......
......@@ -9,7 +9,6 @@
<color name="colorLighter">#E4E4E4</color>
<color name="colorLightest">#F4F4F4</color>
<color name="colorWhite">#FFFFFF</color>
<color name="colorTransparent">#00000000</color>
<color name="colorGreen">#28A745</color>
<color name="colorRed">#DC3545</color>
......
......@@ -7,7 +7,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.0'
classpath 'com.android.tools.build:gradle:3.4.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment