use of com.lingtuan.firefly.listener.RequestListener in project SmartMesh_Android by SmartMeshFoundation.
the class LoginUtil method login.
/**
* login authentication
* @ param uName user name
* @ param uPwd password
* @ param showDialog whether to display the dialog
*/
public void login(final String uName, final String uPwd, final boolean showDialog) {
this.aeskey = Utils.makeRandomKey(16);
NetRequestImpl.getInstance().login(uName, uPwd, aeskey, new RequestListener() {
@Override
public void start() {
if (showDialog) {
LoadingDialog.show(mContext, "");
}
}
@Override
public void success(JSONObject response) {
try {
JSONObject object = response.optJSONObject("data");
// Local encrypted token decrypted storage
String token = object.optString("token");
String mid = object.optString("mid");
if (TextUtils.isEmpty(token)) {
return;
}
token = Aes.decode(aeskey, token);
object.put("token", token);
object.put("mid", mid);
object.put("password", uPwd);
MySharedPrefs.write(mContext, MySharedPrefs.FILE_USER, MySharedPrefs.KEY_LOGIN_USERINFO, object.toString());
UserInfoVo userInfoVo = new UserInfoVo().parse(object);
JsonUtil.updateLocalInfo(mContext, userInfoVo);
NextApplication.myInfo = new UserInfoVo().readMyUserInfo(mContext);
XmppUtils.loginXmppForNextApp(mContext);
getUserInfo(showDialog, mid, uPwd, token);
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void error(int errorCode, String errorMsg) {
if (showDialog) {
LoadingDialog.close();
MyToast.showToast(mContext, errorMsg);
}
}
});
}
use of com.lingtuan.firefly.listener.RequestListener in project SmartMesh_Android by SmartMeshFoundation.
the class RegistUI method smscForgetMethod.
/**
* Mobile phone number to retrieve password
*/
private void smscForgetMethod() {
String mPwd = password.getText().toString();
String mAgainPwd = againPwd.getText().toString();
// Authentication codes are consistent
if (!TextUtils.equals(mPwd, mAgainPwd)) {
MyToast.showToast(RegistUI.this, getString(R.string.account_pwd_again_warning));
return;
}
NetRequestImpl.getInstance().smscForget(number, mPwd, new RequestListener() {
@Override
public void start() {
LoadingDialog.show(RegistUI.this, "");
}
@Override
public void success(JSONObject response) {
LoadingDialog.close();
showToast(response.optString("msg"));
Intent intent = new Intent(RegistUI.this, LoginUI.class);
startActivity(intent);
finish();
}
@Override
public void error(int errorCode, String errorMsg) {
showToast(errorMsg);
LoadingDialog.close();
}
});
}
use of com.lingtuan.firefly.listener.RequestListener in project SmartMesh_Android by SmartMeshFoundation.
the class RegistUI method emailForgetMethod.
/**
* Email retrieve password
*/
private void emailForgetMethod() {
String mPwd = password.getText().toString();
String mAgainPwd = againPwd.getText().toString();
// Authentication codes are consistent
if (!TextUtils.equals(mPwd, mAgainPwd)) {
MyToast.showToast(RegistUI.this, getString(R.string.account_pwd_again_warning));
return;
}
NetRequestImpl.getInstance().emailForget(number, mPwd, new RequestListener() {
@Override
public void start() {
LoadingDialog.show(RegistUI.this, "");
}
@Override
public void success(JSONObject response) {
LoadingDialog.close();
showToast(response.optString("msg"));
Intent intent = new Intent(RegistUI.this, LoginUI.class);
startActivity(intent);
finish();
}
@Override
public void error(int errorCode, String errorMsg) {
showToast(errorMsg);
LoadingDialog.close();
}
});
}
use of com.lingtuan.firefly.listener.RequestListener in project SmartMesh_Android by SmartMeshFoundation.
the class AccountFragment method loadData.
/**
* get token list
*/
private void loadData(final boolean isShowToast) {
boolean isFirstGet = MySharedPrefs.readBoolean(getActivity(), MySharedPrefs.FILE_USER, MySharedPrefs.KEY_FIRST_GET_TOKEN_LIST);
tokenVos = FinalUserDataBase.getInstance().getOpenTokenList(walletAddress.getText().toString());
if (!isFirstGet && tokenVos != null && tokenVos.size() > 0) {
mTokenAdapter.resetSource(tokenVos);
getBalance(isShowToast);
} else {
NetRequestImpl.getInstance().getTokenList(walletAddress.getText().toString(), new RequestListener() {
@Override
public void start() {
}
@Override
public void success(JSONObject response) {
tokenVos.clear();
JSONArray array = response.optJSONArray("data");
if (array != null) {
for (int i = 0; i < array.length(); i++) {
TokenVo tokenVo = new TokenVo().parse(array.optJSONObject(i));
tokenVos.add(tokenVo);
}
}
FinalUserDataBase.getInstance().beginTransaction();
for (int i = 0; i < tokenVos.size(); i++) {
FinalUserDataBase.getInstance().updateTokenList(tokenVos.get(i), walletAddress.getText().toString(), true);
}
FinalUserDataBase.getInstance().endTransactionSuccessful();
MySharedPrefs.writeBoolean(getActivity(), MySharedPrefs.FILE_USER, MySharedPrefs.KEY_FIRST_GET_TOKEN_LIST, false);
mTokenAdapter.resetSource(tokenVos);
getBalance(isShowToast);
}
@Override
public void error(int errorCode, String errorMsg) {
getBalance(isShowToast);
}
});
}
}
use of com.lingtuan.firefly.listener.RequestListener in project SmartMesh_Android by SmartMeshFoundation.
the class AccountFragment method getBalance.
/**
* get token balance
*/
private void getBalance(final boolean isShowToast) {
StringBuilder builder = new StringBuilder();
for (int i = 0; i < tokenVos.size(); i++) {
builder.append(tokenVos.get(i).getContactAddress()).append(",");
}
if (builder.length() > 0) {
builder.deleteCharAt(builder.length() - 1);
}
NetRequestImpl.getInstance().getBalance(walletAddress.getText().toString(), builder.toString(), new RequestListener() {
@Override
public void start() {
}
@Override
public void success(JSONObject response) {
tokenVos.clear();
swipe_refresh.setRefreshing(false);
String total = response.optString("total");
walletBalanceNum.setText(total);
JSONArray array = response.optJSONArray("data");
if (array != null) {
for (int i = 0; i < array.length(); i++) {
TokenVo tokenVo = new TokenVo().parse(array.optJSONObject(i));
tokenVo.setChecked(true);
tokenVos.add(tokenVo);
}
}
FinalUserDataBase.getInstance().beginTransaction();
for (int i = 0; i < tokenVos.size(); i++) {
FinalUserDataBase.getInstance().updateTokenList(tokenVos.get(i), walletAddress.getText().toString(), false);
}
FinalUserDataBase.getInstance().endTransactionSuccessful();
mTokenAdapter.resetSource(tokenVos);
}
@Override
public void error(int errorCode, String errorMsg) {
if (isShowToast) {
showToast(errorMsg);
}
mTokenAdapter.resetSource(tokenVos);
swipe_refresh.setRefreshing(false);
}
});
}
Aggregations