Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
Dunbar
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PLN
Dunbar
Commits
acacc970
Unverified
Commit
acacc970
authored
Nov 02, 2019
by
PLN (Algolia)
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(Friends): Call/Text shortcuts
parent
0fac2ce4
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
48 additions
and
12 deletions
+48
-12
Extensions.kt
app/src/main/java/fr/plnech/dunbar/Extensions.kt
+20
-0
Friend.kt
app/src/main/java/fr/plnech/dunbar/model/Friend.kt
+4
-1
FriendReminder.kt
app/src/main/java/fr/plnech/dunbar/notif/FriendReminder.kt
+3
-6
FriendsActivity.kt
app/src/main/java/fr/plnech/dunbar/ui/FriendsActivity.kt
+2
-2
FriendsAdapter.kt
app/src/main/java/fr/plnech/dunbar/ui/FriendsAdapter.kt
+11
-0
contact.xml
app/src/main/res/layout/contact.xml
+6
-2
colors.xml
app/src/main/res/values/colors.xml
+2
-1
No files found.
app/src/main/java/fr/plnech/dunbar/Extensions.kt
View file @
acacc970
package
fr.plnech.dunbar
import
android.content.Intent
import
android.net.Uri
import
fr.plnech.dunbar.model.Friend
fun
String
.
plural
(
count
:
Int
=
1
):
String
{
return
when
{
count
>
1
->
this
+
"s"
else
->
this
}
}
fun
Friend
.
smsIntent
():
Intent
?
{
return
phone
?.
let
{
val
uri
=
Uri
.
parse
(
"smsto:${it}"
)
Intent
(
Intent
.
ACTION_SENDTO
,
uri
).
apply
{
putExtra
(
"sms_body"
,
"Hey ${this@smsIntent.firstName}, how are you?"
)
}
}
}
fun
Friend
.
callIntent
():
Intent
?
{
return
phone
?.
let
{
Intent
(
Intent
.
ACTION_DIAL
,
Uri
.
parse
(
"tel:${it}"
))
}
}
\ No newline at end of file
app/src/main/java/fr/plnech/dunbar/model/Friend.kt
View file @
acacc970
...
...
@@ -12,11 +12,14 @@ data class Friend(val map: MutableMap<String, String?>, val photo: Bitmap?) {
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
()
=
map
[
"data1"
]
get
()
=
if
(
map
[
Contacts
.
HAS_PHONE_NUMBER
]
==
"1"
)
map
[
"data1"
]
else
null
val
lastTimeStamp
=
map
[
Contacts
.
LAST_TIME_CONTACTED
]
!!
.
toLong
()
...
...
app/src/main/java/fr/plnech/dunbar/notif/FriendReminder.kt
View file @
acacc970
...
...
@@ -2,11 +2,10 @@ package fr.plnech.dunbar.notif
import
android.app.*
import
android.content.Context
import
android.content.Intent
import
android.net.Uri
import
android.os.Build
import
androidx.core.app.NotificationCompat
import
fr.plnech.dunbar.model.Friend
import
fr.plnech.dunbar.smsIntent
val
CHANNEL_ID
=
"dunbar"
...
...
@@ -34,10 +33,8 @@ class FriendReminder(val ctx: Context) {
fun
createNotification
(
friend
:
Friend
,
activity
:
Activity
):
Notification
?
{
if
(!
channelCreated
)
createNotificationChannel
()
val
uriSms
=
Uri
.
parse
(
"smsto:1234567899"
)
val
intentSMS
=
Intent
(
Intent
.
ACTION_SENDTO
,
uriSms
)
intentSMS
.
putExtra
(
"sms_body"
,
"The SMS text"
)
val
pendingIntent
:
PendingIntent
=
PendingIntent
.
getActivity
(
activity
,
0
,
intentSMS
,
0
)
val
pendingIntent
:
PendingIntent
=
PendingIntent
.
getActivity
(
activity
,
0
,
friend
.
smsIntent
(),
0
)
return
NotificationCompat
.
Builder
(
ctx
,
CHANNEL_ID
)
.
setContentTitle
(
"What is ${friend.name} up to?"
)
...
...
app/src/main/java/fr/plnech/dunbar/ui/FriendsActivity.kt
View file @
acacc970
...
...
@@ -86,7 +86,7 @@ class FriendsActivity : AppCompatActivity() {
val
newFriends
=
mutableListOf
<
Friend
>()
contentResolver
.
query
(
ContactsContract
.
CommonDataKinds
.
Phone
.
CONTENT_URI
,
ContactsContract
.
CommonDataKinds
.
Contactables
.
CONTENT_URI
,
null
,
null
,
null
,
...
...
@@ -111,7 +111,7 @@ class FriendsActivity : AppCompatActivity() {
friends
.
addAll
(
newFriends
)
}
friends
.
sortBy
Descending
{
it
.
timesContacted
}
friends
.
sortBy
{
it
.
timesContacted
}
}
private
fun
displayFriends
()
{
...
...
app/src/main/java/fr/plnech/dunbar/ui/FriendsAdapter.kt
View file @
acacc970
...
...
@@ -7,7 +7,9 @@ import android.view.ViewGroup
import
android.widget.Toast
import
androidx.recyclerview.widget.RecyclerView
import
fr.plnech.dunbar.R
import
fr.plnech.dunbar.callIntent
import
fr.plnech.dunbar.model.Friend
import
fr.plnech.dunbar.smsIntent
import
kotlinx.android.synthetic.main.contact.view.*
...
...
@@ -48,6 +50,15 @@ class FriendsViewHolder(private val view: View) : RecyclerView.ViewHolder(view)
append
(
"Never interacted"
)
}
friend
.
phone
?.
let
{
view
.
contactCall
.
visibility
=
View
.
VISIBLE
view
.
contactCall
.
setOnClickListener
{
view
.
context
.
startActivity
(
friend
.
callIntent
())
}
view
.
contactText
.
visibility
=
View
.
VISIBLE
view
.
contactText
.
setOnClickListener
{
view
.
context
.
startActivity
(
friend
.
smsIntent
())
}
append
(
"\n$it"
)
}
friend
.
photo
?.
let
{
...
...
app/src/main/res/layout/contact.xml
View file @
acacc970
...
...
@@ -64,12 +64,14 @@
<com.google.android.material.button.MaterialButton
android:id=
"@+id/contactText"
style=
"@style/Widget.MaterialComponents.Button"
style=
"@style/Widget.MaterialComponents.Button
.OutlinedButton
"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginEnd=
"10dp"
android:layout_marginStart=
"10dp"
android:text=
"Text"
android:visibility=
"invisible"
tools:visibility=
"visible"
app:icon=
"@android:drawable/ic_menu_send"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintHorizontal_bias=
"1.0"
...
...
@@ -79,12 +81,14 @@
<com.google.android.material.button.MaterialButton
android:id=
"@+id/contactCall"
style=
"@style/Widget.MaterialComponents.Button"
style=
"@style/Widget.MaterialComponents.Button
.OutlinedButton
"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginEnd=
"10dp"
android:text=
"Call"
app:icon=
"@android:drawable/ic_menu_call"
android:visibility=
"invisible"
tools:visibility=
"visible"
app:layout_constraintBottom_toBottomOf=
"@id/contactText"
app:layout_constraintHorizontal_bias=
"1.0"
app:layout_constraintLeft_toRightOf=
"@id/contactText"
...
...
app/src/main/res/values/colors.xml
View file @
acacc970
...
...
@@ -2,5 +2,6 @@
<resources>
<color
name=
"colorPrimary"
>
#008577
</color>
<color
name=
"colorPrimaryDark"
>
#00574B
</color>
<color
name=
"colorAccent"
>
#FF5900
</color>
<color
name=
"colorAccent"
>
#FF9800
</color>
<color
name=
"colorComplementAccent"
>
#FF5900
</color>
</resources>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment