Skip to content

Instantly share code, notes, and snippets.

👀
Forever coding

Mitch Tabian mitchtabian

View GitHub Profile
View AppModule.java
@Singleton
@Provides
static User someUser(){
return new User();
}
@mitchtabian
mitchtabian / AppComponent.java
Created Apr 15, 2019
Old way to make app component
View AppComponent.java
@Component
public interface AppComponent {
void inject(BaseApplication application);
}
@mitchtabian
mitchtabian / AppInjector.java
Last active Apr 6, 2019
Scope example with an @singleton User object and @LoginScope User object
View AppInjector.java
@Override
public void onActivityDestroyed(Activity activity) {
if(activity instanceof LoginActivity){
loginComponent = null;
}
}
private void handleActivity(Activity activity){
if(activity instanceof HasSupportFragmentInjector){
@mitchtabian
mitchtabian / AppComponent.java
Created Apr 5, 2019
Example of making use of the Application context using @Component.Builder in AppComponent class (new way)
View AppComponent.java
@Singleton
@Component(
modules = {
AndroidInjectionModule.class,
AppModule.class,
ActivityBuildersModule.class
})
public interface AppComponent extends AndroidInjector<BaseApplication> {
@Component.Builder
@mitchtabian
mitchtabian / AppComponent.java
Last active Apr 5, 2019
Example of NOT making use of @Component.Builder and @BindsInstance (this is the old way)
View AppComponent.java
@Singleton
@Component(
modules = {
AndroidInjectionModule.class,
AppModule.class,
ActivityBuildersModule.class
})
public interface AppComponent extends AndroidInjector<BaseApplication> {
}
@mitchtabian
mitchtabian / AppComponent.java
Last active Apr 5, 2019
creates the "inject" method automatically with AndroidInjector<Class>
View AppComponent.java
// *** Must specify specific TYPE here. 'BaseApplication', not 'Application'. Since it generates an inject(BaseApplication app); method.
public interface AppComponent extends AndroidInjector<BaseApplication> { // no need for inject method. It's generated.
LoginComponent.Builder newLoginComponentBuilder();
// void inject(BaseApplication application);
@Component.Builder
interface Builder {
View Query.java
@Query("SELECT * FROM recipes WHERE title LIKE '%' || :query || '%' OR ingredients LIKE '%' || :query || '%' " +
"ORDER BY social_rank DESC LIMIT (:pageNumber * 30)")
LiveData<List<Recipe>> searchRecipes(String query, int pageNumber);
View FlowableToObservable.java
Observable<Integer> observable = Observable
.just(1, 2, 3, 4, 5);
Flowable<Integer> flowable = observable.toFlowable(BackpressureStrategy.BUFFER);
Observable<Integer> backToObservable = flowable.toObservable();
View ObservableToFlowable.java
Observable<Integer> observable = Observable
.just(1, 2, 3, 4, 5);
Flowable<Integer> flowable = observable.toFlowable(BackpressureStrategy.BUFFER);
View OnBackpressureBuffer.java
Flowable.range(0, 1000000)
.onBackpressureBuffer()
.observeOn(Schedulers.computation())
.subscribe(new FlowableSubscriber<Integer>() {
@Override
public void onSubscribe(Subscription s) {
}
@Override
public void onNext(Integer integer) {
You can’t perform that action at this time.