Skip to content

Instantly share code, notes, and snippets.

Vasili Chyrvon Jeevuz

Block or report user

Report or block Jeevuz

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View NullableBooleansTest
class NullableBooleansTest {
enum class Result { OK, NOT }
private fun testNullableBooleanWhen(
nullableBoolean: Boolean?,
check: (Boolean?) -> Boolean,
resulting: Result
) {
val result = if (check(nullableBoolean)) {
@Jeevuz
Jeevuz / SchedulersRule
Created Aug 27, 2018
Test Rule to test the classes with rx shedulers
View SchedulersRule
class SchedulersRule : ExternalResource() {
lateinit var testScheduler: TestScheduler
override fun before() {
RxJavaPlugins.setIoSchedulerHandler { _ -> Schedulers.trampoline() }
RxAndroidPlugins.setInitMainThreadSchedulerHandler { _ -> Schedulers.trampoline() }
testScheduler = TestScheduler()
RxJavaPlugins.setComputationSchedulerHandler { _ -> testScheduler }
@Jeevuz
Jeevuz / KoinExtensions.kt
Last active Jun 25, 2018
Helpers for Koin (0.9.3)
View KoinExtensions.kt
package ru.mobileup.midhub.extension
import org.koin.android.ext.koin.androidApplication
import org.koin.core.bean.BeanDefinition
import org.koin.core.bean.Definition
import org.koin.dsl.context.Context
import org.koin.dsl.module.Module
import org.koin.dsl.module.applicationContext
/**
@Jeevuz
Jeevuz / EnterStringDialogFragment.kt
Last active Dec 1, 2017
Universal DialogFragments
View EnterStringDialogFragment.kt
package ru.mobileup.businessnavigator.ui.base.dialog
import android.app.Dialog
import android.content.Context
import android.os.Bundle
import android.support.annotation.LayoutRes
import android.support.annotation.StringRes
import android.support.v7.app.AlertDialog
import android.support.v7.app.AppCompatDialogFragment
import android.text.Editable
@Jeevuz
Jeevuz / Extensions.kt
Last active Nov 26, 2019
Here I collect some of my most useful Kotlin extensions
View Extensions.kt
inline fun SharedPreferences.edit(changes: SharedPreferences.Editor.() -> SharedPreferences.Editor) {
edit().changes().apply()
}
fun ImageView.tintSrc(@ColorRes colorRes: Int) {
val drawable = DrawableCompat.wrap(drawable)
DrawableCompat.setTint(drawable, ContextCompat.getColor(context, colorRes))
setImageDrawable(drawable)
if (drawable is TintAwareDrawable) invalidate() // Because in this case setImageDrawable will not call invalidate()
}
@Jeevuz
Jeevuz / SpinnerWithHintAdapter.java
Created Jun 20, 2017
Adapter for spinner with hint
View SpinnerWithHintAdapter.java
/**
* @author Vasili Chyrvon (vasili.chyrvon@gmail.com)
*/
class SpinnerWithHintAdapter(context: Context, @LayoutRes resource: Int, @StringRes hintResId: Int) : ArrayAdapter<String>(context, resource) {
private val hintColor by lazy { getHintColorAttribute() }
private var textColors: ColorStateList? = null
private val hint by lazy { context.getString(hintResId) }
override fun isEnabled(position: Int): Boolean {
@Jeevuz
Jeevuz / ProgressDimDialogFragment.kt
Created Mar 30, 2017
Progress DialogFragment with only progress view on the dimmed screen
View ProgressDimDialogFragment.kt
/**
* Dialog fragment showing progress widget on dimmed screen.
* @author Vasili Chyrvon (vasili.chyrvon@gmail.com)
*/
class ProgressDimDialogFragment : AppCompatDialogFragment() {
companion object {
val TAG = "ProgressDimDialogFragment"
private val ARGS_DISPATCH_BACK_PRESS = "args_dispatches_back_press"
@Jeevuz
Jeevuz / RxPM vs MVP
Last active Apr 5, 2017
Real project's part converted from MVP (with Moxy) into RxPM (with Outlast). See revisions diff.
View RxPM vs MVP
This is real project screen with complex UI that was switched
from using the MVP with Moxy library
to the use of RxPM pattern (Reactive Presentation Model) with Outlast library (persistent PM layer).
I was doing it to see pros and cons of the RxPM pattern.
Pros:
- easy integration with RxBindings for complex UI.
- nice saved states in PM (for PM and MVVM lovers).
- easy combining of reactive streams coming from network, db, etc. in PM.
@Jeevuz
Jeevuz / EnterStringDialogFragment.java
Last active Jan 18, 2017
Dialog to ask for string to enter
View EnterStringDialogFragment.java
package ru.mobileup.myalarm2.ui.dialog;
import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.StringRes;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatDialogFragment;
import android.widget.EditText;
@Jeevuz
Jeevuz / isDeviceLocked.java
Created Sep 20, 2016
Check device is currently locked
View isDeviceLocked.java
/**
* Returns true if the device is locked or screen turned off (in case password not set)
*/
public static boolean isDeviceLocked(Context context) {
boolean isLocked = false;
// First we check the locked state
KeyguardManager keyguardManager = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
boolean inKeyguardRestrictedInputMode = keyguardManager.inKeyguardRestrictedInputMode();
You can’t perform that action at this time.