Skip to content

Instantly share code, notes, and snippets.

View dariopellegrini's full-sized avatar

Dario Pellegrini dariopellegrini

View GitHub Profile
@dariopellegrini
dariopellegrini / BaseController.kt
Created November 16, 2018 16:42
Android Conductor base controller
abstract class BaseController: Controller(), LayoutContainer {
private var _containerView: View? = null
override val containerView: View?
get() = _containerView
protected abstract fun inflateView(inflater: LayoutInflater, container: ViewGroup): View
var toolbar: Toolbar? = null
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup): View {
val view = inflateView(inflater, container).also {
@dariopellegrini
dariopellegrini / Variable.kt
Created April 9, 2018 21:46
A Kotlin version of Variable class, which lets subscribers to be updated after every variable change.
class Variable<T>(private val defaultValue: T) {
var value: T = defaultValue
set(value) {
field = value
observable.onNext(value)
}
val observable = BehaviorSubject.createDefault(value)
}
@dariopellegrini
dariopellegrini / Binding.kt
Created April 9, 2018 21:45
Android EditText data binding with RxKotlin
infix fun Variable<String>.binding(editText: EditText) {
var block = false
this.observable.subscribe {
if (block == false) {
block = true
editText.setText(it)
block = false
}
}
@dariopellegrini
dariopellegrini / Reachability.swift
Created October 10, 2017 14:33
Swift Rx connection checker with timer
import SystemConfiguration
import RxSwift
public class Reachability {
class func isConnectedToNetwork() -> Bool {
var zeroAddress = sockaddr_in(sin_len: 0, sin_family: 0, sin_port: 0, sin_addr: in_addr(s_addr: 0), sin_zero: (0, 0, 0, 0, 0, 0, 0, 0))
zeroAddress.sin_len = UInt8(MemoryLayout.size(ofValue: zeroAddress))
zeroAddress.sin_family = sa_family_t(AF_INET)