mirror of
https://github.com/nextcloud/android.git
synced 2024-12-18 06:51:55 +03:00
add getStatusIconV1
Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
parent
ace68da2a7
commit
98cd991502
7 changed files with 113 additions and 20 deletions
|
@ -4,6 +4,34 @@
|
|||
<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" />
|
||||
</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="PreviewAnnotationInFunctionWithParameters" enabled="true" level="ERROR" enabled_by_default="true">
|
||||
<option name="composableFile" value="true" />
|
||||
|
@ -13,6 +41,10 @@
|
|||
<option name="composableFile" value="true" />
|
||||
<option name="previewFile" value="true" />
|
||||
</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">
|
||||
<option name="composableFile" value="true" />
|
||||
<option name="previewFile" value="true" />
|
||||
|
@ -43,4 +75,4 @@
|
|||
</inspection_tool>
|
||||
<inspection_tool class="RedundantSemicolon" enabled="true" level="ERROR" enabled_by_default="true" />
|
||||
</profile>
|
||||
</component>
|
||||
</component>
|
|
@ -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<TaskTypeData>?,
|
||||
viewModel: AssistantViewModel,
|
||||
filteredTaskList: List<Task>?
|
||||
filteredTaskList: List<Task>?,
|
||||
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<Task>,
|
||||
taskTypes: List<TaskTypeData>?,
|
||||
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
|
||||
}
|
||||
)
|
||||
}
|
||||
)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 = {
|
||||
}
|
||||
)
|
||||
|
|
|
@ -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 = {
|
||||
}
|
||||
) {
|
||||
|
|
|
@ -89,7 +89,8 @@ class ComposeActivity : DrawerActivity() {
|
|||
viewModel = AssistantViewModel(
|
||||
repository = AssistantRepository(client, capabilities)
|
||||
),
|
||||
activity = this
|
||||
activity = this,
|
||||
capability = capabilities
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue