Skip to content

Instantly share code, notes, and snippets.

View AlexGladkov's full-sized avatar
🦆
Quack Quack

Alex AlexGladkov

🦆
Quack Quack
View GitHub Profile
/// Pack For XCode
val packForXcode by tasks.creating(Sync::class) {
group = "build"
val mode = System.getenv("CONFIGURATION") ?: "DEBUG"
val sdkName = System.getenv("SDK_NAME") ?: "iphonesimulator"
val targetName = "ios" + if (sdkName.startsWith("iphoneos")) "Arm64" else "X64"
val framework = kotlin.targets.getByName<KotlinNativeTarget>(targetName).binaries.getFramework(mode)
inputs.property("mode", mode)
dependsOn(framework.linkTask)
val targetDir = File(buildDir, "xcode-frameworks")
/// Module
@Module
class SharedModule {
@Provides
fun provideConfigurationRepository(context: Context): ConfigurationRepository =
ConfigurationRepository(
localDataSource = CommonConfigurationDataSource(context),
remoteDataSource = MockConfigurationDataSource()
)
@AlexGladkov
AlexGladkov / BaseFlowViewModel.kt
Last active February 15, 2024 23:17
BaseViewModel (Migrating LiveData to Flow)
@ExperimentalCoroutinesApi
abstract class BaseFlowViewModel<S, A, E>: ViewModel() {
private val TAG = BaseFlowViewModel::class.java.simpleName
private val _viewStates: MutableStateFlow<S?> = MutableStateFlow(null)
fun viewStates(): StateFlow<S?> = _viewStates
protected var viewState: S
get() = _viewStates.value
?: throw UninitializedPropertyAccessException("\"viewState\" was queried before being initialized")
@AlexGladkov
AlexGladkov / cycle.kt
Created February 20, 2021 13:42
Cycle
// fields
private var needsToBreakCycle = false
for (i in 0..<100) {
if (needsToBreakCycle) continue
// do work
}
Handler().postDelayed({
needsToBreakCycle = true
@AlexGladkov
AlexGladkov / Repo.kt
Created February 24, 2021 11:39
Repositories
class CatalogVersionRepositoryImpl @Inject constructor(
private val catalogVersionRemoteDataSource: CatalogVersionRemoteDataSource,
private val catalogVersionLocalDataSource: CatalogVersionLocalDataSource
) : CatalogVersionRepository {
override fun checkNeedUpdate(): Single<Boolean> {
return catalogVersionRemoteDataSource.getCurrentCatalogVersion()
.map { remoteCatalogueVersion ->
val localCatalogueVersion = catalogVersionLocalDataSource.getCurrentCatalogVersion()
val hasActualVersion = localCatalogueVersion == remoteCatalogueVersion
@AlexGladkov
AlexGladkov / GitResponse.kt
Created February 26, 2021 13:57
Gist parse
data class GistResponse(
val url: String,
...,
val files: FilesRemote
)
data class FilesRemote(
val filename: FilesFilename
)
@AlexGladkov
AlexGladkov / ProductScreen.kt
Last active August 28, 2024 18:21
ProductDetails + Jetpack Compose
package ru.leroymerlin.library_sdk.screens.product_details
import android.media.Rating
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.*
import androidx.compose.runtime.Composable
@AlexGladkov
AlexGladkov / build.gradle.kts
Created May 15, 2021 12:34
Android KMP gradle.kts
plugins {
id("com.android.application")
kotlin("android")
kotlin("kapt")
id("org.jetbrains.compose")
}
android {
compileSdkVersion(30)
buildToolsVersion("30.0.2")
@AlexGladkov
AlexGladkov / TagHost.kt
Last active November 15, 2022 04:05
Jetpack Compose Layout To Tag Cloud
@Composable
fun TagHost(
modifier: Modifier = Modifier,
verticalPadding: Dp = 24.dp,
content: @Composable () -> Unit
) {
Layout(
modifier = modifier,
content = content
) { measurables, constraints ->
@AlexGladkov
AlexGladkov / Example.swift
Created July 26, 2021 08:22
SwiftUI + Kotlin Flow
struct ExampleView: View {
let viewModel: AuthViewModel = AuthViewModel()
var body: some View {
ObservingView(statePublisher: asPublisher(viewModel.viewStates()),
actionPublisher: asPublisher(viewModel.viewActions()),
content: { state, action in
// your view here
})