Ejemplo n.º 1
0
  public static void loadTopic(int n2, final Callback<Topic> callback) {
    Topic.doGet(
        Topic.apiPath("/topics/%d.json", n2),
        new RestTaskCallback(callback) {

          @Override
          public void onComplete(JSONObject jSONObject) throws JSONException {
            callback.onModel(BaseModel.deserializeObject(jSONObject, "topic", Topic.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();
              }
            }
          });
    }
  }
Ejemplo n.º 3
0
  public static void loadTopics(final Callback<List<Topic>> callback) {
    Topic.doGet(
        Topic.apiPath("/topics.json", new Object[0]),
        new RestTaskCallback(callback) {

          @Override
          public void onComplete(JSONObject object) throws JSONException {
            Object object2 = BaseModel.deserializeList((JSONObject) object, "topics", Topic.class);
            object = new ArrayList(object2.size());
            object2 = object2.iterator();
            while (object2.hasNext()) {
              Topic topic = (Topic) object2.next();
              if (topic.getNumberOfArticles() <= 0) continue;
              object.add(topic);
            }
            callback.onModel(object);
          }
        });
  }
Ejemplo n.º 4
0
 public static Topic allArticlesTopic(Context context) {
   Topic allArticles = new Topic();
   allArticles.name = context.getString(R.string.uv_all_articles);
   allArticles.id = -1;
   return allArticles;
 }
  @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;
  }