Last active
January 15, 2022 03:26
-
-
Save gpeal/30fc252ab4143bd034cadeef00d8b1b5 to your computer and use it in GitHub Desktop.
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 com.sun.tools.javac.resources.CompilerProperties | |
import javax.swing.text.View | |
data class WorkoutDetailsState( | |
val workout: Async<Workout> = Uninitialized, | |
) : MavericksState { | |
} | |
class WorkoutDetailsViewModel @Inject constructor( | |
@Assisted initialState: WorkoutState, | |
args: WorkoutDetailsArgs, | |
workoutRepository: WorkoutRepository, | |
) : TonalViewModel<WorkoutDetailsState>(initialState) { | |
init { | |
workoutRepository.getWorkout(args.workoutId) | |
.onEach { setState { copy(workout = it) } } | |
.launchIn(viewModelScope) | |
} | |
} | |
class WorkoutDetailsFragment : TonalFragment(R.layout.workout_details_fragment) { | |
private val binding: WorkoutDetailsBinding by viewBinding() | |
private val viewModel: WorkoutDetailsViewModel by fragmentViewModel() | |
override fun invalidate() = withState(viewModel) { state -> | |
binding.title.text = state.workout()?.title | |
binding.progressBar.isVisible = state.workout() == null | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment