Skip to content

Instantly share code, notes, and snippets.

View matpag's full-sized avatar
🐧
Noot-Nooting around

MatPag matpag

🐧
Noot-Nooting around
View GitHub Profile
@tadfisher
tadfisher / AndroidUpdaterState.kt
Created June 1, 2022 18:00
In-app updates for Jetpack Compose
package com.mercury.app.updater
import android.app.Activity
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.ActivityResult
import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.IntentSenderRequest
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.runtime.Composable
import androidx.compose.runtime.Stable
@mitchtabian
mitchtabian / AndroidManifest.xml
Last active October 21, 2020 12:01
Enable Fragment constructor injection for instrumentation tests when using Hilt. This is a modified version of https://github.com/android/architecture-samples/blob/dev-hilt/app/src/androidTest/java/com/example/android/architecture/blueprints/todoapp/HiltExt.kt
<!-- **NOTE** This must be in /debug/ -->
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.codingwithmitch.daggerhiltplayground">
<application>
<activity
android:name="com.codingwithmitch.daggerhiltplayground.HiltTestActivity"
android:exported="false" />
</application>
@Karn
Karn / LogController.kt
Last active October 18, 2023 14:59
An example implementation of a process to write logs to disk asynchronously using RxJava
typealias LogElement = Triple<String, Int, String?>
object LogController {
private var flush = BehaviorSubject.create<Long>()
private var flushCompleted = BehaviorSubject.create<Long>()
private var LOG_LEVELS = arrayOf("", "", "VERBOSE",
"DEBUG",
"INFO",
@ElfSundae
ElfSundae / git-checkout-all-branches.sh
Last active September 19, 2023 23:10
Git checkout all remote branches
#!/bin/bash
remote=origin ; for brname in `git branch -r | grep $remote | grep -v /master | grep -v /HEAD | awk '{gsub(/^[^\/]+\//,"",$1); print $1}'`; do git branch --track $brname $remote/$brname || true; done 2>/dev/null
@matpag
matpag / DialogNavigator.kt
Last active February 16, 2021 12:29 — forked from fbarthelery/DialogNavigator.kt
Minor changes
package com.geekorum.geekdroid.navigation
import android.content.Context
import android.os.Bundle
import android.util.AttributeSet
import androidx.core.content.res.use
import androidx.core.os.bundleOf
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
package com.geekorum.geekdroid.navigation
import android.content.Context
import android.os.Bundle
import android.util.AttributeSet
import androidx.core.content.res.use
import androidx.core.os.bundleOf
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
@afollestad
afollestad / BroadcastReceiver.kt
Last active January 14, 2024 10:23
A Lifecycle components aware BroadcastReceiver DSL (Kotlin)
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import androidx.lifecycle.Lifecycle.Event.ON_DESTROY
import androidx.lifecycle.Lifecycle.Event.ON_START
import androidx.lifecycle.LifecycleObserver
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.OnLifecycleEvent
import android.content.BroadcastReceiver as StockReceiver
@erics
erics / executeGitInGradle.txt
Last active June 2, 2023 20:40
execute git command in gradle
def getGitCommand = { ->
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'log','--date=local','--name-status','--after="2018.07.19"'
standardOutput = stdout
}
return stdout.toString().trim()
}
task prinGitLog{
import android.app.Application
import android.arch.lifecycle.LiveData
import android.content.Context
import android.net.ConnectivityManager
import android.net.Network
import android.net.NetworkInfo
import android.net.NetworkRequest
import android.os.Build
import android.support.annotation.RequiresPermission
import android.support.annotation.VisibleForTesting
@JoseAlcerreca
JoseAlcerreca / EventObserver.kt
Created April 26, 2018 12:14
An Observer for Events, simplifying the pattern of checking if the Event's content has already been handled.
/**
* An [Observer] for [Event]s, simplifying the pattern of checking if the [Event]'s content has
* already been handled.
*
* [onEventUnhandledContent] is *only* called if the [Event]'s contents has not been handled.
*/
class EventObserver<T>(private val onEventUnhandledContent: (T) -> Unit) : Observer<Event<T>> {
override fun onChanged(event: Event<T>?) {
event?.getContentIfNotHandled()?.let { value ->
onEventUnhandledContent(value)