package br.ufg.inf.adopet.activities;

import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;

import br.ufg.inf.adopet.R;
import br.ufg.inf.adopet.adapters.PagerAdapter;

public class MainActivity extends AppCompatActivity implements TabLayout.OnTabSelectedListener{

    private TabLayout mTabLayout;
    private ViewPager mViewPager;

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


        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        toolbar.setTitle(getString(R.string.app_name));
        toolbar.setNavigationIcon(R.mipmap.ic_launcher);

        mTabLayout = (TabLayout) findViewById(R.id.tabLayout);
        this.setUpTabs();
        mTabLayout.setTabGravity(TabLayout.GRAVITY_CENTER);

        mViewPager = (ViewPager) findViewById(R.id.pager);


        PagerAdapter pager = new PagerAdapter(getSupportFragmentManager(),mTabLayout.getTabCount(),false);
        mViewPager.setAdapter(pager);
        mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                mTabLayout.getTabAt(position).select();
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
        mTabLayout.addOnTabSelectedListener(this);

        setSupportActionBar(toolbar);
    }

    @Override
    public void onTabSelected(TabLayout.Tab tab) {
        mViewPager.setCurrentItem(tab.getPosition());
    }

    @Override
    public void onTabUnselected(TabLayout.Tab tab) {

    }

    @Override
    public void onTabReselected(TabLayout.Tab tab) {

    }

    private void setUpTabs(){

        String[] tabs = getResources().getStringArray(R.array.tabs);

        for (String tab : tabs){
            mTabLayout.addTab(mTabLayout.newTab().setText(tab));
        }

    }
}

@@ -315,16 +315,95 @@
 Adapter;
+%0Aimport br.ufg.inf.adopet.util.AppData;%0Aimport br.ufg.inf.adopet.util.InputTag;
 %0A%0Apublic
@@ -1111,24 +1111,119 @@
 id.pager);%0A%0A
+        boolean auth = !AppData.getData(this, AppData.Preferences.ACCESS_TOKEN,%22%22).equals(%22%22);%0A
 %0A        Pag
@@ -1314,13 +1314,12 @@
 t(),
-false
+auth
 );%0A 

add flag for auth user