feat: FriendsList launch, contacts sub

parent 904b0fde
......@@ -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.FriendsActivity"
android:parentActivityName=".ui.ContactsActivity"
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.FriendsActivity"
android:name=".ui.ContactsActivity"
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>
......
......@@ -15,7 +15,7 @@ fun String.plural(count: Int = 1): String {
}
}
fun Context.fetchFriends(includeNot: Boolean = true): List<Friend> {
fun Context.fetchContacts(includeNot: Boolean = true): List<Friend> {
// TODO: https://developer.android.com/training/permissions/requesting
val friends = mutableListOf<Friend>()
......
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.fetchFriends
import fr.plnech.dunbar.fetchContacts
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_friends.*
import kotlinx.android.synthetic.main.content_contacts.*
import java.util.*
class FriendsActivity : AppCompatActivity() {
class ContactsActivity : AppCompatActivity() {
private lateinit var messages: Messages
private var friends = listOf<Friend>()
private var contacts = listOf<Friend>()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
......@@ -33,20 +29,23 @@ class FriendsActivity : AppCompatActivity() {
// messages = Messages(applicationContext)
fab.setOnClickListener { view ->
reloadFriends()
reloadContacts()
notifyFriend()
}
reloadFriends()
// Show the Up button in the action bar.
supportActionBar?.setDisplayHomeAsUpEnabled(true)
reloadContacts()
notifyFriend()
}
private fun notifyFriend() {
val idNotification = 0
val notRecentlyTalked = friends.filter {
val notRecentlyTalked = contacts.filter {
it.lastDate != null && (Date().time - it.lastDate!!.time) > 1 * 60 * 60 * 1000
}
println("${notRecentlyTalked.size} good old friends I could talk to.")
println("${notRecentlyTalked.size} good old contacts I could talk to.")
val friend = notRecentlyTalked.minBy { it.timesContacted }
......@@ -55,7 +54,7 @@ class FriendsActivity : AppCompatActivity() {
val notification =
FriendReminder(applicationContext).createNotification(
friend,
this@FriendsActivity
this@ContactsActivity
)
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
friendsList.layoutManager = LinearLayoutManager(this)
friendsList.setHasFixedSize(true)
friendsList.adapter = adapter
welcomeTitle.text = getString(R.string.text_welcome).format(nbFriends, "friend".plural(nbFriends))
contactsList.layoutManager = LinearLayoutManager(this)
contactsList.setHasFixedSize(true)
contactsList.adapter = adapter
contactsTitle.text = getString(R.string.text_contacts).format(nbFriends)
}
}
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.*
/**
......
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.*
......
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(
......
......@@ -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
......
......@@ -20,7 +20,7 @@
</com.google.android.material.appbar.AppBarLayout>
<include layout="@layout/content_friends" />
<include layout="@layout/content_contacts" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
......
......@@ -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
......
......@@ -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"
......
......@@ -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.FriendsActivity"
tools:showIn="@layout/activity_friends">
tools:context=".ui.ContactsActivity"
tools:showIn="@layout/activity_contacts">
<TextView
android:id="@+id/welcomeTitle"
android:id="@+id/contactsTitle"
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/friendsList"
app:layout_constraintBottom_toTopOf="@id/contactsList"
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/friendsList"
android:id="@+id/contactsList"
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/welcomeTitle"
app:layout_constraintTop_toBottomOf="@id/contactsTitle"
tools:listitem="@layout/contact"
tools:text="@tools:sample/last_names" />
......
......@@ -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
......@@ -9,7 +9,7 @@
tools:showIn="@layout/activity_friends">
<TextView
android:id="@+id/welcomeTitle"
android:id="@+id/contactsTitle"
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
<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.FriendsActivity">
tools:context="fr.plnech.dunbar.ui.ContactsActivity">
<item
android:id="@+id/action_friends"
android:id="@+id/action_contacts"
android:orderInCategory="100"
android:title="@string/action_friends"
android:title="@string/action_contacts"
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_settings"
......
......@@ -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">Friends</string>
<string name="action_contacts">Contacts</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>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment