From d73ffede10eb814d853f31f0a74a8272dc469b85 Mon Sep 17 00:00:00 2001 From: Paul-Louis NECH Date: Sat, 16 Nov 2019 14:37:52 +0100 Subject: [PATCH] feat: FriendsList launch, contacts sub --- app/src/main/AndroidManifest.xml | 29 +++++++++++++++-------------- app/src/main/java/fr/plnech/dunbar/Extensions.kt | 2 +- app/src/main/java/fr/plnech/dunbar/FriendDetailActivity.kt | 52 ---------------------------------------------------- app/src/main/java/fr/plnech/dunbar/FriendDetailFragment.kt | 62 -------------------------------------------------------------- app/src/main/java/fr/plnech/dunbar/FriendListActivity.kt | 121 ------------------------------------------------------------------------------------------------------------------------- app/src/main/java/fr/plnech/dunbar/ui/ContactsActivity.kt | 75 ++++++++++++++++++++++++++------------------------------------------------- app/src/main/java/fr/plnech/dunbar/ui/FriendDetailActivity.kt | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ app/src/main/java/fr/plnech/dunbar/ui/FriendDetailFragment.kt | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ app/src/main/java/fr/plnech/dunbar/ui/FriendListActivity.kt | 153 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ app/src/main/res/layout-w900dp/friend_list.xml | 4 ++-- app/src/main/res/layout/activity_contacts.xml | 2 +- app/src/main/res/layout/activity_friend_detail.xml | 2 +- app/src/main/res/layout/activity_friends_list.xml | 2 +- app/src/main/res/layout/content_contacts.xml | 37 +++++++++++++++++++++++++++++++++++++ app/src/main/res/layout/content_friends.xml | 37 ------------------------------------- app/src/main/res/layout/friend_detail.xml | 2 +- app/src/main/res/layout/friend_list.xml | 4 ++-- app/src/main/res/menu/menu_main.xml | 6 +++--- app/src/main/res/values/strings.xml | 3 ++- 19 files changed, 361 insertions(+), 348 deletions(-) delete mode 100644 app/src/main/java/fr/plnech/dunbar/FriendDetailActivity.kt delete mode 100644 app/src/main/java/fr/plnech/dunbar/FriendDetailFragment.kt delete mode 100644 app/src/main/java/fr/plnech/dunbar/FriendListActivity.kt create mode 100644 app/src/main/java/fr/plnech/dunbar/ui/FriendDetailActivity.kt create mode 100644 app/src/main/java/fr/plnech/dunbar/ui/FriendDetailFragment.kt create mode 100644 app/src/main/java/fr/plnech/dunbar/ui/FriendListActivity.kt create mode 100644 app/src/main/res/layout/content_contacts.xml delete mode 100644 app/src/main/res/layout/content_friends.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index c0f04bd..39b01c7 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -18,32 +18,33 @@ - + + + + + + + android:value="fr.plnech.dunbar.ui.FriendListActivity" /> - - - - - + diff --git a/app/src/main/java/fr/plnech/dunbar/Extensions.kt b/app/src/main/java/fr/plnech/dunbar/Extensions.kt index 35ae3eb..a1f9449 100644 --- a/app/src/main/java/fr/plnech/dunbar/Extensions.kt +++ b/app/src/main/java/fr/plnech/dunbar/Extensions.kt @@ -15,7 +15,7 @@ fun String.plural(count: Int = 1): String { } } -fun Context.fetchFriends(includeNot: Boolean = true): List { +fun Context.fetchContacts(includeNot: Boolean = true): List { // TODO: https://developer.android.com/training/permissions/requesting val friends = mutableListOf() diff --git a/app/src/main/java/fr/plnech/dunbar/FriendDetailActivity.kt b/app/src/main/java/fr/plnech/dunbar/FriendDetailActivity.kt deleted file mode 100644 index 3a1f589..0000000 --- a/app/src/main/java/fr/plnech/dunbar/FriendDetailActivity.kt +++ /dev/null @@ -1,52 +0,0 @@ -package fr.plnech.dunbar - -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 kotlinx.android.synthetic.main.activity_friend_detail.* - -/** - * An activity representing a single Friend detail screen. This - * activity is only used on narrow width devices. On tablet-size devices, - * item details are presented side-by-side with a list of items - * in a [FriendListActivity]. - */ -class FriendDetailActivity : AppCompatActivity() { - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - setContentView(R.layout.activity_friend_detail) - setSupportActionBar(detail_toolbar) - - fab.setOnClickListener { view -> - Snackbar.make(view, "Replace with your own detail action", Snackbar.LENGTH_LONG) - .setAction("Action", null).show() - } - - supportActionBar?.setDisplayHomeAsUpEnabled(true) - - if (savedInstanceState == null) { - supportFragmentManager.beginTransaction() - .add(R.id.friend_detail_container, FriendDetailFragment().apply { - arguments = Bundle().apply { - putString( - FriendDetailFragment.ARG_ITEM_ID, - intent.getStringExtra(FriendDetailFragment.ARG_ITEM_ID) - ) - } - }) - .commit() - } - } - - override fun onOptionsItemSelected(item: MenuItem) = - when (item.itemId) { - android.R.id.home -> { - navigateUpTo(Intent(this, FriendListActivity::class.java)) - true - } - else -> super.onOptionsItemSelected(item) - } -} diff --git a/app/src/main/java/fr/plnech/dunbar/FriendDetailFragment.kt b/app/src/main/java/fr/plnech/dunbar/FriendDetailFragment.kt deleted file mode 100644 index 7c3f482..0000000 --- a/app/src/main/java/fr/plnech/dunbar/FriendDetailFragment.kt +++ /dev/null @@ -1,62 +0,0 @@ -package fr.plnech.dunbar - -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.dummy.DummyContent -import fr.plnech.dunbar.model.Friend -import kotlinx.android.synthetic.main.activity_friend_detail.* -import kotlinx.android.synthetic.main.friend_detail.view.* - -/** - * A fragment representing a single Friend detail screen. - * This fragment is either contained in a [FriendListActivity] - * in two-pane mode (on tablets) or a [FriendDetailActivity] - * on handsets. - */ -class FriendDetailFragment : Fragment() { - - /** - * The dummy content this fragment is presenting. - */ - private var item: Friend? = null - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - - arguments?.let { - if (it.containsKey(ARG_ITEM_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_ITEM_ID)] - activity?.toolbar_layout?.title = item?.name - } - } - } - - override fun onCreateView( - inflater: LayoutInflater, container: ViewGroup?, - savedInstanceState: Bundle? - ): View? { - val rootView = inflater.inflate(R.layout.friend_detail, container, false) - - // Show the dummy content as text in a TextView. - item?.let { - rootView.friend_detail.text = it.mapString() - activity?.title = it.name - } - - return rootView - } - - companion object { - /** - * The fragment argument representing the item ID that this fragment - * represents. - */ - const val ARG_ITEM_ID = "item_id" - } -} diff --git a/app/src/main/java/fr/plnech/dunbar/FriendListActivity.kt b/app/src/main/java/fr/plnech/dunbar/FriendListActivity.kt deleted file mode 100644 index adaa4fb..0000000 --- a/app/src/main/java/fr/plnech/dunbar/FriendListActivity.kt +++ /dev/null @@ -1,121 +0,0 @@ -package fr.plnech.dunbar - -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.widget.TextView -import androidx.appcompat.app.AppCompatActivity -import androidx.core.app.NavUtils -import androidx.recyclerview.widget.RecyclerView -import com.google.android.material.snackbar.Snackbar -import fr.plnech.dunbar.dummy.DummyContent -import fr.plnech.dunbar.model.Friend -import kotlinx.android.synthetic.main.activity_friends_list.* -import kotlinx.android.synthetic.main.friend_list.* -import kotlinx.android.synthetic.main.friend_list_content.view.* - -class FriendListActivity : AppCompatActivity() { - - /** - * Whether or not the activity is in two-pane mode, i.e. running on a tablet - * device. - */ - private var twoPane: Boolean = false - - 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) - .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 - // large-screen layouts (res/values-w900dp). - // If this view is present, then the - // activity should be in two-pane mode. - twoPane = true - } - - setupRecyclerView(friend_list) - } - - override fun onOptionsItemSelected(item: MenuItem) = - when (item.itemId) { - android.R.id.home -> { - NavUtils.navigateUpFromSameTask(this) - true - } - else -> super.onOptionsItemSelected(item) - } - - private fun setupRecyclerView(recyclerView: RecyclerView) { - recyclerView.adapter = SimpleItemRecyclerViewAdapter(this, DummyContent.ITEMS, twoPane) - } - - class SimpleItemRecyclerViewAdapter( - private val parentActivity: FriendListActivity, - private val values: List, - private val twoPane: Boolean - ) : - RecyclerView.Adapter() { - - private val onClickListener: View.OnClickListener - - init { - onClickListener = View.OnClickListener { v -> - val item = v.tag as Friend - if (twoPane) { - val fragment = FriendDetailFragment().apply { - arguments = Bundle().apply { - putString(FriendDetailFragment.ARG_ITEM_ID, "friend_${item.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_ITEM_ID, "friend_${item.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 - } - } -} diff --git a/app/src/main/java/fr/plnech/dunbar/ui/ContactsActivity.kt b/app/src/main/java/fr/plnech/dunbar/ui/ContactsActivity.kt index a3aadba..9ca5a1d 100644 --- a/app/src/main/java/fr/plnech/dunbar/ui/ContactsActivity.kt +++ b/app/src/main/java/fr/plnech/dunbar/ui/ContactsActivity.kt @@ -1,29 +1,25 @@ 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() + private var contacts = listOf() 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) } - } diff --git a/app/src/main/java/fr/plnech/dunbar/ui/FriendDetailActivity.kt b/app/src/main/java/fr/plnech/dunbar/ui/FriendDetailActivity.kt new file mode 100644 index 0000000..465c2c5 --- /dev/null +++ b/app/src/main/java/fr/plnech/dunbar/ui/FriendDetailActivity.kt @@ -0,0 +1,53 @@ +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.* + +/** + * An activity representing a single Friend detail screen. This + * activity is only used on narrow width devices. On tablet-size devices, + * item details are presented side-by-side with a list of items + * in a [FriendListActivity]. + */ +class FriendDetailActivity : AppCompatActivity() { + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_friend_detail) + setSupportActionBar(detail_toolbar) + + fab.setOnClickListener { view -> + Snackbar.make(view, "Replace with your own detail action", Snackbar.LENGTH_LONG) + .setAction("Action", null).show() + } + + supportActionBar?.setDisplayHomeAsUpEnabled(true) + + if (savedInstanceState == null) { + supportFragmentManager.beginTransaction() + .add(R.id.friend_detail_container, FriendDetailFragment().apply { + arguments = Bundle().apply { + putString( + FriendDetailFragment.ARG_ITEM_ID, + intent.getStringExtra(FriendDetailFragment.ARG_ITEM_ID) + ) + } + }) + .commit() + } + } + + override fun onOptionsItemSelected(item: MenuItem) = + when (item.itemId) { + android.R.id.home -> { + navigateUpTo(Intent(this, FriendListActivity::class.java)) + true + } + else -> super.onOptionsItemSelected(item) + } +} diff --git a/app/src/main/java/fr/plnech/dunbar/ui/FriendDetailFragment.kt b/app/src/main/java/fr/plnech/dunbar/ui/FriendDetailFragment.kt new file mode 100644 index 0000000..a2d3ca1 --- /dev/null +++ b/app/src/main/java/fr/plnech/dunbar/ui/FriendDetailFragment.kt @@ -0,0 +1,63 @@ +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.* +import kotlinx.android.synthetic.main.friend_detail.view.* + +/** + * A fragment representing a single Friend detail screen. + * This fragment is either contained in a [FriendListActivity] + * in two-pane mode (on tablets) or a [FriendDetailActivity] + * on handsets. + */ +class FriendDetailFragment : Fragment() { + + /** + * The dummy content this fragment is presenting. + */ + private var item: Friend? = null + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + arguments?.let { + if (it.containsKey(ARG_ITEM_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_ITEM_ID)] + activity?.toolbar_layout?.title = item?.name + } + } + } + + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + val rootView = inflater.inflate(R.layout.friend_detail, container, false) + + // Show the dummy content as text in a TextView. + item?.let { + rootView.friend_detail.text = it.mapString() + activity?.title = it.name + } + + return rootView + } + + companion object { + /** + * The fragment argument representing the item ID that this fragment + * represents. + */ + const val ARG_ITEM_ID = "item_id" + } +} diff --git a/app/src/main/java/fr/plnech/dunbar/ui/FriendListActivity.kt b/app/src/main/java/fr/plnech/dunbar/ui/FriendListActivity.kt new file mode 100644 index 0000000..66b4530 --- /dev/null +++ b/app/src/main/java/fr/plnech/dunbar/ui/FriendListActivity.kt @@ -0,0 +1,153 @@ +package fr.plnech.dunbar.ui + +import android.content.Intent +import android.os.Bundle +import android.view.* +import android.widget.TextView +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() { + + /** + * Whether or not the activity is in two-pane mode, i.e. running on a tablet + * device. + */ + private var twoPane: Boolean = false + + private var friends = listOf() + + 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) + .setAction("Action", null).show() + } + + if (friend_detail_container != null) { + // The detail container view will be present only in the + // large-screen layouts (res/values-w900dp). + // If this view is present, then the + // activity should be in two-pane mode. + twoPane = true + } + + setupRecyclerView(friend_list) + } + + 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 + ) + } + + class SimpleItemRecyclerViewAdapter( + private val parentActivity: FriendListActivity, + private val values: List, + private val twoPane: Boolean + ) : + RecyclerView.Adapter() { + + private val onClickListener: View.OnClickListener + + init { + onClickListener = View.OnClickListener { v -> + val item = v.tag as Friend + if (twoPane) { + val fragment = FriendDetailFragment().apply { + arguments = Bundle().apply { + putString(FriendDetailFragment.ARG_ITEM_ID, "friend_${item.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_ITEM_ID, "friend_${item.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 + } + } +} diff --git a/app/src/main/res/layout-w900dp/friend_list.xml b/app/src/main/res/layout-w900dp/friend_list.xml index f5abd42..c527b19 100644 --- a/app/src/main/res/layout-w900dp/friend_list.xml +++ b/app/src/main/res/layout-w900dp/friend_list.xml @@ -10,7 +10,7 @@ android:divider="?android:attr/dividerHorizontal" android:orientation="horizontal" android:showDividers="middle" - tools:context=".FriendListActivity"> + tools:context=".ui.FriendListActivity">