Esempio n. 1
0
  /**
   * 加载技术类型数据 ( Android、iOS、前端、拓展资源、App )
   *
   * @param easyRecyclerViewHolder easyRecyclerViewHolder
   * @param position position
   */
  private void loadingTechnology(EasyRecyclerViewHolder easyRecyclerViewHolder, int position) {
    BaseGankData baseGankData = this.getItem(position);
    if (baseGankData == null) return;
    TextView dataDateTV = easyRecyclerViewHolder.findViewById(R.id.data_date_tv);
    TextView dataTitleTV = easyRecyclerViewHolder.findViewById(R.id.data_title_tv);
    TextView dataViaTV = easyRecyclerViewHolder.findViewById(R.id.data_via_tv);
    TextView dataTagTV = easyRecyclerViewHolder.findViewById(R.id.data_tag_tv);

    // 标题
    if (TextUtils.isEmpty(baseGankData.desc)) {
      dataTitleTV.setText("");
    } else {
      dataTitleTV.setText(baseGankData.desc.trim());
    }

    // 时间
    if (baseGankData.publishedAt == null) {
      dataDateTV.setText("");
    } else {
      dataDateTV.setText(DateUtils.getTimestampString(baseGankData.publishedAt));
    }

    // 小编
    if (TextUtils.isEmpty(baseGankData.who)) {
      dataViaTV.setText("");
    } else {
      dataViaTV.setText(this.context.getString(R.string.common_via, baseGankData.who));
    }

    if (TextUtils.isEmpty(baseGankData.url)) {
      dataTagTV.setVisibility(View.GONE);
    } else {
      this.setTag(dataTagTV, baseGankData.url);
    }
  }
Esempio n. 2
0
  /**
   * 加载 福利
   *
   * @param easyRecyclerViewHolder easyRecyclerViewHolder
   * @param position position
   */
  private void loadingWelfare(EasyRecyclerViewHolder easyRecyclerViewHolder, int position) {
    BaseGankData baseGankData = this.getItem(position);
    if (baseGankData == null) return;
    RatioImageView welfareIV = easyRecyclerViewHolder.findViewById(R.id.welfare_iv);

    if (position % 2 == 0) {
      welfareIV.setImageRatio(0.7f);
    } else {
      welfareIV.setImageRatio(0.6f);
    }

    // 图片
    if (TextUtils.isEmpty(baseGankData.url)) {
      GlideUtils.displayNative(welfareIV, R.mipmap.img_default_gray);
    } else {
      GlideUtils.display(welfareIV, baseGankData.url);
    }
  }
Esempio n. 3
0
  /**
   * 加载每日干货类型数据
   *
   * @param easyRecyclerViewHolder easyRecyclerViewHolder
   * @param position position
   */
  private void loadingDaily(EasyRecyclerViewHolder easyRecyclerViewHolder, int position) {
    GankDaily dailyData = this.getItem(position);
    if (dailyData == null) return;
    ImageView dailyIV = easyRecyclerViewHolder.findViewById(R.id.daily_iv);
    TextView dailyDateTV = easyRecyclerViewHolder.findViewById(R.id.daily_date_tv);
    TextView dailyTitleTV = easyRecyclerViewHolder.findViewById(R.id.daily_title_tv);

    TextView androidTagTV = easyRecyclerViewHolder.findViewById(R.id.daily_android_tag_tv);
    TextView iOSTagTV = easyRecyclerViewHolder.findViewById(R.id.daily_ios_tag_tv);
    TextView jsTagTV = easyRecyclerViewHolder.findViewById(R.id.daily_js_tag_tv);

    /*
     * 标题 和 日期
     *
     * 如果没有视频的title和date就找福利的title和date,实在没有就,完!
     */
    if (dailyData.results.videoData != null && dailyData.results.videoData.size() > 0) {
      BaseGankData video = dailyData.results.videoData.get(0);
      dailyTitleTV.setText(video.desc.trim());
      dailyDateTV.setText(
          DateUtils.date2String(video.publishedAt.getTime(), Constant.DAILY_DATE_FORMAT));
    } else if (dailyData.results.welfareData != null && dailyData.results.welfareData.size() > 0) {
      BaseGankData welfare = dailyData.results.welfareData.get(0);
      dailyTitleTV.setText(welfare.desc.trim());
      dailyDateTV.setText(
          DateUtils.date2String(welfare.publishedAt.getTime(), Constant.DAILY_DATE_FORMAT));
    } else {
      dailyTitleTV.setText("这期没福利了,安心学习吧!");
      dailyDateTV.setText("");
    }

    // 图片
    if (dailyData.results.welfareData != null && dailyData.results.welfareData.size() > 0) {
      final BaseGankData welfare = dailyData.results.welfareData.get(0);
      GlideUtils.display(dailyIV, welfare.url);
      dailyIV.setOnClickListener(
          v -> {
            if (MainAdapter.this.listener != null)
              MainAdapter.this.listener.onClickPicture(welfare.url, welfare.desc, v);
          });
    } else {
      GlideUtils.displayNative(dailyIV, R.mipmap.img_default_gray);
    }

    /*
     * 标签 ListView 和 RecyclerView 都要写else 因为复用问题
     * 忧伤
     */
    if (dailyData.category == null) {
      androidTagTV.setVisibility(View.GONE);
      iOSTagTV.setVisibility(View.GONE);
      jsTagTV.setVisibility(View.GONE);
    } else {
      if (dailyData.category.contains(GankApi.DATA_TYPE_ANDROID)) {
        androidTagTV.setVisibility(View.VISIBLE);
      } else {
        androidTagTV.setVisibility(View.GONE);
      }
      if (dailyData.category.contains(GankApi.DATA_TYPE_IOS)) {
        iOSTagTV.setVisibility(View.VISIBLE);
      } else {
        iOSTagTV.setVisibility(View.GONE);
      }
      if (dailyData.category.contains(GankApi.DATA_TYPE_JS)) {
        jsTagTV.setVisibility(View.VISIBLE);
      } else {
        jsTagTV.setVisibility(View.GONE);
      }
    }
  }