显示商品种类

master
fangshicai 3 years ago
parent d2861bbc66
commit eb80cb2935

@ -23,10 +23,11 @@
<entry key="..\:/andriod/Android_Couser_Design/app/src/main/res/layout/activity_home_page.xml" value="0.152" />
<entry key="..\:/andriod/Android_Couser_Design/app/src/main/res/layout/activity_login.xml" value="0.176" />
<entry key="..\:/andriod/Android_Couser_Design/app/src/main/res/layout/activity_main.xml" value="0.1" />
<entry key="..\:/andriod/Android_Couser_Design/app/src/main/res/layout/fragment_home_page.xml" value="0.2" />
<entry key="..\:/andriod/Android_Couser_Design/app/src/main/res/layout/fragment_home_page.xml" value="0.4" />
<entry key="..\:/andriod/Android_Couser_Design/app/src/main/res/layout/fragment_message_page.xml" value="0.13229166666666667" />
<entry key="..\:/andriod/Android_Couser_Design/app/src/main/res/layout/fragment_my_page.xml" value="0.13229166666666667" />
<entry key="..\:/andriod/Android_Couser_Design/app/src/main/res/layout/fragment_shop_page.xml" value="0.1837916063675832" />
<entry key="..\:/andriod/Android_Couser_Design/app/src/main/res/layout/list_good_stype_item.xml" value="0.264" />
<entry key="..\:/andriod/Android_Couser_Design/app/src/main/res/menu/bottom_navigation_menu.xml" value="0.176" />
</map>
</option>

@ -33,22 +33,22 @@
tools:targetApi="31">
<activity
android:name=".activity.HomePageActivity"
android:exported="false" >
<!-- <intent-filter>-->
<!-- <action android:name="android.intent.action.MAIN" />-->
<!-- <category android:name="android.intent.category.LAUNCHER" />-->
<!-- </intent-filter>-->
</activity>
<activity
android:name=".activity.LoginActivity"
android:exported="true">
android:exported="true" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".activity.LoginActivity"
android:exported="false">
<!-- <intent-filter>-->
<!-- <action android:name="android.intent.action.MAIN" />-->
<!-- <category android:name="android.intent.category.LAUNCHER" />-->
<!-- </intent-filter>-->
</activity>
<activity android:name="com.android.MainActivity">
</activity>

@ -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);
}
}
}

@ -3,22 +3,41 @@ package com.android.activity.fragment;
import android.content.Context;
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import com.android.R;
import com.android.activity.adapter.GoodsTypeAdapter;
import com.android.bean.GoodsType;
import com.android.bean.ResponseData;
import com.android.model.goods.GoodsListener;
import com.android.model.goods.GoodsModelimpl;
import java.util.List;
/**
* A simple {@link Fragment} subclass.
*com.android.activity.fragment.HomePageFragment
* create an instance of this fragment.
*/
public class HomePageFragment extends Fragment {
public class HomePageFragment extends Fragment implements View.OnClickListener, GoodsListener {
private Context context = null;
private Button button;
private GoodsModelimpl goodsModelimpl;
private List<GoodsType> goodsTypeList;
private GoodsTypeAdapter goodsTypeAdapter = null;
private RecyclerView recyclerView;
private View rootView;
@ -32,14 +51,50 @@ public class HomePageFragment extends Fragment {
super.onCreate(savedInstanceState);
}
private void initGoodsTypeData() {
goodsModelimpl = new GoodsModelimpl();
goodsModelimpl.getAllGoodsType(this);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
context = getActivity();
View rootView = inflater.inflate(R.layout.fragment_home_page,
rootView = inflater.inflate(R.layout.fragment_home_page,
container, false);
Log.e("1","onCreateView");
initGoodsTypeData();
return rootView;
}
@Override
public void onGetAllGoodsType(ResponseData<List<GoodsType>> responseData) {
this.goodsTypeList = responseData.getData();
initRecyclerview();
}
private void initRecyclerview() {
recyclerView = rootView.findViewById(R.id.lv_goodsType_list);
goodsTypeAdapter = new GoodsTypeAdapter(goodsTypeList,context,R.layout.list_good_stype_item);
LinearLayoutManager llm = new LinearLayoutManager(context);
recyclerView.setLayoutManager(llm);
recyclerView.setAdapter(goodsTypeAdapter);
}
@Override
public void onClick(View v) {
}
}

@ -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() {
}
});
}
}

@ -5,10 +5,12 @@
android:layout_height="match_parent"
tools:context=".activity.fragment.HomePageFragment">
<!-- TODO: Update blank fragment layout -->
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="home" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/lv_goodsType_list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:isScrollContainer="true"/>
</FrameLayout>

@ -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…
Cancel
Save