Skip to content

Commit d8a2c51

Browse files
committed
migrated main screen
1 parent 19ca6a5 commit d8a2c51

File tree

9 files changed

+553
-545
lines changed

9 files changed

+553
-545
lines changed

app/src/main/java/com/firebase/uidemo/ChooserActivity.java

Lines changed: 0 additions & 144 deletions
This file was deleted.
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
/*
2+
* Copyright 2016 Google Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
package com.firebase.uidemo
15+
16+
import android.content.Intent
17+
import android.os.Bundle
18+
import androidx.activity.ComponentActivity
19+
import androidx.activity.compose.setContent
20+
import androidx.annotation.StringRes
21+
import androidx.compose.foundation.clickable
22+
import androidx.compose.foundation.layout.*
23+
import androidx.compose.foundation.lazy.LazyColumn
24+
import androidx.compose.foundation.lazy.items
25+
import androidx.compose.material3.*
26+
import androidx.compose.runtime.Composable
27+
import androidx.compose.runtime.remember
28+
import androidx.compose.ui.Modifier
29+
import androidx.compose.ui.platform.LocalContext
30+
import androidx.compose.ui.res.stringResource
31+
import androidx.compose.ui.tooling.preview.Preview
32+
import androidx.compose.ui.unit.dp
33+
import com.firebase.ui.auth.AuthUI
34+
import com.firebase.ui.auth.util.ExtraConstants
35+
import com.firebase.uidemo.auth.AnonymousUpgradeActivity
36+
import com.firebase.uidemo.auth.AuthUiActivity
37+
import com.firebase.uidemo.auth.compose.AuthComposeActivity
38+
import com.firebase.uidemo.auth.compose.ChooserScreen
39+
import com.firebase.uidemo.database.firestore.FirestoreChatActivity
40+
import com.firebase.uidemo.database.firestore.FirestorePagingActivity
41+
import com.firebase.uidemo.database.realtime.FirebaseDbPagingActivity
42+
import com.firebase.uidemo.database.realtime.RealtimeDbChatActivity
43+
import com.firebase.uidemo.storage.ImageActivity
44+
45+
class ChooserActivity : ComponentActivity() {
46+
47+
override fun onCreate(savedInstanceState: Bundle?) {
48+
super.onCreate(savedInstanceState)
49+
50+
// Deep-link handling identical to the original Java implementation
51+
if (AuthUI.canHandleIntent(intent)) {
52+
val authIntent = Intent(this, AuthUiActivity::class.java).apply {
53+
putExtra(ExtraConstants.EMAIL_LINK_SIGN_IN, intent.data.toString())
54+
}
55+
startActivity(authIntent)
56+
finish()
57+
return
58+
}
59+
60+
setContent { ChooserScreen() }
61+
}
62+
63+
64+
@OptIn(ExperimentalMaterial3Api::class)
65+
@Composable
66+
private fun ChooserScreen() {
67+
val items = remember { activityItems }
68+
69+
Scaffold(
70+
topBar = {
71+
CenterAlignedTopAppBar(
72+
title = { Text(stringResource(R.string.app_name)) }
73+
)
74+
}
75+
) { padding ->
76+
LazyColumn(
77+
contentPadding = padding,
78+
modifier = Modifier.fillMaxSize()
79+
) {
80+
items(items) { entry -> ActivityRow(entry) }
81+
}
82+
}
83+
}
84+
85+
@Composable
86+
private fun ActivityRow(entry: ActivityEntry) {
87+
val ctx = LocalContext.current
88+
Card(
89+
Modifier
90+
.fillMaxWidth()
91+
.padding(horizontal = 16.dp, vertical = 8.dp)
92+
.clickable { ctx.startActivity(Intent(ctx, entry.clazz)) }
93+
) {
94+
Column(Modifier.padding(16.dp)) {
95+
Text(
96+
text = stringResource(entry.titleRes),
97+
style = MaterialTheme.typography.titleMedium
98+
)
99+
Spacer(Modifier.height(4.dp))
100+
Text(
101+
text = stringResource(entry.descRes),
102+
style = MaterialTheme.typography.bodyMedium
103+
)
104+
}
105+
}
106+
}
107+
108+
109+
private data class ActivityEntry(
110+
val clazz: Class<*>,
111+
@StringRes val titleRes: Int,
112+
@StringRes val descRes: Int
113+
)
114+
115+
private val activityItems = listOf(
116+
ActivityEntry(AuthUiActivity::class.java,
117+
R.string.title_auth_activity, R.string.desc_auth),
118+
ActivityEntry(AuthComposeActivity::class.java,
119+
R.string.auth_compose_title, R.string.desc_auth),
120+
ActivityEntry(AnonymousUpgradeActivity::class.java,
121+
R.string.title_anonymous_upgrade, R.string.desc_anonymous_upgrade),
122+
ActivityEntry(FirestoreChatActivity::class.java,
123+
R.string.title_firestore_activity, R.string.desc_firestore),
124+
ActivityEntry(FirestorePagingActivity::class.java,
125+
R.string.title_firestore_paging_activity, R.string.desc_firestore_paging),
126+
ActivityEntry(RealtimeDbChatActivity::class.java,
127+
R.string.title_realtime_database_activity, R.string.desc_realtime_database),
128+
ActivityEntry(FirebaseDbPagingActivity::class.java,
129+
R.string.title_realtime_database_paging_activity, R.string.desc_realtime_database_paging),
130+
ActivityEntry(ImageActivity::class.java,
131+
R.string.title_storage_activity, R.string.desc_storage)
132+
)
133+
}
134+
135+
136+
@Preview(showBackground = true, widthDp = 360, heightDp = 640)
137+
@Composable
138+
private fun ChooserScreenPreview() {
139+
MaterialTheme { ChooserActivity().run { ChooserScreen() } }
140+
}

app/src/main/java/com/firebase/uidemo/auth/compose/AuthScreen.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ fun AuthScreen(
2020
) {
2121
val providers = listOf(
2222
IdpConfig.GoogleBuilder().build(),
23-
IdpConfig.EmailBuilder().build()
23+
IdpConfig.EmailBuilder().build(),
2424
)
2525

2626
Box(

app/src/main/res/values/styles.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<resources>
22

33
<!-- Base application theme. -->
4-
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
4+
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar">
55
<item name="colorPrimary">@color/colorPrimary</item>
66
<item name="colorPrimaryDark">@color/colorPrimaryVariant</item>
77
<item name="colorPrimaryVariant">@color/colorPrimaryVariant</item>
@@ -43,4 +43,4 @@
4343
<item name="android:layout_marginRight">16dp</item>
4444
</style>
4545

46-
</resources>
46+
</resources>

auth/build.gradle.kts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ dependencies {
7272
implementation(Config.Libs.Androidx.fragment)
7373
implementation(Config.Libs.Androidx.customTabs)
7474
implementation(Config.Libs.Androidx.constraint)
75+
implementation("androidx.compose.foundation:foundation-android:1.8.1")
76+
implementation("androidx.compose.material3:material3:1.2.1")
77+
implementation("androidx.compose.material3:material3-android:1.3.2")
7578

7679
val composeBom = platform("androidx.compose:compose-bom:2025.02.00")
7780
implementation(composeBom)

0 commit comments

Comments
 (0)