-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Declarative UI #16111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Declarative UI #16111
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
1,298 changes: 1,298 additions & 0 deletions
1,298
app/schemas/com.nextcloud.client.database.NextcloudDatabase/97.json
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
170 changes: 170 additions & 0 deletions
170
app/src/main/java/com/nextcloud/ui/ClientIntegrationScreen.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,170 @@ | ||
| /* | ||
| * Nextcloud - Android Client | ||
| * | ||
| * SPDX-FileCopyrightText: 2025 Alper Ozturk <alper.ozturk@nextcloud.com> | ||
| * SPDX-FileCopyrightText: 2025 Tobias Kaminsky <tobias.kaminsky@nextcloud.com> | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| package com.nextcloud.ui | ||
|
|
||
| import android.app.Activity | ||
| import androidx.compose.foundation.layout.Arrangement | ||
| import androidx.compose.foundation.layout.Row | ||
| import androidx.compose.foundation.layout.fillMaxSize | ||
| import androidx.compose.foundation.layout.fillMaxWidth | ||
| import androidx.compose.foundation.layout.padding | ||
| import androidx.compose.foundation.lazy.LazyColumn | ||
| import androidx.compose.foundation.lazy.LazyRow | ||
| import androidx.compose.foundation.lazy.items | ||
| import androidx.compose.material.icons.Icons | ||
| import androidx.compose.material.icons.filled.Close | ||
| import androidx.compose.material3.Button | ||
| import androidx.compose.material3.Icon | ||
| import androidx.compose.material3.IconButton | ||
| import androidx.compose.material3.Scaffold | ||
| import androidx.compose.material3.Text | ||
| import androidx.compose.material3.TextButton | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.ui.Modifier | ||
| import androidx.compose.ui.platform.LocalContext | ||
| import androidx.compose.ui.tooling.preview.Preview | ||
| import com.nextcloud.android.lib.resources.clientintegration.ClientIntegrationUI | ||
| import com.nextcloud.android.lib.resources.clientintegration.Element | ||
| import com.nextcloud.android.lib.resources.clientintegration.Layout | ||
| import com.nextcloud.android.lib.resources.clientintegration.LayoutButton | ||
| import com.nextcloud.android.lib.resources.clientintegration.LayoutOrientation | ||
| import com.nextcloud.android.lib.resources.clientintegration.LayoutRow | ||
| import com.nextcloud.android.lib.resources.clientintegration.LayoutText | ||
| import com.nextcloud.android.lib.resources.clientintegration.LayoutURL | ||
| import com.nextcloud.utils.extensions.getActivity | ||
| import com.owncloud.android.lib.resources.status.OCCapability | ||
| import com.owncloud.android.utils.DisplayUtils | ||
|
|
||
| @Composable | ||
| fun ClientIntegrationScreen(clientIntegrationUI: ClientIntegrationUI, baseUrl: String) { | ||
| val activity = LocalContext.current.getActivity() | ||
| val layoutRows = clientIntegrationUI.root?.rows ?: listOf() | ||
|
|
||
| Scaffold(topBar = { | ||
| Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.End) { | ||
| IconButton(onClick = { activity?.finish() }) { | ||
| Icon( | ||
| imageVector = Icons.Filled.Close, | ||
| contentDescription = "Close" | ||
| ) | ||
| } | ||
| } | ||
| }, modifier = Modifier.fillMaxSize()) { | ||
| when (clientIntegrationUI.root?.orientation) { | ||
| LayoutOrientation.VERTICAL -> { | ||
| LazyColumn(modifier = Modifier.padding(it)) { | ||
| items(layoutRows) { row -> | ||
| LazyRow { | ||
| items(row.children) { element -> | ||
| DisplayElement(element, baseUrl, activity) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| else -> { | ||
| LazyRow(modifier = Modifier.padding(it)) { | ||
| items(layoutRows) { row -> | ||
| LazyColumn { | ||
| items(row.children) { element -> | ||
| DisplayElement(element, baseUrl, activity) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Composable | ||
| private fun DisplayElement(element: Element, baseUrl: String, activity: Activity?) { | ||
| when (element) { | ||
| is LayoutButton -> Button(onClick = { }) { | ||
| Text(element.label) | ||
| } | ||
|
|
||
| is LayoutURL -> TextButton({ | ||
| openLink(activity, baseUrl, element.url) | ||
| }) { Text(element.text) } | ||
|
|
||
| is LayoutText -> Text(element.text) | ||
| } | ||
| } | ||
|
|
||
| private fun openLink(activity: Activity?, baseUrl: String, relativeUrl: String) { | ||
| activity?.let { | ||
| DisplayUtils.startLinkIntent(activity, baseUrl + relativeUrl) | ||
| } | ||
| } | ||
|
|
||
| @Composable | ||
| @Preview | ||
| private fun ClientIntegrationScreenPreviewVertical() { | ||
| val clientIntegrationUI = ClientIntegrationUI( | ||
| OCCapability.CLIENT_INTEGRATION_VERSION, | ||
| Layout( | ||
| LayoutOrientation.VERTICAL, | ||
| mutableListOf( | ||
| LayoutRow( | ||
| listOf(LayoutButton("Click", "Primary"), LayoutText("123")) | ||
| ), | ||
| LayoutRow( | ||
| listOf(LayoutButton("Click2", "Primary")) | ||
| ), | ||
| LayoutRow( | ||
| listOf(LayoutURL("Analytics report created", "https://nextcloud.com")) | ||
| ) | ||
| ) | ||
| ) | ||
| ) | ||
|
|
||
| ClientIntegrationScreen( | ||
| clientIntegrationUI, | ||
| "http://nextcloud.local" | ||
| ) | ||
| } | ||
|
|
||
| @Composable | ||
| @Preview | ||
| private fun ClientIntegrationScreenPreviewHorizontal() { | ||
| val clientIntegrationUI = ClientIntegrationUI( | ||
| OCCapability.CLIENT_INTEGRATION_VERSION, | ||
| Layout( | ||
| LayoutOrientation.HORIZONTAL, | ||
| mutableListOf( | ||
| LayoutRow( | ||
| listOf(LayoutButton("Click", "Primary"), LayoutText("123")) | ||
| ), | ||
| LayoutRow( | ||
| listOf(LayoutButton("Click2", "Primary")) | ||
| ), | ||
| LayoutRow( | ||
| listOf(LayoutURL("Analytics report created", "https://nextcloud.com")) | ||
| ) | ||
| ) | ||
| ) | ||
| ) | ||
|
|
||
| ClientIntegrationScreen(clientIntegrationUI, "http://nextcloud.local") | ||
| } | ||
|
|
||
| @Composable | ||
| @Preview | ||
| private fun ClientIntegrationScreenPreviewEmpty() { | ||
| val clientIntegrationUI = ClientIntegrationUI( | ||
| OCCapability.CLIENT_INTEGRATION_VERSION, | ||
| Layout( | ||
| LayoutOrientation.HORIZONTAL, | ||
| emptyList() | ||
| ) | ||
| ) | ||
|
|
||
| ClientIntegrationScreen(clientIntegrationUI, "http://nextcloud.local") | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.