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
6913b966
Commit
6913b966
authored
Apr 22, 2019
by
DESKTOP-NFGF3PG\zxa01
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
commit detail and privacy of device
parent
b010ef94
Changes
42
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
42 changed files
with
1148 additions
and
520 deletions
+1148
-520
.idea/codeStyles/Project.xml
.idea/codeStyles/Project.xml
+0
-29
.idea/encodings.xml
.idea/encodings.xml
+4
-0
app/build.gradle
app/build.gradle
+9
-2
app/src/main/AndroidManifest.xml
app/src/main/AndroidManifest.xml
+13
-7
app/src/main/java/com/example/zxa01/iotclient/common/bindings/CustomViewBindings.java
...e/zxa01/iotclient/common/bindings/CustomViewBindings.java
+1
-1
app/src/main/java/com/example/zxa01/iotclient/common/http/Api.java
...ain/java/com/example/zxa01/iotclient/common/http/Api.java
+6
-3
app/src/main/java/com/example/zxa01/iotclient/common/http/HttpService.java
.../com/example/zxa01/iotclient/common/http/HttpService.java
+1
-2
app/src/main/java/com/example/zxa01/iotclient/common/pojo/Setting.java
...java/com/example/zxa01/iotclient/common/pojo/Setting.java
+1
-1
app/src/main/java/com/example/zxa01/iotclient/detail/model/DetailModel.java
...com/example/zxa01/iotclient/detail/model/DetailModel.java
+7
-0
app/src/main/java/com/example/zxa01/iotclient/detail/view/DetailActivity.java
...m/example/zxa01/iotclient/detail/view/DetailActivity.java
+31
-0
app/src/main/java/com/example/zxa01/iotclient/home/HomeActivity.java
...n/java/com/example/zxa01/iotclient/home/HomeActivity.java
+19
-18
app/src/main/java/com/example/zxa01/iotclient/home/device/model/DeviceModel.java
...xample/zxa01/iotclient/home/device/model/DeviceModel.java
+78
-9
app/src/main/java/com/example/zxa01/iotclient/home/device/model/DevicesModel.java
...ample/zxa01/iotclient/home/device/model/DevicesModel.java
+0
-65
app/src/main/java/com/example/zxa01/iotclient/home/device/view/DeviceAdapter.java
...ample/zxa01/iotclient/home/device/view/DeviceAdapter.java
+7
-7
app/src/main/java/com/example/zxa01/iotclient/home/device/view/DeviceFragment.java
...mple/zxa01/iotclient/home/device/view/DeviceFragment.java
+9
-6
app/src/main/java/com/example/zxa01/iotclient/home/device/view/create/DeviceCreateFragment.java
...tclient/home/device/view/create/DeviceCreateFragment.java
+3
-7
app/src/main/java/com/example/zxa01/iotclient/home/device/viewModel/DeviceViewModel.java
...xa01/iotclient/home/device/viewModel/DeviceViewModel.java
+88
-0
app/src/main/java/com/example/zxa01/iotclient/home/record/RecordFragment.java
...m/example/zxa01/iotclient/home/record/RecordFragment.java
+8
-8
app/src/main/java/com/example/zxa01/iotclient/home/setting/SettingAdapter.java
.../example/zxa01/iotclient/home/setting/SettingAdapter.java
+1
-1
app/src/main/java/com/example/zxa01/iotclient/home/setting/SettingFragment.java
...example/zxa01/iotclient/home/setting/SettingFragment.java
+1
-1
app/src/main/java/com/example/zxa01/iotclient/login/LoginActivity.java
...java/com/example/zxa01/iotclient/login/LoginActivity.java
+0
-150
app/src/main/java/com/example/zxa01/iotclient/login/model/LoginModel.java
...a/com/example/zxa01/iotclient/login/model/LoginModel.java
+45
-0
app/src/main/java/com/example/zxa01/iotclient/login/pojo/LoginMessage.java
.../com/example/zxa01/iotclient/login/pojo/LoginMessage.java
+43
-0
app/src/main/java/com/example/zxa01/iotclient/login/view/LoginActivity.java
...com/example/zxa01/iotclient/login/view/LoginActivity.java
+41
-0
app/src/main/java/com/example/zxa01/iotclient/login/viewModel/LoginViewModel.java
...ample/zxa01/iotclient/login/viewModel/LoginViewModel.java
+39
-0
app/src/main/java/com/example/zxa01/iotclient/pojo/Device.java
...rc/main/java/com/example/zxa01/iotclient/pojo/Device.java
+0
-70
app/src/main/java/com/example/zxa01/iotclient/privacy/PrivacyActivity.java
.../com/example/zxa01/iotclient/privacy/PrivacyActivity.java
+13
-0
app/src/main/res/drawable/border_bottom.xml
app/src/main/res/drawable/border_bottom.xml
+3
-3
app/src/main/res/drawable/border_bottom_xl.xml
app/src/main/res/drawable/border_bottom_xl.xml
+21
-0
app/src/main/res/layout/activity_detail.xml
app/src/main/res/layout/activity_detail.xml
+473
-0
app/src/main/res/layout/activity_home.xml
app/src/main/res/layout/activity_home.xml
+25
-28
app/src/main/res/layout/activity_login.xml
app/src/main/res/layout/activity_login.xml
+91
-75
app/src/main/res/layout/activity_privacy.xml
app/src/main/res/layout/activity_privacy.xml
+16
-0
app/src/main/res/layout/fragment_device.xml
app/src/main/res/layout/fragment_device.xml
+15
-2
app/src/main/res/layout/fragment_record.xml
app/src/main/res/layout/fragment_record.xml
+2
-2
app/src/main/res/layout/recycler_view_device.xml
app/src/main/res/layout/recycler_view_device.xml
+7
-8
app/src/main/res/menu/navigation.xml
app/src/main/res/menu/navigation.xml
+3
-3
app/src/main/res/values/colors.xml
app/src/main/res/values/colors.xml
+2
-1
app/src/main/res/values/strings.xml
app/src/main/res/values/strings.xml
+14
-8
app/src/main/res/values/styles.xml
app/src/main/res/values/styles.xml
+5
-0
build.gradle
build.gradle
+1
-1
gradle/wrapper/gradle-wrapper.properties
gradle/wrapper/gradle-wrapper.properties
+2
-2
No files found.
.idea/codeStyles/Project.xml
deleted
100644 → 0
View file @
b010ef94
<component
name=
"ProjectCodeStyleConfiguration"
>
<code_scheme
name=
"Project"
version=
"173"
>
<Objective-C-extensions>
<file>
<option
name=
"com.jetbrains.cidr.lang.util.OCDeclarationKind"
value=
"Import"
/>
<option
name=
"com.jetbrains.cidr.lang.util.OCDeclarationKind"
value=
"Macro"
/>
<option
name=
"com.jetbrains.cidr.lang.util.OCDeclarationKind"
value=
"Typedef"
/>
<option
name=
"com.jetbrains.cidr.lang.util.OCDeclarationKind"
value=
"Enum"
/>
<option
name=
"com.jetbrains.cidr.lang.util.OCDeclarationKind"
value=
"Constant"
/>
<option
name=
"com.jetbrains.cidr.lang.util.OCDeclarationKind"
value=
"Global"
/>
<option
name=
"com.jetbrains.cidr.lang.util.OCDeclarationKind"
value=
"Struct"
/>
<option
name=
"com.jetbrains.cidr.lang.util.OCDeclarationKind"
value=
"FunctionPredecl"
/>
<option
name=
"com.jetbrains.cidr.lang.util.OCDeclarationKind"
value=
"Function"
/>
</file>
<class>
<option
name=
"com.jetbrains.cidr.lang.util.OCDeclarationKind"
value=
"Property"
/>
<option
name=
"com.jetbrains.cidr.lang.util.OCDeclarationKind"
value=
"Synthesize"
/>
<option
name=
"com.jetbrains.cidr.lang.util.OCDeclarationKind"
value=
"InitMethod"
/>
<option
name=
"com.jetbrains.cidr.lang.util.OCDeclarationKind"
value=
"StaticMethod"
/>
<option
name=
"com.jetbrains.cidr.lang.util.OCDeclarationKind"
value=
"InstanceMethod"
/>
<option
name=
"com.jetbrains.cidr.lang.util.OCDeclarationKind"
value=
"DeallocMethod"
/>
</class>
<extensions>
<pair
source=
"cpp"
header=
"h"
fileNamingConvention=
"NONE"
/>
<pair
source=
"c"
header=
"h"
fileNamingConvention=
"NONE"
/>
</extensions>
</Objective-C-extensions>
</code_scheme>
</component>
\ No newline at end of file
.idea/encodings.xml
0 → 100644
View file @
6913b966
<?xml version="1.0" encoding="UTF-8"?>
<project
version=
"4"
>
<component
name=
"Encoding"
addBOMForNewFiles=
"with NO BOM"
/>
</project>
\ No newline at end of file
app/build.gradle
View file @
6913b966
...
...
@@ -32,14 +32,21 @@ dependencies {
implementation
'com.android.support.constraint:constraint-layout:1.1.3'
implementation
'com.android.support:support-v4:28.0.0'
implementation
'com.android.support:recyclerview-v7:28.0.0'
implementation
"com.squareup.retrofit2:retrofit:2.1.0"
implementation
"com.squareup.retrofit2:converter-gson:2.1.0"
testImplementation
'junit:junit:4.12'
androidTestImplementation
'com.android.support.test:runner:1.0.2'
androidTestImplementation
'com.android.support.test.espresso:espresso-core:3.0.2'
// rxjava
implementation
"io.reactivex:rxjava:1.1.8"
implementation
"io.reactivex:rxandroid:1.2.1"
// retrofit2
implementation
"com.squareup.retrofit2:retrofit: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 @
6913b966
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android=
"http://schemas.android.com/apk/res/android"
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.READ_PROFILE"
/>
...
...
@@ -17,24 +16,31 @@
android:theme=
"@style/AppTheme"
>
<activity
android:name=
".login.LoginActivity"
android:name=
".login.
view.
LoginActivity"
android:label=
"@string/app_name"
android:screenOrientation=
"portrait"
android:windowSoftInputMode=
"adjustPan"
>
android:windowSoftInputMode=
"adjustPan"
>
<intent-filter>
<action
android:name=
"android.intent.action.MAIN"
/>
<category
android:name=
"android.intent.category.LAUNCHER"
/>
</intent-filter>
</activity>
<activity
android:name=
".home.HomeActivity"
android:label=
"@string/app_name"
android:screenOrientation=
"portrait"
android:windowSoftInputMode=
"adjustPan"
></activity>
android:windowSoftInputMode=
"adjustPan"
/>
<activity
android:name=
".detail.view.DetailActivity"
android:label=
"@string/title_detail"
android:screenOrientation=
"portrait"
></activity>
<activity
android:name=
".privacy.PrivacyActivity"
android:label=
"@string/title_privacy"
android:screenOrientation=
"portrait"
/>
</application>
</manifest>
\ No newline at end of file
app/src/main/java/com/example/zxa01/iotclient/bindings/CustomViewBindings.java
→
app/src/main/java/com/example/zxa01/iotclient/
common/
bindings/CustomViewBindings.java
View file @
6913b966
package
com.example.zxa01.iotclient.bindings
;
package
com.example.zxa01.iotclient.
common.
bindings
;
import
android.databinding.BindingAdapter
;
import
android.support.v7.widget.LinearLayoutManager
;
...
...
app/src/main/java/com/example/zxa01/iotclient/http/Api.java
→
app/src/main/java/com/example/zxa01/iotclient/
common/
http/Api.java
View file @
6913b966
package
com.example.zxa01.iotclient.http
;
package
com.example.zxa01.iotclient.
common.
http
;
import
com.example.zxa01.iotclient.home.device.model.DeviceModel
;
import
com.example.zxa01.iotclient.home.device.model.DevicesModel
;
import
com.google.gson.Gson
;
import
com.google.gson.GsonBuilder
;
...
...
@@ -11,6 +9,7 @@ import retrofit2.Call;
import
retrofit2.Retrofit
;
import
retrofit2.converter.gson.GsonConverterFactory
;
import
retrofit2.http.GET
;
import
retrofit2.http.POST
;
public
class
Api
{
...
...
@@ -38,6 +37,10 @@ public class Api {
public
interface
ApiInterface
{
@GET
(
"/api/breeds/list/all"
)
Call
<
Object
>
getDevices
();
@POST
(
"/api/breeds/list/all"
)
Call
<
Object
>
login
();
// @GET("/api/breed/{breed}/images")
// Call<DogBreedImages> getImagesByBreed(@Path("breed") String breed);
...
...
app/src/main/java/com/example/zxa01/iotclient/http/HttpService.java
→
app/src/main/java/com/example/zxa01/iotclient/
common/
http/HttpService.java
View file @
6913b966
package
com.example.zxa01.iotclient.http
;
package
com.example.zxa01.iotclient.
common.
http
;
import
java.io.IOException
;
import
okhttp3.Call
;
import
okhttp3.Callback
;
import
okhttp3.MediaType
;
import
okhttp3.OkHttpClient
;
import
okhttp3.Request
;
...
...
app/src/main/java/com/example/zxa01/iotclient/pojo/Setting.java
→
app/src/main/java/com/example/zxa01/iotclient/
common/
pojo/Setting.java
View file @
6913b966
package
com.example.zxa01.iotclient.pojo
;
package
com.example.zxa01.iotclient.
common.
pojo
;
public
class
Setting
{
private
String
key
;
...
...
app/src/main/java/com/example/zxa01/iotclient/detail/model/DetailModel.java
0 → 100644
View file @
6913b966
package
com.example.zxa01.iotclient.detail.model
;
import
android.databinding.BaseObservable
;
public
class
DetailModel
extends
BaseObservable
{
}
app/src/main/java/com/example/zxa01/iotclient/detail/view/DetailActivity.java
0 → 100644
View file @
6913b966
package
com.example.zxa01.iotclient.detail.view
;
import
android.databinding.DataBindingUtil
;
import
android.support.v7.app.AppCompatActivity
;
import
android.os.Bundle
;
import
android.view.MenuItem
;
import
android.widget.Toolbar
;
import
com.example.zxa01.iotclient.R
;
import
com.example.zxa01.iotclient.databinding.ActivityDetailBinding
;
public
class
DetailActivity
extends
AppCompatActivity
{
private
ActivityDetailBinding
binding
;
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
binding
=
DataBindingUtil
.
setContentView
(
this
,
R
.
layout
.
activity_detail
);
getSupportActionBar
().
setDisplayHomeAsUpEnabled
(
true
);
getSupportActionBar
().
setDisplayShowHomeEnabled
(
true
);
}
@Override
public
boolean
onOptionsItemSelected
(
MenuItem
item
)
{
if
(
item
.
getItemId
()
==
android
.
R
.
id
.
home
)
{
finish
();
}
return
super
.
onOptionsItemSelected
(
item
);
}
}
app/src/main/java/com/example/zxa01/iotclient/home/HomeActivity.java
View file @
6913b966
package
com.example.zxa01.iotclient.home
;
import
com.example.zxa01.iotclient.R
;
import
com.example.zxa01.iotclient.databinding.ActivityHomeBinding
;
import
com.example.zxa01.iotclient.home.device.view.DeviceFragment
;
import
com.example.zxa01.iotclient.home.device.viewModel.DeviceViewModel
;
import
com.example.zxa01.iotclient.home.record.RecordFragment
;
import
com.example.zxa01.iotclient.home.setting.SettingFragment
;
import
android.content.Intent
;
import
android.databinding.DataBindingUtil
;
import
android.net.Uri
;
import
android.os.Bundle
;
import
android.support.design.widget.BottomNavigationView
;
import
android.support.v4.app.Fragment
;
import
android.support.v4.app.FragmentTransaction
;
import
android.support.v7.app.AlertDialog
;
import
android.support.v7.app.AppCompatActivity
;
import
com.example.zxa01.iotclient.R
;
import
com.example.zxa01.iotclient.databinding.ActivityHomeBinding
;
import
com.example.zxa01.iotclient.home.device.view.DeviceFragment
;
import
com.example.zxa01.iotclient.home.device.viewModel.DevicesViewModel
;
import
com.example.zxa01.iotclient.home.privacy.PrivacyFragment
;
import
com.example.zxa01.iotclient.home.setting.SettingFragment
;
import
android.databinding.DataBindingUtil
;
public
class
HomeActivity
extends
AppCompatActivity
implements
DeviceFragment
.
OnFragmentInteractionListener
,
Privacy
Fragment
.
OnFragmentInteractionListener
,
Record
Fragment
.
OnFragmentInteractionListener
,
SettingFragment
.
OnFragmentInteractionListener
{
/* data binding */
private
ActivityHomeBinding
binding
;
/* fragments of HomeActivity */
private
DeviceFragment
mDeviceFragment
=
new
DeviceFragment
();
private
PrivacyFragment
mPrivacyFragment
=
new
Privacy
Fragment
();
private
RecordFragment
mRecordFragment
=
new
Record
Fragment
();
private
SettingFragment
mSettingFragment
=
new
SettingFragment
();
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
binding
=
DataBindingUtil
.
setContentView
(
this
,
R
.
layout
.
activity_home
);
binding
=
DataBindingUtil
.
setContentView
(
this
,
R
.
layout
.
activity_home
);
/* init */
setupFragment
(
binding
.
navigation
);
showFragment
(
mDeviceFragment
);
}
...
...
@@ -51,7 +50,7 @@ public class HomeActivity extends AppCompatActivity implements
}
/* onItemSelected of fragment */
private
void
setupFragment
(
BottomNavigationView
view
){
private
void
setupFragment
(
BottomNavigationView
view
)
{
view
.
setOnNavigationItemSelectedListener
(
menuItem
->
{
switch
(
menuItem
.
getItemId
())
{
...
...
@@ -59,7 +58,7 @@ public class HomeActivity extends AppCompatActivity implements
showFragment
(
mDeviceFragment
);
return
true
;
case
R
.
id
.
navigation_privacy
:
showFragment
(
m
Privacy
Fragment
);
showFragment
(
m
Record
Fragment
);
return
true
;
case
R
.
id
.
navigation_setting
:
showFragment
(
mSettingFragment
);
...
...
@@ -80,10 +79,12 @@ public class HomeActivity extends AppCompatActivity implements
@Override
public
void
onActivityResult
(
int
requestCode
,
int
resultCode
,
Intent
intent
)
{
if
(
requestCode
==
0
)
{
if
(
resultCode
==
RESULT_OK
)
{
new
DevicesViewModel
().
createDevice
(
intent
.
getStringExtra
(
"SCAN_RESULT"
));
}
if
(
resultCode
==
RESULT_OK
)
{
new
DeviceViewModel
().
createDevice
(
intent
.
getStringExtra
(
"SCAN_RESULT"
));
}
else
{
new
AlertDialog
.
Builder
(
this
)
.
setMessage
(
R
.
string
.
qrcode_error
)
.
show
();
}
}
}
app/src/main/java/com/example/zxa01/iotclient/home/device/model/DeviceModel.java
View file @
6913b966
package
com.example.zxa01.iotclient.home.device.model
;
import
com.example.zxa01.iotclient.pojo.Device
;
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
android.arch.lifecycle.MutableLiveData
;
import
android.databinding.BaseObservable
;
import
android.util.Log
;
import
java.util.ArrayList
;
import
java.util.List
;
import
retrofit2.Call
;
import
retrofit2.Callback
;
import
retrofit2.Response
;
public
class
DeviceModel
extends
BaseObservable
{
private
Device
device
;
private
String
status
;
private
List
<
Device
>
deviceList
;
private
MutableLiveData
<
List
<
Device
>>
devices
;
// 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"
)
.
setStatus
(
Device
.
Status
.
Disconnected
);
public
DeviceModel
(
Device
device
){
this
.
device
=
device
;
public
DeviceModel
()
{
deviceList
=
new
ArrayList
<>();
devices
=
new
MutableLiveData
<>();
}
public
Device
getDevice
(
)
{
return
device
;
public
void
addDevice
(
Device
device
)
{
deviceList
.
add
(
device
)
;
}
public
void
setDevice
(
Device
device
)
{
this
.
device
=
device
;
public
MutableLiveData
<
List
<
Device
>>
getDevices
(
)
{
return
devices
;
}
}
public
void
fetchDevices
()
{
Callback
<
Object
>
callback
=
new
Callback
<
Object
>()
{
@Override
public
void
onResponse
(
Call
<
Object
>
call
,
Response
<
Object
>
response
)
{
// TODO transfer response
Log
.
i
(
"Test"
,
response
.
message
());
DeviceModel
deviceModel
=
new
DeviceModel
();
deviceModel
.
addDevice
(
oxygenDevice
);
deviceModel
.
addDevice
(
oxygenDevice
);
devices
.
setValue
(
deviceModel
.
deviceList
);
status
=
"success"
;
}
@Override
public
void
onFailure
(
Call
<
Object
>
call
,
Throwable
t
)
{
Log
.
e
(
"fetchDevices - onFailure()"
,
t
.
getMessage
(),
t
);
}
};
Api
.
getApi
().
getDevices
().
enqueue
(
callback
);
}
public
void
createDevice
(
String
address
)
{
// TODO api post-createDevice & update
}
public
String
getStatus
()
{
return
status
;
}
public
void
setStatus
(
String
statue
)
{
this
.
status
=
statue
;
}
}
app/src/main/java/com/example/zxa01/iotclient/home/device/model/DevicesModel.java
deleted
100644 → 0
View file @
b010ef94
package
com.example.zxa01.iotclient.home.device.model
;
import
android.arch.lifecycle.MutableLiveData
;
import
android.databinding.BaseObservable
;
import
android.util.Log
;
import
com.example.zxa01.iotclient.http.Api
;
import
com.example.zxa01.iotclient.pojo.Device
;
import
java.util.ArrayList
;
import
java.util.List
;
import
retrofit2.Call
;
import
retrofit2.Callback
;
import
retrofit2.Response
;
public
class
DevicesModel
extends
BaseObservable
{
private
String
status
;
private
List
<
DeviceModel
>
deviceList
=
new
ArrayList
<>();
private
MutableLiveData
<
List
<
DeviceModel
>>
devices
=
new
MutableLiveData
<>();
public
void
addDevice
(
DeviceModel
device
)
{
deviceList
.
add
(
device
);
}
public
MutableLiveData
<
List
<
DeviceModel
>>
getDevices
()
{
return
devices
;
}
public
void
fetchDevices
()
{
Callback
<
Object
>
callback
=
new
Callback
<
Object
>()
{
@Override
public
void
onResponse
(
Call
<
Object
>
call
,
Response
<
Object
>
response
)
{
// TODO transfer response
Log
.
i
(
"Test"
,
response
.
message
());
DevicesModel
devicesModel
=
new
DevicesModel
();
devicesModel
.
addDevice
(
new
DeviceModel
(
new
Device
(
1
,
"test"
,
"test"
,
"test"
,
true
)));
devices
.
setValue
(
devicesModel
.
deviceList
);
status
=
"success"
;
}
@Override
public
void
onFailure
(
Call
<
Object
>
call
,
Throwable
t
)
{
Log
.
e
(
"Test"
,
t
.
getMessage
(),
t
);
}
};
Api
.
getApi
().
getDevices
().
enqueue
(
callback
);
}
public
void
createDevice
(
String
address
)
{
// TODO api post-createDevice & update
}
public
String
getStatus
()
{
return
status
;
}
public
void
setStatus
(
String
statue
)
{
this
.
status
=
statue
;
}
}
app/src/main/java/com/example/zxa01/iotclient/home/device/view/DeviceAdapter.java
View file @
6913b966
...
...
@@ -9,18 +9,18 @@ import android.view.LayoutInflater;
import
android.view.ViewGroup
;
import
com.example.zxa01.iotclient.BR
;
import
com.example.zxa01.iotclient.
home.device.model.DeviceModel
;
import
com.example.zxa01.iotclient.home.device.viewModel.Device
s
ViewModel
;
import
com.example.zxa01.iotclient.
common.pojo.device.Device
;
import
com.example.zxa01.iotclient.home.device.viewModel.DeviceViewModel
;
import
java.util.List
;
public
class
DeviceAdapter
extends
RecyclerView
.
Adapter
<
DeviceAdapter
.
MyViewHolder
>
{
private
int
layoutId
;
private
List
<
Device
Model
>
deviceList
;
private
Device
s
ViewModel
viewModel
;
private
List
<
Device
>
deviceList
;
private
DeviceViewModel
viewModel
;
public
DeviceAdapter
(
@LayoutRes
int
layoutId
,
Device
s
ViewModel
viewModel
)
{
public
DeviceAdapter
(
@LayoutRes
int
layoutId
,
DeviceViewModel
viewModel
)
{
this
.
layoutId
=
layoutId
;
this
.
viewModel
=
viewModel
;
}
...
...
@@ -50,7 +50,7 @@ public class DeviceAdapter extends RecyclerView.Adapter<DeviceAdapter.MyViewHold
return
getLayoutIdForPosition
(
position
);
}
public
void
setDevices
(
List
<
Device
Model
>
deviceList
)
{
public
void
setDevices
(
List
<
Device
>
deviceList
)
{
this
.
deviceList
=
deviceList
;
}
...
...
@@ -63,7 +63,7 @@ public class DeviceAdapter extends RecyclerView.Adapter<DeviceAdapter.MyViewHold
this
.
binding
=
binding
;
}
void
bind
(
Device
s
ViewModel
viewModel
,
Integer
position
)
{
void
bind
(
DeviceViewModel
viewModel
,
Integer
position
)
{
viewModel
.
getDeviceAt
(
position
);
binding
.
setVariable
(
BR
.
viewModel
,
viewModel
);
binding
.
setVariable
(
BR
.
position
,
position
);
...
...
app/src/main/java/com/example/zxa01/iotclient/home/device/view/DeviceFragment.java
View file @
6913b966
...
...
@@ -10,15 +10,16 @@ import android.support.v7.widget.LinearLayoutManager;
import
android.view.LayoutInflater
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
com.example.zxa01.iotclient.R
;
import
com.example.zxa01.iotclient.databinding.FragmentDeviceBinding
;
import
com.example.zxa01.iotclient.home.device.viewModel.Device
s
ViewModel
;
import
com.example.zxa01.iotclient.home.device.viewModel.DeviceViewModel
;
import
com.example.zxa01.iotclient.home.device.view.create.DeviceCreateFragment
;
public
class
DeviceFragment
extends
Fragment
{
private
FragmentDeviceBinding
binding
;
private
Device
sViewModel
viewModel
=
new
DevicesViewModel
()
;
private
Device
ViewModel
viewModel
;
public
DeviceFragment
()
{
}
...
...
@@ -31,8 +32,11 @@ public class DeviceFragment extends Fragment {
public
View
onCreateView
(
LayoutInflater
inflater
,
ViewGroup
container
,
Bundle
savedInstanceState
)
{
binding
=
DataBindingUtil
.
inflate
(
inflater
,
R
.
layout
.
fragment_device
,
container
,
false
);
viewModel
=
new
DeviceViewModel
(
binding
.
getRoot
().
getContext
());
binding
.
setViewModel
(
viewModel
);
setup
();
binding
.
fab
.
setOnClickListener
(
item
->
drawDialog
());
binding
.
deviceRecyclerView
.
setLayoutManager
(
new
LinearLayoutManager
(
getActivity
()));
init
();
return
binding
.
getRoot
();
}
...
...
@@ -46,9 +50,7 @@ public class DeviceFragment extends Fragment {
super
.
onDetach
();
}
private
void
setup
()
{
binding
.
fab
.
setOnClickListener
(
item
->
drawDialog
());
binding
.
deviceRecyclerView
.
setLayoutManager
(
new
LinearLayoutManager
(
getActivity
()));
private
void
init
()
{
viewModel
.
refreshDevices
();
viewModel
.
getDevices
().
observe
(
this
,
deviceList
->
viewModel
.
setAdapter
(
deviceList
));
}
...
...
@@ -63,6 +65,7 @@ public class DeviceFragment extends Fragment {
new
DeviceCreateFragment
().
show
(
fragmentTransaction
,
String
.
valueOf
(
R
.
string
.
dialog
));
}
public
interface
OnFragmentInteractionListener
{
void
onDeviceFragment
(
Uri
uri
);
}
...
...
app/src/main/java/com/example/zxa01/iotclient/home/device/view/create/DeviceCreateFragment.java
View file @
6913b966
...
...
@@ -13,7 +13,7 @@ import android.view.ViewGroup;
import
com.example.zxa01.iotclient.R
;
import
com.example.zxa01.iotclient.databinding.FragmentDeviceCreateBinding
;
import
com.example.zxa01.iotclient.home.device.viewModel.Device
s
ViewModel
;
import
com.example.zxa01.iotclient.home.device.viewModel.DeviceViewModel
;
public
class
DeviceCreateFragment
extends
DialogFragment
{
...
...
@@ -34,14 +34,10 @@ public class DeviceCreateFragment extends DialogFragment {
return
new
AlertDialog
.
Builder
(
getActivity
())
.
setView
(
R
.
layout
.
fragment_device_create
)
.
setNeutralButton
(
R
.
string
.
button_qrcode
,
(
dialog
,
whichButton
)
->
{
qrcodeIntent
();
}
(
dialog
,
whichButton
)
->
qrcodeIntent
()
)
.
setPositiveButton
(
R
.
string
.
button_correct
,
(
dialog
,
whichButton
)
->
{
new
DevicesViewModel
().
createDevice
(
"address"
);
}
(
dialog
,
whichButton
)
->
new
DeviceViewModel
().
createDevice
(
"address"
)
)
.
setNegativeButton
(
R
.
string
.
button_cancel
,
(
dialog
,
whichButton
)
->
{
})
...
...
app/src/main/java/com/example/zxa01/iotclient/home/device/viewModel/Device
s
ViewModel.java
→
app/src/main/java/com/example/zxa01/iotclient/home/device/viewModel/DeviceViewModel.java
View file @
6913b966
package
com.example.zxa01.iotclient.home.device.viewModel
;
import
com.example.zxa01.iotclient.R
;
import
com.example.zxa01.iotclient.home.device.model.DeviceModel
;
import
com.example.zxa01.iotclient.common.pojo.device.Device
;
import
com.example.zxa01.iotclient.detail.view.DetailActivity
;
import
com.example.zxa01.iotclient.home.device.view.DeviceAdapter
;
import
com.example.zxa01.iotclient.home.device.model.DevicesModel
;
import
com.example.zxa01.iotclient.pojo.Device
;
import
com.example.zxa01.iotclient.home.device.model.DeviceModel
;
import
android.arch.lifecycle.MutableLiveData
;
import
android.arch.lifecycle.ViewModel
;
import
android.databinding.ObservableArrayList
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.databinding.ObservableBoolean
;
import
android.databinding.ObservableList
;
import
android.util.Log
;
import
java.util.List
;
import
retrofit2.Call
;
import
retrofit2.Response
;
public
class
DevicesViewModel
extends
ViewModel
{
public
class
DeviceViewModel
extends
ViewModel
{
public
Observable
List
<
Device
>
mDevices
=
new
ObservableArrayList
<>(
);
p
ublic
ObservableBoolean
isLoading
=
new
ObservableBoolean
(
false
)
;
private
Device
sModel
devicesModel
=
new
Devices
Model
();
public
Observable
Boolean
isLoading
=
new
ObservableBoolean
(
true
);
p
rivate
Context
context
;
private
Device
Model
deviceModel
=
new
Device
Model
();
private
DeviceAdapter
adapter
=
new
DeviceAdapter
(
R
.
layout
.
recycler_view_device
,
this
);
public
DeviceViewModel
(
Context
context
)
{
this
.
context
=
context
;
}
public
DeviceViewModel
()
{
}
/**
* model
*/
public
void
refreshDevices
()
{
device
s
Model
.
fetchDevices
();
deviceModel
.
fetchDevices
();
}
public
MutableLiveData
<
List
<
Device
Model
>>
getDevices
()
{
return
device
s
Model
.
getDevices
();
public
MutableLiveData
<
List
<
Device
>>
getDevices
()
{
return
deviceModel
.
getDevices
();
}
public
void
createDevice
(
String
address
)
{
device
s
Model
.
createDevice
(
address
);
deviceModel
.
createDevice
(
address
);
this
.
refreshDevices
();
}
...
...
@@ -46,15 +51,26 @@ public class DevicesViewModel extends ViewModel {
* child model
*/
public
Device
Model
getDeviceAt
(
Integer
index
)
{
if
(
device
s
Model
.
getDevices
().
getValue
()
!=
null
&&
public
Device
getDeviceAt
(
Integer
index
)
{
if
(
deviceModel
.
getDevices
().
getValue
()
!=
null
&&
index
!=
null
&&
device
s
Model
.
getDevices
().
getValue
().
size
()
>
index
)
{
return
device
s
Model
.
getDevices
().
getValue
().
get
(
index
);
deviceModel
.
getDevices
().
getValue
().
size
()
>
index
)
{
return
deviceModel
.
getDevices
().
getValue
().
get
(
index
);
}
return
null
;
}
public
void
onDevicesClick
(
Integer
index
)
{
if
(
deviceModel
.
getDevices
().
getValue
()
!=
null
&&
index
!=
null
&&
deviceModel
.
getDevices
().
getValue
().
size
()
>
index
)
{
// TODO detail of device
context
.
startActivity
(
new
Intent
(
context
,
DetailActivity
.
class
)
.
putExtra
(
"index"
,
index
));
}
}
/**
* adapter
*/
...
...
@@ -63,7 +79,8 @@ public class DevicesViewModel extends ViewModel {
return
adapter
;
}
public
void
setAdapter
(
List
<
DeviceModel
>
deviceList
)
{
public
void
setAdapter
(
List
<
Device
>
deviceList
)
{
this
.
isLoading
.
set
(
false
);
this
.
adapter
.
setDevices
(
deviceList
);
this
.
adapter
.
notifyDataSetChanged
();
}
...
...
app/src/main/java/com/example/zxa01/iotclient/home/
privacy/Privacy
Fragment.java
→
app/src/main/java/com/example/zxa01/iotclient/home/
record/Record
Fragment.java
View file @
6913b966
package
com.example.zxa01.iotclient.home.
privacy
;
package
com.example.zxa01.iotclient.home.
record
;
import
android.content.Context
;
import
android.net.Uri
;
...
...
@@ -13,12 +13,12 @@ import com.example.zxa01.iotclient.R;
/**
* A simple {@link Fragment} subclass.
* Activities that contain this fragment must implement the
* {@link
Privacy
Fragment.OnFragmentInteractionListener} interface
* {@link
Record
Fragment.OnFragmentInteractionListener} interface
* to handle interaction events.
* Use the {@link
Privacy
Fragment#newInstance} factory method to
* Use the {@link
Record
Fragment#newInstance} factory method to
* create an instance of this fragment.
*/
public
class
Privacy
Fragment
extends
Fragment
{
public
class
Record
Fragment
extends
Fragment
{
// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private
static
final
String
ARG_PARAM1
=
"param1"
;
...
...
@@ -30,7 +30,7 @@ public class PrivacyFragment extends Fragment {
private
OnFragmentInteractionListener
mListener
;
public
Privacy
Fragment
()
{
public
Record
Fragment
()
{
// Required empty public constructor
}
...
...
@@ -43,8 +43,8 @@ public class PrivacyFragment extends Fragment {
* @return A new instance of fragment PrivacyFragment.
*/
// TODO: Rename and change types and number of parameters
public
static
Privacy
Fragment
newInstance
(
String
param1
,
String
param2
)
{
PrivacyFragment
fragment
=
new
Privacy
Fragment
();
public
static
Record
Fragment
newInstance
(
String
param1
,
String
param2
)
{
RecordFragment
fragment
=
new
Record
Fragment
();
Bundle
args
=
new
Bundle
();
args
.
putString
(
ARG_PARAM1
,
param1
);
args
.
putString
(
ARG_PARAM2
,
param2
);
...
...
@@ -65,7 +65,7 @@ public class PrivacyFragment extends Fragment {
public
View
onCreateView
(
LayoutInflater
inflater
,
ViewGroup
container
,
Bundle
savedInstanceState
)
{
// Inflate the layout for this fragment
return
inflater
.
inflate
(
R
.
layout
.
fragment_
privacy
,
container
,
false
);
return
inflater
.
inflate
(
R
.
layout
.
fragment_
record
,
container
,
false
);
}
// TODO: Rename method, update argument and hook method into UI event
...
...
app/src/main/java/com/example/zxa01/iotclient/home/setting/SettingAdapter.java
View file @
6913b966
...
...
@@ -7,7 +7,7 @@ import android.view.ViewGroup;
import
android.widget.TextView
;
import
com.example.zxa01.iotclient.R
;
import
com.example.zxa01.iotclient.pojo.Setting
;
import
com.example.zxa01.iotclient.
common.
pojo.Setting
;
import
java.util.LinkedList
;
...
...
app/src/main/java/com/example/zxa01/iotclient/home/setting/SettingFragment.java
View file @
6913b966
...
...
@@ -11,7 +11,7 @@ import android.view.View;
import
android.view.ViewGroup
;
import
com.example.zxa01.iotclient.R
;
import
com.example.zxa01.iotclient.pojo.Setting
;
import
com.example.zxa01.iotclient.
common.
pojo.Setting
;
import
java.util.LinkedList
;
...
...
app/src/main/java/com/example/zxa01/iotclient/login/LoginActivity.java
deleted
100644 → 0
View file @
b010ef94
package
com.example.zxa01.iotclient.login
;
import
android.app.Activity
;
import
android.content.Intent
;
import
android.os.AsyncTask
;
import
android.os.Bundle
;
import
android.support.v7.app.AppCompatActivity
;
import
android.view.View
;
import
android.view.inputmethod.InputMethodManager
;
import
android.widget.Button
;
import
android.widget.EditText
;
import
android.widget.LinearLayout
;
import
com.example.zxa01.iotclient.R
;
import
com.example.zxa01.iotclient.home.HomeActivity
;
import
butterknife.BindView
;
import
butterknife.ButterKnife
;
public
class
LoginActivity
extends
AppCompatActivity
{
@BindView
(
R
.
id
.
gateway
)
EditText
mGatewayView
;
@BindView
(
R
.
id
.
account
)
EditText
mAccountView
;
@BindView
(
R
.
id
.
password
)
EditText
mPasswordView
;
@BindView
(
R
.
id
.
sign_in_button
)
Button
mSignInButton
;
@BindView
(
R
.
id
.
linear_login_form
)
LinearLayout
mLayoutLoginForm
;
private
Activity
activity
=
this
;
private
UserLoginTask
mAuthTask
=
null
;
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R
.
layout
.
activity_login
);
ButterKnife
.
bind
(
this
);
mSignInButton
.
setOnClickListener
(
view
->
attemptLogin
());
mLayoutLoginForm
.
setOnClickListener
(
view
->
hideKeyboard
(
activity
));
}
private
void
attemptLogin
()
{
if
(
mAuthTask
!=
null
)
{
return
;
}
mAccountView
.
setError
(
null
);
mPasswordView
.
setError
(
null
);
String
gateway
=
mGatewayView
.
getText
().
toString
();
String
account
=
mAccountView
.
getText
().
toString
();
String
password
=
mPasswordView
.
getText
().
toString
();
boolean
cancel
=
false
;
View
focusView
=
null
;
// check
// if (!TextUtils.isEmpty(gateway) && !isLengthValid(gateway)) {
// mGatewayView.setError(getString(R.string.error_invalid_gateway));
// focusView = mGatewayView;
// cancel = true;
// }
// if (!TextUtils.isEmpty(password) && !isLengthValid(password)) {
// mPasswordView.setError(getString(R.string.error_invalid_password));
// focusView = mPasswordView;
// cancel = true;
// }
// if (TextUtils.isEmpty(account)) {
// mAccountView.setError(getString(R.string.error_field_required));
// focusView = mAccountView;
// cancel = true;
// } else if (!isLengthValid(account)) {
// mAccountView.setError(getString(R.string.error_invalid_account));
// focusView = mAccountView;
// cancel = true;
// }
if
(
cancel
)
{
focusView
.
requestFocus
();
}
else
{
mAuthTask
=
new
UserLoginTask
(
account
,
password
);
mAuthTask
.
execute
((
Void
)
null
);
}
}
private
boolean
isLengthValid
(
String
text
)
{
return
text
.
length
()
>
3
;
}
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
);
}
private
void
startHomeActivity
()
{
Intent
intent
=
new
Intent
(
this
,
HomeActivity
.
class
);
startActivity
(
intent
);
}
public
class
UserLoginTask
extends
AsyncTask
<
Void
,
Void
,
Boolean
>
{
private
String
mAccount
;
private
String
mPassword
;
UserLoginTask
(
String
account
,
String
password
)
{
mAccount
=
account
;
mPassword
=
password
;
}
@Override
protected
Boolean
doInBackground
(
Void
...
params
)
{
try
{
// TODO: 帳號驗證
Thread
.
sleep
(
100
);
}
catch
(
InterruptedException
e
)
{
return
false
;
}
return
true
;
}
@Override
protected
void
onPostExecute
(
final
Boolean
success
)
{
mAuthTask
=
null
;
if
(
success
)
{
startHomeActivity
();
}
else
{
mPasswordView
.
setError
(
getString
(
R
.
string
.
error_incorrect_password
));
mPasswordView
.
requestFocus
();
}
}
@Override
protected
void
onCancelled
()
{
mAuthTask
=
null
;
}
}
}
app/src/main/java/com/example/zxa01/iotclient/login/model/LoginModel.java
0 → 100644
View file @
6913b966
package
com.example.zxa01.iotclient.login.model
;
import
com.example.zxa01.iotclient.login.pojo.LoginMessage
;
import
android.arch.lifecycle.MutableLiveData
;
import
android.databinding.BaseObservable
;
import
android.support.annotation.NonNull
;
public
class
LoginModel
extends
BaseObservable
{
private
MutableLiveData
<
Boolean
>
isAuthorized
=
new
MutableLiveData
<>();
public
LoginModel
()
{
isAuthorized
.
setValue
(
false
);
}
public
MutableLiveData
<
Boolean
>
isAuthorized
(){
return
isAuthorized
;
}
public
void
login
(
@NonNull
LoginMessage
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);
}
public
void
vaild
()
{
//TODO 驗證帳號格式
}
}
app/src/main/java/com/example/zxa01/iotclient/login/pojo/LoginMessage.java
0 → 100644
View file @
6913b966
package
com.example.zxa01.iotclient.login.pojo
;
import
android.support.annotation.NonNull
;
public
class
LoginMessage
{
private
String
gateway
;
private
String
account
;
private
String
password
;
public
LoginMessage
()
{
}
public
LoginMessage
(
@NonNull
String
gateway
,
@NonNull
String
account
,
@NonNull
String
password
)
{
this
.
gateway
=
gateway
;
this
.
account
=
account
;
this
.
password
=
password
;
}
public
String
getGateway
()
{
return
gateway
;
}
public
void
setGateway
(
String
gateway
)
{
this
.
gateway
=
gateway
;
}
public
String
getAccount
()
{
return
account
;
}
public
void
setAccount
(
String
account
)
{
this
.
account
=
account
;
}
public
String
getPassword
()
{
return
password
;
}
public
void
setPassword
(
String
password
)
{
this
.
password
=
password
;
}
}
app/src/main/java/com/example/zxa01/iotclient/login/view/LoginActivity.java
0 → 100644
View file @
6913b966
package
com.example.zxa01.iotclient.login.view
;
import
com.example.zxa01.iotclient.R
;
import
com.example.zxa01.iotclient.databinding.ActivityLoginBinding
;
import
com.example.zxa01.iotclient.login.viewModel.LoginViewModel
;
import
android.app.Activity
;
import
android.databinding.DataBindingUtil
;
import
android.os.Bundle
;
import
android.support.v7.app.AppCompatActivity
;
import
android.view.View
;
import
android.view.inputmethod.InputMethodManager
;
public
class
LoginActivity
extends
AppCompatActivity
{
private
ActivityLoginBinding
binding
;
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
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
binding
=
DataBindingUtil
.
setContentView
(
this
,
R
.
layout
.
activity_login
);
viewModel
=
new
LoginViewModel
(
binding
.
getRoot
().
getContext
());
binding
.
setViewModel
(
viewModel
);
binding
.
linearLoginForm
.
setOnClickListener
(
view
->
hideKeyboard
(
LoginActivity
.
this
));
init
();
}
private
void
init
()
{
viewModel
.
isAuthorized
().
observe
(
this
,
isAuthorized
->
viewModel
.
checkAuthorized
(
isAuthorized
));
}
}
app/src/main/java/com/example/zxa01/iotclient/login/viewModel/LoginViewModel.java
0 → 100644
View file @
6913b966
package
com.example.zxa01.iotclient.login.viewModel
;
import
com.example.zxa01.iotclient.home.HomeActivity
;
import
com.example.zxa01.iotclient.login.model.LoginModel
;
import
com.example.zxa01.iotclient.login.pojo.LoginMessage
;
import
android.arch.lifecycle.MutableLiveData
;
import
android.arch.lifecycle.ViewModel
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.databinding.ObservableField
;
public
class
LoginViewModel
extends
ViewModel
{
public
ObservableField
<
LoginMessage
>
loginMessage
=
new
ObservableField
<>();
private
Context
context
;
private
LoginModel
loginModel
=
new
LoginModel
();
public
LoginViewModel
(
Context
context
)
{
this
.
loginMessage
.
set
(
new
LoginMessage
());
this
.
context
=
context
;
}
public
void
login
()
{
loginModel
.
login
(
loginMessage
.
get
());
}
public
void
checkAuthorized
(
Boolean
isAuthorized
)
{
if
(
isAuthorized
)
{
context
.
startActivity
(
new
Intent
(
context
,
HomeActivity
.
class
));
}
}
public
MutableLiveData
<
Boolean
>
isAuthorized
()
{
return
loginModel
.
isAuthorized
();
}
}
app/src/main/java/com/example/zxa01/iotclient/pojo/Device.java
deleted
100644 → 0
View file @
b010ef94
package
com.example.zxa01.iotclient.pojo
;
import
android.databinding.BaseObservable
;
import
android.databinding.Bindable
;
public
class
Device
extends
BaseObservable
{
private
int
id
;
private
String
name
;
private
String
subTitle
;
private
String
type
;
private
boolean
status
;
public
Device
(
int
id
,
String
name
,
String
subTitle
,
String
type
,
boolean
status
)
{
this
.
id
=
id
;
this
.
name
=
name
;
this
.
subTitle
=
subTitle
;
this
.
type
=
type
;
this
.
status
=
status
;
}
public
Device
()
{
}
@Bindable
public
int
getId
()
{
return
id
;
}
public
void
setId
(
int
id
)
{
this
.
id
=
id
;
}
@Bindable
public
String
getName
()
{
return
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
@Bindable
public
String
getSubTitle
()
{
return
subTitle
;
}
public
void
setSubTitle
(
String
subTitle
)
{
this
.
subTitle
=
subTitle
;
}
@Bindable
public
String
getType
()
{
return
type
;
}
public
void
setType
(
String
type
)
{
this
.
type
=
type
;
}
@Bindable
public
boolean
isStatus
()
{
return
status
;
}
public
void
setStatus
(
boolean
status
)
{
this
.
status
=
status
;
}
}
app/src/main/java/com/example/zxa01/iotclient/privacy/PrivacyActivity.java
0 → 100644
View file @
6913b966
package
com.example.zxa01.iotclient.privacy
;
import
android.support.v7.app.AppCompatActivity
;
import
android.os.Bundle
;
public
class
PrivacyActivity
extends
AppCompatActivity
{
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
// setContentView(R.layout.activity_privacy);
}
}
app/src/main/res/drawable/border_bottom.xml
View file @
6913b966
...
...
@@ -3,17 +3,17 @@
<item>
<shape
android:shape=
"rectangle"
>
<stroke
android:width=
"
2
dp"
android:width=
"
1
dp"
android:color=
"@color/colorLighter"
/>
<solid
android:color=
"@color/colorWhite"
/>
</shape>
</item>
<item
android:bottom=
"
2
dp"
>
android:bottom=
"
1
dp"
>
<shape
android:shape=
"rectangle"
>
<stroke
android:width=
"
2
dp"
android:width=
"
1
dp"
android:color=
"@color/colorWhite"
/>
</shape>
</item>
...
...
app/src/main/res/drawable/border_bottom_xl.xml
0 → 100644
View file @
6913b966
<?xml version="1.0" encoding="utf-8"?>
<layer-list
xmlns:android=
"http://schemas.android.com/apk/res/android"
>
<item>
<shape
android:shape=
"rectangle"
>
<stroke
android:width=
"3dp"
android:color=
"@color/colorLighter"
/>
<solid
android:color=
"@color/colorWhite"
/>
</shape>
</item>
<item
android:bottom=
"3dp"
>
<shape
android:shape=
"rectangle"
>
<stroke
android:width=
"3dp"
android:color=
"@color/colorWhite"
/>
</shape>
</item>
</layer-list>
\ No newline at end of file
app/src/main/res/layout/activity_detail.xml
0 → 100644
View file @
6913b966
This diff is collapsed.
Click to expand it.
app/src/main/res/layout/activity_home.xml
View file @
6913b966
...
...
@@ -3,36 +3,33 @@
xmlns:app=
"http://schemas.android.com/apk/res-auto"
xmlns:tools=
"http://schemas.android.com/tools"
>
<android.support.constraint.ConstraintLayout
android:id=
"@+id/container"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
tools:context=
".home.HomeActivity"
>
<android.support.design.widget.BottomNavigationView
android:id=
"@+id/navigation"
android:layout_width=
"0dp"
android:layout_height=
"wrap_content"
android:layout_marginStart=
"0dp"
android:layout_marginEnd=
"0dp"
android:background=
"?android:attr/windowBackground"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintLeft_toLeftOf=
"parent"
app:layout_constraintRight_toRightOf=
"parent"
app:menu=
"@menu/navigation"
/>
<FrameLayout
android:id=
"@+id/home_fragment_layout"
<android.support.constraint.ConstraintLayout
android:id=
"@+id/container"
android:layout_width=
"match_parent"
android:layout_height=
"0dp"
app:layout_constraintBottom_toTopOf=
"@+id/navigation"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_toTopOf=
"parent"
>
android:layout_height=
"match_parent"
tools:context=
".home.HomeActivity"
>
<android.support.design.widget.BottomNavigationView
android:id=
"@+id/navigation"
android:layout_width=
"0dp"
android:layout_height=
"wrap_content"
android:layout_marginStart=
"0dp"
android:layout_marginEnd=
"0dp"
android:background=
"?android:attr/windowBackground"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintLeft_toLeftOf=
"parent"
app:layout_constraintRight_toRightOf=
"parent"
app:menu=
"@menu/navigation"
/>
</FrameLayout>
<FrameLayout
android:id=
"@+id/home_fragment_layout"
android:layout_width=
"match_parent"
android:layout_height=
"0dp"
app:layout_constraintBottom_toTopOf=
"@+id/navigation"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_toTopOf=
"parent"
/>
</android.support.constraint.ConstraintLayout>
</android.support.constraint.ConstraintLayout>
</layout>
app/src/main/res/layout/activity_login.xml
View file @
6913b966
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:tools=
"http://schemas.android.com/tools"
android:id=
"@+id/linear_login_form"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:gravity=
"center_horizontal"
android:orientation=
"vertical"
android:paddingLeft=
"@dimen/activity_horizontal_margin"
android:paddingTop=
"@dimen/activity_vertical_margin"
android:paddingRight=
"@dimen/activity_horizontal_margin"
android:paddingBottom=
"@dimen/activity_vertical_margin"
tools:context=
".login.LoginActivity"
>
<ScrollView
android:layout_width=
"282dp"
android:layout_height=
"487dp"
>
<LinearLayout
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:orientation=
"vertical"
android:paddingTop=
"@dimen/margin"
>
<TextView
android:layout_width=
"match_parent"
android:layout_height=
"62dp"
android:text=
"@string/login_iot_gateway"
android:textAlignment=
"center"
android:textSize=
"24sp"
/>
<layout
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
xmlns:tools=
"http://schemas.android.com/tools"
>
<data>
<variable
name=
"viewModel"
type=
"com.example.zxa01.iotclient.login.viewModel.LoginViewModel"
/>
</data>
<LinearLayout
android:id=
"@+id/linear_login_form"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:gravity=
"center_horizontal"
android:orientation=
"vertical"
android:paddingLeft=
"@dimen/activity_horizontal_margin"
android:paddingTop=
"@dimen/activity_vertical_margin"
android:paddingRight=
"@dimen/activity_horizontal_margin"
android:paddingBottom=
"@dimen/activity_vertical_margin"
tools:context=
".login.view.LoginActivity"
>
<ScrollView
android:layout_width=
"282dp"
android:layout_height=
"487dp"
>
<
android.support.design.widget.TextInput
Layout
<
Linear
Layout
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
>
android:layout_height=
"wrap_content"
android:orientation=
"vertical"
android:paddingTop=
"@dimen/margin"
>
<EditText
android:id=
"@+id/gateway"
<TextView
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:hint=
"@string/prompt_gateway"
android:inputType=
"text"
android:maxLines=
"1"
android:singleLine=
"true"
/>
android:layout_height=
"62dp"
android:text=
"@string/login_iot_gateway"
android:textAlignment=
"center"
android:textSize=
"24sp"
/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
>
<android.support.design.widget.TextInputLayout
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
>
<EditText
android:id=
"@+id/gateway"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:hint=
"@string/prompt_gateway"
android:inputType=
"text"
android:maxLines=
"1"
android:singleLine=
"true"
android:text=
"@={viewModel.loginMessage.gateway}"
/>
</android.support.design.widget.TextInputLayout>
<EditText
android:id=
"@+id/account"
<android.support.design.widget.TextInputLayout
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:hint=
"@string/prompt_account"
android:inputType=
"text"
android:maxLines=
"1"
android:singleLine=
"true"
/>
android:layout_height=
"wrap_content"
>
</android.support.design.widget.TextInputLayout>
<EditText
android:id=
"@+id/account"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:hint=
"@string/prompt_account"
android:inputType=
"text"
android:maxLines=
"1"
android:singleLine=
"true"
android:text=
"@={viewModel.loginMessage.account}"
/>
<android.support.design.widget.TextInputLayout
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
>
</android.support.design.widget.TextInputLayout>
<EditText
android:id=
"@+id/password"
<android.support.design.widget.TextInputLayout
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
>
<EditText
android:id=
"@+id/password"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:hint=
"@string/prompt_password"
android:imeActionId=
"6"
android:imeOptions=
"actionUnspecified"
android:inputType=
"textPassword"
android:maxLines=
"1"
android:singleLine=
"true"
android:text=
"@={viewModel.loginMessage.password}"
/>
</android.support.design.widget.TextInputLayout>
<Button
android:id=
"@+id/sign_in_button"
style=
"@style/Widget.AppCompat.Button.Colored"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:hint=
"@string/prompt_password"
android:imeActionId=
"6"
android:imeOptions=
"actionUnspecified"
android:inputType=
"textPassword"
android:maxLines=
"1"
android:singleLine=
"true"
/>
</android.support.design.widget.TextInputLayout>
<Button
android:id=
"@+id/sign_in_button"
style=
"@style/Widget.AppCompat.Button.Colored"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_marginTop=
"16dp"
android:text=
"@string/action_sign_in"
android:textStyle=
"bold"
/>
</LinearLayout>
</ScrollView>
</LinearLayout>
android:layout_marginTop=
"16dp"
android:onClick=
"@{()->viewModel.login()}"
android:text=
"@string/action_sign_in"
android:textStyle=
"bold"
/>
</LinearLayout>
</ScrollView>
</LinearLayout>
</layout>
\ No newline at end of file
app/src/main/res/layout/activity_privacy.xml
0 → 100644
View file @
6913b966
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
xmlns:tools=
"http://schemas.android.com/tools"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
tools:context=
".privacy.PrivacyActivity"
>
<TextView
android:id=
"@+id/textView2"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"Privacy"
tools:layout_editor_absoluteX=
"193dp"
tools:layout_editor_absoluteY=
"197dp"
/>
</android.support.constraint.ConstraintLayout>
\ No newline at end of file
app/src/main/res/layout/fragment_device.xml
View file @
6913b966
...
...
@@ -5,10 +5,11 @@
<data>
<import
type=
"android.view.View"
/>
<variable
name=
"viewModel"
type=
"com.example.zxa01.iotclient.home.device.viewModel.DevicesViewModel"
/>
type=
"com.example.zxa01.iotclient.home.device.viewModel.DeviceViewModel"
/>
</data>
<FrameLayout
...
...
@@ -16,6 +17,7 @@
android:layout_height=
"match_parent"
tools:context=
".home.device.view.DeviceFragment"
>
<android.support.v7.widget.RecyclerView
android:id=
"@+id/device_recycler_view"
android:layout_width=
"wrap_content"
...
...
@@ -25,6 +27,16 @@
app:setAdapter=
"@{viewModel.getAdapter()}"
tools:listitem=
"@layout/recycler_view_device"
/>
<ProgressBar
android:id=
"@+id/progressBar"
style=
"@style/Widget.AppCompat.ProgressBar"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_gravity=
"center"
android:secondaryProgress=
"40"
android:theme=
"@style/ProgressTheme"
android:visibility=
"@{viewModel.isLoading ? View.VISIBLE : View.GONE}"
/>
<android.support.design.widget.FloatingActionButton
android:id=
"@+id/fab"
android:layout_width=
"wrap_content"
...
...
@@ -34,6 +46,7 @@
android:src=
"@drawable/ic_add_black_24dp"
app:backgroundTint=
"@color/colorPrimary"
/>
</FrameLayout>
</layout>
app/src/main/res/layout/fragment_
privacy
.xml
→
app/src/main/res/layout/fragment_
record
.xml
View file @
6913b966
...
...
@@ -3,11 +3,11 @@
xmlns:tools=
"http://schemas.android.com/tools"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
tools:context=
".home.
privacy.Privacy
Fragment"
>
tools:context=
".home.
record.Record
Fragment"
>
<TextView
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:text=
"
privacy
"
/>
android:text=
"
records
"
/>
</FrameLayout>
\ No newline at end of file
app/src/main/res/layout/recycler_view_device.xml
View file @
6913b966
...
...
@@ -4,13 +4,14 @@
xmlns:tools=
"http://schemas.android.com/tools"
>
<data>
<variable
name=
"position"
type=
"java.lang.Integer"
/>
<variable
name=
"viewModel"
type=
"com.example.zxa01.iotclient.home.device.viewModel.Device
s
ViewModel"
/>
type=
"com.example.zxa01.iotclient.home.device.viewModel.DeviceViewModel"
/>
</data>
<android.support.constraint.ConstraintLayout
...
...
@@ -20,6 +21,7 @@
android:layout_margin=
"@dimen/margin_sm"
android:background=
"@drawable/shadow"
android:elevation=
"2dp"
android:onClick=
"@{()->viewModel.onDevicesClick(position)}"
android:padding=
"@dimen/margin"
>
<ImageView
...
...
@@ -38,12 +40,12 @@
android:layout_height=
"wrap_content"
android:layout_marginStart=
"16dp"
android:layout_marginBottom=
"8dp"
android:text=
"@{viewModel.getDeviceAt(position).name}"
android:textColor=
"@color/colorGray"
android:textSize=
"20sp"
app:layout_constraintBottom_toTopOf=
"@+id/text_device_subtitle"
app:layout_constraintStart_toEndOf=
"@+id/image_device"
app:layout_constraintTop_toTopOf=
"@+id/image_device"
android:text=
"@{viewModel.getDeviceAt(position).device.name}"
tools:text=
"device name"
/>
<TextView
...
...
@@ -51,14 +53,10 @@
android:layout_width=
"285dp"
android:layout_height=
"20dp"
android:layout_marginStart=
"16dp"
android:
layout_marginEnd=
"8dp
"
android:
text=
"@{viewModel.getDeviceAt(position).UDN}
"
app:layout_constraintBottom_toBottomOf=
"@+id/image_device"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintHorizontal_bias=
"0.050"
app:layout_constraintStart_toEndOf=
"@+id/image_device"
android:text=
"@{viewModel.getDeviceAt(position).device.subTitle}"
tools:text=
"subtitle"
/>
tools:text=
"subtitle"
/>
<TextView
android:id=
"@+id/text_device_status"
...
...
@@ -69,6 +67,7 @@
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintTop_toTopOf=
"@+id/image_device"
tools:text=
"connection"
/>
</android.support.constraint.ConstraintLayout>
</layout>
\ No newline at end of file
app/src/main/res/menu/navigation.xml
View file @
6913b966
...
...
@@ -4,16 +4,16 @@
<item
android:id=
"@+id/navigation_home"
android:icon=
"@drawable/ic_home_black_24dp"
android:title=
"@string/
title
_device"
/>
android:title=
"@string/
nav
_device"
/>
<item
android:id=
"@+id/navigation_privacy"
android:icon=
"@drawable/ic_lock_outline_black_24dp"
android:title=
"@string/
title
_privacy"
/>
android:title=
"@string/
nav
_privacy"
/>
<item
android:id=
"@+id/navigation_setting"
android:icon=
"@drawable/ic_settings_black_24dp"
android:title=
"@string/
title
_setting"
/>
android:title=
"@string/
nav
_setting"
/>
</menu>
app/src/main/res/values/colors.xml
View file @
6913b966
...
...
@@ -2,10 +2,11 @@
<resources>
<color
name=
"colorPrimary"
>
#1da1f2
</color>
<color
name=
"colorPrimaryDark"
>
#0D92E1
</color>
<color
name=
"colorAccent"
>
#
7e7266
</color>
<color
name=
"colorAccent"
>
#
2A4474
</color>
<color
name=
"colorGray"
>
#2d2d2d
</color>
<color
name=
"colorLight"
>
#808080
</color>
<color
name=
"colorLighter"
>
#dadada
</color>
<color
name=
"colorWhite"
>
#FFFFFF
</color>
<color
name=
"colorTransparent"
>
#00000000
</color>
</resources>
app/src/main/res/values/strings.xml
View file @
6913b966
<resources>
<!--Title-->
<string
name=
"title_detail"
>
裝置資訊
</string>
<string
name=
"title_privacy"
>
隱私政策
</string>
<string
name=
"title_setting"
>
設定
</string>
<string
name=
"title_device_create"
>
新增裝置
</string>
<!--Home-->
<string
name=
"app_name"
>
IOTClient
</string>
<string
name=
"
title
_device"
>
Device
</string>
<string
name=
"
title
_privacy"
>
Privacy
</string>
<string
name=
"
title
_setting"
>
Setting
</string>
<string
name=
"
nav
_device"
>
Device
</string>
<string
name=
"
nav
_privacy"
>
Privacy
</string>
<string
name=
"
nav
_setting"
>
Setting
</string>
<!--Create-->
<string
name=
"title_device_create"
>
Create New Device
</string>
<string
name=
"input_placeholder"
>
the address of device
</string>
<string
name=
"input_placeholder"
>
請輸入裝置的UDN
</string>
<string
name=
"button_qrcode"
>
QRcode
</string>
<string
name=
"button_correct"
>
Correct
</string>
<string
name=
"button_cancel"
>
Cancel
</string>
<string
name=
"button_correct"
>
新增
</string>
<string
name=
"button_cancel"
>
返回
</string>
<string
name=
"qrcode_error"
>
格式錯誤
</string>
<!--Login-->
<string
name=
"action_sign_in"
>
Log in
</string>
<string
name=
"action_sign_in"
>
登入
</string>
<string
name=
"login_iot_gateway"
>
Login to IOT gateway
</string>
<string
name=
"prompt_gateway"
>
Gateway address
</string>
<string
name=
"prompt_account"
>
Account
</string>
...
...
app/src/main/res/values/styles.xml
View file @
6913b966
...
...
@@ -8,4 +8,9 @@
<item
name=
"colorAccent"
>
@color/colorAccent
</item>
</style>
<!-- ProgressTheme. -->
<style
name=
"ProgressTheme"
parent=
"Widget.AppCompat.ProgressBar"
>
<item
name=
"colorAccent"
>
@color/colorPrimary
</item>
</style>
</resources>
build.gradle
View file @
6913b966
...
...
@@ -7,7 +7,7 @@ buildscript {
jcenter
()
}
dependencies
{
classpath
'com.android.tools.build:gradle:3.
3.2
'
classpath
'com.android.tools.build:gradle:3.
4.0
'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
...
...
gradle/wrapper/gradle-wrapper.properties
View file @
6913b966
#
Fri Apr 12 13:02:55
CST 2019
#
Sat Apr 20 17:56:49
CST 2019
distributionBase
=
GRADLE_USER_HOME
distributionPath
=
wrapper/dists
zipStoreBase
=
GRADLE_USER_HOME
zipStorePath
=
wrapper/dists
distributionUrl
=
https
\:
//services.gradle.org/distributions/gradle-
4.10
.1-all.zip
distributionUrl
=
https
\:
//services.gradle.org/distributions/gradle-
5.1
.1-all.zip
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