From 4e92a2d41dc22a9a3319979630c364256deb7434 Mon Sep 17 00:00:00 2001 From: panqihua <1029559041@qq.com> Date: Sat, 28 Mar 2020 23:58:26 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=88=91=E7=9A=84=E5=B8=96?= =?UTF-8?q?=E5=AD=90=E7=95=8C=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/main/ui/forum/ForumMyFragment.java | 11 ++-- .../ui/main/ui/forum/ForumNewFragment.java | 52 +-------------- .../pocket/ui/main/ui/forum/ForumPost.java | 64 +++++++++++++++++++ .../layout/forum/layout/forum_my_fragment.xml | 21 +++++- .../visitor/layout/visitor_titlebar.xml | 6 +- 5 files changed, 97 insertions(+), 57 deletions(-) create mode 100644 app/src/main/java/com/community/pocket/ui/main/ui/forum/ForumPost.java diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/forum/ForumMyFragment.java b/app/src/main/java/com/community/pocket/ui/main/ui/forum/ForumMyFragment.java index 50b314b..3e4b536 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/forum/ForumMyFragment.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/forum/ForumMyFragment.java @@ -1,7 +1,8 @@ package com.community.pocket.ui.main.ui.forum; +import android.view.View; + import com.community.pocket.R; -import com.community.pocket.ui.BaseFragment; import org.xutils.view.annotation.ContentView; @@ -9,7 +10,9 @@ import org.xutils.view.annotation.ContentView; * 我的帖子 */ @ContentView(R.layout.forum_my_fragment) -public class ForumMyFragment extends BaseFragment { - - +public class ForumMyFragment extends ForumPost { + @Override + int own() { + return View.GONE; + } } diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/forum/ForumNewFragment.java b/app/src/main/java/com/community/pocket/ui/main/ui/forum/ForumNewFragment.java index 1107e4a..ddd2788 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/forum/ForumNewFragment.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/forum/ForumNewFragment.java @@ -1,66 +1,20 @@ package com.community.pocket.ui.main.ui.forum; -import android.annotation.SuppressLint; -import android.os.Bundle; -import android.text.format.DateFormat; import android.view.View; -import android.view.ViewGroup; -import android.widget.LinearLayout; -import android.widget.TextView; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; import com.community.pocket.R; -import com.community.pocket.ui.BaseFragment; import org.xutils.view.annotation.ContentView; -import org.xutils.view.annotation.ViewInject; - -import java.util.Date; /** * 最新帖子 */ @ContentView(R.layout.forum_new_fragment) -public class ForumNewFragment extends BaseFragment { +public class ForumNewFragment extends ForumPost { - @ViewInject(R.id.post_layout) - private LinearLayout layout; @Override - public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { - super.onViewCreated(view, savedInstanceState); - - loadPost(view); - } - - /** - * 加载最新帖子 - */ - @SuppressLint("SetTextI18n") - private void loadPost(View view) { - //TODO 测试数据 - for (int i = 0; i < 10; i++) { - View childView = View.inflate(getContext(), R.layout.post, null); - TextView title = childView.findViewById(R.id.post_title); - title.setText("标题" + i); - TextView content = childView.findViewById(R.id.post_content); - content.setText("内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容" + i); - TextView author = childView.findViewById(R.id.poster); - author.setText(getString(R.string.poster, "发帖人" + i)); - TextView postReply = childView.findViewById(R.id.post_reply); - postReply.setText(getString(R.string.post_reply, 0)); - TextView time = childView.findViewById(R.id.post_time); - Date date = new Date(); - date.setTime(System.currentTimeMillis()); - time.setText(getString(R.string.post_time, DateFormat.format(getString(R.string.dateformat), date))); - ViewGroup.MarginLayoutParams layoutParams = new ViewGroup.MarginLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); - layoutParams.setMargins(0, 0, 0, 50); - childView.setLayoutParams(layoutParams); - layout.addView(childView); - - - } + int own() { + return View.VISIBLE; } } diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/forum/ForumPost.java b/app/src/main/java/com/community/pocket/ui/main/ui/forum/ForumPost.java new file mode 100644 index 0000000..b1e1320 --- /dev/null +++ b/app/src/main/java/com/community/pocket/ui/main/ui/forum/ForumPost.java @@ -0,0 +1,64 @@ +package com.community.pocket.ui.main.ui.forum; + +import android.annotation.SuppressLint; +import android.os.Bundle; +import android.text.format.DateFormat; +import android.view.View; +import android.view.ViewGroup; +import android.widget.LinearLayout; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import com.community.pocket.R; +import com.community.pocket.ui.BaseFragment; + +import org.xutils.view.annotation.ViewInject; + +import java.util.Date; + +public abstract class ForumPost extends BaseFragment { + + + abstract int own(); + + + @ViewInject(R.id.post_layout) + private LinearLayout layout; + + @Override + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + loadPost(view); + } + + /** + * 加载最新帖子 + */ + @SuppressLint("SetTextI18n") + private void loadPost(View view) { + //TODO 测试数据 + for (int i = 0; i < 10; i++) { + View childView = View.inflate(getContext(), R.layout.post, null); + TextView title = childView.findViewById(R.id.post_title); + title.setText("标题" + i); + TextView content = childView.findViewById(R.id.post_content); + content.setText("内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容" + i); + TextView author = childView.findViewById(R.id.poster); + author.setVisibility(own()); + author.setText(getString(R.string.poster, "发帖人" + i)); + + TextView postReply = childView.findViewById(R.id.post_reply); + postReply.setText(getString(R.string.post_reply, 0)); + TextView time = childView.findViewById(R.id.post_time); + Date date = new Date(); + date.setTime(System.currentTimeMillis()); + time.setText(getString(R.string.post_time, DateFormat.format(getString(R.string.dateformat), date))); + ViewGroup.MarginLayoutParams layoutParams = new ViewGroup.MarginLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); + layoutParams.setMargins(0, 0, 0, 50); + childView.setLayoutParams(layoutParams); + layout.addView(childView); + } + } +} diff --git a/app/src/main/res/layout/main/layout/forum/layout/forum_my_fragment.xml b/app/src/main/res/layout/main/layout/forum/layout/forum_my_fragment.xml index 5a45b9f..85e3a37 100644 --- a/app/src/main/res/layout/main/layout/forum/layout/forum_my_fragment.xml +++ b/app/src/main/res/layout/main/layout/forum/layout/forum_my_fragment.xml @@ -3,4 +3,23 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - tools:context=".ui.main.ui.forum.ForumMyFragment" /> \ No newline at end of file + tools:context=".ui.main.ui.forum.ForumMyFragment"> + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/main/layout/visitor/layout/visitor_titlebar.xml b/app/src/main/res/layout/main/layout/visitor/layout/visitor_titlebar.xml index f12b57b..df89c84 100644 --- a/app/src/main/res/layout/main/layout/visitor/layout/visitor_titlebar.xml +++ b/app/src/main/res/layout/main/layout/visitor/layout/visitor_titlebar.xml @@ -12,7 +12,7 @@ android:layout_height="wrap_content" android:layout_weight="1" android:background="@color/colorAccent" - android:text="@string/forum_hot" + android:text="@string/visitor_appointment" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> @@ -24,7 +24,7 @@ android:layout_height="wrap_content" android:layout_weight="1" android:background="@color/button_unchecked" - android:text="@string/forum_new" + android:text="@string/visitor_reservation" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintStart_toEndOf="@id/forum_hot" app:layout_constraintTop_toTopOf="parent" /> @@ -36,7 +36,7 @@ android:layout_height="wrap_content" android:layout_weight="1" android:background="@color/button_unchecked" - android:text="@string/forum_post" + android:text="@string/visitor_visitor" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintStart_toEndOf="@id/forum_new" app:layout_constraintTop_toTopOf="parent" />