Skip to content

Commit

Permalink
Merge pull request #1224 from joreilly/compose_desktop_updates
Browse files Browse the repository at this point in the history
compose/coil multiplatform refactoring
  • Loading branch information
joreilly authored Mar 30, 2024
2 parents d67084a + 49305ec commit ac84f59
Show file tree
Hide file tree
Showing 30 changed files with 512 additions and 522 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import android.app.Application
import androidx.lifecycle.ProcessLifecycleOwner
import androidx.lifecycle.lifecycleScope
import androidx.work.WorkManager
import coil.ImageLoader
import coil.ImageLoaderFactory
import com.google.firebase.FirebaseApp
import com.google.firebase.crashlytics.ktx.crashlytics
import com.google.firebase.crashlytics.setCustomKeys
Expand All @@ -22,7 +20,7 @@ import org.koin.android.ext.koin.androidContext
import org.koin.android.ext.koin.androidLogger
import org.koin.androidx.workmanager.koin.workManagerFactory

class ConfettiApplication : Application(), ImageLoaderFactory {
class ConfettiApplication : Application() {

private val isFirebaseInstalled
get() = try {
Expand All @@ -32,8 +30,6 @@ class ConfettiApplication : Application(), ImageLoaderFactory {
false
}

override fun newImageLoader(): ImageLoader = get()

override fun onCreate() {
super.onCreate()

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,8 @@ import org.koin.compose.koinInject
import java.time.format.DateTimeFormatter

@Composable
fun SessionDetailsRoute(
component: SessionDetailsComponent,
) {
fun SessionDetailsRoute(component: SessionDetailsComponent) {

val user by koinInject<Authentication>().currentUser.collectAsStateWithLifecycle()
val uiState by component.uiState.subscribeAsState()
val isBookmarked by component.isBookmarked.collectAsStateWithLifecycle()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import com.arkivanov.decompose.extensions.compose.jetpack.subscribeAsState
import dev.johnoreilly.confetti.decompose.SessionsComponent
import dev.johnoreilly.confetti.decompose.SessionsUiState
import dev.johnoreilly.confetti.ui.HomeScaffold
import dev.johnoreilly.confetti.ui.SessionListGridView
import dev.johnoreilly.confetti.ui.isExpanded
import kotlinx.coroutines.flow.receiveAsFlow

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import com.arkivanov.decompose.extensions.compose.jetpack.stack.animation.fade
import com.arkivanov.decompose.extensions.compose.jetpack.stack.animation.stackAnimation
import dev.johnoreilly.confetti.decompose.AppComponent
import dev.johnoreilly.confetti.decompose.AppComponent.Child
import dev.johnoreilly.confetti.conferences.ConferencesRoute

@Composable
fun ConfettiApp(
Expand All @@ -20,7 +19,7 @@ fun ConfettiApp(
) {
when (val child = it.instance) {
is Child.Loading -> LoadingView()
is Child.Conferences -> ConferencesRoute(child.component)
is Child.Conferences -> ConferenceListView(child.component)
is Child.Conference -> ConferenceRoute(child.component, windowSizeClass)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import androidx.compose.material.icons.outlined.Person
import androidx.compose.material.icons.outlined.Place
import androidx.compose.material.icons.outlined.Search
import androidx.compose.material3.Divider
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
Expand Down Expand Up @@ -183,7 +184,7 @@ private fun Children(
@Composable
private fun BottomBar(component: HomeComponent) {
Column {
Divider()
HorizontalDivider()
NavigationBar(
contentColor = MaterialTheme.colorScheme.onSurfaceVariant,
tonalElevation = 0.dp,
Expand Down
3 changes: 3 additions & 0 deletions compose-desktop/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ dependencies {
implementation(compose.material3)
implementation(compose.components.resources)

implementation("com.arkivanov.decompose:decompose:2.2.2-compose-experimental")
implementation("com.arkivanov.decompose:extensions-compose-jetbrains:2.2.2-compose-experimental")

implementation("com.mikepenz:multiplatform-markdown-renderer-m3:0.13.0")
implementation("com.mikepenz:multiplatform-markdown-renderer-jvm:0.13.0")
implementation(project(":shared"))
Expand Down
77 changes: 0 additions & 77 deletions compose-desktop/src/main/kotlin/ConferenceView.kt

This file was deleted.

41 changes: 20 additions & 21 deletions compose-desktop/src/main/kotlin/GeminiQueryView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import androidx.compose.material3.ShapeDefaults
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
Expand All @@ -28,43 +29,41 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.unit.dp
import com.apollographql.apollo3.cache.normalized.FetchPolicy
import com.mikepenz.markdown.m3.Markdown
import dev.johnoreilly.confetti.ConfettiRepository
import dev.johnoreilly.confetti.GeminiApi
import dev.johnoreilly.confetti.GetConferencesQuery
import dev.johnoreilly.confetti.fragment.SessionDetails
import dev.johnoreilly.confetti.decompose.RecommendationsComponent
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.onStart
import kotlinx.coroutines.launch

@Composable
fun GeminiQueryView(conference: GetConferencesQuery.Conference) {
val geminiApi = remember { GeminiApi() }
var query by remember { mutableStateOf("") }
var queryResponse by remember { mutableStateOf("") }

val keyboardController = LocalSoftwareKeyboardController.current
var showProgress by remember { mutableStateOf(false) }

val repository = koin.get<ConfettiRepository>()
val sessionList = remember { mutableStateOf<List<SessionDetails>?>(emptyList()) }
fun GeminiQueryView(component: RecommendationsComponent) {
val sessionList by component.sessions.collectAsState(emptyList())
var conferenceInfo by remember { mutableStateOf("") }
val coroutineScope = rememberCoroutineScope()

LaunchedEffect(conference) {
val conferenceData = repository.conferenceData(conference.id, FetchPolicy.CacheFirst)
sessionList.value = conferenceData.data?.sessions?.nodes?.map { it.sessionDetails }

LaunchedEffect(component) {
conferenceInfo = "Speakers, Session ID, Title, Start Time, Description,\n"
sessionList.value?.forEach { session ->
sessionList.forEach { session ->
session.sessionDescription?.let {
val speakers = session.speakers.joinToString(" ") { it.speakerDetails.name }
conferenceInfo += "${speakers}, ${session.id}, ${session.title}, ${session.startsAt}, ${session.sessionDescription}, \n"
}
}
}

RecommendationsView(conferenceInfo)
}


@Composable
fun RecommendationsView(conferenceInfo: String) {
val geminiApi = remember { GeminiApi() }
var query by remember { mutableStateOf("") }
var queryResponse by remember { mutableStateOf("") }

val keyboardController = LocalSoftwareKeyboardController.current
var showProgress by remember { mutableStateOf(false) }
val coroutineScope = rememberCoroutineScope()

Column(Modifier.padding(16.dp).verticalScroll(rememberScrollState())) {
OutlinedTextField(
Expand Down Expand Up @@ -115,4 +114,4 @@ fun GeminiQueryView(conference: GetConferencesQuery.Conference) {
Markdown(queryResponse)
}
}
}
}
Loading

0 comments on commit ac84f59

Please sign in to comment.