修改登录逻辑和数据访问顺序
增加任务和作业数据统计
This commit is contained in:
@@ -6,8 +6,10 @@ import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.View.OnClickListener
|
||||
import android.view.ViewGroup
|
||||
import android.widget.TextView
|
||||
import android.widget.Toast
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.viewModels
|
||||
import androidx.transition.AutoTransition
|
||||
import androidx.transition.Scene
|
||||
import androidx.transition.TransitionManager
|
||||
@@ -15,11 +17,8 @@ import com.navinfo.omqs.R
|
||||
import com.navinfo.omqs.databinding.FragmentConsoleBinding
|
||||
import com.navinfo.omqs.ui.activity.map.MainActivity
|
||||
import com.navinfo.omqs.ui.fragment.BaseFragment
|
||||
import com.navinfo.omqs.ui.fragment.evaluationresult.EvaluationResultFragment
|
||||
import com.navinfo.omqs.ui.fragment.layermanager.LayerManagerFragment
|
||||
import com.navinfo.omqs.ui.fragment.offlinemap.OfflineMapFragment
|
||||
import com.navinfo.omqs.ui.fragment.personalcenter.PersonalCenterFragment
|
||||
import com.navinfo.omqs.ui.fragment.qsrecordlist.QsRecordListFragment
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
|
||||
@AndroidEntryPoint
|
||||
@@ -33,6 +32,8 @@ class ConsoleFragment : BaseFragment(), OnClickListener {
|
||||
private var mFragment: Fragment? = null
|
||||
private val fragmentId = R.id.console_fragment
|
||||
|
||||
private val viewModel by viewModels<ConsoleViewModel>()
|
||||
|
||||
// 创建a场景
|
||||
private val aScene by lazy {
|
||||
Scene.getSceneForLayout(
|
||||
@@ -72,6 +73,7 @@ class ConsoleFragment : BaseFragment(), OnClickListener {
|
||||
|
||||
override fun onTransitionEnd(transition: androidx.transition.Transition) {
|
||||
initOnClickListener()
|
||||
initLiveData()
|
||||
}
|
||||
|
||||
override fun onTransitionCancel(transition: androidx.transition.Transition) {
|
||||
@@ -95,6 +97,7 @@ class ConsoleFragment : BaseFragment(), OnClickListener {
|
||||
|
||||
override fun onTransitionEnd(transition: androidx.transition.Transition) {
|
||||
initOnClickListener()
|
||||
initLiveData()
|
||||
}
|
||||
|
||||
override fun onTransitionCancel(transition: androidx.transition.Transition) {
|
||||
@@ -108,8 +111,26 @@ class ConsoleFragment : BaseFragment(), OnClickListener {
|
||||
|
||||
})
|
||||
initOnClickListener()
|
||||
|
||||
initLiveData()
|
||||
}
|
||||
|
||||
private fun initLiveData(){
|
||||
/**
|
||||
* 任务数量统计
|
||||
*/
|
||||
viewModel.liveDataTaskCount.observe(viewLifecycleOwner) {
|
||||
binding.consoleRoot.findViewById<TextView>(R.id.console_task_count_text).text =
|
||||
"共 ${it} 条"
|
||||
}
|
||||
/**
|
||||
* 评测数据数量统计
|
||||
*/
|
||||
viewModel.liveDataEvaluationResultCount.observe(viewLifecycleOwner) {
|
||||
binding.consoleRoot.findViewById<TextView>(R.id.console_evaluation_count_text).text =
|
||||
"共 ${it} 条"
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置点击事件
|
||||
@@ -193,12 +214,13 @@ class ConsoleFragment : BaseFragment(), OnClickListener {
|
||||
R.id.console_personal_center_bg, R.id.console_personal_center_icon_bg -> {
|
||||
if (sceneFlag) {
|
||||
mFragment = PersonalCenterFragment {
|
||||
if(it){
|
||||
if (it) {
|
||||
activity?.let { a ->
|
||||
a.supportFragmentManager.beginTransaction().remove(this).commit()
|
||||
a.supportFragmentManager.beginTransaction().remove(this)
|
||||
.commit()
|
||||
(a as MainActivity).showIndoorDataLayout()
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
TransitionManager.go(aScene, aTransition)
|
||||
}
|
||||
|
||||
@@ -208,12 +230,13 @@ class ConsoleFragment : BaseFragment(), OnClickListener {
|
||||
} else {
|
||||
if (mFragment !is PersonalCenterFragment) {
|
||||
mFragment = PersonalCenterFragment {
|
||||
if(it){
|
||||
if (it) {
|
||||
activity?.let { a ->
|
||||
a.supportFragmentManager.beginTransaction().remove(this).commit()
|
||||
a.supportFragmentManager.beginTransaction().remove(this)
|
||||
.commit()
|
||||
(a as MainActivity).showIndoorDataLayout()
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
TransitionManager.go(aScene, aTransition)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.navinfo.omqs.ui.fragment.console
|
||||
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.navinfo.collect.library.data.entity.QsRecordBean
|
||||
import com.navinfo.collect.library.data.entity.TaskBean
|
||||
import com.navinfo.omqs.tools.FileManager
|
||||
import com.navinfo.omqs.util.DateTimeUtil
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import io.realm.Realm
|
||||
import kotlinx.coroutines.launch
|
||||
import javax.inject.Inject
|
||||
|
||||
@HiltViewModel
|
||||
class ConsoleViewModel @Inject constructor() : ViewModel() {
|
||||
/**
|
||||
* 当前任务量统计
|
||||
*/
|
||||
val liveDataTaskCount = MutableLiveData(0)
|
||||
|
||||
/**
|
||||
* 作业数据统计
|
||||
*/
|
||||
val liveDataEvaluationResultCount = MutableLiveData(0)
|
||||
|
||||
init {
|
||||
viewModelScope.launch {
|
||||
val realm = Realm.getDefaultInstance()
|
||||
val nowTime: Long = DateTimeUtil.getNowDate().time
|
||||
val beginNowTime: Long = nowTime - 90 * 3600 * 24 * 1000L
|
||||
val syncUpload: Int = FileManager.Companion.FileUploadStatus.DONE
|
||||
val count =
|
||||
realm.where(TaskBean::class.java).notEqualTo("syncStatus", syncUpload).or()
|
||||
.between("operationTime", beginNowTime, nowTime)
|
||||
.equalTo("syncStatus", syncUpload).count()
|
||||
liveDataTaskCount.postValue(count.toInt())
|
||||
val count2 = realm.where(QsRecordBean::class.java).count()
|
||||
liveDataEvaluationResultCount.postValue(count2.toInt())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -95,55 +95,6 @@ class TaskViewModel @Inject constructor(
|
||||
fun getTaskList(context: Context) {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
|
||||
when (val result = networkService.getTaskList(Constant.USER_ID)) {
|
||||
is NetResult.Success -> {
|
||||
if (result.data != null) {
|
||||
val realm = Realm.getDefaultInstance()
|
||||
realm.executeTransaction {
|
||||
result.data.obj?.let { list ->
|
||||
for (index in list.indices) {
|
||||
val task = list[index]
|
||||
val item = realm.where(TaskBean::class.java).equalTo(
|
||||
"id", task.id
|
||||
).findFirst()
|
||||
if (item != null) {
|
||||
task.fileSize = item.fileSize
|
||||
task.status = item.status
|
||||
task.currentSize = item.currentSize
|
||||
task.hadLinkDvoList = item.hadLinkDvoList
|
||||
//已上传后不在更新操作时间
|
||||
if (task.syncStatus != FileManager.Companion.FileUploadStatus.DONE) {
|
||||
//赋值时间,用于查询过滤
|
||||
task.operationTime = DateTimeUtil.getNowDate().time
|
||||
}
|
||||
} else {
|
||||
//赋值时间,用于查询过滤
|
||||
task.operationTime = DateTimeUtil.getNowDate().time
|
||||
}
|
||||
realm.copyToRealmOrUpdate(task)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 -> {}
|
||||
}
|
||||
getLocalTaskList()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user