Skip to content

Instantly share code, notes, and snippets.

View Skyyo's full-sized avatar
🇺🇦

Denis Rudenko Skyyo

🇺🇦
View GitHub Profile
@Composable
fun VideoCard(
videoItem: VideoItem,
isPlaying: Boolean,
exoPlayer: ExoPlayer,
onClick: OnClick
) {
var isPlayerUiVisible by remember { mutableStateOf(false) }
val isPlayButtonVisible = if (isPlayerUiVisible) true else !isPlaying
@HiltViewModel
class VideosViewModel @Inject constructor() : ViewModel() {
val videos = MutableStateFlow<List<VideoItem>>(listOf())
val currentlyPlayingIndex = MutableStateFlow<Int?>(null)
init {
populateVideosWithTestData()
}
@Composable
fun VideosScreen(viewModel: VideosViewModel = hiltViewModel()) {
val context = LocalContext.current
val exoPlayer = remember(context) { ExoPlayer.Builder(context).build() }
val videos by viewModel.videos.collectAsStateWithLifecycle()
val playingItemIndex by viewModel.currentlyPlayingIndex.collectAsStateWithLifecycle()
LazyColumn {
itemsIndexed(items = videos, key = { _, video -> video.id }) { index, video ->
VideoCard(
@Skyyo
Skyyo / retrofitTag.kt
Created September 29, 2021 13:37
get request tag from request #network #retrofit #authenticator #401
authenticate {
if (response.request.tag(Invocation::class.java)?.arguments()?.contains(AUTH_TAG) == true) {
return null
}
//after this we can catch 401 on the request call site
private class InputErrors(
val nameErrorId: Int?,
val cardErrorId: Int?
)
@HiltViewModel
class FormValidationViewModel @Inject constructor(..) : ViewModel() {
fun onNameEntered(input: String) {
handle[NAME] = name.value.copy(value = input, errorId = null)
@Composable
fun CustomTextField(
modifier: Modifier,
inputWrapper: InputWrapper,
onValueChange: OnValueChange
) {
val fieldValue = remember {
mutableStateOf(TextFieldValue(inputWrapper.value, TextRange(inputWrapper.value.length)))
}
Column {
@Composable
fun InputValidationScreen(..) {
val focusManager = LocalFocusManager.current
val keyboardController = LocalSoftwareKeyboardController.current
val creditCardNumberFocusRequester = remember { FocusRequester() }
val nameFocusRequester = remember { FocusRequester() }
LaunchedEffect(Unit) {
events.collect { event ->
enum class FocusedTextFieldKey {
NAME, CREDIT_CARD_NUMBER, NONE
}
@HiltViewModel
class InputValidationViewModel @Inject constructor(..) : ViewModel() {
private var focusedTextField = handle.get("focusedTextField") ?: FocusedTextFieldKey.NAME
set(value) {
field = value
@Composable
fun CustomTextField(
inputWrapper: InputWrapper,
onValueChange: OnValueChange,
onImeKeyAction: OnImeKeyAction
) {
Column {
TextField(
value = inputWrapper.value,
onValueChange = { onValueChange(it) },
sealed class ScreenEvent {
class ShowToast(val messageId: Int) : ScreenEvent()
class UpdateKeyboard(val show: Boolean) : ScreenEvent()
class MoveFocus(val direction: FocusDirection = FocusDirection.Down) : ScreenEvent()
class RequestFocus(val textFieldKey: FocusedTextFieldKey) : ScreenEvent()
object ClearFocus : ScreenEvent()
}