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 initCountObserver() { | |
lifecycleScope.launch { | |
viewModel.countState.collect { value -> | |
textview_count.text = "$value" | |
} | |
} | |
} |
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 initView() { | |
button_plus.setOnClickListener(::incrementCounter) | |
button_minus.setOnClickListener(::decrementCounter) | |
} | |
private fun incrementCounter(view: View) { | |
viewModel.incrementCount() | |
} | |
private fun decrementCounter(view: View) { |
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
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) |
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
@ExperimentalCoroutinesApi | |
class MainViewModel : ViewModel() { | |
private val _countState = MutableStateFlow(0) | |
val countState: StateFlow<Int> = _countState | |
fun incrementCount() { | |
_countState.value++ | |
} |
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
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 { |
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
name: Publish Bintray | |
on: | |
release: | |
types: [published] | |
jobs: | |
publish: | |
runs-on: ubuntu-latest | |
steps: |
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
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' |
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
class PostsRepository { | |
private val mPostsCollection = FirebaseFirestore.getInstance().collection(Constants.COLLECTION_POST) | |
fun getAllPosts() { // TODO Implement } | |
fun addPost(post: Post) { // TODO Implement } | |
... | |
} |
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
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' | |
} |