Skip to content

Instantly share code, notes, and snippets.

😃
Hi!

Guilherme Lima Pereira guuilp

😃
Hi!
Block or report user

Report or block guuilp

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
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()
@guuilp
guuilp / group_retweet.xml
Created Jun 28, 2018
Constraint Layout DOJO - Solution (STEP 3)
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"/>
@guuilp
guuilp / comment.xml
Created Jun 28, 2018
Constraint Layout DOJO - Solution (STEP 2)
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"
@guuilp
guuilp / profile_image.xml
Created Jun 28, 2018
Constraint Layout DOJO - Solution (STEP 1)
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"/>
@guuilp
guuilp / group_retweet.xml
Last active Jun 28, 2018
Constraint Layout DOJO - Views without constraints (STEP 3)
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"/>
@guuilp
guuilp / profile_image.xml
Created Jun 28, 2018
Constraint Layout DOJO - Views without constraints (STEP 1)
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"/>
@guuilp
guuilp / comment.xml
Created Jun 28, 2018
Constraint Layout DOJO - Views without constraints (STEP 2)
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"/>
You can’t perform that action at this time.