Search in sources :

Example 6 with Post

use of in.testpress.testpress.models.Post in project android by testpress.

the class PostsPager method next.

@Override
public boolean next() throws IOException {
    simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
    boolean emptyPage = 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");
            for (Post resource : resourcePage) {
                resource = register(resource);
                if (resource == null)
                    continue;
                if (resource.category != null) {
                    resource.setCategory(resource.category);
                }
                Ln.d("Category ID " + resource.getCategoryId());
                resource.setPublished(simpleDateFormat.parse(resource.getPublishedDate()).getTime());
                resource.setModifiedDate(simpleDateFormat.parse(resource.getModified()).getTime());
                resources.put(getId(resource), resource);
            }
            Ln.d("Looping resources over");
        }
        // Set page to count value if first call after call to reset()
        if (count > 1) {
            page = count;
            count = 1;
        }
        page++;
    } catch (ParseException e) {
        Ln.d("ParseException " + e);
    } catch (Exception e) {
        hasMore = false;
        throw e;
    }
    hasMore = hasNext() && !emptyPage;
    return hasMore;
}
Also used : Post(in.testpress.testpress.models.Post) ParseException(java.text.ParseException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ParseException(java.text.ParseException)

Example 7 with Post

use of in.testpress.testpress.models.Post in project android by testpress.

the class PostDao method loadCurrentDeep.

protected Post loadCurrentDeep(Cursor cursor, boolean lock) {
    Post entity = loadCurrent(cursor, 0, lock);
    int offset = getAllColumns().length;
    Category category = loadCurrentOther(daoSession.getCategoryDao(), cursor, offset);
    entity.setCategory(category);
    return entity;
}
Also used : Post(in.testpress.testpress.models.Post)

Example 8 with Post

use of in.testpress.testpress.models.Post in project android by testpress.

the class PostsListAdapter method getView.

@SuppressLint("SetTextI18n")
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    final Post post = getItem(position);
    Ln.d("PostsListAdapter getView at position " + position);
    Ln.d("PostsListAdapter getView post = " + post.getTitle());
    if (convertView == null) {
        convertView = activity.getLayoutInflater().inflate(layout, null);
    }
    TextView title = (TextView) convertView.findViewById(R.id.title);
    title.setText(post.getTitle());
    TextView date = (TextView) convertView.findViewById(R.id.date);
    date.setText(FormatDate.getAbbreviatedTimeSpan(post.getPublished()));
    TextView categoryView = (TextView) convertView.findViewById(R.id.category);
    View categoryLayout = convertView.findViewById(R.id.category_layout);
    if (post.getCategory() != null) {
        categoryView.setText(post.getCategory().getName());
        categoryLayout.setVisibility(View.VISIBLE);
    } else {
        categoryLayout.setVisibility(View.GONE);
    }
    convertView.findViewById(R.id.ripple_layout).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intent = new Intent(activity, PostActivity.class);
            intent.putExtra("shortWebUrl", post.getShort_web_url());
            activity.startActivity(intent);
        }
    });
    TextView commentsCount = (TextView) convertView.findViewById(R.id.comments_count);
    View commentsLayout = convertView.findViewById(R.id.comments_layout);
    if (post.getCommentsCount() == 0) {
        commentsLayout.setVisibility(View.INVISIBLE);
    } else {
        commentsCount.setText(post.getCommentsCount().toString());
        commentsLayout.setVisibility(View.VISIBLE);
    }
    title.setTypeface(TestpressSdk.getRubikMediumFont(activity));
    ViewUtils.setTypeface(new TextView[] { commentsCount, date, categoryView }, TestpressSdk.getRubikRegularFont(activity));
    return convertView;
}
Also used : Post(in.testpress.testpress.models.Post) TextView(android.widget.TextView) Intent(android.content.Intent) TextView(android.widget.TextView) View(android.view.View) SuppressLint(android.annotation.SuppressLint)

Aggregations

Post (in.testpress.testpress.models.Post)8 SuppressLint (android.annotation.SuppressLint)2 PostsPager (in.testpress.testpress.core.PostsPager)2 ProgressDialog (android.app.ProgressDialog)1 Intent (android.content.Intent)1 View (android.view.View)1 TextView (android.widget.TextView)1 TestpressApplication (in.testpress.testpress.TestpressApplication)1 Category (in.testpress.testpress.models.Category)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1