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 AspectRatioCardView @JvmOverloads constructor( | |
context: Context, | |
attrs: AttributeSet? = null, | |
defStyleAttr: Int = 0 | |
) : CardView(context, attrs, defStyleAttr) { | |
private var ratio = 1.0f | |
init { | |
attrs?.let { |
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
enum class MultiState { | |
CONTENT, | |
EMPTY, | |
LOADING, | |
ERROR | |
} |
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
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
abstract class BaseActivity<MODEL : BaseModel<Bundle>, VIEW : BaseView, out PRESENTER : BasePresenter<MODEL, VIEW>> : KoinActivity() { | |
protected abstract val presenter: PRESENTER | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
val arguments = (javaClass.genericSuperclass as ParameterizedType).actualTypeArguments | |
val model = Class.forName(arguments.first().javaClass.toString().split(" ").last()).newInstance() | |
presenter.bind(model as MODEL, this as VIEW) | |
} |