This commit is contained in:
ybb 2024-06-20 02:00:28 +08:00
parent ef37b4be25
commit 8597dbf676
12 changed files with 139 additions and 136 deletions

View File

@ -80,4 +80,6 @@ dependencies {
implementation ("com.baidu.lbsyun:BaiduMapSDK_Location:9.3.7")
implementation ("com.guolindev.permissionx:permissionx:1.7.1")
// ViewPager2
}

View File

@ -2,7 +2,10 @@ package com.hnucm.c202201020337;
//商品选择页面商品详情选择口味加入购物车或者直接购买
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
public class GoodsActivity extends AppCompatActivity {
@ -10,5 +13,16 @@ public class GoodsActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_goods);
ImageView imageView37 = findViewById(R.id.imageView37);
imageView37.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(GoodsActivity.this, MainActivity.class);
intent.putExtra("fragmentToLoad", "OrderingFragment"); // 设置要加载的Fragment为OrderingFragment
startActivity(intent);
finish(); // 关闭当前的StoreActivity
}
});
}
}

View File

@ -1,7 +1,9 @@
package com.hnucm.c202201020337;
//main3
import android.content.Intent;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.cardview.widget.CardView;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
@ -16,127 +18,51 @@ import java.util.List;
public class IndentFragment extends Fragment {
private RecyclerView recyclerViewIndent1;
private MyAdapter_indent1 myAdapterIndent1;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_indent, container, false);
recyclerViewIndent1 = view.findViewById(R.id.indent1_recyclerview);
recyclerViewIndent1.setLayoutManager(new LinearLayoutManager(getActivity()));
// 假设有一些示例数据
List<IndentItem> indentItems = new ArrayList<>();
indentItems.add(new IndentItem("自提", "蜜雪冰城(湖中大内店)", "已完成", "2004-06-02 20:15-10", "1", "10", R.drawable.goods2));
indentItems.add(new IndentItem("外送", "星巴克(湖中大外店)", "已完成", "2004-06-03 21:15-10", "2", "20", R.drawable.goods2));
myAdapterIndent1 = new MyAdapter_indent1(indentItems);
recyclerViewIndent1.setAdapter(myAdapterIndent1);
RecyclerView recyclerView = view.findViewById(R.id.indent1_recyclerview);
MyAdapter_indent myAdapterIndent = new MyAdapter_indent();
recyclerView.setAdapter(myAdapterIndent);
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
return view;
}
public class MyViewHolder_indent1 extends RecyclerView.ViewHolder {
TextView type;
TextView storeName;
TextView status;
TextView dateTime;
TextView quantity;
TextView price;
ImageView productImage;
public MyViewHolder_indent1(@NonNull View itemView) {
public class MyViewHolder_indent extends RecyclerView.ViewHolder{
TextView name;
public MyViewHolder_indent(@NonNull View itemView) {
super(itemView);
type = itemView.findViewById(R.id.textView20);
storeName = itemView.findViewById(R.id.textView21);
status = itemView.findViewById(R.id.textView22);
dateTime = itemView.findViewById(R.id.textView23);
quantity = itemView.findViewById(R.id.textView25);
price = itemView.findViewById(R.id.textView24);
productImage = itemView.findViewById(R.id.imageView9);
name = itemView.findViewById(R.id.textView21);
}
}
public class MyAdapter_indent1 extends RecyclerView.Adapter<MyViewHolder_indent1> {
private List<IndentItem> indentItems;
public MyAdapter_indent1(List<IndentItem> indentItems) {
this.indentItems = indentItems;
}
public class MyAdapter_indent extends RecyclerView.Adapter<MyViewHolder_indent>{
@NonNull
@Override
public MyViewHolder_indent1 onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
public MyViewHolder_indent onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(getActivity())
.inflate(R.layout.indend_card,parent,false);
return new MyViewHolder_indent1(view);
return new MyViewHolder_indent(view);
}
@Override
public void onBindViewHolder(@NonNull MyViewHolder_indent1 holder, int position) {
IndentItem item = indentItems.get(position);
holder.type.setText(item.getType());
holder.storeName.setText(item.getStoreName());
holder.status.setText(item.getStatus());
holder.dateTime.setText(item.getDateTime());
holder.quantity.setText("" + item.getQuantity() + "");
holder.price.setText("" + item.getPrice());
holder.productImage.setImageResource(item.getImageResource());
public void onBindViewHolder(@NonNull MyViewHolder_indent holder, int position) {
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// 创建 Intent 实例从当前 Fragment 跳转到 OrdersActivity
Intent intent = new Intent(getActivity(), OrdersActivity.class);
startActivity(intent);
}
});
}
@Override
public int getItemCount() {
return indentItems.size();
return 10;
}
}
public class IndentItem {
private String type;
private String storeName;
private String status;
private String dateTime;
private String quantity;
private String price;
private int imageResource;
public IndentItem(String type, String storeName, String status, String dateTime, String quantity, String price, int imageResource) {
this.type = type;
this.storeName = storeName;
this.status = status;
this.dateTime = dateTime;
this.quantity = quantity;
this.price = price;
this.imageResource = imageResource;
}
public String getType() {
return type;
}
public String getStoreName() {
return storeName;
}
public String getStatus() {
return status;
}
public String getDateTime() {
return dateTime;
}
public String getQuantity() {
return quantity;
}
public String getPrice() {
return price;
}
public int getImageResource() {
return imageResource;
}
}
}

View File

@ -1,5 +1,6 @@
package com.hnucm.c202201020337;
//订单已完成的Fragment
import android.content.Intent;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
@ -7,6 +8,7 @@ import androidx.fragment.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
public class IndentOkFragment extends Fragment {
@ -14,6 +16,20 @@ public class IndentOkFragment extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_indent_ok, container, false);
View view = inflater.inflate(R.layout.fragment_indent_ok, container, false);
ImageView imageView33 = view.findViewById(R.id.imageView33);
imageView33.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getActivity(), MainActivity.class);
intent.putExtra("fragmentToLoad", "IndentFragment");
startActivity(intent);
getActivity().finish();
}
});
return view;
}
}

View File

@ -80,7 +80,7 @@ public class MainActivity extends AppCompatActivity {
}
});
// 处理从StoreActivity返回的Intent
// 返回mainAC
String fragmentToLoad = getIntent().getStringExtra("fragmentToLoad");
if (fragmentToLoad != null) {
switch (fragmentToLoad) {
@ -92,14 +92,33 @@ public class MainActivity extends AppCompatActivity {
.hide(myFragment)
.commit();
break;
default: // 默认情况下显示HomeFragment假设这是初始状态
case "IndentFragment":
getSupportFragmentManager().beginTransaction()
.hide(orderingFragment) // 显示OrderingFragment
.hide(homeFragment)
.show(indentFragment)
.hide(myFragment)
.commit();
break;
case "MyFragment":
getSupportFragmentManager().beginTransaction()
.hide(orderingFragment) // 显示OrderingFragment
.hide(homeFragment)
.hide(indentFragment)
.show(myFragment)
.commit();
break;
case "HomeFragment":
getSupportFragmentManager().beginTransaction()
.hide(orderingFragment) // 显示OrderingFragment
.show(homeFragment)
.hide(orderingFragment)
.hide(indentFragment)
.hide(myFragment)
.commit();
break;
}
}
}

View File

@ -11,6 +11,7 @@ import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.TextView;
@ -37,7 +38,7 @@ public class OrderingFragment extends Fragment {
recyclerView2.setAdapter(myAdapterOrder2);
recyclerView2.setLayoutManager(new LinearLayoutManager(getActivity()));
//跳转到StoreActivity
//点击-跳转到StoreActivity
TextView textView7 = view.findViewById(R.id.textView7);
textView7.setOnClickListener(new View.OnClickListener() {
@Override
@ -99,7 +100,6 @@ public class OrderingFragment extends Fragment {
}
public class MyAdapter_order2 extends RecyclerView.Adapter<MyViewHolder_order2> {
@NonNull
@Override
public MyViewHolder_order2 onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
@ -110,15 +110,22 @@ public class OrderingFragment extends Fragment {
@Override
public void onBindViewHolder(@NonNull MyViewHolder_order2 holder, int position) {
// holder.goodsImage.setImageResource(R.drawable.goods1);
// holder.goodsName.setText("冰新柠檬水");
// holder.goodsDescription.setText("大片柠檬看得见,现切现搅超新鲜");
// holder.goodsPrice.setText("¥4起");
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// 创建 Intent 实例从当前 Fragment 跳转到 GoodsActivity
Intent intent = new Intent(getActivity(), GoodsActivity.class);
startActivity(intent);
}
});
}
@Override
public int getItemCount() {
return 20; // 假设有10个商品
return 20;
}
}
}

View File

@ -1,5 +1,5 @@
package com.hnucm.c202201020337;
//订单详情页,查看历史订单
//订单详情页
import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.widget.ConstraintLayout;
@ -19,15 +19,6 @@ public class OrdersActivity extends AppCompatActivity {
//布局换Fragment
getSupportFragmentManager().beginTransaction().add(R.id.orders_layout,indentOkFragment).commit();
//返回
ImageView imageView1 = findViewById(R.id.imageView33);
imageView1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(OrdersActivity.this,MainActivity.class);
startActivity(intent);
}
});
}
}

View File

@ -14,14 +14,25 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:id="@+id/imageView12"
android:layout_width="300dp"
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/viewPager2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/home_ap1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.tabs.TabLayout
android:id="@+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="@id/viewPager2"
app:layout_constraintEnd_toEndOf="@id/viewPager2"
app:layout_constraintStart_toStartOf="@id/viewPager2"
app:tabIndicatorFullWidth="false"
app:tabMode="fixed" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.cardview.widget.CardView

View File

@ -0,0 +1,14 @@
<?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"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY" />
</LinearLayout>

View File

@ -24,16 +24,6 @@
app:layout_constraintEnd_toEndOf="parent"
app:srcCompat="@drawable/xuebao" />
<ImageView
android:id="@+id/imageView33"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:src="@drawable/arrow2"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/textView88"
android:layout_width="wrap_content"
@ -63,6 +53,16 @@
app:layout_constraintBottom_toBottomOf="@+id/imageView33"
app:layout_constraintEnd_toStartOf="@+id/imageView28"
app:layout_constraintTop_toTopOf="@+id/imageView33" />
<ImageView
android:id="@+id/imageView33"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:src="@drawable/arrow2"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.cardview.widget.CardView

View File

@ -6,6 +6,7 @@
android:layout_height="180dp">
<androidx.cardview.widget.CardView
android:id="@+id/ind_cardview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="10dp"
@ -20,6 +21,7 @@
app:layout_constraintTop_toTopOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/ind_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">

View File

@ -6,6 +6,7 @@
android:layout_height="120dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/order_card_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="8dp"