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 uploadFile(f: File) { | |
val sdf = SimpleDateFormat("yyyyMMddHHmmss", Locale.US) | |
val storagePath = "/pictures/${sdf.format(Date())}.jpg" | |
val ref = FirebaseStorage.getInstance().getReference(storagePath) | |
ref.putFile(Uri.fromFile(f)) | |
.addOnSuccessListener(this) { | |
Log.i(TAG, "picture uploaded") | |
} | |
.addOnFailureListener(this) { e -> | |
Log.i(TAG, "upload failed", 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
val strategy = Strategy.Builder() | |
.setDiscoveryMode(Strategy.DISCOVERY_MODE_BROADCAST) | |
.setTtlSeconds(Strategy.TTL_SECONDS_MAX) | |
.build() | |
val publishOpts = PublishOptions.Builder() | |
.setStrategy(strategy) | |
.setCallback(object : PublishCallback()) { | |
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) | |
} |
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) | |
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
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
// 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
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
@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
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) |
OlderNewer