Skip to content

Commit 61a47f5

Browse files
authoredJan 13, 2021
Merge pull request android#341 from yrezgui/jetcaster-alpha10
[Jetcaster] Bump to alpha10 snapshot
2 parents 4a63c7a + ceafe92 commit 61a47f5

File tree

8 files changed

+92
-30
lines changed

8 files changed

+92
-30
lines changed
 

‎Jetcaster/app/build.gradle

+3-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ dependencies {
9797
implementation Libs.Kotlin.stdlib
9898
implementation Libs.Coroutines.android
9999

100-
implementation Libs.AndroidX.coreKtx
100+
// Accompanist.insets must depend on the SNAPSHOT version of core:1.5.0
101+
implementation(Libs.AndroidX.core) { force true }
102+
implementation(Libs.AndroidX.coreKtx) { force true }
101103
implementation Libs.AndroidX.palette
102104

103105
implementation Libs.AndroidX.Lifecycle.viewmodel

‎Jetcaster/app/src/main/AndroidManifest.xml

+2
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

+18-13
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

+42-1
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

+7-6
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)

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

+9-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ package com.example.jetcaster.util
1818

1919
import android.content.Context
2020
import androidx.collection.LruCache
21-
import androidx.compose.animation.animate
21+
import androidx.compose.animation.animateAsState
2222
import androidx.compose.animation.core.Spring
2323
import androidx.compose.animation.core.spring
2424
import androidx.compose.material.MaterialTheme
@@ -61,8 +61,14 @@ fun DynamicThemePrimaryColorsFromImage(
6161
content: @Composable () -> Unit
6262
) {
6363
val colors = MaterialTheme.colors.copy(
64-
primary = animate(dominantColorState.color, spring(stiffness = Spring.StiffnessLow)),
65-
onPrimary = animate(dominantColorState.onColor, spring(stiffness = Spring.StiffnessLow))
64+
primary = animateAsState(
65+
dominantColorState.color,
66+
spring(stiffness = Spring.StiffnessLow)
67+
).value,
68+
onPrimary = animateAsState(
69+
dominantColorState.onColor,
70+
spring(stiffness = Spring.StiffnessLow)
71+
).value
6672
)
6773
MaterialTheme(colors = colors, content = content)
6874
}

‎Jetcaster/app/src/main/res/values/strings.xml

+5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
-->
1717
<resources>
1818
<string name="app_name">Jetcaster</string>
19+
20+
<string name="connection_error_title">Connection error</string>
21+
<string name="connection_error_message">Unable to fetch podcasts feeds.\nCheck your internet connection and try again.</string>
22+
<string name="retry_label">Retry</string>
23+
1924
<string name="your_podcasts">Your podcasts</string>
2025
<string name="latest_episodes">Latest episodes</string>
2126

‎Jetcaster/buildSrc/src/main/java/com/example/jetcaster/buildsrc/dependencies.kt

+6-6
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ 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 jdkDesugar = "com.android.tools:desugar_jdk_libs:1.0.9"
2626

2727
const val junit = "junit:junit:4.13"
2828

2929
const val material = "com.google.android.material:material:1.1.0"
3030

3131
object Accompanist {
32-
private const val version = "0.4.1"
32+
private const val version = "0.4.1.compose-7067732-SNAPSHOT"
3333
const val coil = "dev.chrisbanes.accompanist:accompanist-coil:$version"
3434
const val insets = "dev.chrisbanes.accompanist:accompanist-insets:$version"
3535
}
@@ -58,12 +58,12 @@ object Libs {
5858
const val appcompat = "androidx.appcompat:appcompat:1.2.0"
5959
const val palette = "androidx.palette:palette:1.0.0"
6060

61-
const val core = "androidx.core:core:1.5.0-alpha04"
62-
const val coreKtx = "androidx.core:core-ktx:1.5.0-alpha04"
61+
const val core = "androidx.core:core:1.5.0-SNAPSHOT"
62+
const val coreKtx = "androidx.core:core-ktx:1.5.0-SNAPSHOT"
6363

6464
object Compose {
65-
private const val snapshot = ""
66-
private const val version = "1.0.0-alpha09"
65+
private const val snapshot = "7067732"
66+
private const val version = "1.0.0-SNAPSHOT"
6767

6868
@get:JvmStatic
6969
val snapshotUrl: String

0 commit comments

Comments
 (0)
Please sign in to comment.