add getStatusIconV1

Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
alperozturk 2024-12-13 10:36:12 +01:00 committed by Alper Öztürk
parent ace68da2a7
commit 98cd991502
7 changed files with 113 additions and 20 deletions

View file

@ -4,6 +4,34 @@
<inspection_tool class="AutoCloseableResource" enabled="true" level="WARNING" enabled_by_default="true"> <inspection_tool class="AutoCloseableResource" enabled="true" level="WARNING" enabled_by_default="true">
<option name="METHOD_MATCHER_CONFIG" value="java.util.Formatter,format,java.io.Writer,append,com.google.common.base.Preconditions,checkNotNull,org.hibernate.Session,close,java.io.PrintWriter,printf,java.io.PrintStream,printf,java.nio.channels.FileChannel,position,okhttp3.Call,execute" /> <option name="METHOD_MATCHER_CONFIG" value="java.util.Formatter,format,java.io.Writer,append,com.google.common.base.Preconditions,checkNotNull,org.hibernate.Session,close,java.io.PrintWriter,printf,java.io.PrintStream,printf,java.nio.channels.FileChannel,position,okhttp3.Call,execute" />
</inspection_tool> </inspection_tool>
<inspection_tool class="ComposePreviewDimensionRespectsLimit" enabled="true" level="WARNING" enabled_by_default="true">
<option name="composableFile" value="true" />
<option name="previewFile" value="true" />
</inspection_tool>
<inspection_tool class="ComposePreviewMustBeTopLevelFunction" enabled="true" level="ERROR" enabled_by_default="true">
<option name="composableFile" value="true" />
<option name="previewFile" value="true" />
</inspection_tool>
<inspection_tool class="ComposePreviewNeedsComposableAnnotation" enabled="true" level="ERROR" enabled_by_default="true">
<option name="composableFile" value="true" />
<option name="previewFile" value="true" />
</inspection_tool>
<inspection_tool class="ComposePreviewNotSupportedInUnitTestFiles" enabled="true" level="ERROR" enabled_by_default="true">
<option name="composableFile" value="true" />
<option name="previewFile" value="true" />
</inspection_tool>
<inspection_tool class="GlancePreviewDimensionRespectsLimit" enabled="true" level="WARNING" enabled_by_default="true">
<option name="composableFile" value="true" />
</inspection_tool>
<inspection_tool class="GlancePreviewMustBeTopLevelFunction" enabled="true" level="ERROR" enabled_by_default="true">
<option name="composableFile" value="true" />
</inspection_tool>
<inspection_tool class="GlancePreviewNeedsComposableAnnotation" enabled="true" level="ERROR" enabled_by_default="true">
<option name="composableFile" value="true" />
</inspection_tool>
<inspection_tool class="GlancePreviewNotSupportedInUnitTestFiles" enabled="true" level="ERROR" enabled_by_default="true">
<option name="composableFile" value="true" />
</inspection_tool>
<inspection_tool class="KotlinUnusedImport" enabled="true" level="ERROR" enabled_by_default="true" /> <inspection_tool class="KotlinUnusedImport" enabled="true" level="ERROR" enabled_by_default="true" />
<inspection_tool class="PreviewAnnotationInFunctionWithParameters" enabled="true" level="ERROR" enabled_by_default="true"> <inspection_tool class="PreviewAnnotationInFunctionWithParameters" enabled="true" level="ERROR" enabled_by_default="true">
<option name="composableFile" value="true" /> <option name="composableFile" value="true" />
@ -13,6 +41,10 @@
<option name="composableFile" value="true" /> <option name="composableFile" value="true" />
<option name="previewFile" value="true" /> <option name="previewFile" value="true" />
</inspection_tool> </inspection_tool>
<inspection_tool class="PreviewDeviceShouldUseNewSpec" enabled="true" level="WEAK WARNING" enabled_by_default="true">
<option name="composableFile" value="true" />
<option name="previewFile" value="true" />
</inspection_tool>
<inspection_tool class="PreviewDimensionRespectsLimit" enabled="true" level="WARNING" enabled_by_default="true"> <inspection_tool class="PreviewDimensionRespectsLimit" enabled="true" level="WARNING" enabled_by_default="true">
<option name="composableFile" value="true" /> <option name="composableFile" value="true" />
<option name="previewFile" value="true" /> <option name="previewFile" value="true" />

View file

@ -50,6 +50,7 @@ import com.nextcloud.ui.composeComponents.bottomSheet.MoreActionsBottomSheet
import com.owncloud.android.R import com.owncloud.android.R
import com.owncloud.android.lib.resources.assistant.v2.model.Task import com.owncloud.android.lib.resources.assistant.v2.model.Task
import com.owncloud.android.lib.resources.assistant.v2.model.TaskTypeData import com.owncloud.android.lib.resources.assistant.v2.model.TaskTypeData
import com.owncloud.android.lib.resources.status.OCCapability
import com.owncloud.android.utils.DisplayUtils import com.owncloud.android.utils.DisplayUtils
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@ -57,7 +58,7 @@ import kotlinx.coroutines.launch
@Suppress("LongMethod") @Suppress("LongMethod")
@OptIn(ExperimentalMaterial3Api::class) @OptIn(ExperimentalMaterial3Api::class)
@Composable @Composable
fun AssistantScreen(viewModel: AssistantViewModel, activity: Activity) { fun AssistantScreen(viewModel: AssistantViewModel, capability: OCCapability, activity: Activity) {
val messageId by viewModel.snackbarMessageId.collectAsState() val messageId by viewModel.snackbarMessageId.collectAsState()
val screenOverlayState by viewModel.screenOverlayState.collectAsState() val screenOverlayState by viewModel.screenOverlayState.collectAsState()
@ -81,7 +82,7 @@ fun AssistantScreen(viewModel: AssistantViewModel, activity: Activity) {
} }
) )
) { ) {
ShowScreenState(screenState, selectedTaskType, taskTypes, viewModel, filteredTaskList) ShowScreenState(screenState, selectedTaskType, taskTypes, viewModel, filteredTaskList, capability)
ShowLinearProgressIndicator(screenState, pullRefreshState) ShowLinearProgressIndicator(screenState, pullRefreshState)
@ -104,7 +105,8 @@ private fun ShowScreenState(
selectedTaskType: TaskTypeData?, selectedTaskType: TaskTypeData?,
taskTypes: List<TaskTypeData>?, taskTypes: List<TaskTypeData>?,
viewModel: AssistantViewModel, viewModel: AssistantViewModel,
filteredTaskList: List<Task>? filteredTaskList: List<Task>?,
capability: OCCapability
) { ) {
when (screenState) { when (screenState) {
ScreenState.Refreshing -> { ScreenState.Refreshing -> {
@ -120,7 +122,8 @@ private fun ShowScreenState(
filteredTaskList ?: listOf(), filteredTaskList ?: listOf(),
taskTypes, taskTypes,
selectedTaskType, selectedTaskType,
viewModel viewModel,
capability
) )
} }
@ -223,7 +226,8 @@ private fun AssistantContent(
taskList: List<Task>, taskList: List<Task>,
taskTypes: List<TaskTypeData>?, taskTypes: List<TaskTypeData>?,
selectedTaskType: TaskTypeData?, selectedTaskType: TaskTypeData?,
viewModel: AssistantViewModel viewModel: AssistantViewModel,
capability: OCCapability
) { ) {
Column(modifier = Modifier.fillMaxSize()) { Column(modifier = Modifier.fillMaxSize()) {
taskTypes?.let { taskTypes?.let {
@ -240,6 +244,7 @@ private fun AssistantContent(
items(taskList) { task -> items(taskList) { task ->
TaskView( TaskView(
task, task,
capability,
showTaskActions = { showTaskActions = {
val newState = ScreenOverlayState.TaskActions(task) val newState = ScreenOverlayState.TaskActions(task)
viewModel.updateScreenState(newState) viewModel.updateScreenState(newState)
@ -279,6 +284,7 @@ private fun EmptyTaskList(
} }
} }
@Suppress("MagicNumber")
@Composable @Composable
@Preview @Preview
private fun AssistantScreenPreview() { private fun AssistantScreenPreview() {
@ -287,12 +293,16 @@ private fun AssistantScreenPreview() {
content = { content = {
AssistantScreen( AssistantScreen(
viewModel = AssistantViewModel(repository = mockRepository), viewModel = AssistantViewModel(repository = mockRepository),
activity = ComposeActivity() activity = ComposeActivity(),
capability = OCCapability().apply {
versionMayor = 30
}
) )
} }
) )
} }
@Suppress("MagicNumber")
@Composable @Composable
@Preview @Preview
private fun AssistantEmptyScreenPreview() { private fun AssistantEmptyScreenPreview() {
@ -301,7 +311,10 @@ private fun AssistantEmptyScreenPreview() {
content = { content = {
AssistantScreen( AssistantScreen(
viewModel = AssistantViewModel(repository = mockRepository), viewModel = AssistantViewModel(repository = mockRepository),
activity = ComposeActivity() activity = ComposeActivity(),
capability = OCCapability().apply {
versionMayor = 30
}
) )
} }
) )

View file

@ -14,6 +14,8 @@ import com.nextcloud.utils.date.DateFormatPattern
import com.nextcloud.utils.date.DateFormatter import com.nextcloud.utils.date.DateFormatter
import com.owncloud.android.R import com.owncloud.android.R
import com.owncloud.android.lib.resources.assistant.v2.model.Task import com.owncloud.android.lib.resources.assistant.v2.model.Task
import com.owncloud.android.lib.resources.status.NextcloudVersion
import com.owncloud.android.lib.resources.status.OCCapability
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
fun Task.getInputAndOutput(): String { fun Task.getInputAndOutput(): String {
@ -37,8 +39,38 @@ fun Task.getInputTitle(): String {
} }
} }
@Suppress("MagicNumber") fun Task.getStatusIcon(capability: OCCapability): Int {
fun Task.getStatusIcon(): Int { return if (capability.version.isNewerOrEqual(NextcloudVersion.nextcloud_30)) {
getStatusIconV2()
} else {
getStatusIconV1()
}
}
private fun Task.getStatusIconV1(): Int {
return when (status) {
"0" -> {
R.drawable.ic_unknown
}
"1" -> {
R.drawable.ic_clock
}
"2" -> {
R.drawable.ic_modification_desc
}
"3" -> {
R.drawable.ic_check_circle_outline
}
"4" -> {
R.drawable.image_fail
}
else -> {
R.drawable.ic_unknown
}
}
}
private fun Task.getStatusIconV2(): Int {
return when (status) { return when (status) {
"STATUS_UNKNOWN" -> { "STATUS_UNKNOWN" -> {
R.drawable.ic_unknown R.drawable.ic_unknown

View file

@ -31,10 +31,11 @@ import com.nextcloud.client.assistant.extensions.getStatusIcon
import com.owncloud.android.lib.resources.assistant.v2.model.Task import com.owncloud.android.lib.resources.assistant.v2.model.Task
import com.owncloud.android.lib.resources.assistant.v2.model.TaskInput import com.owncloud.android.lib.resources.assistant.v2.model.TaskInput
import com.owncloud.android.lib.resources.assistant.v2.model.TaskOutput import com.owncloud.android.lib.resources.assistant.v2.model.TaskOutput
import com.owncloud.android.lib.resources.status.OCCapability
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
@Composable @Composable
fun TaskStatusView(task: Task, foregroundColor: Color) { fun TaskStatusView(task: Task, foregroundColor: Color, capability: OCCapability) {
val context = LocalContext.current val context = LocalContext.current
Row( Row(
@ -43,7 +44,7 @@ fun TaskStatusView(task: Task, foregroundColor: Color) {
.padding(vertical = 16.dp), .padding(vertical = 16.dp),
verticalAlignment = Alignment.CenterVertically verticalAlignment = Alignment.CenterVertically
) { ) {
val iconId = task.getStatusIcon() val iconId = task.getStatusIcon(capability)
val description = task.getModifiedAtRepresentation(context) val description = task.getModifiedAtRepresentation(context)
Image( Image(
@ -124,7 +125,7 @@ private fun TaskStatusViewPreview() {
), ),
Task( Task(
id = 7L, id = 6L,
type = "type7", type = "type7",
status = "STATUS_UNKNOWN", status = "STATUS_UNKNOWN",
userId = "user7", userId = "user7",
@ -138,7 +139,13 @@ private fun TaskStatusViewPreview() {
LazyColumn { LazyColumn {
items(tasks) { items(tasks) {
TaskStatusView(it, foregroundColor = Color.White) TaskStatusView(
it,
foregroundColor = Color.White,
OCCapability().apply {
versionMayor = 30
}
)
} }
} }
} }

View file

@ -44,10 +44,11 @@ import com.owncloud.android.R
import com.owncloud.android.lib.resources.assistant.v2.model.Task import com.owncloud.android.lib.resources.assistant.v2.model.Task
import com.owncloud.android.lib.resources.assistant.v2.model.TaskInput import com.owncloud.android.lib.resources.assistant.v2.model.TaskInput
import com.owncloud.android.lib.resources.assistant.v2.model.TaskOutput import com.owncloud.android.lib.resources.assistant.v2.model.TaskOutput
import com.owncloud.android.lib.resources.status.OCCapability
@Suppress("LongMethod", "MagicNumber") @Suppress("LongMethod", "MagicNumber")
@Composable @Composable
fun TaskView(task: Task, showTaskActions: () -> Unit) { fun TaskView(task: Task, capability: OCCapability, showTaskActions: () -> Unit) {
var showTaskDetailBottomSheet by remember { mutableStateOf(false) } var showTaskDetailBottomSheet by remember { mutableStateOf(false) }
Box { Box {
@ -98,10 +99,10 @@ fun TaskView(task: Task, showTaskActions: () -> Unit) {
) )
} }
TaskStatusView(task, foregroundColor = Color.White) TaskStatusView(task, foregroundColor = Color.White, capability)
if (showTaskDetailBottomSheet) { if (showTaskDetailBottomSheet) {
TaskDetailBottomSheet(task, showTaskActions = { TaskDetailBottomSheet(task, capability, showTaskActions = {
showTaskDetailBottomSheet = false showTaskDetailBottomSheet = false
showTaskActions() showTaskActions()
}) { }) {
@ -145,6 +146,9 @@ private fun TaskViewPreview() {
1707692337, 1707692337,
1707692337 1707692337
), ),
OCCapability().apply {
versionMayor = 30
},
showTaskActions = { showTaskActions = {
} }
) )

View file

@ -50,11 +50,12 @@ import com.owncloud.android.R
import com.owncloud.android.lib.resources.assistant.v2.model.Task import com.owncloud.android.lib.resources.assistant.v2.model.Task
import com.owncloud.android.lib.resources.assistant.v2.model.TaskInput import com.owncloud.android.lib.resources.assistant.v2.model.TaskInput
import com.owncloud.android.lib.resources.assistant.v2.model.TaskOutput import com.owncloud.android.lib.resources.assistant.v2.model.TaskOutput
import com.owncloud.android.lib.resources.status.OCCapability
@Suppress("LongMethod") @Suppress("LongMethod")
@OptIn(ExperimentalFoundationApi::class, ExperimentalMaterial3Api::class) @OptIn(ExperimentalFoundationApi::class, ExperimentalMaterial3Api::class)
@Composable @Composable
fun TaskDetailBottomSheet(task: Task, showTaskActions: () -> Unit, dismiss: () -> Unit) { fun TaskDetailBottomSheet(task: Task, capability: OCCapability, showTaskActions: () -> Unit, dismiss: () -> Unit) {
var showInput by remember { mutableStateOf(true) } var showInput by remember { mutableStateOf(true) }
val sheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true) val sheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true)
@ -142,7 +143,7 @@ fun TaskDetailBottomSheet(task: Task, showTaskActions: () -> Unit, dismiss: () -
) )
} }
TaskStatusView(task, foregroundColor = colorResource(R.color.text_color)) TaskStatusView(task, foregroundColor = colorResource(R.color.text_color), capability)
Spacer(modifier = Modifier.height(32.dp)) Spacer(modifier = Modifier.height(32.dp))
} }
@ -187,6 +188,9 @@ private fun TaskDetailScreenPreview() {
1707692337, 1707692337,
1707692337 1707692337
), ),
OCCapability().apply {
versionMayor = 30
},
showTaskActions = { showTaskActions = {
} }
) { ) {

View file

@ -89,7 +89,8 @@ class ComposeActivity : DrawerActivity() {
viewModel = AssistantViewModel( viewModel = AssistantViewModel(
repository = AssistantRepository(client, capabilities) repository = AssistantRepository(client, capabilities)
), ),
activity = this activity = this,
capability = capabilities
) )
} }
} }