Search in sources :

Example 1 with UserProfile

use of org.mazhuang.guanggoo.data.entity.UserProfile in project guanggoo-android by mzlogin.

the class UserProfilePresenter method getUserProfile.

@Override
public void getUserProfile(String url) {
    mView.startLoading();
    NetworkTaskScheduler.getInstance().execute(new GetUserProfileTask(url, new OnResponseListener<UserProfile>() {

        @Override
        public void onSucceed(UserProfile data) {
            mView.stopLoading();
            mView.onGetUserProfileSucceed(data);
        }

        @Override
        public void onFailed(String msg) {
            mView.stopLoading();
            mView.onGetUserProfileFailed(msg);
        }
    }));
}
Also used : GetUserProfileTask(org.mazhuang.guanggoo.data.task.GetUserProfileTask) OnResponseListener(org.mazhuang.guanggoo.data.OnResponseListener) UserProfile(org.mazhuang.guanggoo.data.entity.UserProfile)

Example 2 with UserProfile

use of org.mazhuang.guanggoo.data.entity.UserProfile in project guanggoo-android by mzlogin.

the class GetUserProfileTask method run.

@Override
public void run() {
    Document doc;
    try {
        doc = get(mUrl);
    } catch (IOException e) {
        e.printStackTrace();
        failedOnUI(e.getMessage());
        return;
    }
    Elements userProfileElements = doc.select("div.user-page .profile");
    if (userProfileElements.isEmpty()) {
        failedOnUI("获取用户资料失败");
        return;
    }
    Elements headerElements = userProfileElements.select("div.ui-header");
    if (headerElements.isEmpty()) {
        failedOnUI("获取用户资料失败");
        return;
    }
    UserProfile profile = new UserProfile();
    profile.setUrl(mUrl);
    profile.setAvatar(headerElements.select("img.avatar").attr("src"));
    profile.setUsername(headerElements.select("div.username").text());
    profile.setNumber(headerElements.select("div.user-number .number").text());
    profile.setSince(headerElements.select("div.user-number .since").text());
    if (profile.isValid()) {
        successOnUI(profile);
    } else {
        failedOnUI("获取用户资料出错");
    }
}
Also used : UserProfile(org.mazhuang.guanggoo.data.entity.UserProfile) IOException(java.io.IOException) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements)

Aggregations

UserProfile (org.mazhuang.guanggoo.data.entity.UserProfile)2 IOException (java.io.IOException)1 Document (org.jsoup.nodes.Document)1 Elements (org.jsoup.select.Elements)1 OnResponseListener (org.mazhuang.guanggoo.data.OnResponseListener)1 GetUserProfileTask (org.mazhuang.guanggoo.data.task.GetUserProfileTask)1