This file contains hidden or 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
class NoAnimationItemAnimator : SimpleItemAnimator() { | |
override fun animateRemove(holder: RecyclerView.ViewHolder): Boolean { | |
dispatchRemoveFinished(holder) | |
return false | |
} | |
override fun animateAdd(holder: RecyclerView.ViewHolder): Boolean { | |
dispatchAddFinished(holder) | |
return false | |
} |
This file contains hidden or 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
class StickySectionItemDecoration( | |
private val recyclerView: RecyclerView, | |
private val callback: Callback | |
) : RecyclerView.ItemDecoration() { | |
private var headerViewCache: View? = null | |
private var isInLayout = false | |
interface Callback { | |
fun isHeader(position: Int): Boolean |
This file contains hidden or 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
#!/bin/sh | |
# Check if device is connected | |
if [[ $(adb get-state) ]]; then | |
# Run Android and jUnit tests | |
./gradlew clean testDebug connectedDebugAndroidTest | |
else | |
# Run jUnit tests | |
./gradlew clean testDebug | |
fi |
This file contains hidden or 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 java.util.* | |
@DslMarker | |
annotation class CalendarDsl | |
@CalendarDsl | |
class CalendarBuilder(val calendar: Calendar) { | |
fun dayOfMonth(function: () -> Int) = calendar.apply { set(Calendar.DAY_OF_MONTH, function()) } | |
fun dayOfMonth(value: Int) = calendar.apply { set(Calendar.DAY_OF_MONTH, value) } |
This file contains hidden or 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 String.encodeBase64ToString(): String = String(this.toByteArray().encodeBase64()) | |
fun String.encodeBase64ToByteArray(): ByteArray = this.toByteArray().encodeBase64() | |
fun ByteArray.encodeBase64ToString(): String = String(this.encodeBase64()) | |
fun String.decodeBase64(): String = String(this.toByteArray().decodeBase64()) | |
fun String.decodeBase64ToByteArray(): ByteArray = this.toByteArray().decodeBase64() | |
fun ByteArray.decodeBase64ToString(): String = String(this.decodeBase64()) | |
fun ByteArray.encodeBase64(): ByteArray { | |
val table = (CharRange('A', 'Z') + CharRange('a', 'z') + CharRange('0', '9') + '+' + '/').toCharArray() |
This file contains hidden or 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
object Bus { | |
// val event = Event<Any>() | |
} | |
class Event<TYPE> { | |
private val handlers = arrayListOf<((TYPE) -> Unit)>() | |
operator fun plusAssign(handler: (TYPE) -> Unit) { | |
handlers.add(handler) | |
} |
This file contains hidden or 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
inline fun TextView.textWatcher(init: CustomTextWatcher.() -> Unit) = addTextChangedListener(CustomTextWatcher().apply(init)) | |
@Suppress("unused") | |
class CustomTextWatcher : TextWatcher { | |
private var _beforeTextChanged: ((CharSequence?, Int, Int, Int) -> Unit)? = null | |
private var _onTextChanged: ((CharSequence?, Int, Int, Int) -> Unit)? = null | |
private var _afterTextChanged: ((Editable?) -> Unit)? = null | |
private var _beforeTextChangedShout: (() -> Unit)? = null | |
private var _onTextChangedShout: (() -> Unit)? = null |
This file contains hidden or 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
class ClearableAutoCompleteTextView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, | |
defStyleAttr: Int = android.R.attr.editTextStyle) | |
: AutoCompleteTextView(context, attrs, defStyleAttr) { | |
private val clearDrawable: Drawable? = ContextCompat.getDrawable(context, R.drawable.ic_clear) | |
init { | |
clearDrawable?.setBounds(0, 0, clearDrawable.intrinsicWidth, clearDrawable.intrinsicHeight) | |
setOnTouchListener { _, event -> | |
if (isClearDrawableVisible() && event.action == MotionEvent.ACTION_UP) { |
This file contains hidden or 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
# change resolution | |
ffmpeg -i video_1920.mp4 -vf scale=300:534 video_300.mp4 | |
# convert | |
ffmpeg -i video_300.mp4 final.gif |
This file contains hidden or 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.graphics.Path; | |
import android.graphics.PathMeasure; | |
import android.os.Build; | |
import android.support.annotation.FloatRange; | |
import android.support.annotation.NonNull; | |
import android.support.annotation.Size; | |
import java.util.ArrayList; | |
import java.util.List; |