Search in sources :

Example 21 with RequestListener

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);
            }
        }
    });
}
Also used : RequestListener(com.lingtuan.firefly.listener.RequestListener) JSONObject(org.json.JSONObject) JSONException(org.json.JSONException) UserInfoVo(com.lingtuan.firefly.vo.UserInfoVo)

Example 22 with RequestListener

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();
        }
    });
}
Also used : RequestListener(com.lingtuan.firefly.listener.RequestListener) JSONObject(org.json.JSONObject) Intent(android.content.Intent)

Example 23 with RequestListener

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();
        }
    });
}
Also used : RequestListener(com.lingtuan.firefly.listener.RequestListener) JSONObject(org.json.JSONObject) Intent(android.content.Intent)

Example 24 with RequestListener

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);
            }
        });
    }
}
Also used : RequestListener(com.lingtuan.firefly.listener.RequestListener) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) TokenVo(com.lingtuan.firefly.wallet.vo.TokenVo) SuppressLint(android.annotation.SuppressLint)

Example 25 with RequestListener

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);
        }
    });
}
Also used : RequestListener(com.lingtuan.firefly.listener.RequestListener) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) TokenVo(com.lingtuan.firefly.wallet.vo.TokenVo) SuppressLint(android.annotation.SuppressLint)

Aggregations

RequestListener (com.lingtuan.firefly.listener.RequestListener)32 JSONObject (org.json.JSONObject)32 SuppressLint (android.annotation.SuppressLint)7 Intent (android.content.Intent)6 JSONArray (org.json.JSONArray)5 UserBaseVo (com.lingtuan.firefly.vo.UserBaseVo)4 UserInfoVo (com.lingtuan.firefly.vo.UserInfoVo)4 JSONException (org.json.JSONException)4 TokenVo (com.lingtuan.firefly.wallet.vo.TokenVo)3 Handler (android.os.Handler)2 RegistUI (com.lingtuan.firefly.login.RegistUI)2 ActivityNotFoundException (android.content.ActivityNotFoundException)1 Bundle (android.os.Bundle)1 NewContactVO (com.lingtuan.firefly.contact.vo.NewContactVO)1 ContactItemComparator (com.lingtuan.firefly.custom.contact.ContactItemComparator)1 ChatMsg (com.lingtuan.firefly.vo.ChatMsg)1