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