Skip to content

Instantly share code, notes, and snippets.

View mvasilova's full-sized avatar

Marina mvasilova

View GitHub Profile
@mvasilova
mvasilova / RetryWithDelay.kt
Last active December 9, 2019 08:27
Retry Flowable method on Error (RxJava 2) - Android (Kotlin)
//Class
import io.reactivex.Flowable
import io.reactivex.functions.Function
import java.util.concurrent.TimeUnit
class RetryWithDelay(private val maxRetries: Int, private val retryDelayMillis: Int, private val retryIf: Function<Throwable, Boolean>, private val unit: TimeUnit = TimeUnit.MILLISECONDS) : Function<Flowable<out Throwable>, Flowable<*>> {
private var retryCount: Int = 0
override fun apply(attempts: Flowable<out Throwable>): Flowable<*> {
return attempts.doOnNext { println("RetryWithDelay $it") }.flatMap { throwable ->
@mvasilova
mvasilova / NetworkHadnler.kt
Created December 9, 2019 08:22
Check InternetConnection - Android (Kotlin)
class NetworkHandler(private val context: Context) {
val isConnected get() = checkInternet()
private fun checkInternet(): Boolean {
val connectivityManager = context.getSystemService(Context.CONNECTIVITY_SERVICE) as? ConnectivityManager
var result = false
if (connectivityManager != null) {
result = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
connectivityManager.activeNetwork != null
} else {
@mvasilova
mvasilova / DividerItemDecoration.kt
Created December 9, 2019 08:18
Divider for item's RecyclerView
import android.graphics.Canvas
import android.graphics.Paint
import android.graphics.Rect
import android.view.View
import androidx.core.graphics.withTranslation
import androidx.core.view.children
import androidx.recyclerview.widget.RecyclerView
class DividerItemDecoration(
private val strokeColor: Int,
@mvasilova
mvasilova / InputFilterMinMax.kt
Created December 9, 2019 08:15
InputFilter min, max for EditText
import android.text.InputFilter
import android.text.Spanned
class InputFilterMinMax : InputFilter {
private var min: Int = 0
private var max: Int = 0
constructor(min: Int, max: Int) {
this.min = min
@mvasilova
mvasilova / Fragment.kt
Created December 9, 2019 08:05
Definition of geolocation - latitude, longitude (with GPS, ipAddress, RxPermissions) - Android (Kotlin)
//Definition of geolocation - latitude, longitude in Fragment
private lateinit var fusedLocationClient: FusedLocationProviderClient
private lateinit var locationRequest: LocationRequest
private lateinit var locationCallback: LocationCallback
private lateinit var rxPermissions: RxPermissions
private var latitude: Double? = 0.0
private var longitude: Double? = 0.0
@mvasilova
mvasilova / README.kt
Created December 9, 2019 07:37
Force update App Android (Kotlin, FirebaseRemoteConfig)
//usages
private lateinit var updateApp: UpdateApp
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
updateApp = UpdateApp(this)
}
override fun onResume() {
super.onResume()