Esempio n. 1
0
  public static void loadPageForTopic(int n2, int n3, final Callback<List<Article>> callback) {
    HashMap<String, String> hashMap = new HashMap<String, String>();
    hashMap.put("sort", "ordered");
    hashMap.put("per_page", "50");
    hashMap.put("page", String.valueOf(n3));
    Article.doGet(
        Article.apiPath("/topics/%d/articles.json", n2),
        hashMap,
        new RestTaskCallback(callback) {

          @Override
          public void onComplete(JSONObject jSONObject) throws JSONException {
            callback.onModel(BaseModel.deserializeList(jSONObject, "articles", Article.class));
          }
        });
  }
  private void loadTopics() {
    final DefaultCallback<List<Article>> articlesCallback =
        new DefaultCallback<List<Article>>(context) {
          @Override
          public void onModel(List<Article> model) {
            Session.getInstance().setTopics(new ArrayList<Topic>());
            articles = model;
            notifyDataSetChanged();
          }
        };

    if (Session.getInstance().getConfig(context).getTopicId() != -1) {
      Article.loadPageForTopic(
          context, Session.getInstance().getConfig(context).getTopicId(), 1, articlesCallback);
    } else {
      Topic.loadTopics(
          context,
          new DefaultCallback<List<Topic>>(context) {
            @Override
            public void onModel(List<Topic> model) {
              if (model.isEmpty()) {
                Session.getInstance().setTopics(model);
                Article.loadPage(context, 1, articlesCallback);
              } else {
                ArrayList<Topic> topics = new ArrayList<Topic>(model);
                topics.add(Topic.allArticlesTopic(context));
                Session.getInstance().setTopics(topics);
                notifyDataSetChanged();
              }
            }
          });
    }
  }
Esempio n. 3
0
  public static RestTask loadInstantAnswers(
      String string2, final Callback<List<BaseModel>> callback) {
    HashMap<String, String> hashMap = new HashMap<String, String>();
    hashMap.put("per_page", "3");
    hashMap.put("forum_id", String.valueOf(Article.getConfig().getForumId()));
    hashMap.put("query", string2);
    if (Article.getConfig().getTopicId() != -1) {
      hashMap.put("topic_id", String.valueOf(Article.getConfig().getTopicId()));
    }
    return Article.doGet(
        Article.apiPath("/instant_answers/search.json", new Object[0]),
        hashMap,
        new RestTaskCallback(callback) {

          @Override
          public void onComplete(JSONObject jSONObject) throws JSONException {
            callback.onModel(BaseModel.deserializeHeterogenousList(jSONObject, "instant_answers"));
          }
        });
  }
 protected void onButtonTapped() {
   if (state == State.INIT) {
     String query = textField.getText().toString().trim();
     if (query.length() == 0) return;
     state = State.INIT_LOADING;
     notifyDataSetChanged();
     Deflection.setSearchText(query);
     Article.loadInstantAnswers(
         query,
         new DefaultCallback<List<BaseModel>>(context) {
           @Override
           public void onModel(List<BaseModel> model) {
             List<BaseModel> results = model.subList(0, Math.min(model.size(), 3));
             Deflection.trackSearchDeflection(results, deflectingType);
             instantAnswers = model;
             if (instantAnswers.isEmpty()) state = State.DETAILS;
             else state = State.INSTANT_ANSWERS;
             notifyDataSetChanged();
           }
         });
   } else if (state == State.INSTANT_ANSWERS) {
     state = State.DETAILS;
     notifyDataSetChanged();
   } else if (state == State.DETAILS) {
     String name = nameField.getText().toString();
     String email = emailField.getText().toString();
     if (email.length() == 0) {
       AlertDialog.Builder builder = new AlertDialog.Builder(context);
       builder.setTitle(R.string.uv_error);
       builder.setMessage(R.string.uv_msg_user_identity_validation);
       builder.create().show();
     } else {
       Session.getInstance().persistIdentity(name, email);
       doSubmit();
     }
   }
 }
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    View view = convertView;
    int type = getItemViewType(position);
    if (view == null) {
      if (type == LOADING) view = inflater.inflate(R.layout.uv_loading_item, null);
      else if (type == FORUM) view = inflater.inflate(R.layout.uv_text_item, null);
      else if (type == KB_HEADER) view = inflater.inflate(R.layout.uv_header_item_light, null);
      else if (type == TOPIC) view = inflater.inflate(R.layout.uv_text_item, null);
      else if (type == CONTACT) view = inflater.inflate(R.layout.uv_text_item, null);
      else if (type == ARTICLE) view = inflater.inflate(R.layout.uv_text_item, null);
      else if (type == POWERED_BY) view = inflater.inflate(R.layout.uv_powered_by_item, null);
    }

    if (type == FORUM) {
      TextView textView = (TextView) view.findViewById(R.id.uv_text);
      textView.setText(R.string.uv_feedback_forum);
      TextView text2 = (TextView) view.findViewById(R.id.uv_text2);
      text2.setText(
          Utils.getQuantityString(
              text2,
              R.plurals.uv_ideas,
              Session.getInstance().getForum().getNumberOfOpenSuggestions()));
    } else if (type == KB_HEADER) {
      TextView textView = (TextView) view.findViewById(R.id.uv_header_text);
      textView.setText(R.string.uv_knowledge_base);
    } else if (type == TOPIC) {
      Topic topic = (Topic) getItem(position);
      TextView textView = (TextView) view.findViewById(R.id.uv_text);
      textView.setText(topic.getName());
      textView = (TextView) view.findViewById(R.id.uv_text2);
      if (topic.getId() == -1) {
        textView.setVisibility(View.GONE);
      } else {
        textView.setVisibility(View.VISIBLE);
        textView.setText(
            String.format(
                "%d %s",
                topic.getNumberOfArticles(),
                context
                    .getResources()
                    .getQuantityString(R.plurals.uv_articles, topic.getNumberOfArticles())));
      }
    } else if (type == CONTACT) {
      TextView textView = (TextView) view.findViewById(R.id.uv_text);
      textView.setText(R.string.uv_contact_us);
      view.findViewById(R.id.uv_text2).setVisibility(View.GONE);
    } else if (type == ARTICLE) {
      TextView textView = (TextView) view.findViewById(R.id.uv_text);
      Article article = (Article) getItem(position);
      textView.setText(article.getTitle());
    } else if (type == POWERED_BY) {
      TextView textView = (TextView) view.findViewById(R.id.uv_version);
      textView.setText(context.getString(R.string.uv_android_sdk) + " v" + UserVoice.getVersion());
    }

    View divider = view.findViewById(R.id.uv_divider);
    if (divider != null)
      divider.setVisibility(
          (position == getCount() - 2 && getItemViewType(getCount() - 1) == POWERED_BY)
                  || position == getCount() - 1
              ? View.GONE
              : View.VISIBLE);
    if (type == FORUM) divider.setVisibility(View.GONE);

    return view;
  }