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.app.Activity | |
import android.content.Intent | |
fun <T : Activity> Activity.startActivity( | |
activityClass: KClass<T>, | |
intentBlock: (Intent.() -> Unit)? = null | |
) { | |
val intent = Intent(this, activityClass.java) | |
intentBlock?.invoke(intent) | |
startActivity(intent) |
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.view.View | |
fun View?.setVisibleIf(boolean: Boolean, otherwise: Int = View.GONE) { | |
this?.visibility = if (boolean) View.VISIBLE else otherwise | |
} | |
fun View?.setVisibleIfNot(boolean: Boolean, otherwise: Int = View.GONE) = setVisibleIf(!boolean, otherwise) |
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.* | |
fun Date.isSameDay(other: Date, timeZone: TimeZone = TimeZone.getDefault()): Boolean { | |
val cal1 = Calendar.getInstance(timeZone).also { it.time = this } | |
val cal2 = Calendar.getInstance(timeZone).also { it.time = other } | |
return cal1.get(Calendar.DAY_OF_YEAR) == cal2.get(Calendar.DAY_OF_YEAR) && | |
cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR) | |
} |
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.os.Parcel | |
fun Parcel.writeBoolean(boolean: Boolean) = writeByte(if (boolean) 1 else 0) | |
fun Parcel.readBoolean() = readByte() != 0.toByte() |
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 androidx.lifecycle.* | |
fun <T> LiveData<T>.observe(lifecycleOwner: LifecycleOwner, callback: (T) -> Unit): Observer { | |
val observer = Observer(callback) | |
this.observe(lifecyleOwner, observer) | |
return observer | |
} |