package me.memleak.pomorello.activities;

import android.content.Intent;

import butterknife.OnClick;
import me.memleak.pomorello.BuildConfig;
import me.memleak.pomorello.R;
import me.memleak.pomorello.helpers.ToastHelper;

/**
 * Created by jafar_qaddoumi on 9/4/15.
 * <p/>
 * Copyright (c) 2015 memleak.me. All rights reserved.
 */
public class SplashActivity extends BaseActivity {

    @Override
    protected int getLayoutResID() {
        return R.layout.activity_splash;
    }

    @Override
    protected void setupViews() {
        if (mPomorelloUser.isAuthenticated()) {
            TasksActivity.startActivity(mActivity);
            mActivity.finish();
        } else {
            // AuthenticateTrelloActivity.startActivity(mActivity);
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (TrelloOuthActivity.REQUEST_CODE_TRELLO_AUTH == requestCode) {
            if (RESULT_OK == resultCode) {
                mPomorelloUser.setAccessToken(data.getStringExtra(TrelloOuthActivity.EXTRA_ACCESS_TOKEN));
                mPomorelloUser.setAccessSecret(data.getStringExtra(TrelloOuthActivity.EXTRA_ACCESS_SECRET));
                mPomorelloUser.save(mContext);
            } else {
                String error;
                if (null != data) {
                    error = data.getStringExtra(TrelloOuthActivity.EXTRA_ERROR_MESSAGE);
                } else {
                    error = getString(R.string.error_empty_trello_msg);
                }

                ToastHelper.top(mContext, error);
            }
        } else {
            super.onActivityResult(requestCode, resultCode, data);
        }
    }

    @OnClick(R.id.splash_btn_login)
    void clickLogin() {
        TrelloOuthActivity.startActivityForResult(mActivity,
                BuildConfig.TRELLO_API_KEY,
                BuildConfig.TRELLO_API_SECRET);
    }
}

@@ -67,16 +67,40 @@
 ntent;%0A%0A
+import java.util.List;%0A%0A
 import b
@@ -239,16 +239,273 @@
 tHelper;
+%0Aimport me.memleak.pomorello.models.TrelloBoard;%0Aimport me.memleak.pomorello.rest.TrelloCallback;%0Aimport me.memleak.pomorello.rest.TrelloClient;%0Aimport me.memleak.pomorello.rest.apis.TrelloApi;%0Aimport retrofit.RetrofitError;%0Aimport retrofit.client.Response;
 %0A%0A/**%0A *
@@ -872,13 +872,29 @@
     
-Tasks
+// AuthenticateTrello
 Acti
@@ -940,112 +940,186 @@
     
-mActivity.finish();%0A        %7D else %7B%0A            // AuthenticateTrelloActivity.startActivity(mActivity);
+ToastHelper.top(mContext, %22load all boards%22);%0A            TrelloApi trelloApi = TrelloClient.getTrelloApi();%0A            trelloApi.getAllBoards(boardsCallback);%0A        %7D else %7B%0A
 %0A   
@@ -2285,11 +2285,608 @@
 );%0A    %7D
+%0A%0A    private TrelloCallback%3CList%3CTrelloBoard%3E%3E boardsCallback = new TrelloCallback%3CList%3CTrelloBoard%3E%3E() %7B%0A%0A        @Override%0A        public void success(List%3CTrelloBoard%3E boardList, Response response) %7B%0A            super.success(boardList, response);%0A%0A            mRealm.beginTransaction();%0A            mRealm.copyToRealmOrUpdate(boardList);%0A            mRealm.commitTransaction();%0A%0A            HomeActivity.startActivity(mActivity);%0A            mActivity.finish();%0A        %7D%0A%0A        @Override%0A        public void failure(RetrofitError error) %7B%0A            super.failure(error);%0A        %7D%0A    %7D;
 %0A%7D%0A

load user boards