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 / goku-tribute-s-page.markdown
Created September 7, 2017 16:39
Goku Tribute's Page
@1jGabriel
1jGabriel / MyFirebaseMessagingService.kt
Last active June 26, 2018 18:56
Firebase Listener
import android.app.NotificationManager
import android.content.Context
import android.graphics.BitmapFactory
import android.support.v4.app.NotificationCompat
import br.com.project.R
import br.com.project
import com.google.firebase.messaging.FirebaseMessagingService
import com.google.firebase.messaging.RemoteMessage
import javax.inject.Inject
@1jGabriel
1jGabriel / Build.gradle
Created July 1, 2018 01:16
Mudar o google-services json de local, a depender do build
task switchToDebug(type: Copy) {
description = 'Switches to DEBUG google-services.json'
from "src/debug"
include "google-services.json"
into "."
}
task switchToHomolog(type: Copy) {
description = 'Switches to HOMOLOG google-services.json'
from "src/homolog"
@1jGabriel
1jGabriel / build.gradle
Created July 1, 2018 01:17
Url dinâmica a partir do ambiente para apk
buildTypes {
debug {
buildConfigField "String", "SERVER_URL_EXTERNAL", '"URL_DEBUG"'
buildConfigField "int", "TRACKER", '0'
}
homolog {
buildConfigField "String", "SERVER_URL_EXTERNAL", '"URL_HOMOLOGAÇÃO"'
buildConfigField "int", "TRACKER", '1'
signingConfig signingConfigs.homolog
@1jGabriel
1jGabriel / ErrorTreatment.kt
Last active October 4, 2018 18:29
Função criada para tratamento de erros retrofit e rx criado por https://github.com/osiascarneiro/
fun <T> Observable<Response<T>>.subscribeTreatment(onNext: (T?) -> Unit, onError: (Throwable) -> Unit): Disposable {
return this.subscribe({
if (!it.isSuccessful) {
onError(Throwable(it.message(), Throwable()))
} else {
onNext(it.body())
}
}, {
when (it) {
is UnknownHostException,
@1jGabriel
1jGabriel / SafeClickListener.kt
Created November 15, 2018 13:51
Evitar mais de 1 click em menos de 1.5 segundo
import android.os.SystemClock
import android.view.View
class SafeClickListener(
private var defaultInterval: Int = 1500,
private val onSafeCLick: (View) -> Unit
) : View.OnClickListener {
private var lastTimeClicked: Long = 0
override fun onClick(v: View) {
@1jGabriel
1jGabriel / AnimationUtil.kt
Created November 28, 2018 18:31
AnimationUtilClass
class AnimationUtil {
companion object {
fun startAnimation(view: View, idAnimation: Int, start: (() -> Unit)? = null , repeat: (() -> Unit)? = null, end: (() -> Unit)? = null) {
val anim = AnimationUtils.loadAnimation(Application.context, idAnimation)
anim.setAnimationListener(object : Animation.AnimationListener {
override fun onAnimationStart(animation: Animation?) {
start?.invoke()
}
@1jGabriel
1jGabriel / ExampleUnitTest.kt
Created February 8, 2019 13:53
Exemplo classe com teste de login no viewmodel
package digital.solutis.base.gamechanger
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
import androidx.lifecycle.Observer
import digital.solutis.gamechanger.model.Service
import digital.solutis.gamechanger.model.consulta.LoginConsulta
import digital.solutis.gamechanger.model.entidade.Usuario
import digital.solutis.gamechanger.viewmodel.LoginViewModel
import io.reactivex.Observable
import org.junit.Before
@1jGabriel
1jGabriel / _Long.kt
Last active June 13, 2019 13:04
Gist para criação de quanto tempo se passou usando timestamp
fun Long.calculateDisplayTimeStamp(): String {
val now = System.currentTimeMillis() / 1000
val diff = now - this
val dayInMilli: Long = 23 * 59 * 60
return if (diff < 60) {
"Agora"
} else if (diff > 60 && diff < 59 * 60) {
"${diff / 60} minutos atrás"
} else if (diff > 59 * 60 && diff < 23 * 59 * 60) {
@1jGabriel
1jGabriel / MainViewModel.kt
Created April 22, 2020 13:22
ViewModel tests with coroutines
class MainViewModel(private val charactersUseCase: GetCharactersUseCase) : ViewModel() {
val viewState = ViewState()
fun dispatchAction(action: ViewAction) = when (action) {
is ViewAction.Init -> getCharacters()
is ViewAction.Refresh -> getCharacters()
}
private fun getCharacters() {