Skip to content

Commit

Permalink
Update to snapshot 6602655.
Browse files Browse the repository at this point in the history
Change-Id: Id0dae663e157e9ccdd0be4a9629b92178c6e1e91
  • Loading branch information
nickbutcher committed Jun 19, 2020
1 parent 89b8ae4 commit 96420be
Show file tree
Hide file tree
Showing 15 changed files with 186 additions and 177 deletions.
66 changes: 35 additions & 31 deletions JetNews/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ apply plugin: 'kotlin-android'
android {
compileSdkVersion 29
defaultConfig {
applicationId "com.example.jetnews"
applicationId 'com.example.jetnews'
minSdkVersion 21
targetSdkVersion 29
versionCode 1
versionName "1.0"
versionName '1.0'
vectorDrawables.useSupportLibrary = true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
}

buildTypes {
release {
minifyEnabled false
Expand All @@ -41,15 +42,18 @@ android {
}

kotlinOptions {
jvmTarget = "1.8"
jvmTarget = '1.8'
apiVersion = '1.3'
allWarningsAsErrors = true
}

buildFeatures {
compose true
}

composeOptions {
kotlinCompilerVersion "1.3.70-dev-withExperimentalGoogleExtensions-20200424"
kotlinCompilerExtensionVersion "$compose_compiler_extension_version"
kotlinCompilerVersion '1.3.70-dev-withExperimentalGoogleExtensions-20200424'
kotlinCompilerExtensionVersion compose_version
}
}

Expand All @@ -58,40 +62,40 @@ configurations {
}

dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version")
implementation("androidx.compose:compose-runtime:$compose_version")
implementation("androidx.ui:ui-core:$compose_version")
implementation("androidx.ui:ui-layout:$compose_version")
implementation("androidx.ui:ui-material:$compose_version")
implementation("androidx.ui:ui-material-icons-extended:$compose_version")
implementation("androidx.ui:ui-foundation:$compose_version")
implementation("androidx.ui:ui-animation:$compose_version")
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "androidx.compose:compose-runtime:$compose_version"
implementation "androidx.ui:ui-core:$compose_version"
implementation "androidx.ui:ui-layout:$compose_version"
implementation "androidx.ui:ui-material:$compose_version"
implementation "androidx.ui:ui-material-icons-extended:$compose_version"
implementation "androidx.ui:ui-foundation:$compose_version"
implementation "androidx.ui:ui-animation:$compose_version"
implementation "androidx.ui:ui-tooling:$compose_version"
implementation('androidx.appcompat:appcompat:1.1.0')
implementation('androidx.activity:activity-ktx:1.1.0')
implementation "androidx.core:core-ktx:1.2.0"
implementation 'androidx.appcompat:appcompat:1.3.0-alpha01'
implementation 'androidx.activity:activity-ktx:1.1.0'
implementation 'androidx.core:core-ktx:1.5.0-alpha01'

androidTestImplementation("junit:junit:4.13")
androidTestImplementation("androidx.test:rules:1.2.0")
androidTestImplementation("androidx.test:runner:1.2.0")
androidTestImplementation("androidx.ui:ui-core:$compose_version")
androidTestImplementation("androidx.ui:ui-test:$compose_version")
androidTestImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test:rules:1.2.0'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation "androidx.ui:ui-core:$compose_version"
androidTestImplementation "androidx.ui:ui-test:$compose_version"

ktlint "com.pinterest:ktlint:0.36.0"
ktlint 'com.pinterest:ktlint:0.37.0'
}

task ktlint(type: JavaExec, group: "verification") {
description = "Check Kotlin code style."
main = "com.pinterest.ktlint.Main"
task ktlint(type: JavaExec, group: 'verification') {
description = 'Check Kotlin code style.'
main = 'com.pinterest.ktlint.Main'
classpath = configurations.ktlint
args "src/**/*.kt"
args 'src/**/*.kt'
}

check.dependsOn ktlint

task ktlintFormat(type: JavaExec, group: "formatting") {
description = "Fix Kotlin code style deviations."
main = "com.pinterest.ktlint.Main"
task ktlintFormat(type: JavaExec, group: 'formatting') {
description = 'Fix Kotlin code style deviations.'
main = 'com.pinterest.ktlint.Main'
classpath = configurations.ktlint
args "-F", "src/**/*.kt"
args '-F', 'src/**/*.kt'
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@ class FakePostsRepository(
override fun getPost(postId: String, callback: (Result<Post?>) -> Unit) {
executeInBackground(callback) {
resultThreadHandler.post {
callback(Result.Success(
postsWithResources.find { it.id == postId }
))
callback(
Result.Success(
postsWithResources.find { it.id == postId }
)
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,12 @@ val paragraphsPost1 = listOf(
"These modules are included in the settings.gradle file as:"
),
Paragraph(
ParagraphType.CodeBlock, "include ':app'\n" +
"include ':features:module1'\n" +
"include ':features:module2'\n" +
"include ':features:module3'\n" +
"include ':features:module4'"
ParagraphType.CodeBlock,
"include ':app'\n" +
"include ':features:module1'\n" +
"include ':features:module2'\n" +
"include ':features:module3'\n" +
"include ':features:module4'"
),
Paragraph(
ParagraphType.Text,
Expand Down Expand Up @@ -96,20 +97,21 @@ val paragraphsPost1 = listOf(
listOf(Markup(MarkupType.Code, 28, 43))
),
Paragraph(
ParagraphType.CodeBlock, "include ':app'\n" +
"include ':module1'\n" +
"include ':module1'\n" +
"include ':module1'\n" +
"include ':module1'"
ParagraphType.CodeBlock,
"include ':app'\n" +
"include ':module1'\n" +
"include ':module1'\n" +
"include ':module1'\n" +
"include ':module1'"
),
Paragraph(
ParagraphType.CodeBlock,
"// Set a custom path for the four features modules.\n" +
"// This avoid to have an empty \"features\" module in Android Studio.\n" +
"project(\":module1\").projectDir=new File(rootDir, \"features/module1\")\n" +
"project(\":module2\").projectDir=new File(rootDir, \"features/module2\")\n" +
"project(\":module3\").projectDir=new File(rootDir, \"features/module3\")\n" +
"project(\":module4\").projectDir=new File(rootDir, \"features/module4\")"
"// This avoid to have an empty \"features\" module in Android Studio.\n" +
"project(\":module1\").projectDir=new File(rootDir, \"features/module1\")\n" +
"project(\":module2\").projectDir=new File(rootDir, \"features/module2\")\n" +
"project(\":module3\").projectDir=new File(rootDir, \"features/module3\")\n" +
"project(\":module4\").projectDir=new File(rootDir, \"features/module4\")"
),
Paragraph(
ParagraphType.Text,
Expand Down Expand Up @@ -312,7 +314,7 @@ val paragraphsPost2 = listOf(
Paragraph(
ParagraphType.CodeBlock,
"@Inject @MinimumBalance lateinit var minimumBalance: BigDecimal \n" +
"// @MinimumBalance is ignored!",
"// @MinimumBalance is ignored!",
listOf(Markup(MarkupType.Bold, 65, 95))
),
Paragraph(
Expand Down Expand Up @@ -401,10 +403,10 @@ val paragraphsPost2 = listOf(
Paragraph(
ParagraphType.CodeBlock,
"class MyVMFactory @Inject constructor(\n" +
" private val vmMap: Map<String, @JvmSuppressWildcards Provider<ViewModel>>\n" +
") { \n" +
" ... \n" +
"}",
" private val vmMap: Map<String, @JvmSuppressWildcards Provider<ViewModel>>\n" +
") { \n" +
" ... \n" +
"}",
listOf(Markup(MarkupType.Bold, 72, 93))
),
Paragraph(
Expand Down Expand Up @@ -692,8 +694,8 @@ val paragraphsPost5 = listOf(
Paragraph(
ParagraphType.CodeBlock,
"public inline fun <T, R> Iterable<T>.map(transform: (T) -> R): List<R> {\n" +
" return mapTo(ArrayList<R>(collectionSizeOrDefault(10)), transform)\n" +
"}",
" return mapTo(ArrayList<R>(collectionSizeOrDefault(10)), transform)\n" +
"}",
listOf(
Markup(MarkupType.Bold, 7, 13),
Markup(MarkupType.Bold, 88, 97)
Expand Down Expand Up @@ -737,8 +739,8 @@ val paragraphsPost5 = listOf(
Paragraph(
ParagraphType.CodeBlock,
"public fun <T, R> Sequence<T>.map(transform: (T) -> R): Sequence<R>{ \n" +
" return TransformingSequence(this, transform)\n" +
"}",
" return TransformingSequence(this, transform)\n" +
"}",
listOf(Markup(MarkupType.Bold, 85, 105))
),
Paragraph(
Expand All @@ -757,9 +759,9 @@ val paragraphsPost5 = listOf(
Paragraph(
ParagraphType.CodeBlock,
"public inline fun <T> Sequence<T>.first(predicate: (T) -> Boolean): T {\n" +
" for (element in this) if (predicate(element)) return element\n" +
" throw NoSuchElementException(“Sequence contains no element matching the predicate.”)\n" +
"}"
" for (element in this) if (predicate(element)) return element\n" +
" throw NoSuchElementException(“Sequence contains no element matching the predicate.”)\n" +
"}"
),
Paragraph(
ParagraphType.Text,
Expand All @@ -772,7 +774,7 @@ val paragraphsPost5 = listOf(
Paragraph(
ParagraphType.CodeBlock,
"internal class TransformingIndexedSequence<T, R> \n" +
"constructor(private val sequence: Sequence<T>, private val transformer: (Int, T) -> R) : Sequence<R> {",
"constructor(private val sequence: Sequence<T>, private val transformer: (Int, T) -> R) : Sequence<R> {",
listOf(
Markup(
MarkupType.Bold,
Expand All @@ -784,12 +786,12 @@ val paragraphsPost5 = listOf(
Paragraph(
ParagraphType.CodeBlock,
"override fun iterator(): Iterator<R> = object : Iterator<R> {\n" +
"\n" +
" override fun next(): R {\n" +
" return transformer(checkIndexOverflow(index++), iterator.next())\n" +
" }\n" +
"\n" +
"}",
"\n" +
" override fun next(): R {\n" +
" return transformer(checkIndexOverflow(index++), iterator.next())\n" +
" }\n" +
"\n" +
"}",
listOf(
Markup(MarkupType.Bold, 83, 89),
Markup(MarkupType.Bold, 107, 118)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ private fun DrawerButton(
Row(
horizontalArrangement = Arrangement.Start,
verticalGravity = Alignment.CenterVertically,
modifier = Modifier.fillMaxWidth()) {
modifier = Modifier.fillMaxWidth()
) {
Image(
asset = icon,
colorFilter = ColorFilter.tint(textIconColor),
Expand Down
22 changes: 12 additions & 10 deletions JetNews/app/src/main/java/com/example/jetnews/ui/SwipeToRefresh.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import androidx.ui.foundation.gestures.draggable
import androidx.ui.layout.Stack
import androidx.ui.layout.offset
import androidx.ui.unit.dp
import androidx.ui.unit.px

private val SWIPE_DISTANCE_SIZE = 100.dp
private const val SWIPE_DOWN_OFFSET = 1.2f
Expand All @@ -49,7 +48,7 @@ fun SwipeToRefreshLayout(
refreshIndicator: @Composable() () -> Unit,
content: @Composable() () -> Unit
) {
val size = with(DensityAmbient.current) { SWIPE_DISTANCE_SIZE.toPx().value }
val size = with(DensityAmbient.current) { SWIPE_DISTANCE_SIZE.toPx() }
// min is below negative to hide
val min = -size
val max = size * SWIPE_DOWN_OFFSET
Expand All @@ -63,7 +62,7 @@ fun SwipeToRefreshLayout(
maxValue = max
) { dragPosition ->
val dpOffset = with(DensityAmbient.current) {
(dragPosition.value * 0.5).px.toDp()
(dragPosition.value * 0.5f).toDp()
}
Stack {
content()
Expand Down Expand Up @@ -123,15 +122,18 @@ internal fun <T> StateDraggable(
val anchors = remember(anchorsToState) { anchorsToState.map { it.first } }
val currentValue = anchorsToState.firstOrNull { it.second == state }!!.first
val flingConfig =
AnchorsFlingConfig(anchors, animationBuilder, onAnimationEnd = { reason, finalValue, _ ->
if (reason != AnimationEndReason.Interrupted) {
val newState = anchorsToState.firstOrNull { it.first == finalValue }?.second
if (newState != null && newState != state) {
onStateChange(newState)
forceAnimationCheck.value = !forceAnimationCheck.value
AnchorsFlingConfig(
anchors, animationBuilder,
onAnimationEnd = { reason, finalValue, _ ->
if (reason != AnimationEndReason.Interrupted) {
val newState = anchorsToState.firstOrNull { it.first == finalValue }?.second
if (newState != null && newState != state) {
onStateChange(newState)
forceAnimationCheck.value = !forceAnimationCheck.value
}
}
}
})
)
val position = animatedFloat(currentValue)
position.setBounds(minValue, maxValue)

Expand Down
Loading

0 comments on commit 96420be

Please sign in to comment.