1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package fr.plnech.dunbar.model
import android.content.Intent
import android.graphics.Bitmap
import android.net.Uri
import android.provider.ContactsContract.Contacts
import java.util.*
data class Friend(val map: MutableMap<String, String?>, val photo: Bitmap?) {
override fun toString(): String = "$name"
fun mapString(): String = map.entries.filter { !it.value.isNullOrEmpty() }.toString()
val name: String?
get() = map[Contacts.DISPLAY_NAME]
val firstName: String?
get() = name?.split(Regex("\\s"))?.firstOrNull()
val id: Int
get() = map[Contacts._ID]!!.toInt()
val phone: String?
get() = if (map[Contacts.HAS_PHONE_NUMBER] == "1") map["data1"] else null
val lastTimeStamp = map[Contacts.LAST_TIME_CONTACTED]!!.toLong()
val lastDate: Date?
get() = if (lastTimeStamp > 0) Date(lastTimeStamp) else null
val timesContacted: Int
get() = map[Contacts.TIMES_CONTACTED]?.toInt() ?: 0
val isYou: String?
get() = map[Contacts.IS_USER_PROFILE]
val visibleOutsideSearch: String?
get() = map[Contacts.IN_DEFAULT_DIRECTORY]
fun smsIntent(): Intent? {
return phone?.let {
val uri = Uri.parse("smsto:${it}")
Intent(Intent.ACTION_SENDTO, uri).apply {
putExtra("sms_body", "Hey ${firstName}, how are you?")
}
}
}
fun callIntent(): Intent? {
return phone?.let {
Intent(Intent.ACTION_DIAL, Uri.parse("tel:${it}"))
}
}
}