import android.content.Intent
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.example.takeout.R
import com.example.takeout.model.beans.Order
import com.mob.wrappers.PaySDKWrapper
import org.jetbrains.anko.find
class OrderRvAdapter (val context: Context) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
private var orderList: List = ArrayList()
fun setOrderData(orders: List) {
this.orderList = orders
notifyDataSetChanged()
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
// val itemView = View.inflate(context, R.layout.item_order_item, null)
//TODO:没有填充满,原因是recycleview的孩子,测量模式是UNSPECIFY
//通过返回值已经addview,如果attachToRoot使用true会再一次addView(),就会报错
val itemView = LayoutInflater.from(context).inflate(R.layout.item_order_item,parent, false)
return OrderItemHolder(itemView)
}
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
(holder as OrderItemHolder).bindData(orderList.get(position))
}
override fun getItemCount(): Int {
return orderList.size
}
inner class OrderItemHolder(item: View) : RecyclerView.ViewHolder(item) {
val tvSellerName: TextView
val tvOrderType: TextView
init {
//findviewbyId tv_order_item_seller_name tv_order_item_type
tvSellerName = item.find(R.id.tv_order_item_seller_name)
tvOrderType = item.find(R.id.tv_order_item_type) //订单状态
// item.setOnClickListener {
// val intent: Intent = Intent(context, OrderDetailActivity::class.java)
// intent.putExtra(“orderId”, order.id)
// intent.putExtra(“type”, order.type)
// context.startActivity(intent)
// }
}
fun bindData(order: Order) {
// tvSellerName.text = order.seller.name
tvOrderType.text = order.type
}
}
}
TakeoutService.kt使用Retrofit请求数据的封装
package com.example.takeout.model.net
import retrofit2.Call
import retrofit2.http.GET
interface TakeoutService {
//ex. @GET(“users/{user}/repos”)
//ex. fun listRepos(@Path(“user”) user: String): Call<List>
//http://127.0.0.1:8090/takeout?index=0
@GET(“takeout?index=0”)
fun getHomeInfo(): Call
//http://127.0.0.1:8090/takelogin?index=0
@GET(“takelogin?index=0”)
fun loginByPhone() : Call
//http://127.0.0.1:8090/takeorder?index=0
@GET(“takeorder?index=0”)
fun getOrderList() : Call
}
item_order_item.xml订单界面单个item数据的界面布局
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android=“http://schemas.android.com/apk/res/android”
xmlns:tools=“http://schemas.android.com/tools”
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:background="#fff"
android:orientation=“horizontal”>
<FrameLayout
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”>
<ImageView
android:id="@+id/iv_order_item_seller_logo"
android:layout_width=“50dp”
android:layout_height=“50dp”
android:layout_margin=“8dp”
android:src="@mipmap/item_kfc" />
<LinearLayout
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:layout_margin=“8dp”
android:orientation=“vertical”>
<LinearLayout
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:gravity=“center_vertical”>
<TextView
android:id="@+id/tv_order_item_seller_name"
android:layout_width=“match_parent”
andro
id:layout_height=“wrap_content”
android:layout_marginLeft=“5dp”
android:layout_weight=“1”
android:singleLine=“true”
android:text=“肯德基宅急送(文化路店)”
android:textColor="#000"
android:textSize=“20sp” />
<TextView
android:id="@+id/tv_order_item_type"
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:layout_marginLeft=“8dp”
android:textSize=“14sp”
android:text=“订单已完成”
android:textColor="#000"/>
<TextView
android:id="@+id/tv_order_item_time"
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:layout_alignParentLeft=“true”
android:text=“2016-09-04 18:00”
android:textSize=“12sp”/>
<View
android:layout_width=“match_parent”
android:layout_height=“2dp”
android:layout_marginTop=“5dp”
android:layout_marginBottom=“5dp”
android:background="@drawable/shape_background_division"/>
<RelativeLayout
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:layout_marginTop=“10dp”
android:layout_marginBottom=“10dp”
android:gravity=“center_vertical”>
<TextView
android:id="@+id/tv_order_item_foods"
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:layout_alignParentLeft=“true”
android:text=“红烧肉等3件商品”
android:textColor="#000"
android:textSize=“14sp”/>
<TextView
android:id="@+id/tv_order_item_money"
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:layout_alignParentRight=“true”
android:text=“¥31.00”
android:textColor="#000"
android:textSize=“12sp”/>
<View
android:layout_width=“match_parent”
android:layout_height=“2dp”
android:layout_marginTop=“5dp”
android:layout_marginBottom=“5dp”
android:background="@drawable/shape_background_division"/>
<RelativeLayout
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:layout_marginTop=“5dp”
android:layout_marginBottom=“5dp”
<TextView
android:id="@+id/tv_order_item_multi_function"
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:layout_alignParentRight=“true”
android:layout_marginRight=“10dp”
android:textSize=“16sp”
android:textColor="#3090E6"
android:background="@drawable/shape_background_stroke_blue"
android:padding=“4dp”
android:text=“再来一单”/>
Order.kt订单界面从服务器请求的数据
package com.example.takeout.model.beans
class Order {
var id: String? = null
var type: String? = null
var seller: Seller? = null
var rider: Rider? = null
var goodsInfos: List? = null
var distribution: Distribution? = null
var detail: OrderDetail? = null
inner class Rider {
var id = 0
var name: String? = null
var phone: String? = null // public Location location;
}
inner class OrderDetail {
var username: String? = null
var phone: String? = null
var address: String? = null
var pay: String? = null
var time: String? = null
}
inner class Distribution {
// 配送方式
var type: String? = null
rider: Rider? = null
var goodsInfos: List? = null
var distribution: Distribution? = null
var detail: OrderDetail? = null
inner class Rider {
var id = 0
var name: String? = null
var phone: String? = null // public Location location;
}
inner class OrderDetail {
var username: String? = null
var phone: String? = null
var address: String? = null
var pay: String? = null
var time: String? = null
}
inner class Distribution {
// 配送方式
var type: String? = null