Search in sources :

Example 1 with StatsPostModel

use of org.wordpress.android.ui.stats.models.StatsPostModel in project WordPress-Android by wordpress-mobile.

the class PostsAndPagesAdapter method getView.

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View rowView = convertView;
    // reuse views
    if (rowView == null) {
        rowView = inflater.inflate(R.layout.stats_list_cell, parent, false);
        // configure view holder
        StatsViewHolder viewHolder = new StatsViewHolder(rowView);
        rowView.setTag(viewHolder);
    }
    final StatsPostModel currentRowData = list.get(position);
    StatsViewHolder holder = (StatsViewHolder) rowView.getTag();
    // Entry
    holder.setEntryTextOpenDetailsPage(currentRowData);
    // Setup the more button
    holder.setMoreButtonOpenInReader(currentRowData);
    // totals
    holder.totalsTextView.setText(FormatUtils.formatDecimal(currentRowData.getTotals()));
    // no icon
    holder.networkImageView.setVisibility(View.GONE);
    return rowView;
}
Also used : StatsPostModel(org.wordpress.android.ui.stats.models.StatsPostModel) StatsViewHolder(org.wordpress.android.ui.stats.StatsViewHolder) View(android.view.View)

Example 2 with StatsPostModel

use of org.wordpress.android.ui.stats.models.StatsPostModel in project WordPress-Android by wordpress-mobile.

the class RemoteTests method testTopPost.

public void testTopPost() throws Exception {
    StatsRestRequestAbstractListener listener = new StatsRestRequestAbstractListener() {

        @Override
        void parseResponse(JSONObject response) throws JSONException {
            TopPostsAndPagesModel model = new TopPostsAndPagesModel(123456, response);
            assertNotNull(model.getTopPostsAndPages());
            assertEquals(model.getTopPostsAndPages().size(), 10);
            StatsPostModel postModel = model.getTopPostsAndPages().get(0);
            assertEquals(postModel.getItemID(), "39806");
            assertEquals(postModel.getTotals(), 2420);
            assertEquals(postModel.getTitle(), "Home");
            assertEquals(postModel.getUrl(), "http://automattic.com/home/");
            assertEquals(postModel.getDate(), StatsUtils.toMs("2011-08-30 21:47:38"));
            assertEquals(postModel.getPostType(), "page");
            postModel = model.getTopPostsAndPages().get(9);
            assertEquals(postModel.getItemID(), "39254");
            assertEquals(postModel.getTotals(), 56);
            assertEquals(postModel.getTitle(), "Growth Explorer");
            assertEquals(postModel.getUrl(), "http://automattic.com/work-with-us/growth-explorer/");
            assertEquals(postModel.getDate(), StatsUtils.toMs("2011-08-25 19:37:27"));
            assertEquals(postModel.getPostType(), "page");
        }
    };
    mRestClient.makeRequest(Request.Method.POST, "https://public-api.wordpress.com/rest/v1.1/sites/123456/stats/top-posts", null, listener, errListener);
}
Also used : StatsPostModel(org.wordpress.android.ui.stats.models.StatsPostModel) JSONObject(org.json.JSONObject) TopPostsAndPagesModel(org.wordpress.android.ui.stats.models.TopPostsAndPagesModel)

Example 3 with StatsPostModel

use of org.wordpress.android.ui.stats.models.StatsPostModel in project WordPress-Android by wordpress-mobile.

the class ActivityLauncher method viewStatsSinglePostDetails.

public static void viewStatsSinglePostDetails(Context context, SiteModel site, PostModel post, boolean isPage) {
    if (post == null)
        return;
    StatsPostModel statsPostModel = new StatsPostModel(site.getSiteId(), String.valueOf(post.getRemotePostId()), post.getTitle(), post.getLink(), isPage ? StatsConstants.ITEM_TYPE_PAGE : StatsConstants.ITEM_TYPE_POST);
    viewStatsSinglePostDetails(context, statsPostModel);
}
Also used : StatsPostModel(org.wordpress.android.ui.stats.models.StatsPostModel)

Example 4 with StatsPostModel

use of org.wordpress.android.ui.stats.models.StatsPostModel in project WordPress-Android by wordpress-mobile.

the class RemoteTests method testTopPostEmptyURL.

public void testTopPostEmptyURL() throws Exception {
    StatsRestRequestAbstractListener listener = new StatsRestRequestAbstractListener() {

        @Override
        void parseResponse(JSONObject response) throws JSONException {
            TopPostsAndPagesModel model = new TopPostsAndPagesModel(1234567890, response);
            assertNotNull(model.getTopPostsAndPages());
            assertEquals(model.getTopPostsAndPages().size(), 10);
            StatsPostModel postModel = model.getTopPostsAndPages().get(0);
            assertEquals(postModel.getItemID(), "750");
            assertEquals(postModel.getTotals(), 7);
            assertEquals(postModel.getTitle(), "Asynchronous unit testing Core Data with Xcode 6");
            // This post has no URL?!? Unpublished post that was prev published?
            assertEquals(postModel.getUrl(), "");
            assertEquals(postModel.getDate(), StatsUtils.toMs("2014-08-06 14:52:11"));
            assertEquals(postModel.getPostType(), "post");
        }
    };
    mRestClient.makeRequest(Request.Method.POST, "https://public-api.wordpress.com/rest/v1.1/sites/1234567890/stats/top-posts", null, listener, errListener);
}
Also used : StatsPostModel(org.wordpress.android.ui.stats.models.StatsPostModel) JSONObject(org.json.JSONObject) TopPostsAndPagesModel(org.wordpress.android.ui.stats.models.TopPostsAndPagesModel)

Example 5 with StatsPostModel

use of org.wordpress.android.ui.stats.models.StatsPostModel in project WordPress-Android by wordpress-mobile.

the class StatsTopPostsAndPagesFragment method updateUI.

@Override
protected void updateUI() {
    if (!isAdded()) {
        return;
    }
    if (hasTopPostsAndPages()) {
        List<StatsPostModel> postViews = mTopPostsAndPagesModel.getTopPostsAndPages();
        ArrayAdapter adapter = new PostsAndPagesAdapter(getActivity(), postViews);
        StatsUIHelper.reloadLinearLayout(getActivity(), adapter, mList, getMaxNumberOfItemsToShowInList());
        showHideNoResultsUI(false);
    } else {
        showHideNoResultsUI(true);
    }
}
Also used : StatsPostModel(org.wordpress.android.ui.stats.models.StatsPostModel) ArrayAdapter(android.widget.ArrayAdapter) PostsAndPagesAdapter(org.wordpress.android.ui.stats.adapters.PostsAndPagesAdapter)

Aggregations

StatsPostModel (org.wordpress.android.ui.stats.models.StatsPostModel)5 JSONObject (org.json.JSONObject)2 TopPostsAndPagesModel (org.wordpress.android.ui.stats.models.TopPostsAndPagesModel)2 View (android.view.View)1 ArrayAdapter (android.widget.ArrayAdapter)1 StatsViewHolder (org.wordpress.android.ui.stats.StatsViewHolder)1 PostsAndPagesAdapter (org.wordpress.android.ui.stats.adapters.PostsAndPagesAdapter)1