Skip to content

Instantly share code, notes, and snippets.

View alexfelipe's full-sized avatar
:octocat:

Alex Felipe alexfelipe

:octocat:
View GitHub Profile
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.padding
@alexfelipe
alexfelipe / Note.kt
Created August 22, 2018 12:43
Transformando a classe de notas em property
@Entity
data class Note(/* properties declaradas */)
@alexfelipe
alexfelipe / NoteListActivity.kt
Created July 27, 2018 00:53
Properties nullable na Activity
class NoteListActivity : AppCompatActivity() {
private var adapter: NoteListAdapter? = null
private var recyclerView: RecyclerView? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_note_list)
adapter = NoteListAdapter(notes(), this)
recyclerView = note_list_recyclerview
@alexfelipe
alexfelipe / build.gradle
Created May 21, 2018 13:07
Adicionando o Room no projeto em Kotlin
// others plugins
apply plugin: 'kotlin-kapt'
android {
// Android project configuration
}
dependencies {
// others dependencies
@alexfelipe
alexfelipe / NoteService.kt
Created April 29, 2018 12:57
Service para notas
package br.com.alexf.ceepws.service
import br.com.alexf.ceepws.model.Note
import br.com.alexf.ceepws.repository.NoteRepository
class NoteService(
private val noteRepository: NoteRepository) {
fun all(): List<Note> {
return noteRepository.findAll().toList()
@alexfelipe
alexfelipe / activity_profile.xml
Last active April 22, 2018 15:21
Layout gerado com o editor visual do Android Studio e Constraint Layout
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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="match_parent"
android:layout_height="match_parent">
<ImageView
@alexfelipe
alexfelipe / NoteDialog.kt
Created February 1, 2018 00:20
Delegando as HOF para o Web Client
fun alter(note: Note,
preExecute: () -> Unit = {},
finished: () -> Unit = {},
altered: (alteredNote: Note) -> Unit) {
titleField.setText(note.title)
descriptionField.setText(note.description)
AlertDialog.Builder(context)
.setTitle("Alter note")
.setView(createdView)
.setPositiveButton("Save") { _, _ ->
@alexfelipe
alexfelipe / RetrofitCallback.kt
Created February 1, 2018 00:15
Extension funtions genéricas para respostas padrões de callback
fun <T> Response<T>?.defaultResponse(success: (t: T) -> Unit) {
this?.body()?.let { success(it) }
}
fun Throwable?.defaultFailure(failure: (throwable: Throwable) -> Unit) {
this?.let {
failure(it)
}
}
@alexfelipe
alexfelipe / NoteWebClient.kt
Created February 1, 2018 00:01
Delegando a responsabilidade de pré e pós execução para a função de callback
fun list(preExecute: () -> Unit,
finished: () -> Unit,
success: (notes: List<Note>) -> Unit,
failure: (throwable: Throwable) -> Unit) {
val call = RetrofitInitializer().noteService().list()
call.enqueue(
callback(
response = { response ->
response?.body()?.let {
success(it)
@alexfelipe
alexfelipe / RetrofitCallback.kt
Last active January 31, 2018 23:59
Adicionando HOFs de pré e pós execução na função de callback genérica
fun <T> callback(preExecute: () -> Unit = {},
finished: () -> Unit = {},
response: (response: Response<T>?) -> Unit = {},
failure: (throwable: Throwable?) -> Unit = {}): Callback<T> {
preExecute()
return object : Callback<T> {
override fun onResponse(call: Call<T>?, response: Response<T>?) {
response(response)
finished()
}