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
# Convert from H264 to H265 | |
ffmpeg -i in.mov -c:v libx265 -an -x265-params crf=20 output.mp4 | |
# Tag as HVC instead of HEV1 so iOS can play it | |
ffmpeg -i output.mp4 -vcodec copy -acodec copy -tag:v hvc1 output2.mp4 | |
# Bonus: it can take a second to play (no more than H264) so here's how to generate | |
# a thumbnail of the first frame to embed in your view as a placeholder. | |
ffmpeg -i output2.mp4 -vf "select=eq(n\,34)" -vframes 1 thumbnail.png |
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 SwiftUI | |
import Combine | |
public struct ChangeObserver<V: Equatable>: ViewModifier { | |
public init(newValue: V, action: @escaping (V) -> Void) { | |
self.newValue = newValue | |
self.newAction = action | |
} | |
private typealias Action = (V) -> Void |
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
/** | |
* Like Delegates.observable except it only calls the callback when the value actually changes. | |
*/ | |
public inline fun <T> uniqueObservable(initialValue: T, emitInitial: Boolean = false, crossinline onChange: (value: T) -> Unit): ReadWriteProperty<Any?, T> { | |
if (emitInitial) onChange(initialValue) | |
return object : ObservableProperty<T>(initialValue) { | |
override fun afterChange(property: KProperty<*>, oldValue: T, newValue: T) { | |
if (oldValue != newValue) onChange(newValue) | |
} | |
} |
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 androidx.compose.foundation.Image | |
import androidx.compose.foundation.layout.Row | |
import androidx.compose.foundation.layout.padding | |
import androidx.compose.foundation.layout.preferredSize | |
import androidx.compose.material.MaterialTheme | |
import androidx.compose.material.Text | |
import androidx.compose.runtime.Composable | |
import androidx.compose.ui.Alignment | |
import androidx.compose.ui.Modifier | |
import androidx.compose.ui.graphics.ColorFilter |
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 timber.log.Timber | |
import kotlin.properties.ReadOnlyProperty | |
import kotlin.reflect.KProperty | |
class MyClass { | |
// This will automatically have the TAG "MyClass" | |
private val log by timber() | |
fun logSomething() { | |
log.i("Hello") |
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
context.registerReceiverInScope(scope, WifiManager.WIFI_STATE_CHANGED_ACTION) { intent -> | |
val state = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, WifiManager.WIFI_STATE_DISABLED) | |
// Use wifi state here | |
} | |
/** | |
* Register a broadcast receiver in the given coroutine scope for any of the specified actions | |
* and call the callback when it is invoked. | |
*/ | |
fun Context.registerReceiverInScope( |
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 WifiNetworksFragment : TonalFragment(R.layout.wifi_networks_fragment) { | |
// This automatically creates and clears the binding in a lifecycle-aware way. | |
private val binding: WifiNetworksFragmentBinding by viewBinding() | |
... | |
} | |
class WifiNetworkView @JvmOverloads constructor( | |
context: Context, | |
attrs: AttributeSet? = null, |
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
/** | |
* Fade a view to visible or gone. This function is idempotent - it can be called over and over again with the same | |
* value without affecting an in-progress animation. | |
*/ | |
fun View.fadeTo(visible: Boolean, duration: Long = 500, startDelay: Long = 0, toAlpha: Float = 1f) { | |
// Make this idempotent. | |
val tagKey = "fadeTo".hashCode() | |
if (visible == isVisible && animation == null && getTag(tagKey) == null) return | |
if (getTag(tagKey) == visible) return |
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
// | |
// ContentView.swift | |
// Example of using matchedGeometryEffect in iOS 13 code | |
// matchedGeometryEffect example code taken and adapted from : | |
// https://sarunw.com/posts/a-first-look-at-matchedgeometryeffect/ | |
// | |
// Created by Emil Pedersen on 16/10/2020. | |
// | |
struct ContentView: 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
// Deps | |
interface Database | |
interface Network | |
// Child | |
interface ChildRepository | |
class Child(dependencies: Dependencies) { |
NewerOlder