Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View Ahmed-Adel-Ismail's full-sized avatar
:octocat:
Androiding

Ahmed Adel Ismail Ahmed-Adel-Ismail

:octocat:
Androiding
View GitHub Profile
@Ahmed-Adel-Ismail
Ahmed-Adel-Ismail / ActivityObservable.java
Last active September 28, 2017 10:50
LifeCycleDisposable is a class that enables auto-disposing Rx-Java disposables without the need to track there Disposable instance ... it even shuts down the stream after a timeout if it took so long (can be adjusted)
import android.app.Activity;
import java.lang.ref.WeakReference;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import io.reactivex.Observable;
import io.reactivex.ObservableOperator;
import io.reactivex.ObservableSource;
@Ahmed-Adel-Ismail
Ahmed-Adel-Ismail / IfElse.java
Last active February 8, 2024 14:44
Observable Operators that enables switch-case and if-else in RxJava stream, you can use them with lift() operator, and pass to them a Map of key/function , if the key is matched with the emitted item, it's function will be executed and it's value will be returned in the stream
/**
* an {@link ObservableOperator} that simulates an if-else in an RxJava Stream, it takes a {@link Map}
* of {@link Predicate} as key and a {@link Function} as value ... the if any emitted item passes
* the {@link Predicate}, this emitted item will be passed to the {@link Function} mapped to it,
* and this item will be invoked and it's result will continue down the stream
* <p>
* sample code :
* <p>
* {@code List<Integer> list = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8);}<br>
* {@code Map<Predicate<Integer>, Function<Integer, String>> blocks = new LinkedHashMap<>(2)}<br>
@Ahmed-Adel-Ismail
Ahmed-Adel-Ismail / Model.java
Created August 27, 2017 22:42
A Model parent-class that survives rotation and configuration changes, all you need to do is call Model.of() in your onCreate, and Model.clear() in onDestroy, this code is based on this link : http://bcorso.github.io/android-retain-fragment/
import android.os.Bundle;
import android.support.annotation.CallSuper;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.AppCompatActivity;
import java.lang.reflect.Constructor;
/**
@Ahmed-Adel-Ismail
Ahmed-Adel-Ismail / MacAddressScanner.java
Last active July 14, 2017 10:22
A class that retrieves Android's Mac address by all possible means (so far), used dependencies are RxJava2, Retrolambda, Guava, custom Preferences class to handle saving / loading from Shared Preferences, and J-Curry (https://github.com/Terebentikh/J-Curry) for currying functions in RxJava2 operators
/**
* a {@link Maybe} that retrieves the Mac address from any of the following sources :
* <p>
* {@code Shared Preference}<br>
* {@code Wifi}<br>
* {@code Network interfaces}
* <p>
* then saves it to {@code Shared preferences} if found
* <p>
* Created by Ahmed Adel Ismail on 7/10/2017.