Skip to content

Commit 71084de

Browse files
committedJun 15, 2020
[Jetsnack] Implement homescreen
Change-Id: I24360d64f4b60e57046c814f22e4ca12b540d679
1 parent 54eb1c0 commit 71084de

25 files changed

+1310
-58
lines changed
 

‎Jetsnack/ASSETS_LICENSE

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
All font files are licensed under the SIL OPEN FONT LICENSE license. All other files are licensed under the Apache 2 license.
2+
3+
4+
SIL OPEN FONT LICENSE
5+
Version 1.1 - 26 February 2007
6+
7+
PREAMBLE
8+
The goals of the Open Font License (OFL) are to stimulate worldwide
9+
development of collaborative font projects, to support the font creation
10+
efforts of academic and linguistic communities, and to provide a free and
11+
open framework in which fonts may be shared and improved in partnership
12+
with others.
13+
14+
The OFL allows the licensed fonts to be used, studied, modified and
15+
redistributed freely as long as they are not sold by themselves. The
16+
fonts, including any derivative works, can be bundled, embedded,
17+
redistributed and/or sold with any software provided that any reserved
18+
names are not used by derivative works. The fonts and derivatives,
19+
however, cannot be released under any other type of license. The
20+
requirement for fonts to remain under this license does not apply
21+
to any document created using the fonts or their derivatives.
22+
23+
DEFINITIONS
24+
"Font Software" refers to the set of files released by the Copyright
25+
Holder(s) under this license and clearly marked as such. This may
26+
include source files, build scripts and documentation.
27+
28+
"Reserved Font Name" refers to any names specified as such after the
29+
copyright statement(s).
30+
31+
"Original Version" refers to the collection of Font Software components as
32+
distributed by the Copyright Holder(s).
33+
34+
"Modified Version" refers to any derivative made by adding to, deleting,
35+
or substituting — in part or in whole — any of the components of the
36+
Original Version, by changing formats or by porting the Font Software to a
37+
new environment.
38+
39+
"Author" refers to any designer, engineer, programmer, technical
40+
writer or other person who contributed to the Font Software.
41+
42+
PERMISSION & CONDITIONS
43+
Permission is hereby granted, free of charge, to any person obtaining
44+
a copy of the Font Software, to use, study, copy, merge, embed, modify,
45+
redistribute, and sell modified and unmodified copies of the Font
46+
Software, subject to the following conditions:
47+
48+
1) Neither the Font Software nor any of its individual components,
49+
in Original or Modified Versions, may be sold by itself.
50+
51+
2) Original or Modified Versions of the Font Software may be bundled,
52+
redistributed and/or sold with any software, provided that each copy
53+
contains the above copyright notice and this license. These can be
54+
included either as stand-alone text files, human-readable headers or
55+
in the appropriate machine-readable metadata fields within text or
56+
binary files as long as those fields can be easily viewed by the user.
57+
58+
3) No Modified Version of the Font Software may use the Reserved Font
59+
Name(s) unless explicit written permission is granted by the corresponding
60+
Copyright Holder. This restriction only applies to the primary font name as
61+
presented to the users.
62+
63+
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
64+
Software shall not be used to promote, endorse or advertise any
65+
Modified Version, except to acknowledge the contribution(s) of the
66+
Copyright Holder(s) and the Author(s) or with their explicit written
67+
permission.
68+
69+
5) The Font Software, modified or unmodified, in part or in whole,
70+
must be distributed entirely under this license, and must not be
71+
distributed under any other license. The requirement for fonts to
72+
remain under this license does not apply to any document created
73+
using the Font Software.
74+
75+
TERMINATION
76+
This license becomes null and void if any of the above conditions are
77+
not met.
78+
79+
DISCLAIMER
80+
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
81+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
82+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
83+
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
84+
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
85+
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
86+
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
87+
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
88+
OTHER DEALINGS IN THE FONT SOFTWARE.

‎Jetsnack/app/build.gradle

+22-22
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,12 @@ android {
2323
compileSdkVersion 29
2424

2525
defaultConfig {
26-
applicationId "com.example.jetsnack"
26+
applicationId 'com.example.jetsnack'
2727
minSdkVersion 21
2828
targetSdkVersion 29
2929
versionCode 1
30-
versionName "1.0"
31-
32-
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
30+
versionName '1.0'
31+
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
3332
}
3433

3534
buildTypes {
@@ -45,8 +44,8 @@ android {
4544
}
4645

4746
kotlinOptions {
48-
jvmTarget = "1.8"
49-
apiVersion = "1.3"
47+
jvmTarget = '1.8'
48+
apiVersion = '1.3'
5049
allWarningsAsErrors = true
5150
}
5251

@@ -55,7 +54,7 @@ android {
5554
}
5655

5756
composeOptions {
58-
kotlinCompilerVersion "1.3.70-dev-withExperimentalGoogleExtensions-20200424"
57+
kotlinCompilerVersion '1.3.70-dev-withExperimentalGoogleExtensions-20200424'
5958
kotlinCompilerExtensionVersion compose_version
6059
}
6160
}
@@ -66,29 +65,30 @@ configurations {
6665

6766
dependencies {
6867
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
69-
implementation('androidx.core:core-ktx:1.1.0') // don't update yet b/152023266
70-
implementation 'androidx.appcompat:appcompat:1.1.0'
71-
72-
implementation("androidx.ui:ui-core:$compose_version")
73-
implementation("androidx.ui:ui-layout:$compose_version")
74-
implementation("androidx.ui:ui-material:$compose_version")
75-
implementation("androidx.ui:ui-tooling:$compose_version")
76-
68+
implementation 'androidx.core:core-ktx:1.5.0-alpha01'
69+
implementation 'androidx.appcompat:appcompat:1.3.0-alpha01'
70+
def coilVersion = "0.1.6.ui-$snapshot-SNAPSHOT"
71+
implementation "dev.chrisbanes.accompanist:accompanist-coil:$coilVersion"
72+
implementation "androidx.ui:ui-core:$compose_version"
73+
implementation "androidx.ui:ui-layout:$compose_version"
74+
implementation "androidx.ui:ui-material:$compose_version"
75+
implementation "androidx.ui:ui-material-icons-extended:$compose_version"
76+
implementation "androidx.ui:ui-tooling:$compose_version"
7777
ktlint "com.pinterest:ktlint:0.37.0"
7878
}
7979

8080
task ktlint(type: JavaExec, group: "verification") {
81-
description = "Check Kotlin code style."
82-
main = "com.pinterest.ktlint.Main"
81+
description = 'Check Kotlin code style.'
82+
main = 'com.pinterest.ktlint.Main'
8383
classpath = configurations.ktlint
84-
args "src/**/*.kt"
84+
args 'src/**/*.kt'
8585
}
8686

8787
check.dependsOn ktlint
8888

89-
task ktlintFormat(type: JavaExec, group: "formatting") {
90-
description = "Fix Kotlin code style deviations."
91-
main = "com.pinterest.ktlint.Main"
89+
task ktlintFormat(type: JavaExec, group: 'formatting') {
90+
description = 'Fix Kotlin code style deviations.'
91+
main = 'com.pinterest.ktlint.Main'
9292
classpath = configurations.ktlint
93-
args "-F", "src/**/*.kt"
93+
args '-F', 'src/**/*.kt'
9494
}

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

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
1616
package="com.example.jetsnack">
1717

18+
<!--Load images from Unsplash-->
19+
<uses-permission android:name="android.permission.INTERNET" />
20+
1821
<application
1922
android:allowBackup="true"
2023
android:icon="@mipmap/ic_launcher"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright 2020 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.example.jetsnack.model
18+
19+
import androidx.compose.Stable
20+
import androidx.compose.mutableStateOf
21+
22+
@Stable
23+
class Filter(
24+
val name: String,
25+
enabled: Boolean = false
26+
) {
27+
val enabled = mutableStateOf(enabled)
28+
}
29+
30+
val filters = listOf(
31+
Filter(name = "Organic"),
32+
Filter(name = "Gluten-free"),
33+
Filter(name = "Dairy-free"),
34+
Filter(name = "Sweet"),
35+
Filter(name = "Savory")
36+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright 2020 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.example.jetsnack.model
18+
19+
import androidx.compose.Immutable
20+
21+
@Immutable
22+
data class Snack(
23+
val id: Long,
24+
val name: String,
25+
val imageUrl: String,
26+
val tagline: String = "",
27+
val tags: Set<String> = emptySet()
28+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
/*
2+
* Copyright 2020 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.example.jetsnack.model
18+
19+
import androidx.compose.Immutable
20+
21+
@Immutable
22+
data class SnackCollection(
23+
val id: Long,
24+
val name: String,
25+
val snacks: List<Snack>,
26+
val type: CollectionType = CollectionType.Normal
27+
)
28+
29+
enum class CollectionType { Normal, Highlight }
30+
31+
/**
32+
* A fake repo
33+
*/
34+
object SnackRepo {
35+
fun getSnacks(): List<SnackCollection> = snackCollections
36+
}
37+
38+
/**
39+
* Static data
40+
*/
41+
42+
val snacks = listOf(
43+
Snack(
44+
id = 1L,
45+
name = "Cupcake",
46+
tagline = "A tag line",
47+
imageUrl = "https://source.unsplash.com/pGM4sjt_BdQ"
48+
),
49+
Snack(
50+
id = 2L,
51+
name = "Donut",
52+
tagline = "A tag line",
53+
imageUrl = "https://source.unsplash.com/Yc5sL-ejk6U"
54+
),
55+
Snack(
56+
id = 3L,
57+
name = "Eclair",
58+
tagline = "A tag line",
59+
imageUrl = "https://source.unsplash.com/-LojFX9NfPY"
60+
),
61+
Snack(
62+
id = 4L,
63+
name = "Froyo",
64+
tagline = "A tag line",
65+
imageUrl = "https://source.unsplash.com/3U2V5WqK1PQ"
66+
),
67+
Snack(
68+
id = 5L,
69+
name = "Gingerbread",
70+
tagline = "A tag line",
71+
imageUrl = "https://source.unsplash.com/Y4YR9OjdIMk"
72+
),
73+
Snack(
74+
id = 6L,
75+
name = "Honeycomb",
76+
tagline = "A tag line",
77+
imageUrl = "https://source.unsplash.com/bELvIg_KZGU"
78+
),
79+
Snack(
80+
id = 7L,
81+
name = "Ice Cream Sandwich",
82+
tagline = "A tag line",
83+
imageUrl = "https://source.unsplash.com/AqorcpZIKnU"
84+
),
85+
Snack(
86+
id = 8L,
87+
name = "Jellybean",
88+
tagline = "A tag line",
89+
imageUrl = "https://source.unsplash.com/0u_vbeOkMpk"
90+
),
91+
Snack(
92+
id = 9L,
93+
name = "KitKat",
94+
tagline = "A tag line",
95+
imageUrl = "https://source.unsplash.com/yb16pT5F_jE"
96+
),
97+
Snack(
98+
id = 10L,
99+
name = "Lollipop",
100+
tagline = "A tag line",
101+
imageUrl = "https://source.unsplash.com/AHF_ZktTL6Q"
102+
),
103+
Snack(
104+
id = 11L,
105+
name = "Marshmallow",
106+
tagline = "A tag line",
107+
imageUrl = "https://source.unsplash.com/rqFm0IgMVYY"
108+
),
109+
Snack(
110+
id = 12L,
111+
name = "Nougat",
112+
tagline = "A tag line",
113+
imageUrl = "https://source.unsplash.com/qRE_OpbVPR8"
114+
),
115+
Snack(
116+
id = 13L,
117+
name = "Oreo",
118+
tagline = "A tag line",
119+
imageUrl = "https://source.unsplash.com/33fWPnyN6tU"
120+
),
121+
Snack(
122+
id = 14L,
123+
name = "Pie",
124+
tagline = "A tag line",
125+
imageUrl = "https://source.unsplash.com/aX_ljOOyWJY"
126+
),
127+
Snack(
128+
id = 15L,
129+
name = "Chips",
130+
imageUrl = "https://source.unsplash.com/UsSdMZ78Q3E"
131+
),
132+
Snack(
133+
id = 16L,
134+
name = "Pretzels",
135+
imageUrl = "https://source.unsplash.com/7meCnGCJ5Ms"
136+
),
137+
Snack(
138+
id = 17L,
139+
name = "Smoothies",
140+
imageUrl = "https://source.unsplash.com/m741tj4Cz7M"
141+
),
142+
Snack(
143+
id = 18L,
144+
name = "Popcorn",
145+
imageUrl = "https://source.unsplash.com/iuwMdNq0-s4"
146+
),
147+
Snack(
148+
id = 19L,
149+
name = "Almonds",
150+
imageUrl = "https://source.unsplash.com/qgWWQU1SzqM"
151+
),
152+
Snack(
153+
id = 20L,
154+
name = "Cheese",
155+
imageUrl = "https://source.unsplash.com/9MzCd76xLGk"
156+
)
157+
)
158+
159+
val tastyTreats = SnackCollection(
160+
id = 1L,
161+
name = "Android's picks",
162+
type = CollectionType.Highlight,
163+
snacks = snacks.subList(0, 13)
164+
)
165+
166+
val popular = SnackCollection(
167+
id = 2L,
168+
name = "Popular on Jetsnack",
169+
snacks = snacks.subList(14, 19)
170+
)
171+
172+
val wfhFavs = tastyTreats.copy(
173+
id = 3L,
174+
name = "WFH favourites"
175+
)
176+
177+
val newlyAdded = popular.copy(
178+
id = 4L,
179+
name = "Newly Added"
180+
)
181+
182+
val exclusive = tastyTreats.copy(
183+
id = 5L,
184+
name = "Only on Jetsnack"
185+
)
186+
187+
val snackCollections = listOf(
188+
tastyTreats,
189+
popular,
190+
wfhFavs,
191+
newlyAdded,
192+
exclusive
193+
)

‎Jetsnack/app/src/main/java/com/example/jetsnack/ui/JetsnackApp.kt

+7-4
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,15 @@
1717
package com.example.jetsnack.ui
1818

1919
import androidx.compose.Composable
20-
import androidx.ui.foundation.Text
21-
import com.example.jetsnack.ui.theme.AppTheme
20+
import com.example.jetsnack.ui.home.Home
21+
import com.example.jetsnack.ui.theme.JetsnackTheme
22+
import com.example.jetsnack.ui.utils.ProvideInsets
2223

2324
@Composable
2425
fun JetsnackApp() {
25-
AppTheme {
26-
Text(text = "Jetsnack!")
26+
ProvideInsets {
27+
JetsnackTheme {
28+
Home(onSnackClick = { /* todo */ })
29+
}
2730
}
2831
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright 2020 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.example.jetsnack.ui.components
18+
19+
import androidx.ui.core.Modifier
20+
import androidx.ui.foundation.drawBackground
21+
import androidx.ui.foundation.drawBorder
22+
import androidx.ui.graphics.Color
23+
import androidx.ui.graphics.HorizontalGradient
24+
import androidx.ui.graphics.LinearGradient
25+
import androidx.ui.graphics.Shape
26+
import androidx.ui.graphics.TileMode
27+
import androidx.ui.unit.dp
28+
29+
fun Modifier.gradientBackground(
30+
colors: List<Color>,
31+
width: Float,
32+
offset: Float
33+
) = drawBackground(
34+
HorizontalGradient(
35+
colors,
36+
startX = -offset,
37+
endX = width - offset,
38+
tileMode = TileMode.Mirror
39+
)
40+
)
41+
42+
fun Modifier.gradientBorder(
43+
colors: List<Color>,
44+
shape: Shape
45+
) = drawBorder(
46+
size = 2.dp,
47+
shape = shape,
48+
brush = LinearGradient(
49+
colors = colors,
50+
startX = 0f,
51+
startY = 0f,
52+
endX = 111f,
53+
endY = 59f
54+
)
55+
)

‎Jetsnack/app/src/main/java/com/example/jetsnack/ui/home/Home.kt

+474
Large diffs are not rendered by default.

‎Jetsnack/app/src/main/java/com/example/jetsnack/ui/theme/Color.kt

+63-4
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,68 @@
1616

1717
package com.example.jetsnack.ui.theme
1818

19+
import androidx.compose.Composable
1920
import androidx.ui.graphics.Color
21+
import androidx.ui.graphics.compositeOver
22+
import androidx.ui.material.ColorPalette
2023

21-
val Purple200 = Color(0xFFBB86FC)
22-
val Purple500 = Color(0xFF6200EE)
23-
val Purple700 = Color(0xFF3700B3)
24-
val Teal200 = Color(0xFF03DAC5)
24+
val Shadow11 = Color(0xff001787)
25+
val Shadow10 = Color(0xff00119e)
26+
val Shadow9 = Color(0xff0009b3)
27+
val Shadow8 = Color(0xff0200c7)
28+
val Shadow7 = Color(0xff0e00d7)
29+
val Shadow6 = Color(0xff2a13e4)
30+
val Shadow5 = Color(0xff4b30ed)
31+
val Shadow4 = Color(0xff7057f5)
32+
val Shadow3 = Color(0xff9b86fa)
33+
val Shadow2 = Color(0xffc8bbfd)
34+
val Shadow1 = Color(0xffded6fe)
35+
val Shadow0 = Color(0xfff4f2ff)
36+
37+
val Ocean11 = Color(0xff005687)
38+
val Ocean10 = Color(0xff006d9e)
39+
val Ocean9 = Color(0xff0087b3)
40+
val Ocean8 = Color(0xff00a1c7)
41+
val Ocean7 = Color(0xff00b9d7)
42+
val Ocean6 = Color(0xff13d0e4)
43+
val Ocean5 = Color(0xff30e2ed)
44+
val Ocean4 = Color(0xff57eff5)
45+
val Ocean3 = Color(0xff86f7fa)
46+
val Ocean2 = Color(0xffbbfdfd)
47+
val Ocean1 = Color(0xffd6fefe)
48+
val Ocean0 = Color(0xfff2ffff)
49+
50+
val Lavender11 = Color(0xff170085)
51+
val Lavender10 = Color(0xff23009e)
52+
val Lavender9 = Color(0xff3300b3)
53+
val Lavender8 = Color(0xff4400c7)
54+
val Lavender7 = Color(0xff5500d7)
55+
val Lavender6 = Color(0xff6f13e4)
56+
val Lavender5 = Color(0xff8a30ed)
57+
val Lavender4 = Color(0xffa557f5)
58+
val Lavender3 = Color(0xffc186fa)
59+
val Lavender2 = Color(0xffdebbfd)
60+
val Lavender1 = Color(0xffebd6fe)
61+
val Lavender0 = Color(0xfff9f2ff)
62+
63+
val Rose11 = Color(0xff7f0054)
64+
val Rose10 = Color(0xff97005c)
65+
val Rose9 = Color(0xffaf0060)
66+
val Rose8 = Color(0xffc30060)
67+
val Rose7 = Color(0xffd4005d)
68+
val Rose6 = Color(0xffe21365)
69+
val Rose5 = Color(0xffec3074)
70+
val Rose4 = Color(0xfff4568b)
71+
val Rose3 = Color(0xfff985aa)
72+
val Rose2 = Color(0xfffdbbcf)
73+
val Rose1 = Color(0xfffed6e2)
74+
val Rose0 = Color(0xfffff2f6)
75+
76+
/**
77+
* Return the fully opaque color that results from compositing [onSurface] atop [surface] with the
78+
* given [alpha]. Useful for situations where semi-transparent colors are undesirable.
79+
*/
80+
@Composable
81+
fun ColorPalette.compositedOnSurface(alpha: Float): Color {
82+
return onSurface.copy(alpha = alpha).compositeOver(surface)
83+
}

‎Jetsnack/app/src/main/java/com/example/jetsnack/ui/theme/Shape.kt

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414
* limitations under the License.
1515
*/
1616

17-
package com.example.compose.jetchat.theme
17+
package com.example.jetsnack.ui.theme
1818

1919
import androidx.ui.foundation.shape.corner.RoundedCornerShape
2020
import androidx.ui.material.Shapes
2121
import androidx.ui.unit.dp
2222

23-
val JetchatShapes = Shapes(
24-
small = RoundedCornerShape(28.dp),
25-
medium = RoundedCornerShape(8.dp),
23+
val Shapes = Shapes(
24+
small = RoundedCornerShape(percent = 50),
25+
medium = RoundedCornerShape(20.dp),
2626
large = RoundedCornerShape(0.dp)
2727
)

‎Jetsnack/app/src/main/java/com/example/jetsnack/ui/theme/Theme.kt

+91-15
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,51 @@
1717
package com.example.jetsnack.ui.theme
1818

1919
import androidx.compose.Composable
20+
import androidx.compose.Providers
21+
import androidx.compose.Stable
22+
import androidx.compose.StructurallyEqual
23+
import androidx.compose.getValue
24+
import androidx.compose.mutableStateOf
25+
import androidx.compose.remember
26+
import androidx.compose.setValue
27+
import androidx.compose.staticAmbientOf
2028
import androidx.ui.foundation.isSystemInDarkTheme
29+
import androidx.ui.graphics.Color
30+
import androidx.ui.material.ColorPalette
2131
import androidx.ui.material.MaterialTheme
2232
import androidx.ui.material.darkColorPalette
2333
import androidx.ui.material.lightColorPalette
2434

25-
private val DarkColorPalette = darkColorPalette(
26-
primary = Purple200,
27-
primaryVariant = Purple700,
28-
secondary = Teal200
35+
private val LightColorPalette = JetsnackColorPalette(
36+
gradient1 = listOf(Shadow2, Ocean3, Shadow4),
37+
gradient2 = listOf(Shadow4, Ocean3, Shadow2),
38+
gradient3 = listOf(Rose4, Lavender3, Rose2),
39+
gradient4 = listOf(Rose2, Lavender3, Rose4),
40+
materialPalette = lightColorPalette(
41+
primary = Shadow5,
42+
primaryVariant = Shadow5,
43+
secondary = Ocean3,
44+
error = Color(0xffd00036)
45+
)
2946
)
3047

31-
private val LightColorPalette = lightColorPalette(
32-
primary = Purple500,
33-
primaryVariant = Purple700,
34-
secondary = Teal200
48+
private val DarkColorPalette = JetsnackColorPalette(
49+
gradient1 = listOf(Shadow5, Ocean7, Shadow9),
50+
gradient2 = listOf(Shadow9, Ocean7, Shadow5),
51+
gradient3 = listOf(Rose11, Lavender7, Rose8),
52+
gradient4 = listOf(Rose8, Lavender7, Rose11),
53+
materialPalette = darkColorPalette(
54+
primary = Shadow1,
55+
primaryVariant = Shadow1,
56+
secondary = Ocean7,
57+
background = Color.Black,
58+
surface = Color.Black,
59+
error = Color(0xffea6d7e)
60+
)
3561
)
3662

3763
@Composable
38-
fun AppTheme(
64+
fun JetsnackTheme(
3965
darkTheme: Boolean = isSystemInDarkTheme(),
4066
content: @Composable () -> Unit
4167
) {
@@ -45,10 +71,60 @@ fun AppTheme(
4571
LightColorPalette
4672
}
4773

48-
MaterialTheme(
49-
colors = colors,
50-
typography = typography,
51-
shapes = Shapes,
52-
content = content
53-
)
74+
ProvideJetsnackColors(colors) {
75+
MaterialTheme(
76+
colors = colors,
77+
typography = Typography,
78+
shapes = Shapes,
79+
content = content
80+
)
81+
}
82+
}
83+
84+
object JetsnackTheme {
85+
@Composable
86+
val colors: JetsnackColorPalette
87+
get() = JetsnackColorAmbient.current
88+
}
89+
90+
/**
91+
* "Extend" Material [ColorPalette] with our own theme colors.
92+
*/
93+
@Stable
94+
class JetsnackColorPalette(
95+
gradient1: List<Color>,
96+
gradient2: List<Color>,
97+
gradient3: List<Color>,
98+
gradient4: List<Color>,
99+
materialPalette: ColorPalette
100+
) : ColorPalette by materialPalette {
101+
var gradient1 by mutableStateOf(gradient1, StructurallyEqual)
102+
private set
103+
var gradient2 by mutableStateOf(gradient2, StructurallyEqual)
104+
private set
105+
var gradient3 by mutableStateOf(gradient3, StructurallyEqual)
106+
private set
107+
var gradient4 by mutableStateOf(gradient4, StructurallyEqual)
108+
private set
109+
110+
fun update(other: JetsnackColorPalette) {
111+
gradient1 = other.gradient1
112+
gradient2 = other.gradient2
113+
gradient3 = other.gradient3
114+
gradient4 = other.gradient4
115+
}
116+
}
117+
118+
@Composable
119+
fun ProvideJetsnackColors(
120+
colors: JetsnackColorPalette,
121+
content: @Composable () -> Unit
122+
) {
123+
val colorPalette = remember { colors }
124+
colorPalette.update(colors)
125+
Providers(JetsnackColorAmbient provides colorPalette, children = content)
126+
}
127+
128+
private val JetsnackColorAmbient = staticAmbientOf<JetsnackColorPalette> {
129+
error("No JetsnackColorPalette provided")
54130
}

‎Jetsnack/app/src/main/java/com/example/jetsnack/ui/theme/Type.kt

+100-4
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,110 @@ package com.example.jetsnack.ui.theme
1818

1919
import androidx.ui.material.Typography
2020
import androidx.ui.text.TextStyle
21-
import androidx.ui.text.font.FontFamily
2221
import androidx.ui.text.font.FontWeight
22+
import androidx.ui.text.font.font
23+
import androidx.ui.text.font.fontFamily
2324
import androidx.ui.unit.sp
25+
import com.example.jetsnack.R
2426

25-
val typography = Typography(
27+
private val Montserrat = fontFamily(
28+
font(R.font.montserrat_light, FontWeight.Light),
29+
font(R.font.montserrat_regular, FontWeight.Normal),
30+
font(R.font.montserrat_medium, FontWeight.Medium),
31+
font(R.font.montserrat_semibold, FontWeight.SemiBold)
32+
)
33+
34+
private val Karla = fontFamily(
35+
font(R.font.karla_regular, FontWeight.Normal),
36+
font(R.font.karla_bold, FontWeight.Bold)
37+
)
38+
39+
val Typography = Typography(
40+
h1 = TextStyle(
41+
fontFamily = Montserrat,
42+
fontSize = 96.sp,
43+
fontWeight = FontWeight.Light,
44+
lineHeight = 117.sp,
45+
letterSpacing = (-1.5).sp
46+
),
47+
h2 = TextStyle(
48+
fontFamily = Montserrat,
49+
fontSize = 60.sp,
50+
fontWeight = FontWeight.Light,
51+
lineHeight = 73.sp,
52+
letterSpacing = (-0.5).sp
53+
),
54+
h3 = TextStyle(
55+
fontFamily = Montserrat,
56+
fontSize = 48.sp,
57+
fontWeight = FontWeight.Normal,
58+
lineHeight = 59.sp
59+
),
60+
h4 = TextStyle(
61+
fontFamily = Montserrat,
62+
fontSize = 30.sp,
63+
fontWeight = FontWeight.SemiBold,
64+
lineHeight = 37.sp
65+
),
66+
h5 = TextStyle(
67+
fontFamily = Montserrat,
68+
fontSize = 24.sp,
69+
fontWeight = FontWeight.SemiBold,
70+
lineHeight = 29.sp
71+
),
72+
h6 = TextStyle(
73+
fontFamily = Montserrat,
74+
fontSize = 20.sp,
75+
fontWeight = FontWeight.SemiBold,
76+
lineHeight = 24.sp
77+
),
78+
subtitle1 = TextStyle(
79+
fontFamily = Montserrat,
80+
fontSize = 16.sp,
81+
fontWeight = FontWeight.SemiBold,
82+
lineHeight = 24.sp,
83+
letterSpacing = 0.15.sp
84+
),
85+
subtitle2 = TextStyle(
86+
fontFamily = Karla,
87+
fontSize = 14.sp,
88+
fontWeight = FontWeight.Bold,
89+
lineHeight = 24.sp,
90+
letterSpacing = 0.1.sp
91+
),
2692
body1 = TextStyle(
27-
fontFamily = FontFamily.Default,
93+
fontFamily = Karla,
94+
fontSize = 16.sp,
2895
fontWeight = FontWeight.Normal,
29-
fontSize = 16.sp
96+
lineHeight = 28.sp,
97+
letterSpacing = 0.15.sp
98+
),
99+
body2 = TextStyle(
100+
fontFamily = Montserrat,
101+
fontSize = 14.sp,
102+
fontWeight = FontWeight.Medium,
103+
lineHeight = 20.sp,
104+
letterSpacing = 0.25.sp
105+
),
106+
button = TextStyle(
107+
fontFamily = Montserrat,
108+
fontSize = 14.sp,
109+
fontWeight = FontWeight.SemiBold,
110+
lineHeight = 16.sp,
111+
letterSpacing = 1.25.sp
112+
),
113+
caption = TextStyle(
114+
fontFamily = Karla,
115+
fontSize = 12.sp,
116+
fontWeight = FontWeight.Bold,
117+
lineHeight = 16.sp,
118+
letterSpacing = 0.4.sp
119+
),
120+
overline = TextStyle(
121+
fontFamily = Montserrat,
122+
fontSize = 12.sp,
123+
fontWeight = FontWeight.SemiBold,
124+
lineHeight = 16.sp,
125+
letterSpacing = 1.sp
30126
)
31127
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
/*
2+
* Copyright 2020 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.example.jetsnack.ui.utils
18+
19+
import android.view.View
20+
import androidx.compose.Composable
21+
import androidx.compose.Immutable
22+
import androidx.compose.Providers
23+
import androidx.compose.getValue
24+
import androidx.compose.onActive
25+
import androidx.compose.onCommit
26+
import androidx.compose.setValue
27+
import androidx.compose.state
28+
import androidx.compose.staticAmbientOf
29+
import androidx.core.view.ViewCompat
30+
import androidx.core.view.WindowInsetsCompat
31+
import androidx.ui.core.DensityAmbient
32+
import androidx.ui.core.Modifier
33+
import androidx.ui.core.ViewAmbient
34+
import androidx.ui.core.composed
35+
import androidx.ui.layout.padding
36+
import androidx.ui.unit.Dp
37+
import androidx.ui.unit.dp
38+
39+
@Immutable
40+
data class Insets(
41+
val left: Dp = 0.dp,
42+
val top: Dp = 0.dp,
43+
val right: Dp = 0.dp,
44+
val bottom: Dp = 0.dp
45+
)
46+
47+
val InsetsAmbient = staticAmbientOf { Insets() }
48+
49+
@Composable
50+
fun ProvideInsets(
51+
setImmersiveFlags: Boolean = true,
52+
content: @Composable () -> Unit
53+
) {
54+
var currentInsets by state<WindowInsetsCompat?> { null }
55+
val view = ViewAmbient.current
56+
onCommit(setImmersiveFlags) {
57+
if (setImmersiveFlags) {
58+
// Set immersive flags to draw behind system bars
59+
view.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or
60+
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or
61+
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
62+
}
63+
}
64+
onActive {
65+
ViewCompat.setOnApplyWindowInsetsListener(view) { _, insets ->
66+
currentInsets = insets
67+
insets
68+
}
69+
view.requestApplyInsets()
70+
}
71+
72+
val current = currentInsets
73+
val insets = if (current != null) {
74+
with(DensityAmbient.current) {
75+
Insets(
76+
left = current.systemWindowInsetLeft.toDp(),
77+
top = current.systemWindowInsetTop.toDp(),
78+
right = current.systemWindowInsetRight.toDp(),
79+
bottom = current.systemWindowInsetBottom.toDp()
80+
)
81+
}
82+
} else {
83+
Insets()
84+
}
85+
86+
Providers(
87+
InsetsAmbient provides insets,
88+
children = content
89+
)
90+
}
91+
92+
fun Modifier.systemBarPadding() = systemBarPadding(
93+
start = true,
94+
top = true,
95+
end = true,
96+
bottom = true
97+
)
98+
99+
fun Modifier.systemBarPadding(
100+
horizontal: Boolean = false,
101+
vertical: Boolean = false
102+
) = systemBarPadding(
103+
start = horizontal,
104+
top = vertical,
105+
end = horizontal,
106+
bottom = vertical
107+
)
108+
109+
fun Modifier.systemBarPadding(
110+
start: Boolean = false,
111+
top: Boolean = false,
112+
end: Boolean = false,
113+
bottom: Boolean = false
114+
): Modifier = composed {
115+
val insets = InsetsAmbient.current
116+
padding(
117+
start = if (start) insets.left else 0.dp,
118+
top = if (top) insets.top else 0.dp,
119+
end = if (end) insets.right else 0.dp,
120+
bottom = if (bottom) insets.bottom else 0.dp
121+
)
122+
}
16.5 KB
Binary file not shown.
14.5 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
Copyright 2020 The Android Open Source Project
4+
5+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
6+
in compliance with the License. You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software distributed under the License
11+
is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12+
or implied. See the License for the specific language governing permissions and limitations under
13+
the License.
14+
-->
15+
<resources>
16+
<color name="immersive_sys_ui">#f2ffffff</color>
17+
</resources>

‎Jetsnack/app/src/main/res/values/colors.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313
the License.
1414
-->
1515
<resources>
16-
<color name="immersive_sys_ui">#33000000</color>
16+
<color name="immersive_sys_ui">#f2000000</color>
1717
<color name="nav_bar">@color/immersive_sys_ui</color>
1818
</resources>

‎Jetsnack/app/src/main/res/values/themes.xml

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<item name="colorAccent">#ff00ff</item>
2020
<item name="android:statusBarColor">@color/immersive_sys_ui</item>
2121
<item name="android:navigationBarColor">@color/nav_bar</item>
22+
<item name="android:windowLightStatusBar" tools:targetApi="m">?attr/isLightTheme</item>
2223
</style>
2324

2425
</resources>

‎Jetsnack/build.gradle

+3-2
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,22 @@
1717
buildscript {
1818
ext.kotlin_version = '1.3.72'
1919
ext.compose_version = '0.1.0-SNAPSHOT'
20+
ext.snapshot = '6581424'
2021
repositories {
2122
google()
2223
jcenter()
2324
}
2425
dependencies {
25-
classpath 'com.android.tools.build:gradle:4.1.0-alpha10'
26+
classpath 'com.android.tools.build:gradle:4.2.0-alpha01'
2627
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
2728
}
2829
}
2930

3031
allprojects {
3132
repositories {
32-
def snapshot = "6543212"
3333
maven { url "https://androidx.dev/snapshots/builds/$snapshot/artifacts/ui/repository" }
3434
google()
35+
maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
3536
jcenter()
3637
}
3738
// Don't require parens on fun type annotations e.g. `@Composable~()~ () -> Unit`. Remove with KT1.4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Tue Jun 09 11:14:49 BST 2020
1+
#Wed Jun 10 18:36:19 BST 2020
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-milestone-1-bin.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-rc-1-bin.zip

0 commit comments

Comments
 (0)
Please sign in to comment.