-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #312 Add extensions for getting all data kinds of a Contact or…
… RawContact as a list
- Loading branch information
Showing
5 changed files
with
130 additions
and
21 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
core/src/main/java/contacts/core/util/ExistingContactData.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package contacts.core.util | ||
|
||
import contacts.core.entities.ExistingContactEntity | ||
import contacts.core.entities.ExistingDataEntity | ||
|
||
/** | ||
* Sequence of all data kinds (e.g. addresses, emails, events, etc) of all of this | ||
* [ExistingContactEntity.rawContacts]. | ||
*/ | ||
fun ExistingContactEntity.data(): Sequence<ExistingDataEntity> = sequence { | ||
yieldAll(rawContacts.flatMap { it.data() }) | ||
} | ||
|
||
/** | ||
* Same as [ExistingContactEntity.data] but as a [List]. | ||
*/ | ||
fun ExistingContactEntity.dataList(): List<ExistingDataEntity> = data().toList() |
36 changes: 36 additions & 0 deletions
36
core/src/main/java/contacts/core/util/ExistingRawContactData.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package contacts.core.util | ||
|
||
import contacts.core.entities.ExistingDataEntity | ||
import contacts.core.entities.ExistingRawContactEntity | ||
|
||
/** | ||
* Sequence of all data kinds (e.g. addresses, emails, events, etc) of this | ||
* [ExistingRawContactEntity]. | ||
*/ | ||
fun ExistingRawContactEntity.data(): Sequence<ExistingDataEntity> = sequence { | ||
yieldAll(addresses.filterIsInstance(ExistingDataEntity::class.java)) | ||
yieldAll(emails.filterIsInstance(ExistingDataEntity::class.java)) | ||
yieldAll(events.filterIsInstance(ExistingDataEntity::class.java)) | ||
// Group memberships are implicitly read-only. | ||
yieldAll(ims.filterIsInstance(ExistingDataEntity::class.java)) | ||
(name as? ExistingDataEntity)?.also { yield(it) } | ||
(nickname as? ExistingDataEntity)?.also { yield(it) } | ||
(note as? ExistingDataEntity)?.also { yield(it) } | ||
(organization as? ExistingDataEntity)?.also { yield(it) } | ||
yieldAll(phones.filterIsInstance(ExistingDataEntity::class.java)) | ||
// Photo is implicitly read-only. | ||
yieldAll(relations.filterIsInstance(ExistingDataEntity::class.java)) | ||
(sipAddress as? ExistingDataEntity)?.also { yield(it) } | ||
yieldAll(websites.filterIsInstance(ExistingDataEntity::class.java)) | ||
|
||
yieldAll( | ||
customDataEntities.values | ||
.flatMap { it.entities } | ||
.filterIsInstance(ExistingDataEntity::class.java) | ||
) | ||
} | ||
|
||
/** | ||
* Same as [ExistingRawContactEntity.data] but as a [List]. | ||
*/ | ||
fun ExistingRawContactEntity.dataList(): List<ExistingDataEntity> = data().toList() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters