Skip to content
FVolodia edited this page Dec 6, 2016 · 9 revisions

Welcome to the AndroidBest wiki!

https://adityaladwa.wordpress.com/2016/10/25/offline-first-reactive-android-apps-repository-pattern-mvp-dagger-2-rxjava-contentprovider/

`package co.jakapp.driver.presenter;

import android.os.Handler;

import co.jakapp.driver.activities.interfaces.views.BaseView; import co.jakapp.driver.navigator.BaseNavigator; import rx.functions.Action0;

/**

  • Created by volodymyr on 9/15/16. */ public abstract class BasePresenter<V extends BaseView, N extends BaseNavigator> { protected V view; protected N navigator; protected boolean isFragmentActive = false; protected boolean isMainActionFinished = false; private Action0 pendingAction;

    protected void setView(V view) { this.view = view; }

    protected void setNavigator(N navigator) { this.navigator = navigator; }

    public void setMainAction(Action0 action){ pendingAction = action; if (isFragmentActive){ allowAction(); } else { isMainActionFinished = true; } }

    public void allowAction(){ new Handler().postDelayed(() -> pendingAction.call(),300);

    }

    public void onAttach() { }

    public void onStart() { }

    public void onResume() { isFragmentActive = true; if (isMainActionFinished){ allowAction(); } isMainActionFinished = false; }

    public void onPause() { }

    public void onStop() { isFragmentActive = false; }

    public void onDestroy() { view = null; navigator = null; } } `