Skip to content

Instantly share code, notes, and snippets.

View AlexGladkov's full-sized avatar
🦆
Quack Quack

Alex AlexGladkov

🦆
Quack Quack
View GitHub Profile
@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 / 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 / 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 / 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 / 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")
/// Module
@Module
class SharedModule {
@Provides
fun provideConfigurationRepository(context: Context): ConfigurationRepository =
ConfigurationRepository(
localDataSource = CommonConfigurationDataSource(context),
remoteDataSource = MockConfigurationDataSource()
)
/// 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")
/// ConfigurationModel
data class ConfigurationModel(
val currentQuestId: Int,
val currentQuestPage: Int,
val boughtQuestIds: List<Int>
)
/// Configuration Local Data Source
interface ConfigurationLocalDataSource {
fun storeConfiguration(configurationModel: ConfigurationModel)
@AlexGladkov
AlexGladkov / Coroutines + Rx.swift
Last active December 16, 2020 08:50
Coroutines + Rx (Multiplatform + iOS Native)
import LMCustomerSDK // Your Kotlin Multiplatform Library
import RxSwift
struct RxAsyncResult<ResultElement: AnyObject> {
#if targetEnvironment(simulator)
let async: AsyncResult<ResultElement>
#else
let async: AsyncResult
#endif
// TODO: - Рефакторинг - разбить на более мелкие функции
func mainFlowController() -> UIViewController {
// NavigationBar setting
AppAppearance.applyAppearanceNavigationbBarStyle()
AppAppearance.applyAppearanceBarButtonItem()
// creates a Home tab
let homeVC: HomeViewController = ControllerFactory.createViewController()
let homeNav = LMNavigationController(rootViewController: homeVC)
homeNav.tabBarItem.title = L10n.ATestHome.title