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
d73ffede
Unverified
Commit
d73ffede
authored
Nov 16, 2019
by
PLN (Algolia)
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: FriendsList launch, contacts sub
parent
904b0fde
Show whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
113 additions
and
99 deletions
+113
-99
AndroidManifest.xml
app/src/main/AndroidManifest.xml
+15
-14
Extensions.kt
app/src/main/java/fr/plnech/dunbar/Extensions.kt
+1
-1
ContactsActivity.kt
app/src/main/java/fr/plnech/dunbar/ui/ContactsActivity.kt
+26
-49
FriendDetailActivity.kt
...src/main/java/fr/plnech/dunbar/ui/FriendDetailActivity.kt
+2
-1
FriendDetailFragment.kt
...src/main/java/fr/plnech/dunbar/ui/FriendDetailFragment.kt
+2
-1
FriendListActivity.kt
app/src/main/java/fr/plnech/dunbar/ui/FriendListActivity.kt
+45
-13
friend_list.xml
app/src/main/res/layout-w900dp/friend_list.xml
+2
-2
activity_contacts.xml
app/src/main/res/layout/activity_contacts.xml
+1
-1
activity_friend_detail.xml
app/src/main/res/layout/activity_friend_detail.xml
+1
-1
activity_friends_list.xml
app/src/main/res/layout/activity_friends_list.xml
+1
-1
content_contacts.xml
app/src/main/res/layout/content_contacts.xml
+7
-7
friend_detail.xml
app/src/main/res/layout/friend_detail.xml
+2
-2
friend_list.xml
app/src/main/res/layout/friend_list.xml
+3
-2
menu_main.xml
app/src/main/res/menu/menu_main.xml
+3
-3
strings.xml
app/src/main/res/values/strings.xml
+2
-1
No files found.
app/src/main/AndroidManifest.xml
View file @
d73ffede
...
...
@@ -18,32 +18,33 @@
<!-- TODO: https://developer.android.com/studio/write/app-link-indexing -->
<activity
android:name=
".FriendListActivity"
android:name=
".
ui.
FriendListActivity"
android:label=
"@string/title_friend_list"
android:parentActivityName=
".ui.
Friend
sActivity"
android:parentActivityName=
".ui.
Contact
sActivity"
android:theme=
"@style/AppTheme.NoActionBar"
>
<meta-data
android:name=
"android.support.PARENT_ACTIVITY"
android:value=
"fr.plnech.dunbar.ui.FriendsActivity"
/>
<intent-filter>
<action
android:name=
"android.intent.action.MAIN"
/>
<category
android:name=
"android.intent.category.LAUNCHER"
/>
</intent-filter>
</activity>
<activity
android:name=
".FriendDetailActivity"
android:name=
".
ui.
FriendDetailActivity"
android:label=
"@string/title_friend_detail"
android:parentActivityName=
".FriendListActivity"
android:parentActivityName=
".
ui.
FriendListActivity"
android:theme=
"@style/AppTheme.NoActionBar"
>
<meta-data
android:name=
"android.support.PARENT_ACTIVITY"
android:value=
"fr.plnech.dunbar.FriendListActivity"
/>
android:value=
"fr.plnech.dunbar.
ui.
FriendListActivity"
/>
</activity>
<activity
android:name=
".ui.
Friend
sActivity"
android:name=
".ui.
Contact
sActivity"
android:label=
"@string/app_name"
android:theme=
"@style/AppTheme.NoActionBar"
>
<intent-filter>
<action
android:name=
"android.intent.action.MAIN"
/>
<category
android:name=
"android.intent.category.LAUNCHER"
/>
</intent-filter>
<meta-data
android:name=
"android.support.PARENT_ACTIVITY"
android:value=
"fr.plnech.dunbar.ui.FriendListActivity"
/>
</activity>
</application>
...
...
app/src/main/java/fr/plnech/dunbar/Extensions.kt
View file @
d73ffede
...
...
@@ -15,7 +15,7 @@ fun String.plural(count: Int = 1): String {
}
}
fun
Context
.
fetch
Friend
s
(
includeNot
:
Boolean
=
true
):
List
<
Friend
>
{
fun
Context
.
fetch
Contact
s
(
includeNot
:
Boolean
=
true
):
List
<
Friend
>
{
// TODO: https://developer.android.com/training/permissions/requesting
val
friends
=
mutableListOf
<
Friend
>()
...
...
app/src/main/java/fr/plnech/dunbar/ui/ContactsActivity.kt
View file @
d73ffede
package
fr.plnech.dunbar.ui
import
android.content.Intent
import
android.os.Bundle
import
android.view.Menu
import
android.view.MenuItem
import
android.widget.Toast
import
androidx.appcompat.app.AppCompatActivity
import
androidx.core.app.NavUtils
import
androidx.core.app.NotificationManagerCompat
import
androidx.recyclerview.widget.LinearLayoutManager
import
fr.plnech.dunbar.FriendListActivity
import
fr.plnech.dunbar.R
import
fr.plnech.dunbar.data.Messages
import
fr.plnech.dunbar.fetch
Friend
s
import
fr.plnech.dunbar.fetch
Contact
s
import
fr.plnech.dunbar.model.Friend
import
fr.plnech.dunbar.notif.FriendReminder
import
fr.plnech.dunbar.plural
import
kotlinx.android.synthetic.main.activity_contacts.*
import
kotlinx.android.synthetic.main.content_
friend
s.*
import
kotlinx.android.synthetic.main.content_
contact
s.*
import
java.util.*
class
Friend
sActivity
:
AppCompatActivity
()
{
class
Contact
sActivity
:
AppCompatActivity
()
{
private
lateinit
var
messages
:
Messages
private
var
friend
s
=
listOf
<
Friend
>()
private
var
contact
s
=
listOf
<
Friend
>()
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
...
...
@@ -33,20 +29,23 @@ class FriendsActivity : AppCompatActivity() {
// messages = Messages(applicationContext)
fab
.
setOnClickListener
{
view
->
reload
Friend
s
()
reload
Contact
s
()
notifyFriend
()
}
reloadFriends
()
// Show the Up button in the action bar.
supportActionBar
?.
setDisplayHomeAsUpEnabled
(
true
)
reloadContacts
()
notifyFriend
()
}
private
fun
notifyFriend
()
{
val
idNotification
=
0
val
notRecentlyTalked
=
friend
s
.
filter
{
val
notRecentlyTalked
=
contact
s
.
filter
{
it
.
lastDate
!=
null
&&
(
Date
().
time
-
it
.
lastDate
!!
.
time
)
>
1
*
60
*
60
*
1000
}
println
(
"${notRecentlyTalked.size} good old
friend
s I could talk to."
)
println
(
"${notRecentlyTalked.size} good old
contact
s I could talk to."
)
val
friend
=
notRecentlyTalked
.
minBy
{
it
.
timesContacted
}
...
...
@@ -55,7 +54,7 @@ class FriendsActivity : AppCompatActivity() {
val
notification
=
FriendReminder
(
applicationContext
).
createNotification
(
friend
,
this
@
Friend
sActivity
this
@
Contact
sActivity
)
notification
?.
let
{
notify
(
idNotification
,
notification
)
...
...
@@ -64,49 +63,27 @@ class FriendsActivity : AppCompatActivity() {
}
}
override
fun
onCreateOptionsMenu
(
menu
:
Menu
):
Boolean
{
// Inflate the menu; this adds items to the action bar if it is present.
menuInflater
.
inflate
(
R
.
menu
.
menu_main
,
menu
)
return
true
}
override
fun
onOptionsItemSelected
(
item
:
MenuItem
):
Boolean
{
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
return
when
(
item
.
itemId
)
{
R
.
id
.
action_settings
->
true
R
.
id
.
action_friends
->
{
startActivity
(
Intent
(
this
,
FriendListActivity
::
class
.
java
))
override
fun
onOptionsItemSelected
(
item
:
MenuItem
)
=
when
(
item
.
itemId
)
{
android
.
R
.
id
.
home
->
{
NavUtils
.
navigateUpFromSameTask
(
this
)
true
}
else
->
super
.
onOptionsItemSelected
(
item
)
}
}
private
fun
reloadFriends
()
{
friends
=
fetchFriends
()
displayFriends
()
// fetchMessages()
private
fun
reloadContacts
()
{
contacts
=
fetchContacts
()
displayContacts
()
}
private
fun
fetchMessages
()
{
messages
.
fetchAll
()
Toast
.
makeText
(
this
,
"${messages.sent.size} messages sent, "
+
"${messages.inbox.size} messages received."
,
Toast
.
LENGTH_SHORT
).
show
()
}
private
fun
displayFriends
()
{
val
adapter
=
FriendsAdapter
(
friends
)
private
fun
displayContacts
()
{
val
adapter
=
FriendsAdapter
(
contacts
)
val
nbFriends
=
adapter
.
itemCount
friend
sList
.
layoutManager
=
LinearLayoutManager
(
this
)
friend
sList
.
setHasFixedSize
(
true
)
friend
sList
.
adapter
=
adapter
welcomeTitle
.
text
=
getString
(
R
.
string
.
text_welcome
).
format
(
nbFriends
,
"friend"
.
plural
(
nbFriends
)
)
contact
sList
.
layoutManager
=
LinearLayoutManager
(
this
)
contact
sList
.
setHasFixedSize
(
true
)
contact
sList
.
adapter
=
adapter
contactsTitle
.
text
=
getString
(
R
.
string
.
text_contacts
).
format
(
nbFriends
)
}
}
app/src/main/java/fr/plnech/dunbar/FriendDetailActivity.kt
→
app/src/main/java/fr/plnech/dunbar/
ui/
FriendDetailActivity.kt
View file @
d73ffede
package
fr.plnech.dunbar
package
fr.plnech.dunbar
.ui
import
android.content.Intent
import
android.os.Bundle
import
android.view.MenuItem
import
androidx.appcompat.app.AppCompatActivity
import
com.google.android.material.snackbar.Snackbar
import
fr.plnech.dunbar.R
import
kotlinx.android.synthetic.main.activity_friend_detail.*
/**
...
...
app/src/main/java/fr/plnech/dunbar/FriendDetailFragment.kt
→
app/src/main/java/fr/plnech/dunbar/
ui/
FriendDetailFragment.kt
View file @
d73ffede
package
fr.plnech.dunbar
package
fr.plnech.dunbar
.ui
import
android.os.Bundle
import
android.view.LayoutInflater
import
android.view.View
import
android.view.ViewGroup
import
androidx.fragment.app.Fragment
import
fr.plnech.dunbar.R
import
fr.plnech.dunbar.dummy.DummyContent
import
fr.plnech.dunbar.model.Friend
import
kotlinx.android.synthetic.main.activity_friend_detail.*
...
...
app/src/main/java/fr/plnech/dunbar/FriendListActivity.kt
→
app/src/main/java/fr/plnech/dunbar/
ui/
FriendListActivity.kt
View file @
d73ffede
package
fr.plnech.dunbar
package
fr.plnech.dunbar
.ui
import
android.content.Intent
import
android.os.Bundle
import
android.view.LayoutInflater
import
android.view.MenuItem
import
android.view.View
import
android.view.ViewGroup
import
android.view.*
import
android.widget.TextView
import
androidx.appcompat.app.AppCompatActivity
import
androidx.
core.app.NavUtils
import
androidx.
recyclerview.widget.LinearLayoutManager
import
androidx.recyclerview.widget.RecyclerView
import
com.google.android.material.snackbar.Snackbar
import
fr.plnech.dunbar.R
import
fr.plnech.dunbar.dummy.DummyContent
import
fr.plnech.dunbar.fetchContacts
import
fr.plnech.dunbar.model.Friend
import
fr.plnech.dunbar.plural
import
kotlinx.android.synthetic.main.activity_friends_list.*
import
kotlinx.android.synthetic.main.content_contacts.*
import
kotlinx.android.synthetic.main.friend_list.*
import
kotlinx.android.synthetic.main.friend_list_content.view.*
...
...
@@ -25,6 +26,8 @@ class FriendListActivity : AppCompatActivity() {
*/
private
var
twoPane
:
Boolean
=
false
private
var
friends
=
listOf
<
Friend
>()
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
setContentView
(
R
.
layout
.
activity_friends_list
)
...
...
@@ -36,8 +39,6 @@ class FriendListActivity : AppCompatActivity() {
Snackbar
.
make
(
view
,
"Replace with your own action"
,
Snackbar
.
LENGTH_LONG
)
.
setAction
(
"Action"
,
null
).
show
()
}
// Show the Up button in the action bar.
supportActionBar
?.
setDisplayHomeAsUpEnabled
(
true
)
if
(
friend_detail_container
!=
null
)
{
// The detail container view will be present only in the
...
...
@@ -50,17 +51,48 @@ class FriendListActivity : AppCompatActivity() {
setupRecyclerView
(
friend_list
)
}
override
fun
onOptionsItemSelected
(
item
:
MenuItem
)
=
when
(
item
.
itemId
)
{
android
.
R
.
id
.
home
->
{
NavUtils
.
navigateUpFromSameTask
(
this
)
override
fun
onCreateOptionsMenu
(
menu
:
Menu
?):
Boolean
{
menuInflater
.
inflate
(
R
.
menu
.
menu_main
,
menu
)
return
super
.
onCreateOptionsMenu
(
menu
)
}
override
fun
onOptionsItemSelected
(
item
:
MenuItem
):
Boolean
{
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
return
when
(
item
.
itemId
)
{
R
.
id
.
action_settings
->
true
R
.
id
.
action_contacts
->
{
startActivity
(
Intent
(
this
,
ContactsActivity
::
class
.
java
))
true
}
else
->
super
.
onOptionsItemSelected
(
item
)
}
}
private
fun
reloadFriends
()
{
friends
=
fetchContacts
()
displayFriends
()
// fetchMessages()
}
private
fun
displayFriends
()
{
val
adapter
=
FriendsAdapter
(
friends
)
val
nbFriends
=
adapter
.
itemCount
contactsList
.
layoutManager
=
LinearLayoutManager
(
this
)
contactsList
.
setHasFixedSize
(
true
)
contactsList
.
adapter
=
adapter
`@
+
id
/
contactsTitle
`
.
text
=
getString
(
R
.
string
.
text_welcome
).
format
(
nbFriends
,
"friend"
.
plural
(
nbFriends
))
}
private
fun
setupRecyclerView
(
recyclerView
:
RecyclerView
)
{
recyclerView
.
adapter
=
SimpleItemRecyclerViewAdapter
(
this
,
DummyContent
.
ITEMS
,
twoPane
)
recyclerView
.
adapter
=
SimpleItemRecyclerViewAdapter
(
this
,
DummyContent
.
ITEMS
,
twoPane
)
}
class
SimpleItemRecyclerViewAdapter
(
...
...
app/src/main/res/layout-w900dp/friend_list.xml
View file @
d73ffede
...
...
@@ -10,7 +10,7 @@
android:divider=
"?android:attr/dividerHorizontal"
android:orientation=
"horizontal"
android:showDividers=
"middle"
tools:context=
".FriendListActivity"
>
tools:context=
".
ui.
FriendListActivity"
>
<!--
This layout is a two-pane layout for the Friends
...
...
@@ -27,7 +27,7 @@
android:layout_marginLeft=
"16dp"
android:layout_marginRight=
"16dp"
app:layoutManager=
"LinearLayoutManager"
tools:context=
"fr.plnech.dunbar.FriendListActivity"
tools:context=
"fr.plnech.dunbar.
ui.
FriendListActivity"
tools:listitem=
"@layout/friend_list_content"
/>
<FrameLayout
...
...
app/src/main/res/layout/activity_contacts.xml
View file @
d73ffede
...
...
@@ -20,7 +20,7 @@
</com.google.android.material.appbar.AppBarLayout>
<include
layout=
"@layout/content_
friend
s"
/>
<include
layout=
"@layout/content_
contact
s"
/>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id=
"@+id/fab"
...
...
app/src/main/res/layout/activity_friend_detail.xml
View file @
d73ffede
...
...
@@ -5,7 +5,7 @@
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:fitsSystemWindows=
"true"
tools:context=
".FriendDetailActivity"
tools:context=
".
ui.
FriendDetailActivity"
tools:ignore=
"MergeRootFrame"
>
<com.google.android.material.appbar.AppBarLayout
...
...
app/src/main/res/layout/activity_friends_list.xml
View file @
d73ffede
...
...
@@ -5,7 +5,7 @@
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:fitsSystemWindows=
"true"
tools:context=
".FriendListActivity"
>
tools:context=
".
ui.
FriendListActivity"
>
<com.google.android.material.appbar.AppBarLayout
android:id=
"@+id/app_bar"
...
...
app/src/main/res/layout/content_
friend
s.xml
→
app/src/main/res/layout/content_
contact
s.xml
View file @
d73ffede
...
...
@@ -5,32 +5,32 @@
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
app:layout_behavior=
"@string/appbar_scrolling_view_behavior"
tools:context=
".ui.
Friend
sActivity"
tools:showIn=
"@layout/activity_
friend
s"
>
tools:context=
".ui.
Contact
sActivity"
tools:showIn=
"@layout/activity_
contact
s"
>
<TextView
android:id=
"@+id/
welcome
Title"
android:id=
"@+id/
contacts
Title"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginTop=
"8dp"
android:layout_marginBottom=
"8dp"
android:textSize=
"24sp"
app:layout_constraintBottom_toTopOf=
"@id/
friend
sList"
app:layout_constraintBottom_toTopOf=
"@id/
contact
sList"
app:layout_constraintLeft_toLeftOf=
"parent"
app:layout_constraintRight_toRightOf=
"parent"
app:layout_constraintTop_toTopOf=
"parent"
app:layout_constraintVertical_bias=
"0.0"
tools:text=
"N
friends on Dunbar
"
/>
tools:text=
"N
contacts
"
/>
<androidx.recyclerview.widget.RecyclerView
android:id=
"@+id/
friend
sList"
android:id=
"@+id/
contact
sList"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:scrollbars=
"vertical"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintLeft_toLeftOf=
"parent"
app:layout_constraintRight_toRightOf=
"parent"
app:layout_constraintTop_toBottomOf=
"@id/
welcome
Title"
app:layout_constraintTop_toBottomOf=
"@id/
contacts
Title"
tools:listitem=
"@layout/contact"
tools:text=
"@tools:sample/last_names"
/>
...
...
app/src/main/res/layout/friend_detail.xml
View file @
d73ffede
...
...
@@ -7,4 +7,4 @@
android:layout_height=
"match_parent"
android:padding=
"16dp"
android:textIsSelectable=
"true"
tools:context=
".FriendDetailFragment"
/>
\ No newline at end of file
tools:context=
".ui.FriendDetailFragment"
/>
\ No newline at end of file
app/src/main/res/layout/friend_list.xml
View file @
d73ffede
...
...
@@ -9,7 +9,7 @@
tools:showIn=
"@layout/activity_friends"
>
<TextView
android:id=
"@+id/
welcome
Title"
android:id=
"@+id/
contacts
Title"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginTop=
"8dp"
...
...
@@ -30,6 +30,6 @@
android:layout_marginLeft=
"16dp"
android:layout_marginRight=
"16dp"
app:layoutManager=
"LinearLayoutManager"
tools:context=
".FriendListActivity"
tools:context=
".
ui.
FriendListActivity"
tools:listitem=
"@layout/contact"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
app/src/main/res/menu/menu_main.xml
View file @
d73ffede
<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.ui.
Friend
sActivity"
>
tools:context=
"fr.plnech.dunbar.ui.
Contact
sActivity"
>
<item
android:id=
"@+id/action_
friend
s"
android:id=
"@+id/action_
contact
s"
android:orderInCategory=
"100"
android:title=
"@string/action_
friend
s"
android:title=
"@string/action_
contact
s"
app:showAsAction=
"ifRoom"
/>
<item
android:id=
"@+id/action_settings"
...
...
app/src/main/res/values/strings.xml
View file @
d73ffede
...
...
@@ -3,8 +3,9 @@
<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>
<string
name=
"action_
friends"
>
Friend
s
</string>
<string
name=
"action_
contacts"
>
Contact
s
</string>
<string
name=
"title_friend_list"
>
Friends
</string>
<string
name=
"title_friend_detail"
>
Friend Detail
</string>
<string
name=
"text_welcome"
>
"%1$d %2$s on Dunbar"
</string>
<string
name=
"text_contacts"
>
"%1$d contacts"
</string>
</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