Skip to content

Instantly share code, notes, and snippets.

View 1jGabriel's full-sized avatar
🏠
Working from home

João Gabriel 1jGabriel

🏠
Working from home
View GitHub Profile
@1jGabriel
1jGabriel / navgraph_3.xml
Created October 19, 2020 13:17
Third feature navgraph
<?xml version="1.0" encoding="utf-8"?>
<navigation 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/nav_feature_three"
app:startDestination="@id/fragment_e">
<fragment
android:id="@+id/fragment_e"
android:name="io.jgabriel.featurethree.FragmentE">
<action
@1jGabriel
1jGabriel / navgraph.xml
Created October 19, 2020 13:08
First Feature Navigation graph
<?xml version="1.0" encoding="utf-8"?>
<navigation 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/nav_feature_one"
app:startDestination="@id/fragment_a">
<fragment
android:id="@+id/fragment_a"
android:name="io.jgabriel.featureone.FragmentA">
@1jGabriel
1jGabriel / build.gradle
Created October 19, 2020 12:47
navigation dependencies
implementation "androidx.navigation:navigation-fragment-ktx:2.2.2"
implementation "androidx.navigation:navigation-ui-ktx:2.2.2"
class MyAdapter : PagingDataAdapter<MyModel, MyAdapter.MyViewHolder>(DiffUtilCallback()) {
// the adapter implementation still the same
}
class DiffUtilCallBack : DiffUtil.ItemCallback<MyModel>() {
override fun areItemsTheSame(oldItem: MyModel, newItem: MyModel): Boolean {
return oldItem.id == newItem.id
}
override fun areContentsTheSame(oldItem: MyModel, newItem: MyModel): Boolean {
@1jGabriel
1jGabriel / KeyboardView.java
Created July 27, 2020 14:46
Virtual Keyboard
package br.com.xpto.custom.ui.view;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.support.annotation.DrawableRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
@1jGabriel
1jGabriel / MyAdapter.kt
Created July 19, 2020 15:32
Adapter utilizando PagingV3
class MyAdapter : PagingDataAdapter<MyModel, MyAdapter.MyViewHolder>(DiffUtilCallback()) {
// a implementação do corpo do adapter permanece a mesma
}
class DiffUtilCallBack : DiffUtil.ItemCallback<MyModel>() {
override fun areItemsTheSame(oldItem: MyModel, newItem: MyModel): Boolean {
return oldItem.id == newItem.id
}
override fun areContentsTheSame(oldItem: MyModel, newItem: MyModel): Boolean {
@1jGabriel
1jGabriel / Fragment.kt
Created July 19, 2020 15:31
Obter dados do ViewModel
fun getData() {
lifecycleScope.launch {
viewModel.getItems().collectLatest {
adapter.submitData(it)
}
}
}
@1jGabriel
1jGabriel / Pager.kt
Created July 19, 2020 15:29
Pager Sample
fun getItems(): Flow<PagingData<MyModel>> {
return Pager(
config = PagingConfig(pageSize = 20),
pagingSourceFactory = { MyPagingSource(api = api) }
).flow.cachedIn(viewModelScope)
}
@1jGabriel
1jGabriel / MyPagingSource.kt
Created July 19, 2020 15:28
Paging Source Sample
class MyPagingSource(
private val api: MyApi
) : PagingSource<Int, MyModel>() {
override suspend fun load(params: LoadParams<Int>): LoadResult<Int, MyModel> {
return try {
val result = api.getItems(params.key ?: STARTING_PAGE_INDEX)
Page(
data = result,
prevKey = params.key,
nextKey = result.nextPage ?: STARTING_PAGE_INDEX.plus(1)
import android.annotation.SuppressLint
import android.content.Context
import android.content.res.ColorStateList
import android.os.Build
import android.support.annotation.RequiresApi
import android.support.design.widget.TextInputLayout
import android.support.v7.widget.AppCompatEditText