From 294cff9cf067260d3a52ce5c12cff8efeb4c36c5 Mon Sep 17 00:00:00 2001 From: Paul-Louis NECH Date: Sat, 16 Nov 2019 15:07:25 +0100 Subject: [PATCH] fix: working friends master/details --- app/src/main/java/fr/plnech/dunbar/ui/FriendDetailActivity.kt | 6 +++--- app/src/main/java/fr/plnech/dunbar/ui/FriendDetailFragment.kt | 15 +++++++++------ app/src/main/java/fr/plnech/dunbar/ui/FriendListActivity.kt | 11 +++++++---- app/src/main/java/fr/plnech/dunbar/ui/FriendsAdapter.kt | 5 ++--- app/src/main/res/layout-w900dp/friend_list.xml | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------- app/src/main/res/layout/contact.xml | 117 --------------------------------------------------------------------------------------------------------------------- app/src/main/res/layout/contact_listitem.xml | 117 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ app/src/main/res/layout/contacts.xml | 7 ------- app/src/main/res/layout/contacts_listview.xml | 7 +++++++ app/src/main/res/layout/content_contacts.xml | 2 +- app/src/main/res/layout/friend_detail.xml | 29 ++++++++++++++++++++++------- app/src/main/res/layout/friend_list.xml | 6 +++--- 12 files changed, 224 insertions(+), 180 deletions(-) delete mode 100644 app/src/main/res/layout/contact.xml create mode 100644 app/src/main/res/layout/contact_listitem.xml delete mode 100644 app/src/main/res/layout/contacts.xml create mode 100644 app/src/main/res/layout/contacts_listview.xml diff --git a/app/src/main/java/fr/plnech/dunbar/ui/FriendDetailActivity.kt b/app/src/main/java/fr/plnech/dunbar/ui/FriendDetailActivity.kt index 465c2c5..26f93b9 100644 --- a/app/src/main/java/fr/plnech/dunbar/ui/FriendDetailActivity.kt +++ b/app/src/main/java/fr/plnech/dunbar/ui/FriendDetailActivity.kt @@ -32,9 +32,9 @@ class FriendDetailActivity : AppCompatActivity() { supportFragmentManager.beginTransaction() .add(R.id.friend_detail_container, FriendDetailFragment().apply { arguments = Bundle().apply { - putString( - FriendDetailFragment.ARG_ITEM_ID, - intent.getStringExtra(FriendDetailFragment.ARG_ITEM_ID) + putInt( + FriendDetailFragment.ARG_FRIEND_ID, + intent.getIntExtra(FriendDetailFragment.ARG_FRIEND_ID, -1) ) } }) diff --git a/app/src/main/java/fr/plnech/dunbar/ui/FriendDetailFragment.kt b/app/src/main/java/fr/plnech/dunbar/ui/FriendDetailFragment.kt index a2d3ca1..1bca735 100644 --- a/app/src/main/java/fr/plnech/dunbar/ui/FriendDetailFragment.kt +++ b/app/src/main/java/fr/plnech/dunbar/ui/FriendDetailFragment.kt @@ -28,11 +28,13 @@ class FriendDetailFragment : Fragment() { super.onCreate(savedInstanceState) arguments?.let { - if (it.containsKey(ARG_ITEM_ID)) { + 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_ITEM_ID)] + item = DummyContent.ITEM_MAP[it.getInt(ARG_FRIEND_ID)] + println("item: $item") activity?.toolbar_layout?.title = item?.name } } @@ -43,11 +45,12 @@ class FriendDetailFragment : Fragment() { 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() + println("Got friend: ${it.name}") activity?.title = it.name + rootView.apply { + friendData.text = it.mapString() + } } return rootView @@ -58,6 +61,6 @@ class FriendDetailFragment : Fragment() { * The fragment argument representing the item ID that this fragment * represents. */ - const val ARG_ITEM_ID = "item_id" + const val ARG_FRIEND_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 index 66b4530..a775b7a 100644 --- a/app/src/main/java/fr/plnech/dunbar/ui/FriendListActivity.kt +++ b/app/src/main/java/fr/plnech/dunbar/ui/FriendListActivity.kt @@ -83,7 +83,8 @@ class FriendListActivity : AppCompatActivity() { contactsList.layoutManager = LinearLayoutManager(this) contactsList.setHasFixedSize(true) contactsList.adapter = adapter - `@+id/contactsTitle`.text = getString(R.string.text_welcome).format(nbFriends, "friend".plural(nbFriends)) + friends_title.text = + getString(R.string.text_welcome).format(nbFriends, "friend".plural(nbFriends)) } @@ -106,11 +107,12 @@ class FriendListActivity : AppCompatActivity() { init { onClickListener = View.OnClickListener { v -> - val item = v.tag as Friend + val friend = v.tag as Friend if (twoPane) { val fragment = FriendDetailFragment().apply { arguments = Bundle().apply { - putString(FriendDetailFragment.ARG_ITEM_ID, "friend_${item.id}") + putInt(FriendDetailFragment.ARG_FRIEND_ID, friend.id) + println("Put arg: ${friend.id}") } } parentActivity.supportFragmentManager @@ -119,7 +121,8 @@ class FriendListActivity : AppCompatActivity() { .commit() } else { val intent = Intent(v.context, FriendDetailActivity::class.java).apply { - putExtra(FriendDetailFragment.ARG_ITEM_ID, "friend_${item.id}") + putExtra(FriendDetailFragment.ARG_FRIEND_ID, friend.id) + println("Put arg: ${friend.id}") } v.context.startActivity(intent) } diff --git a/app/src/main/java/fr/plnech/dunbar/ui/FriendsAdapter.kt b/app/src/main/java/fr/plnech/dunbar/ui/FriendsAdapter.kt index c57213b..346c329 100644 --- a/app/src/main/java/fr/plnech/dunbar/ui/FriendsAdapter.kt +++ b/app/src/main/java/fr/plnech/dunbar/ui/FriendsAdapter.kt @@ -8,7 +8,7 @@ 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.view.* +import kotlinx.android.synthetic.main.contact_listitem.view.* class FriendsAdapter( @@ -22,7 +22,7 @@ class FriendsAdapter( override fun getItemCount(): Int = friends.size - override fun getItemViewType(position: Int): Int = R.layout.contact + override fun getItemViewType(position: Int): Int = R.layout.contact_listitem override fun onBindViewHolder(holder: FriendsViewHolder, position: Int): Unit = holder.bind(friends[position]) @@ -85,5 +85,4 @@ class FriendsViewHolder(private val view: View) : RecyclerView.ViewHolder(view) } } } - } diff --git a/app/src/main/res/layout-w900dp/friend_list.xml b/app/src/main/res/layout-w900dp/friend_list.xml index c527b19..d4596d6 100644 --- a/app/src/main/res/layout-w900dp/friend_list.xml +++ b/app/src/main/res/layout-w900dp/friend_list.xml @@ -1,39 +1,63 @@ - + android:layout_width="wrap_content" + android:layout_height="wrap_content"> - + - + android:baselineAligned="false" + android:divider="?android:attr/dividerHorizontal" + android:orientation="horizontal" + android:showDividers="middle" + tools:context=".ui.FriendListActivity"> - + + + + + - \ No newline at end of file + + diff --git a/app/src/main/res/layout/contact.xml b/app/src/main/res/layout/contact.xml deleted file mode 100644 index 9bc5bef..0000000 --- a/app/src/main/res/layout/contact.xml +++ /dev/null @@ -1,117 +0,0 @@ - - - - - - - - - - - - - - - - - - - - diff --git a/app/src/main/res/layout/contact_listitem.xml b/app/src/main/res/layout/contact_listitem.xml new file mode 100644 index 0000000..9bc5bef --- /dev/null +++ b/app/src/main/res/layout/contact_listitem.xml @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/contacts.xml b/app/src/main/res/layout/contacts.xml deleted file mode 100644 index cd4b749..0000000 --- a/app/src/main/res/layout/contacts.xml +++ /dev/null @@ -1,7 +0,0 @@ - - diff --git a/app/src/main/res/layout/contacts_listview.xml b/app/src/main/res/layout/contacts_listview.xml new file mode 100644 index 0000000..cd3e10e --- /dev/null +++ b/app/src/main/res/layout/contacts_listview.xml @@ -0,0 +1,7 @@ + + diff --git a/app/src/main/res/layout/content_contacts.xml b/app/src/main/res/layout/content_contacts.xml index fc9945b..d67f273 100644 --- a/app/src/main/res/layout/content_contacts.xml +++ b/app/src/main/res/layout/content_contacts.xml @@ -31,7 +31,7 @@ app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toBottomOf="@id/contactsTitle" - tools:listitem="@layout/contact" + tools:listitem="@layout/contact_listitem" tools:text="@tools:sample/last_names" /> \ No newline at end of file diff --git a/app/src/main/res/layout/friend_detail.xml b/app/src/main/res/layout/friend_detail.xml index 4e4032a..744add9 100644 --- a/app/src/main/res/layout/friend_detail.xml +++ b/app/src/main/res/layout/friend_detail.xml @@ -1,10 +1,25 @@ - \ No newline at end of file + android:layout_height="wrap_content" + android:layout_marginTop="24dp"> + + + + diff --git a/app/src/main/res/layout/friend_list.xml b/app/src/main/res/layout/friend_list.xml index 54fc089..97f906e 100644 --- a/app/src/main/res/layout/friend_list.xml +++ b/app/src/main/res/layout/friend_list.xml @@ -6,10 +6,10 @@ android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior" tools:context=".ui.ContactsActivity" - tools:showIn="@layout/activity_friends"> + tools:showIn="@layout/activity_friends_list"> + tools:listitem="@layout/contact_listitem" /> \ No newline at end of file -- libgit2 0.27.0