Skip to content

Instantly share code, notes, and snippets.

View aartikov's full-sized avatar

Artur Artikov aartikov

View GitHub Profile
@aartikov
aartikov / BaseActivity.kt
Created February 13, 2018 06:46
Dagger 2 + Reamp
package ru.eastbanctech.daggertest.base
import android.os.Bundle
import android.support.v4.app.Fragment
import dagger.android.AndroidInjection
import dagger.android.AndroidInjector
import dagger.android.DispatchingAndroidInjector
import dagger.android.support.HasSupportFragmentInjector
import etr.android.reamp.mvp.ReampAppCompatActivity
import etr.android.reamp.mvp.ReampPresenter
@aartikov
aartikov / ContextResourceProvider.kt
Created February 13, 2018 07:27
Resource provider
package ru.eastbanctech.demo.data.providers.resource
import android.content.Context
class ContextResourceProvider(private var context: Context) : ResourceProvider {
override fun getString(resId: Int): String =
context.resources.getString(resId)
override fun getString(resId: Int, vararg args: Any): String =
context.resources.getString(resId, *args)
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import android.text.InputFilter;
import android.text.Spanned;
public class RegexInputFilter implements InputFilter {
private Pattern mPattern;
@aartikov
aartikov / ExoPlayer.kt
Created October 1, 2018 05:16
ExoPlayer
private lateinit var player: ExoPlayer
private lateinit var mediaSourceFactory: ExtractorMediaSource.Factory
private fun initPlayer() {
val bandwidthMeter = DefaultBandwidthMeter()
val videoTrackSelectionFactory = AdaptiveTrackSelection.Factory(bandwidthMeter)
val trackSelector = DefaultTrackSelector(videoTrackSelectionFactory)
val dataSourceFactory = DefaultDataSourceFactory(context, Util.getUserAgent(context, "A"))
mediaSourceFactory = ExtractorMediaSource.Factory(dataSourceFactory).setExtractorsFactory(DefaultExtractorsFactory())
player = ExoPlayerFactory.newSimpleInstance(this, trackSelector)
@aartikov
aartikov / CounterActivity.kt
Created October 17, 2019 03:51
MobX Sample
package com.example.mobxtest
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import kotlinx.android.synthetic.main.activity_counter.*
import magneton.observable.ReactionDisposer
import magneton.observable.computed
import magneton.observable.observable
import magneton.observable.reaction
@aartikov
aartikov / PactSample.kt
Created November 14, 2019 05:40
Pact Sample
package me.aartikov.packtest
import au.com.dius.pact.consumer.ConsumerPactTestMk2
import au.com.dius.pact.consumer.MockServer
import au.com.dius.pact.consumer.dsl.PactDslJsonBody
import au.com.dius.pact.consumer.dsl.PactDslWithProvider
import au.com.dius.pact.model.RequestResponsePact
import com.google.gson.Gson
import okhttp3.OkHttpClient
import okhttp3.Request
package me.aartikov.storesample
import com.dropbox.android.external.store4.*
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.toList
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import org.junit.Assert.assertEquals
@aartikov
aartikov / navigation.kt
Last active September 25, 2020 15:25
navigation
private fun bindNavigationContext() {
val builder = NavigationContext.Builder(this, navigationFactory)
val currentFlowFragment = getCurrentFlowFragment()
if (currentFlowFragment is ContainerIdProvider) {
builder.fragmentNavigation(
currentFlowFragment.childFragmentManager,
(currentFlowFragment as ContainerIdProvider).containerId
)
@aartikov
aartikov / DelegateAccess.kt
Created January 14, 2021 11:03
Wrap MutableStateFlow to property delegate
internal object DelegateAccess {
internal val delegate = ThreadLocal<Any?>()
internal val delegateRequested = ThreadLocal<Boolean>().apply { set(false) }
}
internal val <T> KProperty0<T>.delegate: Any?
get() {
try {
DelegateAccess.delegateRequested.set(true)
this.get()
@aartikov
aartikov / DownloadNotificationManager.kt
Created January 25, 2021 09:38
DownloadNotificationManager
abstract class DownloadNotificationManager(context: Context) : DefaultFetchNotificationManager(context) {
// Copied from DefaultFetchNotificationManager to hide Pause button
override fun updateNotification(notificationBuilder: NotificationCompat.Builder,
downloadNotification: DownloadNotification,
context: Context) {
val smallIcon = if (downloadNotification.isDownloading) {
android.R.drawable.stat_sys_download
} else {
android.R.drawable.stat_sys_download_done