Skip to content

Instantly share code, notes, and snippets.

View charbgr's full-sized avatar
Implementing common sense

Vasilis Charalampakis charbgr

Implementing common sense
View GitHub Profile
charbgr / UserScopeModule.kt
Last active August 13, 2018 15:03
Releasing dependencies in Koin
View UserScopeModule.kt
module("user_scope") {
single("endpoint") { Endpoint() }
// when user switches account, we simply do this:
charbgr / UnitTest.kt
Last active August 13, 2018 09:31
Mocking dependencies in unit-test using Koin
View UnitTest.kt
declare { // It is provided in koin-test utilities
single("draftStorage") {
FakeStorage() as Storage
charbgr / DummyFragment.kt
Last active August 13, 2018 09:03
Injection with Koin
View DummyFragment.kt
class DummyFragment : Fragment() {
private val draftStorage: Storage by inject("draftStorage")
charbgr / DummyFragment.kt
Last active August 13, 2018 09:03
Inject with Dagger
View DummyFragment.kt
class DummyFragment : Fragment() {
lateinit var draftStorage: Storage
override fun onCreate(savedInstanceState: Bundle?) {
(activity as BaseActivity).component().inject(this)
charbgr / OffsetsWithDirection.kt
Created August 17, 2017 12:54 — forked from ZacSweers/OffsetsWithDirection.kt
Observable stream of AppBarLayout offsets + scroll direction
View OffsetsWithDirection.kt
* Here we want to get the appbar offset changes paired with the direction it's moving and
* using RxBinding's great `offsetChanges` API to make an rx Observable of this. The first
* part buffers two while skipping one at a time and emits "scroll direction" enums. Second
* part is just a simple map to pair the offset with the resolved scroll direction comparing
* to the previous offset. This gives us a nice stream of (offset, direction) emissions.
* Note that the filter() is important if you manipulate child views of the ABL. If any child
* view requests layout again, it will trigger an emission from the offset listener with the
* same value as before, potentially causing measure/layout/draw thrashing if your logic
charbgr / ErrorHandlerExtensions.kt
Last active October 27, 2016 15:10
ErrorHandler Kotlin Extension
View ErrorHandlerExtensions.kt
* Creates a new instance of [ErrorHandler]
* Passing a lambda is optional
fun Throwable.handleIsolated(func: ErrorHandler.() -> Unit = {}) {
val errorHandler = ErrorHandler.createIsolated()
charbgr /
Last active October 26, 2016 13:52
Android - Gif Recording Device
adb shell screenrecord --bit-rate=20M "/sdcard/recording.mp4" &
echo "Recording.. ($PID)"
read -n1 -r -p "Press any key to stop" key
sleep 1
adb pull "/sdcard/recording.mp4"
echo "Gififying..."
gifify -r 60 "recording.mp4"
import android.view.ViewGroup;
public abstract class HeaderFooterRecyclerViewAdapter<
ContentViewHolder extends RecyclerView.ViewHolder,
HeaderViewHolder extends RecyclerView.ViewHolder,
FooterViewHolder extends RecyclerView.ViewHolder>
extends RecyclerView.Adapter<RecyclerView.ViewHolder> {