Skip to content

Instantly share code, notes, and snippets.

View ntngel1's full-sized avatar
🌻
Chilling

Kirill Shepelev ntngel1

🌻
Chilling
  • Kinoplan
  • Rostov-on-Don, Russia
View GitHub Profile
// Вот так пашет
private lateinit var cards: RealmResults<RealmCardEntity>
override fun subscribeForChanges(onChange: (card: CardEntity) -> Unit) {
val realm = Realm.getDefaultInstance()
cards = realm.where(RealmCardEntity::class.java)
.findAllAsync()
cards.addChangeListener { results ->
results.let { realm.copyFromRealm(it) }
.map { it.toDomain() }
val clas = KotlinClass(
name = "Kek",
modifiers = arrayListOf("open", "internal", "private"),
annotations = arrayListOf(
KotlinAnnotation(name = "WithoutArgs"),
KotlinAnnotation(name = "WithArgs", arguments = arrayListOf(
KotlinArgument(value = "someValue"), KotlinArgument(parameterName = "someName", value = "someValue")
))
),
classInheritance = KotlinClassInheritance(className = "SomeClass", arguments = arrayListOf(
interface FragmentTransactionHandler {
// withBackstack - логично, закинуть в стэк фрагментов, immediately - ждать пока фрагмент полностью не откроется
fun openFragment(fragment: Fragment, withBackstack: Boolean = false, immediately: Boolean = false)
}
interface MainView : MvpView, FragmentTransactionHandler {
@StateStrategyType(OneExecutionStateStrategy::class)
override fun openFragment(fragment: Fragment, withBackstack: Boolean = false, immediately: Boolean = false)
@InjectViewState
class MainPresenter : MvpPresenter<MainView>() {
private val uploadFragment = UploadFragment.newInstance().apply {
// Задаем callback на нажатие кнопки Show после загрузки фото
onShowPhoto = { photoModel ->
viewState.openScreen(newPhotosFragment)
currentFragment = newPhotosFragment
viewState.setNavigationSelection(R.id.navigation_new)
newPhotosFragment.presenter.onHighlightPhoto(photoModel)
}
abstract class UseCase <in P, out T> {
abstract fun execute(param: P): T
}
class FooUseCase : UseCase<Unit, Unit>() {
override fun execute(param: Unit) {
}
}
override fun getAntropometricData(): Single<AnthropometricModel> = Single.create { emitter ->
val weightDataType = DataType.TYPE_WEIGHT
val heightDataType = DataType.TYPE_HEIGHT
val weightSubscription = Fitness.getRecordingClient(context, account)
.subscribe(weightDataType)
Tasks.await(weightSubscription)
val heightSubscription = Fitness.getRecordingClient(context, account)
override fun getEcgListWithOffset(offset: Int): Single<DeviceEcgList> {
val request = ru.cardiomarker.p1.rpc.ecg.list.Request.newBuilder()
.addLeads(Lead.II)
.addLeads(Lead.CM5)
.apply {
if (offset != 0) {
setOffset(offset)
}
}
.build()
// Top-level build file where you can add configuration options common to all sub-projects/modules.
ext {
rxJava = '2.2.6'
rxAndroid = '2.1.1'
retrofit = '2.5.0'
retrofitRx = '2.5.0'
retrofitGson = '2.5.0'
loggingInterceptor = '3.12.1'
threeTenABP = '1.1.2'
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'com.google.gms.google-services'
@ntngel1
ntngel1 / task.kt
Last active February 27, 2019 13:27
// Задача состоит в том, чтобы получать через даггер одну и тот же фрагмент, но с презентером,
// у которого разные аргументы в конструкторе
@Module
class PhotosViewModule {
@Provides
@Named("PopularPhotos")
fun providePopularPhotosView(): PhotosView.View {
val fragment: Photos.View = PhotosFragment()
// Здесь бы должны как-то заинжектить вручную Presenter с определенными аргументами в конструкторе
fragment.inject(PhotosPresenter(popular = true, new = false))