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
sealed class Result<T> { | |
data class Success<T>(val value: T) : Result<T>() | |
data class Failure<T>(val message: String? = null) : Result<T>() | |
val isSuccess get() = this is Success | |
val isFailure get() = this is Failure | |
fun <T> success(v: T) = Success(v) | |
fun <T> failure(m: String? = null) = Failure<T>(m) |
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
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.example_layout) | |
if (savedInstanceState == null) { | |
viewPager.adapter = PagerAdapter(supportFragmentManager) | |
dotsIndicator.setViewPager(viewPager) | |
} | |
} |
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 android.content.Context | |
import android.database.DataSetObserver | |
import android.graphics.Color | |
import android.graphics.drawable.GradientDrawable | |
import android.support.v4.view.ViewPager | |
import android.util.AttributeSet | |
import android.util.Log | |
import android.view.LayoutInflater | |
import android.widget.FrameLayout |
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
fun <T, R> LiveData<T>.then(callback: (T) -> LiveData<R>): LiveData<R> { | |
return Transformations.switchMap(this, { | |
result(it) | |
}) | |
} |
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 android.text.SpannableStringBuilder | |
import android.text.Spanned.SPAN_INCLUSIVE_EXCLUSIVE | |
import java.util.* | |
/** A [SpannableStringBuilder] wrapper whose API doesn't make me want to stab my eyes out. */ | |
class KTruss { | |
private val builder: SpannableStringBuilder = SpannableStringBuilder() | |
private val stack: Deque<Span> = ArrayDeque<Span>() | |
fun append(string: String): KTruss { |