Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
IOTClient
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lola
IOTClient
Commits
69a4f4b9
Commit
69a4f4b9
authored
May 10, 2019
by
DESKTOP-NFGF3PG\zxa01
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update the api
parent
e809f283
Changes
35
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
35 changed files
with
368 additions
and
431 deletions
+368
-431
app/build.gradle
app/build.gradle
+3
-5
app/src/main/AndroidManifest.xml
app/src/main/AndroidManifest.xml
+1
-1
app/src/main/java/com/example/zxa01/iotclient/common/bindings/CustomViewBindings.java
...e/zxa01/iotclient/common/bindings/CustomViewBindings.java
+15
-0
app/src/main/java/com/example/zxa01/iotclient/common/http/Api.java
...ain/java/com/example/zxa01/iotclient/common/http/Api.java
+22
-20
app/src/main/java/com/example/zxa01/iotclient/common/pojo/device/Device.java
...om/example/zxa01/iotclient/common/pojo/device/Device.java
+12
-11
app/src/main/java/com/example/zxa01/iotclient/common/shared/Config.java
...ava/com/example/zxa01/iotclient/common/shared/Config.java
+11
-5
app/src/main/java/com/example/zxa01/iotclient/component/detail/DetailActivity.java
...mple/zxa01/iotclient/component/detail/DetailActivity.java
+9
-4
app/src/main/java/com/example/zxa01/iotclient/component/detail/DetailModel.java
...example/zxa01/iotclient/component/detail/DetailModel.java
+15
-27
app/src/main/java/com/example/zxa01/iotclient/component/detail/DetailViewModel.java
...ple/zxa01/iotclient/component/detail/DetailViewModel.java
+4
-4
app/src/main/java/com/example/zxa01/iotclient/component/home/HomeActivity.java
.../example/zxa01/iotclient/component/home/HomeActivity.java
+17
-21
app/src/main/java/com/example/zxa01/iotclient/component/home/HomeModel.java
...com/example/zxa01/iotclient/component/home/HomeModel.java
+10
-0
app/src/main/java/com/example/zxa01/iotclient/component/home/HomeViewModel.java
...example/zxa01/iotclient/component/home/HomeViewModel.java
+16
-0
app/src/main/java/com/example/zxa01/iotclient/component/home/device/DeviceFragment.java
...zxa01/iotclient/component/home/device/DeviceFragment.java
+9
-23
app/src/main/java/com/example/zxa01/iotclient/component/home/device/DeviceModel.java
...le/zxa01/iotclient/component/home/device/DeviceModel.java
+34
-42
app/src/main/java/com/example/zxa01/iotclient/component/home/device/DeviceViewModel.java
...xa01/iotclient/component/home/device/DeviceViewModel.java
+14
-10
app/src/main/java/com/example/zxa01/iotclient/component/home/device/create/DeviceCreateFragment.java
...nt/component/home/device/create/DeviceCreateFragment.java
+6
-2
app/src/main/java/com/example/zxa01/iotclient/component/home/record/RecordFragment.java
...zxa01/iotclient/component/home/record/RecordFragment.java
+6
-23
app/src/main/java/com/example/zxa01/iotclient/component/home/record/RecordModel.java
...le/zxa01/iotclient/component/home/record/RecordModel.java
+1
-1
app/src/main/java/com/example/zxa01/iotclient/component/home/record/RecordViewModel.java
...xa01/iotclient/component/home/record/RecordViewModel.java
+2
-3
app/src/main/java/com/example/zxa01/iotclient/component/home/setting/SettingFragment.java
...a01/iotclient/component/home/setting/SettingFragment.java
+7
-19
app/src/main/java/com/example/zxa01/iotclient/component/home/setting/SettingViewModel.java
...01/iotclient/component/home/setting/SettingViewModel.java
+10
-5
app/src/main/java/com/example/zxa01/iotclient/component/login/LoginActivity.java
...xample/zxa01/iotclient/component/login/LoginActivity.java
+17
-11
app/src/main/java/com/example/zxa01/iotclient/component/login/LoginModel.java
...m/example/zxa01/iotclient/component/login/LoginModel.java
+22
-17
app/src/main/java/com/example/zxa01/iotclient/component/login/LoginViewModel.java
...ample/zxa01/iotclient/component/login/LoginViewModel.java
+1
-1
app/src/main/java/com/example/zxa01/iotclient/component/privacy/PrivacyActivity.java
...le/zxa01/iotclient/component/privacy/PrivacyActivity.java
+8
-3
app/src/main/java/com/example/zxa01/iotclient/component/privacy/PrivacyModel.java
...ample/zxa01/iotclient/component/privacy/PrivacyModel.java
+30
-122
app/src/main/java/com/example/zxa01/iotclient/component/privacy/PrivacyViewModel.java
...e/zxa01/iotclient/component/privacy/PrivacyViewModel.java
+17
-16
app/src/main/res/drawable/gradient_theme.xml
app/src/main/res/drawable/gradient_theme.xml
+8
-0
app/src/main/res/layout/activity_detail.xml
app/src/main/res/layout/activity_detail.xml
+2
-2
app/src/main/res/layout/activity_home.xml
app/src/main/res/layout/activity_home.xml
+7
-0
app/src/main/res/layout/activity_privacy.xml
app/src/main/res/layout/activity_privacy.xml
+3
-1
app/src/main/res/layout/fragment_device.xml
app/src/main/res/layout/fragment_device.xml
+2
-0
app/src/main/res/layout/recycler_view_device.xml
app/src/main/res/layout/recycler_view_device.xml
+2
-1
app/src/main/res/layout/recycler_view_privacy.xml
app/src/main/res/layout/recycler_view_privacy.xml
+20
-28
app/src/main/res/values/colors.xml
app/src/main/res/values/colors.xml
+5
-3
No files found.
app/build.gradle
View file @
69a4f4b9
...
@@ -36,6 +36,9 @@ dependencies {
...
@@ -36,6 +36,9 @@ dependencies {
androidTestImplementation
'com.android.support.test:runner:1.0.2'
androidTestImplementation
'com.android.support.test:runner:1.0.2'
androidTestImplementation
'com.android.support.test.espresso:espresso-core:3.0.2'
androidTestImplementation
'com.android.support.test.espresso:espresso-core:3.0.2'
// modelmapper
compile
'net.eunjae.android.modelmapper:ModelMapper:1.0.6'
// rxjava
// rxjava
implementation
"io.reactivex:rxjava:1.1.8"
implementation
"io.reactivex:rxjava:1.1.8"
implementation
"io.reactivex:rxandroid:1.2.1"
implementation
"io.reactivex:rxandroid:1.2.1"
...
@@ -44,9 +47,4 @@ dependencies {
...
@@ -44,9 +47,4 @@ dependencies {
implementation
"com.squareup.retrofit2:retrofit:2.1.0"
implementation
"com.squareup.retrofit2:retrofit:2.1.0"
implementation
"com.squareup.retrofit2:converter-gson:2.1.0"
implementation
"com.squareup.retrofit2:converter-gson:2.1.0"
// 可移除
implementation
'com.squareup.okhttp3:okhttp:3.14.1'
implementation
'com.jakewharton:butterknife:9.0.0-rc2'
annotationProcessor
'com.jakewharton:butterknife-compiler:9.0.0-rc2'
implementation
'com.android.support:gridlayout-v7:28.0.0'
}
}
app/src/main/AndroidManifest.xml
View file @
69a4f4b9
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android=
"http://schemas.android.com/apk/res/android"
<manifest
xmlns:android=
"http://schemas.android.com/apk/res/android"
package=
"com.example.zxa01.iotclient"
>
package=
"com.example.zxa01.iotclient"
>
<!-- To auto-complete the email text field in the login form with the user's emails -->
<uses-permission
android:name=
"android.permission.GET_ACCOUNTS"
/>
<uses-permission
android:name=
"android.permission.GET_ACCOUNTS"
/>
<uses-permission
android:name=
"android.permission.READ_PROFILE"
/>
<uses-permission
android:name=
"android.permission.READ_PROFILE"
/>
<uses-permission
android:name=
"android.permission.READ_CONTACTS"
/>
<uses-permission
android:name=
"android.permission.READ_CONTACTS"
/>
...
...
app/src/main/java/com/example/zxa01/iotclient/common/bindings/CustomViewBindings.java
0 → 100644
View file @
69a4f4b9
package
com.example.zxa01.iotclient.common.bindings
;
import
android.databinding.BindingAdapter
;
import
android.support.v7.widget.LinearLayoutManager
;
import
android.support.v7.widget.RecyclerView
;
public
class
CustomViewBindings
{
@BindingAdapter
(
"setAdapter"
)
public
static
void
bindRecyclerViewAdapter
(
RecyclerView
recyclerView
,
RecyclerView
.
Adapter
<?>
adapter
)
{
recyclerView
.
setHasFixedSize
(
true
);
recyclerView
.
setLayoutManager
(
new
LinearLayoutManager
(
recyclerView
.
getContext
()));
recyclerView
.
setAdapter
(
adapter
);
}
}
app/src/main/java/com/example/zxa01/iotclient/common/http/Api.java
View file @
69a4f4b9
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.privacy.PrivacyChoice
;
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.Gson
;
import
com.google.gson.GsonBuilder
;
import
com.google.gson.GsonBuilder
;
import
java.util.List
;
import
okhttp3.OkHttpClient
;
import
okhttp3.OkHttpClient
;
import
retrofit2.Call
;
import
retrofit2.Call
;
import
retrofit2.Retrofit
;
import
retrofit2.Retrofit
;
import
retrofit2.converter.gson.GsonConverterFactory
;
import
retrofit2.converter.gson.GsonConverterFactory
;
import
retrofit2.http.Body
;
import
retrofit2.http.GET
;
import
retrofit2.http.GET
;
import
retrofit2.http.POST
;
import
retrofit2.http.POST
;
import
retrofit2.http.Path
;
public
class
Api
{
public
class
Api
{
private
static
ApiInterface
api
;
private
static
ApiInterface
api
;
private
static
final
String
BASE_URL
=
"https://dog.ceo"
;
public
static
ApiInterface
getApi
()
{
public
static
ApiInterface
getApi
()
{
if
(
api
==
null
)
{
if
(
api
==
null
)
{
OkHttpClient
client
=
new
OkHttpClient
.
Builder
()
.
build
();
Gson
gson
=
new
GsonBuilder
()
.
create
();
Retrofit
retrofit
=
new
Retrofit
.
Builder
()
Retrofit
retrofit
=
new
Retrofit
.
Builder
()
.
baseUrl
(
BASE_URL
)
.
baseUrl
(
"http://"
+
Config
.
getConfig
().
getGateway
())
.
client
(
client
)
.
client
(
new
OkHttpClient
.
Builder
()
.
build
())
.
addConverterFactory
(
.
addConverterFactory
(
GsonConverterFactory
.
create
(
gson
))
GsonConverterFactory
.
create
(
new
GsonBuilder
()
.
create
()))
.
build
();
.
build
();
api
=
retrofit
.
create
(
ApiInterface
.
class
);
api
=
retrofit
.
create
(
ApiInterface
.
class
);
...
@@ -39,25 +44,22 @@ public class Api {
...
@@ -39,25 +44,22 @@ public class Api {
@POST
(
"/api/breeds/list/all"
)
@POST
(
"/api/breeds/list/all"
)
Call
<
Object
>
login
();
Call
<
Object
>
login
();
@GET
(
"/api/breeds/list/all"
)
@GET
(
"/device"
)
Call
<
Object
>
getDevices
();
Call
<
List
<
Device
>>
getDevices
();
@GET
(
"/
api/breeds/list/all
"
)
@GET
(
"/
device/{udn}
"
)
Call
<
Object
>
getDevice
(
);
Call
<
Device
>
readDevice
(
@Path
(
"udn"
)
String
udn
);
@GET
(
"/
api/breeds/list/all
"
)
@GET
(
"/
device/privacy/{udn}
"
)
Call
<
Object
>
getPrivacyPolicyReport
(
);
Call
<
PrivacyPolicyReport
>
readPrivacyPolicyReportByDevice
(
@Path
(
"udn"
)
String
udn
);
@
GET
(
"/api/breeds/list/all
"
)
@
POST
(
"/choice
"
)
Call
<
Object
>
updatePrivacyPolicyChoice
(
);
Call
<
PrivacyChoice
>
setPrivacyChoice
(
@Body
PrivacyChoice
privacyChoice
);
// TODO
@GET
(
"/api/breeds/list/all"
)
@GET
(
"/api/breeds/list/all"
)
Call
<
Object
>
getRecord
();
Call
<
Object
>
getRecord
();
// @GET("/api/breed/{breed}/images")
// Call<DogBreedImages> getImagesByBreed(@Path("breed") String breed);
}
}
}
}
app/src/main/java/com/example/zxa01/iotclient/common/pojo/device/Device.java
View file @
69a4f4b9
...
@@ -2,13 +2,14 @@ package com.example.zxa01.iotclient.common.pojo.device;
...
@@ -2,13 +2,14 @@ package com.example.zxa01.iotclient.common.pojo.device;
import
android.os.Parcel
;
import
android.os.Parcel
;
import
android.os.Parcelable
;
import
android.os.Parcelable
;
import
android.support.annotation.RequiresApi
;
import
java.util.LinkedList
;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.List
;
public
class
Device
implements
Parcelable
{
public
class
Device
implements
Parcelable
{
private
String
UDN
;
private
String
udn
;
private
String
name
;
private
String
name
;
private
Type
type
;
private
Type
type
;
private
Manufacturer
manufacturer
;
private
Manufacturer
manufacturer
;
...
@@ -31,7 +32,7 @@ public class Device implements Parcelable {
...
@@ -31,7 +32,7 @@ public class Device implements Parcelable {
icons
.
add
(
new
Icon
(
icon
));
icons
.
add
(
new
Icon
(
icon
));
}
}
}
}
this
.
setU
DN
(
device
.
UDN
)
this
.
setU
dn
(
device
.
udn
)
.
setName
(
device
.
name
)
.
setName
(
device
.
name
)
.
setType
(
device
.
type
)
.
setType
(
device
.
type
)
.
setManufacturer
(
device
.
manufacturer
!=
null
?
new
Manufacturer
(
device
.
manufacturer
)
:
null
)
.
setManufacturer
(
device
.
manufacturer
!=
null
?
new
Manufacturer
(
device
.
manufacturer
)
:
null
)
...
@@ -42,7 +43,7 @@ public class Device implements Parcelable {
...
@@ -42,7 +43,7 @@ public class Device implements Parcelable {
}
}
private
Device
(
Parcel
in
)
{
private
Device
(
Parcel
in
)
{
UDN
=
in
.
readString
();
udn
=
in
.
readString
();
name
=
in
.
readString
();
name
=
in
.
readString
();
type
=
Type
.
valueOf
(
in
.
readString
());
type
=
Type
.
valueOf
(
in
.
readString
());
manufacturer
=
in
.
readParcelable
(
Manufacturer
.
class
.
getClassLoader
());
manufacturer
=
in
.
readParcelable
(
Manufacturer
.
class
.
getClassLoader
());
...
@@ -55,7 +56,7 @@ public class Device implements Parcelable {
...
@@ -55,7 +56,7 @@ public class Device implements Parcelable {
@Override
@Override
public
void
writeToParcel
(
Parcel
dest
,
int
flags
)
{
public
void
writeToParcel
(
Parcel
dest
,
int
flags
)
{
dest
.
writeString
(
UDN
);
dest
.
writeString
(
udn
);
dest
.
writeString
(
name
);
dest
.
writeString
(
name
);
dest
.
writeString
(
type
.
name
());
dest
.
writeString
(
type
.
name
());
dest
.
writeParcelable
(
manufacturer
,
flags
);
dest
.
writeParcelable
(
manufacturer
,
flags
);
...
@@ -83,12 +84,12 @@ public class Device implements Parcelable {
...
@@ -83,12 +84,12 @@ public class Device implements Parcelable {
}
}
};
};
public
String
getU
DN
()
{
public
String
getU
dn
()
{
return
UDN
;
return
udn
;
}
}
public
Device
setU
DN
(
String
UDN
)
{
public
Device
setU
dn
(
String
udn
)
{
this
.
UDN
=
UDN
;
this
.
udn
=
udn
;
return
this
;
return
this
;
}
}
...
@@ -176,12 +177,12 @@ public class Device implements Parcelable {
...
@@ -176,12 +177,12 @@ public class Device implements Parcelable {
Device
device
=
(
Device
)
o
;
Device
device
=
(
Device
)
o
;
return
UDN
!=
null
?
UDN
.
equals
(
device
.
UDN
)
:
device
.
UDN
==
null
;
return
udn
!=
null
?
udn
.
equals
(
device
.
udn
)
:
device
.
udn
==
null
;
}
}
@Override
@Override
public
int
hashCode
()
{
public
int
hashCode
()
{
return
UDN
!=
null
?
UDN
.
hashCode
()
:
0
;
return
udn
!=
null
?
udn
.
hashCode
()
:
0
;
}
}
public
enum
Type
{
public
enum
Type
{
...
@@ -191,7 +192,7 @@ public class Device implements Parcelable {
...
@@ -191,7 +192,7 @@ public class Device implements Parcelable {
@Override
@Override
public
String
toString
()
{
public
String
toString
()
{
return
"Device{"
+
return
"Device{"
+
"
UDN='"
+
UDN
+
'\''
+
"
udn='"
+
udn
+
'\''
+
", name='"
+
name
+
'\''
+
", name='"
+
name
+
'\''
+
", type="
+
type
+
", type="
+
type
+
", manufacturer="
+
manufacturer
+
", manufacturer="
+
manufacturer
+
...
...
app/src/main/java/com/example/zxa01/iotclient/common/shared/Config.java
View file @
69a4f4b9
...
@@ -4,29 +4,35 @@ package com.example.zxa01.iotclient.common.shared;
...
@@ -4,29 +4,35 @@ package com.example.zxa01.iotclient.common.shared;
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
java.util.ArrayList
;
import
java.util.LinkedList
;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.List
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
public
class
Config
{
public
class
Config
{
public
static
String
USER
=
"使用者"
;
public
static
String
GATEWAY
=
"閘道器位置"
;
public
static
String
LOGOUT
=
"登出"
;
public
static
String
LOGOUT_MESSAGE
=
"登出本帳號"
;
private
static
Config
config
=
new
Config
();
private
static
Config
config
=
new
Config
();
private
User
user
;
private
User
user
;
private
String
gateway
;
private
String
gateway
;
private
List
<
Setting
>
settings
;
private
List
<
Setting
>
settings
;
private
Config
()
{
private
Config
()
{
this
.
user
=
new
User
();
this
.
reset
();
this
.
gateway
=
""
;
this
.
settings
=
new
LinkedList
<>();
}
}
public
static
Config
getConfig
()
{
public
static
Config
getConfig
()
{
return
config
;
return
config
;
}
}
public
void
reset
()
{
this
.
user
=
new
User
();
this
.
gateway
=
""
;
this
.
settings
=
new
LinkedList
<>();
}
public
User
getUser
()
{
public
User
getUser
()
{
return
user
;
return
user
;
}
}
...
...
app/src/main/java/com/example/zxa01/iotclient/component/detail/DetailActivity.java
View file @
69a4f4b9
...
@@ -4,6 +4,7 @@ import android.databinding.DataBindingUtil;
...
@@ -4,6 +4,7 @@ import android.databinding.DataBindingUtil;
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
;
import
com.example.zxa01.iotclient.R
;
import
com.example.zxa01.iotclient.R
;
import
com.example.zxa01.iotclient.databinding.ActivityDetailBinding
;
import
com.example.zxa01.iotclient.databinding.ActivityDetailBinding
;
...
@@ -16,16 +17,20 @@ public class DetailActivity extends AppCompatActivity {
...
@@ -16,16 +17,20 @@ public class DetailActivity extends AppCompatActivity {
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
super
.
onCreate
(
savedInstanceState
);
binding
=
DataBindingUtil
.
setContentView
(
this
,
R
.
layout
.
activity_detail
);
binding
=
DataBindingUtil
.
setContentView
(
this
,
R
.
layout
.
activity_detail
);
binding
();
init
();
}
private
void
binding
()
{
viewModel
=
new
DetailViewModel
(
binding
.
getRoot
().
getContext
());
viewModel
=
new
DetailViewModel
(
binding
.
getRoot
().
getContext
());
binding
.
setViewModel
(
viewModel
);
binding
.
setViewModel
(
viewModel
);
getSupportActionBar
().
setDisplayHomeAsUpEnabled
(
true
);
getSupportActionBar
().
setDisplayHomeAsUpEnabled
(
true
);
getSupportActionBar
().
setDisplayShowHomeEnabled
(
true
);
getSupportActionBar
().
setDisplayShowHomeEnabled
(
true
);
init
();
}
}
p
ublic
void
init
()
{
p
rivate
void
init
()
{
viewModel
.
fetchDevice
();
viewModel
.
fetchDevice
(
getIntent
().
getStringExtra
(
"udn"
)
);
viewModel
.
observeDeviceMLD
().
observe
(
this
,
viewModel:
:
setDevice
);
viewModel
.
observeDeviceMLD
().
observe
(
this
,
viewModel:
:
setDevice
);
}
}
@Override
@Override
...
...
app/src/main/java/com/example/zxa01/iotclient/component/detail/DetailModel.java
View file @
69a4f4b9
package
com.example.zxa01.iotclient.component.detail
;
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.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.device.Manufacturer
;
import
com.example.zxa01.iotclient.common.pojo.device.Model
;
import
com.example.zxa01.iotclient.common.pojo.device.Model
;
import
retrofit2.Call
;
import
retrofit2.Call
;
import
retrofit2.Callback
;
import
retrofit2.Callback
;
import
retrofit2.Response
;
import
retrofit2.Response
;
...
@@ -17,43 +20,28 @@ public class DetailModel extends BaseObservable {
...
@@ -17,43 +20,28 @@ public class DetailModel extends BaseObservable {
public
DetailModel
()
{
public
DetailModel
()
{
}
}
public
void
setDeviceMLD
(
Device
device
)
{
public
MutableLiveData
<
Device
>
getDeviceMLD
()
{
deviceMLD
.
setValue
(
device
)
;
return
deviceMLD
;
}
}
public
MutableLiveData
<
Device
>
getDeviceMLD
()
{
public
void
setDeviceMLD
(
Device
device
)
{
return
deviceMLD
;
deviceMLD
.
setValue
(
device
)
;
}
}
public
void
fetchDevice
()
{
public
void
readDevice
(
String
udn
)
{
Callback
<
Object
>
callback
=
new
Callback
<
Object
>()
{
// TODO instead of udn
Api
.
getApi
().
readDevice
(
"1"
).
enqueue
(
new
Callback
<
Device
>()
{
@Override
@Override
public
void
onResponse
(
Call
<
Object
>
call
,
Response
<
Object
>
response
)
{
public
void
onResponse
(
Call
<
Device
>
call
,
Response
<
Device
>
response
)
{
// TODO transfer response
setDeviceMLD
(
response
==
null
||
response
.
body
()
==
null
?
setDeviceMLD
(
new
Device
()
null
:
response
.
body
());
.
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
));
}
}
@Override
@Override
public
void
onFailure
(
Call
<
Object
>
call
,
Throwable
t
)
{
public
void
onFailure
(
Call
<
Device
>
call
,
Throwable
t
)
{
Log
.
e
(
"fetchDevice - onFailure()"
,
t
.
getMessage
(),
t
);
Log
.
e
(
"fetchDevice - onFailure()"
,
t
.
getMessage
(),
t
);
}
}
};
});
Api
.
getApi
().
getDevice
().
enqueue
(
callback
);
}
}
...
...
app/src/main/java/com/example/zxa01/iotclient/component/detail/DetailViewModel.java
View file @
69a4f4b9
...
@@ -24,8 +24,8 @@ public class DetailViewModel extends ViewModel {
...
@@ -24,8 +24,8 @@ public class DetailViewModel extends ViewModel {
this
.
context
=
context
;
this
.
context
=
context
;
}
}
public
void
fetchDevice
()
{
public
void
fetchDevice
(
String
udn
)
{
detailModel
.
fetchDevice
(
);
detailModel
.
readDevice
(
udn
);
}
}
public
MutableLiveData
<
Device
>
observeDeviceMLD
()
{
public
MutableLiveData
<
Device
>
observeDeviceMLD
()
{
...
@@ -33,7 +33,7 @@ public class DetailViewModel extends ViewModel {
...
@@ -33,7 +33,7 @@ public class DetailViewModel extends ViewModel {
}
}
public
void
setDevice
(
Device
device
)
{
public
void
setDevice
(
Device
device
)
{
if
(
device
.
getUDN
()
!=
null
)
{
if
(
device
!=
null
&&
device
.
getUdn
()
!=
null
)
{
this
.
isLoading
.
set
(
false
);
this
.
isLoading
.
set
(
false
);
this
.
device
.
set
(
device
);
this
.
device
.
set
(
device
);
}
}
...
@@ -42,7 +42,7 @@ public class DetailViewModel extends ViewModel {
...
@@ -42,7 +42,7 @@ public class DetailViewModel extends ViewModel {
public
void
settingPrivacy
()
{
public
void
settingPrivacy
()
{
context
.
startActivity
(
context
.
startActivity
(
new
Intent
(
context
,
PrivacyActivity
.
class
)
new
Intent
(
context
,
PrivacyActivity
.
class
)
.
putExtra
(
"udn"
,
device
.
get
().
getU
DN
()));
.
putExtra
(
"udn"
,
device
.
get
().
getU
dn
()));
}
}
public
void
downloadPrivacyReport
()
{
public
void
downloadPrivacyReport
()
{
...
...
app/src/main/java/com/example/zxa01/iotclient/component/home/HomeActivity.java
View file @
69a4f4b9
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.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.
net.Uri
;
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
;
...
@@ -14,40 +17,33 @@ import android.support.v7.app.AlertDialog;
...
@@ -14,40 +17,33 @@ import android.support.v7.app.AlertDialog;
import
android.support.v7.app.AppCompatActivity
;
import
android.support.v7.app.AppCompatActivity
;
import
android.databinding.DataBindingUtil
;
import
android.databinding.DataBindingUtil
;
public
class
HomeActivity
extends
AppCompatActivity
implements
public
class
HomeActivity
extends
AppCompatActivity
{
DeviceFragment
.
OnFragmentInteractionListener
,
RecordFragment
.
OnFragmentInteractionListener
,
SettingFragment
.
OnFragmentInteractionListener
{
private
ActivityHomeBinding
binding
;
private
ActivityHomeBinding
binding
;
private
HomeViewModel
viewModel
;
/* fragments of HomeActivity */
private
DeviceFragment
mDeviceFragment
=
new
DeviceFragment
();
private
DeviceFragment
mDeviceFragment
=
new
DeviceFragment
();
private
RecordFragment
mRecordFragment
=
new
RecordFragment
();
private
RecordFragment
mRecordFragment
=
new
RecordFragment
();
private
SettingFragment
mSettingFragment
=
new
SettingFragment
();
private
SettingFragment
mSettingFragment
=
new
SettingFragment
();
@Override
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
super
.
onCreate
(
savedInstanceState
);
binding
=
DataBindingUtil
.
setContentView
(
this
,
R
.
layout
.
activity_home
);
binding
=
DataBindingUtil
.
setContentView
(
this
,
R
.
layout
.
activity_home
);
setupFragment
(
binding
.
navigation
);
binding
(
);
showFragment
(
mDeviceFragment
);
init
(
);
}
}
@Override
private
void
binding
()
{
public
void
onDeviceFragment
(
Uri
uri
)
{
viewModel
=
new
HomeViewModel
(
binding
.
getRoot
().
getContext
());
binding
.
setViewModel
(
viewModel
);
}
}
@Override
private
void
init
()
{
public
void
onPrivacyFragment
(
Uri
uri
)
{
setupFragment
(
binding
.
navigation
);
}
showFragment
(
mDeviceFragment
);
@Override
public
void
onSettingFragment
(
Uri
uri
)
{
}
}
/* onItemSelected of fragment */
private
void
setupFragment
(
BottomNavigationView
view
)
{
private
void
setupFragment
(
BottomNavigationView
view
)
{
view
.
setOnNavigationItemSelectedListener
(
view
.
setOnNavigationItemSelectedListener
(
menuItem
->
{
menuItem
->
{
...
@@ -67,10 +63,9 @@ public class HomeActivity extends AppCompatActivity implements
...
@@ -67,10 +63,9 @@ public class HomeActivity extends AppCompatActivity implements
);
);
}
}
/* show of fragment */
private
void
showFragment
(
Fragment
fragment
)
{
private
void
showFragment
(
Fragment
fragment
)
{
getSupportFragmentManager
().
beginTransaction
()
getSupportFragmentManager
().
beginTransaction
()
.
replace
(
R
.
id
.
home_fragment_layout
,
fragment
)
.
replace
(
binding
.
homeFragmentLayout
.
getId
()
,
fragment
)
.
setTransition
(
FragmentTransaction
.
TRANSIT_FRAGMENT_FADE
)
.
setTransition
(
FragmentTransaction
.
TRANSIT_FRAGMENT_FADE
)
.
commit
();
.
commit
();
}
}
...
@@ -78,11 +73,12 @@ public class HomeActivity extends AppCompatActivity implements
...
@@ -78,11 +73,12 @@ public class HomeActivity extends AppCompatActivity implements
@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
DeviceViewModel
().
createDevice
(
intent
.
getStringExtra
(
"SCAN_RESULT"
));
}
else
{
}
else
{
new
AlertDialog
.
Builder
(
this
)
new
AlertDialog
.
Builder
(
this
)
.
setMessage
(
R
.
string
.
create_qrcode_error
)
.
setMessage
(
R
.
string
.
create_qrcode_error
)
.
show
();
.
show
();
}
}
}
}
}
}
app/src/main/java/com/example/zxa01/iotclient/component/home/HomeModel.java
0 → 100644
View file @
69a4f4b9
package
com.example.zxa01.iotclient.component.home
;
import
android.databinding.BaseObservable
;
public
class
HomeModel
extends
BaseObservable
{
public
HomeModel
()
{
}
}
app/src/main/java/com/example/zxa01/iotclient/component/home/HomeViewModel.java
0 → 100644
View file @
69a4f4b9
package
com.example.zxa01.iotclient.component.home
;
import
android.arch.lifecycle.ViewModel
;
import
android.content.Context
;
public
class
HomeViewModel
extends
ViewModel
{
private
Context
context
;
private
HomeModel
homeModel
=
new
HomeModel
();
public
HomeViewModel
(
Context
context
)
{
this
.
context
=
context
;
}
}
app/src/main/java/com/example/zxa01/iotclient/component/home/device/DeviceFragment.java
View file @
69a4f4b9
...
@@ -2,7 +2,6 @@ package com.example.zxa01.iotclient.component.home.device;
...
@@ -2,7 +2,6 @@ package com.example.zxa01.iotclient.component.home.device;
import
android.content.Context
;
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.v4.app.FragmentTransaction
;
import
android.support.v4.app.FragmentTransaction
;
...
@@ -15,42 +14,33 @@ import com.example.zxa01.iotclient.R;
...
@@ -15,42 +14,33 @@ 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.create.DeviceCreateFragment
;
public
class
DeviceFragment
extends
Fragment
{
public
class
DeviceFragment
extends
Fragment
{
private
FragmentDeviceBinding
binding
;
private
DeviceViewModel
viewModel
;
private
DeviceViewModel
viewModel
;
private
FragmentDeviceBinding
binding
;
public
DeviceFragment
()
{
public
DeviceFragment
()
{
}
}
public
static
DeviceFragment
newInstance
()
{
return
new
DeviceFragment
();
}
@Override
@Override
public
View
onCreateView
(
LayoutInflater
inflater
,
ViewGroup
container
,
public
View
onCreateView
(
LayoutInflater
inflater
,
ViewGroup
container
,
Bundle
savedInstanceState
)
{
Bundle
savedInstanceState
)
{
binding
=
DataBindingUtil
.
inflate
(
inflater
,
R
.
layout
.
fragment_device
,
container
,
false
);
binding
=
DataBindingUtil
.
inflate
(
inflater
,
R
.
layout
.
fragment_device
,
container
,
false
);
viewModel
=
new
DeviceViewModel
(
binding
.
getRoot
().
getContext
());
binding
();
binding
.
setViewModel
(
viewModel
);
binding
.
fab
.
setOnClickListener
(
item
->
drawDialog
());
binding
.
deviceRecyclerView
.
setLayoutManager
(
new
LinearLayoutManager
(
getActivity
()));
init
();
init
();
return
binding
.
getRoot
();
return
binding
.
getRoot
();
}
}
@Override
private
void
binding
(){
public
void
onAttach
(
Context
context
)
{
viewModel
=
new
DeviceViewModel
(
binding
.
getRoot
().
getContext
());
super
.
onAttach
(
context
);
binding
.
setViewModel
(
viewModel
);
}
binding
.
fab
.
setOnClickListener
(
item
->
drawDialog
());
binding
.
deviceRecyclerView
.
setLayoutManager
(
new
LinearLayoutManager
(
getActivity
()));
@Override
public
void
onDetach
()
{
super
.
onDetach
();
}
}
private
void
init
()
{
private
void
init
()
{
viewModel
.
re
fresh
Devices
();
viewModel
.
re
ad
Devices
();
viewModel
.
observeDevicesMLD
().
observe
(
this
,
viewModel:
:
setAdapter
);
viewModel
.
observeDevicesMLD
().
observe
(
this
,
viewModel:
:
setAdapter
);
}
}
...
@@ -65,8 +55,4 @@ public class DeviceFragment extends Fragment {
...
@@ -65,8 +55,4 @@ public class DeviceFragment extends Fragment {
}
}
public
interface
OnFragmentInteractionListener
{
void
onDeviceFragment
(
Uri
uri
);
}
}
}
app/src/main/java/com/example/zxa01/iotclient/component/home/device/DeviceModel.java
View file @
69a4f4b9
...
@@ -2,70 +2,62 @@ package com.example.zxa01.iotclient.component.home.device;
...
@@ -2,70 +2,62 @@ package com.example.zxa01.iotclient.component.home.device;
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.device.Model
;
import
android.arch.lifecycle.MutableLiveData
;
import
android.arch.lifecycle.MutableLiveData
;
import
android.databinding.BaseObservable
;
import
android.databinding.BaseObservable
;
import
android.util.Log
;
import
android.util.Log
;
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
;
import
retrofit2.Response
;
import
retrofit2.Response
;
public
class
DeviceModel
extends
BaseObservable
{
public
class
DeviceModel
extends
BaseObservable
{
private
List
<
Device
>
devices
=
new
ArrayList
<>();
private
MutableLiveData
<
List
<
Device
>>
devicesMLD
=
new
MutableLiveData
<>();
private
MutableLiveData
<
List
<
Device
>>
devicesMLD
=
new
MutableLiveData
<>();
// fake
private
Device
oxygenDevice
=
new
Device
()
.
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"
);
public
DeviceModel
()
{
public
DeviceModel
()
{
}
}
public
void
addDevice
(
Device
device
)
{
devices
.
add
(
device
);
}
public
MutableLiveData
<
List
<
Device
>>
getDevicesMLD
()
{
public
MutableLiveData
<
List
<
Device
>>
getDevicesMLD
()
{
return
devicesMLD
;
return
devicesMLD
;
}
}
public
void
fetchDevices
()
{
public
void
readDevices
()
{
Callback
<
Object
>
callback
=
new
Callback
<
Object
>()
{
Api
.
getApi
().
getDevices
().
enqueue
(
new
Callback
<
List
<
Device
>>()
{
@Override
@Override
public
void
onResponse
(
Call
<
Object
>
call
,
Response
<
Object
>
response
)
{
public
void
onResponse
(
Call
<
List
<
Device
>>
call
,
Response
<
List
<
Device
>>
response
)
{
// TODO transfer response
devicesMLD
.
setValue
(
response
==
null
||
response
.
body
()
==
null
?
addDevice
(
oxygenDevice
);
null
:
response
.
body
().
stream
().
collect
(
Collectors
.
toList
()));
devicesMLD
.
setValue
(
devices
);
}
}
@Override
@Override
public
void
onFailure
(
Call
<
Object
>
call
,
Throwable
t
)
{
public
void
onFailure
(
Call
<
List
<
Device
>
>
call
,
Throwable
t
)
{
Log
.
e
(
"fetch
Devices - onFailure()"
,
t
.
getMessage
(),
t
);
Log
.
e
(
"read
Devices - onFailure()"
,
t
.
getMessage
(),
t
);
}
}
};
}
);
Api
.
getApi
().
getDevices
().
enqueue
(
callback
);
}
}
public
void
createDevice
(
String
address
)
{
public
void
createDevice
(
String
udn
)
{
// TODO api post-createDevice & update
// 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);
//// }
//// }
//// );
}
}
}
}
app/src/main/java/com/example/zxa01/iotclient/component/home/device/DeviceViewModel.java
View file @
69a4f4b9
...
@@ -9,11 +9,13 @@ import android.arch.lifecycle.ViewModel;
...
@@ -9,11 +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
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
;
...
@@ -22,12 +24,15 @@ public class DeviceViewModel extends ViewModel {
...
@@ -22,12 +24,15 @@ public class DeviceViewModel extends ViewModel {
this
.
context
=
context
;
this
.
context
=
context
;
}
}
public
DeviceViewModel
()
{
}
/**
/**
* model
* model
*/
*/
public
void
re
fresh
Devices
()
{
public
void
re
ad
Devices
()
{
deviceModel
.
fetch
Devices
();
deviceModel
.
read
Devices
();
}
}
public
MutableLiveData
<
List
<
Device
>>
observeDevicesMLD
()
{
public
MutableLiveData
<
List
<
Device
>>
observeDevicesMLD
()
{
...
@@ -37,9 +42,10 @@ public class DeviceViewModel extends ViewModel {
...
@@ -37,9 +42,10 @@ public class DeviceViewModel extends ViewModel {
/**
/**
* create
* create
*/
*/
public
void
createDevice
(
String
address
)
{
deviceModel
.
createDevice
(
address
);
public
void
createDevice
(
String
udn
)
{
refreshDevices
();
deviceModel
.
createDevice
(
udn
);
readDevices
();
}
}
/**
/**
...
@@ -59,10 +65,9 @@ public class DeviceViewModel extends ViewModel {
...
@@ -59,10 +65,9 @@ public class DeviceViewModel extends ViewModel {
if
(
deviceModel
.
getDevicesMLD
().
getValue
()
!=
null
&&
if
(
deviceModel
.
getDevicesMLD
().
getValue
()
!=
null
&&
index
!=
null
&&
index
!=
null
&&
deviceModel
.
getDevicesMLD
().
getValue
().
size
()
>
index
)
{
deviceModel
.
getDevicesMLD
().
getValue
().
size
()
>
index
)
{
// TODO detail of device
context
.
startActivity
(
context
.
startActivity
(
new
Intent
(
context
,
DetailActivity
.
class
)
new
Intent
(
context
,
DetailActivity
.
class
)
.
putExtra
(
"
index"
,
index
));
.
putExtra
(
"
udn"
,
deviceModel
.
getDevicesMLD
().
getValue
().
get
(
index
).
getUdn
()
));
}
}
}
}
...
@@ -75,9 +80,8 @@ public class DeviceViewModel extends ViewModel {
...
@@ -75,9 +80,8 @@ public class DeviceViewModel extends ViewModel {
}
}
public
void
setAdapter
(
List
<
Device
>
devices
)
{
public
void
setAdapter
(
List
<
Device
>
devices
)
{
this
.
isLoading
.
set
(
false
);
isLoading
.
set
(
false
);
this
.
adapter
.
setDevices
(
devices
);
adapter
.
setDevices
(
devices
);
this
.
adapter
.
notifyDataSetChanged
();
}
}
}
}
app/src/main/java/com/example/zxa01/iotclient/component/home/device/create/DeviceCreateFragment.java
View file @
69a4f4b9
...
@@ -55,12 +55,16 @@ public class DeviceCreateFragment extends DialogFragment {
...
@@ -55,12 +55,16 @@ public class DeviceCreateFragment extends DialogFragment {
public
View
onCreateView
(
LayoutInflater
inflater
,
ViewGroup
container
,
public
View
onCreateView
(
LayoutInflater
inflater
,
ViewGroup
container
,
Bundle
savedInstanceState
)
{
Bundle
savedInstanceState
)
{
binding
=
DataBindingUtil
.
inflate
(
inflater
,
R
.
layout
.
fragment_device_create
,
container
,
false
);
binding
=
DataBindingUtil
.
inflate
(
inflater
,
R
.
layout
.
fragment_device_create
,
container
,
false
);
viewModel
=
new
DeviceViewModel
(
binding
.
getRoot
().
getContext
());
binding
();
binding
.
setViewModel
(
viewModel
);
return
binding
.
getRoot
();
return
binding
.
getRoot
();
}
}
private
void
binding
()
{
viewModel
=
new
DeviceViewModel
(
binding
.
getRoot
().
getContext
());
binding
.
setViewModel
(
viewModel
);
}
private
void
qrcodeIntent
()
{
private
void
qrcodeIntent
()
{
try
{
try
{
startActivityForResult
(
startActivityForResult
(
...
...
app/src/main/java/com/example/zxa01/iotclient/component/home/record/RecordFragment.java
View file @
69a4f4b9
...
@@ -21,37 +21,20 @@ public class RecordFragment extends Fragment {
...
@@ -21,37 +21,20 @@ public class RecordFragment extends Fragment {
public
RecordFragment
()
{
public
RecordFragment
()
{
}
}
public
static
RecordFragment
newInstance
(
String
param1
,
String
param2
)
{
return
new
RecordFragment
();
}
@Override
@Override
public
View
onCreateView
(
LayoutInflater
inflater
,
ViewGroup
container
,
public
View
onCreateView
(
LayoutInflater
inflater
,
ViewGroup
container
,
Bundle
savedInstanceState
)
{
Bundle
savedInstanceState
)
{
binding
=
DataBindingUtil
.
inflate
(
inflater
,
R
.
layout
.
fragment_record
,
container
,
false
);
this
.
binding
=
DataBindingUtil
.
inflate
(
inflater
,
R
.
layout
.
fragment_record
,
container
,
false
);
viewModel
=
new
RecordViewModel
(
binding
.
getRoot
().
getContext
());
this
.
viewModel
=
new
RecordViewModel
(
binding
.
getRoot
().
getContext
());
binding
.
setViewModel
(
viewModel
);
this
.
binding
.
setViewModel
(
viewModel
);
binding
.
recordRecyclerView
.
setLayoutManager
(
new
LinearLayoutManager
(
getActivity
()));
this
.
binding
.
recordRecyclerView
.
setLayoutManager
(
new
LinearLayoutManager
(
getActivity
()));
init
();
init
();
return
binding
.
getRoot
();
return
binding
.
getRoot
();
}
}
@Override
public
void
onAttach
(
Context
context
)
{
super
.
onAttach
(
context
);
}
@Override
public
void
onDetach
()
{
super
.
onDetach
();
}
private
void
init
()
{
private
void
init
()
{
viewModel
.
refreshRecord
();
this
.
viewModel
.
refreshRecord
();
viewModel
.
observePrivacyPolicyReportsMLD
().
observe
(
this
,
viewModel:
:
setAdapter
);
this
.
viewModel
.
observePrivacyPolicyReportsMLD
().
observe
(
this
,
viewModel:
:
setAdapter
);
}
}
public
interface
OnFragmentInteractionListener
{
void
onPrivacyFragment
(
Uri
uri
);
}
}
}
app/src/main/java/com/example/zxa01/iotclient/component/home/record/RecordModel.java
View file @
69a4f4b9
...
@@ -33,7 +33,7 @@ public class RecordModel extends BaseObservable {
...
@@ -33,7 +33,7 @@ public class RecordModel extends BaseObservable {
private
MutableLiveData
<
List
<
PrivacyPolicyReport
>>
privacyPolicyReportsMLD
=
new
MutableLiveData
<>();
private
MutableLiveData
<
List
<
PrivacyPolicyReport
>>
privacyPolicyReportsMLD
=
new
MutableLiveData
<>();
private
Device
oxygenDevice
=
new
Device
()
private
Device
oxygenDevice
=
new
Device
()
.
setU
DN
(
"a1252c49-4188-4e6d-a32e-66604c664fb8"
)
.
setU
dn
(
"a1252c49-4188-4e6d-a32e-66604c664fb8"
)
.
setName
(
"指尖式血氧機"
)
.
setName
(
"指尖式血氧機"
)
.
setType
(
Device
.
Type
.
Sensor
)
.
setType
(
Device
.
Type
.
Sensor
)
.
setManufacturer
(
new
Manufacturer
()
.
setManufacturer
(
new
Manufacturer
()
...
...
app/src/main/java/com/example/zxa01/iotclient/component/home/record/RecordViewModel.java
View file @
69a4f4b9
...
@@ -68,9 +68,8 @@ public class RecordViewModel extends ViewModel {
...
@@ -68,9 +68,8 @@ public class RecordViewModel extends ViewModel {
}
}
public
void
setAdapter
(
List
<
PrivacyPolicyReport
>
privacyPolicyReports
)
{
public
void
setAdapter
(
List
<
PrivacyPolicyReport
>
privacyPolicyReports
)
{
this
.
isLoading
.
set
(
false
);
isLoading
.
set
(
false
);
this
.
adapter
.
setPrivacyPolicyReports
(
privacyPolicyReports
);
adapter
.
setPrivacyPolicyReports
(
privacyPolicyReports
);
this
.
adapter
.
notifyDataSetChanged
();
}
}
}
}
app/src/main/java/com/example/zxa01/iotclient/component/home/setting/SettingFragment.java
View file @
69a4f4b9
...
@@ -9,6 +9,7 @@ import android.support.v7.widget.LinearLayoutManager;
...
@@ -9,6 +9,7 @@ import android.support.v7.widget.LinearLayoutManager;
import
android.view.LayoutInflater
;
import
android.view.LayoutInflater
;
import
android.view.View
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
android.view.ViewGroup
;
import
com.example.zxa01.iotclient.R
;
import
com.example.zxa01.iotclient.R
;
import
com.example.zxa01.iotclient.databinding.FragmentSettingBinding
;
import
com.example.zxa01.iotclient.databinding.FragmentSettingBinding
;
...
@@ -21,37 +22,24 @@ public class SettingFragment extends Fragment {
...
@@ -21,37 +22,24 @@ public class SettingFragment extends Fragment {
public
SettingFragment
()
{
public
SettingFragment
()
{
}
}
public
static
SettingFragment
newInstance
(
String
param1
,
String
param2
)
{
return
new
SettingFragment
();
}
@Override
@Override
public
View
onCreateView
(
LayoutInflater
inflater
,
ViewGroup
container
,
public
View
onCreateView
(
LayoutInflater
inflater
,
ViewGroup
container
,
Bundle
savedInstanceState
)
{
Bundle
savedInstanceState
)
{
binding
=
DataBindingUtil
.
inflate
(
inflater
,
R
.
layout
.
fragment_setting
,
container
,
false
);
binding
=
DataBindingUtil
.
inflate
(
inflater
,
R
.
layout
.
fragment_setting
,
container
,
false
);
viewModel
=
new
SettingViewModel
(
binding
.
getRoot
().
getContext
());
binding
();
binding
.
setViewModel
(
viewModel
);
binding
.
settingRecyclerView
.
setLayoutManager
(
new
LinearLayoutManager
(
getActivity
()));
init
();
init
();
return
binding
.
getRoot
();
return
binding
.
getRoot
();
}
}
@Override
private
void
binding
()
{
public
void
onAttach
(
Context
context
)
{
viewModel
=
new
SettingViewModel
(
binding
.
getRoot
().
getContext
());
super
.
onAttach
(
context
);
binding
.
setViewModel
(
viewModel
);
}
binding
.
settingRecyclerView
.
setLayoutManager
(
new
LinearLayoutManager
(
getActivity
()));
@Override
public
void
onDetach
()
{
super
.
onDetach
();
}
}
private
void
init
()
{
private
void
init
()
{
viewModel
.
refreshSetting
();
viewModel
.
refreshSetting
();
viewModel
.
observeSettingMLD
().
observe
(
this
,
viewModel:
:
setAdapter
);
viewModel
.
observeSettingMLD
().
observe
(
this
,
viewModel:
:
setAdapter
);
}
}
public
interface
OnFragmentInteractionListener
{
void
onSettingFragment
(
Uri
uri
);
}
}
}
app/src/main/java/com/example/zxa01/iotclient/component/home/setting/SettingViewModel.java
View file @
69a4f4b9
...
@@ -3,10 +3,13 @@ package com.example.zxa01.iotclient.component.home.setting;
...
@@ -3,10 +3,13 @@ package com.example.zxa01.iotclient.component.home.setting;
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
;
import
android.content.Intent
;
import
android.databinding.ObservableBoolean
;
import
android.databinding.ObservableBoolean
;
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
;
import
com.example.zxa01.iotclient.common.shared.Config
;
import
com.example.zxa01.iotclient.component.login.LoginActivity
;
import
java.util.List
;
import
java.util.List
;
...
@@ -35,7 +38,6 @@ public class SettingViewModel extends ViewModel {
...
@@ -35,7 +38,6 @@ public class SettingViewModel extends ViewModel {
}
}
/**
/**
* child model
* child model
*/
*/
...
@@ -53,7 +55,11 @@ public class SettingViewModel extends ViewModel {
...
@@ -53,7 +55,11 @@ public class SettingViewModel extends ViewModel {
if
(
settingModel
.
getSettingMLD
().
getValue
()
!=
null
&&
if
(
settingModel
.
getSettingMLD
().
getValue
()
!=
null
&&
index
!=
null
&&
index
!=
null
&&
settingModel
.
getSettingMLD
().
getValue
().
size
()
>
index
)
{
settingModel
.
getSettingMLD
().
getValue
().
size
()
>
index
)
{
// TODO setting alert
if
(
settingModel
.
getSettingMLD
().
getValue
().
get
(
index
).
getKey
().
equals
(
Config
.
LOGOUT
)){
Config
.
getConfig
().
reset
();
context
.
startActivity
(
new
Intent
(
context
,
LoginActivity
.
class
));
}
}
}
}
}
...
@@ -66,8 +72,7 @@ public class SettingViewModel extends ViewModel {
...
@@ -66,8 +72,7 @@ public class SettingViewModel extends ViewModel {
}
}
public
void
setAdapter
(
List
<
Setting
>
settings
)
{
public
void
setAdapter
(
List
<
Setting
>
settings
)
{
this
.
isLoading
.
set
(
false
);
isLoading
.
set
(
false
);
this
.
adapter
.
setSettings
(
settings
);
adapter
.
setSettings
(
settings
);
this
.
adapter
.
notifyDataSetChanged
();
}
}
}
}
app/src/main/java/com/example/zxa01/iotclient/component/login/LoginActivity.java
View file @
69a4f4b9
package
com.example.zxa01.iotclient.component.login
;
package
com.example.zxa01.iotclient.component.login
;
import
com.example.zxa01.iotclient.R
;
import
com.example.zxa01.iotclient.R
;
import
com.example.zxa01.iotclient.databinding.ActivityLoginBinding
;
import
com.example.zxa01.iotclient.databinding.ActivityLoginBinding
;
...
@@ -14,27 +15,32 @@ public class LoginActivity extends AppCompatActivity {
...
@@ -14,27 +15,32 @@ public class LoginActivity extends AppCompatActivity {
private
ActivityLoginBinding
binding
;
private
ActivityLoginBinding
binding
;
private
LoginViewModel
viewModel
;
private
LoginViewModel
viewModel
;
public
static
void
hideKeyboard
(
Activity
activity
)
{
InputMethodManager
imm
=
(
InputMethodManager
)
activity
.
getSystemService
(
Activity
.
INPUT_METHOD_SERVICE
);
View
view
=
activity
.
getCurrentFocus
();
if
(
view
==
null
)
{
view
=
new
View
(
activity
);
}
imm
.
hideSoftInputFromWindow
(
view
.
getWindowToken
(),
0
);
}
@Override
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
super
.
onCreate
(
savedInstanceState
);
binding
=
DataBindingUtil
.
setContentView
(
this
,
R
.
layout
.
activity_login
);
binding
=
DataBindingUtil
.
setContentView
(
this
,
R
.
layout
.
activity_login
);
binding
();
init
();
}
private
void
binding
()
{
viewModel
=
new
LoginViewModel
(
binding
.
getRoot
().
getContext
());
viewModel
=
new
LoginViewModel
(
binding
.
getRoot
().
getContext
());
binding
.
setViewModel
(
viewModel
);
binding
.
setViewModel
(
viewModel
);
binding
.
linearLoginForm
.
setOnClickListener
(
view
->
hideKeyboard
(
LoginActivity
.
this
));
binding
.
linearLoginForm
.
setOnClickListener
(
view
->
hideKeyboard
(
LoginActivity
.
this
));
init
();
}
}
private
void
init
()
{
private
void
init
()
{
viewModel
.
isAuthorized
().
observe
(
this
,
viewModel:
:
checkAuthorized
);
viewModel
.
isAuthorized
().
observe
(
this
,
viewModel:
:
checkAuthorized
);
}
public
static
void
hideKeyboard
(
Activity
activity
)
{
InputMethodManager
imm
=
(
InputMethodManager
)
activity
.
getSystemService
(
Activity
.
INPUT_METHOD_SERVICE
);
View
view
=
activity
.
getCurrentFocus
();
if
(
view
==
null
)
{
view
=
new
View
(
activity
);
}
imm
.
hideSoftInputFromWindow
(
view
.
getWindowToken
(),
0
);
}
}
}
}
app/src/main/java/com/example/zxa01/iotclient/component/login/LoginModel.java
View file @
69a4f4b9
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.component.login.pojo.LoginMessage
;
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.support.annotation.NonNull
;
...
@@ -10,31 +13,21 @@ import android.support.annotation.NonNull;
...
@@ -10,31 +13,21 @@ import android.support.annotation.NonNull;
public
class
LoginModel
extends
BaseObservable
{
public
class
LoginModel
extends
BaseObservable
{
private
MutableLiveData
<
Boolean
>
isAuthorized
;
private
MutableLiveData
<
Boolean
>
isAuthorized
;
private
static
String
USER
=
"使用者"
;
private
static
String
GATEWAY
=
"閘道器位置"
;
private
static
String
Port
=
"Port"
;
private
static
String
LOGOUT
=
"登出"
;
private
static
String
LOGOUT_MESSAGE
=
"登出本帳號"
;
public
LoginModel
()
{
public
LoginModel
()
{
isAuthorized
=
new
MutableLiveData
<>();
isAuthorized
=
new
MutableLiveData
<>();
isAuthorized
.
setValue
(
false
);
isAuthorized
.
setValue
(
false
);
}
}
public
MutableLiveData
<
Boolean
>
isAuthorized
(){
public
MutableLiveData
<
Boolean
>
isAuthorized
()
{
return
isAuthorized
;
return
isAuthorized
;
}
}
public
void
login
(
@NonNull
LoginMessage
message
)
{
public
void
login
(
@NonNull
LoginMessage
message
)
{
Config
.
getConfig
().
setUser
(
new
User
().
setAccount
(
message
.
getAccount
()));
if
(
verification
(
message
))
{
Config
.
getConfig
().
setGateway
(
message
.
getGateway
());
settingConfig
(
message
);
Config
.
getConfig
().
addSetting
(
new
Setting
(
USER
,
Config
.
getConfig
().
getUser
().
getAccount
()));
Config
.
getConfig
().
addSetting
(
new
Setting
(
GATEWAY
,
message
.
getGateway
()));
Config
.
getConfig
().
addSetting
(
new
Setting
(
Port
,
message
.
getGateway
()));
Config
.
getConfig
().
addSetting
(
new
Setting
(
LOGOUT
,
LOGOUT_MESSAGE
));
isAuthorized
.
setValue
(
true
);
isAuthorized
.
setValue
(
true
);
// Callback<Object> callback = new Callback<Object>() {
// Callback<Object> callback = new Callback<Object>() {
// @Override
// @Override
...
@@ -53,9 +46,21 @@ public class LoginModel extends BaseObservable {
...
@@ -53,9 +46,21 @@ public class LoginModel extends BaseObservable {
// Api.getApi().getDevices().enqueue(callback);
// Api.getApi().getDevices().enqueue(callback);
}
}
public
void
vaild
()
{
//TODO 驗證帳號格式
}
}
private
boolean
verification
(
@NonNull
LoginMessage
message
)
{
return
message
.
getAccount
()
!=
null
&&
message
.
getPassword
()
!=
null
&&
message
.
getGateway
()
!=
null
;
}
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
));
}
}
}
app/src/main/java/com/example/zxa01/iotclient/component/login/LoginViewModel.java
View file @
69a4f4b9
...
@@ -15,8 +15,8 @@ public class LoginViewModel extends ViewModel {
...
@@ -15,8 +15,8 @@ public class LoginViewModel extends ViewModel {
private
LoginModel
loginModel
=
new
LoginModel
();
private
LoginModel
loginModel
=
new
LoginModel
();
public
LoginViewModel
(
Context
context
)
{
public
LoginViewModel
(
Context
context
)
{
loginMessage
.
set
(
new
LoginMessage
());
this
.
context
=
context
;
this
.
context
=
context
;
loginMessage
.
set
(
new
LoginMessage
(
"192.168.2.69:8081"
,
"user"
,
"1234"
));
}
}
public
void
login
()
{
public
void
login
()
{
...
...
app/src/main/java/com/example/zxa01/iotclient/component/privacy/PrivacyActivity.java
View file @
69a4f4b9
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
;
...
@@ -17,15 +19,19 @@ public class PrivacyActivity extends AppCompatActivity {
...
@@ -17,15 +19,19 @@ public class PrivacyActivity extends AppCompatActivity {
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
super
.
onCreate
(
savedInstanceState
);
binding
=
DataBindingUtil
.
setContentView
(
this
,
R
.
layout
.
activity_privacy
);
binding
=
DataBindingUtil
.
setContentView
(
this
,
R
.
layout
.
activity_privacy
);
binding
();
init
();
}
private
void
binding
()
{
viewModel
=
new
PrivacyViewModel
(
binding
.
getRoot
().
getContext
());
viewModel
=
new
PrivacyViewModel
(
binding
.
getRoot
().
getContext
());
binding
.
setViewModel
(
viewModel
);
binding
.
setViewModel
(
viewModel
);
getSupportActionBar
().
setDisplayHomeAsUpEnabled
(
true
);
getSupportActionBar
().
setDisplayHomeAsUpEnabled
(
true
);
getSupportActionBar
().
setDisplayShowHomeEnabled
(
true
);
getSupportActionBar
().
setDisplayShowHomeEnabled
(
true
);
init
();
}
}
private
void
init
()
{
private
void
init
()
{
viewModel
.
fetchPrivacyPolicyReport
(
);
viewModel
.
fetchPrivacyPolicyReport
ByDevice
(
getIntent
().
getStringExtra
(
"udn"
)
);
viewModel
.
observePrivacyPolicyReportMLD
().
observe
(
this
,
viewModel:
:
setPrivacyPolicyReport
);
viewModel
.
observePrivacyPolicyReportMLD
().
observe
(
this
,
viewModel:
:
setPrivacyPolicyReport
);
viewModel
.
observeIsLoadingMLD
().
observe
(
this
,
viewModel:
:
setIsUpload
);
viewModel
.
observeIsLoadingMLD
().
observe
(
this
,
viewModel:
:
setIsUpload
);
}
}
...
@@ -38,5 +44,4 @@ public class PrivacyActivity extends AppCompatActivity {
...
@@ -38,5 +44,4 @@ public class PrivacyActivity extends AppCompatActivity {
return
super
.
onOptionsItemSelected
(
item
);
return
super
.
onOptionsItemSelected
(
item
);
}
}
}
}
app/src/main/java/com/example/zxa01/iotclient/component/privacy/PrivacyModel.java
View file @
69a4f4b9
This diff is collapsed.
Click to expand it.
app/src/main/java/com/example/zxa01/iotclient/component/privacy/PrivacyViewModel.java
View file @
69a4f4b9
package
com.example.zxa01.iotclient.component.privacy
;
package
com.example.zxa01.iotclient.component.privacy
;
import
com.example.zxa01.iotclient.R
;
import
com.example.zxa01.iotclient.R
;
import
com.example.zxa01.iotclient.common.pojo.privacy.PrivacyContent
;
import
com.example.zxa01.iotclient.common.pojo.privacy.PrivacyPolicy
;
import
com.example.zxa01.iotclient.common.pojo.privacy.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.shared.Config
;
import
android.arch.lifecycle.MutableLiveData
;
import
android.arch.lifecycle.MutableLiveData
;
import
android.arch.lifecycle.ViewModel
;
import
android.arch.lifecycle.ViewModel
;
...
@@ -12,13 +14,15 @@ import android.databinding.ObservableField;
...
@@ -12,13 +14,15 @@ import android.databinding.ObservableField;
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
;
import
java.util.List
;
import
java.util.List
;
public
class
PrivacyViewModel
extends
ViewModel
{
public
class
PrivacyViewModel
extends
ViewModel
{
public
ObservableBoolean
isLoading
=
new
ObservableBoolean
(
true
);
public
ObservableBoolean
isLoading
=
new
ObservableBoolean
(
true
);
public
ObservableBoolean
isUpload
=
new
ObservableBoolean
(
true
);
public
ObservableBoolean
isUpload
=
new
ObservableBoolean
(
true
);
public
ObservableField
<
PrivacyPolicyReport
>
privacyPolicyReport
=
new
ObservableField
<>(
new
PrivacyPolicyReport
());
public
ObservableField
<
PrivacyPolicyReport
>
privacyPolicyReport
=
new
ObservableField
<>();
private
PrivacyModel
privacyModel
=
new
PrivacyModel
();
private
PrivacyModel
privacyModel
=
new
PrivacyModel
();
private
PrivacyAdapter
adapter
=
new
PrivacyAdapter
(
R
.
layout
.
recycler_view_privacy
,
this
);
private
PrivacyAdapter
adapter
=
new
PrivacyAdapter
(
R
.
layout
.
recycler_view_privacy
,
this
);
private
Context
context
;
private
Context
context
;
...
@@ -26,15 +30,15 @@ public class PrivacyViewModel extends ViewModel {
...
@@ -26,15 +30,15 @@ public class PrivacyViewModel extends ViewModel {
public
PrivacyViewModel
(
Context
context
)
{
public
PrivacyViewModel
(
Context
context
)
{
this
.
context
=
context
;
this
.
context
=
context
;
this
.
drawDialog
();
drawDialog
();
}
}
/**
/**
* model
* model
*/
*/
public
void
fetchPrivacyPolicyReport
(
)
{
public
void
fetchPrivacyPolicyReport
ByDevice
(
String
udn
)
{
privacyModel
.
fetchPrivacyPolicyReport
(
);
privacyModel
.
readPrivacyPolicyReportByDevice
(
udn
);
}
}
public
MutableLiveData
<
PrivacyPolicyReport
>
observePrivacyPolicyReportMLD
()
{
public
MutableLiveData
<
PrivacyPolicyReport
>
observePrivacyPolicyReportMLD
()
{
...
@@ -42,17 +46,12 @@ public class PrivacyViewModel extends ViewModel {
...
@@ -42,17 +46,12 @@ public class PrivacyViewModel extends ViewModel {
}
}
public
void
setPrivacyPolicyReport
(
PrivacyPolicyReport
privacyPolicyReport
)
{
public
void
setPrivacyPolicyReport
(
PrivacyPolicyReport
privacyPolicyReport
)
{
if
(
privacyPolicyReport
.
getId
()
!=
null
)
{
if
(
privacyPolicyReport
!=
null
&&
privacyPolicyReport
.
getId
()
!=
null
)
{
this
.
isLoading
.
set
(
false
);
this
.
privacyPolicyReport
.
set
(
privacyPolicyReport
);
this
.
privacyPolicyReport
.
set
(
privacyPolicyReport
);
this
.
setAdapter
(
privacyPolicyReport
.
getPolicies
());
setAdapter
(
privacyPolicyReport
.
getPolicies
());
}
}
}
}
public
void
updateP3P
()
{
// TODO accpet privacy
}
/**
/**
* child model
* child model
*/
*/
...
@@ -66,13 +65,15 @@ public class PrivacyViewModel extends ViewModel {
...
@@ -66,13 +65,15 @@ public class PrivacyViewModel extends ViewModel {
return
null
;
return
null
;
}
}
public
void
on
ChangeClick
(
Integer
index
,
View
view
)
{
public
void
on
SetPrivacyChoice
(
Integer
index
,
View
view
)
{
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
)
{
// TODO change pp
privacyModel
.
setPrivacyChoice
(
privacyModel
.
updatePrivacyPolicyChoice
(
new
PrivacyContent
()
privacyModel
.
getPrivacyPolicyReportMLD
().
getValue
().
getPolicies
().
get
(
index
).
getId
(),
.
setUser
(
Config
.
getConfig
().
getUser
())
.
setDevice
(
privacyModel
.
getPrivacyPolicyReportMLD
().
getValue
().
getDevice
())
.
setPolicy
(
privacyModel
.
getPrivacyPolicyReportMLD
().
getValue
().
getPolicies
().
get
(
index
)),
((
Switch
)
view
).
isChecked
());
((
Switch
)
view
).
isChecked
());
}
}
}
}
...
@@ -107,8 +108,8 @@ public class PrivacyViewModel extends ViewModel {
...
@@ -107,8 +108,8 @@ public class PrivacyViewModel extends ViewModel {
}
}
public
void
setAdapter
(
List
<
PrivacyPolicy
>
privacyPolicies
)
{
public
void
setAdapter
(
List
<
PrivacyPolicy
>
privacyPolicies
)
{
isLoading
.
set
(
false
);
adapter
.
setPrivacyPolicyList
(
privacyPolicies
);
adapter
.
setPrivacyPolicyList
(
privacyPolicies
);
adapter
.
notifyDataSetChanged
();
}
}
}
}
app/src/main/res/drawable/gradient_theme.xml
0 → 100644
View file @
69a4f4b9
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:shape=
"rectangle"
>
<gradient
android:startColor=
"@color/colorPrimaryDark"
android:endColor=
"@color/colorAccent"
android:angle=
"180"
/>
</shape>
\ No newline at end of file
app/src/main/res/layout/activity_detail.xml
View file @
69a4f4b9
...
@@ -128,7 +128,7 @@
...
@@ -128,7 +128,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.
UDN
}"
android:text=
"@{viewModel.device.
udn
}"
android:textSize=
"@dimen/font"
/>
android:textSize=
"@dimen/font"
/>
</LinearLayout>
</LinearLayout>
...
@@ -335,7 +335,6 @@
...
@@ -335,7 +335,6 @@
android:text=
"@{viewModel.device.model.name}"
android:text=
"@{viewModel.device.model.name}"
android:textSize=
"@dimen/font"
/>
android:textSize=
"@dimen/font"
/>
</LinearLayout>
</LinearLayout>
</TableRow>
</TableRow>
...
@@ -478,6 +477,7 @@
...
@@ -478,6 +477,7 @@
</TableLayout>
</TableLayout>
</android.support.constraint.ConstraintLayout>
</android.support.constraint.ConstraintLayout>
</ScrollView>
</ScrollView>
</layout>
</layout>
\ No newline at end of file
app/src/main/res/layout/activity_home.xml
View file @
69a4f4b9
...
@@ -3,6 +3,13 @@
...
@@ -3,6 +3,13 @@
xmlns:app=
"http://schemas.android.com/apk/res-auto"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
xmlns:tools=
"http://schemas.android.com/tools"
>
xmlns:tools=
"http://schemas.android.com/tools"
>
<data>
<variable
name=
"viewModel"
type=
"com.example.zxa01.iotclient.component.home.HomeViewModel"
/>
</data>
<android.support.constraint.ConstraintLayout
<android.support.constraint.ConstraintLayout
android:id=
"@+id/container"
android:id=
"@+id/container"
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
...
...
app/src/main/res/layout/activity_privacy.xml
View file @
69a4f4b9
...
@@ -54,7 +54,7 @@
...
@@ -54,7 +54,7 @@
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_weight=
"1"
android:layout_weight=
"1"
android:text=
"@string/title_privacy"
android:text=
"@string/title_privacy"
android:textColor=
"@color/color
Accent
"
android:textColor=
"@color/color
Primary
"
android:textSize=
"@dimen/font_lg"
/>
android:textSize=
"@dimen/font_lg"
/>
<TextView
<TextView
...
@@ -92,6 +92,8 @@
...
@@ -92,6 +92,8 @@
android:layout_height=
"match_parent"
android:layout_height=
"match_parent"
android:clipToPadding=
"false"
android:clipToPadding=
"false"
android:paddingTop=
"@dimen/padding"
android:paddingTop=
"@dimen/padding"
android:layout_marginLeft=
"@dimen/margin_sm"
android:layout_marginRight=
"@dimen/margin_sm"
app:setAdapter=
"@{viewModel.getAdapter()}"
app:setAdapter=
"@{viewModel.getAdapter()}"
tools:listitem=
"@layout/recycler_view_privacy"
/>
tools:listitem=
"@layout/recycler_view_privacy"
/>
...
...
app/src/main/res/layout/fragment_device.xml
View file @
69a4f4b9
...
@@ -23,6 +23,8 @@
...
@@ -23,6 +23,8 @@
android:layout_height=
"match_parent"
android:layout_height=
"match_parent"
android:clipToPadding=
"false"
android:clipToPadding=
"false"
android:paddingTop=
"@dimen/padding"
android:paddingTop=
"@dimen/padding"
android:layout_marginRight=
"@dimen/margin_sm"
android:layout_marginLeft=
"@dimen/margin_sm"
app:setAdapter=
"@{viewModel.getAdapter()}"
app:setAdapter=
"@{viewModel.getAdapter()}"
tools:listitem=
"@layout/recycler_view_device"
/>
tools:listitem=
"@layout/recycler_view_device"
/>
...
...
app/src/main/res/layout/recycler_view_device.xml
View file @
69a4f4b9
...
@@ -53,7 +53,7 @@
...
@@ -53,7 +53,7 @@
android:layout_width=
"285dp"
android:layout_width=
"285dp"
android:layout_height=
"20dp"
android:layout_height=
"20dp"
android:layout_marginStart=
"16dp"
android:layout_marginStart=
"16dp"
android:text=
"@{viewModel.getDeviceAt(position).
UDN
}"
android:text=
"@{viewModel.getDeviceAt(position).
udn
}"
app:layout_constraintBottom_toBottomOf=
"@+id/image_device"
app:layout_constraintBottom_toBottomOf=
"@+id/image_device"
app:layout_constraintStart_toEndOf=
"@+id/image_device"
app:layout_constraintStart_toEndOf=
"@+id/image_device"
tools:text=
"subtitle"
/>
tools:text=
"subtitle"
/>
...
@@ -64,6 +64,7 @@
...
@@ -64,6 +64,7 @@
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginEnd=
"8dp"
android:layout_marginEnd=
"8dp"
android:textSize=
"12sp"
android:textSize=
"12sp"
android:text=
"@{viewModel.getDeviceAt(position).status.toString()}"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintTop_toTopOf=
"@+id/image_device"
app:layout_constraintTop_toTopOf=
"@+id/image_device"
tools:text=
"connection"
/>
tools:text=
"connection"
/>
...
...
app/src/main/res/layout/recycler_view_privacy.xml
View file @
69a4f4b9
...
@@ -24,17 +24,9 @@
...
@@ -24,17 +24,9 @@
<LinearLayout
<LinearLayout
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:layout_height=
"match_parent"
android:paddingBottom=
"@dimen/padding_sm"
android:orientation=
"vertical"
>
android:orientation=
"vertical"
>
<TextView
android:id=
"@+id/textViewTitle"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_weight=
"1"
android:text=
"@string/title_privacy"
android:textColor=
"@color/colorAccent"
android:textSize=
"@dimen/font_lg"
/>
<LinearLayout
<LinearLayout
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
...
@@ -45,15 +37,15 @@
...
@@ -45,15 +37,15 @@
android:layout_width=
"wrap_content"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
'@{@string/privacy_title+" "+String.valueOf(position+1)}'
android:text=
'@{@string/privacy_title+" "+String.valueOf(position+1)}'
android:textColor=
"@color/colorGra
y"
android:textColor=
"@color/colorPrimar
y"
android:textSize=
"@dimen/font"
/>
android:textSize=
"@dimen/font"
/>
<Switch
<Switch
android:id=
"@+id/switch1"
android:id=
"@+id/switch1"
android:layout_width=
"wrap_content
"
android:layout_width=
"0dp
"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_weight=
"1"
android:layout_weight=
"1"
android:onClick=
"@{(view)->viewModel.onChangeClick
(position,view)}"
android:onClick=
"@{(view)->viewModel.onSetPrivacyChoice
(position,view)}"
android:text=
"@string/privacy_content"
android:text=
"@string/privacy_content"
android:textAlignment=
"textEnd"
android:textAlignment=
"textEnd"
android:thumbTextPadding=
"@dimen/padding_lg"
/>
android:thumbTextPadding=
"@dimen/padding_lg"
/>
...
...
app/src/main/res/values/colors.xml
View file @
69a4f4b9
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<resources>
<color
name=
"colorPrimary"
>
#1da1f2
</color>
<color
name=
"colorPrimaryDark"
>
#0D92E1
</color>
<color
name=
"colorPrimary"
>
#1D76D2
</color>
<color
name=
"colorPrimaryDark"
>
#1666BF
</color>
<color
name=
"colorAccent"
>
#2A4474
</color>
<color
name=
"colorAccent"
>
#2A4474
</color>
<color
name=
"colorGray"
>
#2d2d2d
</color>
<color
name=
"colorGray"
>
#2d2d2d
</color>
<color
name=
"colorLight"
>
#808080
</color>
<color
name=
"colorLight"
>
#808080
</color>
<color
name=
"colorLighter"
>
#dadada
</color>
<color
name=
"colorLighter"
>
#E4E4E4
</color>
<color
name=
"colorLightest"
>
#F4F4F4
</color>
<color
name=
"colorWhite"
>
#FFFFFF
</color>
<color
name=
"colorWhite"
>
#FFFFFF
</color>
<color
name=
"colorTransparent"
>
#00000000
</color>
<color
name=
"colorTransparent"
>
#00000000
</color>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment