Blame view
app/src/main/java/com/dinhcv/lifelogpedometer/activity/WelcomeActivity.java
3.07 KB
|
7f095a929
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
package com.dinhcv.lifelogpedometer.activity;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AlertDialog;
import com.dinhcv.lifelogpedometer.R;
import com.dinhcv.lifelogpedometer.interfaces.LLAPIManagerListener;
import com.dinhcv.lifelogpedometer.model.Shareprefer.Setting;
import com.dinhcv.lifelogpedometer.portal.LLAPIManager;
import com.dinhcv.lifelogpedometer.utils.Debug;
import org.json.JSONArray;
import org.json.JSONObject;
public class WelcomeActivity extends ActivityBase implements Runnable {
private boolean isRefresh = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_welcome);
checkRefreshToken();
}
private void checkRefreshToken(){
int id = Setting.getUserIdSharepre(WelcomeActivity.this);
Debug.normal("String id: "+ id);
if (id != 0){
handleRefreshToken(id);
}else {
refeshDone();
}
}
private void handleRefreshToken(int id) {
LLAPIManager.refreshToken(WelcomeActivity.this, id, new LLAPIManagerListener() {
@Override
public void onError(Error error) {
Debug.error("Version JSON result: ERROR " + error);
String err = getResources().getString(R.string.login_error);
isRefresh = false;
refeshDone();
}
@Override
public void onSuccess(String json) {
Debug.warn("Version JSON result: " + json.toString());
isRefresh = true;
refeshDone();
}
@Override
public void onSuccess(JSONObject object) {
Debug.warn("Version JSON object result: Success");
isRefresh = true;
refeshDone();
}
});
}
private void refeshDone(){
Handler handler = new Handler();
handler.postDelayed(WelcomeActivity.this, 2000);
}
private void notifyErr(String err){
AlertDialog.Builder alertDialog = new AlertDialog.Builder(WelcomeActivity.this);
alertDialog.setMessage(err);
alertDialog.setCancelable(false);
alertDialog.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
finish();
}
});
AlertDialog alert = alertDialog.create();
alert.show();
}
@Override
public void run() {
// go to main screen
if ( isRefresh) {
gotoActivity(PedometerActivity.class);
} else {
// Bundle bundle = new Bundle();
// bundle.putString(Const.URL, url);
gotoActivity(LoginActivity.class);
}
finish();
}
@Override
protected void onResume() {
super.onResume();
}
}
|