Skip to content

Instantly share code, notes, and snippets.

View electrolobzik's full-sized avatar

Roman Chernyak electrolobzik

  • Russia, Saint Petersburg
View GitHub Profile
class ReceivedMediaRepository(
private val receivedMediaApiHelper: ReceivedMediaApiHelper,
private val receivedMediaDbHelper: ReceivedMediaDbHelper,
coroutineContext: CoroutineContext,
) : CoroutineScope by CoroutineScope(coroutineContext) {
private val coroutineScope = CoroutineScope(coroutineContext)
private val factory = ReceivedMediaStoreFactory(api = receivedMediaApiHelper, db = receivedMediaDbHelper)
private val mutableStore = factory.create()
/**
* Created by Roman Chernyak (aka @electrolobzik) on 2024-02-22
*/
class Paginator<Data : Any, Cursor : Any>(
coroutineContext: CoroutineContext
) : CoroutineScope by CoroutineScope(coroutineContext) {
private val _state = MutableStateFlow<State<Data, Cursor>>(State.NoData.Empty())
private val _sideEffects = MutableSharedFlow<SideEffect<Cursor>>()
private val inputActions = MutableSharedFlow<Action<Data, Cursor>>()
@electrolobzik
electrolobzik / ExampleSpekTest
Created September 20, 2018 08:33 — forked from Mugurell/ExampleSpekTest
Spek + JUnit5 config for Android project
import org.jetbrains.spek.api.Spek
import org.jetbrains.spek.api.dsl.given
import org.jetbrains.spek.api.dsl.it
import org.junit.Assert
class ExampleSpekTest : Spek({
val x = 2
val y = 3
@electrolobzik
electrolobzik / DisposablePropertyManager.kt
Created April 8, 2017 09:50
Provides delegates for implementing regular and lazy not nullable properties which should be disposed in some moment to free memory
/**
* Created with Android Studio
* User: electrolobzik [email protected]
* Date: 07/04/2017
* Time: 18:55
*
* Provides delegates for implementing regular and lazy not nullable properties which should be disposed in some moment to free memory
*/
class DisposablePropertyManager {
@electrolobzik
electrolobzik / RxBus.kt
Created March 28, 2017 10:16
Event bus implementation with RxJava and RxRelay (https://github.com/JakeWharton/RxRelay) with API similar to https://github.com/greenrobot/EventBus
/**
* Created with Android Studio
* User: electrolobzik [email protected]
* Date: 27/03/2017
* Time: 22:05
*
* Event bus implementation with RxJava and RxRelay (https://github.com/JakeWharton/RxRelay) with API similar to https://github.com/greenrobot/EventBus
*/
class RxBus<T> {
var stickyEvent: T? = null
/**
* Factory for creating a face tracker to be associated with a new face. The multiprocessor
* uses this factory to create face trackers as needed -- one for each individual.
*/
private class GraphicFaceTrackerFactory implements MultiProcessor.Factory<Face> {
@Override
public Tracker<Face> create(Face face) {
return FaceTracker.builder()
.withCameraType(CameraType.FrontCamera)
.withPreviewWidth(cameraSource.getPreviewSize().getHeight())
@electrolobzik
electrolobzik / WrapGridLayoutManager.java
Created November 26, 2015 14:24 — forked from ArthurSav/WrapGridLayoutManager.java
GridLayoutManager with working wrap_content.
package com.inperson.android.utils.leastview;
import android.content.Context;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
public class WrappableGridLayoutManager extends GridLayoutManager {
/*
* Copyright 2014 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
#!/bin/sh
# This script runs a configure script with the Android NDK toolchain
# You may need to adjust the COMPILE_TARGET and ANDROID_API variables
# depending on your requirements.
#
# Call this script in a directory with a valid configure script.
# Example: PREFIX=${PWD}/bin android-configure.sh
# Set the ANDROID_NDK variable to the root
// TypeToken is a Gson class
Type type = new TypeToken<List<Author>>(){}.getType();
GsonFieldConverterFactory factory = new GsonFieldConverterFactory(type);
// Register the factory and set the instance as the global Cupboard instance
CupboardFactory.setCupboard(new CupboardBuilder().registerFieldConverterFactory(factory).build());