retrofit+rxjava京東訂單
阿新 • • 發佈:2019-02-17
1.先建立訂單頁面,並且設定fragment切換頁面以及popuwindown
public class DingDanActivity extends AppCompatActivity implements View.OnClickListener { @BindView(R.id.detail_image_back) ImageView detailImageBack; @BindView(R.id.san_dian_pop) ImageView sanDianPop; @BindView(R.id.radio_group) RadioGroup radioGroup; TextView popDaiPay; TextView popAlreadyPay; TextView popCancel; private PopupWindow popupWindow; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_ding_dan); ButterKnife.bind(this); detailImageBack.setOnClickListener(this); sanDianPop.setOnClickListener(this); findView(); //popupwindown彈出框 initPopUpWindown(); int flag = getIntent().getIntExtra("flag", -1); //預設顯示的是全部頁面 if (flag == -1) { getSupportFragmentManager().beginTransaction().replace(R.id.frame_content, new FragmentAllOrder()).commit(); } else { //如果從fragemnt跳轉過來 需要展示自己的頁面 if (flag == 1) {//待支付 radioGroup.check(R.id.radio_02); getSupportFragmentManager().beginTransaction().replace(R.id.frame_content, new FragmentDaiPayOrder()).commit(); } else if (flag == 2) {//已支付 radioGroup.check(R.id.radio_03); getSupportFragmentManager().beginTransaction().replace(R.id.frame_content, new FragmentAlreadyPayOrder()).commit(); } else if (flag == 3) {//已取消 radioGroup.check(R.id.radio_04); getSupportFragmentManager().beginTransaction().replace(R.id.frame_content, new FragmentCacelOrder()).commit(); } } radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup radioGroup, int id) { switch (id) { case R.id.radio_01://全部 getSupportFragmentManager().beginTransaction().replace(R.id.frame_content, new FragmentAllOrder()).commit(); break; case R.id.radio_02://待支付 getSupportFragmentManager().beginTransaction().replace(R.id.frame_content, new FragmentDaiPayOrder()).commit(); break; case R.id.radio_03://已支付 getSupportFragmentManager().beginTransaction().replace(R.id.frame_content, new FragmentAlreadyPayOrder()).commit(); break; case R.id.radio_04://已取消 getSupportFragmentManager().beginTransaction().replace(R.id.frame_content, new FragmentCacelOrder()).commit(); break; } } }); } private void findView() { popDaiPay = findViewById(R.id.pop_dai_pay); popAlreadyPay = findViewById(R.id.pop_already_pay); popCancel = findViewById(R.id.pop_cancel); } private void initPopUpWindown() { View view = View.inflate(DingDanActivity.this, R.layout.order_pop_layout, null); popupWindow = new PopupWindow(view, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); popupWindow.setFocusable(true); popupWindow.setTouchable(true); popupWindow.setOutsideTouchable(true); popupWindow.setBackgroundDrawable(new BitmapDrawable()); //找到控制元件 popDaiPay = view.findViewById(R.id.pop_dai_pay); popAlreadyPay = view.findViewById(R.id.pop_already_pay); popCancel = view.findViewById(R.id.pop_cancel); popDaiPay.setOnClickListener(this); popAlreadyPay.setOnClickListener(this); popCancel.setOnClickListener(this); } @Override public void onClick(View view) { switch (view.getId()) { case R.id.detail_image_back: finish(); break; case R.id.san_dian_pop://彈出pop //判斷一下當前radioGroup選中了哪一個RadioButton...設定展示的背景顏色 int checkedRadioButtonId = radioGroup.getCheckedRadioButtonId(); switch (checkedRadioButtonId) { case R.id.radio_02://待支付 popDaiPay.setBackgroundColor(Color.BLUE); popAlreadyPay.setBackgroundColor(Color.YELLOW); popCancel.setBackgroundColor(Color.YELLOW); break; case R.id.radio_03://已支付 popDaiPay.setBackgroundColor(Color.YELLOW); popAlreadyPay.setBackgroundColor(Color.BLUE); popCancel.setBackgroundColor(Color.YELLOW); break; case R.id.radio_04://已取消 popDaiPay.setBackgroundColor(Color.YELLOW); popAlreadyPay.setBackgroundColor(Color.WHITE); popCancel.setBackgroundColor(Color.YELLOW); break; } popupWindow.showAsDropDown(sanDianPop); break; case R.id.pop_dai_pay://待支付 radioGroup.check(R.id.radio_02); getSupportFragmentManager().beginTransaction().replace(R.id.frame_content, new FragmentDaiPayOrder()).commit(); popupWindow.dismiss(); break; case R.id.pop_already_pay://已支付 radioGroup.check(R.id.radio_03); getSupportFragmentManager().beginTransaction().replace(R.id.frame_content, new FragmentAlreadyPayOrder()).commit(); popupWindow.dismiss(); break; case R.id.pop_cancel://已取消 radioGroup.check(R.id.radio_04); getSupportFragmentManager().beginTransaction().replace(R.id.frame_content, new FragmentCacelOrder()).commit(); popupWindow.dismiss(); break; } } }
對應佈局:
訂單佈局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:orientation="vertical" android:layout_height="match_parent"> <RelativeLayout android:id="@+id/detai_relative" android:layout_width="match_parent" android:layout_height="wrap_content"> <ImageView android:id="@+id/detail_image_back" android:padding="5dp" android:layout_width="40dp" android:layout_height="40dp" /> <TextView android:layout_centerInParent="true" android:text="我的訂單" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <ImageView android:id="@+id/san_dian_pop" android:padding="5dp" android:layout_alignParentRight="true" android:layout_width="40dp" android:layout_height="40dp" /> </RelativeLayout> <RadioGroup android:id="@+id/radio_group" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="40dp"> <RadioButton android:id="@+id/radio_01" android:checked="true" android:button="@null" android:gravity="center" android:text="全部" android:layout_width="0dp" android:layout_weight="1" android:layout_height="match_parent" /> <RadioButton android:id="@+id/radio_02" android:button="@null" android:gravity="center" android:text="待支付" android:layout_width="0dp" android:layout_weight="1" android:layout_height="match_parent" /> <RadioButton android:id="@+id/radio_03" android:button="@null" android:gravity="center" android:text="已支付" android:layout_width="0dp" android:layout_weight="1" android:layout_height="match_parent" /> <RadioButton android:id="@+id/radio_04" android:button="@null" android:gravity="center" android:text="已取消" android:layout_width="0dp" android:layout_weight="1" android:layout_height="match_parent" /> </RadioGroup> <FrameLayout android:id="@+id/frame_content" android:layout_width="match_parent" android:layout_height="match_parent"> </FrameLayout> </LinearLayout>
popupwindown佈局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:gravity="center" android:id="@+id/pop_dai_pay" android:text="待支付" android:layout_width="80dp" android:layout_height="50dp" /> <TextView android:gravity="center" android:id="@+id/pop_already_pay" android:text="已支付" android:layout_width="80dp" android:layout_height="50dp" /> <TextView android:gravity="center" android:id="@+id/pop_cancel" android:text="已取消" android:layout_width="80dp" android:layout_height="50dp" /> </LinearLayout>
切換的第一個頁面(所有訂單)
public class FragmentAllOrder extends Fragment implements FragmentOrderListInter {
private RecyclerView recyclerView;
private SmartRefreshLayout smartRefreshLayout;
private OrderListPresenter orderListPresenter;
//分頁
private int page = 1;
//大集合
private List<OrderListBean.DataBean> listAll = new ArrayList<>();
private OrderListAdapter orderListAdapter;
private RelativeLayout relative_empty_order;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_order_all_layout,container,false);
recyclerView = view.findViewById(R.id.recycler_order);
smartRefreshLayout = view.findViewById(R.id.smart_refresh);
relative_empty_order = view.findViewById(R.id.relative_empty_order);
return view;
}
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
//佈局管理器
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
//獲取訂單列表的資料
orderListPresenter = new OrderListPresenter(this);
orderListPresenter.getOrderData(Api.ORDER_LIST_URL);
smartRefreshLayout.setOnRefreshListener(new OnRefreshListener() {
@Override
public void onRefresh(RefreshLayout refreshlayout) {
smartRefreshLayout.finishRefresh(2000);
}
});
smartRefreshLayout.setOnLoadmoreListener(new OnLoadmoreListener() {
@Override
public void onLoadmore(RefreshLayout refreshlayout) {
page ++;
orderListPresenter.getOrderData(Api.ORDER_LIST_URL);
}
});
}
/**
* 設定介面卡
*/
private void setAdapter() {
if (orderListAdapter == null) {
orderListAdapter = new OrderListAdapter(getActivity(), listAll);
recyclerView.setAdapter(orderListAdapter);
}else {
orderListAdapter.notifyDataSetChanged();
}
smartRefreshLayout.finishLoadmore();
}
@Override
public void onOrderDataSuccess(OrderListBean orderListBean) {
try {
if ("0".equals(orderListBean.getCode())) {
//新增到大集合
listAll.addAll(orderListBean.getData());
if (listAll.size() == 0) {
relative_empty_order.setVisibility(View.VISIBLE);
smartRefreshLayout.setVisibility(View.GONE);
}else {
relative_empty_order.setVisibility(View.GONE);
smartRefreshLayout.setVisibility(View.VISIBLE);
}
//設定介面卡
setAdapter();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
佈局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.scwang.smartrefresh.layout.SmartRefreshLayout
android:id="@+id/smart_refresh"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_order"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v7.widget.RecyclerView>
</com.scwang.smartrefresh.layout.SmartRefreshLayout>
<RelativeLayout
android:visibility="gone"
android:id="@+id/relative_empty_order"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_centerInParent="true"
android:src="@mipmap/ic_launcher"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
</LinearLayout>
訂單的介面卡:
public class OrderListAdapter extends RecyclerView.Adapter<OrderListHolder> {
private List<OrderListBean.DataBean> listAll;
private Context context;
AddCartBean updateOrderBean;
public OrderListAdapter(Context context, List<OrderListBean.DataBean> listAll) {
this.context = context;
this.listAll = listAll;
}
@Override
public OrderListHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = View.inflate(context, R.layout.order_item_layout, null);
OrderListHolder orderListHolder = new OrderListHolder(view);
return orderListHolder;
}
@Override
public void onBindViewHolder(final OrderListHolder holder, int position) {
final OrderListBean.DataBean dataBean = listAll.get(position);
holder.text_title.setText(dataBean.getTitle());
holder.text_price.setText("價格:" + dataBean.getPrice());
//0 待支付1 已支付2 已取消
int status = dataBean.getStatus();
if (status == 0) {
holder.text_flag.setText("待支付");
holder.order_button.setText("取消訂單");
} else if (status == 1) {
holder.text_flag.setText("已支付");
holder.order_button.setText("檢視訂單");
} else if (status == 2) {
holder.text_flag.setText("已取消");
holder.order_button.setText("檢視訂單");
}
holder.text_time.setText("建立時間:" + dataBean.getCreatetime());
//點選事件
holder.order_button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//顯示的是 取消訂單...取消成功後 顯示檢視訂單,,,flag顯示已取消
if ("取消訂單".equals(holder.order_button.getText().toString())) {
//彈出對話方塊
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle("提示")
.setMessage("確定取消訂單嗎?")
.setNegativeButton("否", null)
.setPositiveButton("是", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
//請求取消訂單的介面,,,成功之後 文字顯示改變
Map<String, String> params = new HashMap<>();
params.put("uid", "2845");
params.put("status", String.valueOf(2));
params.put("orderId", String.valueOf(dataBean.getOrderid()));
RetrofitHelper.getApiService(Api.YU_API).get(Api.UPDATE_ORDER_URL, params)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<String>() {
@Override
public void onSubscribe(Disposable d) {
}
@Override
public void onNext(String s) {
if ("0".equals(updateOrderBean.getCode())) {
holder.text_flag.setText("已取消");
holder.order_button.setText("檢視訂單");
}
}
@Override
public void onError(Throwable e) {
}
@Override
public void onComplete() {
}
});
}
})
.show();
} else {
//如果顯示檢視訂單...去檢視訂單的資訊...吐司
Toast.makeText(context, "即將跳轉檢視訂單", Toast.LENGTH_SHORT).show();
}
}
});
}
@Override
public int getItemCount() {
return listAll.size();
}
}
切換的第二個頁面(待支付頁面)public class FragmentDaiPayOrder extends Fragment implements FragmentOrderListInter {
private RecyclerView recyclerView;
private SmartRefreshLayout smartRefreshLayout;
private OrderListPresenter orderListPresenter;
//分頁
private int page = 1;
//大集合
private List<OrderListBean.DataBean> listAll = new ArrayList<>();
private OrderListAdapter orderListAdapter;
private RelativeLayout relative_empty_order;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_order_all_layout,container,false);
recyclerView = view.findViewById(R.id.recycler_order);
smartRefreshLayout = view.findViewById(R.id.smart_refresh);
relative_empty_order = view.findViewById(R.id.relative_empty_order);
return view;
}
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
//佈局管理器
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
//獲取訂單列表的資料
orderListPresenter = new OrderListPresenter(this);
orderListPresenter.getOrderData(Api.ORDER_LIST_URL);
smartRefreshLayout.setOnRefreshListener(new OnRefreshListener() {
@Override
public void onRefresh(RefreshLayout refreshlayout) {
smartRefreshLayout.finishRefresh(2000);
}
});
smartRefreshLayout.setOnLoadmoreListener(new OnLoadmoreListener() {
@Override
public void onLoadmore(RefreshLayout refreshlayout) {
page ++;
orderListPresenter.getOrderData(Api.ORDER_LIST_URL);
}
});
}
/**
* 設定介面卡
*/
private void setAdapter() {
if (orderListAdapter == null) {
orderListAdapter = new OrderListAdapter(getActivity(), listAll);
recyclerView.setAdapter(orderListAdapter);
}else {
orderListAdapter.notifyDataSetChanged();
}
smartRefreshLayout.finishLoadmore();
}
@Override
public void onOrderDataSuccess(OrderListBean orderListBean) {
try {
if ("0".equals(orderListBean.getCode())) {
//新增到大集合
listAll.addAll(orderListBean.getData());
if (listAll.size() == 0) {
relative_empty_order.setVisibility(View.VISIBLE);
smartRefreshLayout.setVisibility(View.GONE);
}else {
relative_empty_order.setVisibility(View.GONE);
smartRefreshLayout.setVisibility(View.VISIBLE);
}
//設定介面卡
setAdapter();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
佈局:<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.scwang.smartrefresh.layout.SmartRefreshLayout
android:id="@+id/smart_refresh"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_order"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v7.widget.RecyclerView>
</com.scwang.smartrefresh.layout.SmartRefreshLayout>
<RelativeLayout
android:visibility="gone"
android:id="@+id/relative_empty_order"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_centerInParent="true"
android:src="@mipmap/ic_launcher"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
</LinearLayout>qiehuan
切換的第三個頁面(已支付)public class FragmentAlreadyPayOrder extends Fragment implements FragmentOrderListInter {
private RecyclerView recyclerView;
private SmartRefreshLayout smartRefreshLayout;
private OrderListPresenter orderListPresenter;
//分頁
private int page = 1;
//大集合
private List<OrderListBean.DataBean> listAll = new ArrayList<>();
private OrderListAdapter orderListAdapter;
private RelativeLayout relative_empty_order;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_order_all_layout,container,false);
recyclerView = view.findViewById(R.id.recycler_order);
smartRefreshLayout = view.findViewById(R.id.smart_refresh);
relative_empty_order = view.findViewById(R.id.relative_empty_order);
return view;
}
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
//佈局管理器
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
//獲取訂單列表的資料
orderListPresenter = new OrderListPresenter(this);
orderListPresenter.getOrderData(Api.ORDER_LIST_URL);
}
/**
* 設定介面卡
*/
private void setAdapter() {
if (orderListAdapter == null) {
orderListAdapter = new OrderListAdapter(getActivity(), listAll);
recyclerView.setAdapter(orderListAdapter);
}else {
orderListAdapter.notifyDataSetChanged();
}
}
@Override
public void onOrderDataSuccess(OrderListBean orderListBean) {
try {
if ("0".equals(orderListBean.getCode())) {
//新增到大集合
listAll.addAll(orderListBean.getData());
if (listAll.size() == 0) {
relative_empty_order.setVisibility(View.VISIBLE);
smartRefreshLayout.setVisibility(View.GONE);
}else {
relative_empty_order.setVisibility(View.GONE);
smartRefreshLayout.setVisibility(View.VISIBLE);
}
//設定介面卡
setAdapter();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
佈局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.scwang.smartrefresh.layout.SmartRefreshLayout
android:id="@+id/smart_refresh"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_order"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v7.widget.RecyclerView>
</com.scwang.smartrefresh.layout.SmartRefreshLayout>
<RelativeLayout
android:visibility="gone"
android:id="@+id/relative_empty_order"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_centerInParent="true"
android:src="@mipmap/ic_launcher"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
</LinearLayout>
第四個頁面(已取消)public class FragmentCacelOrder extends Fragment implements FragmentOrderListInter {
private RecyclerView recyclerView;
private SmartRefreshLayout smartRefreshLayout;
private OrderListPresenter orderListPresenter;
//分頁
private int page = 1;
//大集合
private List<OrderListBean.DataBean> listAll = new ArrayList<>();
private OrderListAdapter orderListAdapter;
private RelativeLayout relative_empty_order;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_order_all_layout,container,false);
recyclerView = view.findViewById(R.id.recycler_order);
smartRefreshLayout = view.findViewById(R.id.smart_refresh);
relative_empty_order = view.findViewById(R.id.relative_empty_order);
return view;
}
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
//佈局管理器
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
//獲取訂單列表的資料
orderListPresenter = new OrderListPresenter(this);
orderListPresenter.getOrderData(Api.ORDER_LIST_URL);
}
/**
* 設定介面卡
*/
private void setAdapter() {
if (orderListAdapter == null) {
orderListAdapter = new OrderListAdapter(getActivity(), listAll);
recyclerView.setAdapter(orderListAdapter);
}else {
orderListAdapter.notifyDataSetChanged();
}
}
@Override
public void onOrderDataSuccess(OrderListBean orderListBean) {
try {
if ("0".equals(orderListBean.getCode())) {
//新增到大集合
listAll.addAll(orderListBean.getData());
if (listAll.size() == 0) {
relative_empty_order.setVisibility(View.VISIBLE);
smartRefreshLayout.setVisibility(View.GONE);
}else {
relative_empty_order.setVisibility(View.GONE);
smartRefreshLayout.setVisibility(View.VISIBLE);
}
//設定介面卡
setAdapter();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
佈局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.scwang.smartrefresh.layout.SmartRefreshLayout
android:id="@+id/smart_refresh"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_order"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v7.widget.RecyclerView>
</com.scwang.smartrefresh.layout.SmartRefreshLayout>
<RelativeLayout
android:visibility="gone"
android:id="@+id/relative_empty_order"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_centerInParent="true"
android:src="@mipmap/ic_launcher"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
</LinearLayout>
最後:MVPm層:
public class OrderListModel {
private OrderListPresenterInter orderListPresenterInter;
public OrderListModel(OrderListPresenterInter orderListPresenterInter) {
this.orderListPresenterInter = orderListPresenterInter;
}
public void getOrderData(String orderListUrl) {
Map<String, String> params = new HashMap<>();
params.put("uid", "2845");
params.put("page","1");
RetrofitHelper.getApiService(Api.YU_API).get(orderListUrl, params)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<String>() {
@Override
public void onSubscribe(Disposable d) {
}
@Override
public void onNext(String s) {
OrderListBean orderListBean = new Gson().fromJson(s, OrderListBean.class);
orderListPresenterInter.onOrderDataSuccess(orderListBean);
}
@Override
public void onError(Throwable e) {
}
@Override
public void onComplete() {
}
});
}
}
p層:
public class OrderListPresenter implements OrderListPresenterInter {
private FragmentOrderListInter fragmentOrderListInter;
private OrderListModel orderListModel;
public OrderListPresenter(FragmentOrderListInter fragmentOrderListInter) {
this.fragmentOrderListInter = fragmentOrderListInter;
orderListModel = new OrderListModel(this);
}
public void getOrderData(String orderListUrl) {
orderListModel.getOrderData(orderListUrl);
}
@Override
public void onOrderDataSuccess(OrderListBean orderListBean) {
fragmentOrderListInter.onOrderDataSuccess(orderListBean);
}
}