This file contains 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
@Composable | |
fun VideoCard( | |
videoItem: VideoItem, | |
isPlaying: Boolean, | |
exoPlayer: ExoPlayer, | |
onClick: OnClick | |
) { | |
var isPlayerUiVisible by remember { mutableStateOf(false) } | |
val isPlayButtonVisible = if (isPlayerUiVisible) true else !isPlaying |
This file contains 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
@HiltViewModel | |
class VideosViewModel @Inject constructor() : ViewModel() { | |
val videos = MutableStateFlow<List<VideoItem>>(listOf()) | |
val currentlyPlayingIndex = MutableStateFlow<Int?>(null) | |
init { | |
populateVideosWithTestData() | |
} | |
This file contains 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
@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( |
This file contains 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
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 |
This file contains 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 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) |
This file contains 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
@Composable | |
fun CustomTextField( | |
modifier: Modifier, | |
inputWrapper: InputWrapper, | |
onValueChange: OnValueChange | |
) { | |
val fieldValue = remember { | |
mutableStateOf(TextFieldValue(inputWrapper.value, TextRange(inputWrapper.value.length))) | |
} | |
Column { |
This file contains 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
@Composable | |
fun InputValidationScreen(..) { | |
val focusManager = LocalFocusManager.current | |
val keyboardController = LocalSoftwareKeyboardController.current | |
val creditCardNumberFocusRequester = remember { FocusRequester() } | |
val nameFocusRequester = remember { FocusRequester() } | |
LaunchedEffect(Unit) { | |
events.collect { event -> |
This file contains 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
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 |
This file contains 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
@Composable | |
fun CustomTextField( | |
inputWrapper: InputWrapper, | |
onValueChange: OnValueChange, | |
onImeKeyAction: OnImeKeyAction | |
) { | |
Column { | |
TextField( | |
value = inputWrapper.value, | |
onValueChange = { onValueChange(it) }, |
This file contains 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
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() | |
} |