Skip to content

Instantly share code, notes, and snippets.

View johnkil's full-sized avatar

Evgenii Shishkin johnkil

View GitHub Profile
@ianhanniballake
ianhanniballake / PickImageContracts.kt
Last active September 10, 2022 18:03
Gist showing how to write backward compatible ActivityResultContracts for supporting Android 13's new Photo Picker: https://developer.android.com/about/versions/13/features/photopicker
/**
* Use this [ActivityResultContract] to seamlessly switch between
* the new [MediaStore.ACTION_PICK_IMAGES] and [Intent.ACTION_GET_CONTENT]
* based on the availability of the Photo Picker.
*
* Use [PickMultipleImages] if you'd like the user to be able to select multiple
* photos/videos.
*
* Input: the mimeType you'd like to receive. This should generally be
* either `image/\*` or `video/\*` for requesting only images or only videos
@be1ski
be1ski / Activity.kt
Last active December 13, 2021 19:51
/** Пример использования */
class MainActivity : AppCompatActivity(R.layout.activity_main) {
@Inject lateinit var fragmentFactory: FragmentFactory
private val component by nonConfigurationInstance {
DaggerActivityComponent.factory().create()
}
override fun onCreate(savedInstanceState: Bundle?) {
component.inject(this)
@osipxd
osipxd / setLocale.kt
Last active April 15, 2024 12:15
Set locale in Android application
import android.app.Activity
import android.app.Application
import android.content.ComponentCallbacks
import android.content.Context
import android.content.res.Configuration
import android.os.Build
import android.os.Bundle
import java.util.Locale
private const val LANGUAGE_RU = "ru"
@utkukutlu
utkukutlu / AndroidNavigationComponentDialogFragment
Last active November 11, 2023 13:51
android navigation component add fragment instead of replace
Android Navigation Component Dialog Fragment
/*
* Copyright 2019 Sergey Chelombitko
*
* 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
import android.app.Activity
import androidx.fragment.app.Fragment
import android.app.Application
import android.app.Service
import android.view.View
import android.view.ViewParent
import com.bluelinelabs.conductor.Controller
import dagger.MapKey
import dagger.Module
import dagger.multibindings.Multibinds
@naturalwarren
naturalwarren / CoinbaseRxJava2CallAdapterFactory.kt
Last active March 16, 2022 04:58
A Kotlin-esque API for Retrofit.
/**
* Copyright 2019 Coinbase, 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,
@Tagakov
Tagakov / RxKeyboardManager.kt
Created October 30, 2018 13:37
Allows to hide and show keyboard with notification after successful hiding or showing
@Reusable
class RxKeyboardManager(private val activity: Activity, private val mainThread: Scheduler, private val imm: InputMethodManager) {
val keyboardStates = Observable.create<Boolean>({
val globalLayoutListener = ViewTreeObserver.OnGlobalLayoutListener { it.onNext(isKeyboardShown()) }
it.setCancellation { activity.window.decorView.viewTreeObserver.removeOnGlobalLayoutListener(globalLayoutListener) }
activity.window.decorView.viewTreeObserver.addOnGlobalLayoutListener(globalLayoutListener)
}, Emitter.BackpressureMode.LATEST)
.distinctUntilChanged()
.subscribeOn(mainThread)
.share()
@florina-muntenescu
florina-muntenescu / BaseDao.kt
Last active September 28, 2023 15:01
Use Dao inheritance to reduce the amount of boilerplate code - https://medium.com/google-developers/7-pro-tips-for-room-fbadea4bfbd1
/*
* Copyright (C) 2017 The Android Open Source Project
*
* 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
@piruin
piruin / DrawableCompat.kt
Last active May 3, 2023 13:09
Kotlin Extension for set/get compound Drawable to TextView/EditText/Button as property
/*
* Copyright 2017 Piruin Panichphol
*
* 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