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
02077da9
Commit
02077da9
authored
May 30, 2019
by
DESKTOP-NFGF3PG\zxa01
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update download file
parent
738ed6f5
Changes
15
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
92 additions
and
41 deletions
+92
-41
app/src/main/java/com/example/zxa01/iotclient/common/pojo/index/PrivacyPolicyReportResponse.java
...client/common/pojo/index/PrivacyPolicyReportResponse.java
+32
-0
app/src/main/java/com/example/zxa01/iotclient/common/singleton/DefaultData.java
...example/zxa01/iotclient/common/singleton/DefaultData.java
+4
-1
app/src/main/java/com/example/zxa01/iotclient/common/tools/Api.java
...in/java/com/example/zxa01/iotclient/common/tools/Api.java
+4
-3
app/src/main/java/com/example/zxa01/iotclient/common/tools/DownloadFile.java
...om/example/zxa01/iotclient/common/tools/DownloadFile.java
+6
-12
app/src/main/java/com/example/zxa01/iotclient/component/detail/DetailModel.java
...example/zxa01/iotclient/component/detail/DetailModel.java
+5
-3
app/src/main/java/com/example/zxa01/iotclient/component/detail/DetailViewModel.java
...ple/zxa01/iotclient/component/detail/DetailViewModel.java
+3
-3
app/src/main/java/com/example/zxa01/iotclient/component/home/HomeActivity.java
.../example/zxa01/iotclient/component/home/HomeActivity.java
+1
-1
app/src/main/java/com/example/zxa01/iotclient/component/home/device/DeviceFragment.java
...zxa01/iotclient/component/home/device/DeviceFragment.java
+1
-1
app/src/main/java/com/example/zxa01/iotclient/component/home/device/bind/DeviceBindFragment.java
...client/component/home/device/bind/DeviceBindFragment.java
+2
-2
app/src/main/java/com/example/zxa01/iotclient/component/home/device/bind/DeviceBindViewModel.java
...lient/component/home/device/bind/DeviceBindViewModel.java
+8
-5
app/src/main/java/com/example/zxa01/iotclient/component/privacy/PrivacyActivity.java
...le/zxa01/iotclient/component/privacy/PrivacyActivity.java
+1
-0
app/src/main/java/com/example/zxa01/iotclient/component/privacy/PrivacyModel.java
...ample/zxa01/iotclient/component/privacy/PrivacyModel.java
+12
-8
app/src/main/java/com/example/zxa01/iotclient/component/privacy/PrivacyViewModel.java
...e/zxa01/iotclient/component/privacy/PrivacyViewModel.java
+11
-1
app/src/main/res/layout/fragment_device_bind.xml
app/src/main/res/layout/fragment_device_bind.xml
+1
-1
app/src/main/res/layout/recycler_view_privacy.xml
app/src/main/res/layout/recycler_view_privacy.xml
+1
-0
No files found.
app/src/main/java/com/example/zxa01/iotclient/common/pojo/index/PrivacyPolicyReportResponse.java
0 → 100644
View file @
02077da9
package
com.example.zxa01.iotclient.common.pojo.index
;
import
android.provider.DocumentsContract
;
import
com.example.zxa01.iotclient.common.pojo.device.Device
;
import
com.example.zxa01.iotclient.common.pojo.privacy.PrivacyPolicy
;
import
com.example.zxa01.iotclient.common.pojo.privacy.PrivacyPolicyReport
;
import
java.util.HashMap
;
import
java.util.List
;
public
class
PrivacyPolicyReportResponse
extends
PrivacyPolicyReport
{
private
HashMap
<
Integer
,
Boolean
>
choices
;
public
PrivacyPolicyReportResponse
(){
super
();
}
public
PrivacyPolicyReportResponse
(
String
id
,
String
version
,
String
description
,
Device
device
,
List
<
PrivacyPolicy
>
policies
,
DocumentsContract
.
Document
document
,
HashMap
<
Integer
,
Boolean
>
choices
)
{
super
();
this
.
choices
=
choices
;
}
public
HashMap
<
Integer
,
Boolean
>
getChoices
()
{
return
choices
;
}
public
void
setChoices
(
HashMap
<
Integer
,
Boolean
>
choices
)
{
this
.
choices
=
choices
;
}
}
app/src/main/java/com/example/zxa01/iotclient/common/singleton/DefaultData.java
View file @
02077da9
...
...
@@ -10,9 +10,12 @@ public class DefaultData {
private
static
DefaultData
defaultData
=
new
DefaultData
();
private
LoginMessage
loginMessage
;
private
List
<
String
>
devices
=
new
LinkedList
<>();
public
String
gatewayServer
=
"http://192.168.2.90:8080"
;
public
String
cloudServer
=
"http://192.168.2.90:8081"
;
private
DefaultData
()
{
loginMessage
=
new
LoginMessage
(
"192.168.2.69:8080"
,
"user"
,
"1234"
);
loginMessage
=
new
LoginMessage
(
gatewayServer
,
"user"
,
"1234"
);
devices
.
add
(
"a1252c49-4188-4e6d-a32e-66604c664fb8"
);
devices
.
add
(
"abe5ca7b-780e-4857-87e6-014870fe0a3e"
);
}
...
...
app/src/main/java/com/example/zxa01/iotclient/common/tools/Api.java
View file @
02077da9
...
...
@@ -2,6 +2,7 @@ package com.example.zxa01.iotclient.common.tools;
import
com.example.zxa01.iotclient.common.pojo.device.Device
;
import
com.example.zxa01.iotclient.common.pojo.index.PrivacyChoiceResponse
;
import
com.example.zxa01.iotclient.common.pojo.index.PrivacyPolicyReportResponse
;
import
com.example.zxa01.iotclient.common.pojo.privacy.PrivacyChoice
;
import
com.example.zxa01.iotclient.common.pojo.privacy.PrivacyPolicyReport
;
import
com.example.zxa01.iotclient.common.singleton.Config
;
...
...
@@ -26,7 +27,7 @@ public class Api {
public
static
ApiInterface
getApi
()
{
retrofit
=
new
Retrofit
.
Builder
()
.
baseUrl
(
"http://"
+
Config
.
getConfig
().
getGateway
())
.
baseUrl
(
Config
.
getConfig
().
getGateway
())
.
client
(
new
OkHttpClient
.
Builder
()
.
connectTimeout
(
10
,
TimeUnit
.
SECONDS
)
.
cache
(
null
)
...
...
@@ -54,8 +55,8 @@ public class Api {
Call
<
Device
>
bindDeviceAndGateway
(
@Path
(
"udn"
)
String
udn
);
// 取得該裝置的隱私政策與相關資料
@GET
(
"/privacy/{udn}"
)
Call
<
PrivacyPolicyReport
>
readPrivacyPolicyReportByDevice
(
@Path
(
"udn"
)
String
udn
);
@GET
(
"/privacy/{udn}
/{account}
"
)
Call
<
PrivacyPolicyReport
Response
>
readPrivacyPolicyReportByDevice
(
@Path
(
"udn"
)
String
udn
,
@Path
(
"account"
)
String
account
);
// 表達隱私偏好
@POST
(
"/choice"
)
...
...
app/src/main/java/com/example/zxa01/iotclient/common/tools/DownloadFile.java
View file @
02077da9
...
...
@@ -93,25 +93,19 @@ public class DownloadFile {
connection
.
connect
();
downloadFileName
=
java
.
net
.
URLDecoder
.
decode
(
connection
.
getHeaderField
(
"Content-Disposition"
).
replace
(
"Attachment; filename="
,
""
),
connection
.
getHeaderField
(
"Content-Disposition"
)
.
substring
(
connection
.
getHeaderField
(
"Content-Disposition"
).
indexOf
(
"="
)+
1
)
.
replace
(
"UTF-8''"
,
""
)
.
trim
(),
String
.
valueOf
(
StandardCharsets
.
UTF_8
));
// check SDCard
if
(
new
CheckForSDCard
().
isSDCardPresent
())
{
apkStorage
=
new
File
(
Environment
.
getExternalStorageDirectory
().
toString
()
+
"/report"
);
}
else
{
if
(!
new
CheckForSDCard
().
isSDCardPresent
())
{
Toast
.
makeText
(
context
,
"There is no SD Card."
,
Toast
.
LENGTH_SHORT
).
show
();
}
// check directory
if
(!
apkStorage
.
exists
())
{
apkStorage
.
mkdir
();
Log
.
e
(
TAG
,
"Directory Created."
);
}
// check file
outputFile
=
new
File
(
apkStorage
,
downloadFileName
);
outputFile
=
new
File
(
Environment
.
getExternalStoragePublicDirectory
(
Environment
.
DIRECTORY_DOWNLOADS
)
,
downloadFileName
);
if
(!
outputFile
.
exists
())
{
outputFile
.
createNewFile
();
outputFile
.
setWritable
(
true
);
...
...
app/src/main/java/com/example/zxa01/iotclient/component/detail/DetailModel.java
View file @
02077da9
...
...
@@ -5,6 +5,8 @@ import android.databinding.BaseObservable;
import
android.support.annotation.NonNull
;
import
android.util.Log
;
import
com.example.zxa01.iotclient.common.pojo.index.PrivacyPolicyReportResponse
;
import
com.example.zxa01.iotclient.common.singleton.Config
;
import
com.example.zxa01.iotclient.common.tools.Api
;
import
com.example.zxa01.iotclient.common.pojo.device.Device
;
import
com.example.zxa01.iotclient.common.pojo.privacy.PrivacyPolicyReport
;
...
...
@@ -29,16 +31,16 @@ public class DetailModel extends BaseObservable {
}
public
void
readDevice
(
@NonNull
String
udn
)
{
Api
.
getApi
().
readPrivacyPolicyReportByDevice
(
udn
).
enqueue
(
new
Callback
<
PrivacyPolicyReport
>()
{
Api
.
getApi
().
readPrivacyPolicyReportByDevice
(
udn
,
Config
.
getConfig
().
getUser
().
getAccount
()).
enqueue
(
new
Callback
<
PrivacyPolicyReportResponse
>()
{
@Override
public
void
onResponse
(
Call
<
PrivacyPolicyReport
>
call
,
Response
<
PrivacyPolicyReport
>
response
)
{
public
void
onResponse
(
Call
<
PrivacyPolicyReport
Response
>
call
,
Response
<
PrivacyPolicyReportResponse
>
response
)
{
Log
.
i
(
"readDevices - onResponse()"
,
"success"
);
setDeviceMLD
(
response
==
null
||
response
.
body
()
==
null
?
null
:
response
.
body
().
getDevice
());
}
@Override
public
void
onFailure
(
Call
<
PrivacyPolicyReport
>
call
,
Throwable
t
)
{
public
void
onFailure
(
Call
<
PrivacyPolicyReport
Response
>
call
,
Throwable
t
)
{
Log
.
e
(
"readDevice - onFailure()"
,
t
.
getMessage
(),
t
);
}
});
...
...
app/src/main/java/com/example/zxa01/iotclient/component/detail/DetailViewModel.java
View file @
02077da9
package
com.example.zxa01.iotclient.component.detail
;
import
com.example.zxa01.iotclient.common.pojo.device.Device
;
import
com.example.zxa01.iotclient.common.singleton.Config
;
import
com.example.zxa01.iotclient.common.singleton.DefaultData
;
import
com.example.zxa01.iotclient.common.tools.DownloadFile
;
import
com.example.zxa01.iotclient.component.privacy.PrivacyActivity
;
import
android.arch.lifecycle.MutableLiveData
;
...
...
@@ -48,8 +50,6 @@ public class DetailViewModel extends ViewModel {
}
public
void
downloadPrivacyReport
()
{
// fake file just for test
String
url
=
"https://www.ey.gov.tw/File/4EBD1D15E6556A04?A=C"
;
new
DownloadFile
(
context
,
url
);
new
DownloadFile
(
context
,
DefaultData
.
getDefaultData
().
cloudServer
+
"/document/"
+
device
.
get
().
getUdn
());
}
}
app/src/main/java/com/example/zxa01/iotclient/component/home/HomeActivity.java
View file @
02077da9
...
...
@@ -75,7 +75,7 @@ public class HomeActivity extends AppCompatActivity {
@Override
public
void
onActivityResult
(
int
requestCode
,
int
resultCode
,
Intent
intent
)
{
if
(
resultCode
==
RESULT_OK
)
{
new
DeviceBindViewModel
().
bindDeviceAndGateway
(
intent
.
getStringExtra
(
"SCAN_RESULT"
));
new
DeviceBindViewModel
(
this
).
bindDeviceAndGateway
(
intent
.
getStringExtra
(
"SCAN_RESULT"
));
}
else
{
new
AlertDialog
.
Builder
(
this
)
.
setMessage
(
R
.
string
.
bind_qrcode_error
)
...
...
app/src/main/java/com/example/zxa01/iotclient/component/home/device/DeviceFragment.java
View file @
02077da9
...
...
@@ -35,7 +35,7 @@ public class DeviceFragment extends Fragment {
viewModel
=
new
DeviceViewModel
(
binding
.
getRoot
().
getContext
());
binding
.
setViewModel
(
viewModel
);
binding
.
fab
.
setOnClickListener
(
item
->
drawDialog
());
binding
.
fabRefresh
.
setOnClickListener
(
item
->
init
());
binding
.
fabRefresh
.
setOnClickListener
(
item
->
viewModel
.
readDevices
());
binding
.
deviceRecyclerView
.
setLayoutManager
(
new
LinearLayoutManager
(
getActivity
()));
deviceBindFragment
=
new
DeviceBindFragment
();
}
...
...
app/src/main/java/com/example/zxa01/iotclient/component/home/device/bind/DeviceBindFragment.java
View file @
02077da9
...
...
@@ -14,8 +14,8 @@ import com.example.zxa01.iotclient.databinding.FragmentDeviceBindBinding;
public
class
DeviceBindFragment
extends
DialogFragment
{
p
rivate
DeviceBindViewModel
viewModel
;
p
rivate
FragmentDeviceBindBinding
binding
;
p
ublic
DeviceBindViewModel
viewModel
;
p
ublic
FragmentDeviceBindBinding
binding
;
public
DeviceBindFragment
()
{
}
...
...
app/src/main/java/com/example/zxa01/iotclient/component/home/device/bind/DeviceBindViewModel.java
View file @
02077da9
...
...
@@ -13,6 +13,7 @@ import android.support.v7.app.AlertDialog;
import
com.example.zxa01.iotclient.R
;
import
com.example.zxa01.iotclient.common.singleton.DefaultData
;
import
com.example.zxa01.iotclient.component.home.HomeActivity
;
public
class
DeviceBindViewModel
extends
ViewModel
{
...
...
@@ -25,15 +26,19 @@ public class DeviceBindViewModel extends ViewModel {
public
ObservableField
<
String
>
udn
=
new
ObservableField
<>();
private
DeviceBindModel
deviceBindModel
=
new
DeviceBindModel
();
private
Fragment
fragment
;
private
Context
context
;
private
AlertDialog
dialog
;
public
DeviceBindViewModel
(){
public
DeviceBindViewModel
(
Context
context
){
this
.
context
=
context
;
}
public
DeviceBindViewModel
(
Fragment
fragment
)
{
this
.
fragment
=
fragment
;
this
.
context
=
fragment
.
getContext
();
drawDialog
();
// default udn
udn
.
set
(
DefaultData
.
getDefaultData
().
getDevices
().
get
(
0
));
}
/**
...
...
@@ -42,11 +47,9 @@ public class DeviceBindViewModel extends ViewModel {
public
void
bindDeviceAndGateway
(
String
udn
)
{
deviceBindModel
.
bindDeviceAndGateway
(
udn
);
context
.
startActivity
(
new
Intent
(
context
,
HomeActivity
.
class
));
}
public
void
bindDeviceAndGateway
()
{
deviceBindModel
.
bindDeviceAndGateway
(
udn
.
get
());
}
public
void
qrcode
()
{
try
{
...
...
app/src/main/java/com/example/zxa01/iotclient/component/privacy/PrivacyActivity.java
View file @
02077da9
...
...
@@ -32,6 +32,7 @@ public class PrivacyActivity extends AppCompatActivity {
viewModel
.
fetchPrivacyPolicyReportByDevice
(
getIntent
().
getStringExtra
(
"udn"
));
viewModel
.
observePrivacyPolicyReportMLD
().
observe
(
this
,
viewModel:
:
setPrivacyPolicyReport
);
viewModel
.
observeIsLoadingMLD
().
observe
(
this
,
viewModel:
:
setIsUpload
);
// viewModel.observeMappingChoiceMLD().observe(this,viewModel::);
}
@Override
...
...
app/src/main/java/com/example/zxa01/iotclient/component/privacy/PrivacyModel.java
View file @
02077da9
...
...
@@ -6,6 +6,7 @@ import android.os.Handler;
import
android.support.annotation.NonNull
;
import
android.util.Log
;
import
com.example.zxa01.iotclient.common.pojo.index.PrivacyPolicyReportResponse
;
import
com.example.zxa01.iotclient.common.tools.Api
;
import
com.example.zxa01.iotclient.common.pojo.index.PrivacyChoiceResponse
;
import
com.example.zxa01.iotclient.common.pojo.privacy.PrivacyChoice
;
...
...
@@ -13,22 +14,26 @@ import com.example.zxa01.iotclient.common.pojo.privacy.PrivacyContent;
import
com.example.zxa01.iotclient.common.pojo.privacy.PrivacyPolicyReport
;
import
com.example.zxa01.iotclient.common.singleton.Config
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
retrofit2.Call
;
import
retrofit2.Callback
;
import
retrofit2.Response
;
public
class
PrivacyModel
extends
BaseObservable
{
private
MutableLiveData
<
PrivacyPolicyReportResponse
>
privacyPolicyReportMLD
=
new
MutableLiveData
<>();
private
MutableLiveData
<
Boolean
>
isUploadMLD
=
new
MutableLiveData
<>();
private
MutableLiveData
<
PrivacyPolicyReport
>
privacyPolicyReportMLD
=
new
MutableLiveData
<>();
public
PrivacyModel
()
{
privacyPolicyReportMLD
.
setValue
(
new
PrivacyPolicyReport
());
privacyPolicyReportMLD
.
setValue
(
new
PrivacyPolicyReport
Response
());
isUploadMLD
.
setValue
(
false
);
}
public
MutableLiveData
<
PrivacyPolicyReport
>
getPrivacyPolicyReportMLD
()
{
public
MutableLiveData
<
PrivacyPolicyReport
Response
>
getPrivacyPolicyReportMLD
()
{
return
privacyPolicyReportMLD
;
}
...
...
@@ -37,20 +42,19 @@ public class PrivacyModel extends BaseObservable {
}
public
void
readPrivacyPolicyReportByDevice
(
@NonNull
String
udn
)
{
Api
.
getApi
().
readPrivacyPolicyReportByDevice
(
udn
).
enqueue
(
new
Callback
<
PrivacyPolicyReport
>()
{
Api
.
getApi
().
readPrivacyPolicyReportByDevice
(
udn
,
Config
.
getConfig
().
getUser
().
getAccount
()).
enqueue
(
new
Callback
<
PrivacyPolicyReportResponse
>()
{
@Override
public
void
onResponse
(
Call
<
PrivacyPolicyReport
>
call
,
Response
<
PrivacyPolicyReport
>
response
)
{
public
void
onResponse
(
Call
<
PrivacyPolicyReport
Response
>
call
,
Response
<
PrivacyPolicyReportResponse
>
response
)
{
privacyPolicyReportMLD
.
setValue
(
response
.
body
());
}
@Override
public
void
onFailure
(
Call
<
PrivacyPolicyReport
>
call
,
Throwable
t
)
{
public
void
onFailure
(
Call
<
PrivacyPolicyReport
Response
>
call
,
Throwable
t
)
{
Log
.
e
(
"readPrivacyPolicyReportByDevice - onFailure()"
,
t
.
getMessage
(),
t
);
}
});
}
public
void
setPrivacyChoice
(
@NonNull
PrivacyContent
privacyContent
,
@NonNull
boolean
isAccepted
)
{
isUploadMLD
.
setValue
(
true
);
Api
.
getApi
().
setPrivacyChoice
(
new
PrivacyChoice
()
...
...
app/src/main/java/com/example/zxa01/iotclient/component/privacy/PrivacyViewModel.java
View file @
02077da9
package
com.example.zxa01.iotclient.component.privacy
;
import
com.example.zxa01.iotclient.R
;
import
com.example.zxa01.iotclient.common.pojo.index.PrivacyPolicyReportResponse
;
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.PrivacyPolicyReport
;
...
...
@@ -42,10 +43,11 @@ public class PrivacyViewModel extends ViewModel {
privacyModel
.
readPrivacyPolicyReportByDevice
(
udn
);
}
public
MutableLiveData
<
PrivacyPolicyReport
>
observePrivacyPolicyReportMLD
()
{
public
MutableLiveData
<
PrivacyPolicyReport
Response
>
observePrivacyPolicyReportMLD
()
{
return
privacyModel
.
getPrivacyPolicyReportMLD
();
}
public
void
setPrivacyPolicyReport
(
PrivacyPolicyReport
privacyPolicyReport
)
{
if
(
privacyPolicyReport
!=
null
&&
privacyPolicyReport
.
getId
()
!=
null
)
{
this
.
privacyPolicyReport
.
set
(
privacyPolicyReport
);
...
...
@@ -65,6 +67,14 @@ public class PrivacyViewModel extends ViewModel {
return
null
;
}
public
boolean
getPrivacyResponseAt
(
@NonNull
Integer
index
)
{
if
(
privacyModel
.
getPrivacyPolicyReportMLD
().
getValue
()
!=
null
&&
privacyModel
.
getPrivacyPolicyReportMLD
().
getValue
().
getPolicies
().
size
()
>
index
)
{
return
privacyModel
.
getPrivacyPolicyReportMLD
().
getValue
().
getChoices
().
get
(
index
);
}
return
false
;
}
public
void
onSetPrivacyChoice
(
@NonNull
Integer
index
,
View
view
)
{
if
(
privacyModel
.
getPrivacyPolicyReportMLD
().
getValue
()
!=
null
&&
privacyModel
.
getPrivacyPolicyReportMLD
().
getValue
().
getPolicies
().
size
()
>
index
)
{
...
...
app/src/main/res/layout/fragment_device_bind.xml
View file @
02077da9
...
...
@@ -75,7 +75,7 @@
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_weight=
"1"
android:onClick=
"@{()->viewModel.bindDeviceAndGateway()}"
android:onClick=
"@{()->viewModel.bindDeviceAndGateway(
viewModel.udn
)}"
android:text=
"@string/bind_button_correct"
/>
</LinearLayout>
...
...
app/src/main/res/layout/recycler_view_privacy.xml
View file @
02077da9
...
...
@@ -48,6 +48,7 @@
android:onClick=
"@{(view)->viewModel.onSetPrivacyChoice(position,view)}"
android:text=
"@string/privacy_content"
android:textAlignment=
"textEnd"
android:checked=
"@{viewModel.getPrivacyResponseAt(position)}"
android:thumbTextPadding=
"@dimen/padding_lg"
/>
</LinearLayout>
...
...
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