Skip to content

Commit 497c898

Browse files
authored
Merge pull request android#103 from android/nb/dev14-master
Merge develop into master
2 parents 99f24da + 459ebc6 commit 497c898

File tree

21 files changed

+510
-271
lines changed

21 files changed

+510
-271
lines changed

JetNews/app/build.gradle

Lines changed: 39 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@ apply plugin: 'kotlin-android'
2020
android {
2121
compileSdkVersion 29
2222
defaultConfig {
23-
applicationId "com.example.jetnews"
23+
applicationId 'com.example.jetnews'
2424
minSdkVersion 21
2525
targetSdkVersion 29
2626
versionCode 1
27-
versionName "1.0"
27+
versionName '1.0'
2828
vectorDrawables.useSupportLibrary = true
29-
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
29+
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
3030
}
31+
3132
buildTypes {
3233
release {
3334
minifyEnabled false
@@ -41,15 +42,18 @@ android {
4142
}
4243

4344
kotlinOptions {
44-
jvmTarget = "1.8"
45+
jvmTarget = '1.8'
46+
apiVersion = '1.3' // Compose compiler based on 1.4 but set 1.3 for compatibility
47+
allWarningsAsErrors = true
4548
}
4649

4750
buildFeatures {
4851
compose true
4952
}
53+
5054
composeOptions {
51-
kotlinCompilerVersion "1.3.70-dev-withExperimentalGoogleExtensions-20200424"
52-
kotlinCompilerExtensionVersion "$compose_compiler_extension_version"
55+
kotlinCompilerVersion '1.3.70-dev-withExperimentalGoogleExtensions-20200424'
56+
kotlinCompilerExtensionVersion compose_version
5357
}
5458
}
5559

@@ -58,40 +62,44 @@ configurations {
5862
}
5963

6064
dependencies {
61-
implementation("org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version")
62-
implementation("androidx.compose:compose-runtime:$compose_version")
63-
implementation("androidx.ui:ui-core:$compose_version")
64-
implementation("androidx.ui:ui-layout:$compose_version")
65-
implementation("androidx.ui:ui-material:$compose_version")
66-
implementation("androidx.ui:ui-material-icons-extended:$compose_version")
67-
implementation("androidx.ui:ui-foundation:$compose_version")
68-
implementation("androidx.ui:ui-animation:$compose_version")
65+
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
66+
implementation "androidx.compose:compose-runtime:$compose_version"
67+
implementation "androidx.ui:ui-core:$compose_version"
68+
implementation "androidx.ui:ui-layout:$compose_version"
69+
implementation "androidx.ui:ui-material:$compose_version"
70+
implementation "androidx.ui:ui-material-icons-extended:$compose_version"
71+
implementation "androidx.ui:ui-foundation:$compose_version"
72+
implementation "androidx.ui:ui-animation:$compose_version"
6973
implementation "androidx.ui:ui-tooling:$compose_version"
70-
implementation('androidx.appcompat:appcompat:1.1.0')
71-
implementation('androidx.activity:activity-ktx:1.1.0')
72-
implementation "androidx.core:core-ktx:1.2.0"
74+
implementation 'androidx.appcompat:appcompat:1.3.0-alpha01'
75+
implementation 'androidx.activity:activity-ktx:1.1.0'
76+
implementation 'androidx.core:core-ktx:1.5.0-alpha01'
77+
78+
implementation "androidx.ui:ui-livedata:$compose_version"
79+
80+
implementation "androidx.lifecycle:lifecycle-viewmodel-savedstate:2.3.0-alpha05"
7381

74-
androidTestImplementation("junit:junit:4.13")
75-
androidTestImplementation("androidx.test:rules:1.2.0")
76-
androidTestImplementation("androidx.test:runner:1.2.0")
77-
androidTestImplementation("androidx.ui:ui-core:$compose_version")
78-
androidTestImplementation("androidx.ui:ui-test:$compose_version")
82+
androidTestImplementation 'junit:junit:4.13'
83+
androidTestImplementation 'androidx.test:rules:1.2.0'
84+
androidTestImplementation 'androidx.test:runner:1.2.0'
85+
androidTestImplementation "androidx.ui:ui-core:$compose_version"
86+
androidTestImplementation "androidx.ui:ui-test:$compose_version"
7987

80-
ktlint "com.pinterest:ktlint:0.36.0"
88+
ktlint 'com.pinterest:ktlint:0.37.0'
8189
}
8290

83-
task ktlint(type: JavaExec, group: "verification") {
84-
description = "Check Kotlin code style."
85-
main = "com.pinterest.ktlint.Main"
91+
task ktlint(type: JavaExec, group: 'verification') {
92+
description = 'Check Kotlin code style.'
93+
main = 'com.pinterest.ktlint.Main'
8694
classpath = configurations.ktlint
87-
args "src/**/*.kt"
95+
args 'src/**/*.kt'
8896
}
8997

9098
check.dependsOn ktlint
9199

92-
task ktlintFormat(type: JavaExec, group: "formatting") {
93-
description = "Fix Kotlin code style deviations."
94-
main = "com.pinterest.ktlint.Main"
100+
task ktlintFormat(type: JavaExec, group: 'formatting') {
101+
description = 'Fix Kotlin code style deviations.'
102+
main = 'com.pinterest.ktlint.Main'
95103
classpath = configurations.ktlint
96-
args "-F", "src/**/*.kt"
104+
args '-F', 'src/**/*.kt'
97105
}

JetNews/app/src/androidTest/java/com/example/jetnews/TestHelper.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ package com.example.jetnews
1818

1919
import android.content.Context
2020
import androidx.compose.Composable
21+
import androidx.compose.remember
22+
import androidx.lifecycle.SavedStateHandle
2123
import androidx.ui.material.MaterialTheme
2224
import androidx.ui.material.Surface
2325
import androidx.ui.test.ComposeTestRule
@@ -26,23 +28,25 @@ import androidx.ui.test.findAll
2628
import androidx.ui.test.hasSubstring
2729
import com.example.jetnews.ui.JetnewsApp
2830
import com.example.jetnews.ui.JetnewsStatus
29-
import com.example.jetnews.ui.Screen
31+
import com.example.jetnews.ui.NavigationViewModel
3032

3133
/**
3234
* Launches the app from a test context
3335
*/
3436
fun ComposeTestRule.launchJetNewsApp(context: Context) {
3537
setContent {
3638
JetnewsStatus.resetState()
37-
JetnewsApp(TestAppContainer(context))
39+
JetnewsApp(
40+
TestAppContainer(context),
41+
remember { NavigationViewModel(SavedStateHandle()) }
42+
)
3843
}
3944
}
4045

4146
/**
4247
* Resets the state of the app. Needs to be executed in Compose code (within a frame)
4348
*/
4449
fun JetnewsStatus.resetState() {
45-
currentScreen = Screen.Home
4650
favorites.clear()
4751
selectedTopics.clear()
4852
}

JetNews/app/src/main/java/com/example/jetnews/data/posts/impl/FakePostsRepository.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,11 @@ class FakePostsRepository(
5656
override fun getPost(postId: String, callback: (Result<Post?>) -> Unit) {
5757
executeInBackground(callback) {
5858
resultThreadHandler.post {
59-
callback(Result.Success(
60-
postsWithResources.find { it.id == postId }
61-
))
59+
callback(
60+
Result.Success(
61+
postsWithResources.find { it.id == postId }
62+
)
63+
)
6264
}
6365
}
6466
}

JetNews/app/src/main/java/com/example/jetnews/data/posts/impl/PostsData.kt

Lines changed: 47 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,12 @@ val paragraphsPost1 = listOf(
5959
"These modules are included in the settings.gradle file as:"
6060
),
6161
Paragraph(
62-
ParagraphType.CodeBlock, "include ':app'\n" +
63-
"include ':features:module1'\n" +
64-
"include ':features:module2'\n" +
65-
"include ':features:module3'\n" +
66-
"include ':features:module4'"
62+
ParagraphType.CodeBlock,
63+
"include ':app'\n" +
64+
"include ':features:module1'\n" +
65+
"include ':features:module2'\n" +
66+
"include ':features:module3'\n" +
67+
"include ':features:module4'"
6768
),
6869
Paragraph(
6970
ParagraphType.Text,
@@ -96,20 +97,25 @@ val paragraphsPost1 = listOf(
9697
listOf(Markup(MarkupType.Code, 28, 43))
9798
),
9899
Paragraph(
99-
ParagraphType.CodeBlock, "include ':app'\n" +
100-
"include ':module1'\n" +
101-
"include ':module1'\n" +
102-
"include ':module1'\n" +
103-
"include ':module1'"
100+
ParagraphType.CodeBlock,
101+
"""
102+
include ':app'
103+
include ':module1'
104+
include ':module1'
105+
include ':module1'
106+
include ':module1'
107+
""".trimIndent()
104108
),
105109
Paragraph(
106110
ParagraphType.CodeBlock,
107-
"// Set a custom path for the four features modules.\n" +
108-
"// This avoid to have an empty \"features\" module in Android Studio.\n" +
109-
"project(\":module1\").projectDir=new File(rootDir, \"features/module1\")\n" +
110-
"project(\":module2\").projectDir=new File(rootDir, \"features/module2\")\n" +
111-
"project(\":module3\").projectDir=new File(rootDir, \"features/module3\")\n" +
112-
"project(\":module4\").projectDir=new File(rootDir, \"features/module4\")"
111+
"""
112+
// Set a custom path for the four features modules.
113+
// This avoid to have an empty "features" module in Android Studio.
114+
project(":module1").projectDir=new File(rootDir, "features/module1")
115+
project(":module2").projectDir=new File(rootDir, "features/module2")
116+
project(":module3").projectDir=new File(rootDir, "features/module3")
117+
project(":module4").projectDir=new File(rootDir, "features/module4")
118+
""".trimIndent()
113119
),
114120
Paragraph(
115121
ParagraphType.Text,
@@ -311,8 +317,10 @@ val paragraphsPost2 = listOf(
311317
),
312318
Paragraph(
313319
ParagraphType.CodeBlock,
314-
"@Inject @MinimumBalance lateinit var minimumBalance: BigDecimal \n" +
315-
"// @MinimumBalance is ignored!",
320+
"""
321+
@Inject @MinimumBalance lateinit var minimumBalance: BigDecimal
322+
// @MinimumBalance is ignored!
323+
""".trimIndent(),
316324
listOf(Markup(MarkupType.Bold, 65, 95))
317325
),
318326
Paragraph(
@@ -400,11 +408,13 @@ val paragraphsPost2 = listOf(
400408
),
401409
Paragraph(
402410
ParagraphType.CodeBlock,
403-
"class MyVMFactory @Inject constructor(\n" +
404-
" private val vmMap: Map<String, @JvmSuppressWildcards Provider<ViewModel>>\n" +
405-
") { \n" +
406-
" ... \n" +
407-
"}",
411+
"""
412+
class MyVMFactory @Inject constructor(
413+
private val vmMap: Map<String, @JvmSuppressWildcards Provider<ViewModel>>
414+
) {
415+
...
416+
}
417+
""".trimIndent(),
408418
listOf(Markup(MarkupType.Bold, 72, 93))
409419
),
410420
Paragraph(
@@ -692,8 +702,8 @@ val paragraphsPost5 = listOf(
692702
Paragraph(
693703
ParagraphType.CodeBlock,
694704
"public inline fun <T, R> Iterable<T>.map(transform: (T) -> R): List<R> {\n" +
695-
" return mapTo(ArrayList<R>(collectionSizeOrDefault(10)), transform)\n" +
696-
"}",
705+
" return mapTo(ArrayList<R>(collectionSizeOrDefault(10)), transform)\n" +
706+
"}",
697707
listOf(
698708
Markup(MarkupType.Bold, 7, 13),
699709
Markup(MarkupType.Bold, 88, 97)
@@ -737,8 +747,8 @@ val paragraphsPost5 = listOf(
737747
Paragraph(
738748
ParagraphType.CodeBlock,
739749
"public fun <T, R> Sequence<T>.map(transform: (T) -> R): Sequence<R>{ \n" +
740-
" return TransformingSequence(this, transform)\n" +
741-
"}",
750+
" return TransformingSequence(this, transform)\n" +
751+
"}",
742752
listOf(Markup(MarkupType.Bold, 85, 105))
743753
),
744754
Paragraph(
@@ -757,9 +767,9 @@ val paragraphsPost5 = listOf(
757767
Paragraph(
758768
ParagraphType.CodeBlock,
759769
"public inline fun <T> Sequence<T>.first(predicate: (T) -> Boolean): T {\n" +
760-
" for (element in this) if (predicate(element)) return element\n" +
761-
" throw NoSuchElementException(“Sequence contains no element matching the predicate.”)\n" +
762-
"}"
770+
" for (element in this) if (predicate(element)) return element\n" +
771+
" throw NoSuchElementException(“Sequence contains no element matching the predicate.”)\n" +
772+
"}"
763773
),
764774
Paragraph(
765775
ParagraphType.Text,
@@ -772,7 +782,7 @@ val paragraphsPost5 = listOf(
772782
Paragraph(
773783
ParagraphType.CodeBlock,
774784
"internal class TransformingIndexedSequence<T, R> \n" +
775-
"constructor(private val sequence: Sequence<T>, private val transformer: (Int, T) -> R) : Sequence<R> {",
785+
"constructor(private val sequence: Sequence<T>, private val transformer: (Int, T) -> R) : Sequence<R> {",
776786
listOf(
777787
Markup(
778788
MarkupType.Bold,
@@ -784,12 +794,12 @@ val paragraphsPost5 = listOf(
784794
Paragraph(
785795
ParagraphType.CodeBlock,
786796
"override fun iterator(): Iterator<R> = object : Iterator<R> {\n" +
787-
"\n" +
788-
" override fun next(): R {\n" +
789-
" return transformer(checkIndexOverflow(index++), iterator.next())\n" +
790-
" }\n" +
791-
"\n" +
792-
"}",
797+
"\n" +
798+
" override fun next(): R {\n" +
799+
" return transformer(checkIndexOverflow(index++), iterator.next())\n" +
800+
" }\n" +
801+
"\n" +
802+
"}",
793803
listOf(
794804
Markup(MarkupType.Bold, 83, 89),
795805
Markup(MarkupType.Bold, 107, 118)

0 commit comments

Comments
 (0)