添加公告界面

0515
panqihua 5 years ago
parent 5aaf699f71
commit 5be83fe731
  1. 78
      app/src/main/java/com/community/pocket/data/adapter/NoticeAdpter.java
  2. 47
      app/src/main/java/com/community/pocket/data/model/Notice.java
  3. 35
      app/src/main/java/com/community/pocket/ui/main/ui/forum/ForumFragment.java
  4. 10
      app/src/main/res/layout/main/layout/forum/layout/forum.xml
  5. 62
      app/src/main/res/layout/main/layout/forum/layout/forum_notice.xml
  6. 4
      app/src/main/res/values-en-rUS/strings.xml
  7. 4
      app/src/main/res/values-zh-rCN/strings.xml
  8. 4
      app/src/main/res/values/strings.xml

@ -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<NoticeAdpter.PagerViewHolder> {
private List<Notice> noticeList;
public NoticeAdpter(List<Notice> 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);
}
}
}

@ -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;
}
}

@ -1,15 +1,25 @@
package com.community.pocket.ui.main.ui.forum; package com.community.pocket.ui.main.ui.forum;
import android.os.Build; import android.os.Build;
import android.os.Bundle;
import android.view.View; import android.view.View;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi; import androidx.annotation.RequiresApi;
import androidx.viewpager2.widget.ViewPager2;
import com.community.pocket.R; 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 com.community.pocket.ui.main.MainFragment;
import org.xutils.view.annotation.ContentView; import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.Event; 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) @ContentView(R.layout.forum)
public class ForumFragment extends MainFragment { 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<Notice> 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) @RequiresApi(api = Build.VERSION_CODES.KITKAT)
@Event(value = R.id.forum_hot) @Event(value = R.id.forum_hot)

@ -13,6 +13,14 @@
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
tools:layout_constraintEnd_toEndOf="parent" /> tools:layout_constraintEnd_toEndOf="parent" />
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/paper"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/titlebar" />
<androidx.fragment.app.FragmentContainerView <androidx.fragment.app.FragmentContainerView
android:id="@+id/fragment" android:id="@+id/fragment"
android:name="androidx.navigation.fragment.NavHostFragment" android:name="androidx.navigation.fragment.NavHostFragment"
@ -23,6 +31,6 @@
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/titlebar" app:layout_constraintTop_toBottomOf="@id/paper"
app:navGraph="@navigation/forum_navigation" /> app:navGraph="@navigation/forum_navigation" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

@ -0,0 +1,62 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/notice_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="36sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ScrollView
android:id="@+id/content"
android:layout_width="0dp"
android:layout_height="100dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/notice_title">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<EditText
android:id="@+id/notice_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:enabled="false"
android:hint="@string/notice_content_load"
android:importantForAutofill="no"
android:inputType="none|textMultiLine" />
</LinearLayout>
</ScrollView>
<TextView
android:id="@+id/notice_author"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="end"
android:textSize="24sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/content" />
<TextView
android:id="@+id/notice_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="end"
android:textSize="24sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/notice_author" />
</androidx.constraintlayout.widget.ConstraintLayout>

@ -46,4 +46,8 @@
<string name="recent_posts">recent posts:%1$d</string> <string name="recent_posts">recent posts:%1$d</string>
<string name="recent_visitors">recent visitors:%1$d</string> <string name="recent_visitors">recent visitors:%1$d</string>
<string name="active_history">active history</string> <string name="active_history">active history</string>
<string name="notice_author">author:%1s</string>
<string name="notice_content_load">load notice content.....</string>
<string name="notice_time">time:%1s</string>
<string name="dateformat">yyyy-MM-dd HH:mm:ss</string>
</resources> </resources>

@ -46,4 +46,8 @@
<string name="recent_posts">最近发帖数 :%1$d</string> <string name="recent_posts">最近发帖数 :%1$d</string>
<string name="recent_visitors">最近访客数:%1$d</string> <string name="recent_visitors">最近访客数:%1$d</string>
<string name="active_history">信用分活动记录</string> <string name="active_history">信用分活动记录</string>
<string name="notice_author">公告管理员:%1s</string>
<string name="notice_content_load">加载公告内容中。。。。</string>
<string name="notice_time">公告时间:%1s</string>
<string name="dateformat">yyyy-MM-dd HH:mm:ss</string>
</resources> </resources>

@ -47,6 +47,10 @@
<string name="recent_posts">recent posts:%1$d</string> <string name="recent_posts">recent posts:%1$d</string>
<string name="recent_visitors">recent visitors:%1$d</string> <string name="recent_visitors">recent visitors:%1$d</string>
<string name="active_history">active history</string> <string name="active_history">active history</string>
<string name="notice_author">author:%1s</string>
<string name="notice_content_load">load notice content.....</string>
<string name="notice_time">time:%1s</string>
<string name="dateformat">yyyy-MM-dd HH:mm:ss</string>
<!-- Strings used for fragments for navigation --> <!-- Strings used for fragments for navigation -->
<!-- Strings used for fragments for navigation --> <!-- Strings used for fragments for navigation -->

Loading…
Cancel
Save