Navigation Menu

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
import android.support.v7.widget.RecyclerView;
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> {
@charbgr
charbgr / record-gif.sh
Last active October 26, 2016 13:52
Android - Gif Recording Device
#!/bin/bash
adb shell screenrecord --bit-rate=20M "/sdcard/recording.mp4" &
PID=$!
echo "Recording.. ($PID)"
read -n1 -r -p "Press any key to stop" key
kill -SIGHUP $PID
sleep 1
adb pull "/sdcard/recording.mp4"
echo "Gififying..."
gifify -r 60 "recording.mp4"
@charbgr
charbgr / ErrorHandlerExtensions.kt
Last active October 27, 2016 15:10
ErrorHandler Kotlin Extension
/**
* Creates a new instance of [ErrorHandler]
* Passing a lambda is optional
*/
fun Throwable.handleIsolated(func: ErrorHandler.() -> Unit = {}) {
val errorHandler = ErrorHandler.createIsolated()
func(errorHandler)
errorHandler.handle(this)
}
@charbgr
charbgr / DummyFragment.kt
Last active August 13, 2018 09:03
Inject with Dagger
class DummyFragment : Fragment() {
@Inject
@Named("draftStorage")
lateinit var draftStorage: Storage
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
(activity as BaseActivity).component().inject(this)
}
@charbgr
charbgr / DummyFragment.kt
Last active August 13, 2018 09:03
Injection with Koin
class DummyFragment : Fragment() {
private val draftStorage: Storage by inject("draftStorage")
}
@charbgr
charbgr / UnitTest.kt
Last active August 13, 2018 09:31
Mocking dependencies in unit-test using Koin
declare { // It is provided in koin-test utilities
single("draftStorage") {
FakeStorage() as Storage
}
}
@charbgr
charbgr / UserScopeModule.kt
Last active August 13, 2018 15:03
Releasing dependencies in Koin
module("user_scope") {
single("endpoint") { Endpoint() }
...
}
// when user switches account, we simply do this:
release("user_scope")
@charbgr
charbgr / OffsetsWithDirection.kt
Created August 17, 2017 12:54 — forked from ZacSweers/OffsetsWithDirection.kt
Observable stream of AppBarLayout offsets + scroll direction
/*
* 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