第五周(2) 后台代码解耦与客户端具体功能设计

引言

本周恰巧是开发周期的中期,我们按部就班有条不紊的按照原计划进行开发,这一阶段我们主要的任务有以下几个方面:

  • DAO层的代码重写与解耦
  • 评论功能+@我的消息
下面我就我所编写的客户端@我的消息功能做吓介绍:


@我的消息

@我的消息界面显示的是邀请我作为flag监督人的好友请求。 

xml代码如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/activity_bg_gray"
    android:orientation="vertical">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@color/white"
        android:padding="0dp">

        <ImageButton
            android:layout_width="?attr/actionBarSize"
            android:layout_height="?attr/actionBarSize"
            android:layout_alignParentLeft="true"
            android:background="@drawable/toolbar_back_bg"
            android:onClick="myMessageSuperviseBack"
            android:src="?attr/homeAsUpIndicator" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:text="\@我的消息"
            android:textColor="@color/black"
            android:textSize="19sp" />
    </RelativeLayout>

    <android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/supervise_swipe_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="20dp">

        <ListView
            android:id="@+id/myMessageSuperViseListView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginTop="20dp"
            android:background="@color/white" />
    </android.support.v4.widget.SwipeRefreshLayout>
</LinearLayout>
代码中包含一个SwipeRefreshLayout,用于刷新ListView,ListView中显示具体的消息,主视图与具体的item如下:


@我的消息界面Activity为SuperViseDetailActivity,主要代码:

class MyMessageCallBack implements NetUtil.CallBackForResult {

        ArrayList<TempFriendBean> list;

        public MyMessageCallBack() {
            list = new ArrayList<>();
        }

        @Override
        public void onFailure(final IOException e) {
            MyMessageFriendActivity.this.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    Toast.makeText(MyMessageFriendActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
                }
            });
        }

        @Override
        public void onSuccess(Response response) {
            if (response.isSuccessful()) {
                try {
                    String res = response.body().string();
                    JSONObject request = new JSONObject(res);
                    JSONArray jsonArray = request.getJSONArray("request");
                    for (int i = 0; i < jsonArray.length(); i++) {
                        JSONObject jsonObject = jsonArray.getJSONObject(i);
                        String nickname = jsonObject.optString("nickname");
                        String phone = jsonObject.optString("phone");
                        String message = jsonObject.optString("message");
                        String requestUid = jsonObject.optString("requestUid");
                        String agree = jsonObject.optString("agree");
                        int iconId = jsonObject.optInt("photo");

                        list.add(new TempFriendBean(nickname, phone, message, requestUid, agree, iconId));
                    }
                    MyMessageFriendActivity.this.runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            friendMessageAdapter = new FriendMessageAdapter(MyMessageFriendActivity.this, list);
                            listView.setAdapter(friendMessageAdapter);
                        }
                    });
                } catch (IOException e) {
                    e.printStackTrace();
                } catch (JSONException e) {
                    e.printStackTrace();
                }

            }
        }

        public ArrayList<TempFriendBean> getList() {
            return list;
        }
    }

功能: 
在请求成功后,会取得服务器返回的每条数据信息,然后将每一条数据包装在bean中,传到listview的adapter中,从而可以创建每一个item视图,然后显示出来。

代码编写完后,我们进行了代码互测,针对不同的输入信息,设计了多组测试数据,然后在真机上对每一组数据进行实际测试,检查后台返回数据是否,直到这两个功能的测试都运行无误。

总结

虽然本周的工作量比较大,但是都得益于我们默契的配合和完美的计划,总是达到我们预期的目标。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值