This file contains 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
import androidx.fragment.app.Fragment | |
import androidx.lifecycle.LifecycleOwner | |
import androidx.lifecycle.lifecycleScope | |
import kotlinx.coroutines.CoroutineScope | |
@Suppress("UNCHECKED_CAST") | |
internal class ViewLifecycleScopeImpl( | |
private val fragment: Fragment | |
) : ViewLifecycleScope { |
This file contains 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
import kotlinx.coroutines.experimental.android.Main | |
import kotlinx.coroutines.experimental.CoroutineScope | |
class ExampleActivity : Activity(), CoroutineScope by CoroutineScope(Dispatchers.Main) { | |
override fun onCreate(savedInstanceState: Bundle?) | |
super.onCreate(savedInstanceState) | |
val ui = Ui(this) // bind views, etc | |
This file contains 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
import myapp.dependencyCatalogs.LibsCatalogExtension | |
import org.gradle.api.Project | |
import org.gradle.kotlin.dsl.the | |
// this file is in `buildSrc` in the root package, so `libs` will point to this function or the generated `libs` from the `.toml` file | |
/** | |
* Wrapper with no package name to have projects automatically pick up [LibsCatalogExtension] when this function exists. | |
* | |
* The generated version accessors is [org.gradle.accessors.dm.LibrariesForLibs]. |
This file contains 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
import android.arch.lifecycle.LiveData | |
import android.arch.lifecycle.MutableLiveData | |
import android.support.annotation.MainThread | |
import kotlin.reflect.KClass | |
/** Only emits [T] when [source] is true ]*/ | |
fun <T : Any> LiveData<T>.filterTrue(source: LiveData<Boolean>): LiveData<T> { | |
return this.combineLatest(source) { emission, isStateInitialized -> | |
Pair(emission, isStateInitialized) |
This file contains 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
public void elementClicked(int position){ | |
if (view != null){ | |
final int word = view.getWordByPosition(int position) | |
view.doAnimationStuff(); | |
view.launchActivityWithWord(word); | |
} | |
} | |
//because there are no android dependencies here, it becomes easy to implement Mockito style behavioral testing. |
This file contains 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
import org.gradle.api.Project | |
import org.gradle.api.file.ProjectLayout | |
import org.gradle.api.provider.Property | |
import org.gradle.api.provider.Provider | |
import org.gradle.api.provider.ProviderFactory | |
import org.gradle.api.provider.ValueSource | |
import org.gradle.api.provider.ValueSourceParameters | |
import org.gradle.kotlin.dsl.of | |
import java.io.StringReader | |
import java.util.Properties |
This file contains 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
//append code below to existing build.gradle | |
def appModuleRootFolder = '.' | |
def srcDir = 'src' | |
def googleServicesJson = 'google-services.json' | |
task switchToDebug(type: Copy) { | |
def buildType = 'debug' | |
description = 'Switches to DEBUG google-services.json' | |
from "${srcDir}/${buildType}" |
This file contains 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
@file:JvmName("RxChannelExtensions") | |
import kotlinx.coroutines.experimental.Dispatchers | |
import kotlinx.coroutines.experimental.GlobalScope | |
import kotlinx.coroutines.experimental.channels.ReceiveChannel | |
import kotlinx.coroutines.experimental.channels.consumeEach | |
import kotlinx.coroutines.experimental.channels.consumes | |
import kotlinx.coroutines.experimental.channels.consumesAll | |
import kotlinx.coroutines.experimental.channels.produce | |
import kotlinx.coroutines.experimental.launch | |
import kotlinx.coroutines.experimental.sync.Mutex |
This file contains 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
import android.app.Activity | |
import android.app.Application | |
import android.content.Context | |
import android.os.Bundle | |
// A Graph is just an interface that exposes your dependencies (like a Dagger 2 @Component). | |
interface Graph { | |
val context: Context |
This file contains 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
/** | |
* An abstraction around a 3rd party SDK that does some magic to | |
* identify if a user is a bot or not. | |
* | |
* The real implementation may have direct Android dependencies, | |
* so being able to swap this out is useful for unit testing | |
*/ | |
interface VendorSdk { | |
suspend fun isUserABot(): Boolean | |
} |
NewerOlder