Skip to content

Instantly share code, notes, and snippets.

Working from home

Andrew Chen yongjhih

Working from home
View GitHub Profile
View NetworkStatusTracker_full.kt
import android.content.Context
import android.os.Bundle
import android.widget.TextView
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
Vove7 / flutter_aar_upload.gradle
Created Mar 11, 2021
Flutter module upload aar to maven
View flutter_aar_upload.gradle
// This script is used to initialize the build in a module or plugin project.
// During this phase, the script applies the Maven plugin and configures the
// destination of the local repository.
// The local repository will contain the AAR and POM files.
void configureProject(Project project, String mavenUrl, String mavenUser, String mavenPwd, String version) {
if (!project.hasProperty("android")) {
throw new GradleException("Android property not found.")
if (!"libraryVariants")) {
gmk57 / 1 ViewBindingDelegates.kt
Last active Jan 30, 2023
Kotlin delegates for Android View Binding with usage examples
View 1 ViewBindingDelegates.kt
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import androidx.viewbinding.ViewBinding
manuelvicnt / LocationRepository.kt
Last active Dec 28, 2022
LocationFlow shareIn
View LocationRepository.kt
val FusedLocationProviderClient.locationFlow() = callbackFlow<Location> {
// Make the flow follow the applicationScope
// Emit the last emitted element to new collectors
replay = 1,
// Keep the producer active while there are active subscribers
started = SharingStarted.WhileSubscribed()
serhii-pokrovskyi / OnDestroyNullable.kt
Created Dec 5, 2020
Property that will be destroyed in onDestoy
View OnDestroyNullable.kt
fun <T> LifecycleOwner.onDestroyNullable(): ReadWriteProperty<LifecycleOwner, T> =
object : ReadWriteProperty<LifecycleOwner, T>, DefaultLifecycleObserver {
private var value: T? = null
init {
jamiesanson / ViewLifecycleLazy.kt
Last active Sep 10, 2022
A Kotlin lazy implementation which automatically clears itself at appropriate times in the View Lifecycle, with a Fragment example
View ViewLifecycleLazy.kt
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.Observer
import kotlin.reflect.KProperty
fun <T> Fragment.viewLifecycleLazy(initialise: () -> T): ReadOnlyProperty<Fragment, T> =
object : ReadOnlyProperty<Fragment, T>, DefaultLifecycleObserver {
View FragmentExt.kt
* Based on
* Refactored to use the preferred `DefaultLifecycleObserver` which does not rely on the annotation processor.
* See
* Usage:
* `private var binding: TheViewBinding by viewLifecycle()`
Zhuinden / FragmentViewBindingDelegate.kt
Last active Jan 25, 2023
Fragment view binding delegate
View FragmentViewBindingDelegate.kt
import android.view.View
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.Observer
import androidx.viewbinding.ViewBinding
jamiesanson / ViewLifecycleBinding.kt
Last active Oct 12, 2022
Kotlin Property Delegate for Fragment view lifecycle binding
View ViewLifecycleBinding.kt
fun <T> Fragment.viewLifecycle(bindUntilEvent: Lifecycle.Event = Lifecycle.Event.ON_DESTROY): ReadWriteProperty<Fragment, T> =
object: ReadWriteProperty<Fragment, T>, LifecycleObserver {
// A backing property to hold our value
private var binding: T? = null
private var viewLifecycleOwner: LifecycleOwner? = null
init {
// Observe the View Lifecycle of the Fragment
av / main.dart
Created Jan 13, 2020
Flutter: neu
View main.dart
import 'package:flutter/material.dart';
void main() => runApp(NeumorphicApp());
class NeumorphicApp extends StatelessWidget {
Widget build(BuildContext context) {
return MaterialApp(
title: 'Neumorphic App',
theme: ThemeData(