Skip to content

Instantly share code, notes, and snippets.

View joyal670's full-sized avatar

Joyal Jose joyal670

View GitHub Profile
@shibbirweb
shibbirweb / DataStoreManager.kt
Last active April 17, 2023 14:02
Android - Kotlin - Data Store Manager
package com.***.data.dataStoreManager
import android.content.Context
import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.*
import androidx.datastore.preferences.preferencesDataStore
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.map
@oaviad
oaviad / RoomDatabase.kt
Last active May 4, 2021 03:39
room database
@Entity(tableName = "inbox", indices = [Index(value = ["uid"], unique = true)])
data class Message @JvmOverloads constructor(
@PrimaryKey(autoGenerate = true) @ColumnInfo(name = _id) val id: Long?,
@ColumnInfo(name = timestamp) val timestamp: Long
@ColumnInfo(name = uid) val uid: Long,
@ColumnInfo(name = is_read, defaultValue = "0") val isRead: Int = 0
@ColumnInfo(name = text) val text: String?
)
@Database(entities = arrayOf(Message::class), version = 2)
@erikfloresq
erikfloresq / FirebaseMessagingService.java
Last active March 24, 2021 04:27
Android notifications
public class FirebaseMessagingService extends FirebaseMessagingService {
@Override
public void onMessageReceived(@NotNull RemoteMessage remoteMessage) {
// Not getting messages here? See why this may be: https://goo.gl/39bRNJ
Log.d(ContentValues.TAG, "From: " + remoteMessage.getFrom());
// Check if message contains a data payload.
if (!remoteMessage.getData().isEmpty()) {
@weiancheng
weiancheng / CountDownTimer.kt
Last active March 24, 2021 04:27
[Timer] #android
val millisInFuture: Int = 10 * 1000
val countdown_interval: Int = 1000
val timer: CountDownTimer = object: CountDownTimer(millisInFuture, countdown_interval) {
override fun onFinish() {
Log.i(TAG, "CountDownTimer onFinish")
}
override fun onTick(millisUntilFinished: Long) {
Log.i(TAG, "CountDOwnTimer onTick: " + millisUntilFinished)