Skip to content

Instantly share code, notes, and snippets.

View Miha-x64's full-sized avatar
🍵
へ‿(◉‿◉)‿ㄏ

Mike Miha-x64

🍵
へ‿(◉‿◉)‿ㄏ
View GitHub Profile
@Miha-x64
Miha-x64 / PicassoTextView.kt
Last active April 26, 2021 18:48
A TextView with Picasso targets for compound drawables
package net.aquadc.commonandroid.views
import android.annotation.SuppressLint
import android.content.Context
import android.graphics.Bitmap
import android.graphics.drawable.BitmapDrawable
import android.graphics.drawable.ColorDrawable
import android.graphics.drawable.Drawable
import android.graphics.drawable.TransitionDrawable
import android.view.View
class MainActivity : AppCompatActivity(),
NavigationView.OnNavigationItemSelectedListener, FragmentManager.OnBackStackChangedListener {
private lateinit var drawer: DrawerLayout
private lateinit var toggle: ActionBarDrawerToggle
private lateinit var navigation: NavigationView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@Miha-x64
Miha-x64 / BadBackendResponseDeserializer.kt
Created March 31, 2017 18:44
Such deseriazers will help you in processing responses from back-ends which return 200 HTTP code all the time.
object class BadBackendResponseDeserializer : JsonDeserializer<Any?> {
// register all adapters you need
private val gson = GsonBuilder()
.registerTypeAdapter(Post::class.java, WallPostAdapter)
.registerTypeAdapter(Attachment::class.java, AttachmentAdapter)
.registerTypeAdapter(User::class.java, UserAdapter)
.registerTypeAdapter(Group::class.java, GroupAdapter)
.create()
package net.aquadc.commonandroid.lists;
import android.support.v4.view.ViewCompat;
import android.support.v4.view.ViewPropertyAnimatorCompat;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import com.mikepenz.itemanimators.DefaultAnimator;
/**
* ItemAnimator implementation which animates items so it looks like they're falling into list.
@Miha-x64
Miha-x64 / RetrofitCallback.kt
Last active February 9, 2022 10:02
A wrapper around retrofit2.Callback
abstract class RetrofitCallback<T> : retrofit2.Callback<T> {
final override fun onResponse(call: Call<T>, response: Response<T>) =
if (response.isSuccessful) onSuccess(response.body())
else
onError(when (response.code()) {
401 -> Failure.Unauthorized()
404 -> Failure.NotFound()
409 -> Failure.Conflict()
500 -> Failure.InternalServerError()
@Miha-x64
Miha-x64 / ImDate.kt
Last active August 30, 2017 17:08
Immutable Date subclass
package net.aquadc.common
import java.util.*
import kotlin.DeprecationLevel.ERROR
import kotlin.UnsupportedOperationException as UOE
/**
* Created by mike on 17.02.17
*/
@Miha-x64
Miha-x64 / EnumSetTypeAdapterFactory.kt
Last active February 9, 2022 10:01
TypeAdapter(Factory) for enums with no reflective @SerializedName lookup; TypeAdapterFactory whichs treats Set<E> as EnumSet<E>
package net.aquadc.common
import com.google.gson.Gson
import com.google.gson.TypeAdapter
import com.google.gson.TypeAdapterFactory
import com.google.gson.reflect.TypeToken
import java.lang.reflect.ParameterizedType
import java.util.*
/**
package net.aquadc.commonandroid
import android.content.res.Resources
import java.text.SimpleDateFormat
import java.util.*
/**
* Returns text representation of `Date` and time (in millis)
* after which this value should be updated;
* time can be -1, which means that no update will ever be needed
@Miha-x64
Miha-x64 / DynamicActivity.java
Created May 23, 2017 14:58
An activity which copies an APK from assets to private directory, and loads a class and resources from it.
package whatever.dynamicapkloading;
import android.app.Activity;
import android.content.Context;
import android.content.res.AssetManager;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.widget.TextView;
@Miha-x64
Miha-x64 / enums.kt
Last active February 9, 2022 10:00
Enum extensions for Kotlin, superseded by https://github.com/Miha-x64/Kotlin-MPP_Collection_utils
package net.aquadc.common
// Gist: https://gist.github.com/Miha-x64/5f626228b34175f827734596d6701008
import java.util.*
// maps
inline fun <reified K : Enum<K>, V> enumMapOf(): MutableMap<K, V> {
return EnumMap<K, V>(K::class.java)
}