Search in sources :

Example 1 with Post

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

the class PostActivity method updateCommentsCount.

@SuppressLint("DefaultLocale")
void updateCommentsCount(int count) {
    List<Post> posts = postDao.queryBuilder().where(PostDao.Properties.Id.eq(post.getId())).list();
    if (!posts.isEmpty()) {
        Post post = posts.get(0);
        post.setCommentsCount(count);
        post.update();
    }
    post.setCommentsCount(count);
}
Also used : Post(in.testpress.testpress.models.Post) SuppressLint(android.annotation.SuppressLint)

Example 2 with Post

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

the class PostActivity method onCreate.

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.post_details_layout);
    Injector.inject(this);
    ButterKnife.inject(this);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    postDetails.setVisibility(View.GONE);
    progressBar.getIndeterminateDrawable().setColorFilter(getResources().getColor(R.color.primary), PorterDuff.Mode.SRC_IN);
    postDao = ((TestpressApplication) getApplicationContext()).getDaoSession().getPostDao();
    simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
    simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
    shortWebUrl = getIntent().getStringExtra(SHORT_WEB_URL);
    progressDialog = new ProgressDialog(this);
    progressDialog.setMessage(getResources().getString(R.string.please_wait));
    progressDialog.setCancelable(false);
    in.testpress.util.UIUtils.setIndeterminateDrawable(this, progressDialog, 4);
    ViewUtils.setTypeface(new TextView[] { loadPreviousCommentsText, commentsLabel, loadNewCommentsText, title }, TestpressSdk.getRubikMediumFont(this));
    ViewUtils.setTypeface(new TextView[] { date, summary, commentsEmptyView, commentsEditText }, TestpressSdk.getRubikRegularFont(this));
    if (shortWebUrl != null) {
        List<Post> posts = postDao.queryBuilder().where(PostDao.Properties.Short_web_url.eq(shortWebUrl)).list();
        if (!posts.isEmpty()) {
            post = posts.get(0);
            if (post.getContentHtml() != null) {
                displayPost(post);
                return;
            }
        }
        // If there is no post in this url in db or
        // If it content_html is null then fetch the post
        fetchPost();
    } else {
        setEmptyText(R.string.invalid_post, R.string.try_after_sometime, R.drawable.ic_error_outline_black_18dp);
    }
}
Also used : Post(in.testpress.testpress.models.Post) ProgressDialog(android.app.ProgressDialog) SimpleDateFormat(java.text.SimpleDateFormat) TestpressApplication(in.testpress.testpress.TestpressApplication)

Example 3 with Post

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

the class PostsListFragment method initOldPostLoadingPager.

void initOldPostLoadingPager() {
    pager = new PostsPager(getTestpressService(), null);
    pager.setQueryParams("order", "-published_date");
    Post lastPost = postDao.queryBuilder().orderDesc(PostDao.Properties.Published).list().get((int) postDao.count() - 1);
    pager.setQueryParams("until", lastPost.getPublishedDate());
    pager.setLatestModifiedDate(null);
}
Also used : Post(in.testpress.testpress.models.Post) PostsPager(in.testpress.testpress.core.PostsPager)

Example 4 with Post

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

the class PostsListFragment method initRefreshPager.

void initRefreshPager() {
    if (refreshPager == null) {
        refreshPager = new PostsPager(getTestpressService(), postDao);
        refreshPager.setQueryParams("order", "-published_date");
        if (postDao.count() > 0) {
            Post latest = postDao.queryBuilder().orderDesc(PostDao.Properties.ModifiedDate).list().get(0);
            refreshPager.setLatestModifiedDate(latest.getModified());
            LogLatestPostModifiedDate(latest);
            LogAllPosts();
        }
    }
}
Also used : Post(in.testpress.testpress.models.Post) PostsPager(in.testpress.testpress.core.PostsPager)

Example 5 with Post

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

the class PostsListFragment method writeToDB.

protected void writeToDB(List<Post> posts) {
    // Insert the categories and posts to the database
    List<Category> categories = new ArrayList<Category>();
    for (Post post : posts) {
        if (post.category != null) {
            Ln.e("Post category for " + post.getTitle() + " is " + post.category.getName());
            categories.add(post.category);
        } else {
            Ln.e("Post category for " + post.getTitle() + " is null");
        }
    }
    categoryDao.insertOrReplaceInTx(categories);
    postDao.insertOrReplaceInTx(posts);
    LogAllPosts();
}
Also used : Category(in.testpress.testpress.models.Category) Post(in.testpress.testpress.models.Post) ArrayList(java.util.ArrayList)

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