|
@@ -1,7 +1,6 @@
|
|
|
package com.develop.main.ui
|
|
|
|
|
|
import android.content.Context
|
|
|
-import android.content.res.AssetManager
|
|
|
import android.os.Bundle
|
|
|
import android.view.LayoutInflater
|
|
|
import android.view.ViewGroup
|
|
@@ -9,19 +8,18 @@ import android.widget.ImageView
|
|
|
import androidx.appcompat.widget.AppCompatTextView
|
|
|
import androidx.recyclerview.widget.LinearSnapHelper
|
|
|
import androidx.recyclerview.widget.RecyclerView
|
|
|
-import com.develop.airfryer.viewmodel.WorkMode
|
|
|
+import com.develop.common.bean.WorkMode
|
|
|
import com.develop.base.ext.load
|
|
|
import com.develop.base.ext.navigateTo
|
|
|
import com.develop.base.ext.resId2Dimension
|
|
|
import com.develop.base.ext.updateText
|
|
|
import com.develop.base.util.TopResumedAtyHolder
|
|
|
-import com.develop.common.data_repo.db.DataFactory
|
|
|
-import com.develop.common.data_repo.db.ModelsModel
|
|
|
import com.develop.common.data_repo.db.ModesType
|
|
|
import com.develop.common.dialog.CancelConfirmDialog
|
|
|
import com.develop.common.router.Screens
|
|
|
import com.develop.common.tag.MODE_TYPE
|
|
|
import com.develop.common.ui.CommonBVMFragment
|
|
|
+import com.develop.common.utils.ConfigUtils
|
|
|
import com.develop.main.R
|
|
|
import com.develop.main.databinding.FragmentModesBinding
|
|
|
import com.develop.main.viewmodel.HomeViewModel
|
|
@@ -61,21 +59,7 @@ class ModesFragment : CommonBVMFragment<FragmentModesBinding, HomeViewModel>() {
|
|
|
}
|
|
|
|
|
|
|
|
|
- fun loadJSONFromAsset(context: Context, fileName: String): JSONObject? {
|
|
|
- return try {
|
|
|
- val inputStream = context.assets.open(fileName)
|
|
|
- val size = inputStream.available()
|
|
|
- val buffer = ByteArray(size)
|
|
|
- inputStream.read(buffer)
|
|
|
- inputStream.close()
|
|
|
|
|
|
- val jsonString = String(buffer, Charset.defaultCharset())
|
|
|
- JSONObject(jsonString)
|
|
|
- } catch (ex: IOException) {
|
|
|
- ex.printStackTrace()
|
|
|
- null
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
|
@@ -86,18 +70,10 @@ class ModesFragment : CommonBVMFragment<FragmentModesBinding, HomeViewModel>() {
|
|
|
|
|
|
private fun initView() {
|
|
|
|
|
|
- val configJson = this.context?.let { loadJSONFromAsset(it, "config.json") }
|
|
|
- val workModes = configJson?.getJSONArray( if (CofarSDK.devInfo().devMode == DevModes.SOUP) "soupWorkModes" else "airFryerWorkModes");
|
|
|
- var modes = ArrayList<WorkMode>();
|
|
|
- val len = workModes?.length();
|
|
|
- for (i in 0 until len!!) {
|
|
|
- val element = workModes.getJSONObject(i)
|
|
|
- // 处理数组元素,例如打印它们
|
|
|
- var model = WorkMode(name = element.getString("name"), icon = element.getString("icon"), bg = element.getString("bg"), type = element.getString("type"))
|
|
|
- modes.add(model)
|
|
|
- }
|
|
|
+ val configJson = ConfigUtils.loadConfig()
|
|
|
+ var modes = configJson?.workModes?.filter { it.devMode == CofarSDK.devInfo().devMode }
|
|
|
+
|
|
|
|
|
|
- modeTypeList = DataFactory.modesTypeList
|
|
|
binding.galleryRecycle.apply {
|
|
|
linear(RecyclerView.HORIZONTAL)
|
|
|
setup {
|
|
@@ -116,7 +92,7 @@ class ModesFragment : CommonBVMFragment<FragmentModesBinding, HomeViewModel>() {
|
|
|
|
|
|
val devInfo = CofarSDK.devInfo();
|
|
|
|
|
|
- if( devInfo.status != DevStatus.STOP.toInt() && devInfo.runningInstId != modeTypeList[absoluteAdapterPosition].name){
|
|
|
+ if( devInfo.status != DevStatus.STOP.toInt() && devInfo.runningInstId != modes?.get(absoluteAdapterPosition)?.type){
|
|
|
runningWeightTips()
|
|
|
return@onClick
|
|
|
}
|
|
@@ -126,7 +102,7 @@ class ModesFragment : CommonBVMFragment<FragmentModesBinding, HomeViewModel>() {
|
|
|
|
|
|
|
|
|
val bundle = Bundle()
|
|
|
- bundle.putString(MODE_TYPE, modeTypeList[absoluteAdapterPosition].name)
|
|
|
+ bundle.putString(MODE_TYPE, modes?.get(absoluteAdapterPosition)?.type)
|
|
|
with(bundle)
|
|
|
}
|
|
|
}
|