优化
This commit is contained in:
@@ -25,8 +25,8 @@ import androidx.recyclerview.widget.GridLayoutManager
|
||||
import com.google.common.util.concurrent.ListenableFuture
|
||||
import com.sw.dualscreen.GlobalData
|
||||
import com.sw.dualscreen.GlobalKey
|
||||
import com.sw.dualscreen.activity.fragment.CollectFragment
|
||||
import com.sw.dualscreen.adapter.SearchFoodAdapter
|
||||
import com.sw.dualscreen.adapter.DialogSearchFoodAdapter
|
||||
import com.sw.dualscreen.adapter.MainFoodListAdapter
|
||||
import com.sw.dualscreen.databinding.ActivityMainBinding
|
||||
import com.sw.dualscreen.dialog.RemindDialog
|
||||
import com.sw.dualscreen.ext.dp
|
||||
@@ -38,7 +38,6 @@ import com.sw.dualscreen.model.response.ClickBackEvent
|
||||
import com.sw.dualscreen.model.response.FoodInfo
|
||||
import com.sw.dualscreen.model.response.FoodOrder
|
||||
import com.sw.dualscreen.model.response.PaySuccessEvent
|
||||
import com.sw.dualscreen.model.response.ResetBoxEvent
|
||||
import com.sw.dualscreen.model.response.UserFaceModel
|
||||
import com.sw.dualscreen.objbox.Food
|
||||
import com.sw.dualscreen.objbox.FoodModule
|
||||
@@ -80,7 +79,6 @@ import java.time.ZoneId
|
||||
import java.time.format.DateTimeFormatter
|
||||
import java.util.Locale
|
||||
import java.util.concurrent.Executors
|
||||
import kotlin.collections.get
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
/**
|
||||
@@ -104,7 +102,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||
private val handler by lazy { Handler(Looper.getMainLooper()) }
|
||||
private val searchFoodList = mutableListOf<FoodInfo>()
|
||||
private val adapter by lazy {
|
||||
SearchFoodAdapter(searchFoodList).apply {
|
||||
MainFoodListAdapter(searchFoodList).apply {
|
||||
setOnItemClickListener { adapter, view, position ->
|
||||
if (searchFoodList[position].isChecked) {
|
||||
return@setOnItemClickListener
|
||||
@@ -122,6 +120,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||
val mode = SPUtil.getInstance().get(GlobalKey.KEY_CHARGE_MODE, 0)
|
||||
//不计费模式切换菜品,重新加载数据
|
||||
if (mode == 1) {
|
||||
presentation?.isAgainLoadData = false
|
||||
presentation?.loadUnbilledMode()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,8 +17,9 @@ import com.sw.dualscreen.GlobalData
|
||||
import com.sw.dualscreen.R
|
||||
import com.sw.dualscreen.activity.CollectedFoodActivity
|
||||
import com.sw.dualscreen.activity.SettingActivity
|
||||
import com.sw.dualscreen.adapter.CollectFoodListAdapter
|
||||
import com.sw.dualscreen.adapter.FoodCollectionAdapter
|
||||
import com.sw.dualscreen.adapter.SearchFoodAdapter
|
||||
import com.sw.dualscreen.adapter.DialogSearchFoodAdapter
|
||||
import com.sw.dualscreen.databinding.FragmentCollectBinding
|
||||
import com.sw.dualscreen.databinding.LayoutCameraPreviewBinding
|
||||
import com.sw.dualscreen.ext.clickWithDebounce
|
||||
@@ -28,7 +29,6 @@ import com.sw.dualscreen.objbox.Food
|
||||
import com.sw.dualscreen.objbox.FoodCollectionBean
|
||||
import com.sw.dualscreen.objbox.FoodModule
|
||||
import com.sw.dualscreen.objbox.ObjectBox
|
||||
import com.sw.dualscreen.utils.BitmapCropper
|
||||
import com.sw.dualscreen.utils.BitmapSaver
|
||||
import com.sw.dualscreen.utils.CameraUtils
|
||||
import com.sw.dualscreen.utils.Debouncer
|
||||
@@ -72,7 +72,7 @@ class CollectFragment : BaseFragment<FragmentCollectBinding>() {
|
||||
private var settingActivity: SettingActivity? = null
|
||||
private var checkedItem: FoodInfo? = null
|
||||
private val searchFoodAdapter by lazy {
|
||||
SearchFoodAdapter(searchFoodList).apply {
|
||||
CollectFoodListAdapter(searchFoodList).apply {
|
||||
setOnItemClickListener { adapter, view, position ->
|
||||
searchFoodList.forEachIndexed { index, item -> item.isChecked = index == position }
|
||||
checkedItem = searchFoodList[position]
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.sw.dualscreen.adapter
|
||||
|
||||
import android.content.Context
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.graphics.toColorInt
|
||||
import com.chad.library.adapter4.BaseQuickAdapter
|
||||
import com.chad.library.adapter4.viewholder.QuickViewHolder
|
||||
import com.sw.dualscreen.R
|
||||
import com.sw.dualscreen.databinding.ListItemSearchFoodBinding
|
||||
import com.sw.dualscreen.ext.format2String
|
||||
import com.sw.dualscreen.model.response.FoodInfo
|
||||
|
||||
class CollectFoodListAdapter(var list: MutableList<FoodInfo>) :
|
||||
BaseQuickAdapter<FoodInfo, CollectFoodListAdapter.VH>(list) {
|
||||
inner class VH(var binding: ListItemSearchFoodBinding) : QuickViewHolder(binding.root)
|
||||
|
||||
override fun onCreateViewHolder(context: Context, parent: ViewGroup, viewType: Int): VH {
|
||||
val inflater = LayoutInflater.from(context)
|
||||
val binding = ListItemSearchFoodBinding.inflate(inflater, parent, false)
|
||||
return VH(binding)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: VH, position: Int, item: FoodInfo?) {
|
||||
holder.binding.root.setBackgroundResource(R.drawable.bg_text_collect)
|
||||
holder.binding.tvFoodName.run {
|
||||
if (item!!.score == 0) {
|
||||
text = item.foodName
|
||||
} else {
|
||||
val score = (item.score / 100.0).format2String(2)
|
||||
text = item.foodName + (if (item.score != 0) "-${score}%" else "")
|
||||
}
|
||||
isChecked = item.isChecked
|
||||
setTextColor(
|
||||
if (isChecked) "#FF3232".toColorInt()
|
||||
else "#5E7585".toColorInt()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.sw.dualscreen.adapter
|
||||
|
||||
import android.content.Context
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.graphics.toColorInt
|
||||
import com.chad.library.adapter4.BaseQuickAdapter
|
||||
import com.chad.library.adapter4.viewholder.QuickViewHolder
|
||||
import com.sw.dualscreen.R
|
||||
import com.sw.dualscreen.databinding.ListItemSearchFood2Binding
|
||||
import com.sw.dualscreen.ext.format2String
|
||||
import com.sw.dualscreen.model.response.FoodInfo
|
||||
|
||||
class DialogSearchFoodAdapter(var list: MutableList<FoodInfo>) :
|
||||
BaseQuickAdapter<FoodInfo, DialogSearchFoodAdapter.VH>(list) {
|
||||
|
||||
inner class VH(var binding: ListItemSearchFood2Binding) : QuickViewHolder(binding.root)
|
||||
|
||||
override fun onCreateViewHolder(context: Context, parent: ViewGroup, viewType: Int): VH {
|
||||
val inflater = LayoutInflater.from(context)
|
||||
val binding = ListItemSearchFood2Binding.inflate(inflater, parent, false)
|
||||
return VH(binding)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: VH, position: Int, item: FoodInfo?) {
|
||||
holder.binding.tvFoodName.run {
|
||||
if (item!!.score == 0) {
|
||||
text = item.foodName
|
||||
} else {
|
||||
val score = (item.score / 100.0).format2String(2)
|
||||
text = item.foodName + (if (item.score != 0) "-${score}%" else "")
|
||||
}
|
||||
isChecked = item.isChecked
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+11
-2
@@ -3,14 +3,16 @@ package com.sw.dualscreen.adapter
|
||||
import android.content.Context
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.graphics.toColorInt
|
||||
import com.chad.library.adapter4.BaseQuickAdapter
|
||||
import com.chad.library.adapter4.viewholder.QuickViewHolder
|
||||
import com.sw.dualscreen.R
|
||||
import com.sw.dualscreen.databinding.ListItemSearchFoodBinding
|
||||
import com.sw.dualscreen.ext.format2String
|
||||
import com.sw.dualscreen.model.response.FoodInfo
|
||||
|
||||
class SearchFoodAdapter(var list: MutableList<FoodInfo>) :
|
||||
BaseQuickAdapter<FoodInfo, SearchFoodAdapter.VH>(list) {
|
||||
class MainFoodListAdapter(var list: MutableList<FoodInfo>) :
|
||||
BaseQuickAdapter<FoodInfo, MainFoodListAdapter.VH>(list) {
|
||||
|
||||
inner class VH(var binding: ListItemSearchFoodBinding) : QuickViewHolder(binding.root)
|
||||
|
||||
@@ -21,6 +23,7 @@ class SearchFoodAdapter(var list: MutableList<FoodInfo>) :
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: VH, position: Int, item: FoodInfo?) {
|
||||
holder.binding.root.setBackgroundResource(R.drawable.bg_text_main)
|
||||
holder.binding.tvFoodName.run {
|
||||
if (item!!.score == 0) {
|
||||
text = item.foodName
|
||||
@@ -29,6 +32,12 @@ class SearchFoodAdapter(var list: MutableList<FoodInfo>) :
|
||||
text = item.foodName + (if (item.score != 0) "-${score}%" else "")
|
||||
}
|
||||
isChecked = item.isChecked
|
||||
setTextColor(
|
||||
|
||||
|
||||
if (isChecked) "#FF3232".toColorInt()
|
||||
else "#0A1428".toColorInt()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,8 +14,6 @@ object ApiClient {
|
||||
private const val BASE_URL = "http://device.shuziweidao.com:8889/"
|
||||
|
||||
private const val TIME_OUT = 30L // 超时时间(秒)
|
||||
//todo 临时测试改为5秒
|
||||
// private const val TIME_OUT = 5L // 超时时间(秒)
|
||||
|
||||
private val okHttpClient = OkHttpClient.Builder()
|
||||
.connectTimeout(TIME_OUT, TimeUnit.SECONDS)
|
||||
|
||||
@@ -451,10 +451,15 @@ class MainScreenPresentation(
|
||||
isLoadUnbilledMode = false
|
||||
}, 10000)
|
||||
|
||||
//上次已经识别过人脸
|
||||
step3ShowRecognizeResult(currentUserId!!)
|
||||
if (isAgainLoadData.not()) {
|
||||
//上次已经识别过人脸
|
||||
step3ShowRecognizeResult(currentUserId!!)
|
||||
isAgainLoadData = true
|
||||
}
|
||||
}
|
||||
|
||||
public var isAgainLoadData = false
|
||||
|
||||
private var isFirstOpen = true
|
||||
var startTime = 0L
|
||||
|
||||
@@ -673,9 +678,7 @@ class MainScreenPresentation(
|
||||
var maxKcal = userNutrition?.maxCalorie ?: 1.0
|
||||
Timber.tag(TAG).d("maxKcal = $maxKcal")
|
||||
// 避免0作为被除数
|
||||
if (maxKcal <= 0.0) {
|
||||
maxKcal = 1.0
|
||||
}
|
||||
maxKcal = if (maxKcal <= 0.0) 1.0 else maxKcal
|
||||
Timber.tag(TAG).d("maxKcal 1 = $maxKcal")
|
||||
include.totalKcalTv.text = totalKcal.format2String(2)
|
||||
var totalKcalHeight = (totalKcal / maxKcal).toFloat()
|
||||
@@ -696,6 +699,7 @@ class MainScreenPresentation(
|
||||
val grainIndex = UserNutritionUtils.findCalorieIndex(energy.grain, grainArray)
|
||||
include.customFoodColumn.setImageDrawable(false, grainIndex)
|
||||
include.totalFoodTv.text = grain.format2String(2)
|
||||
columnMax = if (columnMax <= 0.0) 1.0 else columnMax
|
||||
var grainHeight = (grain / columnMax).toFloat()
|
||||
if (grainHeight == 0F) {
|
||||
include.divTotalFoodView.visible()
|
||||
@@ -716,7 +720,6 @@ class MainScreenPresentation(
|
||||
include.customVegetableColumn.setImageDrawable(false, fruitsIndex)
|
||||
include.totalVegetableTv.text = fruitsVegetables.format2String(2)
|
||||
var fruitsHeight = (fruitsVegetables / columnMax).toFloat()
|
||||
|
||||
if (fruitsHeight == 0F) {
|
||||
include.divVegetableView.visible()
|
||||
} else {
|
||||
@@ -852,6 +855,7 @@ class MainScreenPresentation(
|
||||
val faceEntity = compareResult.faceEntity
|
||||
val userId = faceEntity.userName
|
||||
currentUserId = userId
|
||||
isAgainLoadData = false
|
||||
if (userId == null) return@Observer
|
||||
//ToastUtils.showToast("人脸识别成功,userId = $userId")
|
||||
if (currentFood == null) {
|
||||
|
||||
@@ -7,17 +7,15 @@ import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
|
||||
import com.sw.dualscreen.R
|
||||
import com.sw.dualscreen.adapter.SearchFoodAdapter
|
||||
import com.sw.dualscreen.adapter.DialogSearchFoodAdapter
|
||||
import com.sw.dualscreen.databinding.BottomSheetDialogBinding
|
||||
import com.sw.dualscreen.model.response.FoodInfo
|
||||
import com.sw.dualscreen.utils.Debouncer
|
||||
import com.sw.dualscreen.utils.KeyboardUtils
|
||||
import com.sw.dualscreen.viewmodel.UserViewModel
|
||||
import kotlinx.coroutines.launch
|
||||
import timber.log.Timber
|
||||
import androidx.core.graphics.drawable.toDrawable
|
||||
|
||||
@@ -33,7 +31,7 @@ class CustomBottomSheetDialog(
|
||||
// lateinit var adapter: GenericItemAdapter<FoodInfo, ItemSearchFoodInfoBinding>
|
||||
private val searchFoodList = mutableListOf<FoodInfo>()
|
||||
private val adapter by lazy {
|
||||
SearchFoodAdapter(searchFoodList).apply {
|
||||
DialogSearchFoodAdapter(searchFoodList).apply {
|
||||
setOnItemClickListener { adapter, view, position ->
|
||||
searchFoodList.forEachIndexed { index, info ->
|
||||
searchFoodList[index].isChecked = index == position
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:color="#FF5E7585" android:state_checked="false"/>
|
||||
<item android:color="#FFFF3232" android:state_checked="true"/>
|
||||
</selector>
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:color="#FF0A1428" android:state_pressed="false"/>
|
||||
<item android:color="#FFFF3232" android:state_pressed="true"/>
|
||||
</selector>
|
||||
+3
-3
@@ -2,14 +2,14 @@
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:state_checked="false">
|
||||
<shape android:shape="rectangle">
|
||||
<corners android:radius="45dp"/>
|
||||
<solid android:color="#FFE7EFF8"/>
|
||||
<corners android:radius="50dp"/>
|
||||
<solid android:color="@color/transparent"/>
|
||||
<stroke android:color="#FFC4CFDA" android:width="2dp"/>
|
||||
</shape>
|
||||
</item>
|
||||
<item android:state_checked="true">
|
||||
<shape android:shape="rectangle">
|
||||
<corners android:radius="45dp"/>
|
||||
<corners android:radius="50dp"/>
|
||||
<solid android:color="#FFFFF0F0"/>
|
||||
<stroke android:color="#FFFF3232" android:width="2dp"/>
|
||||
</shape>
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:state_pressed="false">
|
||||
<shape android:shape="rectangle">
|
||||
<corners android:radius="50dp"/>
|
||||
<solid android:color="@color/white"/>
|
||||
<stroke android:color="#FFF5F6F8" android:width="2dp"/>
|
||||
</shape>
|
||||
</item>
|
||||
<item android:state_pressed="true">
|
||||
<shape android:shape="rectangle">
|
||||
<corners android:radius="50dp"/>
|
||||
<solid android:color="#FFFFF0F0"/>
|
||||
<stroke android:color="#FFFF3232" android:width="2dp"/>
|
||||
</shape>
|
||||
</item>
|
||||
</selector>
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:state_checked="false">
|
||||
<shape android:shape="rectangle">
|
||||
<corners android:radius="50dp"/>
|
||||
<solid android:color="@color/white"/>
|
||||
<!-- <stroke android:color="#FFC4CFDA" android:width="2dp"/>-->
|
||||
</shape>
|
||||
</item>
|
||||
<item android:state_checked="true">
|
||||
<shape android:shape="rectangle">
|
||||
<corners android:radius="50dp"/>
|
||||
<solid android:color="#FFFFF0F0"/>
|
||||
<stroke android:color="#FFFF3232" android:width="2dp"/>
|
||||
</shape>
|
||||
</item>
|
||||
</selector>
|
||||
@@ -157,8 +157,8 @@
|
||||
android:id="@+id/flPay"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/white"
|
||||
android:visibility="gone">
|
||||
<!-- android:background="@color/white"-->
|
||||
|
||||
<androidx.appcompat.widget.AppCompatButton
|
||||
android:id="@+id/btnPay"
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/bottom_sheet_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1000dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/bottom_sheet_background"
|
||||
android:gravity="center_horizontal"
|
||||
android:orientation="vertical">
|
||||
@@ -62,10 +62,9 @@
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recyclerview"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:minHeight="500dp"
|
||||
android:layout_marginTop="48dp"
|
||||
android:layout_marginBottom="20dp"
|
||||
android:layout_height="700dp"
|
||||
android:layout_marginTop="20dp"
|
||||
android:layout_marginBottom="5dp"
|
||||
android:layout_marginHorizontal="14dp"
|
||||
app:spanCount="2"
|
||||
tools:itemCount="12"
|
||||
|
||||
@@ -40,12 +40,14 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginTop="20dp"
|
||||
android:baselineAligned="false"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<!-- 热量 -->
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
style="@style/takeFoodLayout"
|
||||
android:layout_weight="1.7">
|
||||
android:layout_weight="1.7"
|
||||
android:layout_width="0dp">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/kcalValueLayout"
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/tvFoodName"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="90dp"
|
||||
android:background="@drawable/bg_search_food"
|
||||
android:layout_height="100dp"
|
||||
tools:background="@drawable/bg_text_main"
|
||||
android:ellipsize="end"
|
||||
android:gravity="center"
|
||||
android:maxLines="1"
|
||||
@@ -12,7 +12,7 @@
|
||||
android:layout_marginVertical="14dp"
|
||||
android:paddingHorizontal="15dp"
|
||||
android:textAlignment="center"
|
||||
android:textColor="@color/color_search_food"
|
||||
tools:textColor="@color/black"
|
||||
android:textSize="30sp"
|
||||
android:textStyle="bold"
|
||||
tools:text="肉沫干拌面" />
|
||||
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/tvFoodName"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="100dp"
|
||||
android:background="@drawable/bg_text_dialog"
|
||||
android:ellipsize="end"
|
||||
android:gravity="center"
|
||||
android:maxLines="1"
|
||||
android:layout_marginHorizontal="14dp"
|
||||
android:layout_marginVertical="14dp"
|
||||
android:paddingHorizontal="15dp"
|
||||
android:textAlignment="center"
|
||||
android:textColor="@color/color_text_dialog"
|
||||
android:textSize="30sp"
|
||||
android:textStyle="bold"
|
||||
tools:text="肉沫干拌面" />
|
||||
Reference in New Issue
Block a user