Skip to content

Instantly share code, notes, and snippets.

View gtomek's full-sized avatar

Tomek Giszczak gtomek

  • Zurich, CH
View GitHub Profile
@gtomek
gtomek / OkHttp3IdlingResource.kt
Created May 16, 2023 19:15
OkHttp3 IdlingResource in kotlin
class OkHttp3IdlingResource(
private val name: String,
private val dispatcher: Dispatcher
) : IdlingResource {
private val callbackReference = AtomicReference<ResourceCallback>()
init {
dispatcher.idleCallback = Runnable {
callbackReference.get()?.onTransitionToIdle()
102 # keep model classes e.g. kotlin data classes without need of @Keep or @SerializedName annotations
103 -keep class com.yourapppackage.app.**.model.** { <fields>; }
@gtomek
gtomek / strictmode.kt
Created December 20, 2021 07:24
enable strict mode, just flashing
private void enableStrictMode() {
StrictMode.ThreadPolicy.Builder threadPolicyBuilder = new StrictMode.ThreadPolicy.Builder()
.detectAll()
.penaltyFlashScreen()
.penaltyLog();
StrictMode.VmPolicy.Builder vmPolicyBuilder = new StrictMode.VmPolicy.Builder()
.detectAll()
.penaltyLog();
StrictMode.setThreadPolicy(threadPolicyBuilder.build());
@gtomek
gtomek / build.gradle.kts
Last active March 17, 2024 18:28
build gradle kts read properties file
import java.util.Properties
android {
compileSdkVersion(Config.Android.compileSdkVersion)
buildToolsVersion = Config.Android.buildToolsVersion
defaultConfig {
minSdkVersion(Config.Android.minSdkVersion)
versionCode = Config.Libs.versionCode
versionName = Config.Libs.versionName
@gtomek
gtomek / ConcurrencyHelpers.kt
Created June 9, 2020 10:38 — forked from objcode/ConcurrencyHelpers.kt
Helpers to control concurrency for one shot requests using Kotlin coroutines.
import kotlinx.coroutines.CoroutineStart.LAZY
import kotlinx.coroutines.Deferred
import kotlinx.coroutines.async
import kotlinx.coroutines.cancelAndJoin
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import kotlinx.coroutines.yield
import java.util.concurrent.atomic.AtomicReference
import kotlin.DeprecationLevel.ERROR
@gtomek
gtomek / OkHttpCookieJar.java
Created April 30, 2020 07:59
Add cookie jar to OkHttp client
class OkHttpCookieJar {
/**
Requires okhttp-urlconnection aftefact
**/
public OkHttpClient getOkHttpWithCookies() {
// set cookies
CookieManager cookieManager = new CookieManager();
CookieHandler.setDefault(cookieManager);
cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
@gtomek
gtomek / RotatingGradientView.kt
Last active February 1, 2021 09:48
example of how to rotate sweep gradient in android view
/**
* View showing rotating SweepGradient.
*/
class RotatingGradientView @JvmOverloads constructor(
context: Context?,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : View(context, attrs, defStyleAttr) {
private val paint = Paint(Paint.ANTI_ALIAS_FLAG)
private var middleX = 0f
/*
* Copyright (C) 2014 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
@gtomek
gtomek / cvdata.json
Last active November 11, 2019 21:10
JSON with my CV data
{
"name":"Tomasz",
"nationality":"British",
"phone":"+447963049108",
"email":"tom@gmail.com",
"summary":"Talented Lead Android Developer with a proven track record of implementation and leading the development of innovative applications. As a developer, I love clean, self-explanatory code, UI design following platform specific guidelines and providing a smooth user experience. I follow the development of new technologies and regularly participate in local technology meet-ups.",
"knowledgeTopics": [
"Android",
"Java",
"Kotlin",
const val ID = "id"
class MyActivity : Activity() {
private val id1 by extra<String>(ID) // String?
private val id2 by extraNotNull<String>(ID) // String
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
requireNotNull(id1, id2)