// Path: reactivefb/src/main/java/com/beltaief/reactivefb/actions/ReactiveLogin.java
// public final class ReactiveLogin {
// 
//     /**
//      * Login with com.facebook.login.LoginManager
//      * The reason why this method returns a MayBe is that when a user cancel the operation, it
//      * does not emit any value neither an error. Maybe have a onComplete method that is covering
//      * this case.
//      * Use onSuccess to handle a success result.
//      * Use onComplete to handle canceled operation.
//      *
//      * @param activity instance of the current activity
//      * @return a Maybe of LoginResult
//      */
//     @NonNull
//     public static Maybe<LoginResult> login(@NonNull final Activity activity) {
//         checkNotNull(activity, "activity == null");
//         // save a weak reference to the activity
//         ReactiveFB.getSessionManager().setActivity(activity);
//         // login
//         return Maybe.create(new LoginOnSubscribe());
//     }
// 
//     /**
//      * Login with com.facebook.login.widget.LoginButton
//      * To be called from an Activity.
//      * The reason why it's returning an Observable and not a MayBe like login() is that with MayBe
//      * the subscribtion is done only one time. We need an observable in order to subscribe
//      * continuously.
//      *
//      * @param loginButton instance of a com.facebook.login.widget.LoginButton
//      * @return an Observable of LoginResult
//      */
//     @NonNull
//     public static Observable<LoginResult> loginWithButton(@NonNull final LoginButton loginButton) {
// 
//         checkNotNull(loginButton, "loginButton == null");
//         ReactiveFB.checkInit();
//         // login
//         return Observable.create(new LoginWithButtonOnSubscribe(loginButton));
//     }
// 
//     /**
//      * Login with com.facebook.login.widget.LoginButton
//      * To be called from an android.support.v4.app.Fragment
//      *
//      * @param loginButton instance of a com.facebook.login.widget.LoginButton
//      * @param fragment    instance of support android.support.v4.app.Fragment
//      * @return
//      */
//     @NonNull
//     public static Observable<LoginResult> loginWithButton(@NonNull final LoginButton loginButton,
//                                                           @NonNull final Fragment fragment) {
// 
//         checkNotNull(fragment, "fragment == null");
//         checkNotNull(loginButton, "loginButton == null");
//         ReactiveFB.checkInit();
//         // login
//         return Observable.create(new LoginWithButtonOnSubscribe(loginButton));
//     }
// 
//     /**
//      * Login with com.facebook.login.widget.LoginButton
//      * To be called from an android.app.Fragment
//      *
//      * @param loginButton instance of com.facebook.login.widget.LoginButton
//      * @param fragment    instance of android.app.Fragment
//      * @return
//      */
//     @NonNull
//     public static Observable<LoginResult> loginWithButton(@NonNull final LoginButton loginButton,
//                                                           @NonNull final android.app.Fragment fragment) {
// 
//         checkNotNull(fragment, "fragment == null");
//         checkNotNull(loginButton, "loginButton == null");
//         ReactiveFB.checkInit();
//         // login
//         return Observable.create(new LoginWithButtonOnSubscribe(loginButton));
//     }
// 
// 
//     /**
//      * Redirect facebook callback onActivityResult to this library callback.
//      * This is necessary with login/ loginWithButton methods.
//      *
//      * @param requestCode
//      * @param resultCode
//      * @param data
//      */
//     public static void onActivityResult(int requestCode, int resultCode, Intent data) {
//         ReactiveFB.getSessionManager()
//                 .getCallbackManager()
//                 .onActivityResult(requestCode, resultCode, data);
//     }
// 
//     /**
//      * Request additional permissions from facebook. This launches a new login with additional
//      * permissions.
//      *
//      * @param permissions List of {@link PermissionHelper}
//      * @param activity    current activity instance
//      * @return a Maybe of LoginResult.
//      */
//     public static Maybe<LoginResult> requestAdditionalPermission(@NonNull final List<PermissionHelper> permissions,
//                                                                  @NonNull final Activity activity) {
// 
//         checkNotNull(permissions, "permissions == null");
//         checkNotNull(activity, "activity == null");
// 
//         ReactiveFB.getSessionManager().setActivity(activity);
// 
//         return Maybe.create(new AdditionalPermissionOnSubscribe(permissions));
//     }
// 
//     private ReactiveLogin() {
//         throw new AssertionError("No instances.");
//     }
// }


import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.TextView;
import com.beltaief.reactivefb.actions.ReactiveLogin;
import com.beltaief.reactivefbexample.R;
import com.facebook.login.LoginResult;
import com.facebook.login.widget.LoginButton;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.observers.DisposableObserver;
package com.beltaief.reactivefbexample.views;




public class LoginButtonActivity extends AppCompatActivity {

    private static final String TAG = LoginButtonActivity.class.getSimpleName();
    private LoginButton loginButton;
    private TextView result;
    private final CompositeDisposable disposables = new CompositeDisposable();


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login_button);

        loginButton = (LoginButton) findViewById(R.id.fb_button_login);
        result = (TextView) findViewById(R.id.result);

        registerlogin();

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        disposables.clear(); // do not send event after activity has been destroyed
    }

    private void registerlogin() {
// Path: reactivefb/src/main/java/com/beltaief/reactivefb/actions/ReactiveLogin.java
// public final class ReactiveLogin {
// 
//     /**
//      * Login with com.facebook.login.LoginManager
//      * The reason why this method returns a MayBe is that when a user cancel the operation, it
//      * does not emit any value neither an error. Maybe have a onComplete method that is covering
//      * this case.
//      * Use onSuccess to handle a success result.
//      * Use onComplete to handle canceled operation.
//      *
//      * @param activity instance of the current activity
//      * @return a Maybe of LoginResult
//      */
//     @NonNull
//     public static Maybe<LoginResult> login(@NonNull final Activity activity) {
//         checkNotNull(activity, "activity == null");
//         // save a weak reference to the activity
//         ReactiveFB.getSessionManager().setActivity(activity);
//         // login
//         return Maybe.create(new LoginOnSubscribe());
//     }
// 
//     /**
//      * Login with com.facebook.login.widget.LoginButton
//      * To be called from an Activity.
//      * The reason why it's returning an Observable and not a MayBe like login() is that with MayBe
//      * the subscribtion is done only one time. We need an observable in order to subscribe
//      * continuously.
//      *
//      * @param loginButton instance of a com.facebook.login.widget.LoginButton
//      * @return an Observable of LoginResult
//      */
//     @NonNull
//     public static Observable<LoginResult> loginWithButton(@NonNull final LoginButton loginButton) {
// 
//         checkNotNull(loginButton, "loginButton == null");
//         ReactiveFB.checkInit();
//         // login
//         return Observable.create(new LoginWithButtonOnSubscribe(loginButton));
//     }
// 
//     /**
//      * Login with com.facebook.login.widget.LoginButton
//      * To be called from an android.support.v4.app.Fragment
//      *
//      * @param loginButton instance of a com.facebook.login.widget.LoginButton
//      * @param fragment    instance of support android.support.v4.app.Fragment
//      * @return
//      */
//     @NonNull
//     public static Observable<LoginResult> loginWithButton(@NonNull final LoginButton loginButton,
//                                                           @NonNull final Fragment fragment) {
// 
//         checkNotNull(fragment, "fragment == null");
//         checkNotNull(loginButton, "loginButton == null");
//         ReactiveFB.checkInit();
//         // login
//         return Observable.create(new LoginWithButtonOnSubscribe(loginButton));
//     }
// 
//     /**
//      * Login with com.facebook.login.widget.LoginButton
//      * To be called from an android.app.Fragment
//      *
//      * @param loginButton instance of com.facebook.login.widget.LoginButton
//      * @param fragment    instance of android.app.Fragment
//      * @return
//      */
//     @NonNull
//     public static Observable<LoginResult> loginWithButton(@NonNull final LoginButton loginButton,
//                                                           @NonNull final android.app.Fragment fragment) {
// 
//         checkNotNull(fragment, "fragment == null");
//         checkNotNull(loginButton, "loginButton == null");
//         ReactiveFB.checkInit();
//         // login
//         return Observable.create(new LoginWithButtonOnSubscribe(loginButton));
//     }
// 
// 
//     /**
//      * Redirect facebook callback onActivityResult to this library callback.
//      * This is necessary with login/ loginWithButton methods.
//      *
//      * @param requestCode
//      * @param resultCode
//      * @param data
//      */
//     public static void onActivityResult(int requestCode, int resultCode, Intent data) {
//         ReactiveFB.getSessionManager()
//                 .getCallbackManager()
//                 .onActivityResult(requestCode, resultCode, data);
//     }
// 
//     /**
//      * Request additional permissions from facebook. This launches a new login with additional
//      * permissions.
//      *
//      * @param permissions List of {@link PermissionHelper}
//      * @param activity    current activity instance
//      * @return a Maybe of LoginResult.
//      */
//     public static Maybe<LoginResult> requestAdditionalPermission(@NonNull final List<PermissionHelper> permissions,
//                                                                  @NonNull final Activity activity) {
// 
//         checkNotNull(permissions, "permissions == null");
//         checkNotNull(activity, "activity == null");
// 
//         ReactiveFB.getSessionManager().setActivity(activity);
// 
//         return Maybe.create(new AdditionalPermissionOnSubscribe(permissions));
//     }
// 
//     private ReactiveLogin() {
//         throw new AssertionError("No instances.");
//     }
// }


// Path: app/src/main/java/com/beltaief/reactivefbexample/views/LoginButtonActivity.java
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.TextView;
import com.beltaief.reactivefb.actions.ReactiveLogin;
import com.beltaief.reactivefbexample.R;
import com.facebook.login.LoginResult;
import com.facebook.login.widget.LoginButton;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.observers.DisposableObserver;

package com.beltaief.reactivefbexample.views;




public class LoginButtonActivity extends AppCompatActivity {

    private static final String TAG = LoginButtonActivity.class.getSimpleName();
    private LoginButton loginButton;
    private TextView result;
    private final CompositeDisposable disposables = new CompositeDisposable();


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login_button);

        loginButton = (LoginButton) findViewById(R.id.fb_button_login);
        result = (TextView) findViewById(R.id.result);

        registerlogin();

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        disposables.clear(); // do not send event after activity has been destroyed
    }

    private void registerlogin() {
        DisposableObserver<LoginResult> disposableObserver = ReactiveLogin.loginWithButton(loginButton)