feat: 優化商品搜尋介面並修復後台貨道編輯 Bug

- 商品搜尋介面大改版:
  1. 搜尋列表從單欄改為 3 欄網格排列,並導入 MaterialCardView 重新設計商品卡片。
  2. 搜尋框體驗優化:隱藏原生圖示,新增清空按鈕;支援點擊列表或候選字時自動收起鍵盤。
  3. 點擊候選字邏輯修改為直接套用完整字詞。
  4. 擴大點擊範圍,改為點擊整張商品卡片即可選取。
- 貨道編輯清單修復:
  1. 將 textCount 隱藏狀態改為 INVISIBLE 解決 GONE 導致輸入框寬度壓縮為 0 的問題。
  2. 輸入數量時改用 numberPassword 並移除密碼遮罩,以喚起乾淨的純數字鍵盤。
- 資源與樣式:
  1. 新增 button_outline_black.xml 黑框按鈕樣式。
  2. 修正圖片檔名大小寫 (eTicket -> eticket)。
This commit is contained in:
TaiwanStar Developer 2026-06-09 15:59:17 +08:00
parent d917f6445c
commit b1732987ce
12 changed files with 265 additions and 122 deletions

View File

@ -346,8 +346,12 @@ public class Tools {
public void setImmOpenByFocusChange(EditText editText) {
editText.requestFocus();
editText.setSelection(editText.getText().length());
InputMethodManager imm = (InputMethodManager) context.getSystemService(context.INPUT_METHOD_SERVICE);
imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
// 使用 post() 延遲執行確保 hideSystemBars() 觸發的 Window 重繪完成後才彈出鍵盤
// 若直接呼叫 showSoftInputWindow flag 變更會清除 focus導致鍵盤無法彈出
editText.post(() -> {
InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
});
}
public void setImmHideByFocusChange(EditText editText) {

View File

@ -12,6 +12,7 @@ import android.widget.ImageView;
import android.widget.SearchView;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.GridLayoutManager;
import com.unibuy.smartdevice.AppCompatActivityAbstract;
import com.unibuy.smartdevice.MyApp;
@ -94,34 +95,44 @@ public class ProductSearchActivity extends AppCompatActivityAbstract {
if (size > 0) recyclerSearchTextAdpter.notifyItemRangeRemoved(0, size);
if (message.isEmpty()) {
binding.recyclerSearchText.setVisibility(View.GONE);
binding.textSearchStatus.setVisibility(View.VISIBLE);
binding.textSearchStatus.setText("請輸入您要搜尋的文字");
for (ProductStructure product: MyApp.getInstance().getProductList()) {
searchProductList.add(product);
}
recyclerProductSearchAdpter.notifyItemInserted(searchProductList.size() -1);
if (searchProductList.size() > 0) {
recyclerProductSearchAdpter.notifyDataSetChanged();
}
} else {
for (ProductStructure product: MyApp.getInstance().getProductList()) {
if (product.getProductName().contains(message)) {
searchProductList.add(product);
String name = product.getProductName();
// Log.i("product name", name);
int index = name.indexOf(message);
if (index != -1 && index < name.length() - 1) {
String result = name.substring(index + message.length());
if (!result.isEmpty()) {
String oneText = String.valueOf(result.charAt(0));
if (!searchTextList.contains(oneText)) {
searchTextList.add(oneText);
}
}
if (!searchTextList.contains(name)) {
searchTextList.add(name);
}
}
}
if (searchTextList.size() > 2) Collections.sort(searchTextList);
recyclerProductSearchAdpter.notifyItemInserted(searchProductList.size() -1);
recyclerSearchTextAdpter.notifyItemInserted(searchTextList.size() -1);
if (searchTextList.isEmpty()) {
binding.recyclerSearchText.setVisibility(View.GONE);
binding.textSearchStatus.setVisibility(View.VISIBLE);
binding.textSearchStatus.setText("查無相關的候選字");
} else {
binding.recyclerSearchText.setVisibility(View.VISIBLE);
binding.textSearchStatus.setVisibility(View.GONE);
recyclerSearchTextAdpter.notifyDataSetChanged();
}
if (searchProductList.size() > 0) {
recyclerProductSearchAdpter.notifyDataSetChanged();
}
}
break;
}
@ -140,7 +151,7 @@ public class ProductSearchActivity extends AppCompatActivityAbstract {
recyclerProductSearchAdpter = new RecyclerProductSearchAdpter(getCtx(), position, searchProductList);
binding.recyclerProductSearch.setAdapter(recyclerProductSearchAdpter);
binding.recyclerProductSearch.setLayoutManager(new LinearLayoutManager(getCtx()));
binding.recyclerProductSearch.setLayoutManager(new GridLayoutManager(getCtx(), 3));
recyclerSearchTextAdpter = new RecyclerSearchTextAdpter(binding, searchTextList);
binding.recyclerSearchText.setAdapter(recyclerSearchTextAdpter);
@ -149,8 +160,30 @@ public class ProductSearchActivity extends AppCompatActivityAbstract {
// SearchView searchView = binding.searchProductList;
// enlargeSearchView(searchView, 32, 20, R.drawable.search); // icon 32dp文字 20sp自訂 drawable
replaceSearchViewIcon(binding.searchProductList);
binding.searchProductList.setOnQueryTextListener(new SearchProductListOnQueryText(getHandlerMain()));
binding.searchProductList.setOnQueryTextListener(new SearchProductListOnQueryText(getHandlerMain()) {
@Override
public boolean onQueryTextSubmit(String query) {
binding.searchProductList.clearFocus();
return super.onQueryTextSubmit(query);
}
});
// 點擊列表時自動關閉鍵盤
binding.recyclerProductSearch.setOnTouchListener((v, event) -> {
binding.searchProductList.clearFocus();
return false;
});
binding.recyclerSearchText.setOnTouchListener((v, event) -> {
binding.searchProductList.clearFocus();
return false;
});
binding.buttonBack.setOnClickListener(v -> finish());
binding.buttonClear.setOnClickListener(v -> {
binding.searchProductList.setQuery("", false);
binding.searchProductList.clearFocus();
});
if (MyApp.getInstance().getProductList().isEmpty()) {
ProductsDao productsDao = new ProductsDao(getCtx());
@ -172,9 +205,6 @@ public class ProductSearchActivity extends AppCompatActivityAbstract {
private void replaceSearchViewIcon(SearchView searchView) {
if (searchView == null) return;
// 設定 hint
searchView.setQueryHint("輸入搜尋關鍵字");
// 找到內部的 EditText修改字體大小 & 顏色
int searchEditTextId = searchView.getContext()
.getResources()
@ -194,7 +224,24 @@ public class ProductSearchActivity extends AppCompatActivityAbstract {
ImageView searchIcon = searchView.findViewById(searchIconId);
if (searchIcon != null) {
searchIcon.setImageResource(R.drawable.searchopen);
searchIcon.setImageDrawable(null);
searchIcon.setVisibility(View.GONE);
}
// 隱藏內部的清除 icon
int closeIconId = searchView.getContext()
.getResources()
.getIdentifier("android:id/search_close_btn", null, null);
ImageView closeIcon = searchView.findViewById(closeIconId);
if (closeIcon != null) {
closeIcon.setImageDrawable(null);
closeIcon.setEnabled(false);
ViewGroup.LayoutParams params = closeIcon.getLayoutParams();
if (params != null) {
params.width = 0;
params.height = 0;
closeIcon.setLayoutParams(params);
}
}
}

View File

@ -73,6 +73,8 @@ public class RecyclerVmcSlotListAdpter extends RecyclerView.Adapter<RecyclerVmcS
}
holder.binding.textCount.setText(String.valueOf(slot.getCount()));
holder.binding.editCount.setText(String.valueOf(slot.getCount()));
// numberPassword 預設會遮罩輸入關閉遮罩以顯示明碼數字
holder.binding.editCount.setTransformationMethod(null);
if (slot.isLock()) {
holder.binding.textLock.setChecked(false);
@ -194,7 +196,9 @@ public class RecyclerVmcSlotListAdpter extends RecyclerView.Adapter<RecyclerVmcS
@Override
public void onClick(View v) {
binding.textCount.setVisibility(View.GONE);
// 改用 INVISIBLE 而非 GONE避免 buttonCountPlus constraint textCount 折疊
// 導致 editCount 可用寬度被壓縮成 0看不到輸入框IME 無法接受輸入
binding.textCount.setVisibility(View.INVISIBLE);
binding.editCount.setVisibility(View.VISIBLE);
if (this.count == 0) {
binding.editCount.setText("");

View File

@ -69,7 +69,7 @@ public class RecyclerProductSearchAdpter extends RecyclerView.Adapter<RecyclerPr
holder.binding.textProductId.setText(product.getProductID());
holder.binding.textProductName.setText(product.getProductName());
holder.binding.buttonSlotProductSelect.setOnClickListener(new View.OnClickListener() {
holder.binding.cardProduct.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.i("select product", "點選商品:"+product.getProductName());

View File

@ -58,9 +58,9 @@ public class RecyclerSearchTextAdpter extends RecyclerView.Adapter<RecyclerSearc
@Override
public void onClick(View v) {
String nowText = activityProductSearchBinding.searchProductList.getQuery().toString();
Log.i("SearchTextOnClick", nowText + oneText);
activityProductSearchBinding.searchProductList.setQuery(nowText+oneText, false);
Log.i("SearchTextOnClick", "Selected full name: " + oneText);
activityProductSearchBinding.searchProductList.setQuery(oneText, false);
activityProductSearchBinding.searchProductList.clearFocus();
}
}

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@android:color/transparent" />
<stroke android:width="1dp" android:color="@color/black" />
<corners android:radius="8dp" />
</shape>

View File

Before

Width:  |  Height:  |  Size: 40 KiB

After

Width:  |  Height:  |  Size: 40 KiB

View File

@ -6,26 +6,83 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.ProductSearchActivity"
android:background="@color/light_gray">
android:background="@color/background">
<SearchView
android:id="@+id/searchProductList"
<LinearLayout
android:id="@+id/topControlLayout"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="@drawable/textview_border"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
android:layout_height="wrap_content"
android:background="@color/cardSurface"
android:elevation="8dp"
android:orientation="vertical"
android:paddingBottom="16dp"
app:layout_constraintTop_toTopOf="parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerSearchText"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginTop="1dp"
android:background="@color/white"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/searchProductList" />
<TextView
android:id="@+id/textTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:text="選擇商品"
android:textColor="@color/black"
android:textSize="28sp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_marginTop="8dp"
android:orientation="horizontal">
<SearchView
android:id="@+id/searchProductList"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:background="@drawable/textview_border"
android:queryHint="請輸入商品名稱來搜尋"
android:searchIcon="@null"
android:iconifiedByDefault="false" />
<Button
android:id="@+id/buttonClear"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginStart="8dp"
android:backgroundTint="@color/warning"
android:textColor="@color/onWarning"
app:cornerRadius="8dp"
android:text="清除"
android:textSize="24sp" />
</LinearLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_marginTop="8dp">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerSearchText"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone" />
<TextView
android:id="@+id/textSearchStatus"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:text="請輸入您要搜尋的文字"
android:textColor="@color/black"
android:textSize="18sp"
android:visibility="visible" />
</FrameLayout>
</LinearLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerProductSearch"
@ -33,35 +90,50 @@
android:layout_height="0dp"
android:layout_marginTop="1dp"
android:layout_marginBottom="0dp"
app:layout_constraintBottom_toTopOf="@id/linearLayout2"
app:layout_constraintTop_toBottomOf="@+id/recyclerSearchText"
app:layout_constraintBottom_toTopOf="@+id/bottomControlLayout"
app:layout_constraintTop_toBottomOf="@+id/topControlLayout"
app:layout_constraintVertical_bias="1.0">
</androidx.recyclerview.widget.RecyclerView>
<LinearLayout
android:id="@+id/linearLayout2"
android:id="@+id/bottomControlLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:orientation="vertical"
android:padding="8dp"
android:background="@color/cardSurface"
android:elevation="16dp"
app:layout_constraintBottom_toBottomOf="parent">
<Button
android:id="@+id/buttonBack"
android:layout_width="wrap_content"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:backgroundTint="@color/black"
android:text="返回"
android:textSize="24dp"/>
android:orientation="horizontal">
<Button
android:id="@+id/buttonOk"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:backgroundTint="@color/black"
android:text="確定"
android:textSize="24dp"/>
<Button
android:id="@+id/buttonBack"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:backgroundTint="@color/gray"
android:textColor="@color/black"
android:layout_marginEnd="8dp"
app:cornerRadius="8dp"
android:text="返回"
android:textSize="24dp" />
<Button
android:id="@+id/buttonOk"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginStart="8dp"
android:backgroundTint="@color/primary"
android:textColor="@color/onPrimary"
android:text="確定"
app:cornerRadius="8dp"
android:textSize="24dp" />
</LinearLayout>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -5,14 +5,14 @@
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/light_gray"
android:background="@color/background"
tools:context=".ui.devs.vmc.VmcSlotListActivity">
<LinearLayout
android:id="@+id/topControlLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:background="@color/cardSurface"
android:elevation="8dp"
android:orientation="vertical"
android:paddingBottom="16dp"
@ -48,7 +48,7 @@
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="8dp"
android:background="#FFFFFF"
android:background="@color/cardSurface"
android:elevation="16dp"
app:layout_constraintBottom_toBottomOf="parent">
@ -80,7 +80,7 @@
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginEnd="8dp"
android:backgroundTint="@color/light_gray"
android:backgroundTint="@color/gray"
android:textColor="@color/black"
android:text="一鍵補貨"
android:textSize="24dp" />

View File

@ -1,70 +1,79 @@
<?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:id="@+id/cardProduct"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="1dp"
android:paddingBottom="1dp"
>
android:layout_margin="8dp"
android:clickable="true"
android:focusable="true"
android:foreground="?attr/selectableItemBackground"
app:cardCornerRadius="12dp"
app:cardElevation="4dp"
app:cardBackgroundColor="@color/background"
app:strokeColor="@color/gray"
app:strokeWidth="1dp">
<LinearLayout
android:id="@+id/linearLayout"
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="80dp"
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">
<TextView
android:id="@+id/textProductId"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginStart="5dp"
android:layout_marginEnd="5dp"
android:layout_weight="1"
android:gravity="center"
android:text="@string/product_number"
android:textSize="16sp"
android:textStyle="bold" />
android:layout_height="wrap_content"
android:paddingBottom="16dp">
<!-- 圖片區域 1:1 -->
<ImageView
android:id="@+id/imageProductPicture"
android:layout_width="110dp"
android:layout_height="match_parent"
android:layout_width="0dp"
android:layout_height="0dp"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
android:layout_marginStart="5dp"
android:layout_marginEnd="5dp"
android:scaleType="centerCrop"
android:src="@drawable/default_product"
app:layout_constraintDimensionRatio="16:9"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<!-- 商品編號標籤 (左上角) -->
<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:gravity="center"
android:text="@string/product_name"
android:textSize="16sp"
android:textStyle="bold" />
<Button
android:id="@+id/buttonSlotProductSelect"
android:id="@+id/textProductId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.9"
android:backgroundTint="@color/black"
android:textColor="@color/white"
android:text="@string/choose" />
</LinearLayout>
android:layout_marginTop="8dp"
android:layout_marginStart="8dp"
android:background="@color/primary"
android:paddingHorizontal="10dp"
android:paddingVertical="4dp"
android:textColor="@color/onPrimary"
android:textSize="14sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<!-- 商品名稱 -->
<TextView
android:id="@+id/textProductName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:layout_marginHorizontal="12dp"
android:ellipsize="end"
android:maxLines="2"
android:minLines="1"
android:text="@string/product_name"
android:textColor="@color/black"
android:textSize="22sp"
android:textStyle="bold"
android:gravity="center"
app:layout_constraintTop_toBottomOf="@id/imageProductPicture" />
<!-- 保留隱藏的按鈕 ID 避免 Adapter 崩潰,但設為 GONE -->
<Button
android:id="@+id/buttonSlotProductSelect"
android:layout_width="0dp"
android:layout_height="0dp"
android:visibility="gone"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>

View File

@ -12,9 +12,11 @@
android:layout_height="wrap_content"
android:text="@string/click"
android:textSize="20sp"
android:backgroundTint="@color/black"
android:layout_marginStart="1dp"
android:layout_marginEnd="1dp"
android:textColor="@color/black"
android:background="@drawable/button_outline_black"
android:backgroundTint="@null"
android:layout_marginStart="4dp"
android:layout_marginEnd="4dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"

View File

@ -158,14 +158,13 @@
android:layout_height="0dp"
android:gravity="center"
android:text="0"
android:inputType="number"
android:inputType="numberPassword"
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"
android:background="@android:color/transparent"
app:layout_constraintTop_toTopOf="@+id/buttonCountMinus"