Skip to content

Instantly share code, notes, and snippets.

View fededri's full-sized avatar

Federico Torres fededri

  • Autodesk
  • Argentina | Mexico
View GitHub Profile
@fededri
fededri / check_unused_queries.py
Last active March 20, 2024 21:20
check unused SQLDelight queries
import re
# Define the file paths
sql_file_path = ""
kotlin_file_path = ""
# Read the SQLDelight file
with open(sql_file_path, 'r') as file:
sql_file_content = file.read()
// Dagger
interface Authenticator
class RealAuthenticator @Inject constructor() : Authenticator
@Module
@ContributesTo(AppScope::class)
abstract class AuthenticatorModule {
@Binds abstract fun bindRealAuthenticator(authenticator: RealAuthenticator): Authenticator
}
struct MoviesListScreenView: View {
@State var state: MoviesState = MoviesState(movies: [], selectedMovie: nil)
let viewModel = MoviesViewModel()
var body: some View {
List() {
ForEach(state.movies, id: \.self) { movie in
MovieView(movie, ...)
}
}
class MoviesFragment : Fragment() {
private val viewModel: MoviesViewModel by activityViewModels {...}
override fun onCreateView(inflater: LayoutInflater): View = ComposeView(inflater.context).apply {
layoutParams = ...
setContent {
val state by viewModel.observeState().collectAsState()
MoviesListView(state = state, onMovieSelected = { movie ->
class FlowWrapper<T>(private val source: Flow<T>) : Flow<T> by source {
init {
freeze()
}
fun collect(onEach: (T) -> Unit, onCompletion: (cause: Throwable?) -> Unit): Cancellable {
val scope = CoroutineScope(SupervisorJob() + Dispatchers.Main)
scope.launch {
try {
class MoviesViewModel :
ArchViewModel<MoviesActions, MoviesState, MoviesEffects, MovieEvents, Nothing>(
updater = MoviesUpdater(),
initialState = MoviesState(),
initialEffects = setOf(MoviesEffects.LoadMovies()),
processor = MoviesProcessor(threadInfo),
) {
}
class MoviesProcessor() : Processor<MoviesEffects, MoviesActions> {
private val api : TMDApi = TMDApi()
override suspend fun dispatchSideEffect(effect: MoviesEffects): MoviesActions {
return when(effect){
is MoviesEffects.LoadMovies -> getMovies(effect)
}
}
typealias NextResult = Next<MoviesState, MoviesEffects, MovieEvents>
class MoviesUpdater : Updater<MoviesActions, MoviesState, MoviesEffects, MovieEvents> {
override fun onNewAction(
action: MoviesActions,
currentState: MoviesState
): Next<MoviesState, MoviesEffects, MovieEvents> {
return when (action) {
is MoviesActions.FetchMovies -> fetchMovies(action, currentState)
is MoviesActions.SaveMovies -> saveMovies(action, currentState)
@fededri
fededri / MoviesEffects.kt
Created January 25, 2022 02:49
KMM demo app SideEffects
sealed class MoviesEffects(
override val dispatcher: CoroutineDispatcher = ...,
override val coroutineScope: CoroutineScope? = null) : SideEffectInterface {
object LoadMovies : MoviesEffects()
}
@fededri
fededri / MoviesActions.kt
Last active January 25, 2022 02:42
KMM demo app actions
sealed class MoviesActions {
object FetchMovies : MoviesActions()
data class SelectMovie(val movie: Movie) : MoviesActions()
data class SaveMovies(val movies: List<Movie>) : MoviesActions()
}