Skip to content

Instantly share code, notes, and snippets.

View TylerMcCraw's full-sized avatar

Tyler McCraw TylerMcCraw

View GitHub Profile
@josh-burton
josh-burton / androidmanifest.xml
Created May 3, 2017 02:07
Prevent TouchWiz from surrounding your app icon in a frame
<!-- Prevents TouchWiz from surrounding your app icon in a frame -->
<!-- Add to your manifest inside the application tag -->
<meta-data
android:name="com.samsung.android.icon_container.has_icon_container"
android:value="true"/>
@adavis
adavis / AppComponent.java
Last active March 2, 2019 15:18
Background Jobs with Android Job and Dagger
@Singleton
@Component(
modules = {
AppModule.class, JobsModule.class
}
)
public interface AppComponent
{
Application getApplication ();
@mlykotom
mlykotom / Connecting_InjectingSavedStateViewModelFactory.kt
Last active May 4, 2020 14:06
Connecting The Dots :: InjectingViewModelFactory.kt
@Reusable
class InjectingSavedStateViewModelFactory @Inject constructor(
private val assistedFactories: Map<Class<out ViewModel>, @JvmSuppressWildcards AssistedSavedStateViewModelFactory<out ViewModel>>,
private val viewModelProviders: Map<Class<out ViewModel>, @JvmSuppressWildcards Provider<ViewModel>>
) {
/**
* Creates instance of ViewModel either annotated with @AssistedInject or @Inject and passes dependencies it needs.
*/
fun create(owner: SavedStateRegistryOwner, defaultArgs: Bundle? = null) =
object : AbstractSavedStateViewModelFactory(owner, defaultArgs) {
@stevewadsworth
stevewadsworth / Gradle.properties
Last active October 13, 2020 18:43 — forked from neyguvj/build.gradle
Set default build variant witn variant filter (workaround)
#.
# Add to the end of existing file
#.
#.
# By default this is not a CI environment
# To configure for CI either pass to the gradle command -PisCI=true or
# set ORG_GRADLE_PROJECT_isCI=true in the environment
isCI=false
@zachleat
zachleat / reading_time.rb
Last active October 21, 2020 23:00
Read this in X minutes Liquid Filter Plugin (for Jekyll)
# Outputs the reading time
# Read this in “about 4 minutes”
# Put into your _plugins dir in your Jekyll site
# Usage: Read this in about {{ page.content | reading_time }}
module ReadingTimeFilter
def reading_time( input )
words_per_minute = 180
class FragmentViewBindingDelegate<T : ViewBinding>(private val factory: (View) -> T) : ReadOnlyProperty<Fragment, T> {
private var backingValue: T? = null
override operator fun getValue(thisRef: Fragment, property: KProperty<*>): T = when (val binding = backingValue) {
null -> {
thisRef.parentFragmentManager.registerFragmentLifecycleCallbacks(object : FragmentManager.FragmentLifecycleCallbacks() {
override fun onFragmentViewDestroyed(fm: FragmentManager, fragment: Fragment) {
if (fragment != thisRef) return
backingValue = null
fm.unregisterFragmentLifecycleCallbacks(this)
@apkelly
apkelly / MatrixCompose.kt
Last active September 16, 2021 23:11
Matrix Animation
import android.graphics.Typeface
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.RowScope
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.runtime.Composable
@rishabhkohli
rishabhkohli / !!ViewLifecycleAware.kt
Last active December 29, 2021 17:41 — forked from jamiesanson/ViewLifecycleLazy.kt
A Kotlin delegated property implementation which automatically clears itself at appropriate times in the View Lifecycle of a Fragment.
import androidx.fragment.app.Fragment
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner
import kotlin.properties.ReadOnlyProperty
import kotlin.reflect.KProperty
fun <T> Fragment.viewLifecycleAware(initialise: () -> T): ReadOnlyProperty<Fragment, T> =
object : ReadOnlyProperty<Fragment, T>, DefaultLifecycleObserver {
private var value: T? = null
@thelumiereguy
thelumiereguy / InfiniteSquareMandala.kt
Last active March 22, 2022 06:12
A example to animate and draw a square-based Mandala on Jetpack Compose's Canvas
import androidx.compose.animation.core.*
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
/**
* Navigates only if this is safely possible; when this Fragment is still the current destination.
*/
fun Fragment.navigateSafe(
@IdRes resId: Int,
args: Bundle? = null,
navOptions: NavOptions? = null,
navigatorExtras: Navigator.Extras? = null
) {
if (mayNavigate()) findNavController().navigate(