Skip to content

Instantly share code, notes, and snippets.

@joeytsai
joeytsai / AppModule.kt
Created October 27, 2017 06:08
Timber.plant(LinkingDebugTree())
// Make Logcat clickable
private class LinkingDebugTree : Timber.DebugTree() {
override fun createStackElementTag(e: StackTraceElement): String {
val tag = "(${e.fileName}:${e.lineNumber})"
return if (tag.length <= MAX_TAG_LENGTH) tag else super.createStackElementTag(e)
}
companion object {
private val MAX_TAG_LENGTH = 23
}
@joeytsai
joeytsai / gist:7ed37555e987d1b3d99b93e4d8a8d1ff
Created July 8, 2017 20:31
Android Studio Kotlin Live Templates
Abbreviation: logm
Description: Log method name and its arguments
Template: android.util.Log.d(TAG, $content$)
content: groovyScript("'\"' + _1.collect { it + ' = [$' + it + ']'}.join(', ') + '\"'", functionParameters())
@joeytsai
joeytsai / RestLog.kt
Created June 29, 2017 03:05
Spring RestTemplate logging
/*
You can setup an interceptor to read the raw HttpResponse, but it is an InputStream
1) Implement ClientHttpRequestInterceptor to execute the request, the log the response body InputStream
*/
class LoggingInterecptor : ClientHttpRequestInterceptor {
private val LOG = LoggerFactory.getLogger(javaClass)
override fun intercept(request: HttpRequest?, body: ByteArray?, execution: ClientHttpRequestExecution): ClientHttpResponse {
val response = execution.execute(request, body)
@joeytsai
joeytsai / git-tricks.sh
Last active June 30, 2017 00:02
git things
# Export a git project to a zip file
git archive --format=zip -o project.zip master
# Delete merged branches
git branch --merged | egrep -v "(^\*|master|dev)" | xargs git branch -d
@joeytsai
joeytsai / build.gradle
Created May 30, 2017 01:00
Gradle builds depending on each other
# util project
uploadArchives {
repositories {
mavenLocal()
}
}
# now util can ./gradlew uploadArchives
@joeytsai
joeytsai / settings.gradle
Last active May 27, 2017 08:47
Gradle settings
rootProject.name = 'my-app'
if (file("../my-utils").exists()) {
includeBuild "../my-utils"
}
file('modules').listFiles().findAll { it.directory }.each { File moduleBuild ->
includeBuild moduleBuild
}
Today I learned that FCM (formerly GCM) has a fun quirk. The payload of a push notification can contain two elements, "notification" and "data". You can read these payloads in a callback called onMessageReceived().
If the app is in the forgeround, everything works as you'd expect. However, if the app is in the background, and the "notification" element is in the payload, onMessageReceived() is NOT called and Firebase handles the push notification and generates a system notification.
If you want onMessageReceived() to always be called, then you can only have "data" notification. Awesome!
https://firebase.google.com/docs/notifications/android/console-audience#receive_and_handle_notifications
Also, a very frustrating read: https://github.com/firebase/quickstart-android/issues/4
https://firebase.google.com/docs/cloud-messaging/concept-options#notifications_and_data_messages
https://firebase.google.com/docs/cloud-messaging/android/receive#sample-receive