fix: working friends master/details

parent d73ffede
......@@ -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)
)
}
})
......
......@@ -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"
}
}
......@@ -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)
}
......
......@@ -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)
}
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.constraintlayout.widget.ConstraintLayout 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"
......@@ -36,4 +59,5 @@
android:layout_height="match_parent"
android:layout_weight="3" />
</LinearLayout>
\ No newline at end of file
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
......@@ -2,6 +2,6 @@
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/contact_list_item"
tools:listitem="@layout/contact"
tools:listitem="@layout/contact_listitem"
android:layout_width="match_parent"
android:layout_height="match_parent" />
......@@ -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" />
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.constraintlayout.widget.ConstraintLayout 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:id="@+id/friend_detail"
style="?android:attr/textAppearanceLarge"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp"
android:textIsSelectable="true"
tools:context=".ui.FriendDetailFragment" />
\ No newline at end of file
android:layout_height="wrap_content"
android:layout_marginTop="24dp">
<TextView
android:id="@+id/friendData"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="15dp"
android:focusable="false"
android:focusableInTouchMode="false"
android:gravity="end"
android:textAppearance="@style/TextAppearance.AppCompat.Subhead"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="2 interactions, last 1 hour ago" />
</androidx.constraintlayout.widget.ConstraintLayout>
......@@ -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">
<TextView
android:id="@+id/contactsTitle"
android:id="@+id/friends_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
......@@ -31,5 +31,5 @@
android:layout_marginRight="16dp"
app:layoutManager="LinearLayoutManager"
tools:context=".ui.FriendListActivity"
tools:listitem="@layout/contact" />
tools:listitem="@layout/contact_listitem" />
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
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