Skip to content
This repository was archived by the owner on Dec 27, 2024. It is now read-only.

Commit eee863b

Browse files
committed
ComposeMail - Clean up and build.gradle update
1 parent 1062369 commit eee863b

File tree

15 files changed

+114
-68
lines changed

15 files changed

+114
-68
lines changed

demoProjects/ComposeMail/app/build.gradle

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,24 @@ android {
3535
}
3636
}
3737

38+
signingConfigs {
39+
debug {
40+
// For Linux & mac:
41+
storeFile file(System.getenv("HOME") + '/.android/debug.keystore')
42+
// For Windows:
43+
// storeFile file('/Users/USERNAME/.android/debug.keystore')
44+
storePassword 'android'
45+
keyAlias 'androiddebugkey'
46+
keyPassword 'android'
47+
}
48+
}
49+
3850
buildTypes {
3951
release {
52+
// Prefer to use release build variant to run the app for better performance
4053
minifyEnabled false
4154
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
55+
signingConfig signingConfigs.debug
4256
}
4357
}
4458
compileOptions {
@@ -64,21 +78,21 @@ android {
6478
dependencies {
6579
implementation 'androidx.core:core-ktx:1.7.0'
6680

67-
implementation 'androidx.paging:paging-common:3.1.1'
68-
implementation 'androidx.paging:paging-common-ktx:3.1.1'
81+
implementation "androidx.paging:paging-common:$paging_version"
82+
implementation "androidx.paging:paging-common-ktx:$paging_version"
6983

70-
implementation 'androidx.compose.material3:material3-window-size-class:1.0.0-alpha10'
84+
implementation 'androidx.compose.material3:material3-window-size-class:1.0.0-alpha12'
7185

7286
implementation "androidx.compose.ui:ui:$compose_version"
7387
implementation "androidx.compose.material:material:$compose_version"
7488
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
7589
implementation "androidx.compose.material:material-icons-extended:$compose_version"
7690

77-
implementation "androidx.paging:paging-compose:1.0.0-alpha14"
91+
implementation "androidx.paging:paging-compose:$paging_compose_version"
7892

79-
// implementation "androidx.constraintlayout:constraintlayout-compose:1.0.0"
80-
implementation project(':core')
81-
implementation project(':compose')
93+
implementation "androidx.constraintlayout:constraintlayout-compose:1.1.0-alpha01"
94+
// implementation project(':core')
95+
// implementation project(':compose')
8296

8397
implementation 'androidx.lifecycle:lifecycle-viewmodel-compose:2.4.1'
8498

@@ -101,7 +115,6 @@ tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
101115
freeCompilerArgs += "-opt-in=androidx.compose.ui.ExperimentalComposeUiApi"
102116
freeCompilerArgs += "-opt-in=androidx.compose.material3.windowsizeclass.ExperimentalMaterial3WindowSizeClassApi"
103117

104-
105118
// For older than Kotlin 1.6.0
106119
// freeCompilerArgs += "-Xopt-in=androidx.constraintlayout.compose.ExperimentalMotionApi"
107120
// freeCompilerArgs += "-Xopt-in=androidx.compose.ui.ExperimentalComposeUiApi"

demoProjects/ComposeMail/app/src/main/java/com/example/composemail/MainActivity.kt

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,13 @@ import androidx.compose.material.MaterialTheme
2424
import androidx.compose.material.Surface
2525
import androidx.compose.material.Text
2626
import androidx.compose.material3.windowsizeclass.ExperimentalMaterial3WindowSizeClassApi
27-
import androidx.compose.material3.windowsizeclass.WindowHeightSizeClass
28-
import androidx.compose.material3.windowsizeclass.WindowWidthSizeClass
2927
import androidx.compose.material3.windowsizeclass.calculateWindowSizeClass
3028
import androidx.compose.runtime.Composable
3129
import androidx.compose.runtime.CompositionLocalProvider
32-
import androidx.compose.runtime.ProvidableCompositionLocal
33-
import androidx.compose.runtime.compositionLocalOf
3430
import androidx.compose.ui.Modifier
3531
import androidx.compose.ui.tooling.preview.Preview
32+
import com.example.composemail.ui.compositionlocal.LocalHeightSizeClass
33+
import com.example.composemail.ui.compositionlocal.LocalWidthSizeClass
3634
import com.example.composemail.ui.home.ComposeMailHome
3735
import com.example.composemail.ui.theme.ComposeMailTheme
3836

@@ -61,12 +59,6 @@ class MainActivity : ComponentActivity() {
6159
}
6260
}
6361

64-
val LocalHeightSizeClass: ProvidableCompositionLocal<WindowHeightSizeClass> =
65-
compositionLocalOf { WindowHeightSizeClass.Compact }
66-
67-
val LocalWidthSizeClass: ProvidableCompositionLocal<WindowWidthSizeClass> =
68-
compositionLocalOf { WindowWidthSizeClass.Compact }
69-
7062
@Composable
7163
fun Greeting(name: String) {
7264
Text(text = "Hello $name!")

demoProjects/ComposeMail/app/src/main/java/com/example/composemail/model/ComposeMailModel.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ class ComposeMailModel(application: Application) : AndroidViewModel(application)
5353
}.flow
5454

5555
fun openMail(id: Int) {
56-
// TODO: Support opening a conversation
56+
// TODO: Support opening a mail/thread
5757
}
5858

5959
fun closeMail() {
60-
60+
// TODO: Support opening a mail/thread
6161
}
6262
}

demoProjects/ComposeMail/app/src/main/java/com/example/composemail/model/repo/OfflineRepo.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ private val names = listOf(
5151
"Daniel",
5252
)
5353

54-
private val contentLines = LoremIpsum(200).values.first().split(" ")
54+
private val contentLines = LoremIpsum(100).values.first().filter { it != '\n' }.split(" ")
5555

5656
class OfflineRepository(
5757
private val resources: Resources

demoProjects/ComposeMail/app/src/main/java/com/example/composemail/ui/components/CheapText.kt

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,61 @@
1616

1717
package com.example.composemail.ui.components
1818

19+
import androidx.compose.foundation.background
20+
import androidx.compose.foundation.layout.Column
21+
import androidx.compose.foundation.layout.fillMaxSize
22+
import androidx.compose.foundation.layout.width
1923
import androidx.compose.material.LocalTextStyle
2024
import androidx.compose.material.Text
2125
import androidx.compose.runtime.Composable
2226
import androidx.compose.ui.Modifier
2327
import androidx.compose.ui.graphics.Color
2428
import androidx.compose.ui.text.TextStyle
29+
import androidx.compose.ui.text.style.TextOverflow
30+
import androidx.compose.ui.tooling.preview.Preview
31+
import androidx.compose.ui.unit.dp
2532

33+
/**
34+
* [Text] Composable constrained to one line for better animation performance.
35+
*/
2636
@Suppress("NOTHING_TO_INLINE")
2737
@Composable
2838
inline fun CheapText(
2939
text: String,
3040
modifier: Modifier = Modifier,
3141
color: Color = Color.Unspecified,
32-
style: TextStyle = LocalTextStyle.current
42+
style: TextStyle = LocalTextStyle.current,
43+
overflow: TextOverflow = TextOverflow.Clip
3344
) {
3445
Text(
3546
text = text,
3647
modifier = modifier,
3748
color = color,
3849
style = style,
3950
maxLines = 1,
40-
softWrap = false
51+
overflow = overflow,
4152
)
53+
}
54+
55+
@Preview
56+
@Composable
57+
private fun CheapTextPreview() {
58+
Column(Modifier.fillMaxSize()) {
59+
Text(text = "Normal")
60+
Column(
61+
Modifier
62+
.width(40.dp)
63+
.background(Color.LightGray)) {
64+
Text(text = "Hello \nWorld!")
65+
Text(text = "This is a very very long text")
66+
}
67+
Text(text = "Cheap")
68+
Column(
69+
Modifier
70+
.width(40.dp)
71+
.background(Color.LightGray)) {
72+
CheapText(text = "Hello \nWorld!")
73+
CheapText(text = "This is a very very long text")
74+
}
75+
}
4276
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright (C) 2022 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.composemail.ui.compositionlocal
18+
19+
import androidx.compose.material3.windowsizeclass.WindowHeightSizeClass
20+
import androidx.compose.material3.windowsizeclass.WindowWidthSizeClass
21+
import androidx.compose.runtime.ProvidableCompositionLocal
22+
import androidx.compose.runtime.compositionLocalOf
23+
24+
val LocalHeightSizeClass: ProvidableCompositionLocal<WindowHeightSizeClass> =
25+
compositionLocalOf { WindowHeightSizeClass.Compact }
26+
27+
val LocalWidthSizeClass: ProvidableCompositionLocal<WindowWidthSizeClass> =
28+
compositionLocalOf { WindowWidthSizeClass.Compact }

demoProjects/ComposeMail/app/src/main/java/com/example/composemail/ui/home/Home.kt

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ import androidx.compose.runtime.remember
3434
import androidx.compose.ui.Modifier
3535
import androidx.compose.ui.unit.dp
3636
import androidx.lifecycle.viewmodel.compose.viewModel
37-
import com.example.composemail.LocalWidthSizeClass
3837
import com.example.composemail.model.ComposeMailModel
38+
import com.example.composemail.ui.compositionlocal.LocalWidthSizeClass
3939
import com.example.composemail.ui.home.toptoolbar.TopToolbar
4040
import com.example.composemail.ui.mails.MailList
4141
import com.example.composemail.ui.mails.MailListState
@@ -44,7 +44,7 @@ import com.example.composemail.ui.newmail.NewMailLayoutState
4444
import com.example.composemail.ui.newmail.rememberNewMailState
4545

4646
@Composable
47-
fun ComposeMailHome(modifier: Modifier = Modifier) {
47+
fun ComposeMailHome() {
4848
val mailModel: ComposeMailModel = viewModel()
4949
val listState = remember { MailListState() }
5050
val newMailState = rememberNewMailState(initialLayoutState = NewMailLayoutState.Fab)
@@ -86,27 +86,15 @@ fun ComposeMailHome(modifier: Modifier = Modifier) {
8686
)
8787
}
8888
if (LocalWidthSizeClass.current != WindowWidthSizeClass.Compact) {
89+
// TODO: Use MotionLayout to transition between size changes
8990
OutlinedButton(
9091
modifier = Modifier
9192
.fillMaxHeight()
9293
.weight(1f),
9394
onClick = { /*TODO*/ }
9495
) {
95-
Text(text = "Hello World!")
96+
Text(text = "Not Yet Implemented")
9697
}
9798
}
9899
}
99-
}
100-
101-
102-
@Composable
103-
fun Home2(modifier: Modifier = Modifier) {
104-
when (LocalWidthSizeClass.current) {
105-
WindowWidthSizeClass.Expanded -> {
106-
107-
}
108-
else -> {
109-
110-
}
111-
}
112100
}

demoProjects/ComposeMail/app/src/main/java/com/example/composemail/ui/home/toptoolbar/SearchBar.kt

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,47 +33,29 @@ import androidx.compose.runtime.getValue
3333
import androidx.compose.runtime.mutableStateOf
3434
import androidx.compose.runtime.remember
3535
import androidx.compose.runtime.setValue
36-
import androidx.compose.ui.ExperimentalComposeUiApi
3736
import androidx.compose.ui.Modifier
3837
import androidx.compose.ui.draw.clip
39-
import androidx.compose.ui.focus.FocusRequester
40-
import androidx.compose.ui.focus.focusRequester
4138
import androidx.compose.ui.focus.onFocusChanged
4239
import androidx.compose.ui.graphics.Color
43-
import androidx.compose.ui.input.key.Key
44-
import androidx.compose.ui.input.key.key
45-
import androidx.compose.ui.input.key.onKeyEvent
4640
import androidx.compose.ui.tooling.preview.Preview
4741
import androidx.compose.ui.unit.dp
4842
import com.example.composemail.ui.theme.textBackgroundColor
4943

50-
@OptIn(ExperimentalComposeUiApi::class)
5144
@Composable
5245
fun SearchBar(
5346
modifier: Modifier = Modifier
5447
) {
5548
var placeholder: String by remember { mutableStateOf("Search in mails") }
56-
val focusRequester = remember { FocusRequester() }
5749
OutlinedTextField(
5850
modifier = modifier
5951
.clip(RoundedCornerShape(32.dp))
6052
.background(MaterialTheme.colors.textBackgroundColor)
61-
.focusRequester(focusRequester)
6253
.onFocusChanged {
6354
placeholder = if (it.isFocused) {
6455
"I'm not implemented yet!"
6556
} else {
6657
"Search in mails"
6758
}
68-
}
69-
.onKeyEvent {
70-
if (it.key == Key.Back) {
71-
// TODO: DOESN'T WORK
72-
focusRequester.freeFocus()
73-
true
74-
} else {
75-
false
76-
}
7759
},
7860

7961
value = "",

demoProjects/ComposeMail/app/src/main/java/com/example/composemail/ui/home/toptoolbar/TopToolbar.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ fun TopToolbar(
6868
} else {
6969
SearchToolbar(modifier = modifier.padding(4.dp))
7070
}
71-
7271
}
7372
}
7473

demoProjects/ComposeMail/app/src/main/java/com/example/composemail/ui/mails/MailItem.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ import androidx.constraintlayout.compose.MotionLayout
5555
import androidx.constraintlayout.compose.MotionScene
5656
import coil.compose.rememberImagePainter
5757
import com.example.composemail.model.data.MailEntryInfo
58+
import com.example.composemail.ui.components.CheapText
5859
import com.example.composemail.ui.theme.textBackgroundColor
5960

6061
@Composable
@@ -259,22 +260,20 @@ inline fun MailContent(
259260
verticalArrangement = Arrangement.SpaceBetween
260261
) {
261262
Row(horizontalArrangement = Arrangement.SpaceBetween) {
262-
Text(
263+
CheapText(
263264
modifier = Modifier.weight(1.0f, true),
264265
text = info.from.name,
265266
style = MaterialTheme.typography.body1,
266-
maxLines = 1,
267267
overflow = TextOverflow.Ellipsis
268268
)
269-
Text(
269+
CheapText(
270270
text = info.timestamp,
271271
style = MaterialTheme.typography.body2,
272272
)
273273
}
274-
Text(
274+
CheapText(
275275
text = info.shortContent,
276276
style = MaterialTheme.typography.body2,
277-
maxLines = 1,
278277
overflow = TextOverflow.Ellipsis
279278
)
280279
}

demoProjects/ComposeMail/app/src/main/java/com/example/composemail/ui/mails/MailList.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ fun MailList(
4141
modifier = modifier,
4242
verticalArrangement = Arrangement.spacedBy(4.dp)
4343
) {
44-
itemsIndexed(lazyMailItems) { index, mailItem ->
44+
itemsIndexed(lazyMailItems) { _, mailItem ->
4545
MailItem(
4646
info = mailItem,
4747
state = listState.stateFor(mailItem?.id)

demoProjects/ComposeMail/app/src/main/java/com/example/composemail/ui/mails/MailListState.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,26 @@ class MailListState {
2525

2626
private val _selectedCount = mutableStateOf(0)
2727

28+
val selectedIDs: Collection<Int>
29+
get() = selectedTracker.toList()
30+
2831
val selectedCount
2932
get() = _selectedCount.value
3033

3134
fun unselectAll() {
3235
conversationStatesById.values.forEach { it.setSelected(false) }
3336
}
3437

38+
/**
39+
* Returns an instance of [MailItemState] for the given [id].
40+
*
41+
* Repeated calls for the same [id] will return the same [MailItemState] instance.
42+
*/
3543
fun stateFor(id: Int?): MailItemState {
3644
val nextId = id ?: -1
3745
return conversationStatesById.computeIfAbsent(nextId) {
3846
MailItemState(nextId) { id, isSelected ->
47+
// Track which items are selected
3948
if (isSelected) {
4049
selectedTracker.add(id)
4150
} else {

demoProjects/ComposeMail/app/src/main/java/com/example/composemail/ui/utils/ConstraintUtils.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ import androidx.constraintlayout.compose.ConstraintSetScope
2424

2525
@Composable
2626
fun rememberConstraintSet(
27-
vararg keys: Any = emptyArray(),
27+
key: Any = Unit,
2828
constraints: ConstraintSetScope.() -> Unit
2929
): ConstraintSet {
30-
val constraintSet = remember(keys) {
30+
val constraintSet = remember(key) {
3131
ConstraintSet(constraints)
3232
}
3333
return constraintSet

0 commit comments

Comments
 (0)