点击商品进入商品详细页

master
fangshicai 3 years ago
parent 60f32b1980
commit 5e8769e4dd

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RenderSettings">
<option name="showDecorations" value="true" />
</component>
</project>

@ -5,21 +5,13 @@
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <!-- 允许联网 -->
<uses-permission android:name="android.permission.INTERNET" /> <!-- 获取GSM2g、WCDMA联通3g等网络状态的信息 -->
<!-- 允许联网 --> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <!-- 获取wifi网络状态的信息 -->
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <!-- 保持CPU 运转,屏幕和键盘灯有可能是关闭的,用于文件上传和下载 -->
<!-- 获取GSM2g、WCDMA联通3g等网络状态的信息 --> <uses-permission android:name="android.permission.WAKE_LOCK" /> <!-- 获取sd卡写的权限用于文件上传和下载 -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <!-- 允许读取手机状态 用于创建BmobInstallation -->
<!-- 获取wifi网络状态的信息 --> <uses-permission android:name="android.permission.READ_PHONE_STATE" /> <!-- 本地存储 (Local Storage) -->
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<!-- 保持CPU 运转,屏幕和键盘灯有可能是关闭的,用于文件上传和下载 -->
<uses-permission android:name="android.permission.WAKE_LOCK" />
<!-- 获取sd卡写的权限用于文件上传和下载 -->
<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" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application <application
@ -33,8 +25,13 @@
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/Theme.Android_Couser_Design" android:theme="@style/Theme.Android_Couser_Design"
tools:targetApi="31"> tools:targetApi="31">
<activity
android:name=".activity.GoodsDetailsActivity"
android:launchMode="singleTask"
android:exported="false" />
<activity <activity
android:name=".activity.HomePageActivity" android:name=".activity.HomePageActivity"
android:launchMode="singleTask"
android:exported="true"> android:exported="true">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
@ -45,15 +42,15 @@
<activity <activity
android:name=".activity.LoginActivity" android:name=".activity.LoginActivity"
android:exported="false"> android:exported="false">
<!-- <intent-filter> --> <!-- <intent-filter> -->
<!-- <action android:name="android.intent.action.MAIN" /> --> <!-- <action android:name="android.intent.action.MAIN" /> -->
<!-- <category android:name="android.intent.category.LAUNCHER" /> --> <!-- <category android:name="android.intent.category.LAUNCHER" /> -->
<!-- </intent-filter> --> <!-- </intent-filter> -->
</activity> </activity>
<activity android:name="com.android.MainActivity"> <activity android:name="com.android.MainActivity"></activity>
</activity>
</application> </application>
</manifest> </manifest>

@ -0,0 +1,46 @@
package com.android.activity;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import com.android.R;
import com.android.bean.Good;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
public class GoodsDetailsActivity extends AppCompatActivity {
private Good good;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_goods_details);
//注册EventBus
EventBus.getDefault().register(this);
}
//拿取数据
@Subscribe(threadMode = ThreadMode.MAIN,sticky = true)
public void getGoods(Good data){
if(data != null){
this.good = data;
Log.e("GoodsDetailsActivity",good.getContent());
}else {
Log.e("GoodsDetailsActivity","获取失败");
}
}
@Override
protected void onDestroy() {
EventBus.getDefault().unregister(this);
super.onDestroy();
}
}

@ -19,6 +19,7 @@ import com.google.android.material.navigation.NavigationBarView;
import com.google.android.material.navigation.NavigationView; import com.google.android.material.navigation.NavigationView;
import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
public class HomePageActivity extends AppCompatActivity implements BottomNavigationView.OnNavigationItemSelectedListener{ public class HomePageActivity extends AppCompatActivity implements BottomNavigationView.OnNavigationItemSelectedListener{
@ -32,6 +33,7 @@ public class HomePageActivity extends AppCompatActivity implements BottomNavigat
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home_page); setContentView(R.layout.activity_home_page);
// EventBus.getDefault().register(this);
navigation = findViewById(R.id.bottom_navigation); navigation = findViewById(R.id.bottom_navigation);
navigation.setLabelVisibilityMode(NavigationBarView.LABEL_VISIBILITY_LABELED); navigation.setLabelVisibilityMode(NavigationBarView.LABEL_VISIBILITY_LABELED);
@ -66,6 +68,7 @@ public class HomePageActivity extends AppCompatActivity implements BottomNavigat
case R.id.item_my: case R.id.item_my:
fragmentTransaction.replace(R.id.fragment_container, new MyPageFragment()); fragmentTransaction.replace(R.id.fragment_container, new MyPageFragment());
fragmentTransaction.commit(); fragmentTransaction.commit();
break; break;
case R.id.item_shop: case R.id.item_shop:
fragmentTransaction.replace(R.id.fragment_container, new ShopCarPageFragment()); fragmentTransaction.replace(R.id.fragment_container, new ShopCarPageFragment());
@ -79,9 +82,10 @@ public class HomePageActivity extends AppCompatActivity implements BottomNavigat
return true; return true;
} }
@Override @Override
protected void onDestroy() { protected void onDestroy() {
// EventBus.getDefault().unregister(this);
super.onDestroy(); super.onDestroy();
} }
} }

@ -17,10 +17,14 @@ import com.android.model.login.LoginModel;
import com.android.model.login.LoginModelImpl; import com.android.model.login.LoginModelImpl;
import com.android.utils.watcher.MyWatcher; import com.android.utils.watcher.MyWatcher;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
public class LoginActivity extends AppCompatActivity implements LoginListener, View.OnClickListener { public class LoginActivity extends AppCompatActivity implements LoginListener, View.OnClickListener {
private static final String TAG ="LoginActivity"; private static final String TAG ="LoginActivity";
private ResponseData responseData; private ResponseData<User> responseData;
private EditText etPwd; private EditText etPwd;
private EditText etAccount; private EditText etAccount;
private Button LoginButton; private Button LoginButton;
@ -82,14 +86,12 @@ public class LoginActivity extends AppCompatActivity implements LoginListener, V
this.responseData = responseData; this.responseData = responseData;
login(); login();
Log.e("responseData",String.valueOf(responseData.getData().getId()));
} }
@Override @Override
public void onGetCodeSuccess(ResponseData<String> responseData) { public void onGetCodeSuccess(ResponseData<String> responseData) {
Log.e(TAG,"onGetCodeSuccess"+responseData.getCode());
} }
@Override @Override
@ -106,9 +108,13 @@ public class LoginActivity extends AppCompatActivity implements LoginListener, V
private void login() { private void login() {
if(responseData.getCode() == 200){ if(responseData.getCode() == 200){
Intent intent = new Intent(LoginActivity.this,HomePageActivity.class); Intent intent = new Intent(LoginActivity.this,HomePageActivity.class);
EventBus.getDefault().postSticky(responseData);
startActivity(intent); startActivity(intent);
}else { }else {
Log.e("login",responseData.getMsg()); Log.e("login",responseData.getMsg());
} }
} }
} }

@ -48,7 +48,6 @@ public class GoodsAdapter extends RecyclerView.Adapter<GoodsAdapter.ViewHolder>
strTvTitle = goodArrayList.get(position).getContent(); strTvTitle = goodArrayList.get(position).getContent();
strTvCount = goodArrayList.get(position).getPrice().toString(); strTvCount = goodArrayList.get(position).getPrice().toString();
imageUrl = (String) goodArrayList.get(position).getImageUrlList().get(0); imageUrl = (String) goodArrayList.get(position).getImageUrlList().get(0);
Log.e("imageUrl", (String) goodArrayList.get(position).getImageUrlList().get(0));
holder.getTvTitle().setText(strTvTitle); holder.getTvTitle().setText(strTvTitle);
holder.getTvCount().setText(strTvCount); holder.getTvCount().setText(strTvCount);

@ -2,6 +2,7 @@ package com.android.activity.adapter;
import static android.content.ContentValues.TAG; import static android.content.ContentValues.TAG;
import android.annotation.SuppressLint;
import android.content.Context; import android.content.Context;
import android.util.Log; import android.util.Log;
import android.view.View; import android.view.View;
@ -29,6 +30,9 @@ public class StaggerAdapter extends RecyclerView.Adapter<StaggerAdapter.InnerHol
protected final ArrayList<Good> mData; protected final ArrayList<Good> mData;
private RecyclerView mList; private RecyclerView mList;
Context context; Context context;
private OnItemClickListener mOnItemClickListener;
public StaggerAdapter(ArrayList<Good> mData, Context context) { public StaggerAdapter(ArrayList<Good> mData, Context context) {
Log.d("TAG", "StaggerAdapter: "); Log.d("TAG", "StaggerAdapter: ");
@ -44,7 +48,6 @@ public class StaggerAdapter extends RecyclerView.Adapter<StaggerAdapter.InnerHol
@NonNull @NonNull
@Override @Override
public InnerHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { public InnerHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
Log.d("TAG", "onCreateViewHolder: ");
//传入这个view是item的界面 //传入这个view是item的界面
View view = View.inflate(parent.getContext(), R.layout.item_stagger, null); View view = View.inflate(parent.getContext(), R.layout.item_stagger, null);
//创建InnerHolder //创建InnerHolder
@ -54,17 +57,19 @@ public class StaggerAdapter extends RecyclerView.Adapter<StaggerAdapter.InnerHol
//绑定holder一般用来设置数据 //绑定holder一般用来设置数据
@Override @Override
public void onBindViewHolder(@NonNull InnerHolder holder, int position) { public void onBindViewHolder(@NonNull InnerHolder holder, int position) {
String strTvTitle; String strTvTitle;
String strTvCount; String strTvCount;
String imageUrl; String imageUrl;
holder.setmPosition(position);
if (mData.get(position) != null){ if (mData.get(position) != null){
strTvTitle = mData.get(position).getContent(); strTvTitle = mData.get(position).getContent();
strTvCount = mData.get(position).getPrice().toString(); strTvCount = mData.get(position).getPrice().toString();
imageUrl = (String) mData.get(position).getImageUrlList().get(0); imageUrl = (String) mData.get(position).getImageUrlList().get(0);
Log.d("TAG", "Title:"+strTvTitle);
Log.d("TAG", "Count:"+strTvCount);
Log.e("imageUrl", (String) mData.get(position).getImageUrlList().get(0));
holder.getTvTitle().setText(strTvTitle); holder.getTvTitle().setText(strTvTitle);
holder.getTvCount().setText(strTvCount); holder.getTvCount().setText(strTvCount);
@ -82,8 +87,21 @@ public class StaggerAdapter extends RecyclerView.Adapter<StaggerAdapter.InnerHol
return 0; return 0;
} }
//用于监听
public void setOnItemClickListener(OnItemClickListener listener) {
//设置一个监听,一个回调的接口
this.mOnItemClickListener = listener;
}
public interface OnItemClickListener{
//条目
void onItemClick(int position);
}
public class InnerHolder extends RecyclerView.ViewHolder { public class InnerHolder extends RecyclerView.ViewHolder {
private int mPosition;
private final ImageView mImage; private final ImageView mImage;
private final TextView mContent; private final TextView mContent;
private final TextView mPrice; private final TextView mPrice;
@ -96,24 +114,33 @@ public class StaggerAdapter extends RecyclerView.Adapter<StaggerAdapter.InnerHol
mContent = itemView.findViewById(R.id.tv_content); mContent = itemView.findViewById(R.id.tv_content);
mPrice = itemView.findViewById(R.id.tv_price); mPrice = itemView.findViewById(R.id.tv_price);
itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//监听
if (mOnItemClickListener != null) {
mOnItemClickListener.onItemClick(mPosition);
} }
public void setData(Good good) { }
//开始设置数据 });
mContent.setText(good.getContent());
mPrice.setText(good.getPrice());
} }
public TextView getTvTitle() { public TextView getTvTitle() {
return mContent; return mContent;
} }
public TextView getTvCount() { public TextView getTvCount() {
return mPrice; return mPrice;
} }
public ImageView getIvGoods() { public ImageView getIvGoods() {
return mImage; return mImage;
} }
public void setmPosition(int position){
this.mPosition=position;
}
} }
// //实现瀑布流效果 // //实现瀑布流效果
// private void showStagger() { // private void showStagger() {

@ -1,5 +1,6 @@
package com.android.activity.fragment; package com.android.activity.fragment;
import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
@ -14,11 +15,15 @@ import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast;
import com.android.R; import com.android.R;
import com.android.activity.GoodsDetailsActivity;
import com.android.activity.adapter.GoodsAdapter; import com.android.activity.adapter.GoodsAdapter;
import com.android.activity.adapter.StaggerAdapter; import com.android.activity.adapter.StaggerAdapter;
import com.android.bean.Good; import com.android.bean.Good;
import com.android.bean.ResponseData;
import com.android.bean.User;
import com.android.utils.eventBus.EventMsg; import com.android.utils.eventBus.EventMsg;
import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.EventBus;
@ -41,11 +46,10 @@ public class GoodsTypeFragment extends Fragment {
private static final String ARG_TEXT = "param1"; private static final String ARG_TEXT = "param1";
private static final String ARG_GOODS = "goodsTypeList"; private static final String ARG_GOODS = "goodsTypeList";
private ArrayList<Good> goodArrayList; private ArrayList<Good> goodArrayList;
private EventMsg<Good> eventMsg;
private ArrayList<Good> typeGoodList; private ArrayList<Good> typeGoodList;
private RecyclerView recyclerView; private RecyclerView recyclerView;
private StaggerAdapter goodsAdapter; private StaggerAdapter staggerAdapter;
// private GoodsAdapter goodsAdapter; private User user;
View rootView; View rootView;
@ -100,11 +104,7 @@ public class GoodsTypeFragment extends Fragment {
recyclerView = rootView.findViewById(R.id.rl_goods_show); recyclerView = rootView.findViewById(R.id.rl_goods_show);
if (goodArrayList != null){ if (goodArrayList != null){
Log.d("TAG", "initView"); staggerAdapter = new StaggerAdapter(typeGoodList,getContext());
goodsAdapter = new StaggerAdapter(typeGoodList,getContext());
// goodsAdapter = new GoodsAdapter(typeGoodList,getContext());
// recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
// recyclerView.setAdapter(goodsAdapter);
//准备布局管理器 //准备布局管理器
StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(2,StaggeredGridLayoutManager.VERTICAL); StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(2,StaggeredGridLayoutManager.VERTICAL);
//设置布局管理器的方向 //设置布局管理器的方向
@ -112,18 +112,35 @@ public class GoodsTypeFragment extends Fragment {
//设置布局管理器到RecyclerView中 //设置布局管理器到RecyclerView中
recyclerView.setLayoutManager(layoutManager); recyclerView.setLayoutManager(layoutManager);
//设置适配器 //设置适配器
recyclerView.setAdapter(goodsAdapter); recyclerView.setAdapter(staggerAdapter);
//设置监听事件
initListener();
} }
// TextView view = rootView.findViewById(R.id.tv_goods);
// view.setText(goodArrayList.get(1).getUsername());
} }
private void initListener() {
staggerAdapter.setOnItemClickListener(new StaggerAdapter.OnItemClickListener() {
@Override
public void onItemClick(int position) {
//监听的各种操作写在这里
Toast.makeText(getActivity(), "我点击了第"+position+"item", Toast.LENGTH_SHORT).show();
Good goods = typeGoodList.get(position);
//Eventbus发生事件
EventBus.getDefault().postSticky(goods);
//intent跳转
Intent intent = new Intent(getActivity(), GoodsDetailsActivity.class);
startActivity(intent);
}
});
}
@Override @Override
public void onStart() { public void onStart() {
EventBus.getDefault().register(this);
super.onStart(); super.onStart();
@ -143,11 +160,4 @@ public class GoodsTypeFragment extends Fragment {
super.onDestroy(); super.onDestroy();
} }
@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());
}
} }

@ -21,6 +21,7 @@ import com.android.bean.Good;
import com.android.bean.GoodRecords; import com.android.bean.GoodRecords;
import com.android.bean.GoodsType; import com.android.bean.GoodsType;
import com.android.bean.ResponseData; import com.android.bean.ResponseData;
import com.android.bean.User;
import com.android.model.goods.GoodsListener; import com.android.model.goods.GoodsListener;
import com.android.model.goods.GoodsModelimpl; import com.android.model.goods.GoodsModelimpl;
import com.android.utils.eventBus.EventMsg; import com.android.utils.eventBus.EventMsg;
@ -28,6 +29,8 @@ import com.google.android.material.tabs.TabLayout;
import com.google.android.material.tabs.TabLayoutMediator; import com.google.android.material.tabs.TabLayoutMediator;
import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -45,6 +48,7 @@ public class HomePageFragment extends Fragment implements View.OnClickListener,
private List<Good> goodList; private List<Good> goodList;
private View rootView; private View rootView;
private GoodsTypeFSAdapter goodsTypeFSAdapter; private GoodsTypeFSAdapter goodsTypeFSAdapter;
private User user;
private ViewPager2 viewPager; private ViewPager2 viewPager;
@ -59,10 +63,16 @@ public class HomePageFragment extends Fragment implements View.OnClickListener,
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
EventBus.getDefault().register(this);
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
} }
@Override
public void onStop() {
EventBus.getDefault().unregister(this);
super.onStop();
}
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,
@ -76,7 +86,12 @@ public class HomePageFragment extends Fragment implements View.OnClickListener,
} }
private void initGoodsTypeData() { private void initGoodsTypeData() {
if (user != null){
goodsModelimpl = new GoodsModelimpl(user);
}else {
goodsModelimpl = new GoodsModelimpl(); goodsModelimpl = new GoodsModelimpl();
}
goodsModelimpl.getAllGood(this); goodsModelimpl.getAllGood(this);
goodsModelimpl.getAllGoodsType(this); goodsModelimpl.getAllGoodsType(this);
new Handler().postDelayed(new Runnable() { new Handler().postDelayed(new Runnable() {
@ -113,8 +128,6 @@ public class HomePageFragment extends Fragment implements View.OnClickListener,
fragments.add(GoodsTypeFragment.newInstance(goodsTypeList.get(i).getId(), goodList)); fragments.add(GoodsTypeFragment.newInstance(goodsTypeList.get(i).getId(), goodList));
//EventBus发布消息
// EventBus.getDefault().postSticky(new EventMsg<>(goodsTypeList.get(i).getType(),200,goodList));
} }
goodsTypeFSAdapter = new GoodsTypeFSAdapter(getActivity().getSupportFragmentManager(), getLifecycle(),fragments); goodsTypeFSAdapter = new GoodsTypeFSAdapter(getActivity().getSupportFragmentManager(), getLifecycle(),fragments);
@ -126,8 +139,15 @@ public class HomePageFragment extends Fragment implements View.OnClickListener,
} }
@Override @Override
public void onClick(View v) { public void onClick(View v) {
} }
@Subscribe(threadMode = ThreadMode.POSTING,sticky = true)
public void getLoginUser(ResponseData<User> responseData){
this.user = responseData.getData();
}
} }

@ -4,11 +4,19 @@ import android.os.Bundle;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.TextView;
import com.android.R; import com.android.R;
import com.android.bean.ResponseData;
import com.android.bean.User;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
/** /**
* A simple {@link Fragment} subclass. * A simple {@link Fragment} subclass.
@ -16,6 +24,9 @@ import com.android.R;
* create an instance of this fragment. * create an instance of this fragment.
*/ */
public class MyPageFragment extends Fragment { public class MyPageFragment extends Fragment {
private View rootView;
private TextView textView;
private ResponseData<User> userResponseData;
// TODO: Rename parameter arguments, choose names that match // TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
@ -30,6 +41,20 @@ public class MyPageFragment extends Fragment {
// Required empty public constructor // Required empty public constructor
} }
@Override
public void onStart() {
super.onStart();
}
@Override
public void onStop() {
super.onStop();
}
/** /**
* Use this factory method to create a new instance of * Use this factory method to create a new instance of
* this fragment using the provided parameters. * this fragment using the provided parameters.
@ -48,9 +73,22 @@ public class MyPageFragment extends Fragment {
return fragment; return fragment;
} }
@Override
public void onDestroy() {
if (!EventBus.getDefault().isRegistered(this)) {
EventBus.getDefault().register(this);
}
super.onDestroy();
}
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
if (!EventBus.getDefault().isRegistered(this)) {
EventBus.getDefault().register(this);
}
if (getArguments() != null) { if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1); mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2); mParam2 = getArguments().getString(ARG_PARAM2);
@ -61,6 +99,16 @@ public class MyPageFragment extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {
// Inflate the layout for this fragment // Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_my_page, container, false);
rootView = inflater.inflate(R.layout.fragment_my_page, container, false);
textView = rootView.findViewById(R.id.tv_my);
return rootView;
} }
@Subscribe(threadMode = ThreadMode.POSTING,sticky = true)
public void getLoginUser(ResponseData<User> responseData){
this.userResponseData = responseData;
}
} }

@ -13,19 +13,23 @@ import lombok.NoArgsConstructor;
public class User implements Serializable { public class User implements Serializable {
@SerializedName("id") @SerializedName("id")
private Integer id; private Long id;
@SerializedName("username")
private String userName; private String userName;
private String code; private String code;
private String phone; private String phone;
@SerializedName("avatar")
private String avatar; private String avatar;
@SerializedName("appKey")
private String appKey; private String appKey;
@SerializedName("money")
private Integer money; private Integer money;
public Integer getId() { public Long getId() {
return id; return id;
} }
public void setId(Integer id) { public void setId(Long id) {
this.id = id; this.id = id;
} }

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

@ -1,5 +1,6 @@
package com.android.model.goods; package com.android.model.goods;
import android.net.Uri;
import android.util.ArrayMap; import android.util.ArrayMap;
import android.util.Log; import android.util.Log;
@ -7,6 +8,7 @@ import com.android.bean.Good;
import com.android.bean.GoodRecords; import com.android.bean.GoodRecords;
import com.android.bean.GoodsType; import com.android.bean.GoodsType;
import com.android.bean.ResponseData; import com.android.bean.ResponseData;
import com.android.bean.User;
import com.android.model.login.LoginListener; import com.android.model.login.LoginListener;
import java.util.List; import java.util.List;
@ -23,9 +25,16 @@ import retrofit2.adapter.rxjava3.RxJava3CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory; import retrofit2.converter.gson.GsonConverterFactory;
public class GoodsModelimpl implements GoodsModel{ public class GoodsModelimpl implements GoodsModel{
private User user;
private String TAG ="GoodsModelimpl"; private String TAG ="GoodsModelimpl";
public GoodsModelimpl(User user) {
this.user = user;
}
public GoodsModelimpl() {
}
@Override @Override
public void getAllGoodsType(GoodsListener goodsListener) { public void getAllGoodsType(GoodsListener goodsListener) {
@ -50,7 +59,6 @@ public class GoodsModelimpl implements GoodsModel{
@Override @Override
public void onNext(@NonNull ResponseData<List<GoodsType>> listResponseData) { public void onNext(@NonNull ResponseData<List<GoodsType>> listResponseData) {
Log.e(TAG,listResponseData.getMsg());
goodsListener.onGetAllGoodsType(listResponseData); goodsListener.onGetAllGoodsType(listResponseData);
} }
@ -77,8 +85,10 @@ public class GoodsModelimpl implements GoodsModel{
retrofit.create(GoodsHttp_interface.class); retrofit.create(GoodsHttp_interface.class);
Map<String, Object> map = new ArrayMap<>(); Map<String, Object> map = new ArrayMap<>();
Observable<ResponseData<GoodRecords>> observable Observable<ResponseData<GoodRecords>> observable
= httpInterface.sendGetAllGood(17, map); = httpInterface.sendGetAllGood(6l, map);
observable.subscribeOn(Schedulers.io()) observable.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
@ -91,7 +101,6 @@ public class GoodsModelimpl implements GoodsModel{
@Override @Override
public void onNext(@NonNull ResponseData<GoodRecords> listResponseData) { public void onNext(@NonNull ResponseData<GoodRecords> listResponseData) {
goodsListener.onGetAllGoodSuccess(listResponseData); goodsListener.onGetAllGoodSuccess(listResponseData);
Log.e("1111",listResponseData.getData().getRecords().get(1).getUsername());
} }
@Override @Override

@ -37,8 +37,6 @@ public class LoginModelImpl implements LoginModel{
User user = new User(); User user = new User();
user.setCode(phoneCode); user.setCode(phoneCode);
user.setPhone(account); user.setPhone(account);
Log.e("TAG",phoneCode);
Log.e("TAG",account);
Observable<ResponseData<User>> observable = request.login(user); Observable<ResponseData<User>> observable = request.login(user);
observable observable
@ -53,6 +51,7 @@ public class LoginModelImpl implements LoginModel{
@Override @Override
public void onNext(@NonNull ResponseData<User> userResponseData) { public void onNext(@NonNull ResponseData<User> userResponseData) {
loginListener.onLoginSuccess(userResponseData); loginListener.onLoginSuccess(userResponseData);
Log.e("login",userResponseData.getMsg());
} }
@Override @Override

@ -1,6 +1,6 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" <vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp" android:width="8dp"
android:height="24dp" android:height="8dp"
android:viewportWidth="24" android:viewportWidth="24"
android:viewportHeight="24" android:viewportHeight="24"
android:tint="?attr/colorControlNormal"> android:tint="?attr/colorControlNormal">

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activity.GoodsDetailsActivity">
<TextView
android:id="@+id/tv_goods_show"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="商品详细页面"
android:gravity="center"
tools:ignore="MissingConstraints" />
</androidx.constraintlayout.widget.ConstraintLayout>

@ -12,6 +12,7 @@
android:id="@+id/fragment_container" android:id="@+id/fragment_container"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_marginBottom="50dp"
app:layout_constraintBottom_toTopOf="@id/bottom_navigation" app:layout_constraintBottom_toTopOf="@id/bottom_navigation"
/> />

@ -43,7 +43,8 @@
<com.google.android.material.textfield.TextInputEditText <com.google.android.material.textfield.TextInputEditText
android:id="@+id/et_acc" android:id="@+id/et_acc"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" /> android:layout_height="wrap_content"
android:text="14777361004"/>
</com.google.android.material.textfield.TextInputLayout> </com.google.android.material.textfield.TextInputLayout>
<RelativeLayout <RelativeLayout

@ -7,6 +7,7 @@
<!-- TODO: Update blank fragment layout --> <!-- TODO: Update blank fragment layout -->
<TextView <TextView
android:id="@+id/tv_my"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:text="my" /> android:text="my" />

@ -1,39 +1,64 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView <androidx.cardview.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="20dp" xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content"
android:padding="8dp"
app:cardCornerRadius="8dp"
app:cardUseCompatPadding="true"
>
<RelativeLayout <RelativeLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_marginRight="5dp" android:layout_height="wrap_content"
android:layout_height="wrap_content"> android:background="#68E3CC9F"
>
<ImageView <ImageView
android:id="@+id/iv_goods" android:id="@+id/iv_goods"
android:layout_width="120dp" android:layout_width="match_parent"
android:layout_height="90dp" android:layout_height="128dp"
android:scaleType="centerCrop"
> >
</ImageView> </ImageView>
<TextView <TextView
android:id="@+id/tv_title" android:id="@+id/tv_title"
android:layout_width="wrap_content" style="@style/TextAppearance.AppCompat.Subhead"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_below="@+id/iv_goods" android:layout_below="@id/iv_goods"
android:paddingTop="8dp"
android:paddingLeft="16dp"
android:paddingBottom="4dp"
android:textColor="#E64A19"
android:textSize="18sp"
android:textStyle="bold"
android:text="手机" android:text="手机"
android:textSize="20dp" >
android:layout_marginTop="10dp">
</TextView> </TextView>
<TextView
android:id="@+id/tv_subtitle"
style="@style/TextAppearance.AppCompat.Subhead"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/tv_title"
android:paddingLeft="8dp"
android:paddingBottom="4dp"
android:text="描述"
android:textColor="@android:color/secondary_text_light" />
<TextView <TextView
android:id="@+id/tv_price" android:id="@+id/tv_price"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_below="@id/tv_title" android:layout_below="@id/tv_subtitle"
android:layout_marginTop="8dp"
android:text="价格: " android:text="价格: "
android:textSize="15dp"
android:textColor="#FF8F03" android:textColor="#FF8F03"
android:layout_marginTop="15dp"> android:textSize="15dp"></TextView>
</TextView>
<TextView <TextView
android:id="@+id/tv_count" android:id="@+id/tv_count"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -44,11 +69,17 @@
android:text="1000" android:text="1000"
android:textColor="#FF8F03"> android:textColor="#FF8F03">
</TextView> </TextView>
<!-- <Button-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content">-->
<!-- </Button>--> <Button
android:id="@+id/bt_add_car"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/tv_title"
android:layout_marginStart="306dp"
android:background="@drawable/add_shopping_cart_24"
android:clickable="true">
</Button>
</RelativeLayout> </RelativeLayout>

@ -1,8 +1,13 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <androidx.cardview.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@color/grey"> app:cardUseCompatPadding="true"
app:cardCornerRadius="10dp"
xmlns:app="http://schemas.android.com/apk/res-auto">
<RelativeLayout <RelativeLayout
android:layout_width="200dp" android:layout_width="200dp"
@ -13,6 +18,7 @@
android:layout_marginBottom="15dp" android:layout_marginBottom="15dp"
android:background="@color/white"> android:background="@color/white">
<ImageView <ImageView
android:id="@+id/iv_image" android:id="@+id/iv_image"
android:layout_width="200dp" android:layout_width="200dp"
@ -24,29 +30,60 @@
android:layout_width="180dp" android:layout_width="180dp"
android:layout_height="25dp" android:layout_height="25dp"
android:layout_below="@+id/iv_image" android:layout_below="@+id/iv_image"
android:layout_marginStart="13dp"
android:layout_marginTop="10dp" android:layout_marginTop="10dp"
android:layout_marginEnd="20dp" android:layout_marginEnd="20dp"
android:layout_marginBottom="15dp" android:layout_marginBottom="15dp"
android:textSize="20dp" /> android:textSize="20dp" />
<TextView <TextView
android:id="@+id/str" android:id="@+id/tv_price"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="18dp"
android:layout_below="@+id/tv_content" android:layout_below="@+id/tv_content"
android:layout_alignLeft="@+id/tv_content"
android:text="价格: "
android:textColor="@color/red" /> android:textColor="@color/red" />
<TextView <TextView
android:id="@+id/tv_price" android:id="@+id/str"
android:layout_width="100dp" android:layout_width="wrap_content"
android:layout_height="18dp" android:layout_height="wrap_content"
android:layout_below="@+id/tv_content" android:layout_below="@+id/tv_content"
android:layout_toRightOf="@+id/str" android:layout_toRightOf="@+id/tv_price"
android:text="@string/moneyType"
android:textColor="@color/red" /> android:textColor="@color/red" />
<Button
android:id="@+id/elevatedButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="加入购物车"
style="Filled button"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginEnd="32dp"
/>
<!-- <Button-->
<!-- android:id="@+id/bt_buy_now"-->
<!-- android:layout_width="64dp"-->
<!-- android:layout_height="32dp"-->
<!-- android:text="立即购买"-->
<!-- android:textColor="@color/teal_200"-->
<!-- android:backgroundTint="@color/grey"-->
<!-- android:layout_below="@id/tv_content"-->
<!-- android:layout_marginStart="132dp"-->
<!-- />-->
<!-- <Button-->
<!-- android:id="@+id/bt_add_to_cars"-->
<!-- android:layout_width="64dp"-->
<!-- android:layout_height="32dp"-->
<!-- android:text="加入购物车"-->
<!-- android:textColor="@color/teal_200"-->
<!-- android:backgroundTint="@color/grey"-->
<!-- android:layout_below="@id/tv_content"-->
<!-- android:layout_marginStart="64dp"-->
<!-- />-->
<!-- <TextView--> <!-- <TextView-->
<!-- android:id="@+id/iv_delete"--> <!-- android:id="@+id/iv_delete"-->
@ -58,4 +95,6 @@
</RelativeLayout> </RelativeLayout>
</RelativeLayout>
</androidx.cardview.widget.CardView>

@ -2,5 +2,6 @@
<string name="app_name">Android_Couser_Design</string> <string name="app_name">Android_Couser_Design</string>
<!-- TODO: Remove or change this placeholder text --> <!-- TODO: Remove or change this placeholder text -->
<string name="hello_blank_fragment">Hello blank fragment</string> <string name="hello_blank_fragment">Hello blank fragment</string>
<string name="moneyType"></string>
</resources> </resources>
Loading…
Cancel
Save