整理礼包详情内容(layout抽离到xml)
This commit is contained in:
@ -1,7 +1,6 @@
|
||||
package com.gh.gamecenter.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.RecyclerView.ViewHolder;
|
||||
@ -11,7 +10,6 @@ import android.text.TextUtils;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gh.base.OnRequestCallBackListener;
|
||||
@ -23,7 +21,7 @@ import com.gh.common.util.StringUtils;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.SuggestionActivity;
|
||||
import com.gh.gamecenter.adapter.viewholder.FooterViewHolder;
|
||||
import com.gh.gamecenter.adapter.viewholder.GameDetailNewsViewHolder;
|
||||
import com.gh.gamecenter.adapter.viewholder.LibaoDetailContentViewHolder;
|
||||
import com.gh.gamecenter.adapter.viewholder.LibaoDetailTopViewHolder;
|
||||
import com.gh.gamecenter.entity.LibaoDetailEntity;
|
||||
import com.gh.gamecenter.entity.LibaoEntity;
|
||||
@ -106,8 +104,8 @@ public class LibaoDetailAdapter extends BaseRecyclerAdapter<ViewHolder> {
|
||||
view = mLayoutInflater.inflate(R.layout.refresh_footerview, parent, false);
|
||||
return new FooterViewHolder(view);
|
||||
default:
|
||||
view = mLayoutInflater.inflate(R.layout.gamedetail_item_news, parent, false);
|
||||
return new GameDetailNewsViewHolder(view);
|
||||
view = mLayoutInflater.inflate(R.layout.libaodetail_item_content, parent, false);
|
||||
return new LibaoDetailContentViewHolder(view);
|
||||
}
|
||||
}
|
||||
|
||||
@ -115,8 +113,8 @@ public class LibaoDetailAdapter extends BaseRecyclerAdapter<ViewHolder> {
|
||||
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
|
||||
if (holder instanceof LibaoDetailTopViewHolder) {
|
||||
initLibaoDetailTop((LibaoDetailTopViewHolder) holder);
|
||||
} else if (holder instanceof GameDetailNewsViewHolder) {
|
||||
initLibaoDetailContent((GameDetailNewsViewHolder) holder, position);
|
||||
} else if (holder instanceof LibaoDetailContentViewHolder) {
|
||||
initLibaoDetailContent((LibaoDetailContentViewHolder) holder, position);
|
||||
} else if (holder instanceof FooterViewHolder) {
|
||||
FooterViewHolder viewHolder = (FooterViewHolder) holder;
|
||||
viewHolder.initItemPadding();
|
||||
@ -143,22 +141,8 @@ public class LibaoDetailAdapter extends BaseRecyclerAdapter<ViewHolder> {
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
int index = 0;
|
||||
|
||||
if (mLibaoDetailEntity != null) {
|
||||
if (mLibaoEntity != null) {
|
||||
index = index + 3;
|
||||
}
|
||||
|
||||
if (mLibaoDetailEntity.getTime() != null || mLibaoDetailEntity.getInstallRequired()) {
|
||||
index++;
|
||||
}
|
||||
|
||||
if (mLibaoDetailEntity.getDes() != null) {
|
||||
index++;
|
||||
}
|
||||
}
|
||||
return index;
|
||||
if (mLibaoDetailEntity != null && mLibaoEntity != null) return 3; // top + content + bottom
|
||||
return 0;
|
||||
}
|
||||
|
||||
private void initLibaoDetailTop(LibaoDetailTopViewHolder holder) {
|
||||
@ -253,25 +237,15 @@ public class LibaoDetailAdapter extends BaseRecyclerAdapter<ViewHolder> {
|
||||
}
|
||||
}
|
||||
|
||||
private void initLibaoDetailContent(GameDetailNewsViewHolder holder, int position) {
|
||||
holder.newsMore.setVisibility(View.GONE);
|
||||
holder.newsLine.setVisibility(View.VISIBLE);
|
||||
holder.newsList.setPadding(0, DisplayUtils.dip2px(mContext, 10)
|
||||
, 0, DisplayUtils.dip2px(mContext, 10));
|
||||
holder.newsList.removeAllViews();
|
||||
|
||||
if (mLibaoEntity.getContent() != null && position == 1) { // TODO 抽出 xml
|
||||
holder.newsTitle.setText("礼包内容");
|
||||
TextView textView = new TextView(mContext);
|
||||
textView.setTextColor(Color.parseColor("#717171"));
|
||||
textView.setText(Html.fromHtml(mLibaoEntity.getContent()));
|
||||
holder.newsList.addView(textView);
|
||||
} else if (mLibaoDetailEntity != null && position == 2) {
|
||||
holder.newsTitle.setText("领取规则");
|
||||
private void initLibaoDetailContent(LibaoDetailContentViewHolder holder, int position) {
|
||||
|
||||
if (mLibaoEntity.getContent() != null) {
|
||||
holder.mLibaodetailContentLl.setVisibility(View.VISIBLE);
|
||||
holder.mLibaodetailContent.setText(mLibaoEntity.getContent());
|
||||
}
|
||||
if (mLibaoDetailEntity != null ) {
|
||||
holder.mLibaodetailTimeLl.setVisibility(View.VISIBLE);
|
||||
if (mLibaoDetailEntity.getInstallRequired()) {
|
||||
TextView textView = new TextView(mContext);
|
||||
textView.setTextColor(Color.parseColor("#717171"));
|
||||
Spanned content;
|
||||
if (TextUtils.isEmpty(mLibaoEntity.getPlatform())) {
|
||||
content = Html.fromHtml(StringUtils.buildString("领取条件:", "<font color=\"#06D0A8\">安装《",
|
||||
@ -281,36 +255,22 @@ public class LibaoDetailAdapter extends BaseRecyclerAdapter<ViewHolder> {
|
||||
mLibaoEntity.getGame().getName(), "》",
|
||||
PlatformUtils.getInstance(mContext).getPlatformName(mLibaoEntity.getPlatform()), "版</font>"));
|
||||
}
|
||||
|
||||
textView.setText(content);
|
||||
holder.newsList.addView(textView);
|
||||
holder.mLibaodetailCondition.setVisibility(View.VISIBLE);
|
||||
holder.mLibaodetailCondition.setText(content);
|
||||
}
|
||||
|
||||
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
|
||||
params.setMargins(0, DisplayUtils.dip2px(mContext, 8), 0, 0);
|
||||
if (mLibaoDetailEntity.getTime() != null) {
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日 HH:mm", Locale.CHINA);
|
||||
String start = format.format((mLibaoDetailEntity.getTime().getStart() * 1000));
|
||||
String end = format.format((mLibaoDetailEntity.getTime().getEnd() * 1000));
|
||||
|
||||
TextView sTime = new TextView(mContext);
|
||||
sTime.setTextColor(Color.parseColor("#717171"));
|
||||
sTime.setText(StringUtils.buildString("开始时间:", start));
|
||||
holder.newsList.addView(sTime);
|
||||
|
||||
TextView eTime = new TextView(mContext);
|
||||
eTime.setTextColor(Color.parseColor("#717171"));
|
||||
eTime.setText(StringUtils.buildString("截止时间:", end));
|
||||
holder.newsList.addView(eTime);
|
||||
eTime.setLayoutParams(params);
|
||||
holder.mLibaodetailTimeStart.setText(StringUtils.buildString("开始时间:", start));
|
||||
holder.mLibaodetailTimeEnd.setText(StringUtils.buildString("截止时间:", end));
|
||||
}
|
||||
|
||||
} else if (mLibaoDetailEntity.getDes() != null && position == getItemCount() - 2) {
|
||||
holder.newsTitle.setText("使用说明");
|
||||
TextView desTv = new TextView(mContext);
|
||||
desTv.setTextColor(Color.parseColor("#717171"));
|
||||
desTv.setText(Html.fromHtml(mLibaoDetailEntity.getDes()));
|
||||
holder.newsList.addView(desTv);
|
||||
}
|
||||
if (mLibaoDetailEntity.getDes() != null && position == getItemCount() - 2) {
|
||||
holder.mLibaodetailDesLl.setVisibility(View.VISIBLE);
|
||||
holder.mLibaodetailDes.setText(Html.fromHtml(mLibaoDetailEntity.getDes()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,39 @@
|
||||
package com.gh.gamecenter.adapter.viewholder;
|
||||
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gh.base.BaseRecyclerViewHolder;
|
||||
import com.gh.gamecenter.R;
|
||||
|
||||
import butterknife.BindView;
|
||||
|
||||
/**
|
||||
* Created by khy on 8/10/17.
|
||||
*/
|
||||
|
||||
public class LibaoDetailContentViewHolder extends BaseRecyclerViewHolder {
|
||||
|
||||
|
||||
@BindView(R.id.libaodetail_content)
|
||||
public TextView mLibaodetailContent;
|
||||
@BindView(R.id.libaodetail_content_ll)
|
||||
public LinearLayout mLibaodetailContentLl;
|
||||
@BindView(R.id.libaodetail_time_start)
|
||||
public TextView mLibaodetailTimeStart;
|
||||
@BindView(R.id.libaodetail_time_end)
|
||||
public TextView mLibaodetailTimeEnd;
|
||||
@BindView(R.id.libaodetail_time_ll)
|
||||
public LinearLayout mLibaodetailTimeLl;
|
||||
@BindView(R.id.libaodetail_des)
|
||||
public TextView mLibaodetailDes;
|
||||
@BindView(R.id.libaodetail_des_ll)
|
||||
public LinearLayout mLibaodetailDesLl;
|
||||
@BindView(R.id.libaodetail_condition)
|
||||
public TextView mLibaodetailCondition;
|
||||
|
||||
public LibaoDetailContentViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user