Skip to content

Instantly share code, notes, and snippets.

Avatar

TechYourChance techyourchance

View GitHub Profile
@techyourchance
techyourchance / HungarianRemover.java
Last active Jun 8, 2021
Script that refactors Java and Kotlin files from mHungarianNotation to camelCase
View HungarianRemover.java
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.regex.*;
import java.util.Arrays;
import java.util.Collection;
@techyourchance
techyourchance / MyPermission.java
Last active May 28, 2021
Abstraction for clean management of runtime permissions in Android applications
View MyPermission.java
public enum MyPermission {
// declare runtime permissions specific to your app here (don't keep unused ones)
READ_PHONE_STATE(Manifest.permission.READ_PHONE_STATE),
FINE_LOCATION(Manifest.permission.ACCESS_FINE_LOCATION);
public static MyPermission fromAndroidPermission(String androidPermission) {
for (MyPermission permission : MyPermission.values()) {
if (permission.getAndroidPermission().equals(androidPermission)) {
return permission;
}
@techyourchance
techyourchance / BaseBusyObservable.java
Created Dec 21, 2019
Base class for Java Observable which needs to be aware of whether it's "busy" and expose this information to its clients
View BaseBusyObservable.java
public abstract class BaseBusyObservable<LISTENER_CLASS> extends BaseObservable<LISTENER_CLASS> {
private final AtomicBoolean mIsBusy = new AtomicBoolean(false);
public final boolean isBusy() {
return mIsBusy.get();
}
/**
* Atomically assert not busy and become busy
@techyourchance
techyourchance / BaseObservable.java
Last active May 8, 2020
Base class for Java Observable
View BaseObservable.java
public abstract class BaseObservable<LISTENER_CLASS> {
private final Object MONITOR = new Object();
private final Set<LISTENER_CLASS> mListeners = new HashSet<>();
public void registerListener(LISTENER_CLASS listener) {
synchronized (MONITOR) {
boolean hadNoListeners = mListeners.size() == 0;
mListeners.add(listener);