Search in sources :

Example 26 with RequestListener

use of com.lingtuan.firefly.listener.RequestListener in project SmartMesh_Android by SmartMeshFoundation.

the class TokenListUI method loadTokenList.

/**
 * get token list
 */
private void loadTokenList() {
    boolean isFirstGet = MySharedPrefs.readBoolean(TokenListUI.this, MySharedPrefs.FILE_USER, MySharedPrefs.KEY_FIRST_GET_TOKEN_LIST);
    ArrayList<TokenVo> tokenList = FinalUserDataBase.getInstance().getTokenListAll(address);
    if (!isFirstGet && tokenList != null && tokenList.size() > 0) {
        tokenListAdapter.resetSource(tokenList);
        swipeLayout.setRefreshing(false);
    } else {
        NetRequestImpl.getInstance().getTokenList(address, new RequestListener() {

            @Override
            public void start() {
            }

            @Override
            public void success(JSONObject response) {
                source.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));
                        source.add(tokenVo);
                    }
                }
                FinalUserDataBase.getInstance().beginTransaction();
                for (int i = 0; i < source.size(); i++) {
                    FinalUserDataBase.getInstance().updateTokenList(source.get(i), address, true);
                }
                FinalUserDataBase.getInstance().endTransactionSuccessful();
                MySharedPrefs.writeBoolean(TokenListUI.this, MySharedPrefs.FILE_USER, MySharedPrefs.KEY_FIRST_GET_TOKEN_LIST, false);
                tokenListAdapter.resetSource(source);
                swipeLayout.setRefreshing(false);
                checkListEmpty();
            }

            @Override
            public void error(int errorCode, String errorMsg) {
                swipeLayout.setRefreshing(false);
                showToast(errorMsg);
                checkListEmpty();
            }
        });
    }
}
Also used : RequestListener(com.lingtuan.firefly.listener.RequestListener) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) TokenVo(com.lingtuan.firefly.wallet.vo.TokenVo)

Example 27 with RequestListener

use of com.lingtuan.firefly.listener.RequestListener in project SmartMesh_Android by SmartMeshFoundation.

the class ContactSearchNickUI method searchNick.

private synchronized void searchNick(final String text) {
    friendList.clear();
    NetRequestImpl.getInstance().friendSearch(text, new RequestListener() {

        @Override
        public void start() {
        }

        @Override
        public void success(JSONObject response) {
            String data = response.optString("data");
            boolean flag = TextUtils.equals("[]", data);
            JSONArray jsonArray = response.optJSONArray("data");
            if (jsonArray != null && !flag) {
                int count = jsonArray.length();
                for (int i = 0; i < count; i++) {
                    UserInfoVo uInfo = new UserInfoVo().parse(jsonArray.optJSONObject(i));
                    if (uInfo != null) {
                        friendList.add(uInfo);
                    }
                }
                mAdapter.updateList(friendList);
                checkListEmpty(false);
            } else {
                checkListEmpty(true);
            }
            swipeLayout.setRefreshing(false);
        }

        @Override
        public void error(int errorCode, String errorMsg) {
            swipeLayout.setRefreshing(false);
            showToast(errorMsg);
            checkListEmpty(true);
        }
    });
}
Also used : RequestListener(com.lingtuan.firefly.listener.RequestListener) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) UserInfoVo(com.lingtuan.firefly.vo.UserInfoVo)

Example 28 with RequestListener

use of com.lingtuan.firefly.listener.RequestListener in project SmartMesh_Android by SmartMeshFoundation.

the class DiscussGroupListUI method createDiscussionGroups.

/**
 * Create a group chat
 * @param touids members id
 */
private void createDiscussionGroups(String touids, final List<UserBaseVo> member) {
    NetRequestImpl.getInstance().createDiscussionGroups(touids, new RequestListener() {

        @Override
        public void start() {
            showProgressDialog();
        }

        @Override
        public void success(JSONObject response) {
            showToast(response.optString("msg"));
            dismissProgressDialog();
            Utils.gotoGroupChat(DiscussGroupListUI.this, false, null, response.optString("cid"), member);
            new Handler().postDelayed(new Runnable() {

                @Override
                public void run() {
                    swipeLayout.setRefreshing(true);
                    loadGroupList();
                }
            }, 500);
        }

        @Override
        public void error(int errorCode, String errorMsg) {
            dismissProgressDialog();
            showToast(errorMsg);
        }
    });
}
Also used : RequestListener(com.lingtuan.firefly.listener.RequestListener) JSONObject(org.json.JSONObject) Handler(android.os.Handler)

Example 29 with RequestListener

use of com.lingtuan.firefly.listener.RequestListener in project SmartMesh_Android by SmartMeshFoundation.

the class DiscussGroupMemberListUI method removeMember.

public void removeMember(final int arg2) {
    if (mProgressDialog != null) {
        mProgressDialog.dismiss();
        mProgressDialog = null;
    }
    mProgressDialog = LoadingDialog.showDialog(this, null, null);
    mProgressDialog.setCancelable(false);
    NetRequestImpl.getInstance().removeDiscussMember(data.get(arg2).getLocalId(), cid, new RequestListener() {

        @Override
        public void start() {
        }

        @Override
        public void success(JSONObject response) {
            if (mProgressDialog != null) {
                mProgressDialog.dismiss();
                mProgressDialog = null;
            }
            showToast(response.optString("msg"));
            UserBaseVo user = data.get(arg2);
            data.remove(user);
            showdata.remove(user);
            removeMemberChatMsg(user.getShowName());
            mAdapter.notifyDataSetChanged();
        }

        @Override
        public void error(int errorCode, String errorMsg) {
            if (mProgressDialog != null) {
                mProgressDialog.dismiss();
                mProgressDialog = null;
            }
            showToast(errorMsg);
        }
    });
}
Also used : RequestListener(com.lingtuan.firefly.listener.RequestListener) JSONObject(org.json.JSONObject) UserBaseVo(com.lingtuan.firefly.vo.UserBaseVo)

Example 30 with RequestListener

use of com.lingtuan.firefly.listener.RequestListener in project SmartMesh_Android by SmartMeshFoundation.

the class DiscussGroupMemberListUI method addMembersRequest.

private void addMembersRequest(final ArrayList<UserBaseVo> continueList) {
    if (continueList.size() <= 0) {
        return;
    }
    if (mProgressDialog != null) {
        mProgressDialog.dismiss();
        mProgressDialog = null;
    }
    mProgressDialog = LoadingDialog.showDialog(this, null, null);
    mProgressDialog.setCancelable(false);
    StringBuffer touids = new StringBuffer();
    final StringBuffer tonames = new StringBuffer();
    for (int i = 0; i < continueList.size(); i++) {
        if (i == continueList.size() - 1) {
            touids.append(continueList.get(i).getLocalId());
            tonames.append(continueList.get(i).getShowName());
        } else {
            touids.append(continueList.get(i).getLocalId() + ",");
            tonames.append(continueList.get(i).getShowName() + ",");
        }
    }
    NetRequestImpl.getInstance().addDiscussMembers(touids.toString(), cid, new RequestListener() {

        @Override
        public void start() {
        }

        @Override
        public void success(JSONObject response) {
            if (mProgressDialog != null) {
                mProgressDialog.dismiss();
                mProgressDialog = null;
            }
            showToast(response.optString("msg"));
            for (int m = 0; m < continueList.size(); m++) {
                if (isAdmin) {
                    data.add(continueList.get(m));
                    showdata.add(showdata.size() - 2, continueList.get(m));
                } else {
                    data.add(continueList.get(m));
                    showdata.add(showdata.size() - 1, continueList.get(m));
                }
            }
            inviteOthersChatMsg(tonames.toString());
            mAdapter.notifyDataSetChanged();
        }

        @Override
        public void error(int errorCode, String errorMsg) {
            if (mProgressDialog != null) {
                mProgressDialog.dismiss();
                mProgressDialog = null;
            }
            showToast(errorMsg);
        }
    });
}
Also used : RequestListener(com.lingtuan.firefly.listener.RequestListener) JSONObject(org.json.JSONObject)

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