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
# A tiered light indicator is pretty easy to build and this will show you how to build scalable indicators using (2n + 1) decoders | |
# and one arithmetic. I made mine with three lights, which is enough to understand at a glance what's going on. | |
# | |
# You can also put the logic on the lights and use fewer deciders but I prefer this setup because it's easier to modify. | |
# | |
# Inputs: | |
# - R is a constant "ratio". It should be set to the integer value of (tank size - 1 / # of lights). | |
# - resource types | |
# | |
# Variables: |
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
// In the following declaration, what happens when you call fn()? | |
val fn: () -> Unit = { "I am not a string" } | |
// Due to inference, the lambda is evaluated to return Unit and the string is discarded. It is as if you typed, | |
fun fn(): Unit { | |
"I am not a string" | |
return | |
} |
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
dependencies { | |
compile 'com.android.support.constraint:constraint-layout:1.1.0' | |
} |
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
<Button | |
android:layout_width="0dp" | |
android:layout_height="wrap_content" | |
app:layout_constraintWidth_percent="0.70" /> |
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
{"videos":[{"title":"Android Jetpack: EmojiCompat","description":"With the EmojiCompat library, part of Jetpack, your app can get backwards-compatible emoji support on devices with API level 19 and higher and get rid of the blank square characters. To use EmojiCompat, initialize the library when the application starts by using downloadable or bundled fonts. Start supporting emojis in your text views, either by integrating the provided widgets or update your custom views by using the provided helper classes. \n\nFor more information:\nEmojiCompat guide → https://goo.gl/7bEoXB \nEmojiCompat sample app → https://goo.gl/7bEoXB \nGoogle I/O 2017 talk on “What’s new in Support Library” → https://goo.gl/KeRvqB\n\nWatch more Android Jetpack videos here → https://goo.gl/kw8LPv\n\nSubscribe to the Android Developers channel here → https://goo.gl/vLYDU\n\n#jetpack #featured","url":"https://www.youtube.com/watch?v=sYGKUtM2ga8","updated":"2018-06-07T17:09:43+00:00","thumbnail":"https://i4.ytimg.com/vi/sYGKUtM2ga8/hqdefaul |
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
package com.example.android.gdgfinder.libs | |
import kotlinx.coroutines.CompletableDeferred | |
import kotlinx.coroutines.CoroutineScope | |
import kotlinx.coroutines.Dispatchers | |
import kotlinx.coroutines.channels.Channel | |
import kotlinx.coroutines.launch | |
class RequestLimiter<R>(scope: CoroutineScope) { | |
val requestChannel = Channel<Pair<suspend () -> R, CompletableDeferred<R>>>() |
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
/* Copyright 2019 The Android Open Source Project | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* https://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software | |
* distributed under the License is distributed on an "AS IS" BASIS, |
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
class ProductsViewModel(val productsRepository: ProductsRepository): ViewModel() { | |
private val _sortedProducts = MutableLiveData<List<ProductListing>>() | |
val sortedProducts: LiveData<List<ProductListing>> = _sortedProducts | |
/** | |
* Called by the UI when the user clicks the appropriate sort button | |
*/ | |
fun onSortAscending() = sortPricesBy(ascending = true) | |
fun onSortDescending() = sortPricesBy(ascending = false) |
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
class ProductsRepository(val productsDao: ProductsDao) { | |
/** | |
* This is a "regular" suspending function, which means the caller must | |
* be in a coroutine. The repository is not responsible for starting or | |
* stopping coroutines since it doesn't have a natural lifecycle to cancel | |
* unnecessary work. | |
* | |
* This *may* be called from Dispatchers.Main and is main-safe because | |
* Room will take care of main-safety for us. |