This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const payload = { | |
data: { | |
disposition: pic.answer.disposition.toString(), | |
pic_id: picId | |
} | |
} | |
try { | |
const response = await fcm.sendToTopic('answers',payload) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const onAnswer = functions.firestore.document('/pic/{picId}').onUpdate(_onAnswer) | |
async function _onAnswer(change: functions.Change<DocumentSnapshot>): Promise<any> { | |
const picId = change.before.id "//20180624120000" | |
const previous = change.before.data() as Pic | |
const pic = change.after.data() as Pic | |
// Only interested in pics that have a new answer | |
if (previous.answer || !pic.answer) { | |
console.log("This is not the update you are looking for.") | |
return Promise.resolve() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val disposition = button_click_true_or_false | |
picReference.update( | |
"answer.uid", uid, | |
"answer.disposition", disposition) | |
.addOnCompleteListener(this) { | |
Log.d(TAG, "Answer written to database") | |
finish() | |
} | |
.addOnFailureListener(this, {e -> | |
Log.d(TAG, "Answer not written to database", e) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@GlideModule | |
class MyAppGlideModule : AppGlideModule() { | |
override fun registerComponents(context: Context, glide: Glide, registry: Registry) { | |
// Register FirebaseImageLoader from FirebaseUI to handle StorageReference | |
registry.append(StorageReference::class.java, InputStream::class.java, | |
FirebaseImageLoader.Factory()) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private fun poplulateViews(picId: String) { | |
picReference = FirebaseFirestore.getInstance().collection("pics").document(picId) | |
picReference.get() | |
.addOnSuccessListener(this) { snap -> | |
if (snap.exists()) { | |
val ring = snap.toObject(Pic::class.java) | |
val ref = FirebaseStorage.getInstance().getReference(pic.imagePath!!) | |
Glide.with(this@AnswerPicActivity).load(ref).into(ivGuest) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// sned a notification to the app | |
const payload = { | |
notification: { | |
title: 'Hellooo', | |
body: 'Is my kitty\'s bowl empty?', | |
click_action: 'com.hyperaware.catfeeder.ANSWER_PIC' | |
}, | |
data: { | |
pic_id: id | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const onPic = functions.storage.object().onFinalize(_onPic) | |
async function _onPic(object: functions.storage.ObjectMetadata): Promise<any> { | |
const path = object.name // "pictures/20180624120000.jpg" | |
const id = basename(path, '.jpg') // "20180624120000" | |
try { | |
// add a document to Firestore with the details of this pic | |
const pic: Pic = { | |
id: id, | |
date: new Date(), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val client = Nearby.getMessagesClient(this) | |
private val messageListener = object : MessageListener() { | |
override fun onFound(message: Message) { | |
// message.content contains payload | |
} | |
override fun onLost(message: Message) {} | |
} | |
client.subscribe(messageListener, subscribeOpts) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val strategy = Strategy.Builder() | |
.setDiscoveryMode(Strategy.DISCOVERY_MODE_SCAN) | |
.setTtlSeconds(Strategy.TTL_SECONDS_MAX) | |
.build() | |
val subscribeOpts = SubscribeOpts.Builder() | |
.setStrategy(strategy) | |
.setCallback(object : setCallback() { | |
override fun onExpired() { | |
Log.d(TAG, "onExpired") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val client = Nearby.getMessagesClient(this) | |
val message = Message("Hi, Firebase Thing.") | |
client.publish(message, publishOpts) | |
.addOnSuccessListener(this) { | |
Log.e(TAG, "publish scucess") | |
} | |
.addOnFailureListener(this) { e -> | |
Log.e(TAG, "publish failed", e) | |
} |