From 98cd99150222f40fca28012ba01bdbe7a80a025a Mon Sep 17 00:00:00 2001 From: alperozturk Date: Fri, 13 Dec 2024 10:36:12 +0100 Subject: [PATCH] add getStatusIconV1 Signed-off-by: alperozturk --- .idea/inspectionProfiles/ktlint.xml | 34 +++++++++++++++++- .../client/assistant/AsssistantScreen.kt | 27 ++++++++++---- .../assistant/extensions/TaskExtensions.kt | 36 +++++++++++++++++-- .../client/assistant/task/TaskStatusView.kt | 15 +++++--- .../client/assistant/task/TaskView.kt | 10 ++++-- .../taskDetail/TaskDetailBottomSheet.kt | 8 +++-- .../ui/composeActivity/ComposeActivity.kt | 3 +- 7 files changed, 113 insertions(+), 20 deletions(-) diff --git a/.idea/inspectionProfiles/ktlint.xml b/.idea/inspectionProfiles/ktlint.xml index 2064cfd5a0..3ce98ead8c 100644 --- a/.idea/inspectionProfiles/ktlint.xml +++ b/.idea/inspectionProfiles/ktlint.xml @@ -4,6 +4,34 @@ + + + + + + + + + + + + + + + + + + - + \ No newline at end of file diff --git a/app/src/main/java/com/nextcloud/client/assistant/AsssistantScreen.kt b/app/src/main/java/com/nextcloud/client/assistant/AsssistantScreen.kt index ab9d7de13f..c3a2f098c3 100644 --- a/app/src/main/java/com/nextcloud/client/assistant/AsssistantScreen.kt +++ b/app/src/main/java/com/nextcloud/client/assistant/AsssistantScreen.kt @@ -50,6 +50,7 @@ import com.nextcloud.ui.composeComponents.bottomSheet.MoreActionsBottomSheet import com.owncloud.android.R 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.status.OCCapability import com.owncloud.android.utils.DisplayUtils import kotlinx.coroutines.delay import kotlinx.coroutines.launch @@ -57,7 +58,7 @@ import kotlinx.coroutines.launch @Suppress("LongMethod") @OptIn(ExperimentalMaterial3Api::class) @Composable -fun AssistantScreen(viewModel: AssistantViewModel, activity: Activity) { +fun AssistantScreen(viewModel: AssistantViewModel, capability: OCCapability, activity: Activity) { val messageId by viewModel.snackbarMessageId.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) @@ -104,7 +105,8 @@ private fun ShowScreenState( selectedTaskType: TaskTypeData?, taskTypes: List?, viewModel: AssistantViewModel, - filteredTaskList: List? + filteredTaskList: List?, + capability: OCCapability ) { when (screenState) { ScreenState.Refreshing -> { @@ -120,7 +122,8 @@ private fun ShowScreenState( filteredTaskList ?: listOf(), taskTypes, selectedTaskType, - viewModel + viewModel, + capability ) } @@ -223,7 +226,8 @@ private fun AssistantContent( taskList: List, taskTypes: List?, selectedTaskType: TaskTypeData?, - viewModel: AssistantViewModel + viewModel: AssistantViewModel, + capability: OCCapability ) { Column(modifier = Modifier.fillMaxSize()) { taskTypes?.let { @@ -240,6 +244,7 @@ private fun AssistantContent( items(taskList) { task -> TaskView( task, + capability, showTaskActions = { val newState = ScreenOverlayState.TaskActions(task) viewModel.updateScreenState(newState) @@ -279,6 +284,7 @@ private fun EmptyTaskList( } } +@Suppress("MagicNumber") @Composable @Preview private fun AssistantScreenPreview() { @@ -287,12 +293,16 @@ private fun AssistantScreenPreview() { content = { AssistantScreen( viewModel = AssistantViewModel(repository = mockRepository), - activity = ComposeActivity() + activity = ComposeActivity(), + capability = OCCapability().apply { + versionMayor = 30 + } ) } ) } +@Suppress("MagicNumber") @Composable @Preview private fun AssistantEmptyScreenPreview() { @@ -301,7 +311,10 @@ private fun AssistantEmptyScreenPreview() { content = { AssistantScreen( viewModel = AssistantViewModel(repository = mockRepository), - activity = ComposeActivity() + activity = ComposeActivity(), + capability = OCCapability().apply { + versionMayor = 30 + } ) } ) diff --git a/app/src/main/java/com/nextcloud/client/assistant/extensions/TaskExtensions.kt b/app/src/main/java/com/nextcloud/client/assistant/extensions/TaskExtensions.kt index 3902c71f8a..84efe0c9ef 100644 --- a/app/src/main/java/com/nextcloud/client/assistant/extensions/TaskExtensions.kt +++ b/app/src/main/java/com/nextcloud/client/assistant/extensions/TaskExtensions.kt @@ -14,6 +14,8 @@ import com.nextcloud.utils.date.DateFormatPattern import com.nextcloud.utils.date.DateFormatter import com.owncloud.android.R 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 fun Task.getInputAndOutput(): String { @@ -37,8 +39,38 @@ fun Task.getInputTitle(): String { } } -@Suppress("MagicNumber") -fun Task.getStatusIcon(): Int { +fun Task.getStatusIcon(capability: OCCapability): 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) { "STATUS_UNKNOWN" -> { R.drawable.ic_unknown diff --git a/app/src/main/java/com/nextcloud/client/assistant/task/TaskStatusView.kt b/app/src/main/java/com/nextcloud/client/assistant/task/TaskStatusView.kt index e5640d314e..463672fc69 100644 --- a/app/src/main/java/com/nextcloud/client/assistant/task/TaskStatusView.kt +++ b/app/src/main/java/com/nextcloud/client/assistant/task/TaskStatusView.kt @@ -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.TaskInput import com.owncloud.android.lib.resources.assistant.v2.model.TaskOutput +import com.owncloud.android.lib.resources.status.OCCapability import java.util.concurrent.TimeUnit @Composable -fun TaskStatusView(task: Task, foregroundColor: Color) { +fun TaskStatusView(task: Task, foregroundColor: Color, capability: OCCapability) { val context = LocalContext.current Row( @@ -43,7 +44,7 @@ fun TaskStatusView(task: Task, foregroundColor: Color) { .padding(vertical = 16.dp), verticalAlignment = Alignment.CenterVertically ) { - val iconId = task.getStatusIcon() + val iconId = task.getStatusIcon(capability) val description = task.getModifiedAtRepresentation(context) Image( @@ -124,7 +125,7 @@ private fun TaskStatusViewPreview() { ), Task( - id = 7L, + id = 6L, type = "type7", status = "STATUS_UNKNOWN", userId = "user7", @@ -138,7 +139,13 @@ private fun TaskStatusViewPreview() { LazyColumn { items(tasks) { - TaskStatusView(it, foregroundColor = Color.White) + TaskStatusView( + it, + foregroundColor = Color.White, + OCCapability().apply { + versionMayor = 30 + } + ) } } } diff --git a/app/src/main/java/com/nextcloud/client/assistant/task/TaskView.kt b/app/src/main/java/com/nextcloud/client/assistant/task/TaskView.kt index 1c317bcbf6..93f04af9ae 100644 --- a/app/src/main/java/com/nextcloud/client/assistant/task/TaskView.kt +++ b/app/src/main/java/com/nextcloud/client/assistant/task/TaskView.kt @@ -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.TaskInput import com.owncloud.android.lib.resources.assistant.v2.model.TaskOutput +import com.owncloud.android.lib.resources.status.OCCapability @Suppress("LongMethod", "MagicNumber") @Composable -fun TaskView(task: Task, showTaskActions: () -> Unit) { +fun TaskView(task: Task, capability: OCCapability, showTaskActions: () -> Unit) { var showTaskDetailBottomSheet by remember { mutableStateOf(false) } Box { @@ -98,10 +99,10 @@ fun TaskView(task: Task, showTaskActions: () -> Unit) { ) } - TaskStatusView(task, foregroundColor = Color.White) + TaskStatusView(task, foregroundColor = Color.White, capability) if (showTaskDetailBottomSheet) { - TaskDetailBottomSheet(task, showTaskActions = { + TaskDetailBottomSheet(task, capability, showTaskActions = { showTaskDetailBottomSheet = false showTaskActions() }) { @@ -145,6 +146,9 @@ private fun TaskViewPreview() { 1707692337, 1707692337 ), + OCCapability().apply { + versionMayor = 30 + }, showTaskActions = { } ) diff --git a/app/src/main/java/com/nextcloud/client/assistant/taskDetail/TaskDetailBottomSheet.kt b/app/src/main/java/com/nextcloud/client/assistant/taskDetail/TaskDetailBottomSheet.kt index 028002865c..2357c0bceb 100644 --- a/app/src/main/java/com/nextcloud/client/assistant/taskDetail/TaskDetailBottomSheet.kt +++ b/app/src/main/java/com/nextcloud/client/assistant/taskDetail/TaskDetailBottomSheet.kt @@ -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.TaskInput import com.owncloud.android.lib.resources.assistant.v2.model.TaskOutput +import com.owncloud.android.lib.resources.status.OCCapability @Suppress("LongMethod") @OptIn(ExperimentalFoundationApi::class, ExperimentalMaterial3Api::class) @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) } 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)) } @@ -187,6 +188,9 @@ private fun TaskDetailScreenPreview() { 1707692337, 1707692337 ), + OCCapability().apply { + versionMayor = 30 + }, showTaskActions = { } ) { diff --git a/app/src/main/java/com/nextcloud/ui/composeActivity/ComposeActivity.kt b/app/src/main/java/com/nextcloud/ui/composeActivity/ComposeActivity.kt index 3bbc01b1bd..b70fb8c1bf 100644 --- a/app/src/main/java/com/nextcloud/ui/composeActivity/ComposeActivity.kt +++ b/app/src/main/java/com/nextcloud/ui/composeActivity/ComposeActivity.kt @@ -89,7 +89,8 @@ class ComposeActivity : DrawerActivity() { viewModel = AssistantViewModel( repository = AssistantRepository(client, capabilities) ), - activity = this + activity = this, + capability = capabilities ) } }