<commit_before>package in.testpress.testpress.core;

import android.content.Context;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import in.testpress.testpress.TestpressApplication;
import in.testpress.testpress.models.Category;
import in.testpress.testpress.models.CategoryDao;
import in.testpress.testpress.models.DaoSession;
import in.testpress.testpress.models.Post;
import in.testpress.testpress.models.PostDao;
import in.testpress.testpress.models.TestpressApiResponse;
import in.testpress.testpress.util.Ln;
import retrofit.RetrofitError;


public class PostsPager extends ResourcePager<Post> {

    TestpressApiResponse<Post> response;

    public PostsPager(TestpressService service, Context context) {
        super(service);
    }

    @Override
    public ResourcePager<Post> clear() {
        response = null;
        super.clear();
        return this;
    }

    @Override
    protected Object getId(Post resource) {
        return resource.getId();
    }

    @Override
    public List<Post> getItems(int page, int size) throws RetrofitError {
        String url;
        if (response == null) {
            url = Constants.Http.URL_POSTS_FRAG;
        } else {
            try {
                URL full = new URL(response.getNext());
                url = full.getFile().substring(1);
            } catch (MalformedURLException e) {
                e.printStackTrace();
                url = null;
            }
        }
        if (url != null) {
            response = service.getPosts(url, queryParams);
            return response.getResults();
        }
        return Collections.emptyList();
    }

    @Override
    public boolean next() throws IOException {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
        boolean emptyPage = false;
        networkFail = false;
        try {
            for (int i = 0; i < count && hasNext(); i++) {
                Ln.d("PostsPager Getting Items");
                List<Post> resourcePage = getItems(page, -1);
                Ln.d("PostsPager Items Received");
                emptyPage = resourcePage.isEmpty();
                if (emptyPage)
                    break;
                Ln.d("Looping through resources");<commit_msg>Fix date created display in Posts list<commit_after>package in.testpress.testpress.core;

import android.content.Context;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.TimeZone;

import in.testpress.testpress.TestpressApplication;
import in.testpress.testpress.models.Category;
import in.testpress.testpress.models.CategoryDao;
import in.testpress.testpress.models.DaoSession;
import in.testpress.testpress.models.Post;
import in.testpress.testpress.models.PostDao;
import in.testpress.testpress.models.TestpressApiResponse;
import in.testpress.testpress.util.Ln;
import retrofit.RetrofitError;


public class PostsPager extends ResourcePager<Post> {

    TestpressApiResponse<Post> response;

    public PostsPager(TestpressService service, Context context) {
        super(service);
    }

    @Override
    public ResourcePager<Post> clear() {
        response = null;
        super.clear();
        return this;
    }

    @Override
    protected Object getId(Post resource) {
        return resource.getId();
    }

    @Override
    public List<Post> getItems(int page, int size) throws RetrofitError {
        String url;
        if (response == null) {
            url = Constants.Http.URL_POSTS_FRAG;
        } else {
            try {
                URL full = new URL(response.getNext());
                url = full.getFile().substring(1);
            } catch (MalformedURLException e) {
                e.printStackTrace();
                url = null;
            }
        }
        if (url != null) {
            response = service.getPosts(url, queryParams);
            return response.getResults();
        }
        return Collections.emptyList();
    }

    @Override
    public boolean next() throws IOException {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
        simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));

        boolean emptyPage = false;
        networkFail = false;
        try {
            for (int i = 0; i < count && hasNext(); i++) {
                Ln.d("PostsPager Getting Items");
                List<Post> resourcePage = getItems(page, -1);
                Ln.d("PostsPager Items Received");
                emptyPage = resourcePage.isEmpty();
                if (emptyPage)
                    break;
                Ln.d("Looping through resources");
{'fraction_non_alphanumeric': 0.10215482841181166, 'fraction_numerical': 0.0011971268954509178, 'mean_word_length': 2.4453608247422682, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3870533', 'n_tokens_mistral': 1425, 'n_tokens_neox': 1376, 'n_words': 306}