Toggle navigation
Toggle navigation
This project
Loading...
Sign in
cse437_e
/
smartdoorlock-frontend
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
오윤석
2020-11-17 00:12:53 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
7597080240d6e2ccb6376b9b625adf5629d0355e
75970802
1 parent
ea21a7ad
기기 관련 API 추가
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
122 additions
and
29 deletions
app/src/main/java/com/sunnni/smartdoorlock/api/Api.java
app/src/main/java/com/sunnni/smartdoorlock/data/Device.java
app/src/main/java/com/sunnni/smartdoorlock/ui/DeviceManagerActivity.java
app/src/main/java/com/sunnni/smartdoorlock/ui/DeviceRecyclerViewAdapter.java
app/src/main/java/com/sunnni/smartdoorlock/api/Api.java
View file @
7597080
...
...
@@ -8,6 +8,7 @@ import com.google.gson.JsonElement;
import
com.google.gson.JsonObject
;
import
com.google.gson.JsonParser
;
import
com.sunnni.smartdoorlock.data.Auth
;
import
com.sunnni.smartdoorlock.data.Device
;
import
com.sunnni.smartdoorlock.data.RemoteRecord
;
import
com.sunnni.smartdoorlock.data.Setting
;
import
com.sunnni.smartdoorlock.data.Video
;
...
...
@@ -260,4 +261,57 @@ public class Api {
});
}
static
public
void
getDevices
(
final
Callback
callback
)
{
callApi
(
"GET"
,
"/api/device"
,
null
,
new
Callback
()
{
@Override
public
void
callbackMethod
(
Object
obj
)
{
ApiResult
apiResult
=
(
ApiResult
)
obj
;
if
(
apiResult
.
isSuccess
())
{
JsonObject
resp
=
(
JsonObject
)
apiResult
.
getData
();
if
(
resp
.
has
(
"deviceList"
))
{
ArrayList
<
Device
>
videos
=
new
ArrayList
<
Device
>();
Iterator
it
=
resp
.
getAsJsonArray
(
"deviceList"
).
iterator
();
while
(
it
.
hasNext
())
{
JsonObject
jsonObject
=
(
JsonObject
)
it
.
next
();
videos
.
add
(
new
Device
(
jsonObject
.
get
(
"device_id"
).
getAsInt
(),
jsonObject
.
get
(
"rfid_id"
).
getAsString
(),
jsonObject
.
get
(
"created"
).
getAsString
()));
}
callback
.
callbackMethod
(
videos
);
}
else
{
callback
.
callbackMethod
(
null
);
}
}
else
{
callback
.
callbackMethod
(
null
);
}
}
});
}
static
public
void
removeDevice
(
Device
device
,
final
Callback
callback
)
{
callApi
(
"DELETE"
,
"/api/device/"
+
device
.
getDeviceId
(),
null
,
new
Callback
()
{
@Override
public
void
callbackMethod
(
Object
obj
)
{
ApiResult
apiResult
=
(
ApiResult
)
obj
;
if
(
apiResult
.
isSuccess
())
{
callback
.
callbackMethod
(
new
Boolean
(
true
));
}
else
{
callback
.
callbackMethod
(
null
);
}
}
});
}
static
public
void
requestAddDevice
(
final
Callback
callback
)
{
callApi
(
"POST"
,
"/api/device/request"
,
null
,
new
Callback
()
{
@Override
public
void
callbackMethod
(
Object
obj
)
{
ApiResult
apiResult
=
(
ApiResult
)
obj
;
if
(
apiResult
.
isSuccess
())
{
callback
.
callbackMethod
(
new
Boolean
(
true
));
}
else
{
callback
.
callbackMethod
(
null
);
}
}
});
}
}
...
...
app/src/main/java/com/sunnni/smartdoorlock/data/Device.java
View file @
7597080
package
com
.
sunnni
.
smartdoorlock
.
data
;
public
class
Device
{
public
String
deviceNumber
;
public
String
registerDate
;
private
int
deviceId
;
private
String
RFIDId
;
private
String
created
;
public
Device
(
String
number
,
String
date
){
this
.
deviceNumber
=
number
;
this
.
registerDate
=
date
;
public
Device
(
int
deviceId
,
String
RFIDId
,
String
created
){
this
.
deviceId
=
deviceId
;
this
.
RFIDId
=
RFIDId
;
this
.
created
=
created
;
}
public
String
getCreated
()
{
return
created
;
}
public
int
getDeviceId
()
{
return
deviceId
;
}
public
String
getRFIDId
()
{
return
RFIDId
;
}
}
...
...
app/src/main/java/com/sunnni/smartdoorlock/ui/DeviceManagerActivity.java
View file @
7597080
...
...
@@ -9,17 +9,22 @@ import androidx.recyclerview.widget.LinearLayoutManager;
import
androidx.recyclerview.widget.RecyclerView
;
import
android.content.DialogInterface
;
import
android.content.Intent
;
import
android.os.Bundle
;
import
android.view.View
;
import
android.widget.ScrollView
;
import
android.widget.Toast
;
import
com.sunnni.smartdoorlock.R
;
import
com.sunnni.smartdoorlock.api.Api
;
import
com.sunnni.smartdoorlock.data.Device
;
import
com.sunnni.smartdoorlock.data.RemoteRecord
;
import
java.util.ArrayList
;
import
java.util.Objects
;
import
static
android
.
view
.
InputDevice
.
getDevice
;
public
class
DeviceManagerActivity
extends
AppCompatActivity
{
ArrayList
<
Device
>
mList
=
new
ArrayList
<
Device
>();
...
...
@@ -37,7 +42,7 @@ public class DeviceManagerActivity extends AppCompatActivity {
setToolbar
(
mToolbar
);
setRecyclerView
();
setDeviceList
();
getDevice
();
init
();
}
...
...
@@ -78,27 +83,22 @@ public class DeviceManagerActivity extends AppCompatActivity {
mRecyclerView
.
setAdapter
(
mAdapter
);
}
// 기기 목록 dummy data -> api 생성되면 수정
private
void
setDeviceList
(){
Device
temp
;
mList
.
add
(
temp
=
new
Device
(
"0047617826460"
,
"2020.10.08 17:21:30"
));
mList
.
add
(
temp
=
new
Device
(
"0047617826460"
,
"2020.10.08 17:21:30"
));
mList
.
add
(
temp
=
new
Device
(
"0047617826460"
,
"2020.10.08 17:21:30"
));
mList
.
add
(
temp
=
new
Device
(
"0047617826460"
,
"2020.10.08 17:21:30"
));
mList
.
add
(
temp
=
new
Device
(
"0047617826460"
,
"2020.10.08 17:21:30"
));
mList
.
add
(
temp
=
new
Device
(
"0047617826460"
,
"2020.10.08 17:21:30"
));
mList
.
add
(
temp
=
new
Device
(
"0047617826460"
,
"2020.10.08 17:21:30"
));
mList
.
add
(
temp
=
new
Device
(
"0047617826460"
,
"2020.10.08 17:21:30"
));
mList
.
add
(
temp
=
new
Device
(
"0047617826460"
,
"2020.10.08 17:21:30"
));
mList
.
add
(
temp
=
new
Device
(
"0047617826460"
,
"2020.10.08 17:21:30"
));
mList
.
add
(
temp
=
new
Device
(
"0047617826460"
,
"2020.10.08 17:21:30"
));
mList
.
add
(
temp
=
new
Device
(
"0047617826460"
,
"2020.10.08 17:21:30"
));
mList
.
add
(
temp
=
new
Device
(
"0047617826460"
,
"2020.10.08 17:21:30"
));
mList
.
add
(
temp
=
new
Device
(
"0047617826460"
,
"2020.10.08 17:21:30"
));
mList
.
add
(
temp
=
new
Device
(
"0047617826460"
,
"2020.10.08 17:21:30"
));
public
void
getDevice
()
{
Api
.
getDevices
(
new
Api
.
Callback
()
{
@Override
public
void
callbackMethod
(
Object
obj
)
{
if
(
obj
==
null
)
{
Toast
.
makeText
(
getApplicationContext
(),
"연결 상태가 불안정합니다."
,
Toast
.
LENGTH_SHORT
).
show
();
startActivity
(
new
Intent
(
DeviceManagerActivity
.
this
,
MainActivity
.
class
));
return
;
}
else
{
mList
.
clear
();
mList
.
addAll
(
0
,
(
ArrayList
<
Device
>)
obj
);
mAdapter
.
notifyDataSetChanged
();
}
}
});
}
private
void
remoteControlDialog
()
{
AlertDialog
.
Builder
builder
=
new
AlertDialog
.
Builder
(
this
,
R
.
style
.
AlertDialogTheme
);
...
...
@@ -107,8 +107,19 @@ public class DeviceManagerActivity extends AppCompatActivity {
builder
.
setPositiveButton
(
"추가"
,
new
DialogInterface
.
OnClickListener
()
{
@Override
public
void
onClick
(
DialogInterface
dialog
,
int
which
)
{
Api
.
requestAddDevice
(
new
Api
.
Callback
()
{
@Override
public
void
callbackMethod
(
Object
obj
)
{
if
(
obj
==
null
)
{
Toast
.
makeText
(
getApplicationContext
(),
"연결 상태가 불안정합니다."
,
Toast
.
LENGTH_SHORT
).
show
();
startActivity
(
new
Intent
(
DeviceManagerActivity
.
this
,
MainActivity
.
class
));
return
;
}
else
{
Toast
.
makeText
(
DeviceManagerActivity
.
this
,
"도어락에 기기를 태그해주세요."
,
Toast
.
LENGTH_LONG
).
show
();
}
}
});
}
});
builder
.
setNegativeButton
(
"취소"
,
new
DialogInterface
.
OnClickListener
()
{
@Override
...
...
app/src/main/java/com/sunnni/smartdoorlock/ui/DeviceRecyclerViewAdapter.java
View file @
7597080
package
com
.
sunnni
.
smartdoorlock
.
ui
;
import
android.content.DialogInterface
;
import
android.content.Intent
;
import
android.view.LayoutInflater
;
import
android.view.View
;
import
android.view.ViewGroup
;
...
...
@@ -14,6 +15,7 @@ import androidx.core.content.res.ResourcesCompat;
import
androidx.recyclerview.widget.RecyclerView
;
import
com.sunnni.smartdoorlock.R
;
import
com.sunnni.smartdoorlock.api.Api
;
import
com.sunnni.smartdoorlock.data.Device
;
import
java.util.ArrayList
;
...
...
@@ -33,9 +35,9 @@ public class DeviceRecyclerViewAdapter extends RecyclerView.Adapter<DeviceRecycl
this
.
mTrashcan
=
v
.
findViewById
(
R
.
id
.
img_trashcan
);
}
void
bind
(
Device
device
)
{
mTvDeviceNum
.
setText
(
device
.
deviceNumber
);
mTvRegisterDate
.
setText
(
device
.
registerDate
);
void
bind
(
final
Device
device
)
{
mTvDeviceNum
.
setText
(
device
.
getRFIDId
()
);
mTvRegisterDate
.
setText
(
device
.
getCreated
()
);
mTrashcan
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
...
...
@@ -46,7 +48,19 @@ public class DeviceRecyclerViewAdapter extends RecyclerView.Adapter<DeviceRecycl
builder
.
setPositiveButton
(
"삭제"
,
new
DialogInterface
.
OnClickListener
()
{
@Override
public
void
onClick
(
DialogInterface
dialog
,
int
which
)
{
Toast
.
makeText
(
itemView
.
getContext
(),
"삭제되었습니다."
,
Toast
.
LENGTH_SHORT
).
show
();
Api
.
removeDevice
(
device
,
new
Api
.
Callback
()
{
@Override
public
void
callbackMethod
(
Object
obj
)
{
if
(
obj
==
null
)
{
Toast
.
makeText
(
itemView
.
getContext
(),
"연결 상태가 불안정합니다."
,
Toast
.
LENGTH_SHORT
).
show
();
return
;
}
else
{
Toast
.
makeText
(
itemView
.
getContext
(),
"삭제되었습니다."
,
Toast
.
LENGTH_LONG
).
show
();
// TODO : 목록 refresh
// DeviceManagerActivity.getDevices 를 호출하거나 DeviceManagerActivity.mList에서 device 제거
}
}
});
}
});
builder
.
setNegativeButton
(
"취소"
,
new
DialogInterface
.
OnClickListener
()
{
...
...
Please
register
or
login
to post a comment