Skip to content

Instantly share code, notes, and snippets.

View micer's full-sized avatar
👻

Michal Cerman micer

👻
  • Czechia/Spain
View GitHub Profile
@micer
micer / NestedScrollableHost
Created August 24, 2020 11:24
Fixes issue with nested scrolling elements with the same scroll direction inside ViewPager2. https://issuetracker.google.com/issues/123006042
package com.betvictor.casino.presentation.views
/*
* Copyright 2019 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
@micer
micer / RealPathUtil.kt
Last active April 18, 2021 01:21
Utility class to get real path from URI object - all API versions
import android.content.ContentUris
import android.content.Context
import android.database.Cursor
import android.net.Uri
import android.os.Build
import android.os.Environment
import android.provider.DocumentsContract
import android.provider.MediaStore
import android.support.v4.content.CursorLoader
import android.text.TextUtils
@micer
micer / SslUtils.kt
Created July 26, 2018 11:15
SSL Utils
import android.content.Context
import timber.log.Timber.d
import java.security.KeyManagementException
import java.security.KeyStore
import java.security.NoSuchAlgorithmException
import java.security.SecureRandom
import java.security.cert.Certificate
import java.security.cert.CertificateException
import java.security.cert.CertificateFactory
import java.security.cert.X509Certificate
int delay = 25;
observableRemainingTime.setValue(TIME_FOR_ANSWER);
timerDisposable = Observable.timer(delay, TimeUnit.MILLISECONDS, Schedulers.computation())
.observeOn(AndroidSchedulers.mainThread())
.repeatUntil(() -> time <= 0)
.subscribe(tick -> {
time = time - delay;
observableRemainingTime.setValue(time);
},
Throwable::printStackTrace,
@micer
micer / ExtensionFunctions.kt
Created March 14, 2018 10:43
I'll put useful Kotlin Extension Functions here
private inline fun <T> TextView.updateOrHide(content: T?, action: TextView.(content: T) -> Unit) {
if (content != null) {
visibility = View.VISIBLE
action(content)
} else {
visibility = View.GONE
}
}
@micer
micer / gist:05656834dd22cc9b3ab62cf4efd25666
Created March 13, 2018 15:04
Get name of error code static final variable using reflection
public static String getErrorCodeName(int errorCode) {
Field[] fields = ErrorCodes.class.getDeclaredFields();
for (Field f : fields) {
if (Modifier.isStatic(f.getModifiers())
&& Modifier.isFinal(f.getModifiers())) {
try {
int value = f.getInt(new Object());
if (value == errorCode) {
return f.getName();
}
@micer
micer / AppExecutors.java
Created March 7, 2018 00:15
Elegant helper class to run operations on different threads.
package eu.micer.sample.util;
import android.os.Handler;
import android.os.Looper;
import android.support.annotation.NonNull;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
public class AppExecutors {