package info.izumin.android.sunazuri.presentation.activity.oauth;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.customtabs.CustomTabsIntent;
import android.support.v7.app.AppCompatActivity;
import info.izumin.android.sunazuri.R;
import info.izumin.android.sunazuri.Sunazuri;
import info.izumin.android.sunazuri.domain.RootStore;
import info.izumin.android.sunazuri.domain.usecase.FetchTokenUseCase;
import info.izumin.android.sunazuri.infrastructure.entity.OauthParams;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

import javax.inject.Inject;

public class OauthActivity extends AppCompatActivity {
    public static final String TAG = OauthActivity.class.getSimpleName();

    @Inject RootStore store;
    @Inject OauthParams oauthParams;
    @Inject FetchTokenUseCase fetchTokenUseCase;

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

        if (store.getAccessToken() == null) {
            CustomTabsIntent intent = new CustomTabsIntent.Builder().build();
            intent.launchUrl(this, Uri.parse(oauthParams.getAuthorizeUri()));
        }
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        inject();
        fetchTokenUseCase.execute(intent.getDataString())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(this::returnToMain);
    }

    private void returnToMain() {
        setResult(Activity.RESULT_OK);
        finish();
    }

    private void inject() {
        Sunazuri.get(this).getComponent().inject(this);
    }
}

@@ -397,23 +397,41 @@
 ri.d
-omain.RootStore
+ata.action.user.UserActionCreator
 ;%0Aim
@@ -475,32 +475,16 @@
 ain.
-usecase.FetchTokenUseCas
+RootStor
 e;%0Ai
@@ -876,43 +876,43 @@
 ect 
-FetchTokenUseCase fetchTokenUseCase
+UserActionCreator userActionCreator
 ;%0A%0A 
@@ -1119,28 +1119,34 @@
 getA
-ccessToken() == null
+uthorizedUsers().isEmpty()
 ) %7B%0A
@@ -1445,33 +1445,57 @@
     
-fetchTokenUseCase.execute
+store.dispatch(userActionCreator.createAuthAction
 (int
@@ -1514,16 +1514,17 @@
 tring())
+)
 %0A       
@@ -1652,14 +1652,14 @@
 ibe(
-this::
+_a -%3E 
 retu
@@ -1666,16 +1666,18 @@
 rnToMain
+()
 );%0A    %7D

Use action creators instead of usecases