Skip to content

Instantly share code, notes, and snippets.

import timber.log.Timber
import kotlin.properties.ReadOnlyProperty
import kotlin.reflect.KProperty
class MyClass {
// This will automatically have the TAG "MyClass"
private val log by timber()
fun logSomething() {
log.i("Hello")
@iserbin
iserbin / fadeTo.kt
Created April 7, 2021 08:47 — forked from gpeal/fadeTo.kt
Fade To
/**
* Fade a view to visible or gone. This function is idempotent - it can be called over and over again with the same
* value without affecting an in-progress animation.
*/
fun View.fadeTo(visible: Boolean, duration: Long = 500, startDelay: Long = 0, toAlpha: Float = 1f) {
// Make this idempotent.
val tagKey = "fadeTo".hashCode()
if (visible == isVisible && animation == null && getTag(tagKey) == null) return
if (getTag(tagKey) == visible) return
@iserbin
iserbin / FragmentA.kt
Created April 7, 2021 08:46 — forked from gpeal/FragmentA.kt
View Binding Delegates
class WifiNetworksFragment : TonalFragment(R.layout.wifi_networks_fragment) {
// This automatically creates and clears the binding in a lifecycle-aware way.
private val binding: WifiNetworksFragmentBinding by viewBinding()
...
}
class WifiNetworkView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
@iserbin
iserbin / ChatRoomsFragment.kt
Created April 9, 2020 18:13 — forked from luciofm/ChatRoomsFragment.kt
How to run LiveData transformations on a coroutine
class ChatRoomsFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
viewModel = ViewModelProviders.of(this, factory).get(ChatRoomsViewModel::class.java)
subscribeUi()
}
private fun subscribeUi() {
@iserbin
iserbin / MainActivity.kt
Created October 30, 2019 11:06 — forked from NezSpencer/MainActivity.kt
Responsive naira amount textWatcher
package com.nezspencer.test
import android.os.Bundle
import android.support.annotation.NonNull
import android.support.v7.app.AppCompatActivity
import android.text.Editable
import android.text.TextUtils
import android.text.TextWatcher
import android.widget.EditText
import java.text.NumberFormat
@iserbin
iserbin / BaseDao.kt
Created September 26, 2019 11:58 — forked from florina-muntenescu/BaseDao.kt
Use Dao inheritance to reduce the amount of boilerplate code - https://medium.com/google-developers/7-pro-tips-for-room-fbadea4bfbd1
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@iserbin
iserbin / ConstraintLayoutLiveTemplates.csv
Created August 29, 2019 14:38 — forked from wajahatkarim3/ConstraintLayoutLiveTemplates.csv
A table for ConstraintLayout live templates
Abbrevation Description
center Centers any view in the parent horizontally and vertically
centerh Centers any view horizontally in the parent
centerv Centers any view vertically in the parent
vertical Centers any view vertically in any other view
horizontal Centers any view horizontally in any other view
fill Fills any view on all edges to parent
over Puts any view over an other view by setting same constrains as the original view. Works like fill but for any other view
above Puts any view above another view
below Puts any view below another view
@iserbin
iserbin / SomeFragment.java
Created April 12, 2019 14:41 — forked from atoennis/SomeFragment.java
Solution to having nested scrolling within Android. In this scenario a multiline EditText resides within a root level ScrollView. In order to have scroll momentum, the EditText itself doesn't scroll but it is wrapped within a ScrollView.
// When the EditText is touched, disable touches on it's ScrollView's parents.
// Once the user lifts up their finger, enable touches on on the ScrollView's parents once again.
@OnTouch(R.id.edit_text)
boolean handleNoteFieldTouch(View v, MotionEvent event) {
v.getParent().getParent().requestDisallowInterceptTouchEvent(true);
switch (event.getAction() & MotionEvent.ACTION_MASK){
case MotionEvent.ACTION_UP:
v.getParent().getParent().requestDisallowInterceptTouchEvent(false);
break;
@iserbin
iserbin / encode.sh
Created July 4, 2017 07:57 — forked from mikoim/README.md
YouTube recommended encoding settings on ffmpeg (+ libx264)
#/bin/sh
ffmpeg -i input -c:v libx264 -preset slow -profile:v high -crf 18 -coder 1 -pix_fmt yuv420p -movflags +faststart -g 30 -bf 2 -c:a aac -b:a 384k -profile:a aac_low output
class AccountHolder extends MvpViewHolder implements AccountView {
@InjectPresenter
AccountPresenter mAccountPresenter;
/**
@BindView(R.id.item_account_check_box)
CheckBox mCheckBox;
...
**/