Skip to content

Instantly share code, notes, and snippets.

Avatar

Annyce Davis adavis

View GitHub Profile
@adavis
adavis / NonOrganizerTest.kt
Last active Sep 17, 2021
Instrumentation tests for Jetpack Compose screen using Intents for navigation
View NonOrganizerTest.kt
@ExperimentalAnimationApi
@RunWith(AndroidJUnit4::class)
class NonOrganizerTest {
@get:Rule
val composeTestRule = createAndroidComposeRule<MainActivity>()
@Before
fun goToNonOrganizerFragment() {
composeTestRule.activityRule.scenario.onActivity {
@adavis
adavis / product_item.xml
Created Mar 13, 2021
Sample Android XML layout file for a RecyclerView item
View product_item.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp">
<ImageView
@adavis
adavis / ChipsView.kt
Last active Apr 2, 2021
A function to programmatically add views to ConstraintLayout with Flow
View ChipsView.kt
class ChipsView<T : Parcelable>(ctx: Context, attr: AttributeSet) : ConstraintLayout(ctx, attr) {
...
private fun addSubviews() {
val flow = Flow(context).apply {
id = generateViewId()
setWrapMode(Flow.WRAP_CHAIN)
setHorizontalStyle(Flow.CHAIN_PACKED)
setHorizontalAlign(Flow.HORIZONTAL_ALIGN_START)
setHorizontalBias(0f)
@adavis
adavis / commit_message_clean_up.kts
Created Mar 11, 2020
Removes the commit messages that reference merging pull requests from logs
View commit_message_clean_up.kts
import java.io.File
// Get the passed in file, i.e. "-f some/path" or use the default file name
val file = if (args.contains("-f")) args[1 + args.indexOf("-f")]
else "commit_messages.log"
File("${file}_clean").printWriter().use { out ->
File(file).forEachLine { msg ->
if (msg.startsWith("Merge pull request").not()) {
out.println(msg)
@adavis
adavis / ConfettiJobCreator.kt
Last active Jun 21, 2019
Snippets from Dagger and Dynamic Feature Module Support Article
View ConfettiJobCreator.kt
class ConfettiJobCreator @Inject constructor(
private val jobs: @JvmSuppressWildcards Map<String, Provider<Job>>
) : JobCreator {
override fun create(tag: String): Job? = jobs[tag]?.get()
}
@adavis
adavis / unique_id_widget.dart
Last active Apr 25, 2019
Displays a pin number pad with 6 fields
View unique_id_widget.dart
import 'dart:math' show min;
import 'package:flutter/material.dart';
class UniqueId extends StatefulWidget {
const UniqueId({Key key, this.onSubmit}) : super(key: key);
final ValueChanged<String> onSubmit;
@adavis
adavis / tests_with_coverage.sh
Last active Jan 12, 2021
Script for running all Flutter unit and widget tests with code coverage and then displaying the HTML report.
View tests_with_coverage.sh
#!/usr/bin/env bash
red=$(tput setaf 1)
none=$(tput sgr0)
show_help() {
printf "usage: $0 [--help] [--report] [--test] [<path to package>]
Script for running all unit and widget tests with code coverage.
(run from root of repo)
@adavis
adavis / PULL_REQUEST_TEMPLATE.md
Last active Sep 18, 2020
Sample Pull Request template for use on GitHub
View PULL_REQUEST_TEMPLATE.md

Description

Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context.

Fixed #issue

Type of Change

Please delete options that are not relevant.

@adavis
adavis / PlanetDetailUi.kt
Last active Dec 16, 2017
Implementation of the createView method for a Sample Anko Component
View PlanetDetailUi.kt
override fun createView(ui: AnkoContext<PlanetDetailFragment>): View {
return with(ui) {
val container = verticalLayout {
lparams(matchParent)
textView {
setLineSpacing(8f, 1f)
}.lparams {
topMargin = dip(16)
}
@adavis
adavis / CommonExtensions.kt
Last active Sep 15, 2021
Common Android Extensions in Kotlin
View CommonExtensions.kt
fun View.visible() {
visibility = View.VISIBLE
}
fun View.invisible() {
visibility = View.INVISIBLE
}
fun View.gone() {
visibility = View.GONE