Skip to content

Instantly share code, notes, and snippets.

View itslonua's full-sized avatar
🎯
Focusing

a-krapivnoy itslonua

🎯
Focusing
  • Ukraine
View GitHub Profile

Videos

abstract class RadioAdapter<T> extends RecyclerView.Adapter<RadioAdapter.ViewHolder> {
public int mSelectedItem = -1;
private Context mContext;
private List<T> mItems;
public RadioAdapter(Context context, List<T> items) {
mContext = context;
mItems = items;
}
@itslonua
itslonua / find_in_dependencies.gradle
Created April 3, 2018 07:49 — forked from rock3r/find_in_dependencies.gradle
Utility Gradle task to find where duplicate classes come from (for Gradle 4.1+)
// H/t to https://github.com/ethankhall/scripts/blob/master/gradle/find-file.gradle for the idea;
// this re-written version actually works in modern Gradle and Android Gradle plugins.
task findInDependencies << {
println()
def resolvableConfigs = project.getConfigurations()
.stream()
.filter { it.isCanBeResolved() }
@itslonua
itslonua / expand-collapse.java
Created March 14, 2018 15:18 — forked from ZkHaider/expand-collapse.java
Simple Expand / Collapse RecyclerView Item
public static class ExampleViewHolder extends RecyclerView.ViewHolder
implements View.OnClickListener {
private int originalHeight = 0;
private boolean isViewExpanded = false;
private YourCustomView yourCustomView
public ExampleViewHolder(View v) {
super(v);
v.setOnClickListener(this);
@itslonua
itslonua / Memoize.kt
Last active February 7, 2018 13:03
Memoization Function In Kotlin
val memIsTextPresent = Memoize(::isTextPresent)
fun isTextPresent(path: Path, text: String) = path.toFile().readText().contains(text, true)
class Memoize<A, B, C>(val func: (A, B) -> C) : (A, B) -> C {
val cache = ConcurrentHashMap<String, C>()
override fun invoke(p1: A, p2: B) = cache.getOrPut(p1.toString(), { func(p1, p2) })
}
import .... my_text as text // для сокращения чтоб не писать очень_длинное_имя (пример)
import .....button as btn
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
button.setOnClickListener { setMyText() } <- повесили обработчик клика
@itslonua
itslonua / ProgressLayout.java
Created October 25, 2017 16:06 — forked from alexfu/ProgressLayout.java
A simple FrameLayout that hides/shows an indeterminate ProgressBar over top of your UI
/*
* The MIT License (MIT)
*
* Copyright (c) 2015 Alex Fu
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
@itslonua
itslonua / EqualSpacingItemDecoration.java
Created October 25, 2017 10:53 — forked from alexfu/EqualSpacingItemDecoration.java
Add equal spacing to RecyclerView items automatically. Can handle horizontal, vertical, and grid display modes
import android.graphics.Rect;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
public class EqualSpacingItemDecoration extends RecyclerView.ItemDecoration {
private final int spacing;
private int displayMode;
public static final int HORIZONTAL = 0;
class AccountHolder extends MvpViewHolder implements AccountView {
@InjectPresenter
AccountPresenter mAccountPresenter;
/**
@BindView(R.id.item_account_check_box)
CheckBox mCheckBox;
...
**/
@itslonua
itslonua / MvpFrameLayout.java
Created October 23, 2017 11:50 — forked from kingargyle/MvpFrameLayout.java
Moxy MVP FrameLayout View example
package us.nineworlds.serenity.ui.views.mvp;
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.os.Parcelable;
import android.support.annotation.AttrRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.StyleRes;