Guilherme Lima Pereira guuilp
- Campinas - São Paulo
- https://cafecomandroid.com/
View PeopleViewModel.kt
class PeopleViewModel : ViewModel() { | |
private val selectedPerson = MutableLiveData<Person>() | |
fun setSelectedPerson(person: Person){ | |
selectedPerson.value = person | |
} | |
fun getSelectedPerson() = selectedPerson | |
} |
View PeopleActivity.kt
class PeopleActivity : AppCompatActivity() { | |
private val people = listOf( | |
Person(1, "Person 1", "Brazil"), | |
Person(2, "Person 2", "USA"), | |
Person(3, "Person 3", "Canada"), | |
Person(4, "Person 4", "Russia"), | |
Person(5, "Person 5", "Germany") | |
) |
View PeopleAdapter.kt
class PeopleAdapter(private val people: List<Person>, private val listener: Listener) : | |
RecyclerView.Adapter<PeopleAdapter.ViewHolder>() { | |
private var selectedPerson: Person? = null | |
interface Listener { | |
fun onItemClicked(person: Person) | |
} | |
fun updateSelectedPerson(person: Person) { |
View RecyclerView.kt
override fun onBindViewHolder(holder: ViewHolder, position: Int) { | |
holder.apply { | |
checkBox.isChecked = position == mCheckedPosition | |
checkBox.setOnClickListener { | |
if(position == mCheckedPosition) { | |
checkBox.isChecked = false | |
mCheckedPosition = -1 | |
} else { | |
mCheckedPosition = position | |
notifyDataSetChanged() |
View group_retweet.xml
<android.support.constraint.Group | |
android:id="@+id/group_retweet" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
app:constraint_referenced_ids="retweet_top, retweet_user"/> |
View comment.xml
<ImageView | |
android:id="@+id/comment" | |
android:layout_width="21dp" | |
android:layout_height="21dp" | |
android:layout_marginTop="12dp" | |
android:src="@drawable/ic_comment" | |
android:tint="@color/gray" | |
app:layout_constraintTop_toBottomOf="@+id/text" |
View profile_image.xml
<de.hdodenhof.circleimageview.CircleImageView | |
android:id="@+id/profile_image" | |
android:layout_width="50dp" | |
android:layout_height="50dp" | |
android:layout_marginTop="8dp" | |
android:src="@drawable/profile_image" | |
app:layout_constraintTop_toTopOf="parent" | |
app:layout_constraintLeft_toLeftOf="parent"/> |
View group_retweet.xml
<android.support.constraint.Group | |
android:id="@+id/group_retweet" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
app:constraint_referenced_ids="retweet_top, retweet_user"/> |
View profile_image.xml
<de.hdodenhof.circleimageview.CircleImageView | |
android:id="@+id/profile_image" | |
android:layout_width="50dp" | |
android:layout_height="50dp" | |
android:layout_marginTop="8dp" | |
android:src="@drawable/profile_image"/> |
View comment.xml
<ImageView | |
android:id="@+id/comment" | |
android:layout_width="21dp" | |
android:layout_height="21dp" | |
android:layout_marginTop="12dp" | |
android:src="@drawable/ic_comment" | |
android:tint="@color/gray"/> |
NewerOlder