parent
d2861bbc66
commit
eb80cb2935
@ -0,0 +1,61 @@
|
||||
package com.android.activity.adapter;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.android.R;
|
||||
import com.android.bean.GoodsType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class GoodsTypeAdapter extends RecyclerView.Adapter<GoodsTypeAdapter.ViewHolder> {
|
||||
private List<GoodsType> goodsTypeList;
|
||||
private Context context;
|
||||
private int resourceId;
|
||||
private ViewHolder holder;
|
||||
|
||||
public GoodsTypeAdapter(List<GoodsType> goodsTypeList, Context context,int resourceId) {
|
||||
this.goodsTypeList = goodsTypeList;
|
||||
this.context = context;
|
||||
this.resourceId = resourceId;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View view = LayoutInflater.from(context)
|
||||
.inflate(resourceId,parent,false);
|
||||
holder = new ViewHolder(view);
|
||||
return holder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
|
||||
GoodsType goodsType = goodsTypeList.get(position);
|
||||
Log.d("1",goodsType.getType());
|
||||
holder.textView.setText(goodsType.getType());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return goodsTypeList.size();
|
||||
}
|
||||
|
||||
public class ViewHolder extends RecyclerView.ViewHolder {
|
||||
TextView textView;
|
||||
public ViewHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
|
||||
textView = itemView.findViewById(R.id.tv_goods_type_item);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,143 @@
|
||||
package com.android.bean;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class Goods {
|
||||
|
||||
private String addr;
|
||||
private String appKey;
|
||||
private String avatar;
|
||||
private String content;
|
||||
private String username;
|
||||
private String typeName;
|
||||
private Integer createTime;
|
||||
private Integer id;
|
||||
private Integer imageCode;
|
||||
private Integer price;
|
||||
private Integer status;
|
||||
private Integer tUserId;
|
||||
private Integer tuserId;
|
||||
private Integer typeId;
|
||||
private List array;
|
||||
|
||||
public String getAddr() {
|
||||
return addr;
|
||||
}
|
||||
|
||||
public void setAddr(String addr) {
|
||||
this.addr = addr;
|
||||
}
|
||||
|
||||
public String getAppKey() {
|
||||
return appKey;
|
||||
}
|
||||
|
||||
public void setAppKey(String appKey) {
|
||||
this.appKey = appKey;
|
||||
}
|
||||
|
||||
public String getAvatar() {
|
||||
return avatar;
|
||||
}
|
||||
|
||||
public void setAvatar(String avatar) {
|
||||
this.avatar = avatar;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getTypeName() {
|
||||
return typeName;
|
||||
}
|
||||
|
||||
public void setTypeName(String typeName) {
|
||||
this.typeName = typeName;
|
||||
}
|
||||
|
||||
public Integer getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public void setCreateTime(Integer createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Integer getImageCode() {
|
||||
return imageCode;
|
||||
}
|
||||
|
||||
public void setImageCode(Integer imageCode) {
|
||||
this.imageCode = imageCode;
|
||||
}
|
||||
|
||||
public Integer getPrice() {
|
||||
return price;
|
||||
}
|
||||
|
||||
public void setPrice(Integer price) {
|
||||
this.price = price;
|
||||
}
|
||||
|
||||
public Integer getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(Integer status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public Integer gettUserId() {
|
||||
return tUserId;
|
||||
}
|
||||
|
||||
public void settUserId(Integer tUserId) {
|
||||
this.tUserId = tUserId;
|
||||
}
|
||||
|
||||
public Integer getTuserId() {
|
||||
return tuserId;
|
||||
}
|
||||
|
||||
public void setTuserId(Integer tuserId) {
|
||||
this.tuserId = tuserId;
|
||||
}
|
||||
|
||||
public Integer getTypeId() {
|
||||
return typeId;
|
||||
}
|
||||
|
||||
public void setTypeId(Integer typeId) {
|
||||
this.typeId = typeId;
|
||||
}
|
||||
|
||||
public List getArray() {
|
||||
return array;
|
||||
}
|
||||
|
||||
public void setArray(List array) {
|
||||
this.array = array;
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package com.android.bean;
|
||||
|
||||
public class GoodsType {
|
||||
private Integer id;
|
||||
private String type;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package com.android.model.goods;
|
||||
|
||||
import com.android.bean.GoodsType;
|
||||
import com.android.bean.ResponseData;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.reactivex.rxjava3.core.Observable;
|
||||
import retrofit2.http.GET;
|
||||
import retrofit2.http.Headers;
|
||||
|
||||
public interface GoodsHttp_interface {
|
||||
@GET("tran/goods/type")
|
||||
@Headers({"appId:b34ac21286ae45938add627b418a4871",
|
||||
"appSecret:67526def9de11d4a64f5e80e60ed3372eea69"})
|
||||
Observable<ResponseData<List<GoodsType>>> sendGetAllGoodsType();
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package com.android.model.goods;
|
||||
|
||||
import com.android.bean.GoodsType;
|
||||
import com.android.bean.ResponseData;
|
||||
import com.android.bean.User;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface GoodsListener {
|
||||
void onGetAllGoodsType(ResponseData<List<GoodsType>> responseData);
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package com.android.model.goods;
|
||||
|
||||
import com.android.model.login.LoginListener;
|
||||
|
||||
public interface GoodsModel {
|
||||
void getAllGoodsType(GoodsListener goodsListener);
|
||||
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
package com.android.model.goods;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.bean.GoodsType;
|
||||
import com.android.bean.ResponseData;
|
||||
import com.android.model.login.LoginListener;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.rxjava3.annotations.NonNull;
|
||||
import io.reactivex.rxjava3.core.Observable;
|
||||
import io.reactivex.rxjava3.core.Observer;
|
||||
import io.reactivex.rxjava3.disposables.Disposable;
|
||||
import io.reactivex.rxjava3.schedulers.Schedulers;
|
||||
import retrofit2.Retrofit;
|
||||
import retrofit2.adapter.rxjava3.RxJava3CallAdapterFactory;
|
||||
import retrofit2.converter.gson.GsonConverterFactory;
|
||||
|
||||
public class GoodsModelimpl implements GoodsModel{
|
||||
private String TAG ="GoodsModelimpl";
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void getAllGoodsType(GoodsListener goodsListener) {
|
||||
Retrofit retrofit = new Retrofit.Builder()
|
||||
.baseUrl("http://47.107.52.7:88/member/")
|
||||
.addConverterFactory(GsonConverterFactory.create())
|
||||
.addCallAdapterFactory(RxJava3CallAdapterFactory.create())
|
||||
.build();
|
||||
GoodsHttp_interface httpInterface =
|
||||
retrofit.create(GoodsHttp_interface.class);
|
||||
Observable<ResponseData<List<GoodsType>>> observable
|
||||
= httpInterface.sendGetAllGoodsType();
|
||||
|
||||
observable
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Observer<ResponseData<List<GoodsType>>>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@NonNull ResponseData<List<GoodsType>> listResponseData) {
|
||||
Log.e(TAG,listResponseData.getMsg());
|
||||
goodsListener.onGetAllGoodsType(listResponseData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
<?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">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_goods_type_item"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="商品"
|
||||
/>
|
||||
|
||||
|
||||
</LinearLayout>
|
Loading…
Reference in new issue