Commit 1a4ddac9 authored by DESKTOP-NFGF3PG\zxa01's avatar DESKTOP-NFGF3PG\zxa01

update api

parent a97da2ea
...@@ -37,7 +37,7 @@ dependencies { ...@@ -37,7 +37,7 @@ dependencies {
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
// modelmapper // modelmapper
compile 'net.eunjae.android.modelmapper:ModelMapper:1.0.6' implementation 'net.eunjae.android.modelmapper:ModelMapper:1.0.6'
// rxjava // rxjava
implementation "io.reactivex:rxjava:1.1.8" implementation "io.reactivex:rxjava:1.1.8"
......
package com.example.zxa01.iotclient.component.login;
import android.support.test.espresso.ViewInteraction;
import android.support.test.filters.LargeTest;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import com.example.zxa01.iotclient.R;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.action.ViewActions.scrollTo;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withClassName;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.is;
@LargeTest
@RunWith(AndroidJUnit4.class)
public class BindTest {
@Rule
public ActivityTestRule<LoginActivity> mActivityTestRule = new ActivityTestRule<>(LoginActivity.class);
@Test
public void bindTest() {
ViewInteraction appCompatButton = onView(
allOf(withId(R.id.sign_in_button), withText("登入"),
childAtPosition(
childAtPosition(
withClassName(is("android.widget.ScrollView")),
0),
4)));
appCompatButton.perform(scrollTo(), click());
ViewInteraction floatingActionButton = onView(
allOf(withId(R.id.fab),
childAtPosition(
childAtPosition(
withId(R.id.home_fragment_layout),
0),
2),
isDisplayed()));
floatingActionButton.perform(click());
}
private static Matcher<View> childAtPosition(
final Matcher<View> parentMatcher, final int position) {
return new TypeSafeMatcher<View>() {
@Override
public void describeTo(Description description) {
description.appendText("Child at position " + position + " in parent ");
parentMatcher.describeTo(description);
}
@Override
public boolean matchesSafely(View view) {
ViewParent parent = view.getParent();
return parent instanceof ViewGroup && parentMatcher.matches(parent)
&& view.equals(((ViewGroup) parent).getChildAt(position));
}
};
}
}
...@@ -3,6 +3,7 @@ package com.example.zxa01.iotclient.common.bindings; ...@@ -3,6 +3,7 @@ package com.example.zxa01.iotclient.common.bindings;
import android.databinding.BindingAdapter; import android.databinding.BindingAdapter;
import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.view.View;
public class CustomViewBindings { public class CustomViewBindings {
...@@ -12,4 +13,5 @@ public class CustomViewBindings { ...@@ -12,4 +13,5 @@ public class CustomViewBindings {
recyclerView.setLayoutManager(new LinearLayoutManager(recyclerView.getContext())); recyclerView.setLayoutManager(new LinearLayoutManager(recyclerView.getContext()));
recyclerView.setAdapter(adapter); recyclerView.setAdapter(adapter);
} }
} }
package com.example.zxa01.iotclient.common.http; package com.example.zxa01.iotclient.common.http;
import com.example.zxa01.iotclient.common.pojo.device.Device; 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.privacy.PrivacyChoice;
import com.example.zxa01.iotclient.common.pojo.privacy.PrivacyPolicyReport; import com.example.zxa01.iotclient.common.pojo.privacy.PrivacyPolicyReport;
import com.example.zxa01.iotclient.common.shared.Config; import com.example.zxa01.iotclient.common.shared.Config;
...@@ -41,25 +42,33 @@ public class Api { ...@@ -41,25 +42,33 @@ public class Api {
public interface ApiInterface { public interface ApiInterface {
// 未使用
@POST("/api/breeds/list/all") @POST("/api/breeds/list/all")
Call<Object> login(); Call<Object> login();
// 取得與該gateway所綁定的裝置列表
@GET("/device") @GET("/device")
Call<List<Device>> getDevices(); Call<List<Device>> readDevices();
// 新增並綁定裝置與gateway
@POST("/device/{udn}")
Call<Device> bindDeviceAndGateway(@Path("udn") String udn);
// 取得該裝置相關資料
@GET("/device/{udn}") @GET("/device/{udn}")
Call<Device> readDevice(@Path("udn") String udn); Call<Device> readDevice(@Path("udn") String udn);
@GET("/device/privacy/{udn}") // 取得該裝置的隱私政策與相關資料
@GET("/privacy/{udn}")
Call<PrivacyPolicyReport> readPrivacyPolicyReportByDevice(@Path("udn") String udn); Call<PrivacyPolicyReport> readPrivacyPolicyReportByDevice(@Path("udn") String udn);
// 表達隱私偏好
@POST("/choice") @POST("/choice")
Call<PrivacyChoice> setPrivacyChoice(@Body PrivacyChoice privacyChoice); Call<PrivacyChoice> setPrivacyChoice(@Body PrivacyChoice privacyChoice);
// TODO // 取得隱私偏好記錄
@GET("/api/breeds/list/all") @GET("/choice")
Call<Object> getRecord(); Call<List<PrivacyChoiceIndex>> readPrivacyChoiceRecordsByUser();
} }
} }
package com.example.zxa01.iotclient.common.http;
import java.io.IOException;
import okhttp3.Call;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
public class HttpService {
public static final MediaType JSON
= MediaType.parse("application/json; charset=utf-8");
public String doGetSyncRequest(String url) throws IOException {
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url(url)
.build();
Call call = client.newCall(request);
Response mResponse=call.execute();
if (mResponse.isSuccessful()) {
return mResponse.body().string();
} else {
throw new IOException("Unexpected code " + mResponse);
}
// call.enqueue(new Callback(){
//
// @Override
// public void onFailure(Call call, IOException e) {
//
// }
//
// @Override
// public void onResponse(Call call, Response response) throws IOException {
// System.out.println(response);
// }
// });
// return client.newCall(
// new Request.Builder()
// .url(HttpUrl.parse(url).newBuilder().build().toString())
// .build()
// ).execute().body().string();
}
public String doPostRequest(String url, String json) throws IOException {
OkHttpClient client = new OkHttpClient();
return client.newCall(
new Request.Builder()
.url(url)
.post(RequestBody.create(JSON, json))
.build()
).execute().body().string();
}
}
package com.example.zxa01.iotclient.component.login.pojo; package com.example.zxa01.iotclient.common.pojo.auth;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
public class LoginMessage { public class LoginMessage {
...@@ -7,7 +7,7 @@ public class LoginMessage { ...@@ -7,7 +7,7 @@ public class LoginMessage {
private String account; private String account;
private String password; private String password;
public LoginMessage() { public LoginMessage(){
} }
......
...@@ -14,7 +14,7 @@ public class Device implements Parcelable { ...@@ -14,7 +14,7 @@ public class Device implements Parcelable {
private Type type; private Type type;
private Manufacturer manufacturer; private Manufacturer manufacturer;
private Model model; private Model model;
private String UPC; private String upc;
private String location; private String location;
private List<Icon> icons = new LinkedList<>(); private List<Icon> icons = new LinkedList<>();
private Status status; private Status status;
...@@ -37,7 +37,7 @@ public class Device implements Parcelable { ...@@ -37,7 +37,7 @@ public class Device implements Parcelable {
.setType(device.type) .setType(device.type)
.setManufacturer(device.manufacturer != null ? new Manufacturer(device.manufacturer) : null) .setManufacturer(device.manufacturer != null ? new Manufacturer(device.manufacturer) : null)
.setModel(device.model != null ? new Model(device.model) : null) .setModel(device.model != null ? new Model(device.model) : null)
.setUPC(device.UPC) .setUpc(device.upc)
.setLocation(device.location) .setLocation(device.location)
.setStatus(device.status); .setStatus(device.status);
} }
...@@ -48,7 +48,7 @@ public class Device implements Parcelable { ...@@ -48,7 +48,7 @@ public class Device implements Parcelable {
type = Type.valueOf(in.readString()); type = Type.valueOf(in.readString());
manufacturer = in.readParcelable(Manufacturer.class.getClassLoader()); manufacturer = in.readParcelable(Manufacturer.class.getClassLoader());
model = in.readParcelable(Model.class.getClassLoader()); model = in.readParcelable(Model.class.getClassLoader());
UPC = in.readString(); upc = in.readString();
location = in.readString(); location = in.readString();
icons = in.createTypedArrayList(Icon.CREATOR); icons = in.createTypedArrayList(Icon.CREATOR);
status = Status.valueOf(in.readString()); status = Status.valueOf(in.readString());
...@@ -61,7 +61,7 @@ public class Device implements Parcelable { ...@@ -61,7 +61,7 @@ public class Device implements Parcelable {
dest.writeString(type.name()); dest.writeString(type.name());
dest.writeParcelable(manufacturer, flags); dest.writeParcelable(manufacturer, flags);
dest.writeParcelable(model, flags); dest.writeParcelable(model, flags);
dest.writeString(UPC); dest.writeString(upc);
dest.writeString(location); dest.writeString(location);
dest.writeTypedList(icons); dest.writeTypedList(icons);
dest.writeString(status.name()); dest.writeString(status.name());
...@@ -129,12 +129,12 @@ public class Device implements Parcelable { ...@@ -129,12 +129,12 @@ public class Device implements Parcelable {
return this; return this;
} }
public String getUPC() { public String getUpc() {
return UPC; return upc;
} }
public Device setUPC(String UPC) { public Device setUpc(String upc) {
this.UPC = UPC; this.upc = upc;
return this; return this;
} }
...@@ -197,7 +197,7 @@ public class Device implements Parcelable { ...@@ -197,7 +197,7 @@ public class Device implements Parcelable {
", type=" + type + ", type=" + type +
", manufacturer=" + manufacturer + ", manufacturer=" + manufacturer +
", model=" + model + ", model=" + model +
", UPC='" + UPC + '\'' + ", UPC='" + upc + '\'' +
", location='" + location + '\'' + ", location='" + location + '\'' +
", icons=" + icons + ", icons=" + icons +
", status=" + status + ", status=" + status +
......
package com.example.zxa01.iotclient.common.pojo.index;
public class DeviceIndex {
private String udn;
public DeviceIndex(){
}
public String getUdn() {
return udn;
}
public void setUdn(String udn) {
this.udn = udn;
}
}
package com.example.zxa01.iotclient.common.pojo.index;
import com.example.zxa01.iotclient.common.pojo.privacy.PrivacyChoice;
import java.time.LocalDateTime;
public class PrivacyChoiceIndex {
private long id;
private LocalDateTime localDateTime;
private PrivacyChoice privacyChoice;
public PrivacyChoiceIndex(){
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public LocalDateTime getLocalDateTime() {
return localDateTime;
}
public void setLocalDateTime(LocalDateTime localDateTime) {
this.localDateTime = localDateTime;
}
public PrivacyChoice getPrivacyChoice() {
return privacyChoice;
}
public void setPrivacyChoice(PrivacyChoice privacyChoice) {
this.privacyChoice = privacyChoice;
}
}
package com.example.zxa01.iotclient.common.shared;
import com.example.zxa01.iotclient.common.pojo.auth.LoginMessage;
public class DefaultData {
private static DefaultData defaultData = new DefaultData();
private LoginMessage loginMessage;
private DefaultData() {
loginMessage = new LoginMessage("192.168.2.69:8080", "user", "1234");
}
public static DefaultData getDefaultData() {
return defaultData;
}
public LoginMessage getLoginMessage() {
return loginMessage;
}
}
...@@ -2,12 +2,12 @@ package com.example.zxa01.iotclient.component.detail; ...@@ -2,12 +2,12 @@ package com.example.zxa01.iotclient.component.detail;
import android.arch.lifecycle.MutableLiveData; import android.arch.lifecycle.MutableLiveData;
import android.databinding.BaseObservable; import android.databinding.BaseObservable;
import android.support.annotation.NonNull;
import android.util.Log; import android.util.Log;
import com.example.zxa01.iotclient.common.http.Api; 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.Device;
import com.example.zxa01.iotclient.common.pojo.device.Manufacturer; import com.example.zxa01.iotclient.common.pojo.privacy.PrivacyPolicyReport;
import com.example.zxa01.iotclient.common.pojo.device.Model;
import retrofit2.Call; import retrofit2.Call;
import retrofit2.Callback; import retrofit2.Callback;
...@@ -24,13 +24,12 @@ public class DetailModel extends BaseObservable { ...@@ -24,13 +24,12 @@ public class DetailModel extends BaseObservable {
return deviceMLD; return deviceMLD;
} }
public void setDeviceMLD(Device device) { public void setDeviceMLD(@NonNull Device device) {
deviceMLD.setValue(device); deviceMLD.setValue(device);
} }
public void readDevice(String udn) { public void readDevice(@NonNull String udn) {
// TODO instead of udn Api.getApi().readDevice(udn).enqueue(new Callback<Device>() {
Api.getApi().readDevice("1").enqueue(new Callback<Device>() {
@Override @Override
public void onResponse(Call<Device> call, Response<Device> response) { public void onResponse(Call<Device> call, Response<Device> response) {
setDeviceMLD(response == null || response.body() == null ? setDeviceMLD(response == null || response.body() == null ?
...@@ -39,7 +38,7 @@ public class DetailModel extends BaseObservable { ...@@ -39,7 +38,7 @@ public class DetailModel extends BaseObservable {
@Override @Override
public void onFailure(Call<Device> call, Throwable t) { public void onFailure(Call<Device> call, Throwable t) {
Log.e("fetchDevice - onFailure()", t.getMessage(), t); Log.e("readDevice - onFailure()", t.getMessage(), t);
} }
}); });
......
...@@ -9,6 +9,7 @@ import android.content.Context; ...@@ -9,6 +9,7 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.databinding.ObservableBoolean; import android.databinding.ObservableBoolean;
import android.databinding.ObservableField; import android.databinding.ObservableField;
import android.support.annotation.NonNull;
import android.view.Gravity; import android.view.Gravity;
import android.widget.Toast; import android.widget.Toast;
...@@ -20,11 +21,11 @@ public class DetailViewModel extends ViewModel { ...@@ -20,11 +21,11 @@ public class DetailViewModel extends ViewModel {
private Context context; private Context context;
public DetailViewModel(Context context) { public DetailViewModel(Context context) {
this.device.set(new Device());
this.context = context; this.context = context;
device.set(new Device());
} }
public void fetchDevice(String udn) { public void fetchDevice(@NonNull String udn) {
detailModel.readDevice(udn); detailModel.readDevice(udn);
} }
...@@ -32,9 +33,9 @@ public class DetailViewModel extends ViewModel { ...@@ -32,9 +33,9 @@ public class DetailViewModel extends ViewModel {
return detailModel.getDeviceMLD(); return detailModel.getDeviceMLD();
} }
public void setDevice(Device device) { public void setDevice(@NonNull Device device) {
if (device != null && device.getUdn() != null) { if (device.getUdn() != null) {
this.isLoading.set(false); isLoading.set(false);
this.device.set(device); this.device.set(device);
} }
} }
......
package com.example.zxa01.iotclient.component.home; package com.example.zxa01.iotclient.component.home;
import com.example.zxa01.iotclient.R; import com.example.zxa01.iotclient.R;
import com.example.zxa01.iotclient.component.home.device.DeviceViewModel; import com.example.zxa01.iotclient.component.home.device.bind.DeviceBindViewModel;
import com.example.zxa01.iotclient.databinding.ActivityHomeBinding; import com.example.zxa01.iotclient.databinding.ActivityHomeBinding;
import com.example.zxa01.iotclient.component.home.device.DeviceFragment; import com.example.zxa01.iotclient.component.home.device.DeviceFragment;
import com.example.zxa01.iotclient.component.home.record.RecordFragment; import com.example.zxa01.iotclient.component.home.record.RecordFragment;
import com.example.zxa01.iotclient.component.home.setting.SettingFragment; import com.example.zxa01.iotclient.component.home.setting.SettingFragment;
import android.content.Intent; import android.content.Intent;
import android.graphics.drawable.GradientDrawable;
import android.os.Bundle; import android.os.Bundle;
import android.support.design.widget.BottomNavigationView; import android.support.design.widget.BottomNavigationView;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
...@@ -73,10 +72,10 @@ public class HomeActivity extends AppCompatActivity { ...@@ -73,10 +72,10 @@ public class HomeActivity extends AppCompatActivity {
@Override @Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) { public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (resultCode == RESULT_OK) { if (resultCode == RESULT_OK) {
new DeviceViewModel().createDevice(intent.getStringExtra("SCAN_RESULT")); new DeviceBindViewModel().bindDeviceAndGateway(intent.getStringExtra("SCAN_RESULT"));
} else { } else {
new AlertDialog.Builder(this) new AlertDialog.Builder(this)
.setMessage(R.string.create_qrcode_error) .setMessage(R.string.bind_qrcode_error)
.show(); .show();
} }
} }
......
package com.example.zxa01.iotclient.component.home.device; package com.example.zxa01.iotclient.component.home.device;
import android.content.Context;
import android.databinding.DataBindingUtil; import android.databinding.DataBindingUtil;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
...@@ -12,7 +11,7 @@ import android.view.ViewGroup; ...@@ -12,7 +11,7 @@ import android.view.ViewGroup;
import com.example.zxa01.iotclient.R; import com.example.zxa01.iotclient.R;
import com.example.zxa01.iotclient.databinding.FragmentDeviceBinding; import com.example.zxa01.iotclient.databinding.FragmentDeviceBinding;
import com.example.zxa01.iotclient.component.home.device.create.DeviceCreateFragment; import com.example.zxa01.iotclient.component.home.device.bind.DeviceBindFragment;
public class DeviceFragment extends Fragment { public class DeviceFragment extends Fragment {
...@@ -51,7 +50,7 @@ public class DeviceFragment extends Fragment { ...@@ -51,7 +50,7 @@ public class DeviceFragment extends Fragment {
fragmentTransaction.remove(fragment); fragmentTransaction.remove(fragment);
} }
fragmentTransaction.addToBackStack(null); fragmentTransaction.addToBackStack(null);
new DeviceCreateFragment().show(fragmentTransaction, String.valueOf(R.string.dialog)); new DeviceBindFragment().show(fragmentTransaction, String.valueOf(R.string.dialog));
} }
......
...@@ -26,7 +26,7 @@ public class DeviceModel extends BaseObservable { ...@@ -26,7 +26,7 @@ public class DeviceModel extends BaseObservable {
} }
public void readDevices() { public void readDevices() {
Api.getApi().getDevices().enqueue( Api.getApi().readDevices().enqueue(
new Callback<List<Device>>() { new Callback<List<Device>>() {
@Override @Override
public void onResponse(Call<List<Device>> call, Response<List<Device>> response) { public void onResponse(Call<List<Device>> call, Response<List<Device>> response) {
...@@ -42,22 +42,5 @@ public class DeviceModel extends BaseObservable { ...@@ -42,22 +42,5 @@ public class DeviceModel extends BaseObservable {
); );
} }
public void createDevice(String udn) {
// TODO api post-createDevice & update
// Api.getApi().getDevices().enqueue(
//// new Callback<List<Device>>() {
//// @Override
//// public void onResponse(Call<List<Device>> call, Response<List<Device>> response) {
//// devicesMLD.setValue(response == null || response.body() == null ?
//// null : response.body().stream().collect(Collectors.toList()));
//// }
////
//// @Override
//// public void onFailure(Call<List<Device>> call, Throwable t) {
//// Log.e("readDevices - onFailure()", t.getMessage(), t);
//// }
//// }
//// );
}
} }
...@@ -9,13 +9,13 @@ import android.arch.lifecycle.ViewModel; ...@@ -9,13 +9,13 @@ import android.arch.lifecycle.ViewModel;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.databinding.ObservableBoolean; import android.databinding.ObservableBoolean;
import android.support.annotation.NonNull;
import java.util.List; import java.util.List;
public class DeviceViewModel extends ViewModel { public class DeviceViewModel extends ViewModel {
public ObservableBoolean isLoading = new ObservableBoolean(true); public ObservableBoolean isLoading = new ObservableBoolean(true);
private DeviceModel deviceModel = new DeviceModel(); private DeviceModel deviceModel = new DeviceModel();
private DeviceAdapter adapter = new DeviceAdapter(R.layout.recycler_view_device, this); private DeviceAdapter adapter = new DeviceAdapter(R.layout.recycler_view_device, this);
private Context context; private Context context;
...@@ -24,9 +24,6 @@ public class DeviceViewModel extends ViewModel { ...@@ -24,9 +24,6 @@ public class DeviceViewModel extends ViewModel {
this.context = context; this.context = context;
} }
public DeviceViewModel() {
}
/** /**
* model * model
*/ */
...@@ -39,31 +36,20 @@ public class DeviceViewModel extends ViewModel { ...@@ -39,31 +36,20 @@ public class DeviceViewModel extends ViewModel {
return deviceModel.getDevicesMLD(); return deviceModel.getDevicesMLD();
} }
/**
* create
*/
public void createDevice(String udn) {
deviceModel.createDevice(udn);
readDevices();
}
/** /**
* child model * child model
*/ */
public Device getDeviceAt(Integer index) { public Device getDeviceAt(@NonNull Integer index) {
if (deviceModel.getDevicesMLD().getValue() != null && if (deviceModel.getDevicesMLD().getValue() != null &&
index != null &&
deviceModel.getDevicesMLD().getValue().size() > index) { deviceModel.getDevicesMLD().getValue().size() > index) {
return deviceModel.getDevicesMLD().getValue().get(index); return deviceModel.getDevicesMLD().getValue().get(index);
} }
return null; return null;
} }
public void onDevicesClick(Integer index) { public void onDevicesClick(@NonNull Integer index) {
if (deviceModel.getDevicesMLD().getValue() != null && if (deviceModel.getDevicesMLD().getValue() != null &&
index != null &&
deviceModel.getDevicesMLD().getValue().size() > index) { deviceModel.getDevicesMLD().getValue().size() > index) {
context.startActivity( context.startActivity(
new Intent(context, DetailActivity.class) new Intent(context, DetailActivity.class)
......
package com.example.zxa01.iotclient.component.home.device.bind;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.example.zxa01.iotclient.R;
import com.example.zxa01.iotclient.databinding.FragmentDeviceBindBinding;
public class DeviceBindFragment extends DialogFragment {
private DeviceBindViewModel viewModel;
private FragmentDeviceBindBinding binding;
public DeviceBindFragment() {
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
binding = DataBindingUtil.inflate(inflater, R.layout.fragment_device_bind, container, false);
binding();
return binding.getRoot();
}
private void binding() {
viewModel = new DeviceBindViewModel(this);
binding.setViewModel(viewModel);
}
}
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.pojo.device.Device;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
public class DeviceBindModel extends BaseObservable {
public DeviceBindModel() {
}
public void bindDeviceAndGateway(@NonNull String udn) {
Api.getApi().bindDeviceAndGateway(udn).enqueue(
new Callback<Device>() {
@Override
public void onResponse(Call<Device> call, Response<Device> response) {
}
@Override
public void onFailure(Call<Device> call, Throwable t) {
Log.e("bindDeviceAndGateway - onFailure()", t.getMessage(), t);
}
}
);
}
}
package com.example.zxa01.iotclient.component.home.device.bind;
import android.arch.lifecycle.MutableLiveData;
import android.arch.lifecycle.ViewModel;
import android.content.Intent;
import android.databinding.ObservableBoolean;
import android.databinding.ObservableField;
import android.net.Uri;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
public class DeviceBindViewModel extends ViewModel {
private static final String QRCODE_MARKET = "market://details?id=com.google.zxing.client.android";
private static final String QRCODE_INTENT = "com.google.zxing.client.android.SCAN";
private static final String QRCODE_MODE = "SCAN_MODE";
private static final String QRCODE_CODE_MODE = "QR_CODE_MODE";
private static final int QRCODE_REQUEST_CODE = 0;
public ObservableField<String> udn = new ObservableField<>();
private DeviceBindModel deviceBindModel = new DeviceBindModel();
private Fragment fragment;
public DeviceBindViewModel() {
}
public DeviceBindViewModel(Fragment fragment) {
this.fragment = fragment;
}
/**
* button function
*/
public void bindDeviceAndGateway(String udn) {
deviceBindModel.bindDeviceAndGateway(udn);
}
public void bindDeviceAndGateway() {
deviceBindModel.bindDeviceAndGateway(udn.get());
}
public void qrcode() {
try {
fragment.startActivityForResult(
new Intent(QRCODE_INTENT)
.putExtra(QRCODE_MODE, QRCODE_CODE_MODE)
, QRCODE_REQUEST_CODE);
} catch (Exception e) {
fragment.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(QRCODE_MARKET)));
}
}
public void cancel() {
((DeviceBindFragment) fragment).dismiss();
}
}
package com.example.zxa01.iotclient.component.home.device.create;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.example.zxa01.iotclient.R;
import com.example.zxa01.iotclient.databinding.FragmentDeviceCreateBinding;
import com.example.zxa01.iotclient.component.home.device.DeviceViewModel;
public class DeviceCreateFragment extends DialogFragment {
private static final String QRCODE_MARKET = "market://details?id=com.google.zxing.client.android";
private static final String QRCODE_INTENT = "com.google.zxing.client.android.SCAN";
private static final String QRCODE_MODE = "SCAN_MODE";
private static final String QRCODE_CODE_MODE = "QR_CODE_MODE";
private static final int QRCODE_REQUEST_CODE = 0;
private DeviceViewModel viewModel;
private FragmentDeviceCreateBinding binding;
public DeviceCreateFragment() {
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
return new AlertDialog.Builder(getActivity())
.setView(R.layout.fragment_device_create)
.setNeutralButton(R.string.create_button_qrcode,
(dialog, whichButton) -> qrcodeIntent()
)
.setPositiveButton(R.string.create_button_correct,
(dialog, whichButton) -> viewModel.createDevice("address")
)
.setNegativeButton(R.string.create_button_cancel, (dialog, whichButton) -> {
})
.create();
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
binding = DataBindingUtil.inflate(inflater, R.layout.fragment_device_create, container, false);
binding();
return binding.getRoot();
}
private void binding() {
viewModel = new DeviceViewModel(binding.getRoot().getContext());
binding.setViewModel(viewModel);
}
private void qrcodeIntent() {
try {
startActivityForResult(
new Intent(QRCODE_INTENT)
.putExtra(QRCODE_MODE, QRCODE_CODE_MODE)
, QRCODE_REQUEST_CODE);
} catch (Exception e) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(QRCODE_MARKET)));
}
}
}
...@@ -8,14 +8,14 @@ import android.support.v7.widget.RecyclerView; ...@@ -8,14 +8,14 @@ import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.ViewGroup; import android.view.ViewGroup;
import com.example.zxa01.iotclient.BR; import com.example.zxa01.iotclient.BR;
import com.example.zxa01.iotclient.common.pojo.privacy.PrivacyPolicyReport; import com.example.zxa01.iotclient.common.pojo.index.PrivacyChoiceIndex;
import java.util.List; import java.util.List;
public class RecordAdapter extends RecyclerView.Adapter<RecordAdapter.MyViewHolder> { public class RecordAdapter extends RecyclerView.Adapter<RecordAdapter.MyViewHolder> {
private int layoutId; private int layoutId;
private List<PrivacyPolicyReport> privacyPolicyReports; private List<PrivacyChoiceIndex> privacyChoiceIndices;
private RecordViewModel viewModel; private RecordViewModel viewModel;
public RecordAdapter(@LayoutRes int layoutId, RecordViewModel viewModel) { public RecordAdapter(@LayoutRes int layoutId, RecordViewModel viewModel) {
...@@ -40,7 +40,7 @@ public class RecordAdapter extends RecyclerView.Adapter<RecordAdapter.MyViewHold ...@@ -40,7 +40,7 @@ public class RecordAdapter extends RecyclerView.Adapter<RecordAdapter.MyViewHold
@Override @Override
public int getItemCount() { public int getItemCount() {
return privacyPolicyReports == null ? 0 : privacyPolicyReports.size(); return privacyChoiceIndices == null ? 0 : privacyChoiceIndices.size();
} }
@Override @Override
...@@ -48,8 +48,8 @@ public class RecordAdapter extends RecyclerView.Adapter<RecordAdapter.MyViewHold ...@@ -48,8 +48,8 @@ public class RecordAdapter extends RecyclerView.Adapter<RecordAdapter.MyViewHold
return getLayoutIdForPosition(position); return getLayoutIdForPosition(position);
} }
public void setPrivacyPolicyReports(List<PrivacyPolicyReport> privacyPolicyReports) { public void setPrivacyChoiceIndices(List<PrivacyChoiceIndex> privacyChoiceIndices) {
this.privacyPolicyReports = privacyPolicyReports; this.privacyChoiceIndices = privacyChoiceIndices;
} }
class MyViewHolder extends RecyclerView.ViewHolder { class MyViewHolder extends RecyclerView.ViewHolder {
...@@ -62,7 +62,7 @@ public class RecordAdapter extends RecyclerView.Adapter<RecordAdapter.MyViewHold ...@@ -62,7 +62,7 @@ public class RecordAdapter extends RecyclerView.Adapter<RecordAdapter.MyViewHold
} }
void bind(RecordViewModel viewModel, Integer position) { void bind(RecordViewModel viewModel, Integer position) {
viewModel.getPrivacyPolicyReportAt(position); viewModel.getPrivacyChoiceAt(position);
binding.setVariable(BR.viewModel, viewModel); binding.setVariable(BR.viewModel, viewModel);
binding.setVariable(BR.position, position); binding.setVariable(BR.position, position);
binding.executePendingBindings(); binding.executePendingBindings();
......
package com.example.zxa01.iotclient.component.home.record; package com.example.zxa01.iotclient.component.home.record;
import android.content.Context;
import android.databinding.DataBindingUtil; import android.databinding.DataBindingUtil;
import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.LinearLayoutManager;
...@@ -24,17 +22,21 @@ public class RecordFragment extends Fragment { ...@@ -24,17 +22,21 @@ public class RecordFragment extends Fragment {
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {
this.binding = DataBindingUtil.inflate(inflater, R.layout.fragment_record, container, false); binding = DataBindingUtil.inflate(inflater, R.layout.fragment_record, container, false);
this.viewModel = new RecordViewModel(binding.getRoot().getContext()); binding();
this.binding.setViewModel(viewModel);
this.binding.recordRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
init(); init();
return binding.getRoot(); return binding.getRoot();
} }
private void binding() {
viewModel = new RecordViewModel(binding.getRoot().getContext());
binding.setViewModel(viewModel);
binding.recordRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
}
private void init() { private void init() {
this.viewModel.refreshRecord(); viewModel.refreshRecord();
this.viewModel.observePrivacyPolicyReportsMLD().observe(this, viewModel::setAdapter); viewModel.observePrivacyChoiceIndicesMLD().observe(this, viewModel::setAdapter);
} }
} }
...@@ -8,6 +8,7 @@ import com.example.zxa01.iotclient.common.http.Api; ...@@ -8,6 +8,7 @@ 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.Device;
import com.example.zxa01.iotclient.common.pojo.device.Manufacturer; 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.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.PrivacyPolicy;
import com.example.zxa01.iotclient.common.pojo.privacy.PrivacyPolicyReport; 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.Access;
...@@ -22,6 +23,7 @@ import com.example.zxa01.iotclient.common.pojo.privacy.p3p.Statement; ...@@ -22,6 +23,7 @@ import com.example.zxa01.iotclient.common.pojo.privacy.p3p.Statement;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
import retrofit2.Call; import retrofit2.Call;
import retrofit2.Callback; import retrofit2.Callback;
...@@ -29,111 +31,33 @@ import retrofit2.Response; ...@@ -29,111 +31,33 @@ import retrofit2.Response;
public class RecordModel extends BaseObservable { public class RecordModel extends BaseObservable {
private List<PrivacyPolicyReport> privacyPolicyReports = new ArrayList<>(); private List<PrivacyChoiceIndex> privacyChoiceIndices = new ArrayList<>();
private MutableLiveData<List<PrivacyPolicyReport>> privacyPolicyReportsMLD = new MutableLiveData<>(); private MutableLiveData<List<PrivacyChoiceIndex>> privacyChoiceIndicesMLD = new MutableLiveData<>();
private Device oxygenDevice = new Device() public RecordModel() {
.setUdn("a1252c49-4188-4e6d-a32e-66604c664fb8")
.setName("指尖式血氧機")
.setType(Device.Type.Sensor)
.setManufacturer(new Manufacturer()
.setName("Facelake")
.setSerialNumber("3176927193")
.setUrl("http://facelake.com"))
.setModel(new Model()
.setName("指尖式血氧機")
.setDescription("本設備是為符合不同領域及照護應用而設計,並把這些特色融入小如指節的分析儀中,可在數秒內量測出準確可靠的血氧及心跳值。")
.setUrl("https://www.amazon.com/Pulse-Oximeter-Blood-Oxygen-Monitor/dp/B00HXXO332"))
.setUPC("B00HXXO332")
.setLocation("25.013068, 121.541651")
.setStatus(Device.Status.Disconnected);
private PrivacyPolicyReport oxygenPrivacyPolicyReport = new PrivacyPolicyReport()
.setId("0cfb6be3-6f0f-4e63-85b8-e9c936707c0b")
.setVersion("1.0")
.setDescription("為提供您最佳的互動照護服務,本APP部分服務內容可能會請您提供心跳資訊及血氧飽和度資訊,以作為持續自動追蹤心率的技術,提供整日健康狀況的深入分析以及運動強度的資訊。")
.setDevice(oxygenDevice)
.addPrivacyPolicy(new PrivacyPolicy()
.setId("119df569-06b1-4d63-84cd-bde7c9e4ab7e")
.setDescription("為提供您最佳的互動照護服務,本APP部分服務內容可能會請您提供血氧飽和度資訊,以作為呼吸系統疾病、循環系統疾病、其它治療、檢查引起的損傷之遠端醫療照護分析資料。")
.setCollector(new Collector()
.setName("健康促進中心")
.setEmail("[email protected]")
.setPhone("0988415875"))
.setAccess(Access.OTHER_IDENT)
.setDispute(new Dispute()
.setRelatedOrganization("地方法院")
.setType(Dispute.Type.LAW))
.addRemedy(new Remedy()
.setType(Remedy.Type.LAW))
.addStatement(new Statement()
.setConsequence("a1252c49-4188-4e6d-a32e-66604c664fb9")
.addPurpose(new Purpose()
.setType(Purpose.Type.PSEUDO_ANALYSIS)
.setDescription("本APP會使用者蒐集血氧飽和度資訊作為呼吸系統疾病、循環系統疾病、其它治療、檢查引起的損傷之遠端醫療照護分析資料。"))
.addDatum(new Datum()
.setType(Datum.Type.HEALTH)
.setDescription("血氧飽和度資訊"))
.addRecipient(new Recipient()
.setEntity("健康促進中心")
.setType(Recipient.Type.OURS))
.setRetention(Retention.STATED_PURPOSE)))
.addPrivacyPolicy(new PrivacyPolicy()
.setId("abe5ca7b-780e-4857-87e6-014870fe0a3f")
.setDescription("為提供您最佳的互動照護服務,本APP會蒐集使用者心跳資訊,作為持續自動追蹤心率的技術,提供整日健康狀況的深入分析以及運動強度的資訊。")
.setCollector(new Collector()
.setName("健康促進中心")
.setEmail("[email protected]")
.setPhone("0988415875"))
.setAccess(Access.OTHER_IDENT)
.setDispute(new Dispute()
.setRelatedOrganization("地方法院")
.setType(Dispute.Type.LAW))
.addRemedy(new Remedy()
.setType(Remedy.Type.CORRECT))
.addRemedy(new Remedy()
.setType(Remedy.Type.LAW))
.addRemedy(new Remedy()
.setType(Remedy.Type.MONEY))
.addStatement(new Statement()
.setConsequence("a1252c49-4188-4e6d-a32e-66604c664fba")
.addPurpose(new Purpose()
.setType(Purpose.Type.INDIVIDUAL_ANALYSIS)
.setDescription("本APP會蒐集使用者心跳資訊,作為持續自動追蹤心率的技術,提供整日健康狀況的深入分析以及運動強度的資訊。"))
.addDatum(new Datum()
.setType(Datum.Type.HEALTH)
.setDescription("心跳資訊"))
.addRecipient(new Recipient()
.setEntity("健康促進中心")
.setType(Recipient.Type.OURS))
.setRetention(Retention.STATED_PURPOSE)));
public RecordModel(){
} }
private void addPrivacyPolicyReport(PrivacyPolicyReport privacyPolicyReport){ private void addPrivacyChoiceIndices(PrivacyChoiceIndex privacyChoiceIndex) {
privacyPolicyReports.add(privacyPolicyReport); privacyChoiceIndices.add(privacyChoiceIndex);
} }
public MutableLiveData<List<PrivacyPolicyReport>> getPrivacyPolicyReportsMLD() { public MutableLiveData<List<PrivacyChoiceIndex>> getPrivacyChoiceIndicesMLD() {
return privacyPolicyReportsMLD; return privacyChoiceIndicesMLD;
} }
public void fetchRecord() { public void fetchRecord() {
Callback<Object> callback = new Callback<Object>() { Api.getApi().readPrivacyChoiceRecordsByUser().enqueue(new Callback<List<PrivacyChoiceIndex>>() {
@Override @Override
public void onResponse(Call<Object> call, Response<Object> response) { public void onResponse(Call<List<PrivacyChoiceIndex>> call, Response<List<PrivacyChoiceIndex>> response) {
// TODO transfer response // TODO transfer response
addPrivacyPolicyReport(oxygenPrivacyPolicyReport); privacyChoiceIndicesMLD.setValue(response == null || response.body() == null ?
privacyPolicyReportsMLD.setValue(privacyPolicyReports); null : response.body().stream().collect(Collectors.toList()));
} }
@Override @Override
public void onFailure(Call<Object> call, Throwable t) { public void onFailure(Call<List<PrivacyChoiceIndex>> call, Throwable t) {
Log.e("fetchDevices - onFailure()", t.getMessage(), t);
} }
}; });
Api.getApi().getRecord().enqueue(callback);
} }
......
...@@ -5,9 +5,10 @@ import android.arch.lifecycle.ViewModel; ...@@ -5,9 +5,10 @@ import android.arch.lifecycle.ViewModel;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.databinding.ObservableBoolean; import android.databinding.ObservableBoolean;
import android.support.annotation.NonNull;
import com.example.zxa01.iotclient.R; import com.example.zxa01.iotclient.R;
import com.example.zxa01.iotclient.common.pojo.privacy.PrivacyPolicyReport; import com.example.zxa01.iotclient.common.pojo.index.PrivacyChoiceIndex;
import com.example.zxa01.iotclient.component.privacy.PrivacyActivity; import com.example.zxa01.iotclient.component.privacy.PrivacyActivity;
import java.util.List; import java.util.List;
...@@ -31,31 +32,30 @@ public class RecordViewModel extends ViewModel { ...@@ -31,31 +32,30 @@ public class RecordViewModel extends ViewModel {
recordModel.fetchRecord(); recordModel.fetchRecord();
} }
public MutableLiveData<List<PrivacyPolicyReport>> observePrivacyPolicyReportsMLD() { public MutableLiveData<List<PrivacyChoiceIndex>> observePrivacyChoiceIndicesMLD() {
return recordModel.getPrivacyPolicyReportsMLD(); return recordModel.getPrivacyChoiceIndicesMLD();
} }
/** /**
* child model * child model
*/ */
public PrivacyPolicyReport getPrivacyPolicyReportAt(Integer index) { public PrivacyChoiceIndex getPrivacyChoiceAt(@NonNull Integer index) {
if (recordModel.getPrivacyPolicyReportsMLD().getValue() != null && if (recordModel.getPrivacyChoiceIndicesMLD().getValue() != null &&
index != null && recordModel.getPrivacyChoiceIndicesMLD().getValue().size() > index) {
recordModel.getPrivacyPolicyReportsMLD().getValue().size() > index) { return recordModel.getPrivacyChoiceIndicesMLD().getValue().get(index);
return recordModel.getPrivacyPolicyReportsMLD().getValue().get(index);
} }
return null; return null;
} }
public void onPrivacyPolicyReportClick(Integer index) { public void onPrivacyChoiceClick(@NonNull Integer index) {
if (recordModel.getPrivacyPolicyReportsMLD().getValue() != null && if (recordModel.getPrivacyChoiceIndicesMLD().getValue() != null &&
index != null && recordModel.getPrivacyChoiceIndicesMLD().getValue().size() > index) {
recordModel.getPrivacyPolicyReportsMLD().getValue().size() > index) {
// TODO detail of device
context.startActivity( context.startActivity(
new Intent(context, PrivacyActivity.class) new Intent(context, PrivacyActivity.class)
.putExtra("index", index)); .putExtra("udn",
recordModel.getPrivacyChoiceIndicesMLD().getValue().get(index)
.getPrivacyChoice().getPrivacyContent().getDevice().getUdn()));
} }
} }
...@@ -67,9 +67,9 @@ public class RecordViewModel extends ViewModel { ...@@ -67,9 +67,9 @@ public class RecordViewModel extends ViewModel {
return adapter; return adapter;
} }
public void setAdapter(List<PrivacyPolicyReport> privacyPolicyReports) { public void setAdapter(List<PrivacyChoiceIndex> privacyChoiceIndices) {
isLoading.set(false); isLoading.set(false);
adapter.setPrivacyPolicyReports(privacyPolicyReports); adapter.setPrivacyChoiceIndices(privacyChoiceIndices);
} }
} }
...@@ -5,6 +5,7 @@ import android.arch.lifecycle.ViewModel; ...@@ -5,6 +5,7 @@ import android.arch.lifecycle.ViewModel;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.databinding.ObservableBoolean; import android.databinding.ObservableBoolean;
import android.support.annotation.NonNull;
import com.example.zxa01.iotclient.R; import com.example.zxa01.iotclient.R;
import com.example.zxa01.iotclient.common.pojo.Setting; import com.example.zxa01.iotclient.common.pojo.Setting;
......
package com.example.zxa01.iotclient.component.login; package com.example.zxa01.iotclient.component.login;
import com.example.zxa01.iotclient.common.http.Api;
import com.example.zxa01.iotclient.common.pojo.Setting; import com.example.zxa01.iotclient.common.pojo.Setting;
import com.example.zxa01.iotclient.common.pojo.auth.User; import com.example.zxa01.iotclient.common.pojo.auth.User;
import com.example.zxa01.iotclient.common.shared.Config; import com.example.zxa01.iotclient.common.shared.Config;
import com.example.zxa01.iotclient.component.login.pojo.LoginMessage; import com.example.zxa01.iotclient.common.pojo.auth.LoginMessage;
import android.arch.lifecycle.MutableLiveData; import android.arch.lifecycle.MutableLiveData;
import android.databinding.BaseObservable; import android.databinding.BaseObservable;
...@@ -17,7 +15,6 @@ public class LoginModel extends BaseObservable { ...@@ -17,7 +15,6 @@ public class LoginModel extends BaseObservable {
public LoginModel() { public LoginModel() {
isAuthorized = new MutableLiveData<>(); isAuthorized = new MutableLiveData<>();
isAuthorized.setValue(false); isAuthorized.setValue(false);
} }
public MutableLiveData<Boolean> isAuthorized() { public MutableLiveData<Boolean> isAuthorized() {
......
package com.example.zxa01.iotclient.component.login; package com.example.zxa01.iotclient.component.login;
import com.example.zxa01.iotclient.common.shared.DefaultData;
import com.example.zxa01.iotclient.component.home.HomeActivity; import com.example.zxa01.iotclient.component.home.HomeActivity;
import com.example.zxa01.iotclient.component.login.pojo.LoginMessage; import com.example.zxa01.iotclient.common.pojo.auth.LoginMessage;
import android.arch.lifecycle.MutableLiveData; import android.arch.lifecycle.MutableLiveData;
import android.arch.lifecycle.ViewModel; import android.arch.lifecycle.ViewModel;
import android.content.Context; import android.content.Context;
...@@ -11,12 +13,12 @@ import android.databinding.ObservableField; ...@@ -11,12 +13,12 @@ import android.databinding.ObservableField;
public class LoginViewModel extends ViewModel { public class LoginViewModel extends ViewModel {
public ObservableField<LoginMessage> loginMessage = new ObservableField<>(); public ObservableField<LoginMessage> loginMessage = new ObservableField<>();
private Context context;
private LoginModel loginModel = new LoginModel(); private LoginModel loginModel = new LoginModel();
private Context context;
public LoginViewModel(Context context) { public LoginViewModel(Context context) {
this.context = context; this.context = context;
loginMessage.set(new LoginMessage("192.168.2.69:8081","user","1234")); loginMessage.set(DefaultData.getDefaultData().getLoginMessage());
} }
public void login() { public void login() {
...@@ -34,5 +36,4 @@ public class LoginViewModel extends ViewModel { ...@@ -34,5 +36,4 @@ public class LoginViewModel extends ViewModel {
return loginModel.isAuthorized(); return loginModel.isAuthorized();
} }
} }
package com.example.zxa01.iotclient.component.privacy; package com.example.zxa01.iotclient.component.privacy;
import android.databinding.DataBindingUtil; import android.databinding.DataBindingUtil;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.PictureDrawable;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.os.Bundle; import android.os.Bundle;
import android.view.MenuItem; import android.view.MenuItem;
......
...@@ -3,6 +3,7 @@ package com.example.zxa01.iotclient.component.privacy; ...@@ -3,6 +3,7 @@ package com.example.zxa01.iotclient.component.privacy;
import android.arch.lifecycle.MutableLiveData; import android.arch.lifecycle.MutableLiveData;
import android.databinding.BaseObservable; import android.databinding.BaseObservable;
import android.os.Handler; import android.os.Handler;
import android.support.annotation.NonNull;
import android.util.Log; import android.util.Log;
import com.example.zxa01.iotclient.common.http.Api; import com.example.zxa01.iotclient.common.http.Api;
...@@ -32,7 +33,7 @@ public class PrivacyModel extends BaseObservable { ...@@ -32,7 +33,7 @@ public class PrivacyModel extends BaseObservable {
return isUploadMLD; return isUploadMLD;
} }
public void readPrivacyPolicyReportByDevice(String udn) { public void readPrivacyPolicyReportByDevice(@NonNull String udn) {
Api.getApi().readPrivacyPolicyReportByDevice(udn).enqueue(new Callback<PrivacyPolicyReport>() { Api.getApi().readPrivacyPolicyReportByDevice(udn).enqueue(new Callback<PrivacyPolicyReport>() {
@Override @Override
public void onResponse(Call<PrivacyPolicyReport> call, Response<PrivacyPolicyReport> response) { public void onResponse(Call<PrivacyPolicyReport> call, Response<PrivacyPolicyReport> response) {
...@@ -47,7 +48,7 @@ public class PrivacyModel extends BaseObservable { ...@@ -47,7 +48,7 @@ public class PrivacyModel extends BaseObservable {
} }
public void setPrivacyChoice(PrivacyContent privacyContent, boolean isAccepted) { public void setPrivacyChoice(@NonNull PrivacyContent privacyContent, @NonNull boolean isAccepted) {
isUploadMLD.setValue(true); isUploadMLD.setValue(true);
Api.getApi().setPrivacyChoice( Api.getApi().setPrivacyChoice(
new PrivacyChoice().setPrivacyContent(privacyContent).setAccepted(isAccepted)).enqueue( new PrivacyChoice().setPrivacyContent(privacyContent).setAccepted(isAccepted)).enqueue(
......
...@@ -11,6 +11,7 @@ import android.arch.lifecycle.ViewModel; ...@@ -11,6 +11,7 @@ import android.arch.lifecycle.ViewModel;
import android.content.Context; import android.content.Context;
import android.databinding.ObservableBoolean; import android.databinding.ObservableBoolean;
import android.databinding.ObservableField; import android.databinding.ObservableField;
import android.support.annotation.NonNull;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.view.View; import android.view.View;
import android.widget.Switch; import android.widget.Switch;
...@@ -37,7 +38,7 @@ public class PrivacyViewModel extends ViewModel { ...@@ -37,7 +38,7 @@ public class PrivacyViewModel extends ViewModel {
* model * model
*/ */
public void fetchPrivacyPolicyReportByDevice(String udn) { public void fetchPrivacyPolicyReportByDevice(@NonNull String udn) {
privacyModel.readPrivacyPolicyReportByDevice(udn); privacyModel.readPrivacyPolicyReportByDevice(udn);
} }
...@@ -56,7 +57,7 @@ public class PrivacyViewModel extends ViewModel { ...@@ -56,7 +57,7 @@ public class PrivacyViewModel extends ViewModel {
* child model * child model
*/ */
public PrivacyPolicy getPrivacyAt(Integer index) { public PrivacyPolicy getPrivacyAt(@NonNull Integer index) {
if (privacyModel.getPrivacyPolicyReportMLD().getValue() != null && if (privacyModel.getPrivacyPolicyReportMLD().getValue() != null &&
index != null && index != null &&
privacyModel.getPrivacyPolicyReportMLD().getValue().getPolicies().size() > index) { privacyModel.getPrivacyPolicyReportMLD().getValue().getPolicies().size() > index) {
...@@ -65,9 +66,8 @@ public class PrivacyViewModel extends ViewModel { ...@@ -65,9 +66,8 @@ public class PrivacyViewModel extends ViewModel {
return null; return null;
} }
public void onSetPrivacyChoice(Integer index, View view) { public void onSetPrivacyChoice(@NonNull Integer index, View view) {
if (privacyModel.getPrivacyPolicyReportMLD().getValue() != null && if (privacyModel.getPrivacyPolicyReportMLD().getValue() != null &&
index != null &&
privacyModel.getPrivacyPolicyReportMLD().getValue().getPolicies().size() > index) { privacyModel.getPrivacyPolicyReportMLD().getValue().getPolicies().size() > index) {
privacyModel.setPrivacyChoice( privacyModel.setPrivacyChoice(
new PrivacyContent() new PrivacyContent()
......
...@@ -467,7 +467,7 @@ ...@@ -467,7 +467,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginRight="@dimen/margin_lg" android:layout_marginRight="@dimen/margin_lg"
android:padding="@dimen/padding_sm" android:padding="@dimen/padding_sm"
android:text="@{viewModel.device.UPC}" android:text="@{viewModel.device.upc}"
android:textSize="@dimen/font" /> android:textSize="@dimen/font" />
</LinearLayout> </LinearLayout>
......
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android" <layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"> xmlns:tools="http://schemas.android.com/tools">
<data> <data>
......
...@@ -4,15 +4,17 @@ ...@@ -4,15 +4,17 @@
<data> <data>
<import type="android.view.View" />
<variable <variable
name="viewModel" name="viewModel"
type="com.example.zxa01.iotclient.component.home.device.DeviceViewModel" /> type="com.example.zxa01.iotclient.component.home.device.bind.DeviceBindViewModel" />
</data> </data>
<FrameLayout <FrameLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context=".component.home.device.create.DeviceCreateFragment"> tools:context=".component.home.device.bind.DeviceBindFragment">
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
...@@ -20,26 +22,63 @@ ...@@ -20,26 +22,63 @@
android:orientation="vertical"> android:orientation="vertical">
<TextView <TextView
android:id="@+id/textView" android:id="@+id/CreateAndBind"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="@color/colorLightest" android:background="@color/colorLightest"
android:fontFamily="monospace" android:fontFamily="monospace"
android:padding="@dimen/padding" android:padding="@dimen/padding"
android:text="@string/create_title" android:text="@string/bind_title"
android:textAlignment="center" android:textAlignment="center"
android:textSize="@dimen/font" /> android:textSize="@dimen/font" />
<EditText <EditText
android:id="@+id/editText" android:id="@+id/ubnInput"
android:layout_width="match_parent" android:layout_width="350dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_margin="@dimen/margin_sm" android:layout_margin="@dimen/margin"
android:hint="@string/create_input_placeholder" android:hint="@string/bind_input_placeholder"
android:padding="@dimen/padding_lg" android:paddingTop="@dimen/padding_lg"
android:paddingRight="@dimen/padding_xs"
android:paddingLeft="@dimen/padding_xs"
android:paddingBottom="@dimen/padding"
android:text="@={viewModel.udn}"
android:textColorHighlight="@color/colorPrimary" android:textColorHighlight="@color/colorPrimary"
android:textColorLink="@color/colorLight" /> android:textColorLink="@color/colorLight" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/qrcode"
style="@style/Widget.AppCompat.Button.ButtonBar.AlertDialog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="@{()->viewModel.qrcode()}"
android:text="@string/bind_button_qrcode" />
<Button
android:id="@+id/cancel"
style="@style/Widget.AppCompat.Button.ButtonBar.AlertDialog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="@{()->viewModel.cancel()}"
android:text="@string/bind_button_cancel" />
<Button
android:id="@+id/correct"
style="@style/Widget.AppCompat.Button.ButtonBar.AlertDialog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="@{()->viewModel.bindDeviceAndGateway()}"
android:text="@string/bind_button_correct" />
</LinearLayout>
</LinearLayout> </LinearLayout>
</FrameLayout> </FrameLayout>
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="@drawable/border_bottom" android:background="@drawable/border_bottom"
android:onClick="@{()->viewModel.onPrivacyPolicyReportClick(position)}" android:onClick="@{()->viewModel.onPrivacyChoiceClick(position)}"
android:orientation="vertical" android:orientation="vertical"
android:padding="@dimen/margin"> android:padding="@dimen/margin">
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@{viewModel.getPrivacyPolicyReportAt(position).device.name}" android:text="@{viewModel.getPrivacyChoiceAt(position).privacyChoice.privacyContent.device.name}"
android:textColor="@color/colorLight" android:textColor="@color/colorLight"
android:textSize="18sp" android:textSize="18sp"
android:textStyle="bold" android:textStyle="bold"
...@@ -51,15 +51,20 @@ ...@@ -51,15 +51,20 @@
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@{viewModel.getPrivacyPolicyReportAt(position).description}" android:text="@{viewModel.getPrivacyChoiceAt(position).privacyChoice.privacyContent.policy.description}"
tools:text="@tools:sample/lorem" /> tools:text="@tools:sample/lorem" />
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text='2019.04.23' android:text="@{viewModel.getPrivacyChoiceAt(position).localDateTime.toString()}"
tools:text="@tools:sample/lorem" /> tools:text="@tools:sample/lorem" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="同意或拒絕"
tools:text="@tools:sample/lorem" />
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
......
...@@ -11,13 +11,13 @@ ...@@ -11,13 +11,13 @@
<string name="nav_record">Record</string> <string name="nav_record">Record</string>
<string name="nav_setting">Setting</string> <string name="nav_setting">Setting</string>
<!--Create--> <!--Bind-->
<string name="create_title">新增裝置</string> <string name="bind_title">新增且綁定裝置</string>
<string name="create_input_placeholder">請輸入裝置的UDN</string> <string name="bind_input_placeholder">請輸入裝置的UDN</string>
<string name="create_button_qrcode">QRcode</string> <string name="bind_button_qrcode">QRcode</string>
<string name="create_button_correct">新增</string> <string name="bind_button_correct">新增</string>
<string name="create_button_cancel">返回</string> <string name="bind_button_cancel">返回</string>
<string name="create_qrcode_error">格式錯誤</string> <string name="bind_qrcode_error">格式錯誤</string>
<!--Detail--> <!--Detail-->
......
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