feat(ui): 改造貨道管理列表為卡片式 Grid 佈局與 Adapter 邏輯對接
This commit is contained in:
parent
aed8d9bc1f
commit
a933bb22f6
@ -19,10 +19,12 @@ import androidx.viewpager.widget.ViewPager;
|
||||
import com.unibuy.smartdevice.R;
|
||||
import com.unibuy.smartdevice.databinding.RecyclerVmcSlotListBinding;
|
||||
import com.unibuy.smartdevice.exception.Logs;
|
||||
import com.unibuy.smartdevice.exception.LogsEmptyException;
|
||||
import com.unibuy.smartdevice.structure.ProductStructure;
|
||||
import com.unibuy.smartdevice.structure.SlotStructure;
|
||||
import com.unibuy.smartdevice.tools.Tools;
|
||||
import com.unibuy.smartdevice.ui.ProductSearchActivity;
|
||||
import com.unibuy.smartdevice.ui.tools.ImageGlide;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -73,15 +75,42 @@ public class RecyclerVmcSlotListAdpter extends RecyclerView.Adapter<RecyclerVmcS
|
||||
holder.binding.editCount.setText(String.valueOf(slot.getCount()));
|
||||
|
||||
if (slot.isLock()) {
|
||||
holder.binding.textLock.setText(context.getString(R.string.lock));
|
||||
holder.binding.textLock.setTextColor(Color.BLACK);
|
||||
holder.binding.textLock.setChecked(false);
|
||||
holder.binding.textLockStatus.setText("停售中");
|
||||
} else {
|
||||
holder.binding.textLock.setText(context.getString(R.string.unlocked));
|
||||
holder.binding.textLock.setTextColor(Color.GRAY);
|
||||
holder.binding.textLock.setChecked(true);
|
||||
holder.binding.textLockStatus.setText("販售中");
|
||||
}
|
||||
holder.binding.textProductName.setOnClickListener(new selectPositionOnClickListener(position));
|
||||
holder.binding.textCount.setOnClickListener(new textCountOnClickListener(holder.binding, slot.getCount()));
|
||||
holder.binding.textLock.setOnClickListener(new textLockOnClickListener(position));
|
||||
|
||||
String productImg = slot.getProduct().getProductImg();
|
||||
if (productImg != null && !productImg.isEmpty() && !productImg.equals("?")) {
|
||||
try {
|
||||
new ImageGlide(context).fileload(productImg, holder.binding.imageProduct);
|
||||
} catch (LogsEmptyException e) {
|
||||
holder.binding.imageProduct.setImageResource(R.drawable.cpu);
|
||||
}
|
||||
} else {
|
||||
holder.binding.imageProduct.setImageResource(R.drawable.cpu);
|
||||
}
|
||||
|
||||
holder.binding.buttonCountMinus.setOnClickListener(v -> {
|
||||
int current = slot.getCount();
|
||||
if (current > 0) {
|
||||
slot.setCount(current - 1);
|
||||
notifyItemChanged(position);
|
||||
}
|
||||
});
|
||||
|
||||
holder.binding.buttonCountPlus.setOnClickListener(v -> {
|
||||
int current = slot.getCount();
|
||||
slot.setCount(current + 1);
|
||||
notifyItemChanged(position);
|
||||
});
|
||||
|
||||
holder.binding.imageProduct.setOnClickListener(new selectPositionOnClickListener(position));
|
||||
holder.binding.textProductName.setOnClickListener(null);
|
||||
holder.binding.textCount.setOnClickListener(new textCountOnClickListener(holder.binding, slot.getCount()));
|
||||
holder.binding.textDelete.setOnClickListener(new textDeleteOnClickListener(position));
|
||||
holder.binding.editCount.setOnEditorActionListener(new editCountOnEditorActionListener(holder.binding, position));
|
||||
holder.binding.editCount.setOnClickListener(new editCountOnClickListener(holder.binding, slot.getCount()));
|
||||
|
||||
@ -9,7 +9,7 @@ import androidx.activity.result.ActivityResult;
|
||||
import androidx.activity.result.ActivityResultCallback;
|
||||
import androidx.activity.result.ActivityResultLauncher;
|
||||
import androidx.activity.result.contract.ActivityResultContracts;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
|
||||
import com.unibuy.smartdevice.AppCompatActivityAbstract;
|
||||
import com.unibuy.smartdevice.MyApp;
|
||||
@ -127,7 +127,7 @@ public class VmcSlotListActivity extends AppCompatActivityAbstract {
|
||||
|
||||
recyclerVmcSlotListAdpter = new RecyclerVmcSlotListAdpter(this, resultLauncher, MyApp.getInstance().getSlotList(SlotField.VMC.getField()));
|
||||
binding.recyclerSlotList.setAdapter(recyclerVmcSlotListAdpter);
|
||||
binding.recyclerSlotList.setLayoutManager(new LinearLayoutManager(this));
|
||||
binding.recyclerSlotList.setLayoutManager(new GridLayoutManager(this, 3));
|
||||
|
||||
// dataShow();
|
||||
|
||||
|
||||
@ -1,104 +1,199 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
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="wrap_content"
|
||||
android:paddingTop="1dp"
|
||||
android:paddingBottom="1dp"
|
||||
>
|
||||
android:layout_margin="6dp"
|
||||
app:cardCornerRadius="8dp"
|
||||
app:cardElevation="3dp"
|
||||
app:cardBackgroundColor="@color/background"
|
||||
app:strokeColor="@color/outline"
|
||||
app:strokeWidth="1dp">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/linearLayout"
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="110dp"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal"
|
||||
android:background="@color/white"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="15dp">
|
||||
|
||||
<!-- 第一列:貨道編號 | 啟用狀態 -->
|
||||
<TextView
|
||||
android:id="@+id/textSlot"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/lane_number"
|
||||
android:textSize="24sp"
|
||||
android:layout_marginStart="5dp"
|
||||
android:layout_marginEnd="5dp"
|
||||
android:textStyle="bold"/>
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="@color/black"
|
||||
android:textSize="18sp"
|
||||
android:textStyle="bold"
|
||||
android:text="1"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/layoutLock" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/layoutLock"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center_vertical"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textLockStatus"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="4dp"
|
||||
android:textSize="12sp"
|
||||
android:textStyle="bold"
|
||||
android:textColor="@color/black"
|
||||
android:text="販售中" />
|
||||
|
||||
<com.google.android.material.materialswitch.MaterialSwitch
|
||||
android:id="@+id/textLock"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:scaleX="0.8"
|
||||
android:scaleY="0.8"
|
||||
app:switchPadding="0dp" />
|
||||
</LinearLayout>
|
||||
|
||||
<!-- 第二列:圖片區域 1:1 -->
|
||||
<ImageView
|
||||
android:id="@+id/imageProduct"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
app:layout_constraintTop_toBottomOf="@id/layoutLock"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintDimensionRatio="1:1"
|
||||
android:layout_marginTop="16dp"
|
||||
android:scaleType="centerCrop"
|
||||
android:background="#0D000000" /> <!-- 預留空間,灰色透明度5% -->
|
||||
|
||||
<!-- 第三列:商品名稱(點擊可選擇商品) -->
|
||||
<TextView
|
||||
android:id="@+id/textProductName"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginStart="5dp"
|
||||
android:layout_marginEnd="5dp"
|
||||
android:layout_weight="4"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="50dp"
|
||||
android:gravity="center"
|
||||
android:paddingHorizontal="0dp"
|
||||
android:paddingVertical="0dp"
|
||||
android:background="@null"
|
||||
android:textColor="@color/black"
|
||||
android:textSize="20sp"
|
||||
android:textStyle="bold"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
android:text="@string/product_name"
|
||||
android:textSize="24sp"
|
||||
android:textStyle="bold" />
|
||||
app:layout_constraintTop_toBottomOf="@id/imageProduct"
|
||||
android:layout_marginTop="0dp" />
|
||||
|
||||
<!-- 第四列:按鈕 -->
|
||||
<LinearLayout
|
||||
android:id="@+id/layoutButtons"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
app:layout_constraintTop_toBottomOf="@+id/textProductName">
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/textDelete"
|
||||
style="@style/Widget.MaterialComponents.Button"
|
||||
app:backgroundTint="@color/error"
|
||||
android:textColor="@color/onError"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="清空貨道" />
|
||||
</LinearLayout>
|
||||
|
||||
<!-- 第五列:庫存數量控制列 - Minus -->
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/buttonCountMinus"
|
||||
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:text="−"
|
||||
android:textSize="24sp"
|
||||
android:paddingHorizontal="0dp"
|
||||
app:backgroundTint="@color/background"
|
||||
android:textColor="@color/primary"
|
||||
app:layout_constraintTop_toBottomOf="@id/layoutButtons"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@+id/textCount" />
|
||||
|
||||
<!-- 第五列:庫存數量控制列 - Count -->
|
||||
<TextView
|
||||
android:id="@+id/textCount"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="0dp"
|
||||
android:gravity="center"
|
||||
android:layout_marginStart="5dp"
|
||||
android:layout_marginEnd="5dp"
|
||||
android:text="@string/amount"
|
||||
android:textSize="24sp"
|
||||
android:textStyle="bold"/>
|
||||
android:textSize="22sp"
|
||||
android:textStyle="bold"
|
||||
android:textColor="@color/black"
|
||||
android:text="0"
|
||||
app:layout_constraintTop_toTopOf="@+id/buttonCountMinus"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/buttonCountMinus"
|
||||
app:layout_constraintStart_toEndOf="@+id/buttonCountMinus"
|
||||
app:layout_constraintEnd_toStartOf="@+id/buttonCountPlus" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/editCount"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="0dp"
|
||||
android:gravity="center"
|
||||
android:focusableInTouchMode="true"
|
||||
android:focusable="true"
|
||||
android:descendantFocusability="blocksDescendants"
|
||||
android:text="0"
|
||||
android:layout_marginStart="5dp"
|
||||
android:layout_marginEnd="5dp"
|
||||
android:inputType="number"
|
||||
android:visibility="gone"
|
||||
android:textSize="24sp"
|
||||
android:textSize="22sp"
|
||||
android:textStyle="bold"
|
||||
android:textColor="@color/black"
|
||||
android:visibility="gone"
|
||||
android:focusable="true"
|
||||
android:focusableInTouchMode="true"
|
||||
android:descendantFocusability="blocksDescendants"
|
||||
android:imeOptions="actionSend"
|
||||
>
|
||||
</EditText>
|
||||
android:background="@android:color/transparent"
|
||||
app:layout_constraintTop_toTopOf="@+id/buttonCountMinus"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/buttonCountMinus"
|
||||
app:layout_constraintStart_toEndOf="@+id/buttonCountMinus"
|
||||
app:layout_constraintEnd_toStartOf="@+id/buttonCountPlus" />
|
||||
|
||||
<!-- 第五列:庫存數量控制列 - Plus -->
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/buttonCountPlus"
|
||||
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="48dp"
|
||||
android:text="+"
|
||||
android:textSize="24sp"
|
||||
android:paddingHorizontal="0dp"
|
||||
app:backgroundTint="@color/background"
|
||||
android:textColor="@color/primary"
|
||||
app:layout_constraintTop_toTopOf="@+id/buttonCountMinus"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/buttonCountMinus"
|
||||
app:layout_constraintStart_toEndOf="@+id/textCount"
|
||||
app:layout_constraintEnd_toEndOf="parent" />
|
||||
|
||||
<!-- 隱藏元件,保留避免崩潰 -->
|
||||
<Button
|
||||
android:id="@+id/buttonRestocking"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="補貨"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintTop_toBottomOf="@id/buttonCountMinus"
|
||||
app:layout_constraintStart_toStartOf="parent"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textLock"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center"
|
||||
android:text="@string/lock"
|
||||
android:layout_marginStart="5dp"
|
||||
android:layout_marginEnd="5dp"
|
||||
android:textColor="@color/light_gray"
|
||||
android:textSize="24sp"
|
||||
android:textStyle="bold"/>
|
||||
android:id="@+id/textIsZg"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="购物车"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintTop_toBottomOf="@id/buttonRestocking"
|
||||
app:layout_constraintStart_toStartOf="parent"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textDelete"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center"
|
||||
android:text="@string/delete"
|
||||
android:layout_marginStart="5dp"
|
||||
android:layout_marginEnd="5dp"
|
||||
android:textSize="24sp"
|
||||
android:textStyle="bold"/>
|
||||
</LinearLayout>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user