Skip to content

Commit

Permalink
Merge pull request #356 from android/dev_alpha10
Browse files Browse the repository at this point in the history
[All] Update to alpha10
  • Loading branch information
manuelvicnt authored Jan 13, 2021
2 parents de4d7b8 + 02dd7d2 commit 87f862e
Show file tree
Hide file tree
Showing 47 changed files with 302 additions and 187 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ object Versions {
}

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

object GoogleMaps {
Expand All @@ -30,7 +30,7 @@ object Libs {
}

object Accompanist {
private const val version = "0.4.1"
private const val version = "0.4.2"
const val coil = "dev.chrisbanes.accompanist:accompanist-coil:$version"
}

Expand All @@ -50,7 +50,7 @@ object Libs {
object AndroidX {
object Compose {
const val snapshot = ""
private const val version = "1.0.0-alpha09"
private const val version = "1.0.0-alpha10"

const val runtime = "androidx.compose.runtime:runtime:$version"
const val runtimeLivedata = "androidx.compose.runtime:runtime-livedata:$version"
Expand Down
4 changes: 2 additions & 2 deletions JetNews/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ dependencies {
implementation 'androidx.activity:activity-ktx:1.1.0'
implementation 'androidx.core:core-ktx:1.5.0-alpha05'

implementation "androidx.lifecycle:lifecycle-viewmodel-savedstate:2.3.0-beta01"
implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.3.0-beta01"
implementation "androidx.lifecycle:lifecycle-viewmodel-savedstate:2.3.0-rc01"
implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.3.0-rc01"

androidTestImplementation 'junit:junit:4.13.1'
androidTestImplementation 'androidx.test:rules:1.3.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ private val <T> SwipeableState<T>.PreUpPostDownNestedScrollConnection: NestedScr
}

override fun onPreFling(available: Velocity): Velocity {
val toFling = available.pixelsPerSecond.toFloat()
val toFling = Offset(available.x, available.y).toFloat()
return if (toFling < 0) {
performFling(velocity = toFling) {}
// since we go to the anchor with tween settling, consume all for the best UX
Expand All @@ -132,7 +132,7 @@ private val <T> SwipeableState<T>.PreUpPostDownNestedScrollConnection: NestedScr
available: Velocity,
onFinished: (Velocity) -> Unit
) {
performFling(velocity = available.pixelsPerSecond.toFloat()) {
performFling(velocity = Offset(available.x, available.y).toFloat()) {
// since we go to the anchor with tween settling, consume all for the best UX
onFinished.invoke(available)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.rememberUpdatedState
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.AmbientContext
Expand Down Expand Up @@ -134,17 +135,23 @@ fun HomeScreen(
if (posts.hasError) {
val errorMessage = stringResource(id = R.string.load_error)
val retryMessage = stringResource(id = R.string.retry)

// If onRefreshPosts or onErrorDismiss change while the LaunchedEffect is running,
// don't restart the effect and use the latest lambda values.
val onRefreshPostsState by rememberUpdatedState(onRefreshPosts)
val onErrorDismissState by rememberUpdatedState(onErrorDismiss)

// Show snackbar using a coroutine, when the coroutine is cancelled the snackbar will
// automatically dismiss. This coroutine will cancel whenever posts.hasError changes, and
// only start when posts.hasError is true (due to the above if-check).
LaunchedEffect(posts.hasError) {
// automatically dismiss. This coroutine will cancel whenever posts.hasError is false
// (thanks to the surrounding if statement) or if scaffoldState changes.
LaunchedEffect(scaffoldState) {
val snackbarResult = scaffoldState.snackbarHostState.showSnackbar(
message = errorMessage,
actionLabel = retryMessage
)
when (snackbarResult) {
SnackbarResult.ActionPerformed -> onRefreshPosts()
SnackbarResult.Dismissed -> onErrorDismiss()
SnackbarResult.ActionPerformed -> onRefreshPostsState()
SnackbarResult.Dismissed -> onErrorDismissState()
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions JetNews/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

buildscript {
ext.kotlin_version = '1.4.21'
ext.compose_version = '1.0.0-alpha09'
ext.compose_version = '1.0.0-alpha10'
ext.coroutines_version = '1.4.2'

repositories {
Expand All @@ -25,7 +25,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:7.0.0-alpha02'
classpath 'com.android.tools.build:gradle:7.0.0-alpha04'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand Down
2 changes: 1 addition & 1 deletion JetNews/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Tue Oct 27 16:21:59 PDT 2020
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip
distributionUrl=https://services.gradle.org/distributions/gradle-6.8-rc-1-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
2 changes: 2 additions & 0 deletions Jetcaster/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.jetcaster">

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.example.jetcaster.data

import android.util.Log
import com.example.jetcaster.data.room.TransactionRunner
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
Expand Down Expand Up @@ -43,22 +44,26 @@ class PodcastsRepository(
refreshingJob?.join()
} else if (force || podcastStore.isEmpty()) {
refreshingJob = scope.launch {
// Now fetch the podcasts, and add each to each store
podcastsFetcher(SampleFeeds).collect { (podcast, episodes, categories) ->
transactionRunner {
podcastStore.addPodcast(podcast)
episodeStore.addEpisodes(episodes)
try {
// Now fetch the podcasts, and add each to each store
podcastsFetcher(SampleFeeds).collect { (podcast, episodes, categories) ->
transactionRunner {
podcastStore.addPodcast(podcast)
episodeStore.addEpisodes(episodes)

categories.forEach { category ->
// First insert the category
val categoryId = categoryStore.addCategory(category)
// Now we can add the podcast to the category
categoryStore.addPodcastToCategory(
podcastUri = podcast.uri,
categoryId = categoryId
)
categories.forEach { category ->
// First insert the category
val categoryId = categoryStore.addCategory(category)
// Now we can add the podcast to the category
categoryStore.addPodcastToCategory(
podcastUri = podcast.uri,
categoryId = categoryId
)
}
}
}
} catch (e: Throwable) {
Log.d("PodcastsRepository", "podcastsFetcher(SampleFeeds).collect error: $e")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,52 @@

package com.example.jetcaster.ui

import android.content.Context
import android.net.ConnectivityManager
import androidx.compose.material.AlertDialog
import androidx.compose.material.Text
import androidx.compose.material.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.platform.AmbientContext
import androidx.compose.ui.res.stringResource
import com.example.jetcaster.R
import com.example.jetcaster.ui.home.Home

@Composable
fun JetcasterApp() {
val context = AmbientContext.current
var isOnline by remember { mutableStateOf(checkIfOnline(context)) }

// TODO: add some navigation
Home()
if (isOnline) {
Home()
} else {
OfflineDialog { isOnline = checkIfOnline(context) }
}
}

// TODO: Use a better way to check internet connection
@Suppress("DEPRECATION")
private fun checkIfOnline(context: Context): Boolean {
val cm = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
val activeNetwork = cm.activeNetworkInfo
return activeNetwork?.isConnectedOrConnecting == true
}

@Composable
fun OfflineDialog(onRetry: () -> Unit) {
AlertDialog(
onDismissRequest = {},
title = { Text(text = stringResource(R.string.connection_error_title)) },
text = { Text(text = stringResource(R.string.connection_error_message)) },
confirmButton = {
TextButton(onClick = onRetry) {
Text(stringResource(R.string.retry_label))
}
}
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

package com.example.jetcaster.util

import androidx.compose.animation.animate
import androidx.compose.animation.animateAsState
import androidx.compose.animation.core.animateAsState
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.padding
import androidx.compose.material.AmbientContentColor
Expand Down Expand Up @@ -49,24 +50,24 @@ fun ToggleFollowPodcastIconButton(
isFollowed -> Icons.Default.Check
else -> Icons.Default.Add
},
tint = animate(
tint = animateAsState(
when {
isFollowed -> AmbientContentColor.current
else -> Color.Black.copy(alpha = ContentAlpha.high)
}
),
).value,
modifier = Modifier
.shadow(
elevation = animate(if (isFollowed) 0.dp else 1.dp),
elevation = animateAsState(if (isFollowed) 0.dp else 1.dp).value,
shape = MaterialTheme.shapes.small
)
.background(
color = animate(
color = animateAsState(
when {
isFollowed -> MaterialTheme.colors.surface.copy(0.38f)
else -> Color.White
}
),
).value,
shape = MaterialTheme.shapes.small
)
.padding(4.dp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package com.example.jetcaster.util

import android.content.Context
import androidx.collection.LruCache
import androidx.compose.animation.animate
import androidx.compose.animation.animateAsState
import androidx.compose.animation.core.Spring
import androidx.compose.animation.core.spring
import androidx.compose.material.MaterialTheme
Expand Down Expand Up @@ -61,8 +61,14 @@ fun DynamicThemePrimaryColorsFromImage(
content: @Composable () -> Unit
) {
val colors = MaterialTheme.colors.copy(
primary = animate(dominantColorState.color, spring(stiffness = Spring.StiffnessLow)),
onPrimary = animate(dominantColorState.onColor, spring(stiffness = Spring.StiffnessLow))
primary = animateAsState(
dominantColorState.color,
spring(stiffness = Spring.StiffnessLow)
).value,
onPrimary = animateAsState(
dominantColorState.onColor,
spring(stiffness = Spring.StiffnessLow)
).value
)
MaterialTheme(colors = colors, content = content)
}
Expand Down
5 changes: 5 additions & 0 deletions Jetcaster/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
-->
<resources>
<string name="app_name">Jetcaster</string>

<string name="connection_error_title">Connection error</string>
<string name="connection_error_message">Unable to fetch podcasts feeds.\nCheck your internet connection and try again.</string>
<string name="retry_label">Retry</string>

<string name="your_podcasts">Your podcasts</string>
<string name="latest_episodes">Latest episodes</string>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ object Versions {
}

object Libs {
const val androidGradlePlugin = "com.android.tools.build:gradle:7.0.0-alpha03"
const val androidGradlePlugin = "com.android.tools.build:gradle:7.0.0-alpha04"
const val jdkDesugar = "com.android.tools:desugar_jdk_libs:1.0.9"

const val junit = "junit:junit:4.13"

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

object Accompanist {
private const val version = "0.4.1"
private const val version = "0.4.2"
const val coil = "dev.chrisbanes.accompanist:accompanist-coil:$version"
const val insets = "dev.chrisbanes.accompanist:accompanist-insets:$version"
}
Expand Down Expand Up @@ -58,12 +58,11 @@ object Libs {
const val appcompat = "androidx.appcompat:appcompat:1.2.0"
const val palette = "androidx.palette:palette:1.0.0"

const val core = "androidx.core:core:1.5.0-alpha04"
const val coreKtx = "androidx.core:core-ktx:1.5.0-alpha04"
const val coreKtx = "androidx.core:core-ktx:1.5.0-beta01"

object Compose {
private const val snapshot = ""
private const val version = "1.0.0-alpha09"
private const val version = "1.0.0-alpha10"

@get:JvmStatic
val snapshotUrl: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class ConversationTest {
// Launch the conversation screen
composeTestRule.setContent {
Providers(
AmbientBackPressedDispatcher provides newActivity,
AmbientBackPressedDispatcher provides newActivity.onBackPressedDispatcher,
AmbientWindowInsets provides windowInsets
) {
JetchatTheme(isDarkTheme = themeIsDark.collectAsState(false).value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class NavigationTest {
// Start the app
composeTestRule.setContent {
Providers(
AmbientBackPressedDispatcher provides activity,
AmbientBackPressedDispatcher provides activity.onBackPressedDispatcher,
AmbientWindowInsets provides windowInsets,
) {
JetchatTheme {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class UserInputTest {
// Launch the conversation screen
composeTestRule.setContent {
Providers(
AmbientBackPressedDispatcher provides activity,
AmbientBackPressedDispatcher provides activity.onBackPressedDispatcher,
AmbientWindowInsets provides windowInsets,
) {
JetchatTheme {
Expand Down
Loading

0 comments on commit 87f862e

Please sign in to comment.