Skip to content

Commit 87f862e

Browse files
authored
Merge pull request android#356 from android/dev_alpha10
[All] Update to alpha10
2 parents de4d7b8 + 02dd7d2 commit 87f862e

File tree

47 files changed

+302
-187
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+302
-187
lines changed

Crane/buildSrc/src/main/java/com/example/crane/buildsrc/Dependencies.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ object Versions {
2121
}
2222

2323
object Libs {
24-
const val androidGradlePlugin = "com.android.tools.build:gradle:7.0.0-alpha03"
24+
const val androidGradlePlugin = "com.android.tools.build:gradle:7.0.0-alpha04"
2525
const val ktLint = "com.pinterest:ktlint:${Versions.ktLint}"
2626

2727
object GoogleMaps {
@@ -30,7 +30,7 @@ object Libs {
3030
}
3131

3232
object Accompanist {
33-
private const val version = "0.4.1"
33+
private const val version = "0.4.2"
3434
const val coil = "dev.chrisbanes.accompanist:accompanist-coil:$version"
3535
}
3636

@@ -50,7 +50,7 @@ object Libs {
5050
object AndroidX {
5151
object Compose {
5252
const val snapshot = ""
53-
private const val version = "1.0.0-alpha09"
53+
private const val version = "1.0.0-alpha10"
5454

5555
const val runtime = "androidx.compose.runtime:runtime:$version"
5656
const val runtimeLivedata = "androidx.compose.runtime:runtime-livedata:$version"

JetNews/app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ dependencies {
9393
implementation 'androidx.activity:activity-ktx:1.1.0'
9494
implementation 'androidx.core:core-ktx:1.5.0-alpha05'
9595

96-
implementation "androidx.lifecycle:lifecycle-viewmodel-savedstate:2.3.0-beta01"
97-
implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.3.0-beta01"
96+
implementation "androidx.lifecycle:lifecycle-viewmodel-savedstate:2.3.0-rc01"
97+
implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.3.0-rc01"
9898

9999
androidTestImplementation 'junit:junit:4.13.1'
100100
androidTestImplementation 'androidx.test:rules:1.3.0'

JetNews/app/src/main/java/com/example/jetnews/ui/SwipeToRefresh.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ private val <T> SwipeableState<T>.PreUpPostDownNestedScrollConnection: NestedScr
117117
}
118118

119119
override fun onPreFling(available: Velocity): Velocity {
120-
val toFling = available.pixelsPerSecond.toFloat()
120+
val toFling = Offset(available.x, available.y).toFloat()
121121
return if (toFling < 0) {
122122
performFling(velocity = toFling) {}
123123
// since we go to the anchor with tween settling, consume all for the best UX
@@ -132,7 +132,7 @@ private val <T> SwipeableState<T>.PreUpPostDownNestedScrollConnection: NestedScr
132132
available: Velocity,
133133
onFinished: (Velocity) -> Unit
134134
) {
135-
performFling(velocity = available.pixelsPerSecond.toFloat()) {
135+
performFling(velocity = Offset(available.x, available.y).toFloat()) {
136136
// since we go to the anchor with tween settling, consume all for the best UX
137137
onFinished.invoke(available)
138138
}

JetNews/app/src/main/java/com/example/jetnews/ui/home/HomeScreen.kt

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import androidx.compose.runtime.LaunchedEffect
4747
import androidx.compose.runtime.collectAsState
4848
import androidx.compose.runtime.getValue
4949
import androidx.compose.runtime.rememberCoroutineScope
50+
import androidx.compose.runtime.rememberUpdatedState
5051
import androidx.compose.ui.Alignment
5152
import androidx.compose.ui.Modifier
5253
import androidx.compose.ui.platform.AmbientContext
@@ -134,17 +135,23 @@ fun HomeScreen(
134135
if (posts.hasError) {
135136
val errorMessage = stringResource(id = R.string.load_error)
136137
val retryMessage = stringResource(id = R.string.retry)
138+
139+
// If onRefreshPosts or onErrorDismiss change while the LaunchedEffect is running,
140+
// don't restart the effect and use the latest lambda values.
141+
val onRefreshPostsState by rememberUpdatedState(onRefreshPosts)
142+
val onErrorDismissState by rememberUpdatedState(onErrorDismiss)
143+
137144
// Show snackbar using a coroutine, when the coroutine is cancelled the snackbar will
138-
// automatically dismiss. This coroutine will cancel whenever posts.hasError changes, and
139-
// only start when posts.hasError is true (due to the above if-check).
140-
LaunchedEffect(posts.hasError) {
145+
// automatically dismiss. This coroutine will cancel whenever posts.hasError is false
146+
// (thanks to the surrounding if statement) or if scaffoldState changes.
147+
LaunchedEffect(scaffoldState) {
141148
val snackbarResult = scaffoldState.snackbarHostState.showSnackbar(
142149
message = errorMessage,
143150
actionLabel = retryMessage
144151
)
145152
when (snackbarResult) {
146-
SnackbarResult.ActionPerformed -> onRefreshPosts()
147-
SnackbarResult.Dismissed -> onErrorDismiss()
153+
SnackbarResult.ActionPerformed -> onRefreshPostsState()
154+
SnackbarResult.Dismissed -> onErrorDismissState()
148155
}
149156
}
150157
}

JetNews/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
buildscript {
1818
ext.kotlin_version = '1.4.21'
19-
ext.compose_version = '1.0.0-alpha09'
19+
ext.compose_version = '1.0.0-alpha10'
2020
ext.coroutines_version = '1.4.2'
2121

2222
repositories {
@@ -25,7 +25,7 @@ buildscript {
2525
}
2626

2727
dependencies {
28-
classpath 'com.android.tools.build:gradle:7.0.0-alpha02'
28+
classpath 'com.android.tools.build:gradle:7.0.0-alpha04'
2929
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
3030
}
3131
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#Tue Oct 27 16:21:59 PDT 2020
22
distributionBase=GRADLE_USER_HOME
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip
3+
distributionUrl=https://services.gradle.org/distributions/gradle-6.8-rc-1-bin.zip
44
distributionPath=wrapper/dists
55
zipStorePath=wrapper/dists
66
zipStoreBase=GRADLE_USER_HOME

Jetcaster/app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
1818
package="com.example.jetcaster">
1919

20+
<!-- Uses ACCESS_NETWORK_STATE to check if the device is connected to internet or not -->
21+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
2022
<!-- Uses INTERNET to fetch RSS feed + images -->
2123
<uses-permission android:name="android.permission.INTERNET" />
2224

Jetcaster/app/src/main/java/com/example/jetcaster/data/PodcastsRepository.kt

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.example.jetcaster.data
1818

19+
import android.util.Log
1920
import com.example.jetcaster.data.room.TransactionRunner
2021
import kotlinx.coroutines.CoroutineDispatcher
2122
import kotlinx.coroutines.CoroutineScope
@@ -43,22 +44,26 @@ class PodcastsRepository(
4344
refreshingJob?.join()
4445
} else if (force || podcastStore.isEmpty()) {
4546
refreshingJob = scope.launch {
46-
// Now fetch the podcasts, and add each to each store
47-
podcastsFetcher(SampleFeeds).collect { (podcast, episodes, categories) ->
48-
transactionRunner {
49-
podcastStore.addPodcast(podcast)
50-
episodeStore.addEpisodes(episodes)
47+
try {
48+
// Now fetch the podcasts, and add each to each store
49+
podcastsFetcher(SampleFeeds).collect { (podcast, episodes, categories) ->
50+
transactionRunner {
51+
podcastStore.addPodcast(podcast)
52+
episodeStore.addEpisodes(episodes)
5153

52-
categories.forEach { category ->
53-
// First insert the category
54-
val categoryId = categoryStore.addCategory(category)
55-
// Now we can add the podcast to the category
56-
categoryStore.addPodcastToCategory(
57-
podcastUri = podcast.uri,
58-
categoryId = categoryId
59-
)
54+
categories.forEach { category ->
55+
// First insert the category
56+
val categoryId = categoryStore.addCategory(category)
57+
// Now we can add the podcast to the category
58+
categoryStore.addPodcastToCategory(
59+
podcastUri = podcast.uri,
60+
categoryId = categoryId
61+
)
62+
}
6063
}
6164
}
65+
} catch (e: Throwable) {
66+
Log.d("PodcastsRepository", "podcastsFetcher(SampleFeeds).collect error: $e")
6267
}
6368
}
6469
}

Jetcaster/app/src/main/java/com/example/jetcaster/ui/JetcasterApp.kt

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,52 @@
1616

1717
package com.example.jetcaster.ui
1818

19+
import android.content.Context
20+
import android.net.ConnectivityManager
21+
import androidx.compose.material.AlertDialog
22+
import androidx.compose.material.Text
23+
import androidx.compose.material.TextButton
1924
import androidx.compose.runtime.Composable
25+
import androidx.compose.runtime.getValue
26+
import androidx.compose.runtime.mutableStateOf
27+
import androidx.compose.runtime.remember
28+
import androidx.compose.runtime.setValue
29+
import androidx.compose.ui.platform.AmbientContext
30+
import androidx.compose.ui.res.stringResource
31+
import com.example.jetcaster.R
2032
import com.example.jetcaster.ui.home.Home
2133

2234
@Composable
2335
fun JetcasterApp() {
36+
val context = AmbientContext.current
37+
var isOnline by remember { mutableStateOf(checkIfOnline(context)) }
38+
2439
// TODO: add some navigation
25-
Home()
40+
if (isOnline) {
41+
Home()
42+
} else {
43+
OfflineDialog { isOnline = checkIfOnline(context) }
44+
}
45+
}
46+
47+
// TODO: Use a better way to check internet connection
48+
@Suppress("DEPRECATION")
49+
private fun checkIfOnline(context: Context): Boolean {
50+
val cm = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
51+
val activeNetwork = cm.activeNetworkInfo
52+
return activeNetwork?.isConnectedOrConnecting == true
53+
}
54+
55+
@Composable
56+
fun OfflineDialog(onRetry: () -> Unit) {
57+
AlertDialog(
58+
onDismissRequest = {},
59+
title = { Text(text = stringResource(R.string.connection_error_title)) },
60+
text = { Text(text = stringResource(R.string.connection_error_message)) },
61+
confirmButton = {
62+
TextButton(onClick = onRetry) {
63+
Text(stringResource(R.string.retry_label))
64+
}
65+
}
66+
)
2667
}

Jetcaster/app/src/main/java/com/example/jetcaster/util/Buttons.kt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616

1717
package com.example.jetcaster.util
1818

19-
import androidx.compose.animation.animate
19+
import androidx.compose.animation.animateAsState
20+
import androidx.compose.animation.core.animateAsState
2021
import androidx.compose.foundation.background
2122
import androidx.compose.foundation.layout.padding
2223
import androidx.compose.material.AmbientContentColor
@@ -49,24 +50,24 @@ fun ToggleFollowPodcastIconButton(
4950
isFollowed -> Icons.Default.Check
5051
else -> Icons.Default.Add
5152
},
52-
tint = animate(
53+
tint = animateAsState(
5354
when {
5455
isFollowed -> AmbientContentColor.current
5556
else -> Color.Black.copy(alpha = ContentAlpha.high)
5657
}
57-
),
58+
).value,
5859
modifier = Modifier
5960
.shadow(
60-
elevation = animate(if (isFollowed) 0.dp else 1.dp),
61+
elevation = animateAsState(if (isFollowed) 0.dp else 1.dp).value,
6162
shape = MaterialTheme.shapes.small
6263
)
6364
.background(
64-
color = animate(
65+
color = animateAsState(
6566
when {
6667
isFollowed -> MaterialTheme.colors.surface.copy(0.38f)
6768
else -> Color.White
6869
}
69-
),
70+
).value,
7071
shape = MaterialTheme.shapes.small
7172
)
7273
.padding(4.dp)

0 commit comments

Comments
 (0)