Skip to content

Instantly share code, notes, and snippets.

View SamueldaCostaAraujoNunes's full-sized avatar
🏠
Working from home

Samuel da Costa Araujo Nunes SamueldaCostaAraujoNunes

🏠
Working from home
View GitHub Profile
private val _searchView = MutableLiveData(true)
val searchViewVisibility: LiveData<Boolean> = _searchView
fun showSearchView() {
_searchView.value = true
}
fun hideSearchView() {
_searchView.value = false
}
viewModel.searchViewVisibility.observe(this) { item.isVisible = it }
<?xml version="1.0" encoding="utf-8"?>
<androidx.recyclerview.widget.RecyclerView 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/characters_rv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:nestedScrollingEnabled="false"
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
app:spanCount="@integer/rows_recycler"
<?xml version="1.0" encoding="utf-8"?>
<layout 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">
<data>
<variable
name="character"
type="br.com.samuelnunes.rickandmortyapp.data.entities.Character" />
</data>
<string name="character_status">Status: %1$s</string>
<string name="character_species">Specie: %1$s</string>
<string name="character_gender">Gender: %1$s</string>
<string name="character_type">Type: %1$s</string>
@BindingAdapter("visibleIf")
fun View.visibleIf(condition: Boolean) {
visibility = if (condition) {
VISIBLE
} else {
GONE
}
}
<?xml version="1.0" encoding="utf-8"?>
<layout 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">
<data>
<variable
name="character"
type="br.com.samuelnunes.rickandmortyapp.data.entities.Character" />
</data>
package br.com.samuelnunes.rickandmorty.ui.characters
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.paging.PagingDataAdapter
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.RecyclerView
import br.com.samuelnunes.rickandmortyapp.data.entities.Character
import br.com.samuelnunes.rickandmortyapp.databinding.ItemCharacterBinding
package br.com.samuelnunes.rickandmortyapp.ui.characters
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
import androidx.fragment.app.viewModels
import androidx.navigation.fragment.findNavController
@Query("SELECT * FROM Character WHERE id = :id")
suspend fun getCharacter(id: Int): Character