修改任务线颜色

This commit is contained in:
squallzhjch
2023-05-06 16:13:12 +08:00
parent 8e4d1c7e0e
commit 51be5bd178
3 changed files with 19 additions and 13 deletions

View File

@@ -22,6 +22,7 @@ import kotlinx.coroutines.withContext
import java.util.*
import javax.inject.Inject
@HiltViewModel
class TaskListViewModel @Inject constructor(
private val networkService: NetworkService,
@@ -30,6 +31,9 @@ class TaskListViewModel @Inject constructor(
val liveDataTaskList = MutableLiveData<List<TaskBean>>()
val colors =
arrayOf(Color.RED, Color.YELLOW, Color.BLUE, Color.MAGENTA, Color.GREEN, Color.CYAN)
/**
* 下载任务列表
*/
@@ -43,7 +47,8 @@ class TaskListViewModel @Inject constructor(
val realm = Realm.getDefaultInstance()
realm.executeTransaction {
result.data.obj?.let { list ->
for (task in list) {
for (index in list.indices) {
val task = list[index]
val item = realm.where(TaskBean::class.java).equalTo(
"id", task.id
).findFirst()
@@ -54,14 +59,17 @@ class TaskListViewModel @Inject constructor(
task.currentSize = item.currentSize
task.color = item.color
} else {
val random = Random()
task.color = Color.argb(
255,
random.nextInt(256),
random.nextInt(256),
random.nextInt(256)
)
Log.e("jingo", "任务颜色 ${task.color}")
if (index < 6)
task.color = colors[index]
else {
val random = Random()
task.color = Color.argb(
255,
random.nextInt(256),
random.nextInt(256),
random.nextInt(256)
)
}
}
realm.copyToRealmOrUpdate(task)
}
@@ -105,9 +113,6 @@ class TaskListViewModel @Inject constructor(
mapController.lineHandler.omdbTaskLinkLayer.addLineList(item.hadLinkDvoList)
}
}
}
}
}