初始数据展示到页面

master
fangshicai 3 years ago
parent de53e6db38
commit 67b2ef13f6

@ -66,6 +66,14 @@ dependencies {
//eventbus
implementation("org.greenrobot:eventbus:3.3.1")
// glide
implementation 'com.github.bumptech.glide:glide:4.11.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'
implementation "androidx.cardview:cardview:1.0.0"

@ -19,6 +19,8 @@
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- 允许读取手机状态 用于创建BmobInstallation -->
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<!-- 本地存储 (Local Storage)-->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"

@ -9,7 +9,5 @@ public class MainActivity extends AppCompatActivity{
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}

@ -0,0 +1,93 @@
package com.android.activity.adapter;
import android.content.Context;
import android.graphics.Bitmap;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.android.R;
import com.android.bean.Good;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.FutureTarget;
import java.util.ArrayList;
import java.util.concurrent.ExecutionException;
public class GoodsAdapter extends RecyclerView.Adapter<GoodsAdapter.ViewHolder> {
private ArrayList<Good> goodArrayList;
private Context context;
public GoodsAdapter(ArrayList<Good> goodArrayList,Context context) {
this.goodArrayList = goodArrayList;
this.context = context;
Log.e("goodsAdapter","GoodsAdapter");
}
@NonNull
@Override
public GoodsAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.goods_show_item,parent,false);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull GoodsAdapter.ViewHolder holder, int position) {
String strTvTitle;
String strTvCount;
String imageUrl;
if (goodArrayList.get(position) != null){
strTvTitle = goodArrayList.get(position).getContent();
strTvCount = goodArrayList.get(position).getPrice().toString();
imageUrl = (String) goodArrayList.get(position).getImageUrlList().get(0);
Log.e("imageUrl", (String) goodArrayList.get(position).getImageUrlList().get(0));
holder.getTvTitle().setText(strTvTitle);
holder.getTvCount().setText(strTvCount);
Glide.with(context)
.load(imageUrl)
.into(holder.getIvGoods());
}
}
@Override
public int getItemCount() {
if (goodArrayList != null)
return goodArrayList.size();
return 0;
}
public class ViewHolder extends RecyclerView.ViewHolder {
private ImageView ivGoods;
private TextView tvTitle;
private TextView tvCount;
public ViewHolder(@NonNull View itemView) {
super(itemView);
ivGoods = itemView.findViewById(R.id.iv_goods);
tvTitle = itemView.findViewById(R.id.tv_title);
tvCount = itemView.findViewById(R.id.tv_count);
}
public ImageView getIvGoods() {
return ivGoods;
}
public TextView getTvTitle() {
return tvTitle;
}
public TextView getTvCount() {
return tvCount;
}
}
}

@ -3,6 +3,9 @@ package com.android.activity.fragment;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.os.Parcelable;
import android.util.Log;
@ -12,6 +15,7 @@ import android.view.ViewGroup;
import android.widget.TextView;
import com.android.R;
import com.android.activity.adapter.GoodsAdapter;
import com.android.bean.Good;
import com.android.utils.eventBus.EventMsg;
@ -34,11 +38,15 @@ public class GoodsTypeFragment extends Fragment {
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private static final String ARG_TEXT = "param1";
private static final String ARG_GOODS = "goodsTypeList";
private ArrayList<Good> goodArrayList;
private EventMsg<Good> eventMsg;
private ArrayList<Good> typeGoodList;
private RecyclerView recyclerView;
private GoodsAdapter goodsAdapter;
View rootView;
private String mParam1;
private Integer mParam1;
public GoodsTypeFragment() {
// Required empty public constructor
@ -46,11 +54,11 @@ public class GoodsTypeFragment extends Fragment {
// TODO: Rename and change types and number of parameters
public static GoodsTypeFragment newInstance(String param1,List<Good> goodsList) {
public static GoodsTypeFragment newInstance(Integer param1,List<Good> goodsList) {
GoodsTypeFragment fragment = new GoodsTypeFragment();
Bundle args = new Bundle();
args.putString(ARG_TEXT, param1);
args.putParcelableArrayList(ARG_GOODS, (ArrayList<? extends Parcelable>) goodsList);
args.putInt(ARG_TEXT, param1);
args.putSerializable(ARG_GOODS, (Serializable) goodsList);
fragment.setArguments(args);
return fragment;
}
@ -58,9 +66,17 @@ public class GoodsTypeFragment extends Fragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//注册事件
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_TEXT);
mParam1 = getArguments().getInt(ARG_TEXT);
goodArrayList = (ArrayList<Good>) getArguments().getSerializable(ARG_GOODS);
}
if(goodArrayList != null) {
typeGoodList = new ArrayList<>();
for (int j = 0; j < goodArrayList.size(); j++) {
if(goodArrayList.get(j).getTypeId() == mParam1){
typeGoodList.add(goodArrayList.get(j));
}
}
}
}
@ -68,18 +84,36 @@ public class GoodsTypeFragment extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
if(rootView == null)
rootView = inflater.inflate(R.layout.fragment_goods_type, container, false);
//recycle必须在
initView();
return rootView;
}
private void initView() {
recyclerView = rootView.findViewById(R.id.rl_goods_show);
if (goodArrayList != null){
goodsAdapter = new GoodsAdapter(typeGoodList,getContext());
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
recyclerView.setAdapter(goodsAdapter);
}
// TextView view = rootView.findViewById(R.id.tv_goods);
// view.setText(goodArrayList.get(1).getUsername());
}
@Override
public void onStart() {
EventBus.getDefault().register(this);
super.onStart();
}
@Override
@ -99,9 +133,8 @@ public class GoodsTypeFragment extends Fragment {
@Subscribe(sticky = true,threadMode = ThreadMode.MAIN)
public void onReceiveMsg(EventMsg eventMsg){
this.eventMsg = eventMsg;
TextView view = rootView.findViewById(R.id.tv_goods);
view.setText(eventMsg.getMsg());
Log.e("111111111",eventMsg.getMsg());
// TextView view = rootView.findViewById(R.id.tv_goods);
// view.setText(eventMsg.getMsg());
}
}

@ -3,9 +3,12 @@ package com.android.activity.fragment;
import android.content.Context;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.viewpager2.widget.ViewPager2;
import android.os.Handler;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
@ -40,7 +43,6 @@ public class HomePageFragment extends Fragment implements View.OnClickListener,
private GoodsModelimpl goodsModelimpl;
private List<GoodsType> goodsTypeList;
private List<Good> goodList;
private List<Good> typeGoodList;
private View rootView;
private GoodsTypeFSAdapter goodsTypeFSAdapter;
@ -51,6 +53,7 @@ public class HomePageFragment extends Fragment implements View.OnClickListener,
public HomePageFragment() {
// Required empty public constructor
}
@ -68,52 +71,47 @@ public class HomePageFragment extends Fragment implements View.OnClickListener,
rootView = inflater.inflate(R.layout.fragment_home_page,
container, false);
Log.e("1","onCreateView");
initGoodsTypeData();
return rootView;
}
private void initGoodsTypeData() {
goodsModelimpl = new GoodsModelimpl();
goodsModelimpl.getAllGoodsType(this);
goodsModelimpl.getAllGood(this);
goodsModelimpl.getAllGoodsType(this);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
initRecyclerview();
}
},2000);
}
}
//获取商品类型成功回调
@Override
public void onGetAllGoodsType(ResponseData<List<GoodsType>> responseData) {
this.goodsTypeList = responseData.getData();
this.goodsTypeList.add(new GoodsType(0,"全部"));
initRecyclerview();
}
//获取商品成功回调
@Override
public void onGetAllGoodSuccess(ResponseData<GoodRecords> responseData) {
this.goodList = responseData.getData().getRecords();
Log.e("goodList",goodList.get(1).getUsername());
}
private void initRecyclerview() {
viewPager = rootView.findViewById(R.id.view_pager);
ArrayList<Fragment> fragments = new ArrayList<>();
for (int i = 0; i < goodsTypeList.size(); i++) {
// for (int j = 0; j < goodList.size(); j++) {
// if(goodList.get(i).getTypeId() == goodsTypeList.get(i).getId()){
// typeGoodList.add(goodList.get(i));
// }
// }
fragments.add(GoodsTypeFragment.newInstance(goodsTypeList.get(i).getType(), goodList));
fragments.add(GoodsTypeFragment.newInstance(goodsTypeList.get(i).getId(), goodList));
//EventBus发布消息
// EventBus.getDefault().postSticky(new EventMsg<>(goodsTypeList.get(i).getType(),200,goodList));

@ -8,7 +8,7 @@ import java.util.ArrayList;
import java.util.List;
public class Good implements Parcelable {
public class Good implements Serializable {
private String addr;
private String appKey;
@ -19,7 +19,7 @@ public class Good implements Parcelable {
private Long createTime;
private Long id;
private Long imageCode;
private ArrayList imageUrlList;
private List<String> imageUrlList;
private Integer price;
private Integer status;
private Long tUserId;
@ -27,6 +27,67 @@ public class Good implements Parcelable {
private Integer typeId;
private List array;
protected Good(Parcel in) {
addr = in.readString();
appKey = in.readString();
avatar = in.readString();
content = in.readString();
username = in.readString();
typeName = in.readString();
if (in.readByte() == 0) {
createTime = null;
} else {
createTime = in.readLong();
}
if (in.readByte() == 0) {
id = null;
} else {
id = in.readLong();
}
if (in.readByte() == 0) {
imageCode = null;
} else {
imageCode = in.readLong();
}
if (in.readByte() == 0) {
price = null;
} else {
price = in.readInt();
}
if (in.readByte() == 0) {
status = null;
} else {
status = in.readInt();
}
if (in.readByte() == 0) {
tUserId = null;
} else {
tUserId = in.readLong();
}
if (in.readByte() == 0) {
tuserId = null;
} else {
tuserId = in.readLong();
}
if (in.readByte() == 0) {
typeId = null;
} else {
typeId = in.readInt();
}
}
// public static final Creator<Good> CREATOR = new Creator<Good>() {
// @Override
// public Good createFromParcel(Parcel in) {
// return new Good(in);
// }
//
// @Override
// public Good[] newArray(int size) {
// return new Good[size];
// }
// };
public String getAddr() {
return addr;
}
@ -99,7 +160,7 @@ public class Good implements Parcelable {
this.imageCode = imageCode;
}
public ArrayList getImageUrlList() {
public List getImageUrlList() {
return imageUrlList;
}
@ -155,14 +216,30 @@ public class Good implements Parcelable {
this.array = array;
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
}
// @Override
// public int describeContents() {
//
// return 0;
// }
//
// @Override
// public void writeToParcel(Parcel dest, int flags) {
// dest.writeString(addr);
// dest.writeString(appKey);
// dest.writeString(avatar);
// dest.writeString(content);
// dest.writeString(username);
// dest.writeString(typeName);
// dest.writeLong(createTime);
// dest.writeLong(id);
// dest.writeLong(imageCode);
// dest.writeList(imageUrlList);
// dest.writeInt(price);
// dest.writeInt(status);
// dest.writeLong(tUserId);
// dest.writeLong(tuserId);
// dest.writeInt(typeId);
// dest.writeList(array);
//
// }
}

@ -17,13 +17,13 @@ import retrofit2.http.QueryMap;
public interface GoodsHttp_interface {
@GET("tran/goods/type")
@Headers({"appId:b34ac21286ae45938add627b418a4871",
"appSecret:67526def9de11d4a64f5e80e60ed3372eea69"})
@Headers({"appId:e843562fefa144bf808a9621b107b3a4",
"appSecret:76387a99d8b52fad54b94bea1118262573381"})
Observable<ResponseData<List<GoodsType>>> sendGetAllGoodsType();
@GET("tran/goods/all")
@Headers({"appId:b34ac21286ae45938add627b418a4871",
"appSecret:67526def9de11d4a64f5e80e60ed3372eea69"})
@Headers({"appId:e843562fefa144bf808a9621b107b3a4",
"appSecret:76387a99d8b52fad54b94bea1118262573381"})
Observable<ResponseData<GoodRecords>> sendGetAllGood(@Query("userId") Integer userId,
@QueryMap Map<String, Object> map
);

@ -78,7 +78,7 @@ public class GoodsModelimpl implements GoodsModel{
Map<String, Object> map = new ArrayMap<>();
Observable<ResponseData<GoodRecords>> observable
= httpInterface.sendGetAllGood(6, map);
= httpInterface.sendGetAllGood(17, map);
observable.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())

@ -0,0 +1,7 @@
package com.android.utils.constraint;
public class LoginConstraint {
public static final String AppId_VALUE = "appId:b34ac21286ae45938add627b418a4871";
public static final String AppSecret_VALUE = "appId:b34ac21286ae45938add627b418a4871";
public static final String BASE_URL = "http://47.107.52.7:88/member/";
}

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M11,9h2L13,6h3L16,4h-3L13,1h-2v3L8,4v2h3v3zM7,18c-1.1,0 -1.99,0.9 -1.99,2S5.9,22 7,22s2,-0.9 2,-2 -0.9,-2 -2,-2zM17,18c-1.1,0 -1.99,0.9 -1.99,2s0.89,2 1.99,2 2,-0.9 2,-2 -0.9,-2 -2,-2zM7.17,14.75l0.03,-0.12 0.9,-1.63h7.45c0.75,0 1.41,-0.41 1.75,-1.03l3.86,-7.01L19.42,4h-0.01l-1.1,2 -2.76,5L8.53,11l-0.13,-0.27L6.16,6l-0.95,-2 -0.94,-2L1,2v2h2l3.6,7.59 -1.35,2.45c-0.16,0.28 -0.25,0.61 -0.25,0.96 0,1.1 0.9,2 2,2h12v-2L7.42,15c-0.13,0 -0.25,-0.11 -0.25,-0.25z"/>
</vector>

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

@ -5,13 +5,9 @@
android:layout_height="match_parent"
tools:context=".activity.fragment.GoodsTypeFragment">
<!-- TODO: Update blank fragment layout -->
<TextView
android:id="@+id/tv_goods"
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rl_goods_show"
android:layout_width="match_parent"
android:gravity="center"
android:textSize="32sp"
android:layout_height="match_parent"
android:text="@string/hello_blank_fragment" />
android:layout_height="wrap_content"/>
</FrameLayout>

@ -6,20 +6,27 @@
android:layout_height="match_parent"
tools:context=".activity.fragment.HomePageFragment">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<com.google.android.material.tabs.TabLayout
android:id="@+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="scrollable"
/>
/>
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/tabLayout"
/>
</RelativeLayout>
</FrameLayout>

@ -0,0 +1,61 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_marginRight="5dp"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/iv_goods"
android:layout_width="120dp"
android:layout_height="90dp"
>
</ImageView>
<TextView
android:id="@+id/tv_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/iv_goods"
android:text="手机"
android:textSize="20dp"
android:layout_marginTop="10dp">
</TextView>
<TextView
android:id="@+id/tv_price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/tv_title"
android:text="价格: "
android:textSize="15dp"
android:textColor="#FF8F03"
android:layout_marginTop="15dp">
</TextView>
<TextView
android:id="@+id/tv_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@id/tv_price"
android:layout_toRightOf="@id/tv_price"
android:textSize="15dp"
android:text="1000"
android:textColor="#FF8F03">
</TextView>
<!-- <Button-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content">-->
<!-- </Button>-->
</RelativeLayout>
</androidx.cardview.widget.CardView>
Loading…
Cancel
Save