Commit 738ed6f5 authored by DESKTOP-NFGF3PG\zxa01's avatar DESKTOP-NFGF3PG\zxa01

update refresh

parent 089d8270
......@@ -18,7 +18,7 @@
<PersistentState>
<option name="values">
<map>
<entry key="url" value="jar:file:/C:/Program%20Files/Android/Android%20Studio/plugins/android/lib/android.jar!/images/material_design_icons/content/ic_add_black_24dp.xml" />
<entry key="url" value="jar:file:/C:/Program%20Files/Android/Android%20Studio/plugins/android/lib/android.jar!/images/material_design_icons/navigation/ic_refresh_black_24dp.xml" />
</map>
</option>
</PersistentState>
......@@ -29,7 +29,7 @@
<option name="values">
<map>
<entry key="color" value="ffffff" />
<entry key="outputName" value="ic_add_black_24dp" />
<entry key="outputName" value="ic_refresh_black_24dp" />
<entry key="sourceFile" value="C:\Users\zxa01" />
</map>
</option>
......
......@@ -31,9 +31,10 @@
</activity>
<activity
android:name=".component.home.HomeActivity"
android:label="@string/app_name"
android:label="@string/title_home"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan" />
android:windowSoftInputMode="adjustPan"
/>
<activity
android:name=".component.detail.DetailActivity"
......
......@@ -2,13 +2,19 @@ package com.example.zxa01.iotclient.common.singleton;
import com.example.zxa01.iotclient.common.pojo.auth.LoginMessage;
import java.util.LinkedList;
import java.util.List;
public class DefaultData {
private static DefaultData defaultData = new DefaultData();
private LoginMessage loginMessage;
private List<String> devices = new LinkedList<>();
private DefaultData() {
loginMessage = new LoginMessage("192.168.2.69:8080", "user", "1234");
devices.add("a1252c49-4188-4e6d-a32e-66604c664fb8");
devices.add("abe5ca7b-780e-4857-87e6-014870fe0a3e");
}
public static DefaultData getDefaultData() {
......@@ -18,4 +24,9 @@ public class DefaultData {
public LoginMessage getLoginMessage() {
return loginMessage;
}
public List<String> getDevices(){
return devices;
}
}
......@@ -62,8 +62,8 @@ public class Api {
Call<PrivacyChoiceResponse> setPrivacyChoice(@Body PrivacyChoice privacyChoice);
// 取得隱私偏好記錄
@GET("/choice")
Call<List<PrivacyChoiceResponse>> readPrivacyChoiceRecordsByUser();
@GET("/choice/{account}")
Call<List<PrivacyChoiceResponse>> readPrivacyChoiceRecordsByUser(@Path("account") String account);
}
}
package com.example.zxa01.iotclient.component.home;
import com.example.zxa01.iotclient.R;
import com.example.zxa01.iotclient.common.pojo.device.Device;
import com.example.zxa01.iotclient.component.home.device.bind.DeviceBindViewModel;
import com.example.zxa01.iotclient.databinding.ActivityHomeBinding;
import com.example.zxa01.iotclient.component.home.device.DeviceFragment;
......@@ -15,6 +16,8 @@ import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.databinding.DataBindingUtil;
import android.view.MenuItem;
import android.view.Window;
public class HomeActivity extends AppCompatActivity {
......
......@@ -13,14 +13,11 @@ 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 {
private DeviceViewModel viewModel;
private FragmentDeviceBinding binding;
private DeviceBindFragment deviceBindFragment;
public DeviceFragment() {
}
......@@ -38,7 +35,9 @@ public class DeviceFragment extends Fragment {
viewModel = new DeviceViewModel(binding.getRoot().getContext());
binding.setViewModel(viewModel);
binding.fab.setOnClickListener(item -> drawDialog());
binding.fabRefresh.setOnClickListener(item -> init());
binding.deviceRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
deviceBindFragment = new DeviceBindFragment();
}
private void init() {
......@@ -53,7 +52,7 @@ public class DeviceFragment extends Fragment {
fragmentTransaction.remove(fragment);
}
fragmentTransaction.addToBackStack(null);
new DeviceBindFragment().show(fragmentTransaction, String.valueOf(R.string.dialog));
deviceBindFragment.show(fragmentTransaction, String.valueOf(R.string.dialog));
}
......
......@@ -30,7 +30,7 @@ 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());
Log.i("readDevices - onResponse()", "success");
devicesMLD.setValue(response.body() == null ?
null : response.body().stream().collect(Collectors.toList()));
}
......
......@@ -16,7 +16,6 @@ import java.util.List;
public class DeviceViewModel extends ViewModel {
public ObservableBoolean isLoading = new ObservableBoolean(true);
public ObservableBoolean isNoContent = new ObservableBoolean(true);
private DeviceModel deviceModel = new DeviceModel();
private DeviceAdapter adapter = new DeviceAdapter(R.layout.recycler_view_device, this);
private Context context;
......@@ -68,7 +67,6 @@ public class DeviceViewModel extends ViewModel {
public void setAdapter(List<Device> devices) {
isLoading.set(false);
isNoContent.set(devices == null);
adapter.setDevices(devices);
}
......
......@@ -2,6 +2,8 @@ package com.example.zxa01.iotclient.component.home.device.bind;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.View;
......@@ -28,14 +30,18 @@ public class DeviceBindFragment extends DialogFragment {
Bundle savedInstanceState) {
binding = DataBindingUtil.inflate(inflater, R.layout.fragment_device_bind, container, false);
binding();
init();
return binding.getRoot();
}
private void binding() {
viewModel = new DeviceBindViewModel(this);
binding.setViewModel(viewModel);
}
private void init(){
viewModel.observeIsLoadingMLD().observe(this,viewModel::setIsUpload);
}
}
package com.example.zxa01.iotclient.component.home.device.bind;
import android.arch.lifecycle.MutableLiveData;
import android.databinding.BaseObservable;
import android.os.Handler;
import android.support.annotation.NonNull;
import android.util.Log;
......@@ -13,22 +15,32 @@ import retrofit2.Response;
public class DeviceBindModel extends BaseObservable {
private MutableLiveData<Boolean> isUploadMLD = new MutableLiveData<>();
public DeviceBindModel() {
}
public MutableLiveData<Boolean> getIsUploadMLD() {
return isUploadMLD;
}
public void bindDeviceAndGateway(@NonNull String udn) {
isUploadMLD.setValue(true);
Api.getApi().bindDeviceAndGateway(udn).enqueue(
new Callback<Device>() {
@Override
public void onResponse(Call<Device> call, Response<Device> response) {
Log.i("bindDeviceAndGateway - onResponse()","success");
isUploadMLD.setValue(false);
}
@Override
public void onFailure(Call<Device> call, Throwable t) {
Log.e("bindDeviceAndGateway - onFailure()", t.getMessage(), t);
isUploadMLD.setValue(false);
}
}
);
}
}
......@@ -2,12 +2,17 @@ package com.example.zxa01.iotclient.component.home.device.bind;
import android.arch.lifecycle.MutableLiveData;
import android.arch.lifecycle.ViewModel;
import android.content.Context;
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;
import android.support.v7.app.AlertDialog;
import com.example.zxa01.iotclient.R;
import com.example.zxa01.iotclient.common.singleton.DefaultData;
public class DeviceBindViewModel extends ViewModel {
......@@ -20,16 +25,19 @@ public class DeviceBindViewModel extends ViewModel {
public ObservableField<String> udn = new ObservableField<>();
private DeviceBindModel deviceBindModel = new DeviceBindModel();
private Fragment fragment;
private AlertDialog dialog;
public DeviceBindViewModel(){
public DeviceBindViewModel() {
}
public DeviceBindViewModel(Fragment fragment) {
this.fragment = fragment;
drawDialog();
}
/**
* button function
* binding
*/
public void bindDeviceAndGateway(String udn) {
......@@ -51,9 +59,33 @@ public class DeviceBindViewModel extends ViewModel {
}
}
/**
* UI
*/
public void cancel() {
((DeviceBindFragment) fragment).dismiss();
}
public MutableLiveData<Boolean> observeIsLoadingMLD() {
return deviceBindModel.getIsUploadMLD();
}
public void setIsUpload(Boolean isUpload) {
if (isUpload) {
dialog.show();
} else {
cancel();
dialog.hide();
}
}
private void drawDialog() {
dialog = new AlertDialog.Builder(fragment.getContext())
.setMessage(R.string.bind_binding_waiting)
.setTitle(R.string.bind_waiting)
.create();
}
}
......@@ -5,6 +5,7 @@ import android.databinding.BaseObservable;
import android.support.annotation.NonNull;
import android.util.Log;
import com.example.zxa01.iotclient.common.singleton.Config;
import com.example.zxa01.iotclient.common.tools.Api;
import com.example.zxa01.iotclient.common.pojo.index.PrivacyChoiceResponse;
......@@ -27,10 +28,10 @@ public class RecordModel extends BaseObservable {
}
public void fetchRecord() {
Api.getApi().readPrivacyChoiceRecordsByUser().enqueue(new Callback<List<PrivacyChoiceResponse>>() {
Api.getApi().readPrivacyChoiceRecordsByUser(Config.getConfig().getUser().getAccount()).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());
Log.i("fetchRecord - onResponse()", "success");
privacyChoiceResponsesMLD.setValue(response.body() == null ?
null : response.body().stream().collect(Collectors.toList()));
}
......
......@@ -6,23 +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 {
public ObservableBoolean isLoading = new ObservableBoolean(true);
public ObservableBoolean isNoContent = new ObservableBoolean(true);
private RecordModel recordModel = new RecordModel();
private RecordAdapter adapter = new RecordAdapter(R.layout.recycler_view_record, this);
private Context context;
......@@ -76,7 +71,6 @@ public class RecordViewModel extends ViewModel {
public void setAdapter(List<PrivacyChoiceResponse> privacyChoiceResponses) {
isLoading.set(false);
isNoContent.set(privacyChoiceResponses == null);
privacyChoiceResponses.sort((pre, post) -> post.getLocalDateTime().compareTo(pre.getLocalDateTime()));
adapter.setPrivacyChoiceResponses(privacyChoiceResponses.stream()
.map(choice -> choice.setLocalDateTime(convertDateTime(choice.getLocalDateTime())))
......
<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="M10,20v-6h4v6h5v-8h3L12,3 2,12h3v8z" />
<vector android:height="24dp" android:tint="#FFFFFF"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M10,20v-6h4v6h5v-8h3L12,3 2,12h3v8z"/>
</vector>
<vector android:height="24dp" android:tint="#808080"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M17.65,6.35C16.2,4.9 14.21,4 12,4c-4.42,0 -7.99,3.58 -7.99,8s3.57,8 7.99,8c3.73,0 6.84,-2.55 7.73,-6h-2.08c-0.82,2.33 -3.04,4 -5.65,4 -3.31,0 -6,-2.69 -6,-6s2.69,-6 6,-6c1.66,0 3.14,0.69 4.22,1.78L13,11h7V4l-2.35,2.35z"/>
</vector>
......@@ -4,7 +4,6 @@
xmlns:tools="http://schemas.android.com/tools">
<data>
<variable
name="viewModel"
type="com.example.zxa01.iotclient.component.home.HomeViewModel" />
......@@ -35,7 +34,9 @@
app:layout_constraintBottom_toTopOf="@+id/navigation"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintTop_toTopOf="parent" >
</FrameLayout>
</android.support.constraint.ConstraintLayout>
......
......@@ -23,8 +23,8 @@
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingTop="@dimen/padding"
android:layout_marginRight="@dimen/margin_sm"
android:layout_marginLeft="@dimen/margin_sm"
android:paddingRight="@dimen/padding_sm"
android:paddingLeft="@dimen/padding_sm"
app:setAdapter="@{viewModel.getAdapter()}"
tools:listitem="@layout/recycler_view_device" />
......@@ -38,6 +38,17 @@
android:theme="@style/ProgressTheme"
android:visibility="@{viewModel.isLoading ? View.VISIBLE : View.GONE}" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab_refresh"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_marginLeft="@dimen/margin"
android:layout_marginRight="@dimen/margin"
android:layout_marginBottom="90dp"
android:src="@drawable/ic_refresh_black_24dp"
app:backgroundTint="@color/colorWhite" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
......
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:title="Item" />
</menu>
\ No newline at end of file
<resources>
<!--Title-->
<string name="title_home">裝置列表</string>
<string name="title_detail">裝置資訊</string>
<string name="title_privacy">隱私選擇設定</string>
<string name="title_setting">設定</string>
<string name="title_back">上一頁</string>
<!--Home-->
<string name="app_name">IOTClient</string>
......@@ -14,6 +16,8 @@
<!--Bind-->
<string name="bind_title">新增且綁定裝置</string>
<string name="bind_input_placeholder">請輸入裝置的UDN</string>
<string name="bind_binding_waiting">裝置綁定中</string>
<string name="bind_waiting">請稍後</string>
<string name="bind_button_qrcode">QRcode</string>
<string name="bind_button_correct">新增</string>
<string name="bind_button_cancel">返回</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