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
val cardView: MaskedCardView | |
fun usageExample() { | |
// Each corner can have a different radius | |
val shapeBuilder = cardView.shapeAppearanceModel.toBuilder() | |
.setTopLeftCornerSize(AbsoluteCornerSize(dpToPx(12f))) | |
.setBottomRightCornerSize(AbsoluteCornerSize(dpToPx(6f))) | |
cardView.shapeAppearanceModel = shapeBuilder.build() | |
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
<?xml version="1.0" encoding="utf-8"?> | |
<manifest> | |
<!-- Let's us query installed apps so we can open them (required on Android 11) --> | |
<queries> | |
<intent> | |
<action android:name="android.intent.action.MAIN" /> | |
<data android:mimeType="*/*" /> | |
</intent> | |
<intent> | |
<action android:name="android.intent.action.VIEW" /> |
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
/** | |
* Validates login credentials. | |
* | |
* To use it, call [validate] with your [Credentials] and check the returned [ValidationResult]. | |
* | |
* To add new validations, define the rules which need to be satisfied | |
* and the errors that can be thrown in response to dissatisfied rules. | |
* | |
* For each field in your login form define a mapping of [Rule]s to [Error]s | |
* which apply to the given field. |
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
@Retention(AnnotationRetention.RUNTIME) | |
@JsonQualifier | |
annotation class JsonNullable | |
/** | |
* Fields annotated with @JsonNullable will be serialized as `null` instead of being ignored. | |
*/ | |
class JsonNullableAdapter : JsonAdapter.Factory { | |
override fun create(type: Type, annotations: MutableSet<out Annotation>, moshi: Moshi): JsonAdapter<Any>? { |
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
data class Quadruple<out A, out B, out C, out D>(val first: A, val second: B, val third: C, val forth: D) | |
data class Quintuple<out A, out B, out C, out D, out E>(val first: A, val second: B, val third: C, val fourth: D, val fifth: E) | |
/** A shorthand for a null LiveData object */ | |
val NULL_LD = null as LiveData<Nothing>? | |
fun <X, Y> LiveData<X>.map(mapFunction: (X) -> Y): LiveData<Y> { | |
return Transformations.map(this, mapFunction) | |
} |
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
object Example { | |
fun alterTableUsage(database: SupportSQLiteDatabase) { | |
DbMigrationsHelper.alterTable( | |
db = database, | |
tableName = "Reservations", | |
columns = mapOf( | |
"id INTEGER".toExisting(), // Retains without changes | |
"title TEXT".toExisting("name"), // Renames column "name" to "title" | |
"description TEXT".toNothing(), // Adds a new column |
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
org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 | |
org.gradle.daemon=true | |
org.gradle.configureondemand=true | |
org.gradle.caching=true | |
android.enableBuildCache=true |
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
data class UniqueIdentifier<out T>(val value: T) | |
typealias TransactionId = UniqueIdentifier<Int> | |
class UniqueIdentifierAdapter : JsonSerializer<UniqueIdentifier<*>>, JsonDeserializer<UniqueIdentifier<*>> { | |
override fun serialize( | |
src: UniqueIdentifier<*>, | |
typeOfSrc: Type, | |
context: JsonSerializationContext |
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 TransactionListViewModel @Inject constructor( | |
private val repository: TransactionListRepository | |
) : ViewModel() { | |
val transactions = MediatorLiveData<Resource<List<Transaction>>>() | |
private val retryTransactionsTrigger = MutableLiveData<Nothing>() | |
private val transactionListFilter = MutableLiveData<TransactionListFilter>() | |
init { | |
transactionListFilter.value = TransactionListFilter() |
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 java.util.Scanner | |
fun main(args: Array<String>) { | |
val inputReader = Scanner(System.`in`) | |
val input = inputReader.nextLine() | |
val sizeOfStairs = input.toInt() | |
StaircaseBuilder() | |
.build(sizeOfStairs) |
NewerOlder