Skip to content

Instantly share code, notes, and snippets.

/*
* Copyright 2016 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@shawnthye
shawnthye / FCM.md
Last active October 16, 2017 10:34
Firebase Push Notification

Request

https://fcm.googleapis.com/fcm/send
Headers Value
Authorization key=<YOUR SERVER KEY>
Content-Type application/json

Request Sample

@shawnthye
shawnthye / LocalBroadcastReceiver.java
Created December 13, 2017 18:41
Push Notification - Local Broadcast Receiver and Result Receiver
public class LocalBroadcastReceiver extends BroadcastReceiver {
@Override public void onReceive(Context context, Intent intent) {
Log.d("LocalBroadcastReceiver", "onReceive()");
// Tell the result receiver to CANCEL some specific action.
// eg. do not display System Notification
setResultCode(Activity.RESULT_CANCELED);
}
}
@shawnthye
shawnthye / properties.groovy
Created March 14, 2019 11:52 — forked from HopefulLlama/properties.groovy
Print all properties of a Groovy object
println object.properties
.sort{it.key}
.collect{it}
.findAll{!['class', 'active'].contains(it.key)}
.join('\n')
@shawnthye
shawnthye / JetpackNavigationActivity.kt
Last active November 14, 2021 12:16
Workaround for Bottom Navigation with Jetpack Navigation 2.4.0-beta02
override fun onBackPressed() {
/**
* We only override the behavior when back to home from other menu
* else we leave it to the default [onBackPressed]
*/
if (bottomNavigationView.selectedItemId != bottomNavigationView.menu[0].itemId) {
val previousDestination = navController.previousBackStackEntry?.destination ?: run {
/**
* on the root, left it to default [onBackPressed]
@shawnthye
shawnthye / BottomNavigationView.onItemReselected.kt
Created November 14, 2021 12:15
Workaround for Bottom Navigation with Jetpack Navigation 2.4.0-beta02 reselected
bottomNavigationView.setOnItemReselectedListener { menu ->
val destination = navController.graph[menu.itemId]
val graph = destination as? NavGraph ?: return@setOnItemReselectedListener
navController.popBackStack(graph.startDestinationId, false)
}