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-09 22:25:00 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
d6106c7def4449648380401275f72e98eff6f9c3
d6106c7d
1 parent
02752198
access token 대응
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
53 additions
and
12 deletions
app/src/main/java/com/sunnni/smartdoorlock/api/Api.java
app/src/main/java/com/sunnni/smartdoorlock/api/Auth.java
app/src/main/java/com/sunnni/smartdoorlock/ui/SplashActivity.java
app/src/main/java/com/sunnni/smartdoorlock/api/Api.java
View file @
d6106c7
...
...
@@ -96,6 +96,10 @@ public class Api {
}.
start
();
}
static
public
void
setAccessToken
(
String
accessToken
)
{
Api
.
accessToken
=
accessToken
;
}
static
public
void
auth
(
String
doorId
,
final
Callback
callback
)
{
if
(
"123123123"
.
equals
(
doorId
))
{
// 테스트를 위한 super pass
...
...
@@ -113,10 +117,11 @@ public class Api {
if
(
apiResult
.
isSuccess
())
{
JsonObject
resp
=
(
JsonObject
)
apiResult
.
getData
();
if
(
resp
.
get
(
"is_available"
).
getAsBoolean
())
{
callback
.
callbackMethod
(
true
);
callback
.
callbackMethod
(
new
Auth
(
true
,
resp
.
get
(
"access_token"
).
getAsString
()));
return
;
}
}
callback
.
callbackMethod
(
false
);
callback
.
callbackMethod
(
new
Auth
(
false
)
);
}
});
}
...
...
app/src/main/java/com/sunnni/smartdoorlock/api/Auth.java
0 → 100644
View file @
d6106c7
package
com
.
sunnni
.
smartdoorlock
.
api
;
public
class
Auth
{
private
boolean
isAvailable
;
private
String
accessToken
=
null
;
public
Auth
(
boolean
isAvailable
,
String
accessToken
)
{
this
.
isAvailable
=
isAvailable
;
this
.
accessToken
=
accessToken
;
}
public
Auth
(
boolean
isAvailable
)
{
this
.
isAvailable
=
isAvailable
;
}
public
boolean
getIsAvailable
()
{
return
this
.
isAvailable
;
}
public
String
getAccessToken
()
{
return
this
.
accessToken
;
}
}
app/src/main/java/com/sunnni/smartdoorlock/ui/SplashActivity.java
View file @
d6106c7
...
...
@@ -4,6 +4,7 @@ import androidx.appcompat.app.AppCompatActivity;
import
androidx.constraintlayout.widget.ConstraintLayout
;
import
android.content.Intent
;
import
android.content.SharedPreferences
;
import
android.os.Bundle
;
import
android.os.Handler
;
import
android.util.Log
;
...
...
@@ -19,6 +20,7 @@ import com.google.android.material.textfield.TextInputEditText;
import
com.google.android.material.textfield.TextInputLayout
;
import
com.sunnni.smartdoorlock.R
;
import
com.sunnni.smartdoorlock.api.Api
;
import
com.sunnni.smartdoorlock.api.Auth
;
public
class
SplashActivity
extends
AppCompatActivity
{
...
...
@@ -35,16 +37,23 @@ public class SplashActivity extends AppCompatActivity {
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R
.
layout
.
activity_splash
);
logoContainer
=
findViewById
(
R
.
id
.
ll_logo
);
textInputLayout
=
findViewById
(
R
.
id
.
til_super_key
);
btnEnter
=
findViewById
(
R
.
id
.
cl_enter
);
edtSuperKey
=
findViewById
(
R
.
id
.
edt_super_key
);
imgEnter
=
findViewById
((
R
.
id
.
img_enter
));
SharedPreferences
pref
=
getSharedPreferences
(
"gateway"
,
MODE_PRIVATE
);
String
accessToken
=
pref
.
getString
(
"accessToken"
,
""
);
if
(!
""
.
equals
(
accessToken
))
{
Api
.
setAccessToken
(
accessToken
);
startActivity
(
new
Intent
(
SplashActivity
.
this
,
MainActivity
.
class
));
}
else
{
logoContainer
=
findViewById
(
R
.
id
.
ll_logo
);
textInputLayout
=
findViewById
(
R
.
id
.
til_super_key
);
btnEnter
=
findViewById
(
R
.
id
.
cl_enter
);
edtSuperKey
=
findViewById
(
R
.
id
.
edt_super_key
);
imgEnter
=
findViewById
((
R
.
id
.
img_enter
));
logoAnimation
=
AnimationUtils
.
loadAnimation
(
this
,
R
.
anim
.
anim_bottom_up
);
logoAnimation
=
AnimationUtils
.
loadAnimation
(
this
,
R
.
anim
.
anim_bottom_up
);
splashLoading
();
init
();
splashLoading
();
init
();
}
}
private
void
splashLoading
()
{
...
...
@@ -71,8 +80,12 @@ public class SplashActivity extends AppCompatActivity {
Api
.
auth
(
text
,
new
Api
.
Callback
()
{
@Override
public
void
callbackMethod
(
Object
obj
)
{
Boolean
success
=
(
Boolean
)
obj
;
if
(
success
)
{
Auth
auth
=
(
Auth
)
obj
;
if
(
auth
.
getIsAvailable
())
{
SharedPreferences
pref
=
getSharedPreferences
(
"gateway"
,
MODE_PRIVATE
);
SharedPreferences
.
Editor
editor
=
pref
.
edit
();
editor
.
putString
(
"accessToken"
,
auth
.
getAccessToken
());
editor
.
commit
();
startActivity
(
new
Intent
(
SplashActivity
.
this
,
MainActivity
.
class
));
}
else
{
Toast
.
makeText
(
getApplicationContext
(),
"고유번호를 확인해주세요."
,
Toast
.
LENGTH_SHORT
).
show
();
...
...
Please
register
or
login
to post a comment