SettingMainActivity.kt 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. package com.develop.setting.ui
  2. import android.content.Intent
  3. import android.graphics.Rect
  4. import android.net.NetworkInfo
  5. import android.os.Bundle
  6. import android.util.Log
  7. import android.view.LayoutInflater
  8. import android.view.View
  9. import android.widget.ImageView
  10. import androidx.appcompat.widget.AppCompatTextView
  11. import androidx.recyclerview.widget.RecyclerView
  12. import com.develop.base.ext.load
  13. import com.alibaba.android.arouter.facade.annotation.Route
  14. import com.blankj.utilcode.util.ToastUtils
  15. import com.develop.base.ext.getSN
  16. import com.develop.base.ext.isBrand036I
  17. import com.develop.base.ext.navigateTo
  18. import com.develop.base.ext.resId2Dimension
  19. import com.develop.base.ext.setVisible
  20. import com.develop.base.ext.src
  21. import com.develop.base.ext.updateText
  22. import com.develop.base.manager.WifiHelp
  23. import com.develop.base.util.FileKit
  24. import com.develop.common.data_repo.db.DataFactory
  25. import com.develop.common.data_repo.db.SettingModel
  26. import com.develop.common.data_repo.db.SettingType
  27. import com.develop.common.router.Screens
  28. import com.develop.common.tag.LANGUAGE_FROM_SETTING
  29. import com.develop.common.tag.WIFI_FROM_MAIN_SETTING
  30. import com.develop.common.ui.CommonBindingActivity
  31. import com.develop.setting.R
  32. import com.develop.setting.databinding.ActivitySettingMainBinding
  33. import com.drake.brv.utils.grid
  34. import com.drake.brv.utils.models
  35. import com.drake.brv.utils.setup
  36. import com.kuyuntech.cofarcooking.device.sdk.constant.core.DevStatus
  37. import com.kuyuntech.cofarcooking.device.sdk.util.core.CofarSDK
  38. @Route(path = Screens.Setting.MAIN_SETTING)
  39. class SettingMainActivity : CommonBindingActivity<ActivitySettingMainBinding>() {
  40. private var dataList = mutableListOf<SettingModel>()
  41. override fun createViewBinding(inflater: LayoutInflater): ActivitySettingMainBinding {
  42. return ActivitySettingMainBinding.inflate(layoutInflater)
  43. }
  44. override fun onCreate(savedInstanceState: Bundle?) {
  45. super.onCreate(savedInstanceState)
  46. var ctx = this
  47. dataList = if (getSN().startsWith("010D")) {
  48. DataFactory.genSetting010DModesList(resources)
  49. } else {
  50. DataFactory.genSettingModesList(resources)
  51. }
  52. binding.tvTitle.updateText(getString(com.develop.common.R.string.settings))
  53. binding.ivClose.setVisible()
  54. binding.ivClose.setImageResource(com.develop.common.R.drawable.ic_close)
  55. binding.ivClose.setOnClickListener {
  56. finish()
  57. }
  58. binding.mainSettingRecycler.apply {
  59. addItemDecoration(object : RecyclerView.ItemDecoration() {
  60. override fun getItemOffsets(
  61. outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State
  62. ) {
  63. super.getItemOffsets(outRect, view, parent, state)
  64. outRect.top = dp77
  65. }
  66. })
  67. grid(4)
  68. setup {
  69. addType<SettingModel>(R.layout.item_setting_main_view)
  70. onBind {
  71. val model = getModel<SettingModel>()
  72. findView<AppCompatTextView>(R.id.tv_name).updateText(model.name)
  73. findView<ImageView>(R.id.iv_icon).src = model.resId
  74. }
  75. R.id.iv_icon.onClick {
  76. Log.d("dddddd", "---")
  77. when (dataList[absoluteAdapterPosition].type) {
  78. SettingType.BRIGHTNESS -> {
  79. navigateTo(Screens.Setting.BRIGHTNESS)
  80. }
  81. SettingType.SOUND -> {
  82. navigateTo(Screens.Setting.SOUND)
  83. }
  84. SettingType.WIFI -> {
  85. navigateTo(Screens.Setting.WIFI) {
  86. val bundle = Bundle()
  87. bundle.putBoolean(WIFI_FROM_MAIN_SETTING, true)
  88. with(bundle)
  89. }
  90. }
  91. SettingType.USER_ACCOUNT -> {
  92. navigateTo(Screens.Auth.MEMBER) {
  93. withBoolean("enter_from_home", true)
  94. }
  95. }
  96. SettingType.LANGUAGE -> {
  97. navigateTo(Screens.Setting.LANGUAGE) {
  98. val bundle = Bundle()
  99. bundle.putBoolean(LANGUAGE_FROM_SETTING, true)
  100. with(bundle)
  101. }
  102. }
  103. SettingType.ABOUT -> {
  104. navigateTo(Screens.Setting.ABOUT)
  105. }
  106. SettingType.RESTORE_FACTORY_SETTINGS -> {
  107. navigateTo(Screens.Setting.RESTORE)
  108. }
  109. SettingType.STORAGE -> {
  110. openFileManager()
  111. }
  112. SettingType.TUYA -> {
  113. if (CofarSDK.devInfo().status !== DevStatus.STOP.toInt()) {
  114. ToastUtils.showShort(getString(com.develop.common.R.string.change_lang_tips))
  115. } else {
  116. if (NetworkInfo.DetailedState.CONNECTED == WifiHelp.Build(ctx)
  117. .build().getDetailedState()
  118. ) {
  119. navigateTo(Screens.Setting.TUYA)
  120. } else {
  121. navigateTo(Screens.Setting.WIFI) {
  122. val bundle = Bundle()
  123. bundle.putBoolean(WIFI_FROM_MAIN_SETTING, true)
  124. with(bundle)
  125. }
  126. }
  127. }
  128. }
  129. }
  130. }
  131. }
  132. }.models = dataList
  133. }
  134. // 打开文件管理器选择文件
  135. private fun openFileManager() {
  136. // 打开文件管理器选择文件
  137. val intent = Intent(Intent.ACTION_GET_CONTENT)
  138. intent.type = "application/zip"
  139. intent.addCategory(Intent.CATEGORY_OPENABLE)
  140. startActivityForResult(intent, 100)
  141. }
  142. override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
  143. super.onActivityResult(requestCode, resultCode, data)
  144. if (requestCode == 100) {
  145. data?.data?.apply {
  146. val path = FileKit.getPath(this@SettingMainActivity, this)
  147. }
  148. }
  149. }
  150. companion object {
  151. var dp156 = (com.develop.common.R.dimen.convert_156px).resId2Dimension().toInt()
  152. var dp40 = (com.develop.common.R.dimen.convert_40px).resId2Dimension().toInt()
  153. var dp77 = (com.develop.common.R.dimen.convert_77px).resId2Dimension().toInt()
  154. }
  155. }