오윤석

access token 대응

...@@ -96,6 +96,10 @@ public class Api { ...@@ -96,6 +96,10 @@ public class Api {
96 }.start(); 96 }.start();
97 } 97 }
98 98
99 + static public void setAccessToken(String accessToken) {
100 + Api.accessToken = accessToken;
101 + }
102 +
99 static public void auth(String doorId, final Callback callback) { 103 static public void auth(String doorId, final Callback callback) {
100 if("123123123".equals(doorId)) { 104 if("123123123".equals(doorId)) {
101 // 테스트를 위한 super pass 105 // 테스트를 위한 super pass
...@@ -113,10 +117,11 @@ public class Api { ...@@ -113,10 +117,11 @@ public class Api {
113 if(apiResult.isSuccess()) { 117 if(apiResult.isSuccess()) {
114 JsonObject resp = (JsonObject) apiResult.getData(); 118 JsonObject resp = (JsonObject) apiResult.getData();
115 if(resp.get("is_available").getAsBoolean()) { 119 if(resp.get("is_available").getAsBoolean()) {
116 - callback.callbackMethod(true); 120 + callback.callbackMethod(new Auth(true, resp.get("access_token").getAsString()));
121 + return;
117 } 122 }
118 } 123 }
119 - callback.callbackMethod(false); 124 + callback.callbackMethod(new Auth(false));
120 } 125 }
121 }); 126 });
122 } 127 }
......
1 +package com.sunnni.smartdoorlock.api;
2 +
3 +public class Auth {
4 + private boolean isAvailable;
5 + private String accessToken = null;
6 +
7 + public Auth(boolean isAvailable, String accessToken) {
8 + this.isAvailable = isAvailable;
9 + this.accessToken = accessToken;
10 + }
11 +
12 + public Auth(boolean isAvailable) {
13 + this.isAvailable = isAvailable;
14 + }
15 +
16 + public boolean getIsAvailable() {
17 + return this.isAvailable;
18 + }
19 +
20 + public String getAccessToken() {
21 + return this.accessToken;
22 + }
23 +}
...@@ -4,6 +4,7 @@ import androidx.appcompat.app.AppCompatActivity; ...@@ -4,6 +4,7 @@ import androidx.appcompat.app.AppCompatActivity;
4 import androidx.constraintlayout.widget.ConstraintLayout; 4 import androidx.constraintlayout.widget.ConstraintLayout;
5 5
6 import android.content.Intent; 6 import android.content.Intent;
7 +import android.content.SharedPreferences;
7 import android.os.Bundle; 8 import android.os.Bundle;
8 import android.os.Handler; 9 import android.os.Handler;
9 import android.util.Log; 10 import android.util.Log;
...@@ -19,6 +20,7 @@ import com.google.android.material.textfield.TextInputEditText; ...@@ -19,6 +20,7 @@ import com.google.android.material.textfield.TextInputEditText;
19 import com.google.android.material.textfield.TextInputLayout; 20 import com.google.android.material.textfield.TextInputLayout;
20 import com.sunnni.smartdoorlock.R; 21 import com.sunnni.smartdoorlock.R;
21 import com.sunnni.smartdoorlock.api.Api; 22 import com.sunnni.smartdoorlock.api.Api;
23 +import com.sunnni.smartdoorlock.api.Auth;
22 24
23 public class SplashActivity extends AppCompatActivity { 25 public class SplashActivity extends AppCompatActivity {
24 26
...@@ -35,16 +37,23 @@ public class SplashActivity extends AppCompatActivity { ...@@ -35,16 +37,23 @@ public class SplashActivity extends AppCompatActivity {
35 super.onCreate(savedInstanceState); 37 super.onCreate(savedInstanceState);
36 setContentView(R.layout.activity_splash); 38 setContentView(R.layout.activity_splash);
37 39
38 - logoContainer = findViewById(R.id.ll_logo); 40 + SharedPreferences pref = getSharedPreferences("gateway", MODE_PRIVATE);
39 - textInputLayout = findViewById(R.id.til_super_key); 41 + String accessToken = pref.getString("accessToken", "");
40 - btnEnter = findViewById(R.id.cl_enter); 42 + if(!"".equals(accessToken)) {
41 - edtSuperKey = findViewById(R.id.edt_super_key); 43 + Api.setAccessToken(accessToken);
42 - imgEnter = findViewById((R.id.img_enter)); 44 + startActivity(new Intent(SplashActivity.this, MainActivity.class));
45 + } else {
46 + logoContainer = findViewById(R.id.ll_logo);
47 + textInputLayout = findViewById(R.id.til_super_key);
48 + btnEnter = findViewById(R.id.cl_enter);
49 + edtSuperKey = findViewById(R.id.edt_super_key);
50 + imgEnter = findViewById((R.id.img_enter));
43 51
44 - logoAnimation = AnimationUtils.loadAnimation(this, R.anim.anim_bottom_up); 52 + logoAnimation = AnimationUtils.loadAnimation(this, R.anim.anim_bottom_up);
45 53
46 - splashLoading(); 54 + splashLoading();
47 - init(); 55 + init();
56 + }
48 } 57 }
49 58
50 private void splashLoading() { 59 private void splashLoading() {
...@@ -71,8 +80,12 @@ public class SplashActivity extends AppCompatActivity { ...@@ -71,8 +80,12 @@ public class SplashActivity extends AppCompatActivity {
71 Api.auth(text, new Api.Callback() { 80 Api.auth(text, new Api.Callback() {
72 @Override 81 @Override
73 public void callbackMethod(Object obj) { 82 public void callbackMethod(Object obj) {
74 - Boolean success = (Boolean) obj; 83 + Auth auth = (Auth) obj;
75 - if(success) { 84 + if(auth.getIsAvailable()) {
85 + SharedPreferences pref = getSharedPreferences("gateway", MODE_PRIVATE);
86 + SharedPreferences.Editor editor = pref.edit();
87 + editor.putString("accessToken", auth.getAccessToken());
88 + editor.commit();
76 startActivity(new Intent(SplashActivity.this, MainActivity.class)); 89 startActivity(new Intent(SplashActivity.this, MainActivity.class));
77 } else { 90 } else {
78 Toast.makeText(getApplicationContext(),"고유번호를 확인해주세요.",Toast.LENGTH_SHORT).show(); 91 Toast.makeText(getApplicationContext(),"고유번호를 확인해주세요.",Toast.LENGTH_SHORT).show();
......