fix: 合并冲突

This commit is contained in:
2023-04-24 10:56:29 +08:00
52 changed files with 1497 additions and 447 deletions

View File

@@ -29,10 +29,10 @@ open abstract class PermissionsActivity : BaseActivity() {
//定位权限
permissionList.add(Permission.ACCESS_FINE_LOCATION)
permissionList.add(Permission.ACCESS_COARSE_LOCATION)
// //android10
// if (Build.VERSION.SDK_INT == Build.VERSION_CODES.Q) {
//android10
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.Q) {
// permissionList.add(Permission.ACCESS_BACKGROUND_LOCATION)
// }
}
XXPermissions.with(this)
// 申请单个权限
.permission(permissionList)

View File

@@ -4,6 +4,8 @@ import android.os.Bundle
import androidx.activity.viewModels
import androidx.core.view.WindowCompat
import androidx.databinding.DataBindingUtil
import androidx.lifecycle.ViewModelProvider
import com.blankj.utilcode.util.ToastUtils
import androidx.lifecycle.lifecycleScope
import androidx.navigation.findNavController
import com.navinfo.collect.library.map.NIMapController
@@ -14,6 +16,8 @@ import com.navinfo.omqs.databinding.ActivityMainBinding
import com.navinfo.omqs.http.offlinemapdownload.OfflineMapDownloadManager
import com.navinfo.omqs.system.SystemConstant
import com.navinfo.omqs.ui.activity.BaseActivity
import com.navinfo.omqs.ui.fragment.evaluationresult.EvaluationResultFragment
import com.navinfo.omqs.ui.fragment.evaluationresult.EvaluationResultViewModel
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject
@@ -52,8 +56,12 @@ class MainActivity : BaseActivity() {
binding.mainActivity = this
//给xml传递viewModel对象
binding.viewModel = viewModel
// lifecycle.addObserver(viewModel)
lifecycleScope
viewModel.liveDataQsRecordIdList.observe(this) {
//处理页面跳转
viewModel.navigation(this, it)
}
}
override fun onStart() {
@@ -63,9 +71,11 @@ class MainActivity : BaseActivity() {
mapController.locationLayerHandler.startLocation()
//启动轨迹存储
mapController.locationLayerHandler.setNiLocationListener(NiLocationListener {
binding!!.viewModel!!.addSaveTrace(it)
binding!!.viewModel!!.startSaveTraceThread(this)
viewModel.addSaveTrace(it)
// binding.viewModel!!.startSaveTraceThread(this)
})
//显示轨迹图层
// mapController.layerManagerHandler.showNiLocationLayer(Constant.DATA_PATH+ SystemConstant.USER_ID+"/trace.sqlite")
mapController.layerManagerHandler.showNiLocationLayer()
}
@@ -96,6 +106,7 @@ class MainActivity : BaseActivity() {
* 打开相机预览
*/
fun openCamera() {
binding.viewModel!!.onClickCameraButton(this)
//显示轨迹图层
//binding!!.viewModel!!.onClickCameraButton(this)
}
@@ -108,7 +119,7 @@ class MainActivity : BaseActivity() {
naviController.navigate(R.id.EvaluationResultFragment)
}
override fun onBackPressed() {
super.onBackPressed()
}
// override fun onBackPressed() {
// super.onBackPressed()
// }
}

View File

@@ -2,12 +2,16 @@ package com.navinfo.omqs.ui.activity.map
import android.content.Context
import android.content.DialogInterface
import android.os.Bundle
import android.util.Log
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.navigation.findNavController
import com.blankj.utilcode.util.ToastUtils
import com.navinfo.collect.library.data.dao.impl.TraceDataBase
import com.navinfo.collect.library.data.entity.NiLocation
import com.navinfo.collect.library.map.NIMapController
import com.navinfo.collect.library.map.handler.OnQsRecordItemClickListener
import com.navinfo.collect.library.utils.GeometryTools
import com.navinfo.collect.library.utils.GeometryToolsKt
import com.navinfo.omqs.Constant
@@ -19,7 +23,6 @@ import dagger.hilt.android.lifecycle.HiltViewModel
import io.realm.RealmSet
import org.oscim.core.GeoPoint
import org.videolan.libvlc.LibVlcUtil
import java.util.*
import javax.inject.Inject
/**
@@ -30,9 +33,19 @@ class MainViewModel @Inject constructor(
private val mapController: NIMapController,
) : ViewModel() {
val liveDataQsRecordIdList = MutableLiveData<List<String>>()
private var mCameraDialog: CommonDialog? = null
private var niLocationList:MutableList<NiLocation> = ArrayList<NiLocation>()
private var niLocationList: MutableList<NiLocation> = ArrayList<NiLocation>()
init {
mapController.layerManagerHandler.setOnQsRecordItemClickListener(object :
OnQsRecordItemClickListener {
override fun onQsRecordList(list: MutableList<String>) {
liveDataQsRecordIdList.value = list
}
})
}
/**
* 点击我的位置,回到我的位置
@@ -46,14 +59,21 @@ class MainViewModel @Inject constructor(
}
//点击相机按钮
fun onClickCameraButton(context: Context){
fun onClickCameraButton(context: Context) {
Log.e("qj", LibVlcUtil.hasCompatibleCPU(context).toString())
ToastUtils.showShort("点击了相机")
if (mCameraDialog == null) {
mCameraDialog = CommonDialog(context, context.resources.getDimension(R.dimen.head_img_width).toInt() * 3 + context.resources.getDimension(R.dimen.ten).toInt() + context.resources.getDimension(R.dimen.twenty_four).toInt(), context.resources.getDimension(R.dimen.head_img_width).toInt() + 10, 1)
mCameraDialog = CommonDialog(
context,
context.resources.getDimension(R.dimen.head_img_width)
.toInt() * 3 + context.resources.getDimension(R.dimen.ten)
.toInt() + context.resources.getDimension(R.dimen.twenty_four).toInt(),
context.resources.getDimension(R.dimen.head_img_width).toInt() + 10,
1
)
mCameraDialog!!.setCancelable(true)
}
mCameraDialog!!.openCamear(mCameraDialog!!.getmShareUtil().continusTakePhotoState)
@@ -62,10 +82,11 @@ class MainViewModel @Inject constructor(
mCameraDialog!!.hideLoading()
mCameraDialog!!.stopVideo()
try {
if (!mCameraDialog!!.getmShareUtil().connectstate){
if (!mCameraDialog!!.getmShareUtil().connectstate) {
mCameraDialog!!.updateCameraResources(1, mCameraDialog!!.getmDeviceNum())
}
TakePhotoManager.getInstance().getCameraVedioClent(mCameraDialog!!.getmDeviceNum()).StopSearch()
TakePhotoManager.getInstance().getCameraVedioClent(mCameraDialog!!.getmDeviceNum())
.StopSearch()
} catch (e: Exception) {
}
})
@@ -77,12 +98,12 @@ class MainViewModel @Inject constructor(
})
}
fun startSaveTraceThread(context: Context){
fun startSaveTraceThread(context: Context) {
Thread(Runnable {
try {
while (true){
while (true) {
if(niLocationList!=null&&niLocationList.size>0){
if (niLocationList != null && niLocationList.size > 0) {
var niLocation = niLocationList[0]
val geometry = GeometryTools.createGeometry(GeoPoint(niLocation.latitude,niLocation.longitude))
@@ -99,23 +120,60 @@ class MainViewModel @Inject constructor(
}
}
TraceDataBase.getDatabase(context, Constant.DATA_PATH+ SystemConstant.USER_ID+"/trace.sqlite").niLocationDao.insert(niLocation)
TraceDataBase.getDatabase(
context,
Constant.DATA_PATH + SystemConstant.USER_ID + "/trace.sqlite"
).niLocationDao.insert(niLocation)
niLocationList.removeAt(0)
Log.e("qj","saveTrace")
Log.e("qj", "saveTrace")
}
Thread.sleep(30)
}
} catch (e: InterruptedException) {
e.printStackTrace()
Log.e("qj","异常==${e.message}")
Log.e("qj", "异常==${e.message}")
}
}).start()
}
//增加轨迹存储
fun addSaveTrace(niLocation: NiLocation){
if(niLocation!=null&&niLocationList!=null){
fun addSaveTrace(niLocation: NiLocation) {
if (niLocation != null && niLocationList != null) {
niLocationList.add(niLocation)
}
}
fun navigation(activity: MainActivity, list: List<String>) {
//获取右侧fragment容器
val naviController = activity.findNavController(R.id.main_activity_right_fragment)
naviController.currentDestination?.let { navDestination ->
// when (val fragment =
// activity.supportFragmentManager.findFragmentById(navDestination.id)) {
// //判断右侧的fragment是不是质检数据
//// is EvaluationResultFragment -> {
//// val viewModelFragment =
//// ViewModelProvider(fragment)[EvaluationResultViewModel::class.java]
//// viewModelFragment.notifyData(list)
//// }
// is EmptyFragment -> {
// if (list.size == 1) {
// val bundle = Bundle()
// bundle.putString("QsId", list[0])
// naviController.navigate(R.id.EvaluationResultFragment, bundle)
// }
// }
// }
when (navDestination.id) {
R.id.EmptyFragment -> {
if (list.size == 1) {
val bundle = Bundle()
bundle.putString("QsId", list[0])
naviController.navigate(R.id.EvaluationResultFragment, bundle)
}
}
}
}
}
}

View File

@@ -4,6 +4,7 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.navigation.NavOptions
import androidx.navigation.findNavController
import com.navinfo.omqs.R
@@ -14,30 +15,26 @@ import dagger.hilt.android.AndroidEntryPoint
@AndroidEntryPoint
class EvaluationResultFragment : BaseFragment(), View.OnClickListener {
private var _binding: FragmentEvaluationResultBinding? = null
private val binding get() = _binding!!
private lateinit var binding: FragmentEvaluationResultBinding
private val viewModel by shareViewModels<EvaluationResultViewModel>("QsRecode")
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
): View {
_binding = FragmentEvaluationResultBinding.inflate(inflater, container, false)
binding =
DataBindingUtil.inflate(inflater, R.layout.fragment_evaluation_result, container, false)
binding.fragment = this
binding.viewModel = viewModel
binding.lifecycleOwner = this
return binding.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
liveDataObserve()
/**
* 点击监听
*/
binding.evaluationClassType.setOnClickListener(this)
binding.evaluationProblemType.setOnClickListener(this)
binding.evaluationPhenomenon.setOnClickListener(this)
binding.evaluationLink.setOnClickListener(this)
binding.evaluationCause.setOnClickListener(this)
//监听是否退出当前页面
viewModel.liveDataFinish.observe(viewLifecycleOwner) {
onBackPressed()
}
//返回按钮点击
binding.evaluationBar.setNavigationOnClickListener {
onBackPressed()
@@ -59,7 +56,17 @@ class EvaluationResultFragment : BaseFragment(), View.OnClickListener {
/**
* 读取元数据
*/
viewModel.loadMetadata()
if (arguments != null) {
val id = requireArguments().getString("QsId")
if (id != null) {
viewModel.loadData(id)
} else {
viewModel.initNewData()
}
} else {
viewModel.initNewData()
}
// //监听大分类数据变化
// viewModel.liveDataClassTypeList.observe(viewLifecycleOwner) {
// if (it == null || it.isEmpty()) {
@@ -155,43 +162,12 @@ class EvaluationResultFragment : BaseFragment(), View.OnClickListener {
//
// }
/**
* 监听liveData
*/
private fun liveDataObserve() {
//监听问题分类更新UI
viewModel.liveDataCurrentClassType.observe(viewLifecycleOwner) {
binding.evaluationClassType.text = it
}
//监听问题类型更新UI
viewModel.liveDataCurrentProblemType.observe(viewLifecycleOwner) {
binding.evaluationProblemType.text = it
}
//监听问题现象更新UI
viewModel.liveDataCurrentPhenomenon.observe(viewLifecycleOwner) {
binding.evaluationPhenomenon.text = it
}
//监听问题环节更新UI
viewModel.liveDataCurrentProblemLink.observe(viewLifecycleOwner) {
binding.evaluationLink.text = it
}
//监听问题初步原因更新UI
viewModel.liveDataCurrentCause.observe(viewLifecycleOwner) {
binding.evaluationCause.text = it
}
//监听是否退出当前页面
viewModel.liveDataFinish.observe(viewLifecycleOwner) {
onBackPressed()
}
}
override fun onDestroyView() {
activity?.apply {
findNavController(R.id.main_activity_middle_fragment).navigateUp()
}
super.onDestroyView()
_binding = null
}
/**

View File

@@ -4,12 +4,12 @@ import android.util.Log
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.navinfo.collect.library.map.GeoPoint
import com.navinfo.collect.library.map.NIMapController
import com.navinfo.collect.library.data.entity.QsRecordBean
import com.navinfo.collect.library.map.NIMapController
import com.navinfo.omqs.db.RoomAppDatabase
import dagger.hilt.android.lifecycle.HiltViewModel
import io.realm.Realm
import io.realm.kotlin.where
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import java.util.*
@@ -28,63 +28,34 @@ class EvaluationResultViewModel @Inject constructor(
val liveDataFinish = MutableLiveData<Boolean>()
/**
* 问题分类 liveData给[PhenomenonLeftAdapter]展示的数据
* 问题分类 liveData给[LeftAdapter]展示的数据
*/
val liveDataClassTypeList = MutableLiveData<List<String>>()
val liveDataLeftTypeList = MutableLiveData<List<String>>()
/**
* 问题类型 liveData 给[PhenomenonMiddleAdapter]展示的数据
* 问题类型 liveData 给[MiddleAdapter]展示的数据
*/
val liveDataProblemTypeList = MutableLiveData<List<String>>()
val liveDataMiddleTypeList = MutableLiveData<List<String>>()
/**
* 问题现象 liveData 给[PhenomenonRightGroupHeaderAdapter]展示的数据
* 问题现象 liveData 给[RightGroupHeaderAdapter]展示的数据
*/
val liveDataPhenomenonRightList = MutableLiveData<List<PhenomenonMiddleBean>>()
val liveDataRightTypeList = MutableLiveData<List<RightBean>>()
/**
* 当前选择问题分类 给[EvaluationResultFragment]中 【问题分类】展示数据
*/
var liveDataCurrentClassType = MutableLiveData<String>()
/**
* 当前选择的问题类型 给[EvaluationResultFragment]中 【问题类型】展示数据
*/
var liveDataCurrentProblemType = MutableLiveData<String>()
/**
* 当前选择的问题现象 给[EvaluationResultFragment]中 【问题现象】展示数据
*/
var liveDataCurrentPhenomenon = MutableLiveData<String>()
/**
* 当前选择的问题环节 给[EvaluationResultFragment]中 【问题环节】展示数据
*/
var liveDataCurrentProblemLink = MutableLiveData<String>()
/**
* 当前选择的问初步原因 给[EvaluationResultFragment]中 【初步原因】展示数据
*/
var liveDataCurrentCause = MutableLiveData<String>()
var currentGeoPoint: GeoPoint? = null
var liveDataQsRecordBean = MutableLiveData<QsRecordBean>()
var oldBean: QsRecordBean? = null
init {
liveDataQsRecordBean.value = QsRecordBean(id = UUID.randomUUID().toString())
Log.e("jingo", "EvaluationResultViewModel 创建了 ${hashCode()}")
mapController.markerHandle.apply {
setOnMapClickListener {
currentGeoPoint = it
liveDataQsRecordBean.value!!.geometry = it.toGeometry()
addMarker(it, markerTitle)
}
}
val geoPoint = mapController.locationLayerHandler.getCurrentGeoPoint()
geoPoint?.let {
currentGeoPoint = it
mapController.markerHandle.addMarker(geoPoint, markerTitle)
}
}
@@ -99,144 +70,181 @@ class EvaluationResultViewModel @Inject constructor(
/**
* 查询数据库,获取问题分类
*/
fun loadMetadata() {
fun initNewData() {
viewModelScope.launch(Dispatchers.IO) {
getClassTypeList()
getProblemLinkList()
}
val geoPoint = mapController.locationLayerHandler.getCurrentGeoPoint()
geoPoint?.let {
liveDataQsRecordBean.value!!.geometry = it.toGeometry()
mapController.markerHandle.addMarker(geoPoint, markerTitle)
}
}
/**
* //获取问题分类列表
*/
fun getClassTypeList() {
Log.e("jingo", "getClassTypeList S")
viewModelScope.launch(Dispatchers.IO) {
val list = roomAppDatabase.getScProblemTypeDao().findClassTypeList()
list?.let {
//通知页面更新
liveDataClassTypeList.postValue(it)
//如果右侧栏没数据,给个默认值
if (liveDataCurrentClassType.value == null) {
liveDataCurrentClassType.postValue(it[0])
if (list.isNotEmpty()) {
//通知页面更新
liveDataLeftTypeList.postValue(it)
val classType = it[0]
//如果右侧栏没数据,给个默认值
if (liveDataQsRecordBean.value!!.classType.isEmpty()) {
Log.e("jingo", "getClassTypeList $classType")
liveDataQsRecordBean.value!!.classType = classType
}
getProblemList(classType)
}
getProblemList(it[0])
}
}
Log.e("jingo", "getClassTypeList E")
}
/**
* 获取问题环节列表和初步问题
*/
fun getProblemLinkList() {
Log.e("jingo", "getProblemLinkList S")
viewModelScope.launch(Dispatchers.IO) {
val list = roomAppDatabase.getScRootCauseAnalysisDao().findAllData()
list?.let { tl ->
if (tl.isNotEmpty()) {
val typeTitleList = mutableListOf<String>()
val phenomenonRightList = mutableListOf<PhenomenonMiddleBean>()
val middleList = mutableListOf<String>()
val rightList = mutableListOf<RightBean>()
for (item in tl) {
if (!typeTitleList.contains(item.problemLink)) {
typeTitleList.add(item.problemLink)
if (!middleList.contains(item.problemLink)) {
middleList.add(item.problemLink)
}
phenomenonRightList.add(
PhenomenonMiddleBean(
rightList.add(
RightBean(
title = item.problemLink, text = item.problemCause, isSelect = false
)
)
}
if (liveDataCurrentProblemLink.value == null) {
liveDataCurrentProblemLink.postValue(phenomenonRightList[0].text)
if (liveDataQsRecordBean.value!!.problemLink.isEmpty()) {
liveDataQsRecordBean.value!!.problemLink = middleList[0]
Log.e("jingo", "getProblemLinkList ${middleList[0]}")
}
if (liveDataCurrentCause.value == null) {
liveDataCurrentCause.postValue(typeTitleList[0])
if (liveDataQsRecordBean.value!!.cause.isEmpty()) {
liveDataQsRecordBean.value!!.cause = rightList[0].text
Log.e("jingo", "getProblemLinkList ${rightList[0].text}")
}
liveDataProblemTypeList.postValue(typeTitleList)
liveDataPhenomenonRightList.postValue(phenomenonRightList)
liveDataQsRecordBean.postValue(liveDataQsRecordBean.value)
liveDataMiddleTypeList.postValue(middleList)
liveDataRightTypeList.postValue(rightList)
}
}
}
Log.e("jingo", "getProblemLinkList E")
}
/**
* 获取问题类型列表和问题现象
*/
private suspend fun getProblemList(classType: String) {
Log.e("jingo", "getProblemList S")
val typeList = roomAppDatabase.getScProblemTypeDao().findProblemTypeList(classType)
typeList?.let { tl ->
if (tl.isNotEmpty()) {
val typeTitleList = mutableListOf<String>()
val phenomenonRightList = mutableListOf<PhenomenonMiddleBean>()
val phenomenonRightList = mutableListOf<RightBean>()
for (item in tl) {
if (!typeTitleList.contains(item.problemType)) {
typeTitleList.add(item.problemType)
}
phenomenonRightList.add(
PhenomenonMiddleBean(
RightBean(
title = item.problemType, text = item.phenomenon, isSelect = false
)
)
}
if (liveDataCurrentPhenomenon.value == null) {
liveDataCurrentPhenomenon.postValue(phenomenonRightList[0].text)
if (liveDataQsRecordBean.value!!.problemType.isEmpty()) {
liveDataQsRecordBean.value!!.problemType = typeTitleList[0]
Log.e("jingo", "getProblemList ${typeTitleList[0]}")
}
if (liveDataCurrentProblemType.value == null) {
liveDataCurrentProblemType.postValue(typeTitleList[0])
liveDataMiddleTypeList.postValue(typeTitleList)
if (liveDataQsRecordBean.value!!.phenomenon.isEmpty()) {
liveDataQsRecordBean.value!!.phenomenon = phenomenonRightList[0].text
Log.e("jingo", "getProblemList ${phenomenonRightList[0].text}")
}
liveDataProblemTypeList.postValue(typeTitleList)
liveDataPhenomenonRightList.postValue(phenomenonRightList)
liveDataQsRecordBean.postValue(liveDataQsRecordBean.value)
liveDataRightTypeList.postValue(phenomenonRightList)
}
}
Log.e("jingo", "getProblemList E")
}
/**
* 查询问题类型
* 查询问题类型列表
*/
fun getProblemTypeList(classType: String) {
viewModelScope.launch(Dispatchers.IO) {
liveDataCurrentClassType.postValue(classType)
getProblemList(classType)
}
}
fun setPhenomenonMiddleBean(bean: PhenomenonMiddleBean) {
if (liveDataCurrentPhenomenon.value != bean.text) liveDataCurrentPhenomenon.value =
bean.text
if (liveDataCurrentProblemType.value != bean.title) liveDataCurrentProblemType.value =
bean.title
/**
* 监听右侧栏的点击事件,修改数据
*/
fun setPhenomenonMiddleBean(adapterBean: RightBean) {
liveDataQsRecordBean.value!!.phenomenon = adapterBean.text
liveDataQsRecordBean.value!!.problemType = adapterBean.title
liveDataQsRecordBean.postValue(liveDataQsRecordBean.value)
}
fun setProblemLinkMiddleBean(bean: PhenomenonMiddleBean) {
if (liveDataCurrentProblemLink.value != bean.text) liveDataCurrentProblemLink.value =
bean.text
if (liveDataCurrentCause.value != bean.title) liveDataCurrentCause.value = bean.title
fun setProblemLinkMiddleBean(adapterBean: RightBean) {
liveDataQsRecordBean.value!!.cause = adapterBean.text
liveDataQsRecordBean.value!!.problemLink = adapterBean.title
liveDataQsRecordBean.postValue(liveDataQsRecordBean.value)
}
fun saveData() {
viewModelScope.launch(Dispatchers.IO) {
val qsRecord = QsRecordBean(
id = UUID.randomUUID().toString(),
classType = liveDataCurrentClassType.value.toString(),
type = liveDataCurrentProblemType.value.toString(),
phenomenon = liveDataCurrentPhenomenon.value.toString(),
problemLink = liveDataCurrentProblemLink.value.toString(),
cause = liveDataCurrentCause.value.toString(),
)
qsRecord.geometry = currentGeoPoint!!.toGeometry()
val realm = Realm.getDefaultInstance()
Log.e("jingo","realm hashCOde ${realm.hashCode()}")
realm.executeTransaction {
it.copyToRealmOrUpdate(qsRecord)
it.copyToRealmOrUpdate(liveDataQsRecordBean.value)
}
realm.close()
mapController.mMapView.updateMap()
// realm.close()
mapController.layerManagerHandler.addOrUpdateQsRecordMark(liveDataQsRecordBean.value!!)
liveDataFinish.postValue(true)
}
}
fun deleteData() {
viewModelScope.launch(Dispatchers.IO) {
val realm = Realm.getDefaultInstance()
Log.e("jingo","realm hashCOde ${realm.hashCode()}")
realm.executeTransaction {
val objects = it.where(QsRecordBean::class.java)
.equalTo("id", liveDataQsRecordBean.value?.id).findFirst()
objects?.deleteFromRealm()
}
// realm.close()
mapController.layerManagerHandler.removeQsRecordMark(liveDataQsRecordBean.value!!)
liveDataFinish.postValue(true)
}
}
/**
* 根据数据id查询数据
*/
fun loadData(id: String) {
viewModelScope.launch(Dispatchers.IO) {
val realm = Realm.getDefaultInstance()
val objects = realm.where<QsRecordBean>().equalTo("id", id).findFirst()
if (objects != null) {
oldBean = realm.copyFromRealm(objects)
liveDataQsRecordBean.postValue(oldBean!!.copy())
}
}
}
}

View File

@@ -7,7 +7,7 @@ import com.navinfo.omqs.databinding.TextItemSelectBinding
import com.navinfo.omqs.ui.other.BaseRecyclerViewAdapter
import com.navinfo.omqs.ui.other.BaseViewHolder
class PhenomenonLeftAdapter(private var itemListener: ((Int, String) -> Unit?)? = null) :
class LeftAdapter(private var itemListener: ((Int, String) -> Unit?)? = null) :
BaseRecyclerViewAdapter<String>() {
private var selectTitle = ""

View File

@@ -7,7 +7,7 @@ import com.navinfo.omqs.databinding.TextItemSelectBinding
import com.navinfo.omqs.ui.other.BaseRecyclerViewAdapter
import com.navinfo.omqs.ui.other.BaseViewHolder
class PhenomenonMiddleAdapter(private var itemListener: ((Int, String) -> Unit?)? = null) :
class MiddleAdapter(private var itemListener: ((Int, String) -> Unit?)? = null) :
BaseRecyclerViewAdapter<String>() {
private var selectTitle = ""

View File

@@ -5,13 +5,9 @@ import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.navigation.findNavController
import androidx.navigation.fragment.findNavController
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.RecyclerView.OnScrollListener
import com.navinfo.omqs.R
import com.navinfo.omqs.databinding.FragmentPhenomenonBinding
import com.navinfo.omqs.ui.fragment.BaseFragment
import com.navinfo.omqs.ui.other.shareViewModels
@@ -41,12 +37,15 @@ class PhenomenonFragment :
//左侧菜单
binding.phenomenonLeftRecyclerview.setHasFixedSize(true)
binding.phenomenonLeftRecyclerview.layoutManager = LinearLayoutManager(requireContext())
val leftAdapter = PhenomenonLeftAdapter { _, text ->
/**
* 监听左侧栏的点击事件
*/
val leftAdapter = LeftAdapter { _, text ->
viewModel.getProblemTypeList(text)
}
binding.phenomenonLeftRecyclerview.adapter = leftAdapter
//左侧菜单查询结果监听
viewModel.liveDataClassTypeList.observe(viewLifecycleOwner) {
viewModel.liveDataLeftTypeList.observe(viewLifecycleOwner) {
leftAdapter.refreshData(it)
}
@@ -55,26 +54,34 @@ class PhenomenonFragment :
var rightLayoutManager = LinearLayoutManager(requireContext())
binding.phenomenonRightRecyclerview.layoutManager = rightLayoutManager
val rightAdapter = PhenomenonRightGroupHeaderAdapter { _, bean ->
/**
* 监听右侧栏的点击事件
*/
val rightAdapter = RightGroupHeaderAdapter { _, bean ->
viewModel.setPhenomenonMiddleBean(bean)
}
binding.phenomenonRightRecyclerview.adapter = rightAdapter
//右侧菜单增加组标题
binding.phenomenonRightRecyclerview.addItemDecoration(
PhenomenonRightGroupHeaderDecoration(
RightGroupHeaderDecoration(
requireContext()
)
)
//右侧菜单查询数据监听
viewModel.liveDataPhenomenonRightList.observe(viewLifecycleOwner) {
viewModel.liveDataRightTypeList.observe(viewLifecycleOwner) {
rightAdapter.refreshData(it)
}
val middleAdapter = PhenomenonMiddleAdapter { _, title ->
/**
* 监听中间栏的点击事件
*/
val middleAdapter = MiddleAdapter { _, title ->
rightLayoutManager.scrollToPositionWithOffset(rightAdapter.getGroupTopIndex(title), 0)
}
/**
* 监控右侧滚动,更新左侧
*/
binding.phenomenonRightRecyclerview.addOnScrollListener(object :
OnScrollListener() {
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
@@ -98,7 +105,7 @@ class PhenomenonFragment :
binding.phenomenonMiddleRecyclerview.layoutManager = LinearLayoutManager(requireContext())
binding.phenomenonMiddleRecyclerview.adapter = middleAdapter
//中间侧菜单查询结果监听
viewModel.liveDataProblemTypeList.observe(viewLifecycleOwner) {
viewModel.liveDataMiddleTypeList.observe(viewLifecycleOwner) {
middleAdapter.refreshData(it)
}
binding.phenomenonDrawer.setOnClickListener {

View File

@@ -1,6 +0,0 @@
package com.navinfo.omqs.ui.fragment.evaluationresult
/**
* 问题现象列表
*/
data class PhenomenonMiddleBean(val title: String, val text: String, var isSelect: Boolean = false)

View File

@@ -35,22 +35,22 @@ class ProblemLinkFragment : BaseFragment() {
var rightLayoutManager = LinearLayoutManager(requireContext())
binding.linkRightRecyclerview.layoutManager = rightLayoutManager
val rightAdapter = PhenomenonRightGroupHeaderAdapter { _, bean ->
val rightAdapter = RightGroupHeaderAdapter { _, bean ->
viewModel.setProblemLinkMiddleBean(bean)
}
binding.linkRightRecyclerview.adapter = rightAdapter
//右侧菜单增加组标题
binding.linkRightRecyclerview.addItemDecoration(
PhenomenonRightGroupHeaderDecoration(
RightGroupHeaderDecoration(
requireContext()
)
)
//右侧菜单查询数据监听
viewModel.liveDataPhenomenonRightList.observe(viewLifecycleOwner) {
viewModel.liveDataRightTypeList.observe(viewLifecycleOwner) {
rightAdapter.refreshData(it)
}
val middleAdapter = PhenomenonMiddleAdapter { _, title ->
val middleAdapter = MiddleAdapter { _, title ->
rightLayoutManager.scrollToPositionWithOffset(rightAdapter.getGroupTopIndex(title), 0)
}
@@ -72,7 +72,7 @@ class ProblemLinkFragment : BaseFragment() {
binding.linkMiddleRecyclerview.layoutManager = LinearLayoutManager(requireContext())
binding.linkMiddleRecyclerview.adapter = middleAdapter
//中间侧菜单查询结果监听
viewModel.liveDataProblemTypeList.observe(viewLifecycleOwner) {
viewModel.liveDataMiddleTypeList.observe(viewLifecycleOwner) {
middleAdapter.refreshData(it)
}
binding.linkDrawer.setOnClickListener {

View File

@@ -0,0 +1,6 @@
package com.navinfo.omqs.ui.fragment.evaluationresult
/**
* 问题现象列表
*/
data class RightBean(val title: String, val text: String, var isSelect: Boolean = false)

View File

@@ -7,8 +7,8 @@ import com.navinfo.omqs.databinding.TextItemSelectBinding
import com.navinfo.omqs.ui.other.BaseRecyclerViewAdapter
import com.navinfo.omqs.ui.other.BaseViewHolder
class PhenomenonRightGroupHeaderAdapter(private var itemListener: ((Int, PhenomenonMiddleBean) -> Unit?)? = null) :
BaseRecyclerViewAdapter<PhenomenonMiddleBean>() {
class RightGroupHeaderAdapter(private var itemListener: ((Int, RightBean) -> Unit?)? = null) :
BaseRecyclerViewAdapter<RightBean>() {
private var groupTitleList = mutableListOf<String>()
override fun getItemViewRes(position: Int): Int {
return R.layout.text_item_select
@@ -85,7 +85,7 @@ class PhenomenonRightGroupHeaderAdapter(private var itemListener: ((Int, Phenome
return 0
}
override fun refreshData(newData: List<PhenomenonMiddleBean>) {
override fun refreshData(newData: List<RightBean>) {
super.refreshData(newData)
groupTitleList.clear()
for (item in newData) {

View File

@@ -5,7 +5,6 @@ import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.graphics.Rect
import android.util.Log
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
@@ -15,7 +14,7 @@ import androidx.recyclerview.widget.RecyclerView.ItemDecoration
/**
* 自定义装饰器实现分组+吸顶效果
*/
class PhenomenonRightGroupHeaderDecoration(context: Context) : ItemDecoration() {
class RightGroupHeaderDecoration(context: Context) : ItemDecoration() {
//头部的高
private val mItemHeaderHeight: Int
private val mTextPaddingLeft: Int
@@ -48,8 +47,8 @@ class PhenomenonRightGroupHeaderDecoration(context: Context) : ItemDecoration()
* @param state
*/
override fun onDraw(c: Canvas, parent: RecyclerView, state: RecyclerView.State) {
if (parent.adapter is PhenomenonRightGroupHeaderAdapter) {
val adapter = parent.adapter as PhenomenonRightGroupHeaderAdapter
if (parent.adapter is RightGroupHeaderAdapter) {
val adapter = parent.adapter as RightGroupHeaderAdapter
val count = parent.childCount //获取可见范围内Item的总数
for (i in 0 until count) {
val view: View = parent.getChildAt(i)
@@ -99,8 +98,8 @@ class PhenomenonRightGroupHeaderDecoration(context: Context) : ItemDecoration()
* @param state
*/
override fun onDrawOver(c: Canvas, parent: RecyclerView, state: RecyclerView.State) {
if (parent.adapter is PhenomenonRightGroupHeaderAdapter) {
val adapter = parent.adapter as PhenomenonRightGroupHeaderAdapter
if (parent.adapter is RightGroupHeaderAdapter) {
val adapter = parent.adapter as RightGroupHeaderAdapter
val position =
(parent.layoutManager as LinearLayoutManager?)!!.findFirstVisibleItemPosition()
parent.findViewHolderForAdapterPosition(position)?.let {
@@ -169,8 +168,8 @@ class PhenomenonRightGroupHeaderDecoration(context: Context) : ItemDecoration()
parent: RecyclerView,
state: RecyclerView.State
) {
if (parent.adapter is PhenomenonRightGroupHeaderAdapter) {
val adapter = parent.adapter as PhenomenonRightGroupHeaderAdapter
if (parent.adapter is RightGroupHeaderAdapter) {
val adapter = parent.adapter as RightGroupHeaderAdapter
//获取当前view在整个列表中的位置
val position = parent.getChildLayoutPosition(view)
//是不是改组的第一个
@@ -180,7 +179,7 @@ class PhenomenonRightGroupHeaderDecoration(context: Context) : ItemDecoration()
if (adapter.isLastGroupTitle(position)) {
lastGroupView = view
}
} else if (position == (parent.adapter as PhenomenonRightGroupHeaderAdapter).itemCount - 1) {
} else if (position == (parent.adapter as RightGroupHeaderAdapter).itemCount - 1) {
//判断这条是不是最后一条
//如果是最后一个,找到他所在组的第一个
lastGroupView?.let {

View File

@@ -10,6 +10,8 @@ import com.navinfo.omqs.R
import com.navinfo.omqs.databinding.AdapterOfflineMapCityBinding
import com.navinfo.omqs.bean.OfflineMapCityBean
import com.navinfo.omqs.http.offlinemapdownload.OfflineMapDownloadManager
import com.navinfo.omqs.tools.FileManager
import com.navinfo.omqs.tools.FileManager.Companion.FileDownloadStatus
import com.navinfo.omqs.ui.other.BaseRecyclerViewAdapter
import com.navinfo.omqs.ui.other.BaseViewHolder
import javax.inject.Inject
@@ -31,11 +33,11 @@ class OfflineMapCityListAdapter(
if (it.tag != null) {
val cityBean = data[it.tag as Int]
when (cityBean.status) {
OfflineMapCityBean.NONE, OfflineMapCityBean.UPDATE, OfflineMapCityBean.PAUSE, OfflineMapCityBean.ERROR -> {
FileDownloadStatus.NONE, FileDownloadStatus.UPDATE, FileDownloadStatus.PAUSE, FileDownloadStatus.ERROR -> {
Log.e("jingo", "开始下载 ${cityBean.status}")
downloadManager.start(cityBean.id)
}
OfflineMapCityBean.LOADING, OfflineMapCityBean.WAITING -> {
FileDownloadStatus.LOADING, FileDownloadStatus.WAITING -> {
Log.e("jingo", "暂停 ${cityBean.status}")
downloadManager.pause(cityBean.id)
}
@@ -88,37 +90,37 @@ class OfflineMapCityListAdapter(
binding.offlineMapProgress.progress =
(cityBean.currentSize * 100 / cityBean.fileSize).toInt()
when (cityBean.status) {
OfflineMapCityBean.NONE -> {
FileDownloadStatus.NONE -> {
if (binding.offlineMapProgress.visibility == View.VISIBLE) binding.offlineMapProgress.visibility =
View.INVISIBLE
binding.offlineMapDownloadBtn.text = "下载"
}
OfflineMapCityBean.WAITING -> {
FileDownloadStatus.WAITING -> {
if (binding.offlineMapProgress.visibility != View.VISIBLE) binding.offlineMapProgress.visibility =
View.VISIBLE
binding.offlineMapDownloadBtn.text = "等待中"
}
OfflineMapCityBean.LOADING -> {
FileDownloadStatus.LOADING -> {
if (binding.offlineMapProgress.visibility != View.VISIBLE) binding.offlineMapProgress.visibility =
View.VISIBLE
binding.offlineMapDownloadBtn.text = "暂停"
}
OfflineMapCityBean.PAUSE -> {
FileDownloadStatus.PAUSE -> {
if (binding.offlineMapProgress.visibility != View.VISIBLE) binding.offlineMapProgress.visibility =
View.VISIBLE
binding.offlineMapDownloadBtn.text = "继续"
}
OfflineMapCityBean.ERROR -> {
FileDownloadStatus.ERROR -> {
if (binding.offlineMapProgress.visibility != View.VISIBLE) binding.offlineMapProgress.visibility =
View.VISIBLE
binding.offlineMapDownloadBtn.text = "重试"
}
OfflineMapCityBean.DONE -> {
FileDownloadStatus.DONE -> {
if (binding.offlineMapProgress.visibility == View.VISIBLE) binding.offlineMapProgress.visibility =
View.INVISIBLE
binding.offlineMapDownloadBtn.text = "已完成"
}
OfflineMapCityBean.UPDATE -> {
FileDownloadStatus.UPDATE -> {
if (binding.offlineMapProgress.visibility == View.VISIBLE) binding.offlineMapProgress.visibility =
View.INVISIBLE
binding.offlineMapDownloadBtn.text = "更新"

View File

@@ -8,11 +8,12 @@ import androidx.fragment.app.Fragment
import androidx.navigation.fragment.findNavController
import com.google.android.material.tabs.TabLayoutMediator
import com.navinfo.omqs.databinding.FragmentOfflineMapBinding
import com.navinfo.omqs.ui.fragment.BaseFragment
/**
* 离线地图总页面
*/
class OfflineMapFragment : Fragment() {
class OfflineMapFragment : BaseFragment() {
private var _binding: FragmentOfflineMapBinding? = null

View File

@@ -24,6 +24,7 @@ import com.navinfo.omqs.db.ImportOMDBHelper
import com.navinfo.omqs.hilt.ImportOMDBHiltFactory
import com.navinfo.omqs.tools.CoroutineUtils
import com.navinfo.omqs.ui.activity.BaseActivity
import com.navinfo.omqs.ui.fragment.BaseFragment
import dagger.hilt.android.AndroidEntryPoint
import io.realm.Realm
import io.realm.RealmDictionary
@@ -40,12 +41,13 @@ import javax.inject.Inject
* 个人中心
*/
@AndroidEntryPoint
class PersonalCenterFragment : Fragment(), FSAFActivityCallbacks {
class PersonalCenterFragment : BaseFragment(), FSAFActivityCallbacks {
private var _binding: FragmentPersonalCenterBinding? = null
private val binding get() = _binding!!
private val fileChooser by lazy { FileChooser(requireContext()) }
private val viewModel by lazy { viewModels<PersonalCenterViewModel>().value }
@Inject
lateinit var importOMDBHiltFactory: ImportOMDBHiltFactory
@Inject
@@ -65,9 +67,9 @@ class PersonalCenterFragment : Fragment(), FSAFActivityCallbacks {
binding.root.setNavigationItemSelectedListener {
when (it.itemId) {
R.id.personal_center_menu_offline_map ->
findNavController().navigate(R.id.action_FirstFragment_to_SecondFragment)
findNavController().navigate(R.id.OfflineMapFragment)
R.id.personal_center_menu_obtain_data -> { // 生成数据根据sqlite文件生成对应的zip文件
fileChooser.openChooseFileDialog(object: FileChooserCallback() {
fileChooser.openChooseFileDialog(object : FileChooserCallback() {
override fun onCancel(reason: String) {
}
@@ -75,31 +77,47 @@ class PersonalCenterFragment : Fragment(), FSAFActivityCallbacks {
val file = UriUtils.uri2File(uri)
// 开始导入数据
// 656e6372797000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
val job = CoroutineUtils.launchWithLoading(requireContext(), loadingMessage = "生成数据...") {
val importOMDBHelper: ImportOMDBHelper = importOMDBHiltFactory.obtainImportOMDBHelper(requireContext(), file, File(file.parentFile, "config.json"))
val job = CoroutineUtils.launchWithLoading(
requireContext(),
loadingMessage = "生成数据..."
) {
val importOMDBHelper: ImportOMDBHelper =
importOMDBHiltFactory.obtainImportOMDBHelper(
requireContext(),
file,
File(file.parentFile, "config.json")
)
viewModel.obtainOMDBZipData(importOMDBHelper)
}
}
})
}
R.id.personal_center_menu_import_data -> { // 导入zip数据
fileChooser.openChooseFileDialog(object: FileChooserCallback() {
fileChooser.openChooseFileDialog(object : FileChooserCallback() {
override fun onCancel(reason: String) {
}
override fun onResult(uri: Uri) {
val file = UriUtils.uri2File(uri)
// 开始导入数据
CoroutineUtils.launchWithLoading(requireContext(), loadingMessage = "导入数据...") {
val importOMDBHelper: ImportOMDBHelper = importOMDBHiltFactory.obtainImportOMDBHelper(requireContext(), file, File(file.parentFile, "config.json"))
CoroutineUtils.launchWithLoading(
requireContext(),
loadingMessage = "导入数据..."
) {
val importOMDBHelper: ImportOMDBHelper =
importOMDBHiltFactory.obtainImportOMDBHelper(
requireContext(),
file,
File(file.parentFile, "config.json")
)
viewModel.importOMDBData(importOMDBHelper)
}
}
})
}
R.id.personal_center_menu_import_yuan_data->{
R.id.personal_center_menu_import_yuan_data -> {
// 用户选中导入数据,打开文件选择器,用户选择导入的数据文件目录
fileChooser.openChooseFileDialog(object: FileChooserCallback() {
fileChooser.openChooseFileDialog(object : FileChooserCallback() {
override fun onCancel(reason: String) {
}
@@ -114,6 +132,9 @@ class PersonalCenterFragment : Fragment(), FSAFActivityCallbacks {
// 定位到指定位置
niMapController.mMapView.vtmMap.animator().animateTo(GeoPoint(28.608398, 115.67901))
}
R.id.personal_center_menu_task_list -> {
findNavController().navigate(R.id.TaskListFragment)
}
}
true
}

View File

@@ -185,15 +185,16 @@ class PersonalCenterViewModel @Inject constructor(
val list = mutableListOf<ScProblemTypeBean>()
for (i in 1 until rowCount) {
val row: Row = it.getRow(i) // 获取行
val cellCount: Int = row.physicalNumberOfCells // 获取列数
if (cellCount == 3) {
val bean = ScProblemTypeBean()
bean.classType = row.getCell(0).stringCellValue
bean.problemType = row.getCell(1).stringCellValue
bean.phenomenon = row.getCell(2).stringCellValue
list.add(bean)
Log.e("jingo", bean.toString())
}
// val cellCount: Int = row.physicalNumberOfCells // 获取列数
val bean = ScProblemTypeBean(
elementType = row.getCell(0).stringCellValue,
elementCode = row.getCell(1).numericCellValue.toString(),
classType = row.getCell(2).stringCellValue,
problemType = row.getCell(3).stringCellValue,
phenomenon = row.getCell(4).stringCellValue
)
list.add(bean)
Log.e("jingo", bean.toString())
}
roomAppDatabase.getScProblemTypeDao().insertOrUpdateList(list)
}

View File

@@ -0,0 +1,132 @@
package com.navinfo.omqs.ui.fragment.tasklist
import android.content.Context
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.lifecycle.Observer
import com.navinfo.omqs.R
import com.navinfo.omqs.bean.TaskBean
import com.navinfo.omqs.databinding.AdapterTaskListBinding
import com.navinfo.omqs.http.taskdownload.TaskDownloadManager
import com.navinfo.omqs.tools.FileManager.Companion.FileDownloadStatus
import com.navinfo.omqs.ui.other.BaseRecyclerViewAdapter
import com.navinfo.omqs.ui.other.BaseViewHolder
/**
* 离线地图城市列表 RecyclerView 适配器
*
* 在 RecycleView 的 ViewHolder 中监听 ViewModel 的 LiveData然后此时传递的 lifecycleOwner 是对应的 Fragment。由于 ViewHolder 的生命周期是比 Fragment 短的,所以当 ViewHolder 销毁时,由于 Fragment 的 Lifecycle 还没有结束,此时 ViewHolder 会发生内存泄露(监听的 LiveData 没有解绑)
* 这种场景下有两种解决办法:
*使用 LiveData 的 observeForever 然后在 ViewHolder 销毁前手动调用 removeObserver
*使用 LifecycleRegistry 给 ViewHolder 分发生命周期(这里使用了这个)
*/
class TaskListAdapter(
private val downloadManager: TaskDownloadManager, private val context: Context
) : BaseRecyclerViewAdapter<TaskBean>() {
private val downloadBtnClick = View.OnClickListener() {
if (it.tag != null) {
val taskBean = data[it.tag as Int]
when (taskBean.status) {
FileDownloadStatus.NONE, FileDownloadStatus.UPDATE, FileDownloadStatus.PAUSE, FileDownloadStatus.ERROR -> {
Log.e("jingo", "开始下载 ${taskBean.status}")
downloadManager.start(taskBean.id)
}
FileDownloadStatus.LOADING, FileDownloadStatus.WAITING -> {
Log.e("jingo", "暂停 ${taskBean.status}")
downloadManager.pause(taskBean.id)
}
else -> {
Log.e("jingo", "暂停 ${taskBean.status}")
}
}
}
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BaseViewHolder {
val viewBinding =
AdapterTaskListBinding.inflate(LayoutInflater.from(parent.context), parent, false)
return BaseViewHolder(viewBinding)
}
override fun onViewRecycled(holder: BaseViewHolder) {
super.onViewRecycled(holder)
//页面滑动时会用holder重构页面但是对进度条的监听回调会一直返回扰乱UI所以当当前holder去重构的时候移除监听
downloadManager.removeObserver(holder.tag.toInt())
}
override fun onBindViewHolder(holder: BaseViewHolder, position: Int) {
val binding: AdapterTaskListBinding =
holder.viewBinding as AdapterTaskListBinding
val taskBean = data[position]
//tag 方便onclick里拿到数据
holder.tag = taskBean.id.toString()
changeViews(binding, taskBean)
downloadManager.addTask(taskBean)
downloadManager.observer(taskBean.id, holder, DownloadObserver(taskBean.id, binding))
binding.taskDownloadBtn.tag = position
binding.taskDownloadBtn.setOnClickListener(downloadBtnClick)
binding.taskName.text = taskBean.evaluationTaskName
// binding.offlineMapCitySize.text = cityBean.getFileSizeText()
}
inner class DownloadObserver(val id: Int, val binding: AdapterTaskListBinding) :
Observer<TaskBean> {
override fun onChanged(t: TaskBean?) {
if (id == t?.id)
changeViews(binding, t)
}
}
private fun changeViews(binding: AdapterTaskListBinding, cityBean: TaskBean) {
binding.taskProgress.progress =
(cityBean.currentSize * 100 / cityBean.fileSize).toInt()
when (cityBean.status) {
FileDownloadStatus.NONE -> {
if (binding.taskProgress.visibility == View.VISIBLE) binding.taskProgress.visibility =
View.INVISIBLE
binding.taskDownloadBtn.text = "下载"
}
FileDownloadStatus.WAITING -> {
if (binding.taskProgress.visibility != View.VISIBLE) binding.taskProgress.visibility =
View.VISIBLE
binding.taskDownloadBtn.text = "等待中"
}
FileDownloadStatus.LOADING -> {
if (binding.taskProgress.visibility != View.VISIBLE) binding.taskProgress.visibility =
View.VISIBLE
binding.taskDownloadBtn.text = "暂停"
}
FileDownloadStatus.PAUSE -> {
if (binding.taskProgress.visibility != View.VISIBLE) binding.taskProgress.visibility =
View.VISIBLE
binding.taskDownloadBtn.text = "继续"
}
FileDownloadStatus.ERROR -> {
if (binding.taskProgress.visibility != View.VISIBLE) binding.taskProgress.visibility =
View.VISIBLE
binding.taskDownloadBtn.text = "重试"
}
FileDownloadStatus.DONE -> {
if (binding.taskProgress.visibility == View.VISIBLE) binding.taskProgress.visibility =
View.INVISIBLE
binding.taskDownloadBtn.text = "已完成"
}
FileDownloadStatus.UPDATE -> {
if (binding.taskProgress.visibility == View.VISIBLE) binding.taskProgress.visibility =
View.INVISIBLE
binding.taskDownloadBtn.text = "更新"
}
}
}
override fun getItemViewRes(position: Int): Int {
return R.layout.adapter_offline_map_city
}
}

View File

@@ -0,0 +1,55 @@
package com.navinfo.omqs.ui.fragment.tasklist
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.viewModels
import androidx.recyclerview.widget.LinearLayoutManager
import com.navinfo.omqs.databinding.FragmentTaskListBinding
import com.navinfo.omqs.http.taskdownload.TaskDownloadManager
import com.navinfo.omqs.ui.fragment.BaseFragment
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject
@AndroidEntryPoint
class TaskListFragment : BaseFragment(){
@Inject
lateinit var downloadManager: TaskDownloadManager
private var _binding: FragmentTaskListBinding? = null
private val viewModel by viewModels<TaskListViewModel>()
private val binding get() = _binding!!
private val adapter: TaskListAdapter by lazy {
TaskListAdapter(
downloadManager,
requireContext()
)
}
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View {
_binding = FragmentTaskListBinding.inflate(inflater, container, false)
return binding.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val layoutManager = LinearLayoutManager(context)
//// 设置 RecyclerView 的固定大小,避免在滚动时重新计算视图大小和布局,提高性能
binding.taskRecyclerview.setHasFixedSize(true)
binding.taskRecyclerview.layoutManager = layoutManager
binding.taskRecyclerview.adapter = adapter
viewModel.liveDataTaskList.observe(viewLifecycleOwner) {
adapter.refreshData(it)
}
viewModel.getTaskList(requireContext())
}
override fun onDestroyView() {
super.onDestroyView()
_binding = null
}
}

View File

@@ -0,0 +1,61 @@
package com.navinfo.omqs.ui.fragment.tasklist
import android.content.Context
import android.util.Log
import android.widget.Toast
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.navinfo.omqs.bean.TaskBean
import com.navinfo.omqs.http.NetResult
import com.navinfo.omqs.http.NetworkService
import com.navinfo.omqs.tools.FileManager
import dagger.hilt.android.lifecycle.HiltViewModel
import io.realm.Realm
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import javax.inject.Inject
@HiltViewModel
class TaskListViewModel @Inject constructor(
private val networkService: NetworkService
) : ViewModel() {
val liveDataTaskList = MutableLiveData<List<TaskBean>>()
fun getTaskList(context: Context) {
viewModelScope.launch(Dispatchers.IO) {
val realm = Realm.getDefaultInstance()
Log.e("jingo","realm hashCOde ${realm.hashCode()}")
when (val result = networkService.getTaskList("02911")) {
is NetResult.Success -> {
if (result.data != null) {
realm.executeTransaction {
realm.copyToRealmOrUpdate(result.data.obj)
}
}
}
is NetResult.Error -> {
withContext(Dispatchers.Main) {
Toast.makeText(context, "${result.exception.message}", Toast.LENGTH_SHORT)
.show()
}
}
is NetResult.Failure -> {
withContext(Dispatchers.Main) {
Toast.makeText(context, "${result.code}:${result.msg}", Toast.LENGTH_SHORT)
.show()
}
}
is NetResult.Loading -> {}
else -> {}
}
val objects = realm.where(TaskBean::class.java).findAll()
liveDataTaskList.postValue(realm.copyFromRealm(objects))
// realm.close()
}
}
}

View File

@@ -0,0 +1,53 @@
package com.navinfo.omqs.ui.widget
import android.content.Context
import android.util.AttributeSet
import android.view.MotionEvent
import android.view.View
import android.widget.EditText
import androidx.appcompat.widget.AppCompatEditText
import com.navinfo.omqs.R
class MyEditeText @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = android.R.attr.editTextStyle //不这样写可能有些属性用不了
) : AppCompatEditText(context, attrs, defStyleAttr) {
init {
//Edittext通知父控件自己处理自己的滑动事件
setOnTouchListener { v, event ->
if (canVerticalScroll(this)) {
v.parent.requestDisallowInterceptTouchEvent(true)
if (event.action == MotionEvent.ACTION_UP) {
v.parent.requestDisallowInterceptTouchEvent(false)
}
}
false
}
}
/**
* EditText竖直方向是否可以滚动
*
* @param //editText需要判断的EditText
* @return true可以滚动 false不可以滚动
*/
private fun canVerticalScroll(contentEt: EditText): Boolean {
//滚动的距离
val scrollY = contentEt.scrollY
//控件内容的总高度
val scrollRange = contentEt.layout.height
//控件实际显示的高度
val scrollExtent =
contentEt.height - contentEt.compoundPaddingTop - contentEt.compoundPaddingBottom
//控件内容总高度与实际显示高度的差值
val scrollDifference = scrollRange - scrollExtent
if (scrollDifference == 0) {
return false
}
return (scrollY > 0) || (scrollY < scrollDifference - 1)
}
}