package com.benny.openlauncher.hideApps;

import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
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.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.WindowManager;

import com.benny.openlauncher.R;
import com.benny.openlauncher.util.AppManager;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

@SuppressWarnings("ResultOfMethodCallIgnored")
public class Activity_hideApps extends AppCompatActivity {


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

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            getWindow().setStatusBarColor(getResources().getColor(R.color.colorPrimaryDark));
        }

        setTitle(getString(R.string.settings_iconHide));

        ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
        setupViewPager(viewPager);

        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setDisplayShowHomeEnabled(true);

        File directory = new File(Environment.getExternalStorageDirectory() + "/launcher.backup/");
        if (!directory.exists()) {
            directory.mkdirs();
        }
    }

    @Override
    protected void onDestroy() {
        AppManager.getInstance(this).recreateAfterGettingApps = true;
        AppManager.getInstance(this).init();
        super.onDestroy();
    }

    private void setupViewPager(ViewPager viewPager) {

        ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());

        adapter.addFragment(new Fragment_hideApps(), String.valueOf("Skip"));

        viewPager.setAdapter(adapter);
    }

    class ViewPagerAdapter extends FragmentPagerAdapter {
        private final List<Fragment> mFragmentList = new ArrayList<>();
        private final List<String> mFragmentTitleList = new ArrayList<>();

        private ViewPagerAdapter(FragmentManager manager) {
            super(manager);
        }

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

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

        private void addFragment(Fragment fragment, String title) {
            mFragmentList.add(fragment);
            mFragmentTitleList.add(title);
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return mFragmentTitleList.get(position);// add return null; to display only icons
        }
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                onBackPressed();
                break;
        }
        return super.onOptionsItemSelected(item);
    }

}
@@ -742,17 +742,16 @@
 vity %7B%0A%0A
-%0A
     @Ove
@@ -1182,67 +1182,8 @@
   %7D%0A
-%0A        setTitle(getString(R.string.settings_iconHide));%0A%0A
     
@@ -1282,24 +1282,81 @@
 iewPager);%0A%0A
+        setTitle(getString(R.string.settings_iconHide));%0A
         Tool
@@ -1574,186 +1574,8 @@
 ue);
-%0A%0A        File directory = new File(Environment.getExternalStorageDirectory() + %22/launcher.backup/%22);%0A        if (!directory.exists()) %7B%0A            directory.mkdirs();%0A        %7D
 %0A   
@@ -1829,17 +1829,16 @@
 ager) %7B%0A
-%0A
         
@@ -1911,25 +1911,24 @@
 Manager());%0A
-%0A
         adap
@@ -1993,17 +1993,16 @@
 kip%22));%0A
-%0A
         
@@ -2035,24 +2035,291 @@
 er);%0A    %7D%0A%0A
+    @Override%0A    public boolean onOptionsItemSelected(MenuItem item) %7B%0A        switch (item.getItemId()) %7B%0A            case android.R.id.home:%0A                onBackPressed();%0A                break;%0A        %7D%0A        return super.onOptionsItemSelected(item);%0A    %7D%0A%0A
     class Vi
@@ -3092,67 +3092,26 @@
     
-return mFragmentTitleList.get(position);
 // add 
+null 
 return
- null;
  to 
@@ -3141,457 +3141,66 @@
     
-%7D%0A
     
-%7D%0A%0A%0A    @Override%0A    public boolean onCreateOptionsMenu(Menu menu) %7B%0A        // Inflate the menu; this adds items to the action bar if it is present.%0A        return true;%0A    %7D%0A%0A    @Override%0A    public boolean onOptionsItemSelected(MenuItem item) %7B%0A        switch (item.getItemId()) %7B%0A            case android.R.id.home:%0A                onBackPressed();%0A                break;%0A        %7D%0A        return super.onOptionsItemSelected(item);%0A    %7D%0A
+return mFragmentTitleList.get(position);%0A        %7D%0A    %7D
 %0A%7D

remove file check from hide apps activity