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
0fac2ce4
Unverified
Commit
0fac2ce4
authored
Nov 02, 2019
by
PLN (Algolia)
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: Basic notif, better layout
parent
f7f464bd
Show whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
146 additions
and
23 deletions
+146
-23
AndroidManifest.xml
app/src/main/AndroidManifest.xml
+1
-1
Messages.kt
app/src/main/java/fr/plnech/dunbar/data/Messages.kt
+1
-1
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
+57
-0
FriendsActivity.kt
app/src/main/java/fr/plnech/dunbar/ui/FriendsActivity.kt
+23
-5
FriendsAdapter.kt
app/src/main/java/fr/plnech/dunbar/ui/FriendsAdapter.kt
+17
-2
ic_friend.png
app/src/main/res/drawable/ic_friend.png
+0
-0
activity_friends.xml
app/src/main/res/layout/activity_friends.xml
+2
-2
contact.xml
app/src/main/res/layout/contact.xml
+34
-5
content_friends.xml
app/src/main/res/layout/content_friends.xml
+2
-2
menu_main.xml
app/src/main/res/menu/menu_main.xml
+1
-1
colors.xml
app/src/main/res/values/colors.xml
+1
-1
strings.xml
app/src/main/res/values/strings.xml
+2
-0
styles.xml
app/src/main/res/values/styles.xml
+1
-2
No files found.
app/src/main/AndroidManifest.xml
View file @
0fac2ce4
...
...
@@ -14,7 +14,7 @@
android:supportsRtl=
"true"
android:theme=
"@style/AppTheme"
>
<activity
android:name=
".
Main
Activity"
android:name=
".
ui.Friends
Activity"
android:label=
"@string/app_name"
android:theme=
"@style/AppTheme.NoActionBar"
>
<intent-filter>
...
...
app/src/main/java/fr/plnech/dunbar/Messages.kt
→
app/src/main/java/fr/plnech/dunbar/
data/
Messages.kt
View file @
0fac2ce4
package
fr.plnech.dunbar
package
fr.plnech.dunbar
.data
import
android.content.Context
import
android.net.Uri
...
...
app/src/main/java/fr/plnech/dunbar/Friend.kt
→
app/src/main/java/fr/plnech/dunbar/
model/
Friend.kt
View file @
0fac2ce4
package
fr.plnech.dunbar
package
fr.plnech.dunbar
.model
import
android.graphics.Bitmap
import
android.provider.ContactsContract.Contacts
...
...
@@ -15,6 +15,9 @@ data class Friend(val map: MutableMap<String, String?>, val photo: Bitmap?) {
val
id
:
Int
get
()
=
map
[
Contacts
.
_ID
]
!!
.
toInt
()
val
phone
:
String
?
get
()
=
map
[
"data1"
]
val
lastTimeStamp
=
map
[
Contacts
.
LAST_TIME_CONTACTED
]
!!
.
toLong
()
val
lastDate
:
Date
?
...
...
app/src/main/java/fr/plnech/dunbar/notif/FriendReminder.kt
0 → 100644
View file @
0fac2ce4
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
val
CHANNEL_ID
=
"dunbar"
class
FriendReminder
(
val
ctx
:
Context
)
{
var
channelCreated
=
false
private
fun
createNotificationChannel
()
{
// Create the NotificationChannel, but only on API 26+ because
// the NotificationChannel class is new and not in the support library
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
O
)
{
val
channel
=
NotificationChannel
(
CHANNEL_ID
,
ctx
.
getString
(
fr
.
plnech
.
dunbar
.
R
.
string
.
channel_name
),
NotificationManager
.
IMPORTANCE_DEFAULT
).
apply
{
description
=
ctx
.
getString
(
fr
.
plnech
.
dunbar
.
R
.
string
.
channel_description
)
}
(
ctx
.
getSystemService
(
Context
.
NOTIFICATION_SERVICE
)
as
NotificationManager
)
.
createNotificationChannel
(
channel
)
}
channelCreated
=
true
}
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
)
return
NotificationCompat
.
Builder
(
ctx
,
CHANNEL_ID
)
.
setContentTitle
(
"What is ${friend.name} up to?"
)
.
setContentText
(
"Ask them for some news!"
)
.
setSmallIcon
(
fr
.
plnech
.
dunbar
.
R
.
drawable
.
ic_friend
)
// .setStyle(
// NotificationCompat.BigTextStyle()
// .bigText("Much longer text that cannot fit one line...")
// )
.
setContentIntent
(
pendingIntent
)
.
setAutoCancel
(
true
)
.
also
{
it
.
priority
=
NotificationCompat
.
PRIORITY_HIGH
}.
build
()
}
}
\ No newline at end of file
app/src/main/java/fr/plnech/dunbar/
Main
Activity.kt
→
app/src/main/java/fr/plnech/dunbar/
ui/Friends
Activity.kt
View file @
0fac2ce4
package
fr.plnech.dunbar
package
fr.plnech.dunbar
.ui
import
android.content.ContentUris
import
android.graphics.Bitmap
...
...
@@ -9,20 +9,26 @@ import android.view.Menu
import
android.view.MenuItem
import
android.widget.Toast
import
androidx.appcompat.app.AppCompatActivity
import
androidx.core.app.NotificationManagerCompat
import
androidx.recyclerview.widget.LinearLayoutManager
import
kotlinx.android.synthetic.main.activity_main.*
import
kotlinx.android.synthetic.main.content_main.*
import
fr.plnech.dunbar.R
import
fr.plnech.dunbar.data.Messages
import
fr.plnech.dunbar.model.Friend
import
fr.plnech.dunbar.notif.FriendReminder
import
fr.plnech.dunbar.plural
import
kotlinx.android.synthetic.main.activity_friends.*
import
kotlinx.android.synthetic.main.content_friends.*
import
java.io.IOException
class
Main
Activity
:
AppCompatActivity
()
{
class
Friends
Activity
:
AppCompatActivity
()
{
private
lateinit
var
messages
:
Messages
private
val
friends
=
mutableListOf
<
Friend
>()
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
setContentView
(
R
.
layout
.
activity_
main
)
setContentView
(
R
.
layout
.
activity_
friends
)
setSupportActionBar
(
toolbar
)
// messages = Messages(applicationContext)
...
...
@@ -32,6 +38,18 @@ class MainActivity : AppCompatActivity() {
}
reloadFriends
()
notifyFriend
()
}
private
fun
notifyFriend
()
{
val
idNotif
=
0
with
(
NotificationManagerCompat
.
from
(
this
))
{
val
notification
=
FriendReminder
(
applicationContext
).
createNotification
(
friends
[
0
],
this
@FriendsActivity
)
notification
?.
let
{
notify
(
idNotif
,
notification
)
}
}
}
override
fun
onCreateOptionsMenu
(
menu
:
Menu
):
Boolean
{
...
...
app/src/main/java/fr/plnech/dunbar/FriendsAdapter.kt
→
app/src/main/java/fr/plnech/dunbar/
ui/
FriendsAdapter.kt
View file @
0fac2ce4
package
fr.plnech.dunbar
package
fr.plnech.dunbar
.ui
import
android.text.format.DateUtils
import
android.view.LayoutInflater
...
...
@@ -6,6 +6,8 @@ import android.view.View
import
android.view.ViewGroup
import
android.widget.Toast
import
androidx.recyclerview.widget.RecyclerView
import
fr.plnech.dunbar.R
import
fr.plnech.dunbar.model.Friend
import
kotlinx.android.synthetic.main.contact.view.*
...
...
@@ -14,7 +16,13 @@ class FriendsAdapter(
)
:
RecyclerView
.
Adapter
<
FriendsViewHolder
>()
{
override
fun
onCreateViewHolder
(
parent
:
ViewGroup
,
viewType
:
Int
):
FriendsViewHolder
=
FriendsViewHolder
(
LayoutInflater
.
from
(
parent
.
context
).
inflate
(
viewType
,
parent
,
false
))
FriendsViewHolder
(
LayoutInflater
.
from
(
parent
.
context
).
inflate
(
viewType
,
parent
,
false
)
)
override
fun
getItemCount
():
Int
=
friends
.
size
...
...
@@ -39,9 +47,16 @@ class FriendsViewHolder(private val view: View) : RecyclerView.ViewHolder(view)
}
else
{
append
(
"Never interacted"
)
}
friend
.
phone
?.
let
{
append
(
"\n$it"
)
}
friend
.
photo
?.
let
{
pic
.
setImageBitmap
(
it
)
}
}
view
.
setOnClickListener
{
Toast
.
makeText
(
view
.
context
,
friend
.
mapString
(),
Toast
.
LENGTH_LONG
).
show
()
println
(
friend
.
mapString
())
}
}
...
...
app/src/main/res/drawable/ic_friend.png
0 → 100644
View file @
0fac2ce4
29.8 KB
app/src/main/res/layout/activity_
main
.xml
→
app/src/main/res/layout/activity_
friends
.xml
View file @
0fac2ce4
...
...
@@ -4,7 +4,7 @@
xmlns:tools=
"http://schemas.android.com/tools"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
tools:context=
".
Main
Activity"
>
tools:context=
".
ui.Friends
Activity"
>
<com.google.android.material.appbar.AppBarLayout
android:layout_width=
"match_parent"
...
...
@@ -20,7 +20,7 @@
</com.google.android.material.appbar.AppBarLayout>
<include
layout=
"@layout/content_
main
"
/>
<include
layout=
"@layout/content_
friends
"
/>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id=
"@+id/fab"
...
...
app/src/main/res/layout/contact.xml
View file @
0fac2ce4
...
...
@@ -32,9 +32,9 @@
android:id=
"@+id/contactName"
android:layout_width=
"0dp"
android:layout_height=
"wrap_content"
android:layout_marginEnd=
"15dp"
android:focusable=
"false"
android:focusableInTouchMode=
"false"
android:layout_marginEnd=
"15dp"
android:gravity=
"end"
android:maxLines=
"2"
android:textAppearance=
"@style/TextAppearance.AppCompat.Title"
...
...
@@ -49,18 +49,47 @@
android:id=
"@+id/contactData"
android:layout_width=
"0dp"
android:layout_height=
"wrap_content"
android:layout_marginBottom=
"15dp"
android:layout_marginEnd=
"15dp"
android:layout_marginBottom=
"15dp"
android:focusable=
"false"
android:focusableInTouchMode=
"false"
android:gravity=
"end"
android:textAppearance=
"@style/TextAppearance.AppCompat.Subhead"
app:layout_constraintBottom_to
BottomOf=
"parent
"
app:layout_constraintBottom_to
TopOf=
"@id/contactCall
"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintLeft_toRightOf=
"@id/
pic
"
app:layout_constraintLeft_toRightOf=
"@id/
contactText
"
app:layout_constraintRight_toLeftOf=
"@id/contactName"
app:layout_constraintTop_toBottomOf=
"@id/contactName"
tools:text=
"@tools:sample/full_names"
/>
tools:text=
"2 interactions, last 1 hour ago"
/>
<com.google.android.material.button.MaterialButton
android:id=
"@+id/contactText"
style=
"@style/Widget.MaterialComponents.Button"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginEnd=
"10dp"
android:layout_marginStart=
"10dp"
android:text=
"Text"
app:icon=
"@android:drawable/ic_menu_send"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintHorizontal_bias=
"1.0"
app:layout_constraintLeft_toRightOf=
"@id/pic"
app:layout_constraintRight_toLeftOf=
"@id/contactCall"
app:layout_constraintTop_toBottomOf=
"@id/contactData"
/>
<com.google.android.material.button.MaterialButton
android:id=
"@+id/contactCall"
style=
"@style/Widget.MaterialComponents.Button"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginEnd=
"10dp"
android:text=
"Call"
app:icon=
"@android:drawable/ic_menu_call"
app:layout_constraintBottom_toBottomOf=
"@id/contactText"
app:layout_constraintHorizontal_bias=
"1.0"
app:layout_constraintLeft_toRightOf=
"@id/contactText"
app:layout_constraintRight_toRightOf=
"parent"
app:layout_constraintTop_toBottomOf=
"@id/contactData"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
app/src/main/res/layout/content_
main
.xml
→
app/src/main/res/layout/content_
friends
.xml
View file @
0fac2ce4
...
...
@@ -5,8 +5,8 @@
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
app:layout_behavior=
"@string/appbar_scrolling_view_behavior"
tools:context=
".
Main
Activity"
tools:showIn=
"@layout/activity_
main
"
>
tools:context=
".
ui.Friends
Activity"
tools:showIn=
"@layout/activity_
friends
"
>
<TextView
android:id=
"@+id/welcomeTitle"
...
...
app/src/main/res/menu/menu_main.xml
View file @
0fac2ce4
<menu
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
xmlns:tools=
"http://schemas.android.com/tools"
tools:context=
"fr.plnech.dunbar.
Main
Activity"
>
tools:context=
"fr.plnech.dunbar.
ui.Friends
Activity"
>
<item
android:id=
"@+id/action_settings"
android:orderInCategory=
"100"
...
...
app/src/main/res/values/colors.xml
View file @
0fac2ce4
...
...
@@ -2,5 +2,5 @@
<resources>
<color
name=
"colorPrimary"
>
#008577
</color>
<color
name=
"colorPrimaryDark"
>
#00574B
</color>
<color
name=
"colorAccent"
>
#
D81B6
0
</color>
<color
name=
"colorAccent"
>
#
FF590
0
</color>
</resources>
app/src/main/res/values/strings.xml
View file @
0fac2ce4
<resources>
<string
name=
"app_name"
>
Dunbar
</string>
<string
name=
"channel_name"
>
Dunbar
</string>
<string
name=
"channel_description"
>
Updates about friends you don\'t want to forget
</string>
<string
name=
"action_settings"
>
Settings
</string>
</resources>
app/src/main/res/values/styles.xml
View file @
0fac2ce4
<resources>
<!-- Base application theme. -->
<style
name=
"AppTheme"
parent=
"Theme.AppCompat.Light.DarkActionBar"
>
<!-- Customize your theme here. -->
<style
name=
"AppTheme"
parent=
"Theme.MaterialComponents.Light.DarkActionBar"
>
<item
name=
"colorPrimary"
>
@color/colorPrimary
</item>
<item
name=
"colorPrimaryDark"
>
@color/colorPrimaryDark
</item>
<item
name=
"colorAccent"
>
@color/colorAccent
</item>
...
...
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