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
/** | |
* Wraps an [onClick] lambda with another one that supports debouncing. The default deboucing time | |
* is 1000ms. | |
* | |
* @return debounced onClick | |
*/ | |
@Composable | |
inline fun debounced(crossinline onClick: () -> Unit, debounceTime: Long = 1000L): () -> Unit { | |
var lastTimeClicked by remember { mutableStateOf(0L) } | |
val onClickLambda: () -> Unit = { |
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
private var verticalScrollOffset = AtomicInteger(0) | |
recyclerView.addOnLayoutChangeListener { _, _, _, _, bottom, _, _, _, oldBottom -> | |
val y = oldBottom - bottom | |
if (y.absoluteValue > 0) { | |
recyclerView.post { | |
if (y > 0 || verticalScrollOffset.get().absoluteValue >= y.absoluteValue) { | |
recyclerView.scrollBy(0, y) | |
} else { | |
recyclerView.scrollBy(0, verticalScrollOffset.get()) |
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
Thread.setDefaultUncaughtExceptionHandler ({ t, e -> //… }) |
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
// Java | |
@FunctionaInterface | |
public interface UncaughtExceptionHandler { | |
void uncaughtException(Thread t, Throwable e); | |
} |
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 fail(message: String): Nothing { | |
val throwable = Throwable(message) | |
Thread.setDefaultUncaughtExceptionHandler { t, e -> System.err.println(e.message) } | |
throw throwable | |
} | |
// ... | |
val user: User = getUser() ?: fail("User not found!") | |
println("Hello, ${user.name}") |
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 fail(message: String): Nothing { | |
throw IllegalStateException(message) | |
} | |
// ... | |
val user: User = getUser() ?: fail("User not found!") | |
println("Hello, ${user.name}") |
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 fail(message: String) { | |
throw IllegalStateException(message) | |
} | |
// Is the same as: | |
fun fail(message: String): Unit { | |
throw IllegalStateException(message) | |
} |
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 fail(message: String) { | |
throw IllegalStateException(message) | |
} | |
…. | |
val user: User = getUser() ?: fail("User not found!") | |
println("Hello, ${user.name}") |
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
val user: User = getUser() ?: throw IllegalStateException("User not found!") | |
println("Hello, ${user.name}") |
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 getUser(): User? { | |
// ... | |
} | |
val user: User? = getUser() | |
if (user != null) { | |
println("Hello, ${user.name}") | |
} else { | |
throw IllegalStateException("User not found!") | |
} |
NewerOlder