package co.ommu.inlisjogja.fragment;

import android.content.Context;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;
import java.util.List;

import co.ommu.inlisjogja.R;

public class ActionFragment extends Fragment {
    Context context;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_action, container, false);

        ViewPager viewPager = (ViewPager) view.findViewById(R.id.viewpager);
        if (viewPager != null) {
            setupViewPager(viewPager);
        }

        TabLayout tabLayout = (TabLayout) view.findViewById(R.id.tabs);
        tabLayout.setupWithViewPager(viewPager);

        return view;
    }

    private void setupViewPager(ViewPager viewPager) {
        Adapter adapter = new Adapter(getActivity().getSupportFragmentManager());
        adapter.addFragment(new ViewFragment(), getResources().getString(R.string.action_views));
        adapter.addFragment(new BookmarkFragment(), getResources().getString(R.string.action_bookmarks));
        adapter.addFragment(new LikeFragment(), getResources().getString(R.string.action_likes));
        viewPager.setAdapter(adapter);
    }

    static class Adapter extends FragmentPagerAdapter {
        private final List<Fragment> mFragments = new ArrayList<>();
        private final List<String> mFragmentTitles = new ArrayList<>();

        public Adapter(FragmentManager fm) {
            super(fm);
        }

        public void addFragment(Fragment fragment, String title) {
            mFragments.add(fragment);
            mFragmentTitles.add(title);
        }

        @Override
        public Fragment getItem(int position) {
            return mFragments.get(position);
        }

        @Override
        public int getCount() {
            return mFragments.size();
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return mFragmentTitles.get(position);
        }
    }
}

@@ -1652,25 +1652,25 @@
 agment%3E 
-m
+o
 Fragment
 s = new 
@@ -1661,17 +1661,16 @@
 Fragment
-s
  = new A
@@ -1718,17 +1718,17 @@
 String%3E 
-m
+o
 Fragment
@@ -1732,17 +1732,16 @@
 entTitle
-s
  = new A
@@ -1913,25 +1913,25 @@
         
-m
+o
 Fragment
 s.add(fr
@@ -1922,17 +1922,16 @@
 Fragment
-s
 .add(fra
@@ -1950,17 +1950,17 @@
         
-m
+o
 Fragment
@@ -1964,17 +1964,16 @@
 entTitle
-s
 .add(tit
@@ -2073,25 +2073,25 @@
  return 
-m
+o
 Fragment
 s.get(po
@@ -2082,17 +2082,16 @@
 Fragment
-s
 .get(pos
@@ -2178,25 +2178,25 @@
  return 
-m
+o
 Fragment
 s.size()
@@ -2187,17 +2187,16 @@
 Fragment
-s
 .size();
@@ -2301,17 +2301,17 @@
  return 
-m
+o
 Fragment
@@ -2315,17 +2315,16 @@
 entTitle
-s
 .get(pos

modify action tabs