Skip to content

Instantly share code, notes, and snippets.

View itslonua's full-sized avatar
🎯
Focusing

a-krapivnoy itslonua

🎯
Focusing
  • Ukraine
View GitHub Profile
@itslonua
itslonua / FlowThrottleDebounce.kt
Created December 5, 2021 16:44 — forked from chibatching/FlowThrottleDebounce.kt
Throttle and Debounce on Flow Kotlin Coroutines
fun <T> Flow<T>.throttle(waitMillis: Int) = flow {
coroutineScope {
val context = coroutineContext
var nextMillis = 0L
var delayPost: Deferred<Unit>? = null
collect {
val current = SystemClock.uptimeMillis()
if (nextMillis < current) {
nextMillis = current + waitMillis
@itslonua
itslonua / AutoCompleteTextViewBehaviour.java
Created March 26, 2019 15:46 — forked from RobertZagorski/AutoCompleteTextViewBehaviour.java
AutoCompleteTextView CoordinatorLayout.Behavior that is aware of Snackbar and changes autocompletes popup when Snackbar is shown.
package com.example.rzagorski.coordinatorawareautocompletetextviewapp;
import android.content.Context;
import android.support.annotation.Nullable;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.Snackbar;
import android.support.v7.widget.AppCompatAutoCompleteTextView;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
@itslonua
itslonua / CustomLayout.java
Created December 4, 2018 21:23 — forked from hector6872/CustomLayout.java
Custom Viewgroup: onSaveInstanceState - onRestoreInstanceState http://trickyandroid.com/saving-android-view-state-correctly/
public class CustomLayout extends LinearLayout {
@SuppressWarnings("unchecked") @Override public Parcelable onSaveInstanceState() {
Parcelable saveInstanceState = super.onSaveInstanceState();
SavedState savedState = new SavedState(saveInstanceState);
savedState.childrenStates = new SparseArray();
for (int i = 0; i < getChildCount(); i++) {
getChildAt(i).saveHierarchyState(savedState.childrenStates);
}
return savedState;
@itslonua
itslonua / MainActivity.java
Created October 23, 2018 19:25 — forked from Aeonitis/MainActivity.java
Android - Check Network State in your app, Notifying you when an app is online/offline
/**
* This would be the activity which registers the receiver class via it's interface
*/
public class MainActivity implements NetworkStateReceiver.NetworkStateReceiverListener {
private NetworkStateReceiver networkStateReceiver; // Receiver that detects network state changes
@Override
protected void onCreate(Bundle savedInstanceState) {
/***/
@itslonua
itslonua / AspectRatioCardView.java
Created September 19, 2018 10:49 — forked from furkantektas/AspectRatioCardView.java
CardView with aspect ratio
package com.furkantektas.braingames.ui;
import android.content.Context;
import android.content.res.TypedArray;
import android.support.v7.widget.CardView;
import android.util.AttributeSet;
import com.furkantektas.braingames.R;
/**
@itslonua
itslonua / Android TimeExpiringLruCache.java
Created August 7, 2018 14:25 — forked from trajakovic/Android TimeExpiringLruCache.java
I've took original Android's LruCache, and implemented time expiration parameter, so when you call next time "get", and value is timed-out, you'll get null (and old entry will be removed from cache).
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import android.os.SystemClock;
public class TimeExpiringLruCache<K, V> {
private final LinkedHashMap<K, V> map;
private final HashMap<K, Long> validityTime;
@itslonua
itslonua / git-clearHistory
Created July 13, 2018 20:55 — forked from ygorth/git-clearHistory
Steps to clear out the history of a git/github repository
-- Remove the history from
rm -rf .git
-- recreate the repos from the current content only
git init && git add . && git status
git commit -m "Initial commit"
-- push to the github remote repos ensuring you overwrite history
git remote add origin git@github.com:<YOUR ACCOUNT>/<YOUR REPOS>.git
git push -u --force origin master

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() }