Android Open Source - Simple-Dilbert Dilbert Fragment Adapter






From Project

Back to project page Simple-Dilbert.

License

The source code is released under:

Apache License

If you think the Android project Simple-Dilbert listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.mareksebera.simpledilbert.core;
/*from w  w w.  ja  v a 2s .co m*/
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import com.mareksebera.simpledilbert.preferences.DilbertPreferences;

import org.joda.time.Days;
import org.joda.time.LocalDate;

final class DilbertFragmentAdapter extends FragmentPagerAdapter {

    @Override
    public CharSequence getPageTitle(int position) {
        return getDateForPosition(position).toString(
                DilbertPreferences.NICE_DATE_FORMATTER);
    }

    public DilbertFragmentAdapter(FragmentManager fm) {
        super(fm);
        this.countCache = Days.daysBetween(
                DilbertPreferences.getFirstStripDate(),
                LocalDate.now()).getDays() + 1;
    }

    @Override
    public Fragment getItem(int position) {
        Fragment f = new DilbertFragment();
        Bundle bundle = new Bundle();
        bundle.putString(
                DilbertFragment.ARGUMENT_DATE,
                getDateForPosition(position).toString(
                        DilbertPreferences.DATE_FORMATTER));
        f.setArguments(bundle);
        return f;
    }

    public LocalDate getDateForPosition(int position) {
        return LocalDate.now().minusDays(
                (getCount() - position) - 1);
    }

    private int countCache = 0;

    @Override
    public int getCount() {
        return countCache;
    }

    public int getPositionForDate(LocalDate date) {
        return getCount()
                - Days.daysBetween(date,
                LocalDate.now())
                .plus(Days.ONE).getDays();
    }

}




Java Source Code List

com.mareksebera.simpledilbert.AppController.java
com.mareksebera.simpledilbert.core.DilbertFragmentActivity.java
com.mareksebera.simpledilbert.core.DilbertFragmentAdapter.java
com.mareksebera.simpledilbert.core.DilbertFragmentInterface.java
com.mareksebera.simpledilbert.core.DilbertFragment.java
com.mareksebera.simpledilbert.favorites.DilbertFavoritedActivity.java
com.mareksebera.simpledilbert.favorites.DilbertFavoritedFragmentAdapter.java
com.mareksebera.simpledilbert.favorites.FavoritedItem.java
com.mareksebera.simpledilbert.picker.FolderPickerActivity.java
com.mareksebera.simpledilbert.picker.FolderPickerAdapter.java
com.mareksebera.simpledilbert.picker.FolderPickerFragment.java
com.mareksebera.simpledilbert.preferences.DilbertPreferencesActivity.java
com.mareksebera.simpledilbert.preferences.DilbertPreferences.java
com.mareksebera.simpledilbert.utilities.ActionBarUtility.java
com.mareksebera.simpledilbert.utilities.DownloadManagerBroadcastReceiver.java
com.mareksebera.simpledilbert.utilities.FailSafeBitmapDisplayer.java
com.mareksebera.simpledilbert.utilities.FindUrls.java
com.mareksebera.simpledilbert.utilities.FixedViewPager.java
com.mareksebera.simpledilbert.utilities.GetStripUrlInterface.java
com.mareksebera.simpledilbert.utilities.GetStripUrl.java
com.mareksebera.simpledilbert.widget.WidgetProvider.java