Skip to content

Commit cd61b05

Browse files
committed
tweak app bar
1 parent 2579731 commit cd61b05

2 files changed

Lines changed: 80 additions & 76 deletions

File tree

Examples/OneSignalDemoV2/app/src/main/java/com/onesignal/sdktest/ui/main/MainScreen.kt

Lines changed: 28 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import androidx.compose.runtime.remember
3030
import androidx.compose.runtime.setValue
3131
import androidx.compose.ui.Modifier
3232
import androidx.compose.ui.Alignment
33-
import androidx.compose.ui.graphics.Brush
3433
import androidx.compose.ui.graphics.Color
3534
import androidx.compose.ui.graphics.ColorFilter
3635
import androidx.compose.ui.platform.LocalContext
@@ -54,7 +53,7 @@ import com.onesignal.sdktest.ui.components.TooltipDialog
5453
import com.onesignal.sdktest.ui.components.TrackEventDialog
5554
import com.onesignal.sdktest.ui.secondary.SecondaryActivity
5655
import com.onesignal.sdktest.ui.theme.OneSignalRed
57-
import com.onesignal.sdktest.ui.theme.OneSignalRedDark
56+
5857
import com.onesignal.sdktest.util.TooltipHelper
5958

6059
@OptIn(ExperimentalMaterial3Api::class)
@@ -104,38 +103,28 @@ fun MainScreen(viewModel: MainViewModel) {
104103
Box(modifier = Modifier.fillMaxSize()) {
105104
Scaffold(
106105
topBar = {
107-
Box(
108-
modifier = Modifier
109-
.fillMaxWidth()
110-
.background(
111-
Brush.horizontalGradient(
112-
colors = listOf(OneSignalRed, OneSignalRedDark)
106+
TopAppBar(
107+
title = {
108+
Row(verticalAlignment = Alignment.CenterVertically) {
109+
Image(
110+
painter = painterResource(id = R.drawable.onesignal_rectangle),
111+
contentDescription = "OneSignal Logo",
112+
modifier = Modifier.height(24.dp),
113+
colorFilter = ColorFilter.tint(Color.White)
113114
)
114-
)
115-
) {
116-
TopAppBar(
117-
title = {
118-
Row(verticalAlignment = Alignment.CenterVertically) {
119-
Image(
120-
painter = painterResource(id = R.drawable.onesignal_rectangle),
121-
contentDescription = "OneSignal Logo",
122-
modifier = Modifier.height(24.dp),
123-
colorFilter = ColorFilter.tint(Color.White)
124-
)
125-
Spacer(modifier = Modifier.width(10.dp))
126-
Text(
127-
"SDK Test",
128-
color = Color.White.copy(alpha = 0.7f),
129-
fontSize = 14.sp,
130-
fontWeight = FontWeight.Normal
131-
)
132-
}
133-
},
134-
colors = TopAppBarDefaults.topAppBarColors(
135-
containerColor = Color.Transparent
136-
)
115+
Spacer(modifier = Modifier.width(10.dp))
116+
Text(
117+
"Sample App",
118+
color = Color.White.copy(alpha = 0.7f),
119+
fontSize = 14.sp,
120+
fontWeight = FontWeight.Normal
121+
)
122+
}
123+
},
124+
colors = TopAppBarDefaults.topAppBarColors(
125+
containerColor = OneSignalRed
137126
)
138-
}
127+
)
139128
}
140129
) { paddingValues ->
141130
Column(
@@ -162,14 +151,18 @@ fun MainScreen(viewModel: MainViewModel) {
162151
onConsentRequiredChange = { viewModel.setConsentRequired(it) },
163152
privacyConsentGiven = privacyConsentGiven,
164153
onConsentChange = { viewModel.setPrivacyConsent(it) },
165-
externalUserId = externalUserId,
166-
onLoginClick = { showLoginDialog = true },
167-
onLogoutClick = { viewModel.logoutUser() },
168154
onGetKeysClick = {
169155
context.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("https://onesignal.com")))
170156
}
171157
)
172158

159+
// === USER SECTION ===
160+
UserSection(
161+
externalUserId = externalUserId,
162+
onLoginClick = { showLoginDialog = true },
163+
onLogoutClick = { viewModel.logoutUser() }
164+
)
165+
173166
// === PUSH SECTION ===
174167
PushSection(
175168
pushSubscriptionId = pushSubscriptionId,

Examples/OneSignalDemoV2/app/src/main/java/com/onesignal/sdktest/ui/main/Sections.kt

Lines changed: 52 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,8 @@ fun AppSection(
5252
onConsentRequiredChange: (Boolean) -> Unit,
5353
privacyConsentGiven: Boolean,
5454
onConsentChange: (Boolean) -> Unit,
55-
externalUserId: String?,
56-
onLoginClick: () -> Unit,
57-
onLogoutClick: () -> Unit,
5855
onGetKeysClick: () -> Unit
5956
) {
60-
val isLoggedIn = !externalUserId.isNullOrEmpty()
61-
6257
SectionCard(title = "App") {
6358
// App ID
6459
Row(
@@ -136,53 +131,69 @@ fun AppSection(
136131
)
137132
}
138133
}
139-
140-
// Logged In As (shown above buttons when logged in)
141-
if (isLoggedIn) {
142-
Spacer(modifier = Modifier.height(8.dp))
143-
Card(
134+
}
135+
136+
// === USER SECTION ===
137+
@Composable
138+
fun UserSection(
139+
externalUserId: String?,
140+
onLoginClick: () -> Unit,
141+
onLogoutClick: () -> Unit
142+
) {
143+
val isLoggedIn = !externalUserId.isNullOrEmpty()
144+
145+
SectionCard(title = "User") {
146+
// Status
147+
Row(
144148
modifier = Modifier
145149
.fillMaxWidth()
146-
.padding(horizontal = 16.dp),
147-
colors = CardDefaults.cardColors(containerColor = OneSignalGreenLight),
148-
shape = MaterialTheme.shapes.medium,
149-
border = BorderStroke(1.dp, OneSignalGreen.copy(alpha = 0.2f)),
150-
elevation = CardDefaults.cardElevation(defaultElevation = 0.dp)
150+
.padding(horizontal = 16.dp, vertical = 14.dp),
151+
horizontalArrangement = Arrangement.SpaceBetween,
152+
verticalAlignment = Alignment.CenterVertically
151153
) {
152-
Column(
153-
modifier = Modifier
154-
.fillMaxWidth()
155-
.padding(16.dp),
156-
horizontalAlignment = Alignment.CenterHorizontally
157-
) {
158-
Text(
159-
"Logged in as",
160-
style = MaterialTheme.typography.bodySmall,
161-
color = MaterialTheme.colorScheme.onSurfaceVariant
162-
)
163-
Spacer(modifier = Modifier.height(2.dp))
164-
Text(
165-
externalUserId ?: "",
166-
style = MaterialTheme.typography.titleMedium.copy(
167-
fontWeight = FontWeight.Bold,
168-
fontSize = 18.sp
169-
),
170-
color = OneSignalGreen,
171-
textAlign = TextAlign.Center,
172-
maxLines = 1,
173-
overflow = TextOverflow.Ellipsis
154+
Text(
155+
"Status",
156+
style = MaterialTheme.typography.bodyMedium,
157+
color = MaterialTheme.colorScheme.onSurfaceVariant
158+
)
159+
Text(
160+
text = if (isLoggedIn) "Logged In" else "Anonymous",
161+
style = MaterialTheme.typography.bodyMedium.copy(
162+
fontWeight = FontWeight.Medium,
163+
color = if (isLoggedIn) OneSignalGreen else MaterialTheme.colorScheme.onSurfaceVariant
174164
)
175-
}
165+
)
166+
}
167+
HorizontalDivider(modifier = Modifier.padding(horizontal = 16.dp))
168+
// External ID
169+
Row(
170+
modifier = Modifier
171+
.fillMaxWidth()
172+
.padding(horizontal = 16.dp, vertical = 14.dp),
173+
horizontalArrangement = Arrangement.SpaceBetween,
174+
verticalAlignment = Alignment.CenterVertically
175+
) {
176+
Text(
177+
"External ID",
178+
style = MaterialTheme.typography.bodyMedium,
179+
color = MaterialTheme.colorScheme.onSurfaceVariant
180+
)
181+
Text(
182+
text = externalUserId ?: "",
183+
style = MaterialTheme.typography.bodyMedium.copy(fontWeight = FontWeight.Medium),
184+
maxLines = 1,
185+
overflow = TextOverflow.Ellipsis
186+
)
176187
}
177188
}
178-
189+
179190
Spacer(modifier = Modifier.height(8.dp))
180-
191+
181192
PrimaryButton(
182193
text = if (isLoggedIn) "SWITCH USER" else "LOGIN USER",
183194
onClick = onLoginClick
184195
)
185-
196+
186197
if (isLoggedIn) {
187198
OutlineButton(
188199
text = "LOGOUT USER",

0 commit comments

Comments
 (0)