Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

feat: connect Kotlin example (#27313)

Jan Tennert0677592b84f0
diff --git a/apps/studio/components/interfaces/Home/Connect/Connect.constants.ts b/apps/studio/components/interfaces/Home/Connect/Connect.constants.ts
index 355050b9a7c..24bb9cec4a9 100644
--- a/apps/studio/components/interfaces/Home/Connect/Connect.constants.ts
+++ b/apps/studio/components/interfaces/Home/Connect/Connect.constants.ts
@@ -206,6 +206,20 @@ export const MOBILES: ConnectionType[] = [
},
],
},
+ {
+ key: 'androidkotlin',
+ label: 'Android Kotlin',
+ icon: 'kotlin',
+ guideLink: 'https://supabase.com/docs/guides/getting-started/tutorials/with-kotlin',
+ children: [
+ {
+ key: 'supabasekt',
+ label: 'supabase-kt',
+ children: [],
+ icon: 'supabase',
+ },
+ ],
+ },
]
export const ORMS: ConnectionType[] = [
diff --git a/apps/studio/components/interfaces/Home/Connect/content/androidkotlin/supabasekt/content.tsx b/apps/studio/components/interfaces/Home/Connect/content/androidkotlin/supabasekt/content.tsx
new file mode 100644
index 00000000000..7e866e184ea
--- /dev/null
+++ b/apps/studio/components/interfaces/Home/Connect/content/androidkotlin/supabasekt/content.tsx
@@ -0,0 +1,83 @@
+import type { ContentFileProps } from 'components/interfaces/Home/Connect/Connect.types'
+
+import {
+ ConnectTabs,
+ ConnectTabTriggers,
+ ConnectTabTrigger,
+ ConnectTabContent,
+} from 'components/interfaces/Home/Connect/ConnectTabs'
+import SimpleCodeBlock from 'components/to-be-cleaned/SimpleCodeBlock'
+
+const ContentFile = ({ projectKeys }: ContentFileProps) => {
+ return (
+ <ConnectTabs>
+ <ConnectTabTriggers>
+ <ConnectTabTrigger value="MainActivity.kt" />
+ <ConnectTabTrigger value="TodoItem.kt" />
+ </ConnectTabTriggers>
+
+ <ConnectTabContent value="TodoItem.kt">
+ <SimpleCodeBlock className="kotlin" parentClassName="min-h-72">
+ {`
+@Serializable
+data class TodoItem(val id: Int, val name: String)
+ `}
+ </SimpleCodeBlock>
+ </ConnectTabContent>
+
+ <ConnectTabContent value="MainActivity.kt">
+ <SimpleCodeBlock className="kotlin" parentClassName="min-h-72">
+ {`
+val supabase = createSupabaseClient(
+ supabaseUrl = "${projectKeys.apiUrl ?? 'your-project-url'}",
+ supabaseKey = "${projectKeys.anonKey ?? 'your-anon-key'}"
+ ) {
+ install(Postgrest)
+}
+
+class MainActivity : ComponentActivity() {
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ setContent {
+ MaterialTheme {
+ // A surface container using the 'background' color from the theme
+ Surface(
+ modifier = Modifier.fillMaxSize(),
+ color = MaterialTheme.colorScheme.background
+ ) {
+ TodoList()
+ }
+ }
+ }
+ }
+}
+
+@Composable
+fun TodoList() {
+ var items by remember { mutableStateOf<List<TodoItem>>(listOf()) }
+ LaunchedEffect(Unit) {
+ withContext(Dispatchers.IO) {
+ items = supabase.from("todos")
+ .select().decodeList<TodoItem>()
+ }
+ }
+ LazyColumn {
+ items(
+ items,
+ key = { item -> item.id },
+ ) { item ->
+ Text(
+ item.name,
+ modifier = Modifier.padding(8.dp),
+ )
+ }
+ }
+}
+`}
+ </SimpleCodeBlock>
+ </ConnectTabContent>
+ </ConnectTabs>
+ )
+}
+
+export default ContentFile