Skip to content

Instantly share code, notes, and snippets.

Dario Pellegrini dariopellegrini

Block or report user

Report or block dariopellegrini

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@dariopellegrini
dariopellegrini / BaseController.kt
Created Nov 16, 2018
Android Conductor base controller
View BaseController.kt
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 Apr 9, 2018
A Kotlin version of Variable class, which lets subscribers to be updated after every variable change.
View Variable.kt
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 Apr 9, 2018
Android EditText data binding with RxKotlin
View Binding.kt
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 Oct 10, 2017
Swift Rx connection checker with timer
View Reachability.swift
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)
You can’t perform that action at this time.