Skip to content

Commit

Permalink
Minor Fixups for Codelab
Browse files Browse the repository at this point in the history
Change-Id: I42a5d795e85308351cc86089ef5f4c77ab8b8091
  • Loading branch information
secondsun committed Apr 30, 2024
1 parent 169d2eb commit 71b166f
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 16 deletions.
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
<!-- This activity handles configuration for the SociaLiteAppWidget -->
<activity android:name=".widget.SociaLiteAppWidgetConfigActivity"
android:taskAffinity=""
android:theme="@style/Theme.Social"
android:exported="true">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import android.content.Intent
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.core.content.pm.ShortcutManagerCompat
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import com.google.android.samples.socialite.ui.Main
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class SociaLiteAppWidgetConfigActivity : ComponentActivity() {

ContactRow(
contact = contact,
onClick = TODO("Replace with code from codelab"),
onClick = { TODO("Replace with code from codelab") },
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@
package com.google.android.samples.socialite.widget.ui

import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.core.net.toUri
import androidx.glance.GlanceModifier
import androidx.glance.GlanceTheme
import androidx.glance.Image
import androidx.glance.ImageProvider
import androidx.glance.action.Action
import androidx.glance.action.clickable
import androidx.glance.appwidget.ImageProvider
import androidx.glance.appwidget.appWidgetBackground
import androidx.glance.appwidget.cornerRadius
import androidx.glance.background
import androidx.glance.layout.Alignment
import androidx.glance.layout.Box
import androidx.glance.layout.Column
import androidx.glance.layout.ContentScale
import androidx.glance.layout.fillMaxSize
Expand All @@ -39,33 +39,35 @@ import androidx.glance.layout.wrapContentHeight
import androidx.glance.text.FontWeight
import androidx.glance.text.Text
import androidx.glance.text.TextStyle
import androidx.glance.unit.ColorProvider
import com.google.android.samples.socialite.widget.model.WidgetModel

@Composable
fun FavoriteContact(model: WidgetModel, onClick: Action) {
Box(
modifier = GlanceModifier.fillMaxSize().clickable(onClick)
.cornerRadius(8.dp).padding(bottom = 8.dp),
contentAlignment = Alignment.TopCenter,
fun FavoriteContact(modifier: GlanceModifier = GlanceModifier, model: WidgetModel, onClick: Action) {
Column(
modifier = modifier.fillMaxSize().clickable(onClick)
.background(GlanceTheme.colors.widgetBackground).appWidgetBackground()
.padding(bottom = 8.dp),
verticalAlignment = Alignment.Vertical.Bottom,
horizontalAlignment = Alignment.Horizontal.CenterHorizontally,
) {
Image(
modifier = GlanceModifier.fillMaxSize().cornerRadius(8.dp),
modifier = GlanceModifier.fillMaxWidth().wrapContentHeight().defaultWeight()
.cornerRadius(16.dp),
provider = ImageProvider(model.photo.toUri()),
contentScale = ContentScale.Crop,
contentDescription = model.displayName,
)
Column(
modifier = GlanceModifier.fillMaxWidth().wrapContentHeight(),
verticalAlignment = Alignment.Vertical.Top,
modifier = GlanceModifier.fillMaxWidth().wrapContentHeight().padding(top = 4.dp),
verticalAlignment = Alignment.Vertical.Bottom,
horizontalAlignment = Alignment.Horizontal.CenterHorizontally,
) {
Text(
text = model.displayName,
style = TextStyle(
fontWeight = FontWeight.Bold,
fontSize = 24.sp,
color = ColorProvider(Color.White),
color = (GlanceTheme.colors.onSurface),
),
)

Expand All @@ -74,7 +76,7 @@ fun FavoriteContact(model: WidgetModel, onClick: Action) {
style = TextStyle(
fontWeight = FontWeight.Bold,
fontSize = 16.sp,
color = ColorProvider(Color.White),
color = (GlanceTheme.colors.onSurface),
),
)
}
Expand Down
Binary file modified app/src/main/res/drawable/widget_preview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 71b166f

Please sign in to comment.