Ejemplo n.º 1
0
  private void loadUser() {
    if (Session.getInstance().getUser() == null) {
      if (shouldSignIn()) {
        RequestToken.getRequestToken(
            new DefaultCallback<RequestToken>(context) {
              @Override
              public void onModel(RequestToken model) {
                if (canceled) return;
                Session.getInstance().setRequestToken(model);
                Config config = Session.getInstance().getConfig();
                User.findOrCreate(
                    config.getEmail(),
                    config.getName(),
                    config.getGuid(),
                    new DefaultCallback<AccessTokenResult<User>>(context) {
                      public void onModel(AccessTokenResult<User> model) {
                        if (canceled) return;
                        Session.getInstance().setAccessToken(context, model.getAccessToken());
                        Session.getInstance().setUser(model.getModel());
                        done();
                      }

                      @Override
                      public void onError(RestResult error) {
                        if (error.getType().equals("unauthorized")) {
                          done();
                        } else {
                          super.onError(error);
                        }
                      }
                    });
              }
            });
      } else {
        AccessToken accessToken =
            BaseModel.load(
                Session.getInstance().getSharedPreferences(),
                "access_token",
                "access_token",
                AccessToken.class);
        if (accessToken != null) {
          Session.getInstance().setAccessToken(accessToken);
          User.loadCurrentUser(
              new DefaultCallback<User>(context) {
                @Override
                public void onModel(User model) {
                  Session.getInstance().setUser(model);
                  done();
                }
              });
        } else {
          done();
        }
      }
    } else {
      done();
    }
  }
Ejemplo n.º 2
0
 @Override
 public void load(JSONObject jSONObject) throws JSONException {
   super.load(jSONObject);
   this.title = this.getString(jSONObject, "question");
   this.html = this.getHtml(jSONObject, "answer_html");
   if (jSONObject.has("normalized_weight")) {
     this.weight = jSONObject.getInt("normalized_weight");
   }
   if (!jSONObject.isNull("topic")) {
     this.topicName = jSONObject.getJSONObject("topic").getString("name");
   }
 }
Ejemplo n.º 3
0
 @Override
 public void load(JSONObject jSONObject) throws JSONException {
   super.load(jSONObject);
   this.name = this.getString(jSONObject, "name");
   this.numberOfArticles = jSONObject.getInt("article_count");
 }