Skip to content

Instantly share code, notes, and snippets.

View PatilShreyas's full-sized avatar
👨‍💻
Might be writing code at the moment

Shreyas Patil PatilShreyas

👨‍💻
Might be writing code at the moment
View GitHub Profile
private fun initCountObserver() {
lifecycleScope.launch {
viewModel.countState.collect { value ->
textview_count.text = "$value"
}
}
}
private fun initView() {
button_plus.setOnClickListener(::incrementCounter)
button_minus.setOnClickListener(::decrementCounter)
}
private fun incrementCounter(view: View) {
viewModel.incrementCount()
}
private fun decrementCounter(view: View) {
class MainActivity : AppCompatActivity() {
private val viewModel by lazy {
ViewModelProvider(this)[MainViewModel::class.java]
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
@ExperimentalCoroutinesApi
class MainViewModel : ViewModel() {
private val _countState = MutableStateFlow(0)
val countState: StateFlow<Int> = _countState
fun incrementCount() {
_countState.value++
}
package dev.shreyaspatil.firebase.coroutines.utils
import com.google.firebase.firestore.CollectionReference
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.cancel
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.callbackFlow
@ExperimentalCoroutinesApi
fun CollectionReference.getSnapshotFlow() = callbackFlow {

Hello

name: Publish Bintray
on:
release:
types: [published]
jobs:
publish:
runs-on: ubuntu-latest
steps:
ext {
// This should be same as you've created in bintray
bintrayRepo = 'maven'
// Name which will be visible on bintray
bintrayName = 'CoolLibrary'
// Library Details
publishedGroupId = 'dev.shreyaspatil'
class PostsRepository {
private val mPostsCollection = FirebaseFirestore.getInstance().collection(Constants.COLLECTION_POST)
fun getAllPosts() { // TODO Implement }
fun addPost(post: Post) { // TODO Implement }
...
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// Required plugins added to classpath to facilitate pushing to Jcenter/Bintray
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
}