diff --git a/app/src/main/java/com/community/pocket/data/adapter/NoticeAdpter.java b/app/src/main/java/com/community/pocket/data/adapter/NoticeAdpter.java new file mode 100644 index 0000000..b21008d --- /dev/null +++ b/app/src/main/java/com/community/pocket/data/adapter/NoticeAdpter.java @@ -0,0 +1,78 @@ +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 java.util.Date; +import java.util.List; + +/** + * 公告内容 + */ +public class NoticeAdpter extends RecyclerView.Adapter { + + private List noticeList; + + public NoticeAdpter(List noticeList) { + this.noticeList = noticeList; + } + + @NonNull + @Override + public PagerViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.forum_notice, parent, false); + return new PagerViewHolder(itemView); + } + + @Override + public void onBindViewHolder(@NonNull PagerViewHolder holder, int position) { + Notice notice = noticeList.get(position); + //设置数据源 + 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))); + } + + @Override + public int getItemCount() { + return noticeList.size(); + } + + // ViewHolder需要继承RecycleView.ViewHolder + static 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); + } + } +} + + diff --git a/app/src/main/java/com/community/pocket/data/model/Notice.java b/app/src/main/java/com/community/pocket/data/model/Notice.java new file mode 100644 index 0000000..620859f --- /dev/null +++ b/app/src/main/java/com/community/pocket/data/model/Notice.java @@ -0,0 +1,47 @@ +package com.community.pocket.data.model; + +/** + * 公告信息 + */ +public class Notice { + //公告标题 + private String title; + //公告内容 + private String content; + //公告人 + private String author; + //公告时间 + private Long time; + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } + + public String getAuthor() { + return author; + } + + public void setAuthor(String author) { + this.author = author; + } + + public Long getTime() { + return time; + } + + public void setTime(Long time) { + this.time = time; + } +} diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/forum/ForumFragment.java b/app/src/main/java/com/community/pocket/ui/main/ui/forum/ForumFragment.java index e9cd514..35a671f 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/forum/ForumFragment.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/forum/ForumFragment.java @@ -1,15 +1,25 @@ package com.community.pocket.ui.main.ui.forum; import android.os.Build; +import android.os.Bundle; import android.view.View; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import androidx.annotation.RequiresApi; +import androidx.viewpager2.widget.ViewPager2; import com.community.pocket.R; +import com.community.pocket.data.adapter.NoticeAdpter; +import com.community.pocket.data.model.Notice; import com.community.pocket.ui.main.MainFragment; import org.xutils.view.annotation.ContentView; import org.xutils.view.annotation.Event; +import org.xutils.view.annotation.ViewInject; + +import java.util.ArrayList; +import java.util.List; /** * 论坛框架 @@ -17,6 +27,31 @@ import org.xutils.view.annotation.Event; @ContentView(R.layout.forum) public class ForumFragment extends MainFragment { + @ViewInject(R.id.paper) + private ViewPager2 viewPager2; + + @Override + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + + initNotice(); + } + + //加载公告信息 + private void initNotice() { + List notices = new ArrayList<>(); + //TODO 测试数据 + for (int i = 0; i < 10; i++) { + Notice notice = new Notice(); + notice.setTime(System.currentTimeMillis()); + notice.setAuthor("作者" + i); + notice.setTitle("标题" + i); + notice.setContent("内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容" + i); + notices.add(notice); + } + viewPager2.setAdapter(new NoticeAdpter(notices)); + } + //跳转热榜界面 @RequiresApi(api = Build.VERSION_CODES.KITKAT) @Event(value = R.id.forum_hot) diff --git a/app/src/main/res/layout/main/layout/forum/layout/forum.xml b/app/src/main/res/layout/main/layout/forum/layout/forum.xml index f9e309c..ca3abee 100644 --- a/app/src/main/res/layout/main/layout/forum/layout/forum.xml +++ b/app/src/main/res/layout/main/layout/forum/layout/forum.xml @@ -13,6 +13,14 @@ app:layout_constraintTop_toTopOf="parent" tools:layout_constraintEnd_toEndOf="parent" /> + + \ No newline at end of file diff --git a/app/src/main/res/layout/main/layout/forum/layout/forum_notice.xml b/app/src/main/res/layout/main/layout/forum/layout/forum_notice.xml new file mode 100644 index 0000000..ce48b41 --- /dev/null +++ b/app/src/main/res/layout/main/layout/forum/layout/forum_notice.xml @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values-en-rUS/strings.xml b/app/src/main/res/values-en-rUS/strings.xml index bdbb1eb..9dfc303 100644 --- a/app/src/main/res/values-en-rUS/strings.xml +++ b/app/src/main/res/values-en-rUS/strings.xml @@ -46,4 +46,8 @@ recent posts:%1$d recent visitors:%1$d active history + author:%1s + load notice content..... + time:%1s + yyyy-MM-dd HH:mm:ss \ No newline at end of file diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 0a567cf..665d415 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -46,4 +46,8 @@ 最近发帖数 :%1$d 最近访客数:%1$d 信用分活动记录 + 公告管理员:%1s + 加载公告内容中。。。。 + 公告时间:%1s + yyyy-MM-dd HH:mm:ss \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 38e61ef..49cab6e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -47,6 +47,10 @@ recent posts:%1$d recent visitors:%1$d active history + author:%1s + load notice content..... + time:%1s + yyyy-MM-dd HH:mm:ss