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

Commit 313374d

Browse files
committed
Added compose screen
Change-Id: I1fd6e1dfee3e3445ea56702170f8f3ab51ef7dd4
1 parent db4cd2d commit 313374d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+914
-131
lines changed

app/build.gradle

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ android {
3636
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
3737
}
3838
}
39+
compileOptions {
40+
sourceCompatibility = 1.8
41+
targetCompatibility = 1.8
42+
}
43+
kotlinOptions {
44+
jvmTarget = "1.8"
45+
}
3946
}
4047

4148
dependencies {
@@ -50,6 +57,7 @@ dependencies {
5057
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
5158
implementation 'androidx.recyclerview:recyclerview:1.1.0-alpha06'
5259
implementation 'androidx.core:core-ktx:1.0.2'
60+
implementation 'androidx.lifecycle:lifecycle-livedata-core-ktx:2.2.0-alpha03'
5361
implementation "androidx.navigation:navigation-fragment-ktx:$navigation_version"
5462
implementation "androidx.navigation:navigation-ui-ktx:$navigation_version"
5563

app/src/main/AndroidManifest.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
<application
66
android:allowBackup="true"
7-
android:name=".App"
87
android:icon="@mipmap/ic_launcher"
98
android:label="@string/app_name"
109
android:roundIcon="@mipmap/ic_launcher_round"

app/src/main/java/com/materialstudies/reply/App.kt renamed to app/src/main/java/com/materialstudies/reply/data/Account.kt

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,19 @@
1414
* limitations under the License.
1515
*/
1616

17-
package com.materialstudies.reply
17+
package com.materialstudies.reply.data
1818

19-
import android.app.Application
20-
import com.materialstudies.reply.data.EmailStore
19+
import androidx.annotation.DrawableRes
2120

22-
class App : Application() {
23-
24-
val emailStore = EmailStore()
21+
/**
22+
* An object which represents a person/account.
23+
*/
24+
data class Account(
25+
val id: Long,
26+
val firstName: String,
27+
val lastName: String,
28+
val email: String,
29+
@DrawableRes val avatar: Int
30+
) {
31+
val fullName: String = "$firstName $lastName"
2532
}
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
/*
2+
* Copyright 2019 Google LLC
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+
* https://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.materialstudies.reply.data
18+
19+
import com.materialstudies.reply.R
20+
21+
/**
22+
* An static data store of [Account]s. This includes both [Account]s owned by the current user and
23+
* all [Account]s of the current user's contacts.
24+
*/
25+
object AccountStore {
26+
27+
private val userAccounts = listOf(
28+
Account(
29+
0L,
30+
"Jeff",
31+
"Hansen",
32+
33+
R.drawable.avatar_10
34+
),
35+
Account(
36+
0L,
37+
"Jeff",
38+
"H",
39+
40+
R.drawable.avatar_10
41+
)
42+
)
43+
44+
private val userContactAccounts = listOf(
45+
Account(
46+
1L,
47+
"Tracy",
48+
"Alvarez",
49+
50+
R.drawable.avatar_4
51+
),
52+
Account(
53+
2L,
54+
"Allison",
55+
"Trabucco",
56+
57+
R.drawable.avatar_7
58+
),
59+
Account(
60+
3L,
61+
"Ali",
62+
"Connors",
63+
64+
R.drawable.avatar_5
65+
),
66+
Account(
67+
4L,
68+
"Alberto",
69+
"Williams",
70+
71+
R.drawable.avatar_8
72+
),
73+
Account(
74+
5L,
75+
"Kim",
76+
"Alen",
77+
78+
R.drawable.avatar_9
79+
),
80+
Account(
81+
6L,
82+
"Google",
83+
"Express",
84+
85+
R.drawable.avatar_express
86+
),
87+
Account(
88+
7L,
89+
"Sandra",
90+
"Adams",
91+
92+
R.drawable.avatar_2
93+
),
94+
Account(
95+
8L,
96+
"Trevor",
97+
"Hansen",
98+
99+
R.drawable.avatar_3
100+
),
101+
Account(
102+
9L,
103+
"Britta",
104+
"Holt",
105+
106+
R.drawable.avatar_4
107+
),
108+
Account(
109+
10L,
110+
"Frank",
111+
"Hawkins",
112+
113+
R.drawable.avatar_6
114+
)
115+
)
116+
117+
/**
118+
* Get the current user's default account.
119+
*/
120+
fun getDefaultUserAccount() = userAccounts.first()
121+
122+
/**
123+
* Get all [Account]s owned by the current user.
124+
*/
125+
fun getUserAccounts() = userAccounts
126+
127+
/**
128+
* Whether or not the given [accountId] is an account owned by the current user.
129+
*/
130+
fun isUserAccount(accountId: Long): Boolean = userAccounts.any { it.id == accountId }
131+
132+
/**
133+
* Get the contact of the current user with the given [accountId].
134+
*/
135+
fun getContactAccountById(accountId: Long): Account {
136+
return userContactAccounts.firstOrNull { it.id == accountId } ?: userContactAccounts.first()
137+
}
138+
}

app/src/main/java/com/materialstudies/reply/data/Email.kt

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,30 @@
1616

1717
package com.materialstudies.reply.data
1818

19-
import androidx.annotation.DrawableRes
2019
import androidx.recyclerview.widget.DiffUtil
2120

2221
/**
2322
* A simple data class to represent an Email.
2423
*/
2524
data class Email(
26-
val id: Int,
27-
val sender: String,
28-
val recipient: String,
29-
val subject: String,
30-
val body: String,
31-
@DrawableRes val senderResId: Int,
25+
val id: Long,
26+
val sender: Account,
27+
val recipients: List<Account> = emptyList(),
28+
val subject: String = "",
29+
val body: String = "",
3230
val attachments: List<EmailAttachment> = emptyList(),
3331
var isImportant: Boolean = false,
3432
var isStarred: Boolean = false
3533
) {
34+
//TODO(hunterstich) Update to use real Dates.
35+
val senderPreview: String = "${sender.fullName} - 4 hrs ago"
3636
val hasBody: Boolean = body.isNotBlank()
3737
val hasAttachments: Boolean = attachments.isNotEmpty()
38+
val recipientsPreview: String = recipients
39+
.map { it.firstName }
40+
.fold("") { name, acc -> "$acc, $name" }
41+
val nonUserAccountRecipients = recipients
42+
.filterNot { AccountStore.isUserAccount(it.id) }
3843
}
3944

4045
object EmailDiffCallback : DiffUtil.ItemCallback<Email>() {

0 commit comments

Comments
 (0)