Skip to content
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

Minor Fixups for Codelab #66

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -46,6 +46,7 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.hilt.navigation.compose.hiltViewModel
import com.google.android.samples.socialite.di.AppCoroutineScope
import com.google.android.samples.socialite.model.Contact
import com.google.android.samples.socialite.repository.ChatRepository
import com.google.android.samples.socialite.ui.SocialTheme
Expand All @@ -56,12 +57,17 @@ import com.google.android.samples.socialite.ui.rememberIconPainter
import com.google.android.samples.socialite.widget.model.WidgetModelRepository
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope

@AndroidEntryPoint
class SociaLiteAppWidgetConfigActivity : ComponentActivity() {
@Inject
lateinit var widgetModelRepository: WidgetModelRepository

@Inject
@AppCoroutineScope
lateinit var coroutineScope: CoroutineScope

@Inject
lateinit var chatRepository: ChatRepository

Expand Down Expand Up @@ -95,7 +101,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.
Loading