diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index e5b0221..76883ff 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -22,6 +22,7 @@ android:theme="@style/Theme.Huangrui" android:usesCleartextTraffic="true" tools:targetApi="31"> + @@ -151,8 +152,12 @@ android:name=".Login" android:exported="false" /> + android:name=".Carbon" + android:exported="false" + /> + diff --git a/app/src/main/java/com/hnucm/c25/Carbon.java b/app/src/main/java/com/hnucm/c25/Carbon.java new file mode 100644 index 0000000..b5499b6 --- /dev/null +++ b/app/src/main/java/com/hnucm/c25/Carbon.java @@ -0,0 +1,14 @@ +package com.hnucm.c25; + +import androidx.appcompat.app.AppCompatActivity; + +import android.os.Bundle; + +public class Carbon extends AppCompatActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_carbon); + } +} \ No newline at end of file diff --git a/app/src/main/java/com/hnucm/c25/KaiFaPiao.java b/app/src/main/java/com/hnucm/c25/KaiFaPiao.java index 57bb278..f3b9f0c 100644 --- a/app/src/main/java/com/hnucm/c25/KaiFaPiao.java +++ b/app/src/main/java/com/hnucm/c25/KaiFaPiao.java @@ -8,18 +8,36 @@ import androidx.recyclerview.widget.RecyclerView; import android.content.Intent; import android.os.Bundle; +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 com.google.gson.Gson; + +import java.io.IOException; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Locale; +import java.util.Set; + +import okhttp3.Call; +import okhttp3.Callback; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Response; public class KaiFaPiao extends AppCompatActivity { RecyclerView recyclerView ; MyAdapter myAdapter ; + List history_items = new ArrayList<>(); + TextView fapiao; + TextView money; + Set selectedItems = new HashSet<>(); + ImageView allSelect ; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -28,6 +46,9 @@ public class KaiFaPiao extends AppCompatActivity { myAdapter = new MyAdapter(); recyclerView.setAdapter(myAdapter); recyclerView.setLayoutManager(new LinearLayoutManager(this)); + fapiao = findViewById(R.id.textView75); + money=findViewById(R.id.textView76); + allSelect=findViewById(R.id.imageView96); //todo 返回我的 ImageView back = findViewById(R.id.imageView92); back.setOnClickListener(new View.OnClickListener() { @@ -37,12 +58,90 @@ public class KaiFaPiao extends AppCompatActivity { startActivity(intent); } }); + //todo 全选 + allSelect.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + toggleSelectAll(!selectedItems.isEmpty()); + } + }); + Request request = new Request.Builder() + .url("https://test04.usemock.com/takeHistory") + .get() + .build(); + OkHttpClient okHttpClient = new OkHttpClient(); + Call call = okHttpClient.newCall(request); + //创建了一个线程 + call.enqueue(new Callback() { + @Override + public void onFailure(@NonNull Call call, @NonNull IOException e) { + //请求失败 + } + @Override + public void onResponse(@NonNull Call call, @NonNull Response response) throws IOException { + //请求成功 + String result = response.body().string(); + Log.i("test",result); + + + //所有对于UI控件的操作行为放在主线程中 解决方法:切换到主线程 + runOnUiThread(new Runnable() { + @Override + public void run() { + try { + Gson gson = new Gson(); + history_item historyItem = gson.fromJson(result,history_item.class); + history_items.addAll(historyItem.takeHistory); // 将解析的数据添加到列表中 + myAdapter.notifyDataSetChanged(); + + } catch (Exception e) { + throw new RuntimeException(e); + } + + + } + }); + } + }); } + public void toggleSelectAll(boolean isSelected) { + if (isSelected&&selectedItems.size()==history_items.size()) { + // 如果当前状态是全选,则清空selectedItems + selectedItems.clear(); + fapiao.setSelected(false); + } else { + // 如果当前状态不是全选,则添加所有项到selectedItems + for (int i = 0; i < history_items.size(); i++) { + selectedItems.add(i); + } + fapiao.setSelected(true); + } + myAdapter.notifyDataSetChanged(); + myAdapter.calculateTotalAmount(); + } public class MyViewHolder extends RecyclerView.ViewHolder { - + ImageView select ; + TextView startTextView; + TextView endTextView; + TextView timeTextView; + TextView moneyTextView; + ImageView enterImage; + ImageView endImage; + ConstraintLayout history; public MyViewHolder(@NonNull View itemView) { super(itemView); + select=itemView.findViewById(R.id.imageView94); + startTextView = itemView.findViewById(R.id.startTextView); + endTextView = itemView.findViewById(R.id.endTextView); + timeTextView = itemView.findViewById(R.id.timeTextView); + moneyTextView = itemView.findViewById(R.id.moneyTextView); + endImage = itemView.findViewById(R.id.endImage); + enterImage = itemView.findViewById(R.id.enterImage); + history = findViewById(R.id.history); + } + public void setSelected(boolean isSelected) { + select.setSelected(isSelected); } } public class MyAdapter extends RecyclerView.Adapter{ @@ -59,25 +158,56 @@ public class KaiFaPiao extends AppCompatActivity { //设置item中的控件设置值 点击事件 @Override public void onBindViewHolder(@NonNull MyViewHolder holder, int position) { + history_item.TakeHistoryDTO historyItem = history_items.get(position); + holder.startTextView.setText(historyItem.start); + holder.moneyTextView.setText("¥ "+historyItem.price); + holder.timeTextView.setText(historyItem.time); + holder.endTextView.setText(historyItem.end); //TODO 点击事件 + // 更新视图以反映选中状态 + holder.setSelected(selectedItems.contains(position)); + + // 处理点击事件 holder.itemView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - //TODO 跳转到行程详情 - ImageView xuanzhong = findViewById(R.id.imageView94); - xuanzhong.setSelected(true); -// Intent intent = new Intent(KaiFaPiao.this, linedetail.class); -// startActivity(intent); + // 切换选中状态 + if (selectedItems.contains(position)) { + selectedItems.remove(position); + holder.setSelected(false); + } else { + selectedItems.add(position); + holder.setSelected(true); + } + + // 重新计算总金额 + calculateTotalAmount(); } }); } + private void calculateTotalAmount() { + double totalAmount = 0; + for (Integer position : selectedItems) { + history_item.TakeHistoryDTO item = history_items.get(position); + totalAmount += Double.parseDouble(item.price); + } + // 更新金额显示 + money.setText(String.format(Locale.getDefault(), "%.2f", totalAmount)); + + // 根据selectedItems是否为空来设置fapiao的选中状态 + if (!selectedItems.isEmpty()) { + fapiao.setSelected(true); + } else { + fapiao.setSelected(false); + } + } //item显示条数 @Override public int getItemCount() { - return 10; + return history_items.size(); } } } \ No newline at end of file diff --git a/app/src/main/java/com/hnucm/c25/MyFragment.java b/app/src/main/java/com/hnucm/c25/MyFragment.java index 764be0a..d189440 100644 --- a/app/src/main/java/com/hnucm/c25/MyFragment.java +++ b/app/src/main/java/com/hnucm/c25/MyFragment.java @@ -3,6 +3,7 @@ package com.hnucm.c25; import android.content.Intent; import android.os.Bundle; +import androidx.cardview.widget.CardView; import androidx.fragment.app.Fragment; import android.view.LayoutInflater; @@ -21,7 +22,9 @@ public class MyFragment extends Fragment { Bundle savedInstanceState) { ImmersionBar.with(this).init(); View view = inflater.inflate(R.layout.fragment_my, container, false); - ImageView enter =view. findViewById(R.id.imageView137); +// ImageView enter =view. findViewById(R.id.imageView137); +// CardView enter = view.findViewById(R.id.enter); + TextView enter = view.findViewById(R.id.textView74); enter.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { diff --git a/app/src/main/java/com/hnucm/c25/MyLogin.java b/app/src/main/java/com/hnucm/c25/MyLogin.java index b3e1089..8543900 100644 --- a/app/src/main/java/com/hnucm/c25/MyLogin.java +++ b/app/src/main/java/com/hnucm/c25/MyLogin.java @@ -84,6 +84,7 @@ public class MyLogin extends AppCompatActivity { @Override public void onClick(View v) { Intent intent = new Intent(MyLogin.this,shouye.class); + intent.putExtra("id",3); startActivity(intent); } }); @@ -92,7 +93,8 @@ public class MyLogin extends AppCompatActivity { saoma.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - Intent intent = new Intent(MyLogin.this,TakeSubwayFragment.class); + Intent intent = new Intent(MyLogin.this,shouye.class); + intent.putExtra("id",2); startActivity(intent); } }); diff --git a/app/src/main/java/com/hnucm/c25/ShouyeFragment.java b/app/src/main/java/com/hnucm/c25/ShouyeFragment.java index b606edc..e4a5813 100644 --- a/app/src/main/java/com/hnucm/c25/ShouyeFragment.java +++ b/app/src/main/java/com/hnucm/c25/ShouyeFragment.java @@ -131,6 +131,14 @@ public class ShouyeFragment extends Fragment { startActivity(intent); } }); + CardView carbon= view.findViewById(R.id.cardView6); + carbon.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent intent = new Intent(getContext(),Carbon.class); + startActivity(intent); + } + }); return view; } } \ No newline at end of file diff --git a/app/src/main/java/com/hnucm/c25/SubwayHistory.java b/app/src/main/java/com/hnucm/c25/SubwayHistory.java index a9c84c4..606118a 100644 --- a/app/src/main/java/com/hnucm/c25/SubwayHistory.java +++ b/app/src/main/java/com/hnucm/c25/SubwayHistory.java @@ -131,7 +131,7 @@ public class SubwayHistory extends AppCompatActivity { history_item.TakeHistoryDTO historyItem = history_items.get(position); holder.startTextView.setText(historyItem.start); holder.finishTextView.setText(historyItem.status); - holder.moneyTextView.setText(historyItem.price); + holder.moneyTextView.setText("¥ "+historyItem.price); holder.timeTextView.setText(historyItem.time); holder.endTextView.setText(historyItem.end); diff --git a/app/src/main/java/com/hnucm/c25/shouye.java b/app/src/main/java/com/hnucm/c25/shouye.java index e822ab8..2e09198 100644 --- a/app/src/main/java/com/hnucm/c25/shouye.java +++ b/app/src/main/java/com/hnucm/c25/shouye.java @@ -61,6 +61,7 @@ MyFragment myFragment = new MyFragment(); getSupportFragmentManager().beginTransaction().hide(takeSubwayFragment).hide(shouyeFragment).show(myFragment).commit(); } }); + //1是我的,2是乘车,3是首页 int id = getIntent().getIntExtra("id",0); if(id==1){ getSupportFragmentManager() @@ -68,5 +69,11 @@ MyFragment myFragment = new MyFragment(); .hide(takeSubwayFragment).hide(shouyeFragment).show(myFragment).commit(); } + if(id==2){ + getSupportFragmentManager().beginTransaction().hide(myFragment).hide(shouyeFragment).show(takeSubwayFragment).commit(); + } + if(id==3){ + getSupportFragmentManager().beginTransaction().hide(takeSubwayFragment).hide(myFragment).show(shouyeFragment).commit(); + } } } \ No newline at end of file diff --git a/app/src/main/res/drawable/city.png b/app/src/main/res/drawable/city.png new file mode 100644 index 0000000..50e4427 Binary files /dev/null and b/app/src/main/res/drawable/city.png differ diff --git a/app/src/main/res/drawable/city1.png b/app/src/main/res/drawable/city1.png new file mode 100644 index 0000000..8d87cc5 Binary files /dev/null and b/app/src/main/res/drawable/city1.png differ diff --git a/app/src/main/res/drawable/fapiao_roundcorner.xml b/app/src/main/res/drawable/fapiao_roundcorner.xml new file mode 100644 index 0000000..4ff23ca --- /dev/null +++ b/app/src/main/res/drawable/fapiao_roundcorner.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/fapiao_roundcorner_selected.xml b/app/src/main/res/drawable/fapiao_roundcorner_selected.xml new file mode 100644 index 0000000..3baabe1 --- /dev/null +++ b/app/src/main/res/drawable/fapiao_roundcorner_selected.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/fapiao_selector.xml b/app/src/main/res/drawable/fapiao_selector.xml new file mode 100644 index 0000000..d503304 --- /dev/null +++ b/app/src/main/res/drawable/fapiao_selector.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/jianbianse.xml b/app/src/main/res/drawable/jianbianse.xml new file mode 100644 index 0000000..f2cecea --- /dev/null +++ b/app/src/main/res/drawable/jianbianse.xml @@ -0,0 +1,8 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/rounded_corners.xml b/app/src/main/res/drawable/rounded_corners.xml new file mode 100644 index 0000000..d2eb65d --- /dev/null +++ b/app/src/main/res/drawable/rounded_corners.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_carbon.xml b/app/src/main/res/layout/activity_carbon.xml new file mode 100644 index 0000000..e851f5b --- /dev/null +++ b/app/src/main/res/layout/activity_carbon.xml @@ -0,0 +1,90 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_kai_fa_piao.xml b/app/src/main/res/layout/activity_kai_fa_piao.xml index fbd64f1..7ac6c0e 100644 --- a/app/src/main/res/layout/activity_kai_fa_piao.xml +++ b/app/src/main/res/layout/activity_kai_fa_piao.xml @@ -122,22 +122,13 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="16dp" - android:text="开票金额:¥0.00" + android:text="开票金额:¥ " android:textSize="16sp" android:textStyle="bold" app:layout_constraintBottom_toBottomOf="@+id/textView300" app:layout_constraintStart_toEndOf="@+id/textView300" app:layout_constraintTop_toTopOf="@+id/textView300" /> - - + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_my_login.xml b/app/src/main/res/layout/activity_my_login.xml index e786c3d..245da02 100644 --- a/app/src/main/res/layout/activity_my_login.xml +++ b/app/src/main/res/layout/activity_my_login.xml @@ -521,11 +521,11 @@ + app:srcCompat="@drawable/ma1" /> \ No newline at end of file diff --git a/app/src/main/res/layout/activity_set.xml b/app/src/main/res/layout/activity_set.xml index 03051e6..8124ee2 100644 --- a/app/src/main/res/layout/activity_set.xml +++ b/app/src/main/res/layout/activity_set.xml @@ -153,72 +153,6 @@ app:layout_constraintTop_toTopOf="@+id/imageView141" /> - - - - - - - - - - - - - - + app:layout_constraintTop_toBottomOf="@+id/constraintLayout37"> - - + - + - + - + - + + app:layout_constraintTop_toTopOf="parent" /> \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_my.xml b/app/src/main/res/layout/fragment_my.xml index d2af30a..d594e96 100644 --- a/app/src/main/res/layout/fragment_my.xml +++ b/app/src/main/res/layout/fragment_my.xml @@ -68,6 +68,7 @@ android:layout_height="200dp" android:background="#2F3D68" app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintHorizontal_bias="0.0" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent"> @@ -94,14 +95,19 @@ app:layout_constraintStart_toStartOf="@+id/textView273" app:layout_constraintTop_toBottomOf="@+id/textView273" /> - + app:layout_constraintTop_toBottomOf="@+id/textView275" /> + diff --git a/app/src/main/res/layout/history_item_layout.xml b/app/src/main/res/layout/history_item_layout.xml index 7cdda93..0c7d574 100644 --- a/app/src/main/res/layout/history_item_layout.xml +++ b/app/src/main/res/layout/history_item_layout.xml @@ -75,12 +75,12 @@ android:id="@+id/moneyTextView" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginTop="16dp" - android:text="¥4.00" + android:text="4.00" android:textSize="16sp" android:textStyle="bold" - app:layout_constraintStart_toStartOf="@+id/finishTextView" - app:layout_constraintTop_toBottomOf="@+id/finishTextView" /> + app:layout_constraintBottom_toBottomOf="@+id/textView77" + app:layout_constraintStart_toEndOf="@+id/textView77" + app:layout_constraintTop_toTopOf="@+id/textView77" /> + + \ No newline at end of file