Search in sources :

Example 1 with FollowersModel

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

the class StatsFollowersFragment method updateUI.

@Override
protected void updateUI() {
    if (!isAdded()) {
        return;
    }
    if (!hasDataAvailable()) {
        showHideNoResultsUI(true);
        mTotalsLabel.setText(getTotalFollowersLabel(0));
        return;
    }
    mTotalsLabel.setVisibility(View.VISIBLE);
    final FollowersModel followersModel = getCurrentDataModel();
    if (followersModel != null && followersModel.getFollowers() != null && followersModel.getFollowers().size() > 0) {
        ArrayAdapter adapter = new DotComFollowerAdapter(getActivity(), followersModel.getFollowers());
        StatsUIHelper.reloadLinearLayout(getActivity(), adapter, mList, getMaxNumberOfItemsToShowInList());
        showHideNoResultsUI(false);
        if (mTopPagerSelectedButtonIndex == 0) {
            mTotalsLabel.setText(getTotalFollowersLabel(followersModel.getTotalWPCom()));
        } else {
            mTotalsLabel.setText(getTotalFollowersLabel(followersModel.getTotalEmail()));
        }
        if (isSingleView()) {
            if (followersModel.getPages() > 1) {
                mBottomPaginationContainer.setVisibility(View.VISIBLE);
                mTopPaginationContainer.setVisibility(View.VISIBLE);
                String paginationLabel = String.format(getString(R.string.stats_pagination_label), FormatUtils.formatDecimal(followersModel.getPage()), FormatUtils.formatDecimal(followersModel.getPages()));
                mBottomPaginationText.setText(paginationLabel);
                mTopPaginationText.setText(paginationLabel);
                setNavigationButtonsEnabled(true);
                // Setting up back buttons
                if (followersModel.getPage() == 1) {
                    // first page. No go back buttons
                    setNavigationBackButtonsVisibility(false);
                } else {
                    setNavigationBackButtonsVisibility(true);
                    View.OnClickListener clickListener = new View.OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            setNavigationButtonsEnabled(false);
                            refreshStats(followersModel.getPage() - 1, new StatsService.StatsEndpointsEnum[] { sectionsToUpdate()[mTopPagerSelectedButtonIndex] });
                        }
                    };
                    mBottomPaginationGoBackButton.setOnClickListener(clickListener);
                    mTopPaginationGoBackButton.setOnClickListener(clickListener);
                }
                // Setting up forward buttons
                if (followersModel.getPage() == followersModel.getPages()) {
                    // last page. No go forward buttons
                    setNavigationForwardButtonsVisibility(false);
                } else {
                    setNavigationForwardButtonsVisibility(true);
                    View.OnClickListener clickListener = new View.OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            setNavigationButtonsEnabled(false);
                            refreshStats(followersModel.getPage() + 1, new StatsService.StatsEndpointsEnum[] { sectionsToUpdate()[mTopPagerSelectedButtonIndex] });
                        }
                    };
                    mBottomPaginationGoForwardButton.setOnClickListener(clickListener);
                    mTopPaginationGoForwardButton.setOnClickListener(clickListener);
                }
                // Change the total number of followers label by adding the current paging info
                int startIndex = followersModel.getPage() * StatsService.MAX_RESULTS_REQUESTED_PER_PAGE - StatsService.MAX_RESULTS_REQUESTED_PER_PAGE + 1;
                int endIndex = startIndex + followersModel.getFollowers().size() - 1;
                String pagedLabel = getString(mTopPagerSelectedButtonIndex == 0 ? R.string.stats_followers_total_wpcom_paged : R.string.stats_followers_total_email_paged, startIndex, endIndex, FormatUtils.formatDecimal(mTopPagerSelectedButtonIndex == 0 ? followersModel.getTotalWPCom() : followersModel.getTotalEmail()));
                mTotalsLabel.setText(pagedLabel);
            } else {
                // No paging required. Hide the controls.
                mBottomPaginationContainer.setVisibility(View.GONE);
                mTopPaginationContainer.setVisibility(View.GONE);
            }
        }
    } else {
        showHideNoResultsUI(true);
        mBottomPaginationContainer.setVisibility(View.GONE);
        mTotalsLabel.setText(getTotalFollowersLabel(0));
    }
    // Always visible. Even if the current tab is empty, otherwise the user can't switch tab
    mTopPagerContainer.setVisibility(View.VISIBLE);
}
Also used : FollowersModel(org.wordpress.android.ui.stats.models.FollowersModel) StatsService(org.wordpress.android.ui.stats.service.StatsService) WPNetworkImageView(org.wordpress.android.widgets.WPNetworkImageView) View(android.view.View) ArrayAdapter(android.widget.ArrayAdapter)

Example 2 with FollowersModel

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

the class RemoteTests method testFollowersEmail.

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

        @Override
        void parseResponse(JSONObject response) throws JSONException {
            FollowersModel model = new FollowersModel(123456, response);
            assertEquals(model.getTotalEmail(), 2931);
            assertEquals(model.getTotalWPCom(), 7926165);
            assertEquals(model.getTotal(), 2931);
            assertEquals(model.getPage(), 1);
            assertEquals(model.getPages(), 419);
            assertNotNull(model.getFollowers());
            assertEquals(model.getFollowers().size(), 7);
            FollowerModel first = model.getFollowers().get(0);
            assertEquals(first.getAvatar(), "https://2.gravatar.com/avatar/e82142697283897ad7444810e5975895?s=64" + "&d=https%3A%2F%2F2.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D64&r=G");
            assertEquals(first.getLabel(), "user1@example.com");
            assertNull(first.getURL());
            assertNull(first.getFollowData());
            assertEquals(first.getDateSubscribed(), "2014-12-16T11:24:41+00:00");
            FollowerModel last = model.getFollowers().get(6);
            assertEquals(last.getAvatar(), "https://0.gravatar.com/avatar/3b37f38b63ce4f595cc5cfbaadb10938?s=64" + "&d=https%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D64&r=G");
            assertEquals(last.getLabel(), "user7@example.com");
            assertNull(last.getURL());
            assertNull(last.getFollowData());
            assertEquals(last.getDateSubscribed(), "2014-12-15T15:09:01+00:00");
        }
    };
    mRestClient.makeRequest(Request.Method.POST, "https://public-api.wordpress.com/rest/v1.1/sites/123456/stats/followers", null, listener, errListener);
}
Also used : FollowersModel(org.wordpress.android.ui.stats.models.FollowersModel) FollowerModel(org.wordpress.android.ui.stats.models.FollowerModel) JSONObject(org.json.JSONObject)

Example 3 with FollowersModel

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

the class RemoteTests method testFollowersWPCOM.

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

        @Override
        void parseResponse(JSONObject response) throws JSONException {
            FollowersModel model = new FollowersModel(1234567890, response);
            assertEquals(model.getTotalEmail(), 2930);
            assertEquals(model.getTotalWPCom(), 7925800);
            assertEquals(model.getTotal(), 7925800);
            assertEquals(model.getPage(), 1);
            assertEquals(model.getPages(), 1132258);
            assertNotNull(model.getFollowers());
            assertEquals(model.getFollowers().size(), 7);
            FollowerModel first = model.getFollowers().get(0);
            assertEquals(first.getAvatar(), "https://0.gravatar.com/avatar/624b89cb0c8b9136f9629dd7bcab0517?s=64" + "&d=https%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D64&r=G");
            assertEquals(first.getLabel(), "ritu929");
            assertEquals(first.getURL(), "http://ritu9blog.wordpress.com");
            assertEquals(first.getDateSubscribed(), "2014-12-16T14:53:21+00:00");
            assertNotNull(first.getFollowData());
            FollowDataModel followDatamodel = first.getFollowData();
            assertFalse(followDatamodel.isFollowing());
            assertEquals(followDatamodel.getType(), "follow");
        }
    };
    mRestClient.makeRequest(Request.Method.POST, "https://public-api.wordpress.com/rest/v1.1/sites/1234567890/stats/followers", null, listener, errListener);
}
Also used : FollowersModel(org.wordpress.android.ui.stats.models.FollowersModel) FollowerModel(org.wordpress.android.ui.stats.models.FollowerModel) JSONObject(org.json.JSONObject) FollowDataModel(org.wordpress.android.ui.stats.models.FollowDataModel)

Aggregations

FollowersModel (org.wordpress.android.ui.stats.models.FollowersModel)3 JSONObject (org.json.JSONObject)2 FollowerModel (org.wordpress.android.ui.stats.models.FollowerModel)2 View (android.view.View)1 ArrayAdapter (android.widget.ArrayAdapter)1 FollowDataModel (org.wordpress.android.ui.stats.models.FollowDataModel)1 StatsService (org.wordpress.android.ui.stats.service.StatsService)1 WPNetworkImageView (org.wordpress.android.widgets.WPNetworkImageView)1