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
787746df
Unverified
Commit
787746df
authored
Nov 16, 2019
by
PLN (Algolia)
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(FriendsList): Title
parent
294cff9c
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
152 additions
and
208 deletions
+152
-208
FriendDetailFragment.kt
...src/main/java/fr/plnech/dunbar/ui/FriendDetailFragment.kt
+0
-4
FriendListActivity.kt
app/src/main/java/fr/plnech/dunbar/ui/FriendListActivity.kt
+14
-82
FriendsAdapter.kt
app/src/main/java/fr/plnech/dunbar/ui/FriendsAdapter.kt
+0
-64
FriendsPanesViewAdapter.kt
.../main/java/fr/plnech/dunbar/ui/FriendsPanesViewAdapter.kt
+58
-0
FriendsViewHolder.kt
app/src/main/java/fr/plnech/dunbar/ui/FriendsViewHolder.kt
+73
-0
friend_list.xml
app/src/main/res/layout-w900dp/friend_list.xml
+6
-33
friend_list.xml
app/src/main/res/layout/friend_list.xml
+1
-25
No files found.
app/src/main/java/fr/plnech/dunbar/ui/FriendDetailFragment.kt
View file @
787746df
...
...
@@ -28,13 +28,11 @@ class FriendDetailFragment : Fragment() {
super
.
onCreate
(
savedInstanceState
)
arguments
?.
let
{
println
(
"Got args!"
)
if
(
it
.
containsKey
(
ARG_FRIEND_ID
))
{
// Load the dummy content specified by the fragment
// arguments. In a real-world scenario, use a Loader
// to load content from a content provider.
item
=
DummyContent
.
ITEM_MAP
[
it
.
getInt
(
ARG_FRIEND_ID
)]
println
(
"item: $item"
)
activity
?.
toolbar_layout
?.
title
=
item
?.
name
}
}
...
...
@@ -46,8 +44,6 @@ class FriendDetailFragment : Fragment() {
):
View
?
{
val
rootView
=
inflater
.
inflate
(
R
.
layout
.
friend_detail
,
container
,
false
)
item
?.
let
{
println
(
"Got friend: ${it.name}"
)
activity
?.
title
=
it
.
name
rootView
.
apply
{
friendData
.
text
=
it
.
mapString
()
}
...
...
app/src/main/java/fr/plnech/dunbar/ui/FriendListActivity.kt
View file @
787746df
...
...
@@ -2,21 +2,17 @@ package fr.plnech.dunbar.ui
import
android.content.Intent
import
android.os.Bundle
import
android.view.
*
import
android.
widget.TextView
import
android.view.
Menu
import
android.
view.MenuItem
import
androidx.appcompat.app.AppCompatActivity
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.*
class
FriendListActivity
:
AppCompatActivity
()
{
...
...
@@ -31,12 +27,11 @@ class FriendListActivity : AppCompatActivity() {
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
setContentView
(
R
.
layout
.
activity_friends_list
)
setSupportActionBar
(
toolbar
)
toolbar
.
title
=
title
fab
.
setOnClickListener
{
view
->
Snackbar
.
make
(
view
,
"Replace with your own
action
"
,
Snackbar
.
LENGTH_LONG
)
Snackbar
.
make
(
view
,
"Replace with your own
stuff
"
,
Snackbar
.
LENGTH_LONG
)
.
setAction
(
"Action"
,
null
).
show
()
}
...
...
@@ -48,7 +43,7 @@ class FriendListActivity : AppCompatActivity() {
twoPane
=
true
}
setupRecyclerView
(
friend_list
)
reloadFriends
(
)
}
override
fun
onCreateOptionsMenu
(
menu
:
Menu
?):
Boolean
{
...
...
@@ -71,86 +66,23 @@ class FriendListActivity : AppCompatActivity() {
}
private
fun
reloadFriends
()
{
friends
=
fetchContacts
()
println
(
"Reload"
)
friends
=
DummyContent
.
ITEMS
// FIXME: Persistence
displayFriends
()
// fetchMessages()
}
private
fun
displayFriends
()
{
val
adapter
=
FriendsAdapter
(
friends
)
println
(
"displayF"
)
val
adapter
=
FriendsPanesViewAdapter
(
this
,
friends
,
twoPane
)
val
nbFriends
=
adapter
.
itemCount
contactsL
ist
.
layoutManager
=
LinearLayoutManager
(
this
)
contactsL
ist
.
setHasFixedSize
(
true
)
contactsL
ist
.
adapter
=
adapter
friends_title
.
text
=
friend_l
ist
.
layoutManager
=
LinearLayoutManager
(
this
)
friend_l
ist
.
setHasFixedSize
(
true
)
friend_l
ist
.
adapter
=
adapter
val
welcomeFriends
=
getString
(
R
.
string
.
text_welcome
).
format
(
nbFriends
,
"friend"
.
plural
(
nbFriends
))
}
private
fun
setupRecyclerView
(
recyclerView
:
RecyclerView
)
{
recyclerView
.
adapter
=
SimpleItemRecyclerViewAdapter
(
this
,
DummyContent
.
ITEMS
,
twoPane
)
}
class
SimpleItemRecyclerViewAdapter
(
private
val
parentActivity
:
FriendListActivity
,
private
val
values
:
List
<
Friend
>,
private
val
twoPane
:
Boolean
)
:
RecyclerView
.
Adapter
<
SimpleItemRecyclerViewAdapter
.
ViewHolder
>()
{
private
val
onClickListener
:
View
.
OnClickListener
init
{
onClickListener
=
View
.
OnClickListener
{
v
->
val
friend
=
v
.
tag
as
Friend
if
(
twoPane
)
{
val
fragment
=
FriendDetailFragment
().
apply
{
arguments
=
Bundle
().
apply
{
putInt
(
FriendDetailFragment
.
ARG_FRIEND_ID
,
friend
.
id
)
println
(
"Put arg: ${friend.id}"
)
}
}
parentActivity
.
supportFragmentManager
.
beginTransaction
()
.
replace
(
R
.
id
.
friend_detail_container
,
fragment
)
.
commit
()
}
else
{
val
intent
=
Intent
(
v
.
context
,
FriendDetailActivity
::
class
.
java
).
apply
{
putExtra
(
FriendDetailFragment
.
ARG_FRIEND_ID
,
friend
.
id
)
println
(
"Put arg: ${friend.id}"
)
}
v
.
context
.
startActivity
(
intent
)
}
}
}
override
fun
onCreateViewHolder
(
parent
:
ViewGroup
,
viewType
:
Int
):
ViewHolder
{
val
view
=
LayoutInflater
.
from
(
parent
.
context
)
.
inflate
(
R
.
layout
.
friend_list_content
,
parent
,
false
)
return
ViewHolder
(
view
)
}
override
fun
onBindViewHolder
(
holder
:
ViewHolder
,
position
:
Int
)
{
val
item
=
values
[
position
]
holder
.
idView
.
text
=
item
.
name
holder
.
contentView
.
text
=
item
.
mapString
()
with
(
holder
.
itemView
)
{
tag
=
item
setOnClickListener
(
onClickListener
)
}
}
override
fun
getItemCount
()
=
values
.
size
inner
class
ViewHolder
(
view
:
View
)
:
RecyclerView
.
ViewHolder
(
view
)
{
val
idView
:
TextView
=
view
.
id_text
val
contentView
:
TextView
=
view
.
content
}
title
=
welcomeFriends
println
(
"Welcome: $welcomeFriends"
)
}
}
app/src/main/java/fr/plnech/dunbar/ui/FriendsAdapter.kt
View file @
787746df
package
fr.plnech.dunbar.ui
import
android.text.format.DateUtils
import
android.view.LayoutInflater
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_listitem.view.*
class
FriendsAdapter
(
...
...
@@ -27,62 +23,3 @@ class FriendsAdapter(
override
fun
onBindViewHolder
(
holder
:
FriendsViewHolder
,
position
:
Int
):
Unit
=
holder
.
bind
(
friends
[
position
])
}
\ No newline at end of file
class
FriendsViewHolder
(
private
val
view
:
View
)
:
RecyclerView
.
ViewHolder
(
view
)
{
private
val
name
=
view
.
contactName
private
val
data
=
view
.
contactData
private
val
phone
=
view
.
contactPhone
private
val
callButton
=
view
.
contactCall
private
val
smsButton
=
view
.
contactText
private
val
pic
=
view
.
pic
fun
bind
(
friend
:
Friend
)
{
name
.
text
=
friend
.
name
data
.
text
=
buildDataString
(
friend
)
bindPhone
(
friend
)
bindPic
(
friend
)
bindClick
(
friend
)
}
private
fun
bindPhone
(
friend
:
Friend
)
{
friend
.
phone
?.
let
{
phone
.
text
=
it
mapOf
(
callButton
to
friend
.
callIntent
(),
smsButton
to
friend
.
smsIntent
()
).
entries
.
forEach
{
pair
->
pair
.
key
.
apply
{
visibility
=
View
.
VISIBLE
setOnClickListener
{
view
.
context
.
startActivity
(
pair
.
value
)
}
}
}
}
}
private
fun
bindPic
(
friend
:
Friend
)
{
pic
.
setImageBitmap
(
friend
.
photo
)
}
private
fun
bindClick
(
friend
:
Friend
)
{
view
.
setOnClickListener
{
Toast
.
makeText
(
view
.
context
,
friend
.
mapString
(),
Toast
.
LENGTH_LONG
).
show
()
println
(
friend
.
mapString
())
}
}
private
fun
buildDataString
(
friend
:
Friend
):
String
{
return
buildString
{
if
(
friend
.
lastDate
!=
null
)
{
append
(
friend
.
timesContacted
)
append
(
" interactions, last "
)
append
(
DateUtils
.
getRelativeTimeSpanString
(
friend
.
lastTimeStamp
))
}
else
{
append
(
"Never interacted"
)
}
}
}
}
app/src/main/java/fr/plnech/dunbar/ui/FriendsPanesViewAdapter.kt
0 → 100644
View file @
787746df
package
fr.plnech.dunbar.ui
import
android.content.Intent
import
android.os.Bundle
import
android.view.LayoutInflater
import
android.view.View
import
android.view.ViewGroup
import
androidx.recyclerview.widget.RecyclerView
import
fr.plnech.dunbar.R
import
fr.plnech.dunbar.model.Friend
class
FriendsPanesViewAdapter
(
private
val
parentActivity
:
FriendListActivity
,
private
val
friends
:
List
<
Friend
>,
private
val
twoPane
:
Boolean
)
:
RecyclerView
.
Adapter
<
FriendsViewHolder
>()
{
private
val
onClickListener
:
View
.
OnClickListener
init
{
onClickListener
=
View
.
OnClickListener
{
v
->
val
friend
=
v
.
tag
as
Friend
if
(
twoPane
)
{
val
fragment
=
FriendDetailFragment
().
apply
{
arguments
=
Bundle
().
apply
{
putInt
(
FriendDetailFragment
.
ARG_FRIEND_ID
,
friend
.
id
)
}
}
parentActivity
.
supportFragmentManager
.
beginTransaction
()
.
replace
(
R
.
id
.
friend_detail_container
,
fragment
)
.
commit
()
}
else
{
val
intent
=
Intent
(
v
.
context
,
FriendDetailActivity
::
class
.
java
).
apply
{
putExtra
(
FriendDetailFragment
.
ARG_FRIEND_ID
,
friend
.
id
)
}
v
.
context
.
startActivity
(
intent
)
}
}
}
override
fun
onCreateViewHolder
(
parent
:
ViewGroup
,
viewType
:
Int
):
FriendsViewHolder
{
return
FriendsViewHolder
(
LayoutInflater
.
from
(
parent
.
context
).
inflate
(
R
.
layout
.
contact_listitem
,
parent
,
false
)
)
}
override
fun
onBindViewHolder
(
holder
:
FriendsViewHolder
,
position
:
Int
)
{
holder
.
bind
(
friends
[
position
])
{
onClickListener
.
onClick
(
it
)
}
}
override
fun
getItemCount
()
=
friends
.
size
}
\ No newline at end of file
app/src/main/java/fr/plnech/dunbar/ui/FriendsViewHolder.kt
0 → 100644
View file @
787746df
package
fr.plnech.dunbar.ui
import
android.text.format.DateUtils
import
android.view.View
import
android.widget.Toast
import
androidx.recyclerview.widget.RecyclerView
import
fr.plnech.dunbar.model.Friend
import
kotlinx.android.synthetic.main.contact_listitem.view.*
class
FriendsViewHolder
(
private
val
view
:
View
)
:
RecyclerView
.
ViewHolder
(
view
)
{
private
val
name
=
view
.
contactName
private
val
data
=
view
.
contactData
private
val
phone
=
view
.
contactPhone
private
val
callButton
=
view
.
contactCall
private
val
smsButton
=
view
.
contactText
private
val
pic
=
view
.
pic
fun
bind
(
friend
:
Friend
,
onClickListener
:
((
View
)
->
Unit
)?
=
null
)
{
name
.
text
=
friend
.
name
data
.
text
=
buildDataString
(
friend
)
view
.
tag
=
friend
bindPhone
(
friend
)
bindPic
(
friend
)
bindClick
(
friend
,
onClickListener
)
}
private
fun
bindPhone
(
friend
:
Friend
)
{
friend
.
phone
?.
let
{
phone
.
text
=
it
mapOf
(
callButton
to
friend
.
callIntent
(),
smsButton
to
friend
.
smsIntent
()
).
entries
.
forEach
{
pair
->
pair
.
key
.
apply
{
visibility
=
View
.
VISIBLE
setOnClickListener
{
view
.
context
.
startActivity
(
pair
.
value
)
}
}
}
}
}
private
fun
bindPic
(
friend
:
Friend
)
{
pic
.
setImageBitmap
(
friend
.
photo
)
}
private
fun
bindClick
(
friend
:
Friend
,
onClickListener
:
((
View
)
->
Unit
)?
=
null
)
{
view
.
setOnClickListener
(
onClickListener
?:
{
Toast
.
makeText
(
view
.
context
,
friend
.
mapString
(),
Toast
.
LENGTH_LONG
).
show
()
println
(
friend
.
mapString
())
})
}
private
fun
buildDataString
(
friend
:
Friend
):
String
{
return
buildString
{
if
(
friend
.
lastDate
!=
null
)
{
append
(
friend
.
timesContacted
)
append
(
" interactions, last "
)
append
(
DateUtils
.
getRelativeTimeSpanString
(
friend
.
lastTimeStamp
))
}
else
{
append
(
"Never interacted"
)
}
}
}
}
\ No newline at end of file
app/src/main/res/layout-w900dp/friend_list.xml
View file @
787746df
<?xml version="1.0" encoding="utf-8"?>
<
androidx.constraintlayout.widget.Constraint
Layout
xmlns:android=
"http://schemas.android.com/apk/res/android"
<
Linear
Layout
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"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
>
<TextView
android:id=
"@+id/friends_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/panes"
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"
/>
<LinearLayout
android:id=
"@+id/panes"
app:layout_constraintTop_toBottomOf=
"@id/friends_title"
app:layout_constraintLeft_toLeftOf=
"parent"
app:layout_constraintRight_toRightOf=
"parent"
app:layout_constraintBottom_toBottomOf=
"parent"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:layout_marginLeft=
"16dp"
...
...
@@ -35,14 +12,10 @@
android:showDividers=
"middle"
tools:context=
".ui.FriendListActivity"
>
<!--
This layout is a two-pane layout for the Friends
master/detail flow.
<!-- This layout is a two-pane layout for the Friends
master/detail flow. -->
-->
<androidx.recyclerview.widget.RecyclerView
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:tools=
"http://schemas.android.com/tools"
<androidx.recyclerview.widget.RecyclerView
android:id=
"@+id/friend_list"
android:name=
"fr.plnech.dunbar.FriendListFragment"
android:layout_width=
"@dimen/item_width"
...
...
@@ -59,5 +32,4 @@
android:layout_height=
"match_parent"
android:layout_weight=
"3"
/>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
\ No newline at end of file
app/src/main/res/layout/friend_list.xml
View file @
787746df
<?xml version="1.0" encoding="utf-8"?>
<androidx.
constraintlayout.widget.ConstraintLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
<androidx.
recyclerview.widget.RecyclerView
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"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
app:layout_behavior=
"@string/appbar_scrolling_view_behavior"
tools:context=
".ui.ContactsActivity"
tools:showIn=
"@layout/activity_friends_list"
>
<TextView
android:id=
"@+id/friends_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_list"
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"
/>
<androidx.recyclerview.widget.RecyclerView
android:id=
"@+id/friend_list"
android:name=
"fr.plnech.dunbar.FriendListFragment"
android:layout_width=
"match_parent"
...
...
@@ -32,4 +11,3 @@
app:layoutManager=
"LinearLayoutManager"
tools:context=
".ui.FriendListActivity"
tools:listitem=
"@layout/contact_listitem"
/>
\ No newline at end of file
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
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