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

Updated Chapter 12 - Networking #69

Open
wants to merge 6 commits into
base: editions/3.0
Choose a base branch
from
Open
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 2 additions & 1 deletion 12-networking/projects/challenge/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ bin/
gen/
out/

# Gradle files
# Project files
.gradle/
.kotlin/
build/
androidApp/build
desktopApp/build
Expand Down
12 changes: 5 additions & 7 deletions 12-networking/projects/challenge/androidApp/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Kodeco Inc
* Copyright (c) 2025 Kodeco Inc
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -35,6 +35,8 @@
plugins {
id("com.android.application")
kotlin("android")

alias(libs.plugins.jetbrains.compose.compiler)
}

dependencies {
Expand Down Expand Up @@ -63,8 +65,8 @@ android {
applicationId = "com.kodeco.learn"
minSdk = libs.versions.android.sdk.min.get().toInt()
targetSdk = libs.versions.android.sdk.target.get().toInt()
versionCode = 2
versionName = "2.0"
versionCode = 3
versionName = "3.0"
}

buildTypes {
Expand All @@ -86,10 +88,6 @@ android {
jvmTarget = "17"
}

composeOptions {
kotlinCompilerExtensionVersion = libs.versions.android.compose.compiler.get()
}

packaging {
resources {
excludes += "/META-INF/{AL2.0,LGPL2.1}"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Kodeco Inc
* Copyright (c) 2025 Kodeco Inc
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Kodeco Inc
* Copyright (c) 2025 Kodeco Inc
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Kodeco Inc
* Copyright (c) 2025 Kodeco Inc
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Kodeco Inc
* Copyright (c) 2025 Kodeco Inc
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -37,8 +37,8 @@ package com.kodeco.learn.ui.bookmark
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.material.BottomSheetScaffoldState
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material3.BottomSheetScaffoldState
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.State
Expand All @@ -53,7 +53,7 @@ import kotlinx.coroutines.CoroutineScope

private const val TAG = "BookmarkContent"

@OptIn(ExperimentalMaterialApi::class)
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun BookmarkContent(
selected: MutableState<KodecoEntry>,
Expand All @@ -80,7 +80,7 @@ fun BookmarkContent(
}
}

@OptIn(ExperimentalMaterialApi::class)
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun AddBookmarks(
selected: MutableState<KodecoEntry>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Kodeco Inc
* Copyright (c) 2025 Kodeco Inc
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Kodeco Inc
* Copyright (c) 2025 Kodeco Inc
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Kodeco Inc
* Copyright (c) 2025 Kodeco Inc
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -45,9 +45,9 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.BottomSheetScaffoldState
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material3.Divider
import androidx.compose.material3.BottomSheetScaffoldState
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Icon
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
Expand All @@ -69,7 +69,7 @@ import kotlinx.coroutines.launch

private const val TAG = "EntryContent"

@OptIn(ExperimentalMaterialApi::class)
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun AddEntryContent(
item: KodecoEntry,
Expand Down Expand Up @@ -169,7 +169,7 @@ fun AddEntryContent(
Spacer(modifier = Modifier.height(16.dp))

if (divider) {
Divider(
HorizontalDivider(
modifier = Modifier.fillMaxWidth(),
thickness = 1.dp
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Kodeco Inc
* Copyright (c) 2025 Kodeco Inc
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Kodeco Inc
* Copyright (c) 2025 Kodeco Inc
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -47,8 +47,8 @@ import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.BottomSheetScaffoldState
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material3.BottomSheetScaffoldState
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
Expand All @@ -69,7 +69,7 @@ import kotlinx.coroutines.CoroutineScope

private const val TAG = "HomeContent"

@OptIn(ExperimentalMaterialApi::class)
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun HomeContent(
selected: MutableState<KodecoEntry>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Kodeco Inc
* Copyright (c) 2025 Kodeco Inc
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -39,8 +39,8 @@ import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material.BottomSheetScaffoldState
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material3.BottomSheetScaffoldState
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
Expand All @@ -55,7 +55,7 @@ import kotlinx.coroutines.launch

private const val TAG = "HomeSheetContent"

@OptIn(ExperimentalMaterialApi::class)
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun HomeSheetContent(
item: MutableState<KodecoEntry>,
Expand All @@ -76,7 +76,7 @@ fun HomeSheetContent(
.fillMaxWidth()
.clickable {
coroutineScope.launch {
bottomSheetScaffoldState.bottomSheetState.collapse()
bottomSheetScaffoldState.bottomSheetState.hide()
}

onUpdateBookmark(item.value)
Expand All @@ -102,7 +102,7 @@ fun HomeSheetContent(
.fillMaxWidth()
.clickable {
coroutineScope.launch {
bottomSheetScaffoldState.bottomSheetState.collapse()
bottomSheetScaffoldState.bottomSheetState.hide()
}

onShareAsLink(item.value)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Kodeco Inc
* Copyright (c) 2025 Kodeco Inc
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -73,6 +73,8 @@ import com.kodeco.learn.ui.theme.colorContent85Transparency

private const val TAG = "LatestContent"

private const val ITEMS = 5

@Composable
fun LatestContent(
items: SnapshotStateMap<PLATFORM, List<KodecoEntry>>,
Expand Down Expand Up @@ -109,7 +111,7 @@ fun AddPages(

AddNewPage(
platform = platform,
items = items[platform] ?: emptyList(),
items = items[platform]?.subList(0, ITEMS) ?: emptyList(),
onOpenEntry = onOpenEntry
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Kodeco Inc
* Copyright (c) 2025 Kodeco Inc
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Kodeco Inc
* Copyright (c) 2025 Kodeco Inc
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Kodeco Inc
* Copyright (c) 2025 Kodeco Inc
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -35,8 +35,8 @@
package com.kodeco.learn.ui.main

import androidx.compose.foundation.layout.Column
import androidx.compose.material.BottomSheetScaffoldState
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material3.BottomSheetScaffoldState
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.State
Expand All @@ -54,7 +54,7 @@ import kotlinx.coroutines.CoroutineScope

private val DEFAULT_SCREEN = BottomNavigationScreens.Home

@OptIn(ExperimentalMaterialApi::class)
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun MainContent(
navController: NavHostController,
Expand All @@ -79,7 +79,7 @@ fun MainContent(
}
}

@OptIn(ExperimentalMaterialApi::class)
@OptIn(ExperimentalMaterial3Api::class)
@Composable
private fun MainScreenNavigationConfigurations(
navController: NavHostController,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Kodeco Inc
* Copyright (c) 2025 Kodeco Inc
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -37,10 +37,11 @@ package com.kodeco.learn.ui.main
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.BottomSheetScaffold
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.rememberBottomSheetScaffoldState
import androidx.compose.material3.BottomSheetScaffold
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.rememberBottomSheetScaffoldState
import androidx.compose.material3.Scaffold
import androidx.compose.material3.rememberStandardBottomSheetState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.State
Expand All @@ -58,7 +59,7 @@ import com.kodeco.learn.ui.home.HomeSheetContent

private lateinit var selected: MutableState<KodecoEntry>

@OptIn(ExperimentalMaterialApi::class)
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun MainScreen(
profile: GravatarEntry?,
Expand All @@ -80,7 +81,9 @@ fun MainScreen(
navController.enableOnBackPressed(false)

val coroutineScope = rememberCoroutineScope()
val bottomSheetScaffoldState = rememberBottomSheetScaffoldState()
val bottomSheetScaffoldState = rememberBottomSheetScaffoldState(
bottomSheetState = rememberStandardBottomSheetState(skipHiddenState = false)
)

selected = remember { mutableStateOf(KodecoEntry()) }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Kodeco Inc
* Copyright (c) 2025 Kodeco Inc
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -71,15 +71,15 @@ fun MainTopAppBar(
val avatarUrl = profile?.thumbnailUrl
if (avatarUrl == null) {
Icon(
imageVector = Icons.Filled.Person,
contentDescription = stringResource(R.string.description_profile)
imageVector = Icons.Filled.Person,
contentDescription = stringResource(R.string.description_profile)
)
} else {
AddImagePreview(
url = avatarUrl,
modifier = Modifier
.clip(CircleShape)
.size(25.dp)
url = avatarUrl,
modifier = Modifier
.clip(CircleShape)
.size(25.dp)
)
}
}
Expand Down
Loading