/*
 * Kiwix Android
 * Copyright (C) 2018  Kiwix <android.kiwix.org>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
package org.kiwix.kiwixmobile.zim_manager;

import android.content.Context;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import org.kiwix.kiwixmobile.R;
import org.kiwix.kiwixmobile.downloader.DownloadFragment;
import org.kiwix.kiwixmobile.zim_manager.fileselect_view.ZimFileSelectFragment;
import org.kiwix.kiwixmobile.zim_manager.library_view.LibraryFragment;

/**
 * A {@link FragmentPagerAdapter} that returns a fragment corresponding to
 * one of the sections/tabs/pages.
 */
public class SectionsPagerAdapter extends FragmentPagerAdapter {

  public LibraryFragment libraryFragment = new LibraryFragment();
  private ZimFileSelectFragment zimFileSelectFragment = new ZimFileSelectFragment();
  private DownloadFragment downloadFragment = new DownloadFragment();

  private Context context;

  SectionsPagerAdapter(Context context, FragmentManager fm) {
    super(fm);
    this.context = context;
  }

  public DownloadFragment getDownloadFragment() {
    return downloadFragment;
  }

  @Override
  public Fragment getItem(int position) {
    // getItem is called to instantiate the fragment for the given page.
    switch (position) {
      case 0:
        return zimFileSelectFragment;
      case 1:
        return libraryFragment;
      case 2:
        return downloadFragment;
      default:
        return null;
    }
  }

  @Override
  public int getCount() {
    // Show 3 total pages.
    return 3;
  }

  @Override
  public CharSequence getPageTitle(int position) {
    switch (position) {
      case 0:
        return context.getResources().getString(R.string.local_zims);
      case 1:
        return context.getResources().getString(R.string.remote_zims);
      case 2:
        return context.getResources().getString(R.string.zim_downloads);
    }
    return null;
  }
}
