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
58e90f84
Unverified
Commit
58e90f84
authored
Nov 02, 2019
by
PLN (Algolia)
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: Cleaner adapter/detail
parent
acacc970
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
67 additions
and
28 deletions
+67
-28
TODO.md
TODO.md
+2
-0
FriendsAdapter.kt
app/src/main/java/fr/plnech/dunbar/ui/FriendsAdapter.kt
+36
-13
contact.xml
app/src/main/res/layout/contact.xml
+29
-15
No files found.
TODO.md
View file @
58e90f84
...
...
@@ -2,6 +2,8 @@
-
List friends
-
Remind daily
-
Select best friend to remind of
-
Keep track of reminded?
-
Stats
-
Quick increment
...
...
app/src/main/java/fr/plnech/dunbar/ui/FriendsAdapter.kt
View file @
58e90f84
...
...
@@ -37,37 +37,60 @@ class FriendsAdapter(
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
=
buildString
{
if
(
friend
.
lastDate
!=
null
)
{
data
.
text
=
buildDataString
(
friend
)
bindPhone
(
friend
)
bindPic
(
friend
)
bindClick
(
friend
)
}
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"
)
}
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"
)
private
fun
bindClick
(
friend
:
Friend
)
{
view
.
setOnClickListener
{
Toast
.
makeText
(
view
.
context
,
friend
.
mapString
(),
Toast
.
LENGTH_LONG
).
show
()
println
(
friend
.
mapString
())
}
}
private
fun
bindPic
(
friend
:
Friend
)
{
friend
.
photo
?.
let
{
pic
.
setImageBitmap
(
it
)
}
}
view
.
setOnClickListener
{
Toast
.
makeText
(
view
.
context
,
friend
.
mapString
(),
Toast
.
LENGTH_LONG
).
show
()
println
(
friend
.
mapString
())
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
)
}
}
}
}
}
...
...
app/src/main/res/layout/contact.xml
View file @
58e90f84
...
...
@@ -24,7 +24,7 @@
android:elevation=
"2dp"
android:src=
"@drawable/user"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraint
Right_toLef
tOf=
"@id/contactName"
app:layout_constraint
End_toStar
tOf=
"@id/contactName"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_toTopOf=
"parent"
/>
...
...
@@ -40,8 +40,7 @@
android:textAppearance=
"@style/TextAppearance.AppCompat.Title"
app:layout_constraintBottom_toTopOf=
"@id/contactData"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintLeft_toRightOf=
"@id/pic"
app:layout_constraintRight_toLeftOf=
"@id/contactName"
app:layout_constraintStart_toEndOf=
"@id/pic"
app:layout_constraintTop_toTopOf=
"parent"
tools:text=
"@tools:sample/full_names"
/>
...
...
@@ -50,6 +49,21 @@
android:layout_width=
"0dp"
android:layout_height=
"wrap_content"
android:layout_marginEnd=
"15dp"
android:focusable=
"false"
android:focusableInTouchMode=
"false"
android:gravity=
"end"
android:textAppearance=
"@style/TextAppearance.AppCompat.Subhead"
app:layout_constraintBottom_toTopOf=
"@id/contactPhone"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintStart_toEndOf=
"@id/pic"
app:layout_constraintTop_toBottomOf=
"@id/contactName"
tools:text=
"2 interactions, last 1 hour ago"
/>
<TextView
android:id=
"@+id/contactPhone"
android:layout_width=
"0dp"
android:layout_height=
"wrap_content"
android:layout_marginEnd=
"15dp"
android:layout_marginBottom=
"15dp"
android:focusable=
"false"
android:focusableInTouchMode=
"false"
...
...
@@ -57,27 +71,27 @@
android:textAppearance=
"@style/TextAppearance.AppCompat.Subhead"
app:layout_constraintBottom_toTopOf=
"@id/contactCall"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintLeft_toRightOf=
"@id/contactText"
app:layout_constraintRight_toLeftOf=
"@id/contactName"
app:layout_constraintTop_toBottomOf=
"@id/contactName"
tools:text=
"2 interactions, last 1 hour ago"
/>
app:layout_constraintStart_toEndOf=
"@+id/pic"
app:layout_constraintTop_toBottomOf=
"@id/contactData"
tools:text=
"0213 456"
/>
<com.google.android.material.button.MaterialButton
android:id=
"@+id/contactText"
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:layout_marginEnd=
"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"
app:layout_constraintLeft_toRightOf=
"@id/pic"
app:layout_constraintRight_toLeftOf=
"@id/contactCall"
app:layout_constraintTop_toBottomOf=
"@id/contactData"
/>
app:layout_constraintEnd_toStartOf=
"@id/contactCall"
app:layout_constraintStart_toEndOf=
"@id/pic"
app:layout_constraintTop_toBottomOf=
"@id/contactPhone"
tools:visibility=
"visible"
/>
<com.google.android.material.button.MaterialButton
android:id=
"@+id/contactCall"
...
...
@@ -86,14 +100,14 @@
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: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"
/>
app:layout_constraintStart_toEndOf=
"@id/contactText"
app:layout_constraintTop_toBottomOf=
"@id/contactPhone"
tools:visibility=
"visible"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
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