Skip to content

Instantly share code, notes, and snippets.

View prokash-sarkar's full-sized avatar
🎯
Focusing

Prokash Sarkar prokash-sarkar

🎯
Focusing
View GitHub Profile
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'jacoco'
apply from: "$project.rootDir/tools/script-jacoco.gradle"
android {
// Code omitted for brevity
private static boolean isAndroidModule(Project project) {
boolean isAndroidLibrary = project.plugins.hasPlugin('com.android.library')
boolean isAndroidApp = project.plugins.hasPlugin('com.android.application')
return isAndroidLibrary || isAndroidApp
}
afterEvaluate { project ->
def projectName = project.name
if (isAndroidModule(project)) setupAndroidReporting()
else setupKotlinReporting()
def setupKotlinReporting() {
jacocoTestReport {
dependsOn test
reports {
csv.enabled false // change if needed
xml.enabled false // change if needed
html {
enabled true
destination file("${buildDir}/coverage-report")
}
afterEvaluate { project ->
def projectName = project.name
if (isAndroidModule(project)) setupAndroidReporting()
else setupKotlinReporting()
}
private static boolean isAndroidModule(Project project) {
boolean isAndroidLibrary = project.plugins.hasPlugin('com.android.library')
boolean isAndroidApp = project.plugins.hasPlugin('com.android.application')
return isAndroidLibrary || isAndroidApp
}
/**
* How to run?
*
* App Module:
* ./gradlew app:testAppDebugUnitTestCoverage
* ./gradlew app:testBetaDebugUnitTestCoverage
* ./gradlew app:testProdDebugUnitTestCoverage
*
* Domain Module:
* ./gradlew domain:jacocoTestReport
@prokash-sarkar
prokash-sarkar / AuthenticationInterceptor.kt
Last active January 27, 2021 09:18
Example of runtime modification of an auth token and base URL of the okHttp client using Interceptor and Dagger injection.
class AuthenticationInterceptor @Inject constructor(baseUrl: String, jwtToken: String) :
Interceptor {
private var baseUrl: HttpUrl
private var jwtToken: String
companion object {
private const val LOG_TAG = "AuthenticationInterceptor:"
private const val AUTHORIZATION = "Authorization"
private const val BEARER = "Bearer"
@prokash-sarkar
prokash-sarkar / BaseViewModel.kt
Last active November 7, 2019 12:36
BaseViewModel
abstract class BaseViewModel: ViewModel()
{
protected val _viewState: MutableLiveData<ViewState> = MutableLiveData()
// don't expose the MutableLiveData outside of the class
val viewState: LiveData<ViewState>
get() = _viewState // only getter / no setter
fun setViewState(viewState: ViewState){
@prokash-sarkar
prokash-sarkar / LiveDataReactiveStreams.kt
Created September 28, 2019 04:39
Using LiveDataReactiveStreams to convert Flowable
fun <T> LiveData<T>.toFlowable(owner: LifecycleOwner): Flowable<T> =
Flowable.fromPublisher(LiveDataReactiveStreams.toPublisher(owner, this))
fun <T> Flowable<T>.toLiveData(): LiveData<T> = LiveDataReactiveStreams.fromPublisher(this)
@prokash-sarkar
prokash-sarkar / Scoping Functions.kt
Created September 15, 2019 06:33
Exmaples of 5 Kotlin Scoping functions, Run, With, Let, Apply, Also
class ScopingFunctions {
fun main() {
val firstPerson = Person("Prokash", 28, "Programmer")
val secondPerson = Person("Elizabeth", 34, "Singer")
//Calls the specified function block with this value as its receiver and returns its result.
run {
if (firstPerson.age > secondPerson.age) firstPerson else secondPerson
}.printPerson()