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
//primera opción extener una funcin sobre [BaseObservable] que emita una [ObservableProperty] que emite el cambio y lo notifica | |
// a los databinders para repintar | |
inline fun <Param> BaseObservable.bindingParam(initialValue: Param, | |
crossinline afterChange: (Param) -> Unit): ReadWriteProperty<BaseObservable, Param> = | |
object : ObservableProperty<Param>(initialValue) { | |
override fun afterChange(property: KProperty<*>, oldValue: Param, newValue: Param) { | |
if (oldValue != newValue) { | |
[email protected]() |
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
//forma clásica extrapolada directamente de java | |
//funcion estatica donde el primer parámetro es la vista y los n siguientes los especificados por le BindingAdapter | |
@BindingAdapter("bind:url") | |
fun loadUrl(imageView: ImageView, url: String) { | |
Picasso.with(imageView.ctx).load(url).transform(CircleTransform()).into(imageView) | |
} | |
//opción alternativa | |
@BindingAdapter("bind:url") | |
fun ImageView.loadUrl(url: String) { |
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
fun alphaWithBounceAnimator(): ReadWriteProperty<ImageView, Int> = | |
object : ReadWriteProperty<ImageView, Int> { | |
override fun getValue(thisRef: ImageView, property: KProperty<*>): Int { | |
return thisRef.imageAlpha | |
} | |
override fun setValue(thisRef: ImageView, property: KProperty<*>, value: Int) { | |
val animX = ObjectAnimator.ofFloat(thisRef, "scaleX", 1f, 2.5f, 1f) |
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
fun backgroundColorAnimator(): ReadWriteProperty<View, Int> = | |
object : ReadWriteProperty<View, Int> { | |
override fun getValue(thisRef: View, property: KProperty<*>): Int { | |
return (thisRef.background as? ColorDrawable)?.color ?: 0 | |
} | |
override fun setValue(thisRef: View, property: KProperty<*>, value: Int) { | |
ValueAnimator.ofObject(ArgbEvaluator(), getValue(thisRef, property), value).apply { |
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
fun List<Number>.getNearestNeighbors(posibleNeighbors: List<List<Number>>, numberOfNeighbors: Int): List<List<Double>> { | |
return posibleNeighbors.mapIndexed { index, posibleNeighbor -> index to this.pearsonCorrelationWith(posibleNeighbor) } | |
.sortedBy { it.second } | |
.take(numberOfNeighbors) | |
.map { posibleNeighbors[it.first].map { it.toDouble() } } | |
} |
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
val day = today | |
val todayOnWeekInTheFuture = today + 1.week | |
//the power of infix | |
val isBefore = day isBefore todayOnWeekInTheFuture | |
day.formatedDateText("dd/MM/yyyy") | |
val oneJan2020at10Oclock = Dates.of(2020, 1, 1,10) |
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
class UsageFragment : Fragment() { | |
private val numberWhatever by Argument("ARG_PROPERTY", 0) | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
//same behaviour tham BundleParam but withArguments in fragments | |
print("$numberWhatever!") | |
} |
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
class CollectorExporter constructor(context: Context, | |
private val executor: AppExecutor, | |
private val sync: Sync = SyncClient(context)) { | |
fun export(analyticsFolder: File, metadataFolder: File, collectorNetworkAddress: String, executor: ListeningExecutorService = this.executor, uploadFolder: String): | |
ListenableFuture<Unit> { | |
return executor.submit(Callable { | |
sync.sync(analyticsFolder.absolutePath, collectorNetworkAddress, uploadFolder) |
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
@Test | |
@DisplayName("When Exporting only one file then rsync#sync should be called only once") | |
fun exportServerCallRsyncSync() { | |
collectorExporter.export(mockedFile, serverAddress, DirectExecutor, "").get() | |
verify(sync, times(1)).sync(absolutePathMock, serverAddress, "") | |
} |
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
override suspend fun execute(query: PostsQuery): Either<Failure, List<Post>> { | |
val operation = if (query.forceRefresh) MainSyncOperation else CacheSyncOperation | |
return either { | |
val posts = !repository.getAll(query = query, operation = operation) | |
posts | |
.filter { it.featuredImage != null } //we just want posts with featured images | |
.map { post -> | |
withContext(coroutineDispatcher) { | |
async { | |
val host: String? = try { |