-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(androidApp): create widget to see user profile.
- Loading branch information
1 parent
46dad40
commit 74ac77a
Showing
17 changed files
with
270 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 5 additions & 3 deletions
8
androidApp/src/main/java/org/gdglille/devfest/android/ScheduleWorkManager.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
androidApp/src/main/java/org/gdglille/devfest/android/widgets/NetworkingAppWidget.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package org.gdglille.devfest.android.widgets | ||
|
||
import android.content.Context | ||
import android.content.Intent | ||
import androidx.core.net.toUri | ||
import androidx.glance.GlanceId | ||
import androidx.glance.GlanceTheme | ||
import androidx.glance.appwidget.GlanceAppWidget | ||
import androidx.glance.appwidget.action.actionStartActivity | ||
import androidx.glance.appwidget.provideContent | ||
import org.gdglille.devfest.android.R | ||
import org.gdglille.devfest.android.theme.m3.navigation.Screen | ||
import org.gdglille.devfest.android.widgets.feature.NetworkingWidget | ||
import org.gdglille.devfest.repositories.UserRepository | ||
import org.koin.core.component.KoinComponent | ||
import org.koin.core.component.inject | ||
|
||
class NetworkingAppWidget : GlanceAppWidget(), KoinComponent { | ||
private val userRepository: UserRepository by inject() | ||
|
||
override suspend fun provideGlance(context: Context, id: GlanceId) { | ||
provideContent { | ||
GlanceTheme { | ||
NetworkingWidget( | ||
userRepository = userRepository, | ||
iconId = R.drawable.ic_launcher_foreground, | ||
onNewProfile = actionStartActivity( | ||
intent = Intent( | ||
Intent.ACTION_VIEW, | ||
"c4h://event/${Screen.NewProfile.route}".toUri() | ||
) | ||
), | ||
onMyProfile = actionStartActivity( | ||
intent = Intent( | ||
Intent.ACTION_VIEW, | ||
"c4h://event/${Screen.MyProfile.route}".toUri() | ||
) | ||
) | ||
) | ||
} | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
androidApp/src/main/java/org/gdglille/devfest/android/widgets/NetworkingWidgetReceiver.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package org.gdglille.devfest.android.widgets | ||
|
||
import androidx.glance.appwidget.GlanceAppWidget | ||
import androidx.glance.appwidget.GlanceAppWidgetReceiver | ||
|
||
class NetworkingWidgetReceiver : GlanceAppWidgetReceiver() { | ||
override val glanceAppWidget: GlanceAppWidget | ||
get() = NetworkingAppWidget() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:initialLayout="@layout/glance_default_loading_layout" | ||
android:minWidth="150dp" | ||
android:minHeight="100dp" | ||
android:targetCellWidth="3" | ||
android:targetCellHeight="2" | ||
android:minResizeWidth="150dp" | ||
android:minResizeHeight="100dp" | ||
android:resizeMode="horizontal|vertical" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
...ature/src/main/kotlin/org/gdglille/devfest/android/widgets/feature/NetworkingViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package org.gdglille.devfest.android.widgets.feature | ||
|
||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Job | ||
import kotlinx.coroutines.flow.SharingStarted | ||
import kotlinx.coroutines.flow.StateFlow | ||
import kotlinx.coroutines.flow.catch | ||
import kotlinx.coroutines.flow.map | ||
import kotlinx.coroutines.flow.stateIn | ||
import org.gdglille.devfest.models.ui.UserProfileUi | ||
import org.gdglille.devfest.repositories.UserRepository | ||
|
||
sealed class NetworkingUiState { | ||
data object Loading : NetworkingUiState() | ||
data class Success(val user: UserProfileUi?) : NetworkingUiState() | ||
} | ||
|
||
class NetworkingViewModel( | ||
userRepository: UserRepository, | ||
coroutineScope: CoroutineScope = CoroutineScope(Job()) | ||
) { | ||
val uiState: StateFlow<NetworkingUiState> = userRepository.fetchProfile() | ||
.map { NetworkingUiState.Success(it) } | ||
.catch { emit(NetworkingUiState.Success(null)) } | ||
.stateIn( | ||
scope = coroutineScope, | ||
started = SharingStarted.WhileSubscribed(5000), | ||
initialValue = NetworkingUiState.Loading | ||
) | ||
} |
34 changes: 34 additions & 0 deletions
34
...-feature/src/main/kotlin/org/gdglille/devfest/android/widgets/feature/NetworkingWidget.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package org.gdglille.devfest.android.widgets.feature | ||
|
||
import androidx.annotation.DrawableRes | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.collectAsState | ||
import androidx.compose.runtime.remember | ||
import androidx.glance.GlanceModifier | ||
import androidx.glance.action.Action | ||
import org.gdglille.devfest.android.widgets.screens.NetworkingScreen | ||
import org.gdglille.devfest.android.widgets.ui.Loading | ||
import org.gdglille.devfest.repositories.UserRepository | ||
|
||
@Composable | ||
fun NetworkingWidget( | ||
userRepository: UserRepository, | ||
@DrawableRes iconId: Int, | ||
onNewProfile: Action, | ||
onMyProfile: Action, | ||
modifier: GlanceModifier = GlanceModifier | ||
) { | ||
val viewModel = remember { NetworkingViewModel(userRepository) } | ||
when (val uiState = viewModel.uiState.collectAsState().value) { | ||
is NetworkingUiState.Loading -> Loading() | ||
is NetworkingUiState.Success -> { | ||
NetworkingScreen( | ||
userInfo = uiState.user, | ||
iconId = iconId, | ||
onNewProfile = onNewProfile, | ||
onMyProfile = onMyProfile, | ||
modifier = modifier | ||
) | ||
} | ||
} | ||
} |
Oops, something went wrong.