Skip to content

Instantly share code, notes, and snippets.

View cbedoy's full-sized avatar

Bedoy cbedoy

View GitHub Profile
@cbedoy
cbedoy / gist:a33c8fc77326b170bb5e32be9122025a
Created January 24, 2023 19:59
Crea un codigo para generar un bom para usarlo en android
import org.gradle.api.Project
// Create the BOM file
val bomFile = project.file("dependencies.bom")
// Get all dependencies of the project
val dependencies = project.configurations.getByName("implementation").allDependencies
// Write the dependencies to the BOM file
bomFile.writeText(dependencies.joinToString("\n"))
@cbedoy
cbedoy / DimenAndFontGenerator.kt
Last active May 24, 2022 20:52
Dimens and Font size generator
/**
* Made by cbedoy
*/
val dimenRatio = mapOf(
"mdp" to .8F, "hdp" to .9f, "xhdp" to 1f, "xxhdp" to 1.1f, "xxxhdp" to 1.2f
)
fun generate(n: Int) {
dimenRatio.map {
@cbedoy
cbedoy / Example.kt
Created September 14, 2021 14:34
Fancy use Case and viewModel
class FancyUseCase (private val serviceOrAnyDataLayer: Something){
operator fun invoke(number: String) = flow {
when(val response = serviceOrAnyDataLayer.requestAny()) {
is Success -> {
emit("Yeah")
}
else -> {
emit("Damit")
}
}
open class BaseDialog : DialogFragment() {
override fun onCreate(savedInstanceState: Bundle?) {
setStyle(STYLE_NO_TITLE, R.style.DialogTheme)
super.onCreate(savedInstanceState)
}
override fun onStart() {
super.onStart()
dialog?.window?.setWindowAnimations(R.style.DialogAnimation)
@cbedoy
cbedoy / commands.sh
Created May 24, 2021 18:06
Some commands
// KTlint report
scripts/gatekeeper/ktlint -v "**/src/**/*.kt" -a --relative --reporter=plain --reporter=checkstyle
// Ktlint fix format
scripts/gatekeeper/ktlint -F
// Git rebase
git rebase -i HEAD~N
// Changelog
@cbedoy
cbedoy / MessageRepresentation.kt
Created May 20, 2021 22:44
MessageRepresentationDialog
@Parcelize
data class MessageRepresentation(
val title : String = "",
val description: String = "",
val boldDescriptionComponents: List<String> = emptyList(),
val backgroundResource: Int = 0,
val imageResource: Int = 0,
val progressBar: MessageRepresentationProgress = MessageRepresentationProgress(),
.....
) : Parcelable
@cbedoy
cbedoy / NewServiceViewModel2.kt
Last active March 24, 2021 22:50
ViewModel + MVI + Flow
class NewServiceViewModel2 (
private val useCase: NewServiceUseCase) : BaseMVIViewModel<NewServiceState, NewServiceIntent>(
initialState = NewServiceState.IldeState
) {
override val TAG: String
get() = "NewServiceViewModel"
override suspend fun onCollect(intent: NewServiceIntent, producer: suspend (Flow<NewServiceState>) -> Unit) {
when(intent){
is NewServiceIntent.LoadProducts -> {
typealias Producer<T> = suspend (Flow<T>) -> Unit
abstract class BaseMVIViewModel<State, Intent>(
initialState: State
) : ViewModel(){
private val intentChannel = Channel<Intent>(Channel.UNLIMITED)
private var _state = MutableStateFlow(initialState)
open val state: StateFlow<State>
get() = _state
class NewServiceUseCase(
private val repository: NewServiceRepository
){
val loadProducts = flow {
emit(ShowLoader)
when(val response = repository.loadProducts){
is Success -> {
emit(ReloadProducts(response.preparedProducts))
}
else -> {
class NewServiceViewModel(
private val useCase: NewServiceUseCase
): ViewModel {
private val _state: MutableStateFLow<NewServiceState>(NewServiceState.IldeState)
val state: StateFlow<NewServiceState> get() = _cart
suspend fun handleIntents(intent: NewServiceIntent){
when(intent){
is LoadProductsIntent -> {