Commit 2bf070bb authored by DESKTOP-NFGF3PG\zxa01's avatar DESKTOP-NFGF3PG\zxa01

update UI

parent 1a4ddac9
package com.example.zxa01.iotclient.common.http;
import com.example.zxa01.iotclient.common.pojo.device.Device;
import com.example.zxa01.iotclient.common.pojo.index.PrivacyChoiceIndex;
import com.example.zxa01.iotclient.common.pojo.privacy.PrivacyChoice;
import com.example.zxa01.iotclient.common.pojo.index.PrivacyChoiceResponse;
import com.example.zxa01.iotclient.common.pojo.privacy.PrivacyPolicyReport;
import com.example.zxa01.iotclient.common.shared.Config;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.util.List;
......@@ -54,21 +52,17 @@ public class Api {
@POST("/device/{udn}")
Call<Device> bindDeviceAndGateway(@Path("udn") String udn);
// 取得該裝置相關資料
@GET("/device/{udn}")
Call<Device> readDevice(@Path("udn") String udn);
// 取得該裝置的隱私政策與相關資料
@GET("/privacy/{udn}")
Call<PrivacyPolicyReport> readPrivacyPolicyReportByDevice(@Path("udn") String udn);
// 表達隱私偏好
@POST("/choice")
Call<PrivacyChoice> setPrivacyChoice(@Body PrivacyChoice privacyChoice);
Call<PrivacyChoiceResponse> setPrivacyChoice(@Body String privacyChoice);
// 取得隱私偏好記錄
@GET("/choice")
Call<List<PrivacyChoiceIndex>> readPrivacyChoiceRecordsByUser();
Call<List<PrivacyChoiceResponse>> readPrivacyChoiceRecordsByUser();
}
}
package com.example.zxa01.iotclient.common.pojo;
public class Setting {
private String key;
private String value;
public Setting(String key, String value) {
this.key = key;
this.value = value;
public Setting() {
}
public String getKey() {
return key;
}
public void setKey(String key) {
public Setting setKey(String key) {
this.key = key;
return this;
}
public String getValue() {
return value;
}
public void setValue(String value) {
public Setting setValue(String value) {
this.value = value;
return this;
}
}
package com.example.zxa01.iotclient.common.pojo.index;
import com.example.zxa01.iotclient.common.pojo.privacy.PrivacyContent;
import com.example.zxa01.iotclient.common.pojo.privacy.PrivacyChoice;
import java.time.LocalDateTime;
public class PrivacyChoiceIndex {
public class PrivacyChoiceResponse {
private long id;
private LocalDateTime localDateTime;
private PrivacyChoice privacyChoice;
private String localDateTime;
private PrivacyContent privacyContent;
public PrivacyChoiceIndex(){
public PrivacyChoiceResponse(){
}
......@@ -22,19 +20,19 @@ public class PrivacyChoiceIndex {
this.id = id;
}
public LocalDateTime getLocalDateTime() {
public String getLocalDateTime() {
return localDateTime;
}
public void setLocalDateTime(LocalDateTime localDateTime) {
public void setLocalDateTime(String localDateTime) {
this.localDateTime = localDateTime;
}
public PrivacyChoice getPrivacyChoice() {
return privacyChoice;
public PrivacyContent getPrivacyContent() {
return privacyContent;
}
public void setPrivacyChoice(PrivacyChoice privacyChoice) {
this.privacyChoice = privacyChoice;
public void setPrivacyContent(PrivacyContent privacyContent) {
this.privacyContent = privacyContent;
}
}
......@@ -8,7 +8,7 @@ public class DefaultData {
private LoginMessage loginMessage;
private DefaultData() {
loginMessage = new LoginMessage("192.168.2.69:8080", "user", "1234");
loginMessage = new LoginMessage("192.168.2.90:8080", "user", "1234");
}
public static DefaultData getDefaultData() {
......
......@@ -29,15 +29,15 @@ public class DetailModel extends BaseObservable {
}
public void readDevice(@NonNull String udn) {
Api.getApi().readDevice(udn).enqueue(new Callback<Device>() {
Api.getApi().readPrivacyPolicyReportByDevice(udn).enqueue(new Callback<PrivacyPolicyReport>() {
@Override
public void onResponse(Call<Device> call, Response<Device> response) {
public void onResponse(Call<PrivacyPolicyReport> call, Response<PrivacyPolicyReport> response) {
setDeviceMLD(response == null || response.body() == null ?
null : response.body());
null : response.body().getDevice());
}
@Override
public void onFailure(Call<Device> call, Throwable t) {
public void onFailure(Call<PrivacyPolicyReport> call, Throwable t) {
Log.e("readDevice - onFailure()", t.getMessage(), t);
}
});
......
......@@ -6,7 +6,7 @@ import android.content.Context;
public class HomeViewModel extends ViewModel {
private Context context;
private HomeModel homeModel = new HomeModel();
private HomeModel homeModel;
public HomeViewModel(Context context) {
this.context = context;
......
......@@ -5,6 +5,7 @@ import com.example.zxa01.iotclient.common.pojo.device.Device;
import android.arch.lifecycle.MutableLiveData;
import android.databinding.BaseObservable;
import android.support.annotation.NonNull;
import android.util.Log;
import java.util.List;
......@@ -29,8 +30,8 @@ public class DeviceModel extends BaseObservable {
Api.getApi().readDevices().enqueue(
new Callback<List<Device>>() {
@Override
public void onResponse(Call<List<Device>> call, Response<List<Device>> response) {
devicesMLD.setValue(response == null || response.body() == null ?
public void onResponse(Call<List<Device>> call, @NonNull Response<List<Device>> response) {
devicesMLD.setValue(response.body() == null ?
null : response.body().stream().collect(Collectors.toList()));
}
......
......@@ -8,14 +8,14 @@ import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import com.example.zxa01.iotclient.BR;
import com.example.zxa01.iotclient.common.pojo.index.PrivacyChoiceIndex;
import com.example.zxa01.iotclient.common.pojo.index.PrivacyChoiceResponse;
import java.util.List;
public class RecordAdapter extends RecyclerView.Adapter<RecordAdapter.MyViewHolder> {
private int layoutId;
private List<PrivacyChoiceIndex> privacyChoiceIndices;
private List<PrivacyChoiceResponse> privacyChoiceResponses;
private RecordViewModel viewModel;
public RecordAdapter(@LayoutRes int layoutId, RecordViewModel viewModel) {
......@@ -40,7 +40,7 @@ public class RecordAdapter extends RecyclerView.Adapter<RecordAdapter.MyViewHold
@Override
public int getItemCount() {
return privacyChoiceIndices == null ? 0 : privacyChoiceIndices.size();
return privacyChoiceResponses == null ? 0 : privacyChoiceResponses.size();
}
@Override
......@@ -48,8 +48,8 @@ public class RecordAdapter extends RecyclerView.Adapter<RecordAdapter.MyViewHold
return getLayoutIdForPosition(position);
}
public void setPrivacyChoiceIndices(List<PrivacyChoiceIndex> privacyChoiceIndices) {
this.privacyChoiceIndices = privacyChoiceIndices;
public void setPrivacyChoiceResponses(List<PrivacyChoiceResponse> privacyChoiceResponses) {
this.privacyChoiceResponses = privacyChoiceResponses;
}
class MyViewHolder extends RecyclerView.ViewHolder {
......
......@@ -2,26 +2,11 @@ package com.example.zxa01.iotclient.component.home.record;
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.pojo.device.Device;
import com.example.zxa01.iotclient.common.pojo.device.Manufacturer;
import com.example.zxa01.iotclient.common.pojo.device.Model;
import com.example.zxa01.iotclient.common.pojo.index.PrivacyChoiceIndex;
import com.example.zxa01.iotclient.common.pojo.privacy.PrivacyPolicy;
import com.example.zxa01.iotclient.common.pojo.privacy.PrivacyPolicyReport;
import com.example.zxa01.iotclient.common.pojo.privacy.p3p.Access;
import com.example.zxa01.iotclient.common.pojo.privacy.p3p.Collector;
import com.example.zxa01.iotclient.common.pojo.privacy.p3p.Datum;
import com.example.zxa01.iotclient.common.pojo.privacy.p3p.Dispute;
import com.example.zxa01.iotclient.common.pojo.privacy.p3p.Purpose;
import com.example.zxa01.iotclient.common.pojo.privacy.p3p.Recipient;
import com.example.zxa01.iotclient.common.pojo.privacy.p3p.Remedy;
import com.example.zxa01.iotclient.common.pojo.privacy.p3p.Retention;
import com.example.zxa01.iotclient.common.pojo.privacy.p3p.Statement;
import java.util.ArrayList;
import com.example.zxa01.iotclient.common.pojo.index.PrivacyChoiceResponse;
import java.util.List;
import java.util.stream.Collectors;
......@@ -31,31 +16,26 @@ import retrofit2.Response;
public class RecordModel extends BaseObservable {
private List<PrivacyChoiceIndex> privacyChoiceIndices = new ArrayList<>();
private MutableLiveData<List<PrivacyChoiceIndex>> privacyChoiceIndicesMLD = new MutableLiveData<>();
private MutableLiveData<List<PrivacyChoiceResponse>> privacyChoiceResponsesMLD = new MutableLiveData<>();
public RecordModel() {
}
private void addPrivacyChoiceIndices(PrivacyChoiceIndex privacyChoiceIndex) {
privacyChoiceIndices.add(privacyChoiceIndex);
}
public MutableLiveData<List<PrivacyChoiceIndex>> getPrivacyChoiceIndicesMLD() {
return privacyChoiceIndicesMLD;
public MutableLiveData<List<PrivacyChoiceResponse>> getPrivacyChoiceResponsesMLD() {
return privacyChoiceResponsesMLD;
}
public void fetchRecord() {
Api.getApi().readPrivacyChoiceRecordsByUser().enqueue(new Callback<List<PrivacyChoiceIndex>>() {
Api.getApi().readPrivacyChoiceRecordsByUser().enqueue(new Callback<List<PrivacyChoiceResponse>>() {
@Override
public void onResponse(Call<List<PrivacyChoiceIndex>> call, Response<List<PrivacyChoiceIndex>> response) {
// TODO transfer response
privacyChoiceIndicesMLD.setValue(response == null || response.body() == null ?
public void onResponse(Call<List<PrivacyChoiceResponse>> call, @NonNull Response<List<PrivacyChoiceResponse>> response) {
privacyChoiceResponsesMLD.setValue(response.body() == null ?
null : response.body().stream().collect(Collectors.toList()));
}
@Override
public void onFailure(Call<List<PrivacyChoiceIndex>> call, Throwable t) {
public void onFailure(Call<List<PrivacyChoiceResponse>> call, Throwable t) {
Log.e("fetchRecord - onFailure()", t.getMessage(), t);
}
});
......
......@@ -8,7 +8,7 @@ import android.databinding.ObservableBoolean;
import android.support.annotation.NonNull;
import com.example.zxa01.iotclient.R;
import com.example.zxa01.iotclient.common.pojo.index.PrivacyChoiceIndex;
import com.example.zxa01.iotclient.common.pojo.index.PrivacyChoiceResponse;
import com.example.zxa01.iotclient.component.privacy.PrivacyActivity;
import java.util.List;
......@@ -32,30 +32,30 @@ public class RecordViewModel extends ViewModel {
recordModel.fetchRecord();
}
public MutableLiveData<List<PrivacyChoiceIndex>> observePrivacyChoiceIndicesMLD() {
return recordModel.getPrivacyChoiceIndicesMLD();
public MutableLiveData<List<PrivacyChoiceResponse>> observePrivacyChoiceIndicesMLD() {
return recordModel.getPrivacyChoiceResponsesMLD();
}
/**
* child model
*/
public PrivacyChoiceIndex getPrivacyChoiceAt(@NonNull Integer index) {
if (recordModel.getPrivacyChoiceIndicesMLD().getValue() != null &&
recordModel.getPrivacyChoiceIndicesMLD().getValue().size() > index) {
return recordModel.getPrivacyChoiceIndicesMLD().getValue().get(index);
public PrivacyChoiceResponse getPrivacyChoiceAt(@NonNull Integer index) {
if (recordModel.getPrivacyChoiceResponsesMLD().getValue() != null &&
recordModel.getPrivacyChoiceResponsesMLD().getValue().size() > index) {
return recordModel.getPrivacyChoiceResponsesMLD().getValue().get(index);
}
return null;
}
public void onPrivacyChoiceClick(@NonNull Integer index) {
if (recordModel.getPrivacyChoiceIndicesMLD().getValue() != null &&
recordModel.getPrivacyChoiceIndicesMLD().getValue().size() > index) {
if (recordModel.getPrivacyChoiceResponsesMLD().getValue() != null &&
recordModel.getPrivacyChoiceResponsesMLD().getValue().size() > index) {
context.startActivity(
new Intent(context, PrivacyActivity.class)
.putExtra("udn",
recordModel.getPrivacyChoiceIndicesMLD().getValue().get(index)
.getPrivacyChoice().getPrivacyContent().getDevice().getUdn()));
recordModel.getPrivacyChoiceResponsesMLD().getValue().get(index)
.getPrivacyContent().getDevice().getUdn()));
}
}
......@@ -67,9 +67,9 @@ public class RecordViewModel extends ViewModel {
return adapter;
}
public void setAdapter(List<PrivacyChoiceIndex> privacyChoiceIndices) {
public void setAdapter(List<PrivacyChoiceResponse> privacyChoiceResponses) {
isLoading.set(false);
adapter.setPrivacyChoiceIndices(privacyChoiceIndices);
adapter.setPrivacyChoiceResponses(privacyChoiceResponses);
}
}
......@@ -26,21 +26,6 @@ public class LoginModel extends BaseObservable {
if (verification(message)) {
settingConfig(message);
isAuthorized.setValue(true);
// Callback<Object> callback = new Callback<Object>() {
// @Override
// public void onResponse(Call<Object> call, Response<Object> response) {
// // TODO login
// isAuthorized.setValue(true);
// }
//
// @Override
// public void onFailure(Call<Object> call, Throwable t) {
// Log.e("login - onFailure()", t.getMessage(), t);
// }
// };
//
// // TODO loginMessage to json
// Api.getApi().getDevices().enqueue(callback);
}
}
......@@ -55,9 +40,9 @@ public class LoginModel extends BaseObservable {
private void settingConfig(@NonNull LoginMessage message) {
Config.getConfig().setUser(new User().setAccount(message.getAccount()));
Config.getConfig().setGateway(message.getGateway());
Config.getConfig().addSetting(new Setting(Config.USER, Config.getConfig().getUser().getAccount()));
Config.getConfig().addSetting(new Setting(Config.GATEWAY, message.getGateway()));
Config.getConfig().addSetting(new Setting(Config.LOGOUT, Config.LOGOUT_MESSAGE));
Config.getConfig().addSetting(new Setting().setKey(Config.USER).setValue(Config.getConfig().getUser().getAccount()));
Config.getConfig().addSetting(new Setting().setKey(Config.GATEWAY).setValue(message.getGateway()));
Config.getConfig().addSetting(new Setting().setKey(Config.LOGOUT).setValue(Config.LOGOUT_MESSAGE));
}
}
......@@ -7,9 +7,12 @@ import android.support.annotation.NonNull;
import android.util.Log;
import com.example.zxa01.iotclient.common.http.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 retrofit2.Call;
import retrofit2.Callback;
......@@ -18,6 +21,7 @@ import retrofit2.Response;
public class PrivacyModel extends BaseObservable {
private MutableLiveData<Boolean> isUploadMLD = new MutableLiveData<>();
private MutableLiveData<PrivacyPolicyReport> privacyPolicyReportMLD = new MutableLiveData<>();
public PrivacyModel() {
......@@ -50,19 +54,30 @@ public class PrivacyModel extends BaseObservable {
public void setPrivacyChoice(@NonNull PrivacyContent privacyContent, @NonNull boolean isAccepted) {
isUploadMLD.setValue(true);
Api.getApi().setPrivacyChoice(
new PrivacyChoice().setPrivacyContent(privacyContent).setAccepted(isAccepted)).enqueue(
new Callback<PrivacyChoice>() {
Api.getApi().setPrivacyChoice(transferPrivacyContent(privacyContent, isAccepted))
.enqueue(new Callback<PrivacyChoiceResponse>() {
@Override
public void onResponse(Call<PrivacyChoice> call, Response<PrivacyChoice> response) {
new Handler().postDelayed(() -> isUploadMLD.setValue(false), 500);
public void onResponse(Call<PrivacyChoiceResponse> call, Response<PrivacyChoiceResponse> response) {
dialogDelay();
}
@Override
public void onFailure(Call<PrivacyChoice> call, Throwable t) {
public void onFailure(Call<PrivacyChoiceResponse> call, Throwable t) {
dialogDelay();
Log.e("setPrivacyChoice - onFailure()", t.getMessage(), t);
}
});
}
private void dialogDelay() {
new Handler().postDelayed(() -> isUploadMLD.setValue(false), 500);
}
private String transferPrivacyContent(@NonNull PrivacyContent privacyContent, @NonNull boolean isAccepted) {
return new Gson().toJson(
new PrivacyChoice().setPrivacyContent(
privacyContent.setUser(Config.getConfig().getUser()))
.setAccepted(isAccepted));
}
}
......@@ -59,7 +59,6 @@ public class PrivacyViewModel extends ViewModel {
public PrivacyPolicy getPrivacyAt(@NonNull Integer index) {
if (privacyModel.getPrivacyPolicyReportMLD().getValue() != null &&
index != null &&
privacyModel.getPrivacyPolicyReportMLD().getValue().getPolicies().size() > index) {
return privacyModel.getPrivacyPolicyReportMLD().getValue().getPolicies().get(index);
}
......
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/colorGreen" />
<corners android:radius="4dp" />
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/colorLightest" />
<corners android:radius="4dp" />
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/colorRed" />
<corners android:radius="4dp" />
</shape>
\ No newline at end of file
......@@ -40,14 +40,12 @@
android:id="@+id/textViewTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/padding"
android:paddingTop="@dimen/padding_lg"
android:paddingRight="@dimen/padding"
android:paddingBottom="@dimen/padding"
android:background="@drawable/border_bottom_xl"
android:background="@color/colorLightest"
android:elevation="2dp"
android:padding="@dimen/padding"
android:text="@string/record_title"
android:textColor="@color/colorAccent"
android:textSize="@dimen/font_lg"
android:textColor="@color/colorLight"
android:textSize="@dimen/font"
android:textStyle="bold" />
<android.support.v7.widget.RecyclerView
......@@ -55,7 +53,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:layout_marginTop="@dimen/margin"
android:paddingTop="@dimen/padding_sm"
app:setAdapter="@{viewModel.getAdapter()}"
tools:listitem="@layout/recycler_view_record" />
......
......@@ -34,37 +34,63 @@
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{viewModel.getPrivacyChoiceAt(position).privacyChoice.privacyContent.device.name}"
android:textColor="@color/colorLight"
android:text="@{viewModel.getPrivacyChoiceAt(position).privacyContent.device.name}"
android:textColor="@color/colorPrimary"
android:textSize="18sp"
android:textStyle="bold"
tools:text="@tools:sample/lorem" />
tools:text="溫度感測器" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/padding_sm"
android:paddingTop="@dimen/padding_xs"
android:paddingBottom="@dimen/padding_xs"
android:text='@{@string/privacy_version+" "+String.valueOf(position+1)}'
android:textSize="@dimen/font_sm"
tools:text="@tools:sample/lorem" />
tools:text="版本1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{viewModel.getPrivacyChoiceAt(position).privacyChoice.privacyContent.policy.description}"
tools:text="@tools:sample/lorem" />
android:text="@{viewModel.getPrivacyChoiceAt(position).privacyContent.policy.description}"
tools:text="本APP會蒐集使用者周遭溫度作為第三方資料之地區環境分析資料。" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{viewModel.getPrivacyChoiceAt(position).localDateTime.toString()}"
tools:text="@tools:sample/lorem" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_sm"
android:layout_marginBottom="@dimen/margin_sm"
android:textColor="@color/colorWhite"
android:background="@drawable/green_radius_background"
android:paddingLeft="@dimen/padding_sm"
android:paddingTop="@dimen/padding_xs"
android:paddingRight="@dimen/padding_sm"
android:paddingBottom="@dimen/padding_xs"
android:text="同意"
android:textSize="@dimen/font_sm"
tools:text="同意" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_sm"
android:layout_marginBottom="@dimen/margin_sm"
android:layout_marginLeft="@dimen/margin_sm"
android:background="@drawable/light_radius_background"
android:paddingLeft="@dimen/padding_sm"
android:paddingTop="@dimen/padding_xs"
android:paddingRight="@dimen/padding_sm"
android:paddingBottom="@dimen/padding_xs"
android:text="@{viewModel.getPrivacyChoiceAt(position).localDateTime}"
android:textSize="@dimen/font_sm"
tools:text="2019-01-12 13:52" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="同意或拒絕"
tools:text="@tools:sample/lorem" />
</LinearLayout>
</LinearLayout>
......
......@@ -10,5 +10,7 @@
<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>
</resources>
......@@ -33,6 +33,7 @@
<string name="privacy_content">拒絕/同意</string>
<string name="privacy_loading_title">隱私選擇儲存中</string>
<string name="privacy_loading_message">請稍後...</string>
<string name="privacy_loading_error">儲存失敗,請重新嘗試</string>
<!--Record-->
<string name="record_title">隱私選擇記錄</string>
......
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