Search in sources :

Example 1 with Person

use of org.wordpress.android.models.Person in project WordPress-Android by wordpress-mobile.

the class PeopleTable method getPersonFromCursor.

private static Person getPersonFromCursor(Cursor c, String table, int localTableBlogId) {
    long personId = c.getInt(c.getColumnIndex("person_id"));
    Person person = new Person(personId, localTableBlogId);
    person.setDisplayName(c.getString(c.getColumnIndex("display_name")));
    person.setAvatarUrl(c.getString(c.getColumnIndex("avatar_url")));
    switch(table) {
        case TEAM_TABLE:
            person.setUsername(c.getString(c.getColumnIndex("user_name")));
            String role = c.getString(c.getColumnIndex("role"));
            person.setRole(Role.fromString(role));
            person.setPersonType(Person.PersonType.USER);
            break;
        case FOLLOWERS_TABLE:
            person.setUsername(c.getString(c.getColumnIndex("user_name")));
            person.setSubscribed(c.getString(c.getColumnIndex("subscribed")));
            person.setPersonType(Person.PersonType.FOLLOWER);
            break;
        case EMAIL_FOLLOWERS_TABLE:
            person.setSubscribed(c.getString(c.getColumnIndex("subscribed")));
            person.setPersonType(Person.PersonType.EMAIL_FOLLOWER);
            break;
        case VIEWERS_TABLE:
            person.setUsername(c.getString(c.getColumnIndex("user_name")));
            person.setPersonType(Person.PersonType.VIEWER);
            break;
    }
    return person;
}
Also used : Person(org.wordpress.android.models.Person)

Example 2 with Person

use of org.wordpress.android.models.Person in project WordPress-Android by wordpress-mobile.

the class PeopleTable method getPeople.

private static List<Person> getPeople(String table, int localTableBlogId) {
    String[] args = { Integer.toString(localTableBlogId) };
    String orderBy;
    if (shouldOrderAlphabetically(table)) {
        orderBy = " ORDER BY lower(display_name), lower(user_name)";
    } else {
        // we want the server-side order for followers & viewers
        orderBy = " ORDER BY ROWID";
    }
    Cursor c = getReadableDb().rawQuery("SELECT * FROM " + table + " WHERE local_blog_id=?" + orderBy, args);
    List<Person> people = new ArrayList<>();
    try {
        while (c.moveToNext()) {
            Person person = getPersonFromCursor(c, table, localTableBlogId);
            people.add(person);
        }
    } finally {
        SqlUtils.closeCursor(c);
    }
    return people;
}
Also used : ArrayList(java.util.ArrayList) Cursor(android.database.Cursor) Person(org.wordpress.android.models.Person)

Example 3 with Person

use of org.wordpress.android.models.Person in project WordPress-Android by wordpress-mobile.

the class PeopleManagementActivity method confirmRemovePerson.

private void confirmRemovePerson() {
    Person person = getCurrentPerson();
    if (person == null) {
        return;
    }
    AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.Calypso_AlertDialog);
    builder.setTitle(getString(R.string.person_remove_confirmation_title, person.getDisplayName()));
    if (person.getPersonType() == Person.PersonType.USER) {
        builder.setMessage(getString(R.string.user_remove_confirmation_message, person.getDisplayName()));
    } else if (person.getPersonType() == Person.PersonType.VIEWER) {
        builder.setMessage(R.string.viewer_remove_confirmation_message);
    } else {
        builder.setMessage(R.string.follower_remove_confirmation_message);
    }
    builder.setNegativeButton(R.string.cancel, null);
    builder.setPositiveButton(R.string.remove, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            removeSelectedPerson();
        }
    });
    builder.show();
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) Person(org.wordpress.android.models.Person)

Example 4 with Person

use of org.wordpress.android.models.Person in project WordPress-Android by wordpress-mobile.

the class PersonDetailFragment method refreshPersonDetails.

public void refreshPersonDetails() {
    if (!isAdded())
        return;
    Person person = loadPerson();
    if (person != null) {
        int avatarSz = getResources().getDimensionPixelSize(R.dimen.people_avatar_sz);
        String avatarUrl = GravatarUtils.fixGravatarUrl(person.getAvatarUrl(), avatarSz);
        mAvatarImageView.setImageUrl(avatarUrl, WPNetworkImageView.ImageType.AVATAR);
        mDisplayNameTextView.setText(StringUtils.unescapeHTML(person.getDisplayName()));
        if (person.getRole() != null) {
            mRoleTextView.setText(StringUtils.capitalize(person.getRole().toDisplayString()));
        }
        if (!TextUtils.isEmpty(person.getUsername())) {
            mUsernameTextView.setText(String.format("@%s", person.getUsername()));
        }
        if (mPersonType == Person.PersonType.USER) {
            mRoleContainer.setVisibility(View.VISIBLE);
            setupRoleContainerForCapability();
        } else {
            mRoleContainer.setVisibility(View.GONE);
        }
        if (mPersonType == Person.PersonType.USER || mPersonType == Person.PersonType.VIEWER) {
            mSubscribedDateContainer.setVisibility(View.GONE);
        } else {
            mSubscribedDateContainer.setVisibility(View.VISIBLE);
            if (mPersonType == Person.PersonType.FOLLOWER) {
                mSubscribedDateTitleView.setText(R.string.title_follower);
            } else if (mPersonType == Person.PersonType.EMAIL_FOLLOWER) {
                mSubscribedDateTitleView.setText(R.string.title_email_follower);
            }
            String dateSubscribed = SimpleDateFormat.getDateInstance().format(person.getDateSubscribed());
            String dateText = getString(R.string.follower_subscribed_since, dateSubscribed);
            mSubscribedDateTextView.setText(dateText);
        }
        // Adds extra padding to display name for email followers to make it vertically centered
        int padding = mPersonType == Person.PersonType.EMAIL_FOLLOWER ? (int) getResources().getDimension(R.dimen.margin_small) : 0;
        changeDisplayNameTopPadding(padding);
    } else {
        AppLog.w(AppLog.T.PEOPLE, "Person returned null from DB for personID: " + mPersonId + " & localTableBlogID: " + mLocalTableBlogId);
    }
}
Also used : Person(org.wordpress.android.models.Person)

Example 5 with Person

use of org.wordpress.android.models.Person in project WordPress-Android by wordpress-mobile.

the class PeopleUtils method fetchFollowers.

private static void fetchFollowers(final SiteModel site, final int page, final FetchFollowersCallback callback, final boolean isEmailFollower) {
    com.wordpress.rest.RestRequest.Listener listener = new RestRequest.Listener() {

        @Override
        public void onResponse(JSONObject jsonObject) {
            if (jsonObject != null && callback != null) {
                try {
                    JSONArray jsonArray = jsonObject.getJSONArray("subscribers");
                    Person.PersonType personType = isEmailFollower ? Person.PersonType.EMAIL_FOLLOWER : Person.PersonType.FOLLOWER;
                    List<Person> people = peopleListFromJSON(jsonArray, site.getId(), personType);
                    int pageFetched = jsonObject.optInt("page");
                    int numberOfPages = jsonObject.optInt("pages");
                    boolean isEndOfList = page >= numberOfPages || page >= FOLLOWER_PAGE_LIMIT;
                    callback.onSuccess(people, pageFetched, isEndOfList);
                } catch (JSONException e) {
                    AppLog.e(T.API, "JSON exception occurred while parsing the response for " + "sites/%s/stats/followers: " + e);
                    callback.onError();
                }
            }
        }
    };
    RestRequest.ErrorListener errorListener = new RestRequest.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError volleyError) {
            AppLog.e(T.API, volleyError);
            if (callback != null) {
                callback.onError();
            }
        }
    };
    Map<String, String> params = new HashMap<>();
    params.put("max", Integer.toString(FETCH_LIMIT));
    params.put("page", Integer.toString(page));
    params.put("type", isEmailFollower ? "email" : "wp_com");
    String path = String.format(Locale.US, "sites/%d/stats/followers", site.getSiteId());
    WordPress.getRestClientUtilsV1_1().get(path, params, null, listener, errorListener);
}
Also used : VolleyError(com.android.volley.VolleyError) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) RestRequest(com.wordpress.rest.RestRequest) JSONObject(org.json.JSONObject) Person(org.wordpress.android.models.Person)

Aggregations

Person (org.wordpress.android.models.Person)11 VolleyError (com.android.volley.VolleyError)4 RestRequest (com.wordpress.rest.RestRequest)4 HashMap (java.util.HashMap)4 LinkedHashMap (java.util.LinkedHashMap)4 JSONException (org.json.JSONException)4 JSONObject (org.json.JSONObject)4 JSONArray (org.json.JSONArray)3 PeopleUtils (org.wordpress.android.ui.people.utils.PeopleUtils)2 AlertDialog (android.app.AlertDialog)1 DialogInterface (android.content.DialogInterface)1 Cursor (android.database.Cursor)1 ArrayList (java.util.ArrayList)1