增加室内整理工具扫描业务
This commit is contained in:
parent
d0b85d649a
commit
a970ca1992
@ -65,6 +65,7 @@
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name=".ui.activity.map.MainActivity"
|
||||
android:exported="false"
|
||||
@ -73,10 +74,13 @@
|
||||
android:theme="@style/Theme.OMQualityInspection" />
|
||||
|
||||
<activity
|
||||
android:name=".ui.activity.scan.QRCodeActivity"
|
||||
android:name=".ui.activity.scan.QrCodeActivity"
|
||||
android:theme="@style/Theme.OMQualityInspection"
|
||||
android:screenOrientation="portrait" />
|
||||
|
||||
<activity
|
||||
android:name=".ui.activity.scan.QRCodeResultActivity"
|
||||
android:theme="@style/Theme.OMQualityInspection"
|
||||
android:screenOrientation="portrait" />
|
||||
|
||||
<meta-data
|
||||
|
@ -48,7 +48,7 @@ class Constant {
|
||||
/**
|
||||
* 室内整理工具IP
|
||||
*/
|
||||
lateinit var INDOOR_IPS: String
|
||||
lateinit var INDOOR_IP: String
|
||||
|
||||
const val DEBUG = true
|
||||
|
||||
|
@ -31,5 +31,5 @@ interface NetworkService {
|
||||
/**
|
||||
* 连接室内整理工具
|
||||
*/
|
||||
suspend fun connectIndoorTools(url: String): NetResult<DefaultResponse<QRCodeBean>>
|
||||
suspend fun connectIndoorTools(url: String): NetResult<QRCodeBean>
|
||||
}
|
@ -77,11 +77,11 @@ class NetworkServiceImpl @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun connectIndoorTools(url: String): NetResult<DefaultResponse<QRCodeBean>> =
|
||||
override suspend fun connectIndoorTools(url: String): NetResult<QRCodeBean> =
|
||||
//在IO线程中运行
|
||||
withContext(Dispatchers.IO) {
|
||||
return@withContext try {
|
||||
val result = netApi.retrofitConnectIndoorTools(url)
|
||||
val result = netApi.retrofitConnectIndoorTools(url = url)
|
||||
if (result.isSuccessful) {
|
||||
if (result.code() == 200) {
|
||||
NetResult.Success(result.body())
|
||||
|
@ -68,10 +68,11 @@ interface RetrofitNetworkServiceAPI {
|
||||
|
||||
|
||||
/**
|
||||
* 获取离线地图城市列表
|
||||
* 连接室内整理工具
|
||||
*/
|
||||
@GET("/drdc/MapDownload/maplist")
|
||||
suspend fun retrofitConnectIndoorTools(@Url url: String): Response<DefaultResponse<QRCodeBean>>
|
||||
@Streaming
|
||||
@GET
|
||||
suspend fun retrofitConnectIndoorTools(@Url url: String): Response<QRCodeBean>
|
||||
|
||||
@Headers("Content-Type: application/json")
|
||||
@POST("/devcp/uploadSceneProblem")
|
||||
|
@ -6,11 +6,13 @@ import android.widget.Toast
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.navinfo.omqs.Constant
|
||||
import com.navinfo.omqs.bean.QRCodeBean
|
||||
import com.navinfo.omqs.bean.SysUserBean
|
||||
import com.navinfo.omqs.http.DefaultResponse
|
||||
import com.navinfo.omqs.http.NetResult
|
||||
import com.navinfo.omqs.http.NetworkService
|
||||
import com.navinfo.omqs.ui.activity.login.LoginStatus
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
@ -19,54 +21,28 @@ import kotlinx.coroutines.withContext
|
||||
import java.io.IOException
|
||||
import javax.inject.Inject
|
||||
|
||||
enum class QRCodeStatus {
|
||||
/**
|
||||
* 访问服务器登陆中
|
||||
*/
|
||||
LOGIN_STATUS_NET_LOADING,
|
||||
|
||||
/**
|
||||
* 访问离线地图列表
|
||||
*/
|
||||
LOGIN_STATUS_NET_OFFLINE_MAP,
|
||||
|
||||
/**
|
||||
* 初始化文件夹
|
||||
*/
|
||||
LOGIN_STATUS_FOLDER_INIT,
|
||||
|
||||
/**
|
||||
* 创建文件夹失败
|
||||
*/
|
||||
LOGIN_STATUS_FOLDER_FAILURE,
|
||||
|
||||
enum class QrCodeStatus {
|
||||
/**
|
||||
* 网络访问失败
|
||||
*/
|
||||
LOGIN_STATUS_NET_FAILURE,
|
||||
|
||||
QR_CODE_STATUS_NET_FAILURE,
|
||||
/**
|
||||
* 成功
|
||||
*/
|
||||
LOGIN_STATUS_SUCCESS,
|
||||
|
||||
/**
|
||||
* 取消
|
||||
*/
|
||||
LOGIN_STATUS_CANCEL,
|
||||
QR_CODE_STATUS_SUCCESS
|
||||
}
|
||||
|
||||
|
||||
@HiltViewModel
|
||||
class QRCodeViewModel @Inject constructor(
|
||||
class QrCodeViewModel @Inject constructor(
|
||||
private val networkService: NetworkService
|
||||
) : ViewModel() {
|
||||
//用户信息
|
||||
val qrCodeBean: MutableLiveData<QRCodeBean> = MutableLiveData()
|
||||
|
||||
//是不是连接成功
|
||||
val qrCodeStatus: MutableLiveData<QRCodeStatus> = MutableLiveData()
|
||||
val qrCodeStatus: MutableLiveData<QrCodeStatus> = MutableLiveData()
|
||||
|
||||
var jobQRCodeStatus: Job? = null;
|
||||
|
||||
init {
|
||||
qrCodeBean.value = QRCodeBean()
|
||||
@ -98,12 +74,25 @@ class QRCodeViewModel @Inject constructor(
|
||||
val url = "http://$ipTemp:8080/sensor/service/keepalive"
|
||||
when (val result = networkService.connectIndoorTools(url)) {
|
||||
is NetResult.Success<*> -> {
|
||||
|
||||
if (result.data != null) {
|
||||
try {
|
||||
val defaultUserResponse =
|
||||
result.data as DefaultResponse<SysUserBean>
|
||||
if (defaultUserResponse.success) {
|
||||
|
||||
val defaultUserResponse = result.data as QRCodeBean
|
||||
|
||||
if (defaultUserResponse.errcode==0) {
|
||||
|
||||
Constant.INDOOR_IP = ipTemp
|
||||
|
||||
qrCodeStatus.postValue(QrCodeStatus.QR_CODE_STATUS_SUCCESS)
|
||||
|
||||
withContext(Dispatchers.Main) {
|
||||
Toast.makeText(
|
||||
context,
|
||||
"连接室内整理工具成功。",
|
||||
Toast.LENGTH_LONG
|
||||
).show()
|
||||
}
|
||||
} else {
|
||||
withContext(Dispatchers.Main) {
|
||||
Toast.makeText(
|
||||
@ -116,6 +105,13 @@ class QRCodeViewModel @Inject constructor(
|
||||
}
|
||||
|
||||
} catch (e: IOException) {
|
||||
withContext(Dispatchers.Main) {
|
||||
Toast.makeText(
|
||||
context,
|
||||
"${e.message}",
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -129,6 +125,7 @@ class QRCodeViewModel @Inject constructor(
|
||||
)
|
||||
.show()
|
||||
}
|
||||
qrCodeStatus.postValue(QrCodeStatus.QR_CODE_STATUS_NET_FAILURE)
|
||||
}
|
||||
|
||||
is NetResult.Failure<*> -> {
|
||||
@ -140,6 +137,7 @@ class QRCodeViewModel @Inject constructor(
|
||||
)
|
||||
.show()
|
||||
}
|
||||
qrCodeStatus.postValue(QrCodeStatus.QR_CODE_STATUS_NET_FAILURE)
|
||||
}
|
||||
|
||||
else -> {}
|
||||
@ -148,4 +146,9 @@ class QRCodeViewModel @Inject constructor(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCleared() {
|
||||
super.onCleared()
|
||||
}
|
||||
|
||||
}
|
@ -1,39 +1,35 @@
|
||||
package com.navinfo.omqs.ui.activity.scan
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Intent
|
||||
import android.graphics.Rect
|
||||
import android.graphics.RectF
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import androidx.activity.viewModels
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.camera.core.ImageCapture
|
||||
import androidx.camera.view.LifecycleCameraController
|
||||
import androidx.databinding.DataBindingUtil
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.navinfo.omqs.R
|
||||
import com.navinfo.omqs.databinding.ActivityQrCodeBinding
|
||||
import com.navinfo.omqs.ui.activity.login.LoginViewModel
|
||||
import com.navinfo.omqs.ui.activity.BaseActivity
|
||||
import com.navinfo.omqs.ui.listener.QRCodeAnalyser
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import java.util.concurrent.ExecutorService
|
||||
import java.util.concurrent.Executors
|
||||
import androidx.lifecycle.Observer
|
||||
import com.navinfo.omqs.ui.activity.login.LoginStatus
|
||||
|
||||
/**
|
||||
* date:2021/6/18
|
||||
* author:zhangteng
|
||||
* date:2023/6/18
|
||||
* author:qj
|
||||
* description:二维码扫描
|
||||
*/
|
||||
class QRCodeActivity : AppCompatActivity() {
|
||||
@AndroidEntryPoint
|
||||
class QrCodeActivity : BaseActivity() {
|
||||
private lateinit var binding: ActivityQrCodeBinding
|
||||
private lateinit var lifecycleCameraController: LifecycleCameraController
|
||||
private lateinit var cameraExecutor: ExecutorService
|
||||
private val viewModel by viewModels<QRCodeViewModel>()
|
||||
|
||||
private val viewModel by viewModels<QrCodeViewModel>()
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
@ -43,9 +39,29 @@ class QRCodeActivity : AppCompatActivity() {
|
||||
binding.lifecycleOwner = this
|
||||
binding.activity = this
|
||||
|
||||
initView()
|
||||
initController()
|
||||
}
|
||||
|
||||
private fun initView() {
|
||||
//登录校验,初始化成功
|
||||
viewModel.qrCodeStatus.observe(this, qrCodeObserve)
|
||||
}
|
||||
|
||||
/*
|
||||
* 监听扫描结果
|
||||
* */
|
||||
private val qrCodeObserve = Observer<QrCodeStatus> {
|
||||
when (it) {
|
||||
QrCodeStatus.QR_CODE_STATUS_SUCCESS -> {
|
||||
finish()
|
||||
}
|
||||
QrCodeStatus.QR_CODE_STATUS_NET_FAILURE -> {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility", "UnsafeOptInUsageError")
|
||||
private fun initController() {
|
||||
cameraExecutor = Executors.newSingleThreadExecutor()
|
||||
@ -92,15 +108,18 @@ class QRCodeActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
private fun intentToResult(result: String) {
|
||||
viewModel.connect(this, result)
|
||||
|
||||
Log.e("qj", "QRCodeActivity === $result")
|
||||
|
||||
viewModel.connect(this, result)
|
||||
|
||||
/* val intent = Intent(this, QRCodeResultActivity::class.java)
|
||||
intent.putExtra(QRCodeResultActivity.RESULT_KEY, result)
|
||||
startActivity(intent)
|
||||
finish()*/
|
||||
}
|
||||
|
||||
|
||||
private var scaleX = 0f
|
||||
private var scaleY = 0f
|
||||
|
@ -22,7 +22,7 @@ import com.navinfo.omqs.db.ImportOMDBHelper
|
||||
import com.navinfo.omqs.hilt.ImportOMDBHiltFactory
|
||||
import com.navinfo.omqs.tools.CoroutineUtils
|
||||
import com.navinfo.omqs.ui.fragment.BaseFragment
|
||||
import com.navinfo.omqs.ui.activity.scan.QRCodeActivity
|
||||
import com.navinfo.omqs.ui.activity.scan.QrCodeActivity
|
||||
import com.permissionx.guolindev.PermissionX
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import org.oscim.core.GeoPoint
|
||||
@ -142,7 +142,7 @@ class PersonalCenterFragment(private var backListener: (() -> Unit?)? = null) :
|
||||
}
|
||||
|
||||
private fun intentTOQRCode() {
|
||||
var intent = Intent(context, QRCodeActivity::class.java);
|
||||
var intent = Intent(context, QrCodeActivity::class.java);
|
||||
startActivity(intent)
|
||||
}
|
||||
|
||||
|
@ -7,15 +7,13 @@
|
||||
|
||||
<data>
|
||||
|
||||
<import type="android.view.View" />
|
||||
|
||||
<variable
|
||||
name="activity"
|
||||
type="com.navinfo.omqs.ui.activity.scan.QRCodeActivity" />
|
||||
type="com.navinfo.omqs.ui.activity.scan.QrCodeActivity" />
|
||||
|
||||
<variable
|
||||
name="qrCodeModel"
|
||||
type="com.navinfo.omqs.ui.activity.scan.QRCodeViewModel" />
|
||||
type="com.navinfo.omqs.ui.activity.scan.QrCodeViewModel" />
|
||||
</data>
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
|
Loading…
x
Reference in New Issue
Block a user