오윤석

access token 대응

......@@ -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));
}
});
}
......
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;
}
}
......@@ -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();
......