Instead of the verbose setOnClickListener
:
RxView.clicks(submitButton).subscribe(o -> log("submit button clicked!"));
Observable
.just(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
import android.support.v7.widget.RecyclerView | |
import android.view.View | |
interface OnItemClickListener { | |
fun onItemClicked(position: Int, view: View) | |
} | |
fun RecyclerView.addOnItemClickListener(onClickListener: OnItemClickListener) { | |
this.addOnChildAttachStateChangeListener(object: RecyclerView.OnChildAttachStateChangeListener { | |
override fun onChildViewDetachedFromWindow(view: View?) { |
This is an old way to Upload an Image from camera or gallery in WebView. It was made a long time ago and is not maintened anymore. Use it at your own risk.
// IMPORTANT! READ THIS FIRST | |
// Assisted Injection doesn't work with @HiltViewModel or @ViewModelInject | |
// Read more about the issue here: https://github.com/google/dagger/issues/2287 | |
// | |
// | |
// AssistedInject and Hilt working together in v2.28-alpha times | |
// Example of a ViewModel using AssistedInject injected in a Fragment by Hilt | |
// As AssistedInject isn't part of Dagger yet, we cannot use in | |
// conjuction with @ViewModelInject |
// Take photo from camera and save it to public gallery | |
// Before Q and After Q implementations | |
// Answer riginally taken from this SO answer | |
// https://stackoverflow.com/a/59482148/5695091 | |
private val REQUEST_TAKE_PHOTO = 101 | |
private val REQUEST_PICK_PHOTO = 102 | |
private var photoURI : Uri? = null | |
package com.exmaple | |
import android.graphics.* | |
import com.github.mikephil.charting.animation.ChartAnimator | |
import com.github.mikephil.charting.interfaces.dataprovider.BarDataProvider | |
import com.github.mikephil.charting.interfaces.datasets.IBarDataSet | |
import com.github.mikephil.charting.renderer.BarChartRenderer | |
import com.github.mikephil.charting.utils.Utils | |
import com.github.mikephil.charting.utils.ViewPortHandler |
class LifecycleGroup(val lifecycleOwner: LifecycleOwner) { | |
/** | |
* Recommended for the majority of use cases | |
* The crucial difference from [collect] is that when the original flow emits a new value, [block] for previous | |
* value is cancelled. | |
**/ | |
inline fun <T> Flow<T>.collectLatestWhenStarted(crossinline block: suspend (T) -> Unit): Job { | |
return lifecycleOwner.lifecycleScope.launchWhenStarted { | |
[email protected] { | |
block(it) |
fun View.focusAndShowKeyboard(tryAgain: Boolean = true) { | |
/** | |
* This is to be called when the window already has focus. | |
*/ | |
fun View.showTheKeyboardNow() { | |
if (isFocused) { | |
post { | |
// We still post the call, just in case we are being notified of the windows focus | |
// but InputMethodManager didn't get properly setup yet. | |
val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager |
@Composable | |
fun TweetList(state: TweetListState) { | |
val context = LocalContext.current | |
val listState = rememberLazyListState() | |
val exoPlayer = remember { | |
SimpleExoPlayer.Builder(context).build().apply { | |
repeatMode = Player.REPEAT_MODE_ALL | |
} | |
} |