阅读目录

0.优化
1.个人中心页面的布局
2. 订单列表逻辑梳理与实现
3. 个人信息的更新实现

3.1 个人信息页面的布局
3.3 数据的转化
 5.3 图片库中图片选择事件的处理
 5.4 相机拍照之后的剪裁
6.图片上传和更新逻辑实现
 7.收货地址管理功能实现

7.1【收货地址数据的转化】
7.2【数据适配器的完成】
7.3 收货地址delegate创建
 7.4 点击事件的进入
 7.5 删除键功能实现
 8.基于极光推送的消息推送

0.优化

回到顶部

1.个人中心页面的布局

  1 <?xml version="1.0" encoding="utf-8"?>2 <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"3     android:layout_width="match_parent"4     android:layout_height="match_parent"5     android:background="@color/app_background">6 7     <LinearLayout8         android:layout_width="match_parent"9         android:layout_height="wrap_content"10         android:orientation="vertical">11 12         <!--头像部分-->13         <RelativeLayout14             android:layout_width="match_parent"15             android:layout_height="160dp"16             android:background="@android:color/holo_orange_dark">17 18             <de.hdodenhof.circleimageview.CircleImageView19                 android:id="@+id/img_user_avatar"20                 android:layout_width="80dp"21                 android:layout_height="80dp"22                 android:layout_centerHorizontal="true"23                 android:layout_marginTop="30dp"24                 android:src="@mipmap/avatar" />25 26             <TextView27                 android:layout_width="wrap_content"28                 android:layout_height="wrap_content"29                 android:layout_alignParentBottom="true"30                 android:layout_centerHorizontal="true"31                 android:layout_marginBottom="20dp"32                 android:text="傅猿猿"33                 android:textColor="@android:color/white"34                 android:textSize="16sp" />35 36         </RelativeLayout>37 38         <!--订单部分-->39         <RelativeLayout40             android:layout_width="match_parent"41             android:layout_height="50dp"42             android:background="@android:color/white"43             android:orientation="horizontal"44             android:paddingLeft="10dp"45             android:paddingRight="10dp">46 47             <TextView48                 android:layout_width="wrap_content"49                 android:layout_height="match_parent"50                 android:layout_alignParentLeft="true"51                 android:gravity="center"52                 android:text="我的订单"53                 android:textColor="@android:color/black" />54 55             <TextView56                 android:id="@+id/tv_all_order"57                 android:layout_width="wrap_content"58                 android:layout_height="match_parent"59                 android:layout_toLeftOf="@+id/tv_all_account_arrow"60                 android:gravity="center"61                 android:text="全部订单"62                 android:textColor="@android:color/darker_gray" />63 64             <com.joanzapata.iconify.widget.IconTextView65                 android:id="@+id/tv_all_account_arrow"66                 android:layout_width="wrap_content"67                 android:layout_height="match_parent"68                 android:layout_alignParentEnd="true"69                 android:layout_alignParentRight="true"70                 android:layout_alignParentTop="true"71                 android:layout_marginLeft="10dp"72                 android:gravity="center"73                 android:text="{fa-chevron-right}"74                 android:textColor="@android:color/darker_gray" />75 76         </RelativeLayout>77 78         <LinearLayout79             android:layout_width="match_parent"80             android:layout_height="80dp"81             android:background="@android:color/white"82             android:baselineAligned="true"83             android:orientation="horizontal">84 85             <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"86                 android:id="@+id/ll_pay"87                 android:layout_width="0dp"88                 android:layout_height="match_parent"89                 android:layout_weight="1"90                 android:gravity="center"91                 android:orientation="vertical">92 93                 <com.joanzapata.iconify.widget.IconTextView94                     android:layout_width="30dp"95                     android:layout_height="30dp"96                     android:layout_gravity="center_horizontal"97                     android:gravity="center"98                     android:text="{fa-credit-card}"99                     android:textSize="20sp" />
100
101                 <TextView
102                     android:layout_width="wrap_content"
103                     android:layout_height="wrap_content"
104                     android:layout_gravity="center_horizontal"
105                     android:layout_marginTop="5dp"
106                     android:gravity="center"
107                     android:text="待付款"
108                     android:textSize="10sp" />
109
110             </LinearLayout>
111
112             <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
113                 android:id="@+id/ll_receive"
114                 android:layout_width="0dp"
115                 android:layout_height="match_parent"
116                 android:layout_weight="1"
117                 android:gravity="center"
118                 android:orientation="vertical">
119
120                 <com.joanzapata.iconify.widget.IconTextView
121                     android:layout_width="30dp"
122                     android:layout_height="30dp"
123                     android:layout_gravity="center_horizontal"
124                     android:gravity="center"
125                     android:text="{fa-truck}"
126                     android:textSize="20sp" />
127
128                 <TextView
129                     android:id="@+id/textView"
130                     android:layout_width="wrap_content"
131                     android:layout_height="wrap_content"
132                     android:layout_gravity="center_horizontal"
133                     android:layout_marginTop="5dp"
134                     android:gravity="center"
135                     android:text="待收货"
136                     android:textSize="10sp" />
137
138             </LinearLayout>
139
140             <LinearLayout
141                 android:id="@+id/ll_evaluate"
142                 android:layout_width="0dp"
143                 android:layout_height="match_parent"
144                 android:layout_weight="1"
145                 android:gravity="center"
146                 android:orientation="vertical">
147
148                 <com.joanzapata.iconify.widget.IconTextView
149                     android:layout_width="30dp"
150                     android:layout_height="30dp"
151                     android:layout_gravity="center_horizontal"
152                     android:gravity="center"
153                     android:text="{fa-clone}"
154                     android:textSize="20sp" />
155
156                 <TextView
157                     android:layout_width="wrap_content"
158                     android:layout_height="wrap_content"
159                     android:layout_gravity="center_horizontal"
160                     android:layout_marginTop="5dp"
161                     android:gravity="center"
162                     android:text="待评价"
163                     android:textSize="10sp" />
164
165             </LinearLayout>
166
167             <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
168                 android:id="@+id/ll_after_market"
169                 android:layout_width="0dp"
170                 android:layout_height="match_parent"
171                 android:layout_weight="1"
172                 android:gravity="center"
173                 android:orientation="vertical">
174
175                 <com.joanzapata.iconify.widget.IconTextView
176                     android:layout_width="30dp"
177                     android:layout_height="30dp"
178                     android:layout_gravity="center_horizontal"
179                     android:gravity="center"
180                     android:text="{fa-comments-o}"
181                     android:textSize="20sp" />
182
183                 <TextView
184                     android:layout_width="wrap_content"
185                     android:layout_height="wrap_content"
186                     android:layout_gravity="center_horizontal"
187                     android:layout_marginTop="5dp"
188                     android:gravity="center"
189                     android:text="售后"
190                     android:textSize="10sp" />
191
192             </LinearLayout>
193
194         </LinearLayout>
195
196         <android.support.v7.widget.RecyclerView
197             android:id="@+id/rv_personal_setting"
198             android:layout_width="match_parent"
199             android:layout_height="match_parent"
200             android:layout_marginTop="20dp" />
201     </LinearLayout>
202
203 </ScrollView>

【bean的书写】使用建造者模式

  1 package com.flj.latte.ec.main.personal.list;2 3 import android.widget.CompoundButton;4 5 import com.chad.library.adapter.base.entity.MultiItemEntity;6 import com.flj.latte.delegates.LatteDelegate;7 8 9 public class ListBean implements MultiItemEntity {10 11     private int mItemType = 0;12     private String mImageUrl = null; //头像的地址;13     private String mText = null;  //名称 14     private String mValue = null;15     private int mId = 0;16     private LatteDelegate mDelegate = null;17 //    其中存在checkbox的选择,需要设置一个listener;18     private CompoundButton.OnCheckedChangeListener mOnCheckedChangeListener = null;19 20     public ListBean(int mItemType, String mImageUrl, String mText, String mValue, int mId, LatteDelegate mDelegate, CompoundButton.OnCheckedChangeListener mOnCheckedChangeListener) {21         this.mItemType = mItemType;22         this.mImageUrl = mImageUrl;23         this.mText = mText;24         this.mValue = mValue;25         this.mId = mId;26         this.mDelegate = mDelegate;27         this.mOnCheckedChangeListener = mOnCheckedChangeListener;28     }29 30     public String getImageUrl() {31         32         return mImageUrl;33     }34 35     public String getText() {36         if (mText == null) {37             return "";38         }39         return mText;40     }41 42     public String getValue() {43         if (mValue == null) {44             return "";45         }46         return mValue;47     }48 49     public int getId() {50         51         return mId;52     }53 54     public LatteDelegate getDelegate() {55         return mDelegate;56     }57 58     public CompoundButton.OnCheckedChangeListener getmOnCheckedChangeListener() {59         return mOnCheckedChangeListener;60     }61 62     @Override63     public int getItemType() {64         return mItemType;65     }66 67     public static final class Builder {68 69         private int id = 0;70         private int itemType = 0;71         private String imageUrl = null;72         private String text = null;73         private String value = null;74         private CompoundButton.OnCheckedChangeListener onCheckedChangeListener = null;75         private LatteDelegate delegate = null;76 77         public Builder setId(int id) {78             this.id = id;79             return this;80         }81 82         public Builder setItemType(int itemType) {83             this.itemType = itemType;84             return this;85         }86 87         public Builder setImageUrl(String imageUrl) {88             this.imageUrl = imageUrl;89             return this;90         }91 92         public Builder setText(String text) {93             this.text = text;94             return this;95         }96 97         public Builder setValue(String value) {98             this.value = value;99             return this;
100         }
101
102         public Builder setOnCheckedChangeListener(CompoundButton.OnCheckedChangeListener onCheckedChangeListener) {
103             this.onCheckedChangeListener = onCheckedChangeListener;
104             return this;
105         }
106
107         public Builder setDelegate(LatteDelegate delegate) {
108             this.delegate = delegate;
109             return this;
110         }
111
112         public ListBean build() {
113             return new ListBean(itemType, imageUrl, text, value, id, delegate, onCheckedChangeListener);
114         }
115     }
116 }

【适配器的添加】

【item的几种布局-1】带有箭头的item布局

 1 <?xml version="1.0" encoding="utf-8"?>2 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"3     android:layout_width="match_parent"4     android:layout_height="50dp"5     android:layout_marginBottom="5dp"6     android:background="@android:color/white">7 8     <android.support.v7.widget.AppCompatTextView9         android:id="@+id/tv_arrow_text"
10         android:layout_width="wrap_content"
11         android:layout_height="match_parent"
12         android:layout_marginLeft="20dp"
13         android:gravity="center" />
14
15     <android.support.v7.widget.AppCompatTextView
16         android:id="@+id/tv_arrow_value"
17         android:layout_width="wrap_content"
18         android:layout_height="match_parent"
19         android:layout_marginRight="10dp"
20         android:layout_toLeftOf="@+id/icon_arrow"
21         android:gravity="center"
22         android:text="未设置" />
23
24     <com.joanzapata.iconify.widget.IconTextView
25         android:id="@+id/icon_arrow"
26         android:layout_width="wrap_content"
27         android:layout_height="match_parent"
28         android:layout_alignParentRight="true"
29         android:layout_marginRight="20dp"
30         android:gravity="center"
31         android:text="{fa-chevron-right}" />
32
33 </RelativeLayout>

【设置个人中心的数据】当前写一些假的数据;

【新建type类】

回到顶部

2. 订单列表逻辑梳理与实现

【数据】根据不同的tag,不同的数据类型, 展示不同的数据;

【数据的转换】

【适配器的设置】

【orderList的layout】

 1 <?xml version="1.0" encoding="utf-8"?>2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"3     xmlns:tools="http://schemas.android.com/tools"4     android:layout_width="match_parent"5     android:layout_height="80dp"6     android:layout_marginBottom="2dp"7     android:background="@android:color/white"8     android:orientation="horizontal">9
10     <FrameLayout
11         android:layout_width="0dp"
12         android:layout_height="match_parent"
13         android:layout_weight="1">
14
15         <android.support.v7.widget.AppCompatImageView
16             android:id="@+id/image_order_list"
17             android:layout_width="70dp"
18             android:layout_height="70dp"
19             android:layout_gravity="center"
20             tools:ignore="RtlHardcoded" />
21     </FrameLayout>
22
23     <LinearLayout
24         android:layout_width="0dp"
25         android:layout_height="match_parent"
26         android:layout_weight="2"
27         android:orientation="vertical">
28
29         <android.support.v7.widget.AppCompatTextView
30             android:id="@+id/tv_order_list_title"
31             android:layout_width="match_parent"
32             android:layout_height="0dp"
33             android:layout_gravity="top"
34             android:layout_weight="1"
35             android:text="Title"
36             tools:ignore="NestedWeights" />
37
38         <LinearLayout
39             android:layout_width="match_parent"
40             android:layout_height="0dp"
41             android:layout_weight="1"
42             android:orientation="horizontal">
43
44             <android.support.v7.widget.AppCompatTextView
45                 android:id="@+id/tv_order_list_price"
46                 android:layout_width="0dp"
47                 android:layout_height="match_parent"
48                 android:layout_weight="1"
49                 android:gravity="left|center"
50                 android:text="price"
51                 tools:ignore="RtlHardcoded" />
52
53             <android.support.v7.widget.AppCompatTextView
54                 android:id="@+id/tv_order_list_time"
55                 android:layout_width="0dp"
56                 android:layout_height="match_parent"
57                 android:layout_weight="1"
58                 android:gravity="left|center"
59                 android:text="time"
60                 tools:ignore="RtlHardcoded" />
61         </LinearLayout>
62     </LinearLayout>
63
64     <com.joanzapata.iconify.widget.IconTextView
65         android:layout_width="0dp"
66         android:layout_height="match_parent"
67         android:layout_weight="1"
68         android:gravity="center"
69         android:text="{fa-chevron-right}"
70         android:textSize="18sp"
71         tools:ignore="HardcodedText" />
72
73 </LinearLayout>

 1 package com.flj.latte.ec.main.personal.order;2 3 import android.annotation.SuppressLint;4 import android.support.v7.widget.AppCompatImageView;5 import android.support.v7.widget.AppCompatTextView;6 7 import com.bumptech.glide.Glide;8 import com.bumptech.glide.load.engine.DiskCacheStrategy;9 import com.bumptech.glide.request.RequestOptions;
10 import com.diabin.latte.ec.R;
11 import com.flj.latte.ui.recycler.MultipleFields;
12 import com.flj.latte.ui.recycler.MultipleItemEntity;
13 import com.flj.latte.ui.recycler.MultipleRecyclerAdapter;
14 import com.flj.latte.ui.recycler.MultipleViewHolder;
15
16 import java.util.List;
17
18 public class OrderListAdapter extends MultipleRecyclerAdapter {
19
20     private static final RequestOptions OPTIONS = new RequestOptions()
21             .diskCacheStrategy(DiskCacheStrategy.ALL)
22             .centerCrop()
23             .dontAnimate();
24
25     protected OrderListAdapter(List<MultipleItemEntity> data) {
26         super(data);
27         addItemType(OrderListItemType.ITEM_ORDER_LIST, R.layout.item_order_list);
28     }
29
30     @SuppressLint("SetTextI18n")
31     @Override
32     protected void convert(MultipleViewHolder holder, MultipleItemEntity entity) {
33         super.convert(holder, entity);
34         switch (holder.getItemViewType()) {
35             case OrderListItemType.ITEM_ORDER_LIST:
36                 final AppCompatImageView imageView = holder.getView(R.id.image_order_list);
37                 final AppCompatTextView title = holder.getView(R.id.tv_order_list_title);
38                 final AppCompatTextView price = holder.getView(R.id.tv_order_list_price);
39                 final AppCompatTextView time = holder.getView(R.id.tv_order_list_time);
40
41                 final String titleVal = entity.getField(MultipleFields.TITLE);
42                 final String timeVal = entity.getField(OrderItemFields.TIME);
43                 final double priceVal = entity.getField(OrderItemFields.PRICE);
44                 final String imageUrl = entity.getField(MultipleFields.IMAGE_URL);
45
46                 Glide.with(mContext)
47                         .load(imageUrl)
48                         .apply(OPTIONS)
49                         .into(imageView);
50
51                 title.setText(titleVal);
52                 price.setText("价格:" + String.valueOf(priceVal));
53                 time.setText("时间:" + timeVal);
54                 break;
55             default:
56                 break;
57         }
58     }
59 }

【订单页面的布局】

【对recycleView数据的填充】

【图片加载的设置】

【bug】time的修复

回到顶部

3. 个人信息的更新实现

回到顶部

3.1 个人信息页面的布局

 1 <?xml version="1.0" encoding="utf-8"?>2 <android.support.v7.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android"3     android:layout_width="match_parent"4     android:layout_height="match_parent"5     android:background="#f5f5f5"6     android:orientation="vertical">7 8     <android.support.v7.widget.Toolbar9         android:background="@android:color/holo_orange_dark"
10         android:layout_width="match_parent"
11         android:layout_height="wrap_content" />
12
13     <android.support.v7.widget.RecyclerView
14         android:id="@+id/rv_user_profile"
15         android:layout_width="match_parent"
16         android:layout_height="match_parent" />
17
18 </android.support.v7.widget.LinearLayoutCompat>

【对于头像的设置和处理】处理姓名、性别还有头像的修改等等;

【头像事件的绑定】

回到顶部

3.3 数据的转化

【UI的绑定】

【源码】com.flj.latte.ec.main.personal.profile.UserProfileDelegate

 1 package com.flj.latte.ec.main.personal.profile;2 3 import android.os.Bundle;4 import android.support.annotation.NonNull;5 import android.support.annotation.Nullable;6 import android.support.v7.widget.LinearLayoutManager;7 import android.support.v7.widget.RecyclerView;8 import android.view.View;9
10 import com.diabin.latte.ec.R;
11 import com.diabin.latte.ec.R2;
12 import com.flj.latte.delegates.LatteDelegate;
13 import com.flj.latte.ec.main.personal.list.ListAdapter;
14 import com.flj.latte.ec.main.personal.list.ListBean;
15 import com.flj.latte.ec.main.personal.list.ListItemType;
16 import com.flj.latte.ec.main.personal.settings.NameDelegate;
17
18 import java.util.ArrayList;
19 import java.util.List;
20
21 import butterknife.BindView;
22
23
24 public class UserProfileDelegate extends LatteDelegate {
25
26     @BindView(R2.id.rv_user_profile)
27     RecyclerView mRecyclerView = null;
28
29     @Override
30     public Object setLayout() {
31         return R.layout.delegate_user_profile;
32     }
33     //尽量都使用动态的方式,不要在xml中写死;
34     @Override
35     public void onBindView(@Nullable Bundle savedInstanceState, @NonNull View rootView) {
36         final ListBean image = new ListBean.Builder()
37                 .setItemType(ListItemType.ITEM_AVATAR)
38                 .setId(1)
39                 .setImageUrl("http://i9.qhimg.com/t017d891ca365ef60b5.jpg")
40                 .build();
41
42         final ListBean name = new ListBean.Builder()
43                 .setItemType(ListItemType.ITEM_NORMAL)
44                 .setId(2)
45                 .setText("姓名")
46                 .setDelegate(new NameDelegate())
47                 .setValue("未设置姓名")
48                 .build();
49
50         final ListBean gender = new ListBean.Builder()
51                 .setItemType(ListItemType.ITEM_NORMAL)
52                 .setId(3)
53                 .setText("性别")
54                 .setValue("未设置性别")
55                 .build();
56
57         final ListBean birth = new ListBean.Builder()
58                 .setItemType(ListItemType.ITEM_NORMAL)
59                 .setId(4)
60                 .setText("生日")
61                 .setValue("未设置生日")
62                 .build();
63
64         final List<ListBean> data = new ArrayList<>();
65         data.add(image);
66         data.add(name);
67         data.add(gender);
68         data.add(birth);
69     }
70 }

回到顶部

5.3 图片库中图片选择事件的处理

【请求码的书写】

【调用类的书写】

【动态权限的处理】

【增加权限】

【调用】

回到顶部

5.4 相机拍照之后的剪裁

【配置清单】官方提供的;

【增加回调图片进行剪裁之后并保存】

回到顶部

6.图片上传和更新逻辑实现

【最后得到的图像的处理】上传到服务器并且可以设置本地的头像;

【设置本地的头像】

【效果】本地的头像已经发生了改变;

【上传至服务器】

【剪裁之后进行了服务器的数据上传】

【说明】对于姓名和性别也是一样的道理;此处没有实现

回到顶部

7.收货地址管理功能实现

【说明】收货地址使用的是recyclerView;

回到顶部

7.1【收货地址数据的转化】

回到顶部

7.2【数据适配器的完成】

【item布局】

 1 <?xml version="1.0" encoding="utf-8"?>2 <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"  //此处使用的cardView3     xmlns:card_view="http://schemas.android.com/apk/res-auto"4     android:layout_width="match_parent"5     android:layout_height="140dp"6     android:layout_gravity="center"7     card_view:cardBackgroundColor="@android:color/white"8     card_view:cardCornerRadius="6dp"9     card_view:cardElevation="3dp"
10     card_view:cardUseCompatPadding="true">
11
12     <android.support.v7.widget.LinearLayoutCompat
13         android:layout_width="match_parent"
14         android:layout_height="match_parent"
15         android:orientation="vertical">
16
17         <RelativeLayout
18             android:layout_width="match_parent"
19             android:layout_height="0dp"
20             android:layout_weight="1"
21             android:orientation="horizontal">
22
23             <android.support.v7.widget.AppCompatTextView
24                 android:id="@+id/tv_address_name"
25                 android:layout_width="wrap_content"
26                 android:layout_height="wrap_content"
27                 android:layout_alignParentLeft="true"
28                 android:layout_centerVertical="true"
29                 android:layout_marginLeft="20dp"
30                 android:text="姓名"
31                 android:textColor="@color/app_main" />
32
33             <android.support.v7.widget.AppCompatTextView
34                 android:id="@+id/tv_address_phone"
35                 android:layout_width="wrap_content"
36                 android:layout_height="wrap_content"
37                 android:layout_centerInParent="true"
38                 android:text="电话"
39                 android:textColor="@color/we_chat_black" />
40
41             <android.support.v7.widget.AppCompatTextView
42                 android:id="@+id/tv_address_delete"
43                 android:layout_width="wrap_content"
44                 android:layout_height="wrap_content"
45                 android:layout_alignParentRight="true"
46                 android:layout_centerVertical="true"
47                 android:layout_marginRight="20dp"
48                 android:text="删除"
49                 android:textColor="@android:color/darker_gray" />
50
51         </RelativeLayout>
52
53         <View
54             android:layout_width="match_parent"
55             android:layout_height="1dp"
56             android:layout_marginLeft="10dp"
57             android:layout_marginRight="10dp"
58             android:background="@color/app_background" />
59
60         <RelativeLayout
61             android:layout_width="match_parent"
62             android:layout_height="0dp"
63             android:layout_weight="2">
64
65             <android.support.v7.widget.AppCompatTextView
66                 android:id="@+id/tv_address_address"
67                 android:layout_width="wrap_content"
68                 android:layout_height="wrap_content"
69                 android:layout_alignParentLeft="true"
70                 android:layout_centerVertical="true"
71                 android:layout_marginLeft="20dp"
72                 android:gravity="center_vertical|left"
73                 android:textColor="@color/we_chat_black"
74                 android:textSize="18sp" />
75
76         </RelativeLayout>
77     </android.support.v7.widget.LinearLayoutCompat>
78 </android.support.v7.widget.CardView>

【完善】

 1 package com.flj.latte.ec.main.personal.address;2 3 import android.support.v7.widget.AppCompatTextView;4 import android.view.View;5 6 import com.diabin.latte.ec.R;7 import com.flj.latte.net.RestClient;8 import com.flj.latte.net.callback.ISuccess;9 import com.flj.latte.ui.recycler.MultipleFields;
10 import com.flj.latte.ui.recycler.MultipleItemEntity;
11 import com.flj.latte.ui.recycler.MultipleRecyclerAdapter;
12 import com.flj.latte.ui.recycler.MultipleViewHolder;
13
14 import java.util.List;
15
16
17 public class AddressAdapter extends MultipleRecyclerAdapter {
18
19     protected AddressAdapter(List<MultipleItemEntity> data) {
20         super(data);
21         addItemType(AddressItemType.ITEM_ADDRESS, R.layout.item_address);
22     }
23
24     @Override
25     protected void convert(final MultipleViewHolder holder, MultipleItemEntity entity) {
26         super.convert(holder, entity);
27         switch (holder.getItemViewType()) {
28             case AddressItemType.ITEM_ADDRESS:
29                 final String name = entity.getField(MultipleFields.NAME);
30                 final String phone = entity.getField(AddressItemFields.PHONE);
31                 final String address = entity.getField(AddressItemFields.ADDRESS);
32                 final boolean isDefault = entity.getField(MultipleFields.TAG);
33                 final int id = entity.getField(MultipleFields.ID);
34
35                 final AppCompatTextView nameText = holder.getView(R.id.tv_address_name);
36                 final AppCompatTextView phoneText = holder.getView(R.id.tv_address_phone);
37                 final AppCompatTextView addressText = holder.getView(R.id.tv_address_address);
38                 final AppCompatTextView deleteTextView = holder.getView(R.id.tv_address_delete);
39                 deleteTextView.setOnClickListener(new View.OnClickListener() {
40                     @Override
41                     public void onClick(View v) {
42                         RestClient.builder()
43                                 .url("address.php")
44                                 .params("id", id)
45                                 .success(new ISuccess() {
46                                     @Override
47                                     public void onSuccess(String response) {
48                                         remove(holder.getLayoutPosition());
49                                     }
50                                 })
51                                 .build()
52                                 .post();
53                     }
54                 });
55
56                 nameText.setText(name);
57                 phoneText.setText(phone);
58                 addressText.setText(address);
59                 break;
60             default:
61                 break;
62         }
63     }
64 }

回到顶部

7.3 收货地址delegate创建

【布局】

 1 <?xml version="1.0" encoding="utf-8"?>2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"3     android:layout_width="match_parent"4     android:layout_height="match_parent"5     android:orientation="vertical">6 7     <android.support.v7.widget.Toolbar8         android:layout_width="match_parent"9         android:layout_height="?attr/actionBarSize"
10         android:background="@android:color/holo_orange_dark">
11
12         <RelativeLayout
13             android:layout_width="match_parent"
14             android:layout_height="match_parent">
15
16             <android.support.v7.widget.AppCompatTextView
17                 android:layout_width="match_parent"
18                 android:layout_height="match_parent"
19                 android:layout_centerInParent="true"
20                 android:gravity="center"
21                 android:text="地址管理"
22                 android:textColor="@android:color/white"
23                 android:textSize="20sp" />
24
25             <com.joanzapata.iconify.widget.IconTextView
26                 android:id="@+id/icon_address_add"
27                 android:layout_width="wrap_content"
28                 android:layout_height="match_parent"
29                 android:layout_alignParentRight="true"
30                 android:layout_marginRight="20dp"
31                 android:gravity="center"
32                 android:text="{fa-plus-square-o}"
33                 android:textColor="@android:color/white"
34                 android:textSize="30sp" />
35
36         </RelativeLayout>
37
38     </android.support.v7.widget.Toolbar>
39
40     <android.support.v7.widget.RecyclerView
41         android:id="@+id/rv_address"
42         android:layout_width="match_parent"
43         android:layout_height="match_parent" />
44
45 </LinearLayout>

 1 package com.flj.latte.ec.main.personal.address;2 import android.os.Bundle;3 import android.support.annotation.NonNull;4 import android.support.annotation.Nullable;5 import android.support.v7.widget.LinearLayoutManager;6 import android.support.v7.widget.RecyclerView;7 import android.view.View;8 import com.diabin.latte.ec.R;9 import com.diabin.latte.ec.R2;
10 import com.flj.latte.delegates.LatteDelegate;
11 import com.flj.latte.net.RestClient;
12 import com.flj.latte.net.callback.ISuccess;
13 import com.flj.latte.ui.recycler.MultipleItemEntity;
14 import com.flj.latte.util.log.LatteLogger;
15 import java.util.List;
16 import butterknife.BindView;
17
18
19 public class AddressDelegate extends LatteDelegate implements ISuccess {
20
21     @BindView(R2.id.rv_address)
22     RecyclerView mRecyclerView = null;
23
24     @Override
25     public Object setLayout() {
26         return R.layout.delegate_address;
27     }
28
29     @Override
30     public void onBindView(@Nullable Bundle savedInstanceState, @NonNull View rootView) {
31         RestClient.builder()
32                 .url("address.php")
33                 .loader(getContext())
34                 .success(this)
35                 .build()
36                 .get();
37     }
38
39     @Override
40     public void onSuccess(String response) {
41         LatteLogger.d("AddressDelegate", response);
42         final LinearLayoutManager manager = new LinearLayoutManager(getContext());
43         mRecyclerView.setLayoutManager(manager);
44         final List<MultipleItemEntity> data =
45                 new AddressDataConverter().setJsonData(response).convert();
46         final AddressAdapter addressAdapter = new AddressAdapter(data);
47         mRecyclerView.setAdapter(addressAdapter);
48     }
49 }

回到顶部

7.4 点击事件的进入

 1 package com.flj.latte.ec.main.personal;2 3 import android.view.View;4 import com.chad.library.adapter.base.BaseQuickAdapter;5 import com.chad.library.adapter.base.listener.SimpleClickListener;6 import com.flj.latte.delegates.LatteDelegate;7 import com.flj.latte.ec.main.personal.list.ListBean;8 9 public class PersonalClickListener extends SimpleClickListener {
10
11     private final LatteDelegate DELEGATE;
12
13     public PersonalClickListener(LatteDelegate delegate) {
14         this.DELEGATE = delegate;
15     }
16
17     @Override
18     public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
19         final ListBean bean = (ListBean) baseQuickAdapter.getData().get(position);
20         int id = bean.getId();
21         switch (id) {
22             case 1:
23                 DELEGATE.getParentDelegate().getSupportDelegate().start(bean.getDelegate());
24                 break;
25             case 2:
26                 DELEGATE.getParentDelegate().getSupportDelegate().start(bean.getDelegate());
27                 break;
28             default:
29                 break;
30         }
31     }
32
33     @Override
34     public void onItemLongClick(BaseQuickAdapter adapter, View view, int position) {
35
36     }
37
38     @Override
39     public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
40
41     }
42
43     @Override
44     public void onItemChildLongClick(BaseQuickAdapter adapter, View view, int position) {
45
46     }
47 }

回到顶部

7.5 删除键功能实现

回到顶部

8.基于极光推送的消息推送

云炬Android开发笔记 14 个人中心、图片裁剪、图片上传、收货地址、消息推送、权限管理等功能开发与一键式封装相关推荐

  1. Android平台上使用MQTT协议实现消息推送功能

    MQTT实现消息推送,效果如下 服务端下载地址:http://activemq.apache.org/download-archives.html jar包地址 百度网盘:https://pan.ba ...

  2. Android开发使用ServerSocket ServerSocketChannel DatagramSocket进行TCP UDP通信 实现服务器与APP消息推送

    前言 在日常开发中采用Http协议进行数据传输的情况非常多,但这都是APP主动请求服务端,将数据传到服务器或者从服务器下载数据:那么如果我们想服务器主动联系我们或者我们频繁的上报消息给服务器,怎么弄呢 ...

  3. 华为消息推送 有透传通道吗_华为推送之服务端简单开发

    个人觉得华为推送官方文档写得太....哈哈!完全符合复制拿来用就好,今天我也去复制一番. 1.获取华为appSecretKey和appId 2.然后就是复制官网的代码(是不是纯copy),最后就最后了 ...

  4. Java后台微信点餐小程序开发最新版笔记,Springboot+Mysql+Freemarker+Bootstrap+微信小程序实现扫码点餐小程序,包含语音提示,微信消息推送,网页管理后台

    由于之前的Java后台微信点餐小程序有些知识点过时了,所以今天重新出一版,把里面过时的知识点更新下 前五章是部署笔记,后面是知识点的详细讲解,大家可以先看部署笔记,部署起来后,再跟着详细知识学习. 第 ...

  5. mmall 学习笔记--分类管理模块,商品管理模块,购物车模块,收货地址模块,支付模块,订单管理模块,云服务器线上部署,自动发布,

    ()数据库配置 常见语句 Create table 'my_table'( int id not null auto_increment ) () 建表的时候出现text,bigInt,decimal ...

  6. 2015最新最全 Android 谷歌消息推送GCM 详细使用教程

    因为项目是非大陆的手机项目,所以当要使用到消息推送的时候,百度了一下,国内的消息方案可以是: 1.百度云推送.也确实很快就可以搭建客户端和服务端,加载他的sdk,大概花了半个小时,就可以在手机端收到推 ...

  7. iOS开发之消息推送 —— 远程消息推送入门

    每次看到iOS的远程消息推送,总是感觉很头大,即便后来项目都做完了,还是觉得摸不着远程推送的脉门,网上介绍的资料虽多,但不是写的太简单了,就是写的太详细了,不能一下抓住要点,今天终于能够抽出点时间,来 ...

  8. Android消息推送:手把手教你集成小米推送

    <script type="text/javascript" src="http://static.blog.csdn.net/scripts/category.j ...

  9. 快应用消息推送push服务端开发

    文章目录 快应用消息推送push开发 一.设备信息保存 1.设备id的生成 1-1生成规则 1-2生成弊端 1-3更为简单的方式保证唯一性 2.不合法regId的过滤 3.上报更多设备信息 4.程序实 ...

最新文章

  1. 【文本分类】深入理解embedding层的模型、结构与文本表示
  2. 框架和库有什么区别? [关闭]
  3. CSS之 :before :after的用法,伪类和伪元素的区别
  4. Python3字符串切片操作代码示例
  5. PHP学习总结(正则表达式、日期与时间)
  6. Windows编程之多媒体
  7. Django 新建account应用
  8. 16位伪指令汇编程序查看内存
  9. kell Vision5有那些使用技巧呢
  10. 第五次打卡 模型融合
  11. CCD实际尺寸对照表
  12. 工业相机的50个知识点
  13. 设计一个长方形的类,成员的变量有长与宽,成员函数要求周长与面积,然后进行测试。
  14. 【打卡-Coggle竞赛学习2023年3月】对话意图识别
  15. 基于51单片机的多层电梯(1-16层)运行系统仿真设计_层数可改
  16. LaTeX会议论文添加版权信息
  17. -bash: ls: No such file or directory 产生的原因及修改方法
  18. 开机出现checking file system on C或者D E F盘符的解决方法
  19. 理解WebViewClient各方法重写的作用
  20. H3C acl配置举例

热门文章

  1. mysql-5.7.21 二进制安装 | Jemalloc内存优化 | 备份恢复|修改密码
  2. Backbone React Requirejs 应用实战(一)——RequireJS管理React依赖
  3. clcikhouse Code: 1000. DB::Exception: File not found
  4. nyoj 931 货物运输(Floyd输出路径)
  5. JSP简单练习-页面重定向
  6. hdu 1879 继续畅通工程 最小生成树
  7. docker18.09.3修改守护进程配置文件不生效问题
  8. URI Scheme注册伪协议实现远程命令执行
  9. 1.5 Python基础知识 - while循环
  10. HDU 5828 Rikka with Sequence (线段树+剪枝优化)