增加数据上传业务
This commit is contained in:
parent
a81e2f5d82
commit
c5876c9713
50
app/src/main/java/com/navinfo/omqs/bean/EvaluationInfo.kt
Normal file
50
app/src/main/java/com/navinfo/omqs/bean/EvaluationInfo.kt
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
package com.navinfo.omqs.bean
|
||||||
|
|
||||||
|
import com.google.gson.annotations.SerializedName
|
||||||
|
|
||||||
|
data class EvaluationInfo(
|
||||||
|
@SerializedName("evaluationTaskId")
|
||||||
|
val evaluationTaskId: String = "",//测评任务id
|
||||||
|
@SerializedName("linkPid")
|
||||||
|
val linkPid: String = "",//Link号
|
||||||
|
|
||||||
|
@SerializedName("linkStatus")
|
||||||
|
val linkStatus: String = "",//Link状态
|
||||||
|
|
||||||
|
@SerializedName("markId")
|
||||||
|
val markId: String = "",//Link状态
|
||||||
|
|
||||||
|
@SerializedName("trackPhotoNumber")
|
||||||
|
val trackPhotoNumber: String = "",//轨迹照片编号 多个分号隔开
|
||||||
|
|
||||||
|
@SerializedName("markGeometry")
|
||||||
|
val markGeometry: String = "",//MARK_几何坐标
|
||||||
|
|
||||||
|
@SerializedName("featureName")
|
||||||
|
val featureName: String = "",//问题类型
|
||||||
|
|
||||||
|
@SerializedName("problemType")
|
||||||
|
val problemType: String = "",//问题现象
|
||||||
|
|
||||||
|
@SerializedName("problemPhenomenon")
|
||||||
|
val problemPhenomenon: String = "",//问题现象
|
||||||
|
|
||||||
|
@SerializedName("problemDesc")
|
||||||
|
val problemDesc: String = "",//问题描述
|
||||||
|
|
||||||
|
@SerializedName("problemLink")
|
||||||
|
val problemLink: String = "",//问题环节
|
||||||
|
|
||||||
|
@SerializedName("problemReason")
|
||||||
|
val problemReason: String = "",//问题原因
|
||||||
|
|
||||||
|
@SerializedName("evaluatorName")
|
||||||
|
val evaluatorName: String = "",//测评人名称
|
||||||
|
|
||||||
|
@SerializedName("evaluationDate")
|
||||||
|
val evaluationDate: String = "",//测评日期(yyyy-mm-dd)
|
||||||
|
|
||||||
|
@SerializedName("evaluationWay")
|
||||||
|
val evaluationWay: String = ""//测评方式
|
||||||
|
)
|
||||||
|
|
@ -2,6 +2,7 @@ package com.navinfo.omqs.bean
|
|||||||
|
|
||||||
import com.google.gson.annotations.SerializedName
|
import com.google.gson.annotations.SerializedName
|
||||||
import com.navinfo.omqs.Constant
|
import com.navinfo.omqs.Constant
|
||||||
|
import com.navinfo.omqs.tools.FileManager
|
||||||
import com.navinfo.omqs.tools.FileManager.Companion.FileDownloadStatus
|
import com.navinfo.omqs.tools.FileManager.Companion.FileDownloadStatus
|
||||||
import io.realm.RealmList
|
import io.realm.RealmList
|
||||||
import io.realm.RealmObject
|
import io.realm.RealmObject
|
||||||
@ -57,6 +58,12 @@ open class TaskBean @JvmOverloads constructor(
|
|||||||
* 当前下载状态
|
* 当前下载状态
|
||||||
*/
|
*/
|
||||||
var status: Int = FileDownloadStatus.NONE,
|
var status: Int = FileDownloadStatus.NONE,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 上传状态
|
||||||
|
*/
|
||||||
|
var syncStatus: Int = FileManager.Companion.FileUploadStatus.NONE,
|
||||||
|
|
||||||
@Ignore
|
@Ignore
|
||||||
var message: String = ""
|
var message: String = ""
|
||||||
) : RealmObject() {
|
) : RealmObject() {
|
||||||
|
@ -7,6 +7,7 @@ import com.navinfo.omqs.db.RoomAppDatabase
|
|||||||
import com.navinfo.omqs.http.RetrofitNetworkServiceAPI
|
import com.navinfo.omqs.http.RetrofitNetworkServiceAPI
|
||||||
import com.navinfo.omqs.http.offlinemapdownload.OfflineMapDownloadManager
|
import com.navinfo.omqs.http.offlinemapdownload.OfflineMapDownloadManager
|
||||||
import com.navinfo.omqs.http.taskdownload.TaskDownloadManager
|
import com.navinfo.omqs.http.taskdownload.TaskDownloadManager
|
||||||
|
import com.navinfo.omqs.http.taskupload.TaskUploadManager
|
||||||
import dagger.Module
|
import dagger.Module
|
||||||
import dagger.Provides
|
import dagger.Provides
|
||||||
import dagger.hilt.InstallIn
|
import dagger.hilt.InstallIn
|
||||||
@ -48,6 +49,16 @@ class ActivityModule {
|
|||||||
): TaskDownloadManager =
|
): TaskDownloadManager =
|
||||||
TaskDownloadManager(importFactory, networkServiceAPI)
|
TaskDownloadManager(importFactory, networkServiceAPI)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 注入任务下载
|
||||||
|
*/
|
||||||
|
@ActivityRetainedScoped
|
||||||
|
@Provides
|
||||||
|
fun providesTaskListUploadManager(
|
||||||
|
networkServiceAPI: RetrofitNetworkServiceAPI,
|
||||||
|
): TaskUploadManager =
|
||||||
|
TaskUploadManager(networkServiceAPI)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 实验失败,这样创建,viewmodel不会在activity销毁的时候同时销毁
|
* 实验失败,这样创建,viewmodel不会在activity销毁的时候同时销毁
|
||||||
* 4-14:因为没有传入activity的 owner,无法检测生命周期,
|
* 4-14:因为没有传入activity的 owner,无法检测生命周期,
|
||||||
|
@ -1,14 +1,12 @@
|
|||||||
package com.navinfo.omqs.http
|
package com.navinfo.omqs.http
|
||||||
|
|
||||||
|
import com.navinfo.omqs.bean.EvaluationInfo
|
||||||
import com.navinfo.omqs.bean.OfflineMapCityBean
|
import com.navinfo.omqs.bean.OfflineMapCityBean
|
||||||
import com.navinfo.omqs.bean.TaskBean
|
import com.navinfo.omqs.bean.TaskBean
|
||||||
import okhttp3.ResponseBody
|
import okhttp3.ResponseBody
|
||||||
|
import retrofit2.Call
|
||||||
import retrofit2.Response
|
import retrofit2.Response
|
||||||
import retrofit2.http.GET
|
import retrofit2.http.*
|
||||||
import retrofit2.http.Header
|
|
||||||
import retrofit2.http.Query
|
|
||||||
import retrofit2.http.Streaming
|
|
||||||
import retrofit2.http.Url
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* retrofit2 网络请求接口
|
* retrofit2 网络请求接口
|
||||||
@ -58,6 +56,10 @@ interface RetrofitNetworkServiceAPI {
|
|||||||
@Query("evaluatorNo") evaluatorNo: String,
|
@Query("evaluatorNo") evaluatorNo: String,
|
||||||
): Response<DefaultTaskResponse<List<TaskBean>>>
|
): Response<DefaultTaskResponse<List<TaskBean>>>
|
||||||
|
|
||||||
|
@Headers("Content-Type: application/json")
|
||||||
|
@POST("/devcp/upload")
|
||||||
|
fun postRequest(@Body listEvaluationInfo: List<EvaluationInfo>?): Call<ResponseBody>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @FormUrlEncoded 请求格式注解,请求实体是一个From表单,每个键值对需要使用@Field注解
|
* @FormUrlEncoded 请求格式注解,请求实体是一个From表单,每个键值对需要使用@Field注解
|
||||||
@Field 请求参数注解,提交请求的表单字段,必须要添加,而且需要配合@FormUrlEncoded使用
|
@Field 请求参数注解,提交请求的表单字段,必须要添加,而且需要配合@FormUrlEncoded使用
|
||||||
|
@ -0,0 +1,105 @@
|
|||||||
|
package com.navinfo.omqs.http.taskupload
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import androidx.lifecycle.LifecycleOwner
|
||||||
|
import androidx.lifecycle.Observer
|
||||||
|
import com.navinfo.omqs.bean.TaskBean
|
||||||
|
import com.navinfo.omqs.http.RetrofitNetworkServiceAPI
|
||||||
|
import java.util.concurrent.ConcurrentHashMap
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 管理任务数据上传
|
||||||
|
*/
|
||||||
|
|
||||||
|
class TaskUploadManager constructor(
|
||||||
|
val netApi: RetrofitNetworkServiceAPI,
|
||||||
|
) {
|
||||||
|
|
||||||
|
lateinit var context: Context
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 最多同时下载数量
|
||||||
|
*/
|
||||||
|
private val MAX_SCOPE = 1
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 存储有哪些城市需要下载的队列
|
||||||
|
*/
|
||||||
|
private val scopeMap: ConcurrentHashMap<Int, TaskUploadScope> by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) {
|
||||||
|
ConcurrentHashMap<Int, TaskUploadScope>()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 存储正在下载的城市队列
|
||||||
|
*/
|
||||||
|
private val taskScopeMap: ConcurrentHashMap<Int, TaskUploadScope> by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) {
|
||||||
|
ConcurrentHashMap<Int, TaskUploadScope>()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun init(context: Context) {
|
||||||
|
this.context = context
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 启动下载任务
|
||||||
|
* 请不要直接使用此方法启动下载任务,它是交由[OfflineMapDownloadScope]进行调用
|
||||||
|
*/
|
||||||
|
fun launchScope(scope: TaskUploadScope) {
|
||||||
|
if (taskScopeMap.size >= MAX_SCOPE) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (taskScopeMap.contains(scope.taskBean.id)) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
taskScopeMap[scope.taskBean.id] = scope
|
||||||
|
scope.launch()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 启动下一个任务,如果有正在等待中的任务的话
|
||||||
|
* 请不要直接使用此方法启动下载任务,它是交由[OfflineMapDownloadScope]进行调用
|
||||||
|
* @param previousUrl 上一个下载任务的下载连接
|
||||||
|
*/
|
||||||
|
fun launchNext(id: Int) {
|
||||||
|
taskScopeMap.remove(id)
|
||||||
|
for (entrySet in scopeMap) {
|
||||||
|
val uploadScope = entrySet.value
|
||||||
|
if (uploadScope.isNotSync()) {
|
||||||
|
launchScope(uploadScope)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将下载任务加入到协程作用域的下载队列里
|
||||||
|
* 请求一个下载任务[OfflineMapDownloadScope]
|
||||||
|
* 这是创建[OfflineMapDownloadScope]的唯一途径,请不要通过其他方式创建[OfflineMapDownloadScope]
|
||||||
|
*/
|
||||||
|
fun start(id: Int) {
|
||||||
|
scopeMap[id]?.start()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fun addTask(taskBean: TaskBean) {
|
||||||
|
if (!scopeMap.containsKey(taskBean.id)) {
|
||||||
|
scopeMap[taskBean.id] = TaskUploadScope( this, taskBean)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fun observer(
|
||||||
|
id: Int, lifecycleOwner: LifecycleOwner, observer: Observer<TaskBean>
|
||||||
|
) {
|
||||||
|
if (scopeMap.containsKey(id)) {
|
||||||
|
scopeMap[id]!!.observer(lifecycleOwner, observer)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun removeObserver(id: Int) {
|
||||||
|
if (scopeMap.containsKey(id)) {
|
||||||
|
scopeMap[id]!!.removeObserver()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,158 @@
|
|||||||
|
package com.navinfo.omqs.http.taskupload
|
||||||
|
|
||||||
|
import android.util.Log
|
||||||
|
import androidx.lifecycle.LifecycleOwner
|
||||||
|
import androidx.lifecycle.MutableLiveData
|
||||||
|
import androidx.lifecycle.Observer
|
||||||
|
import com.navinfo.collect.library.data.entity.QsRecordBean
|
||||||
|
import com.navinfo.omqs.bean.EvaluationInfo
|
||||||
|
import com.navinfo.omqs.bean.TaskBean
|
||||||
|
import com.navinfo.omqs.tools.FileManager
|
||||||
|
import com.navinfo.omqs.tools.FileManager.Companion.FileDownloadStatus
|
||||||
|
import io.realm.Realm
|
||||||
|
import kotlinx.coroutines.*
|
||||||
|
import okhttp3.ResponseBody
|
||||||
|
import retrofit2.Call
|
||||||
|
import retrofit2.Callback
|
||||||
|
import retrofit2.Response
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
class TaskUploadScope(
|
||||||
|
private val uploadManager: TaskUploadManager,
|
||||||
|
val taskBean: TaskBean,
|
||||||
|
) :
|
||||||
|
CoroutineScope by CoroutineScope(Dispatchers.IO + CoroutineName("OfflineMapUpLoad")) {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*下载任务,用来取消的
|
||||||
|
*/
|
||||||
|
private var uploadJob: Job? = null
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 管理观察者,同时只有一个就行了
|
||||||
|
*/
|
||||||
|
private val observer = Observer<Any> {}
|
||||||
|
// private var lifecycleOwner: LifecycleOwner? = null
|
||||||
|
|
||||||
|
/**
|
||||||
|
*通知UI更新
|
||||||
|
*/
|
||||||
|
private val uploadData = MutableLiveData<TaskBean>()
|
||||||
|
|
||||||
|
init {
|
||||||
|
uploadData.value = taskBean
|
||||||
|
}
|
||||||
|
|
||||||
|
//改进的代码
|
||||||
|
fun start() {
|
||||||
|
change(FileDownloadStatus.WAITING)
|
||||||
|
uploadManager.launchScope(this@TaskUploadScope)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 启动协程进行下载
|
||||||
|
* 请不要尝试在外部调用此方法,那样会脱离[OfflineMapuploadManager]的管理
|
||||||
|
*/
|
||||||
|
fun launch() {
|
||||||
|
uploadJob = launch() {
|
||||||
|
upload()
|
||||||
|
uploadManager.launchNext(taskBean.id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新状态
|
||||||
|
* @param status [OfflineMapCityBean.Status]
|
||||||
|
*/
|
||||||
|
private fun change(status: Int, message: String = "") {
|
||||||
|
if (taskBean.syncStatus != status ) {
|
||||||
|
uploadData.postValue(taskBean)
|
||||||
|
launch {
|
||||||
|
val realm = Realm.getDefaultInstance()
|
||||||
|
realm.executeTransaction {
|
||||||
|
it.copyToRealmOrUpdate(taskBean)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否未上传
|
||||||
|
*/
|
||||||
|
fun isNotSync(): Boolean {
|
||||||
|
return taskBean.syncStatus == FileManager.Companion.FileUploadStatus.NONE
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加下载任务观察者
|
||||||
|
*/
|
||||||
|
fun observer(owner: LifecycleOwner, ob: Observer<TaskBean>) {
|
||||||
|
removeObserver()
|
||||||
|
uploadData.observe(owner, ob)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 上传文件
|
||||||
|
*/
|
||||||
|
private suspend fun upload() {
|
||||||
|
try {
|
||||||
|
//如果已上传则返回
|
||||||
|
if (taskBean.syncStatus == FileManager.Companion.FileUploadStatus.DONE) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
val realm = Realm.getDefaultInstance()
|
||||||
|
taskBean.hadLinkDvoList.forEach {
|
||||||
|
val list = realm.where(QsRecordBean::class.java).equalTo("linkId", it.linkPid).findAll()
|
||||||
|
}
|
||||||
|
|
||||||
|
val list: MutableList<EvaluationInfo> = ArrayList()
|
||||||
|
val evaluationInfo = EvaluationInfo(taskBean.id.toString(),
|
||||||
|
"123123",
|
||||||
|
"原库",
|
||||||
|
"123123",
|
||||||
|
"",
|
||||||
|
"POINT (116.252097 40.00752)",
|
||||||
|
"点限速",
|
||||||
|
"多余",
|
||||||
|
"多余",
|
||||||
|
"多余",
|
||||||
|
"多余",
|
||||||
|
"多余",
|
||||||
|
"张三",
|
||||||
|
"20230426")
|
||||||
|
|
||||||
|
list.add(evaluationInfo)
|
||||||
|
|
||||||
|
//3. Create an instance of the interface:
|
||||||
|
val apiService = uploadManager.netApi.postRequest(list).enqueue(object :
|
||||||
|
Callback<ResponseBody> {
|
||||||
|
override fun onResponse(call: Call<ResponseBody>, response: Response<ResponseBody>) {
|
||||||
|
// handle the response
|
||||||
|
Log.e("qj","")
|
||||||
|
change(FileManager.Companion.FileUploadStatus.NONE)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onFailure(call: Call<ResponseBody>, t: Throwable) {
|
||||||
|
// handle the failure
|
||||||
|
Log.e("qj","")
|
||||||
|
change(FileManager.Companion.FileUploadStatus.ERROR)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
} catch (e: Throwable) {
|
||||||
|
change(FileManager.Companion.FileUploadStatus.ERROR)
|
||||||
|
Log.e("jingo","数据上传出错 ${e.message}")
|
||||||
|
} finally {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun removeObserver() {
|
||||||
|
uploadData.observeForever(observer)
|
||||||
|
uploadData.removeObserver(observer)
|
||||||
|
}
|
||||||
|
}
|
@ -22,6 +22,12 @@ class FileManager {
|
|||||||
const val DONE = 8 //完成
|
const val DONE = 8 //完成
|
||||||
}
|
}
|
||||||
|
|
||||||
|
object FileUploadStatus {
|
||||||
|
const val NONE = 0 //无状态
|
||||||
|
const val DONE = 1 //完成
|
||||||
|
const val ERROR = 2 //错误
|
||||||
|
}
|
||||||
|
|
||||||
//初始化数据文件夹
|
//初始化数据文件夹
|
||||||
fun initRootDir(context: Context) {
|
fun initRootDir(context: Context) {
|
||||||
// 在SD卡创建项目目录
|
// 在SD卡创建项目目录
|
||||||
|
@ -66,7 +66,7 @@ class MainActivity : BaseActivity() {
|
|||||||
mapController.locationLayerHandler.startLocation()
|
mapController.locationLayerHandler.startLocation()
|
||||||
//启动轨迹存储
|
//启动轨迹存储
|
||||||
mapController.locationLayerHandler.setNiLocationListener(NiLocationListener {
|
mapController.locationLayerHandler.setNiLocationListener(NiLocationListener {
|
||||||
ToastUtils.showLong("定位${it.longitude}")
|
//ToastUtils.showLong("定位${it.longitude}")
|
||||||
binding!!.viewModel!!.addSaveTrace(it)
|
binding!!.viewModel!!.addSaveTrace(it)
|
||||||
binding!!.viewModel!!.startSaveTraceThread(this)
|
binding!!.viewModel!!.startSaveTraceThread(this)
|
||||||
})
|
})
|
||||||
|
@ -7,7 +7,6 @@ import android.util.Log
|
|||||||
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.MutableLiveData
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import androidx.navigation.findNavController
|
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.dao.impl.TraceDataBase
|
||||||
import com.navinfo.collect.library.data.entity.NiLocation
|
import com.navinfo.collect.library.data.entity.NiLocation
|
||||||
import com.navinfo.collect.library.map.NIMapController
|
import com.navinfo.collect.library.map.NIMapController
|
||||||
@ -62,7 +61,7 @@ class MainViewModel @Inject constructor(
|
|||||||
|
|
||||||
Log.e("qj", LibVlcUtil.hasCompatibleCPU(context).toString())
|
Log.e("qj", LibVlcUtil.hasCompatibleCPU(context).toString())
|
||||||
|
|
||||||
ToastUtils.showShort("点击了相机")
|
//ToastUtils.showShort("点击了相机")
|
||||||
|
|
||||||
if (mCameraDialog == null) {
|
if (mCameraDialog == null) {
|
||||||
mCameraDialog = CommonDialog(
|
mCameraDialog = CommonDialog(
|
||||||
|
@ -10,6 +10,8 @@ import com.navinfo.omqs.R
|
|||||||
import com.navinfo.omqs.bean.TaskBean
|
import com.navinfo.omqs.bean.TaskBean
|
||||||
import com.navinfo.omqs.databinding.AdapterTaskListBinding
|
import com.navinfo.omqs.databinding.AdapterTaskListBinding
|
||||||
import com.navinfo.omqs.http.taskdownload.TaskDownloadManager
|
import com.navinfo.omqs.http.taskdownload.TaskDownloadManager
|
||||||
|
import com.navinfo.omqs.http.taskupload.TaskUploadManager
|
||||||
|
import com.navinfo.omqs.tools.FileManager
|
||||||
import com.navinfo.omqs.tools.FileManager.Companion.FileDownloadStatus
|
import com.navinfo.omqs.tools.FileManager.Companion.FileDownloadStatus
|
||||||
import com.navinfo.omqs.ui.other.BaseRecyclerViewAdapter
|
import com.navinfo.omqs.ui.other.BaseRecyclerViewAdapter
|
||||||
import com.navinfo.omqs.ui.other.BaseViewHolder
|
import com.navinfo.omqs.ui.other.BaseViewHolder
|
||||||
@ -25,7 +27,8 @@ import javax.inject.Inject
|
|||||||
*使用 LifecycleRegistry 给 ViewHolder 分发生命周期(这里使用了这个)
|
*使用 LifecycleRegistry 给 ViewHolder 分发生命周期(这里使用了这个)
|
||||||
*/
|
*/
|
||||||
class TaskListAdapter(
|
class TaskListAdapter(
|
||||||
private val downloadManager: TaskDownloadManager
|
private val downloadManager: TaskDownloadManager,
|
||||||
|
private val uploadManager: TaskUploadManager
|
||||||
) : BaseRecyclerViewAdapter<TaskBean>() {
|
) : BaseRecyclerViewAdapter<TaskBean>() {
|
||||||
|
|
||||||
|
|
||||||
@ -48,6 +51,18 @@ class TaskListAdapter(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val uploadBtnClick = View.OnClickListener() {
|
||||||
|
if (it.tag != null) {
|
||||||
|
val taskBean = data[it.tag as Int]
|
||||||
|
Log.e("jingo", "开始上传 ${taskBean.syncStatus}")
|
||||||
|
when (taskBean.syncStatus) {
|
||||||
|
FileManager.Companion.FileUploadStatus.NONE->{
|
||||||
|
uploadManager.start(taskBean.id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BaseViewHolder {
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BaseViewHolder {
|
||||||
val viewBinding =
|
val viewBinding =
|
||||||
AdapterTaskListBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
AdapterTaskListBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
||||||
@ -69,8 +84,12 @@ class TaskListAdapter(
|
|||||||
changeViews(binding, taskBean)
|
changeViews(binding, taskBean)
|
||||||
downloadManager.addTask(taskBean)
|
downloadManager.addTask(taskBean)
|
||||||
downloadManager.observer(taskBean.id, holder, DownloadObserver(taskBean.id, binding))
|
downloadManager.observer(taskBean.id, holder, DownloadObserver(taskBean.id, binding))
|
||||||
|
uploadManager.addTask(taskBean)
|
||||||
|
uploadManager.observer(taskBean.id, holder, UploadObserver(taskBean.id, binding))
|
||||||
binding.taskDownloadBtn.tag = position
|
binding.taskDownloadBtn.tag = position
|
||||||
binding.taskDownloadBtn.setOnClickListener(downloadBtnClick)
|
binding.taskDownloadBtn.setOnClickListener(downloadBtnClick)
|
||||||
|
binding.taskUploadBtn.tag = position
|
||||||
|
binding.taskUploadBtn.setOnClickListener(uploadBtnClick)
|
||||||
binding.taskName.text = taskBean.evaluationTaskName
|
binding.taskName.text = taskBean.evaluationTaskName
|
||||||
binding.taskCityName.text = taskBean.cityName
|
binding.taskCityName.text = taskBean.cityName
|
||||||
binding.taskDataVersion.text = "版本号:${taskBean.dataVersion}"
|
binding.taskDataVersion.text = "版本号:${taskBean.dataVersion}"
|
||||||
@ -85,6 +104,22 @@ class TaskListAdapter(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inner class UploadObserver(val id: Int, val binding: AdapterTaskListBinding) :
|
||||||
|
Observer<TaskBean> {
|
||||||
|
override fun onChanged(t: TaskBean?) {
|
||||||
|
if (id == t?.id)
|
||||||
|
changeUploadTxtViews(binding, t)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun changeUploadTxtViews(binding: AdapterTaskListBinding, taskBean: TaskBean) {
|
||||||
|
when (taskBean.syncStatus) {
|
||||||
|
FileManager.Companion.FileUploadStatus.NONE -> {
|
||||||
|
binding.taskUploadBtn.text = "已上传"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun changeViews(binding: AdapterTaskListBinding, taskBean: TaskBean) {
|
private fun changeViews(binding: AdapterTaskListBinding, taskBean: TaskBean) {
|
||||||
if (taskBean.fileSize > 0L) {
|
if (taskBean.fileSize > 0L) {
|
||||||
|
@ -9,6 +9,7 @@ import androidx.navigation.fragment.findNavController
|
|||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import com.navinfo.omqs.databinding.FragmentTaskListBinding
|
import com.navinfo.omqs.databinding.FragmentTaskListBinding
|
||||||
import com.navinfo.omqs.http.taskdownload.TaskDownloadManager
|
import com.navinfo.omqs.http.taskdownload.TaskDownloadManager
|
||||||
|
import com.navinfo.omqs.http.taskupload.TaskUploadManager
|
||||||
import com.navinfo.omqs.ui.fragment.BaseFragment
|
import com.navinfo.omqs.ui.fragment.BaseFragment
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
@ -17,12 +18,14 @@ import javax.inject.Inject
|
|||||||
class TaskListFragment : BaseFragment(){
|
class TaskListFragment : BaseFragment(){
|
||||||
@Inject
|
@Inject
|
||||||
lateinit var downloadManager: TaskDownloadManager
|
lateinit var downloadManager: TaskDownloadManager
|
||||||
|
@Inject
|
||||||
|
lateinit var uploadManager: TaskUploadManager
|
||||||
private var _binding: FragmentTaskListBinding? = null
|
private var _binding: FragmentTaskListBinding? = null
|
||||||
private val viewModel by viewModels<TaskListViewModel>()
|
private val viewModel by viewModels<TaskListViewModel>()
|
||||||
private val binding get() = _binding!!
|
private val binding get() = _binding!!
|
||||||
private val adapter: TaskListAdapter by lazy {
|
private val adapter: TaskListAdapter by lazy {
|
||||||
TaskListAdapter(
|
TaskListAdapter(
|
||||||
downloadManager,
|
downloadManager,uploadManager
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -31,6 +34,7 @@ class TaskListFragment : BaseFragment(){
|
|||||||
savedInstanceState: Bundle?
|
savedInstanceState: Bundle?
|
||||||
): View {
|
): View {
|
||||||
downloadManager.init(requireContext())
|
downloadManager.init(requireContext())
|
||||||
|
uploadManager.init(requireContext())
|
||||||
_binding = FragmentTaskListBinding.inflate(inflater, container, false)
|
_binding = FragmentTaskListBinding.inflate(inflater, container, false)
|
||||||
return binding.root
|
return binding.root
|
||||||
|
|
||||||
|
@ -65,6 +65,19 @@
|
|||||||
android:textColor="@color/btn_blue_solid"
|
android:textColor="@color/btn_blue_solid"
|
||||||
android:textSize="@dimen/card_title_font_2size" />
|
android:textSize="@dimen/card_title_font_2size" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/task_upload_btn"
|
||||||
|
style="@style/map_download_style_btn"
|
||||||
|
android:layout_width="60dp"
|
||||||
|
android:layout_centerVertical="true"
|
||||||
|
android:layout_marginRight="5dp"
|
||||||
|
android:layout_toLeftOf="@id/task_download_btn"
|
||||||
|
android:gravity="center"
|
||||||
|
android:shadowColor="@android:color/transparent"
|
||||||
|
android:text="同步"
|
||||||
|
android:textColor="@color/btn_blue_solid"
|
||||||
|
android:textSize="@dimen/card_title_font_2size" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/task_status"
|
android:id="@+id/task_status"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user