|
@@ -1,11 +1,11 @@
|
|
|
package com.develop.setting.ui
|
|
|
|
|
|
-import android.content.Context
|
|
|
import android.graphics.Rect
|
|
|
-import android.net.wifi.WifiConfiguration
|
|
|
+import android.net.NetworkInfo
|
|
|
import android.net.wifi.WifiManager
|
|
|
import android.os.Bundle
|
|
|
import android.os.CountDownTimer
|
|
|
+import android.os.Handler
|
|
|
import android.util.Log
|
|
|
import android.view.LayoutInflater
|
|
|
import android.view.View
|
|
@@ -28,17 +28,27 @@ import com.develop.base.ext.setVisible
|
|
|
import com.develop.base.manager.WifiData
|
|
|
import com.develop.base.manager.WifiHelp
|
|
|
import com.develop.base.util.GlobalToast
|
|
|
+import com.develop.base.util.MMkvUtils
|
|
|
+import com.develop.common.data_repo.net.Api
|
|
|
+import com.develop.common.data_repo.net.model.request.DeviceInfoBody
|
|
|
+import com.develop.common.data_repo.net.model.response.DevInfoResult
|
|
|
import com.develop.common.event.FinishAtyEvent
|
|
|
+import com.develop.common.event.TuyaEventBus
|
|
|
import com.develop.common.router.Screens
|
|
|
+import com.develop.common.tag.ISTUYA
|
|
|
import com.develop.common.tag.WIFI_FROM_MAIN_SETTING
|
|
|
import com.develop.common.ui.CommonBindingActivity
|
|
|
import com.develop.common.utils.FoucsLinearLayoutManager
|
|
|
+import com.develop.common.utils.TuyaUtils
|
|
|
import com.develop.common.widget.WifiContentView
|
|
|
import com.develop.setting.R
|
|
|
import com.develop.setting.databinding.ActivityWifiListBinding
|
|
|
import com.drake.brv.utils.bindingAdapter
|
|
|
import com.drake.brv.utils.models
|
|
|
import com.drake.brv.utils.setup
|
|
|
+import com.drake.net.Post
|
|
|
+import com.drake.net.utils.scopeNetLife
|
|
|
+import com.google.gson.Gson
|
|
|
import com.yanzhenjie.permission.AndPermission
|
|
|
import com.yanzhenjie.permission.runtime.Permission
|
|
|
import org.greenrobot.eventbus.EventBus
|
|
@@ -54,6 +64,7 @@ class WifiListActivity : CommonBindingActivity<ActivityWifiListBinding>(),
|
|
|
private var selectedPosition = -1
|
|
|
|
|
|
private var timer: CountDownTimer? = null
|
|
|
+ private var isSuccess = false
|
|
|
|
|
|
override fun createViewBinding(inflater: LayoutInflater): ActivityWifiListBinding {
|
|
|
return ActivityWifiListBinding.inflate(inflater)
|
|
@@ -89,16 +100,16 @@ class WifiListActivity : CommonBindingActivity<ActivityWifiListBinding>(),
|
|
|
if (isBrand036I()) {
|
|
|
binding.ivBanner.setBackgroundResource(com.develop.common.R.drawable.guide_bg_036i)
|
|
|
binding.ivLogo.setVisible()
|
|
|
- }else if (isBrand054A()){
|
|
|
+ } else if (isBrand054A()) {
|
|
|
binding.ivBanner.setBackgroundResource(com.develop.common.R.drawable.account_background_054a)
|
|
|
binding.ivLogo.setGone()
|
|
|
- }else if (isBrand062()){
|
|
|
+ } else if (isBrand062()) {
|
|
|
binding.ivBanner.setBackgroundResource(com.develop.common.R.drawable.account_background_062a)
|
|
|
binding.ivLogo.setGone()
|
|
|
- }else if (isBrand011A()){
|
|
|
+ } else if (isBrand011A()) {
|
|
|
binding.ivBanner.setBackgroundResource(com.develop.common.R.drawable.account_background_011a)
|
|
|
binding.ivLogo.setGone()
|
|
|
- }else if (getSN().startsWith("045")){
|
|
|
+ } else if (getSN().startsWith("045")) {
|
|
|
binding.ivBanner.setBackgroundResource(com.develop.common.R.drawable.account_background_045a)
|
|
|
binding.ivLogo.setGone()
|
|
|
}
|
|
@@ -183,19 +194,19 @@ class WifiListActivity : CommonBindingActivity<ActivityWifiListBinding>(),
|
|
|
private fun initListener() {
|
|
|
binding.tvSkin.setOnClickListener {
|
|
|
if (NetworkUtils.isConnected()) {
|
|
|
- if (getGoneLogin()){
|
|
|
- if (isBrand062()){
|
|
|
+ if (getGoneLogin()) {
|
|
|
+ if (isBrand062()) {
|
|
|
navigateTo(Screens.Main.ENTRANCE_CHOSEN_TWO)
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
navigateTo(Screens.Main.ENTRANCE_CHOSEN)
|
|
|
}
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
navigateTo(Screens.Auth.MEMBER)
|
|
|
}
|
|
|
} else {
|
|
|
- if (isBrand062()){
|
|
|
+ if (isBrand062()) {
|
|
|
navigateTo(Screens.Main.ENTRANCE_CHOSEN_TWO)
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
navigateTo(Screens.Main.ENTRANCE_CHOSEN)
|
|
|
}
|
|
|
|
|
@@ -209,10 +220,10 @@ class WifiListActivity : CommonBindingActivity<ActivityWifiListBinding>(),
|
|
|
if (isFromMainSetting) {
|
|
|
finish()
|
|
|
} else {
|
|
|
- if (getGoneLogin()){
|
|
|
+ if (getGoneLogin()) {
|
|
|
navigateTo(Screens.Main.ENTRANCE_CHOSEN)
|
|
|
finish()
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
navigateTo(Screens.Auth.MEMBER)
|
|
|
}
|
|
|
finish()
|
|
@@ -236,6 +247,14 @@ class WifiListActivity : CommonBindingActivity<ActivityWifiListBinding>(),
|
|
|
}.setAlreadyConnectionCallback {
|
|
|
dismissPlainDialog()
|
|
|
}.setNetworkStateChangedListener {
|
|
|
+ //连接成功 // 处理涂鸦功能,出厂设置后,没设置wifi 会导致请求超时
|
|
|
+ if (it == NetworkInfo.DetailedState.CONNECTED) {
|
|
|
+ if (!isSuccess) {
|
|
|
+ //设置 isSuccess 避免重复请求
|
|
|
+ isSuccess = true
|
|
|
+ Handler().postDelayed({ getDevInfo() }, 1000)
|
|
|
+ }
|
|
|
+ }
|
|
|
dismissPlainDialog()
|
|
|
}.build()
|
|
|
|
|
@@ -293,6 +312,36 @@ class WifiListActivity : CommonBindingActivity<ActivityWifiListBinding>(),
|
|
|
binding.wifiRecycler.scrollY = deltaHeight
|
|
|
}
|
|
|
|
|
|
+ //获取是否有涂鸦功能
|
|
|
+ fun getDevInfo() {
|
|
|
+ //已经有涂鸦功能,避免再次请求
|
|
|
+ if (MMkvUtils.getBool(ISTUYA, false)) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ scopeNetLife {
|
|
|
+ val result = Post<DevInfoResult>(Api.DEV_INFO) {
|
|
|
+ body = DeviceInfoBody.genDeviceInfoBody()
|
|
|
+ }.await()
|
|
|
+ getInitTuya(result)
|
|
|
+ }.catch {
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ fun getInitTuya(result: DevInfoResult) {
|
|
|
+ var gson = Gson()
|
|
|
+ if (result.tuyaLicense != null) {
|
|
|
+ result.tuyaLicense?.let {
|
|
|
+ TuyaUtils.mAk = it.ak
|
|
|
+ TuyaUtils.mPid = it.pid
|
|
|
+ TuyaUtils.mUid = it.uuid
|
|
|
+ TuyaUtils.initSDK(this, "1.0.0")
|
|
|
+ //涂鸦存值判断有涂鸦功能
|
|
|
+ MMkvUtils.save(ISTUYA, true)
|
|
|
+ if (isFromMainSetting) {
|
|
|
+ EventBus.getDefault().post(TuyaEventBus())
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
}
|