You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
2.2 KiB
72 lines
2.2 KiB
package com.community.pocket.data.adapter;
|
|
|
|
import android.content.Context;
|
|
import android.text.format.DateFormat;
|
|
import android.view.LayoutInflater;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import android.widget.TextView;
|
|
|
|
import androidx.annotation.NonNull;
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
import com.community.pocket.R;
|
|
import com.community.pocket.data.model.Notice;
|
|
import com.youth.banner.adapter.BannerAdapter;
|
|
|
|
import java.util.Date;
|
|
import java.util.List;
|
|
|
|
/**
|
|
* 公告内容
|
|
* TODO 实现无限循环自动滚动
|
|
*/
|
|
public class NoticeAdpter extends BannerAdapter<Notice, NoticeAdpter.PagerViewHolder> {
|
|
|
|
public NoticeAdpter(List<Notice> datas) {
|
|
super(datas);
|
|
}
|
|
|
|
@Override
|
|
public PagerViewHolder onCreateHolder(ViewGroup parent, int viewType) {
|
|
View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.forum_notice, parent, false);
|
|
return new PagerViewHolder(itemView);
|
|
}
|
|
|
|
@Override
|
|
public void onBindView(PagerViewHolder holder, Notice notice, int position, int size) {
|
|
//设置数据源
|
|
holder.title.setText(notice.getTitle());
|
|
holder.content.setText(notice.getContent());
|
|
Context context = holder.author.getContext();
|
|
Date date = new Date();
|
|
date.setTime(notice.getTime());
|
|
holder.author.setText(context.getString(R.string.notice_author, notice.getAuthor()));
|
|
holder.time.setText(context.getString(R.string.notice_time, DateFormat.format(context.getString(R.string.dateformat), date)));
|
|
}
|
|
|
|
// ViewHolder需要继承RecycleView.ViewHolder
|
|
class PagerViewHolder extends RecyclerView.ViewHolder {
|
|
|
|
//公告标题
|
|
private TextView title;
|
|
//公告内容
|
|
private TextView content;
|
|
//公告管理员
|
|
private TextView author;
|
|
//公告时间
|
|
private TextView time;
|
|
|
|
PagerViewHolder(@NonNull View itemView) {
|
|
super(itemView);
|
|
//初始化组件
|
|
title = itemView.findViewById(R.id.notice_title);
|
|
content = itemView.findViewById(R.id.notice_content);
|
|
author = itemView.findViewById(R.id.notice_author);
|
|
time = itemView.findViewById(R.id.notice_time);
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|