From 8bb27af826adcff8575f8bf2dd81d8ed160a77a5 Mon Sep 17 00:00:00 2001 From: panqihua <1029559041@qq.com> Date: Sat, 4 Apr 2020 22:56:01 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=9C=80=E6=96=B0=E5=B8=96?= =?UTF-8?q?=E5=AD=90=E3=80=81=E6=88=91=E7=9A=84=E5=B8=96=E5=AD=90UI?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/main/forum/ForumHotRequest.java | 12 +-- .../data/main/forum/ForumMyRequest.java | 48 ++++++++++++ .../data/main/forum/ForumNewRequest.java | 44 +++++++++++ .../pocket/data/model/AbstractForumHot.java | 5 ++ .../community/pocket/data/model/Forum.java | 75 +++++++++++++++++++ .../community/pocket/data/model/ForumHot.java | 47 +++++++----- .../pocket/data/model/ForumHotList.java | 35 --------- .../com/community/pocket/data/model/Hot.java | 33 ++++++++ .../community/pocket/data/model/UserHot.java | 7 +- .../ui/main/ui/forum/ForumMyFragment.java | 18 ----- .../ui/main/ui/forum/ForumMyViewModel.java | 7 -- .../ui/main/ui/forum/ForumNewFragment.java | 20 ----- .../ui/main/ui/forum/ForumNewViewModel.java | 7 -- .../pocket/ui/main/ui/forum/ForumPost.java | 36 +++------ .../main/ui/forum/hot/ForumHotFragment.java | 15 ++-- .../main/ui/forum/hot/ForumHotResponse.java | 4 +- .../ui/main/ui/forum/my/ForumMyFragment.java | 54 +++++++++++++ .../ui/main/ui/forum/my/ForumMyResponse.java | 9 +++ .../ui/main/ui/forum/my/ForumMyViewModel.java | 27 +++++++ .../main/ui/forum/news/ForumNewFragment.java | 54 +++++++++++++ .../main/ui/forum/news/ForumNewResponse.java | 13 ++++ .../main/ui/forum/news/ForumNewViewModel.java | 29 +++++++ .../layout/forum/layout/forum_my_fragment.xml | 2 +- .../forum/layout/forum_new_fragment.xml | 2 +- .../main/res/navigation/forum_navigation.xml | 4 +- app/src/main/res/values-en-rUS/strings.xml | 4 + app/src/main/res/values-zh-rCN/strings.xml | 4 + app/src/main/res/values/strings.xml | 4 + 28 files changed, 468 insertions(+), 151 deletions(-) create mode 100644 app/src/main/java/com/community/pocket/data/main/forum/ForumMyRequest.java create mode 100644 app/src/main/java/com/community/pocket/data/main/forum/ForumNewRequest.java create mode 100644 app/src/main/java/com/community/pocket/data/model/AbstractForumHot.java create mode 100644 app/src/main/java/com/community/pocket/data/model/Forum.java delete mode 100644 app/src/main/java/com/community/pocket/data/model/ForumHotList.java create mode 100644 app/src/main/java/com/community/pocket/data/model/Hot.java delete mode 100644 app/src/main/java/com/community/pocket/ui/main/ui/forum/ForumMyFragment.java delete mode 100644 app/src/main/java/com/community/pocket/ui/main/ui/forum/ForumMyViewModel.java delete mode 100644 app/src/main/java/com/community/pocket/ui/main/ui/forum/ForumNewFragment.java delete mode 100644 app/src/main/java/com/community/pocket/ui/main/ui/forum/ForumNewViewModel.java create mode 100644 app/src/main/java/com/community/pocket/ui/main/ui/forum/my/ForumMyFragment.java create mode 100644 app/src/main/java/com/community/pocket/ui/main/ui/forum/my/ForumMyResponse.java create mode 100644 app/src/main/java/com/community/pocket/ui/main/ui/forum/my/ForumMyViewModel.java create mode 100644 app/src/main/java/com/community/pocket/ui/main/ui/forum/news/ForumNewFragment.java create mode 100644 app/src/main/java/com/community/pocket/ui/main/ui/forum/news/ForumNewResponse.java create mode 100644 app/src/main/java/com/community/pocket/ui/main/ui/forum/news/ForumNewViewModel.java diff --git a/app/src/main/java/com/community/pocket/data/main/forum/ForumHotRequest.java b/app/src/main/java/com/community/pocket/data/main/forum/ForumHotRequest.java index 929afaf..0051165 100644 --- a/app/src/main/java/com/community/pocket/data/main/forum/ForumHotRequest.java +++ b/app/src/main/java/com/community/pocket/data/main/forum/ForumHotRequest.java @@ -2,7 +2,7 @@ package com.community.pocket.data.main.forum; import com.community.pocket.R; import com.community.pocket.data.model.ForumHot; -import com.community.pocket.data.model.ForumHotList; +import com.community.pocket.data.model.Hot; import com.community.pocket.data.model.UserHot; import com.community.pocket.ui.main.ui.forum.hot.ForumHotResponse; @@ -29,25 +29,25 @@ public class ForumHotRequest { //加载热门信息 public ForumHotResponse loadHot() { List userHots = new ArrayList<>(); - List topicHots = new ArrayList<>(); - List activeHots = new ArrayList<>(); + List topicHots = new ArrayList<>(); + List activeHots = new ArrayList<>(); for (int i = 0; i < 3; i++) { UserHot userHot = new UserHot(); userHot.setUserId(i); userHot.setUserName("user" + i); userHots.add(userHot); - ForumHotList forumHot = new ForumHotList(); + ForumHot forumHot = new ForumHot(); forumHot.setForumId(i); forumHot.setTitle("topIc" + i); topicHots.add(forumHot); - ForumHotList activeHot = new ForumHotList(); + ForumHot activeHot = new ForumHot(); activeHot.setForumId(i); activeHot.setTitle("hot" + i); activeHots.add(activeHot); } ForumHotResponse response = new ForumHotResponse(); response.setSuccess(R.string.load_hot_ok); - response.setBody(new ForumHot(userHots, topicHots, activeHots)); + response.setBody(new Hot(userHots, topicHots, activeHots)); return response; } } diff --git a/app/src/main/java/com/community/pocket/data/main/forum/ForumMyRequest.java b/app/src/main/java/com/community/pocket/data/main/forum/ForumMyRequest.java new file mode 100644 index 0000000..28c567d --- /dev/null +++ b/app/src/main/java/com/community/pocket/data/main/forum/ForumMyRequest.java @@ -0,0 +1,48 @@ +package com.community.pocket.data.main.forum; + + +import com.community.pocket.R; +import com.community.pocket.data.model.Forum; +import com.community.pocket.ui.main.ui.forum.my.ForumMyResponse; + +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + +/** + * 我的帖子请求接口 + * TODO 完善逻辑 + */ +public class ForumMyRequest { + private static volatile ForumMyRequest instance; + + private ForumMyRequest() { + } + + public static ForumMyRequest getInstance() { + if (instance == null) { + instance = new ForumMyRequest(); + } + return instance; + } + + /** + * @return 加载我的帖子 + */ + public ForumMyResponse loadForumMy() { + List forumList = new ArrayList<>(); + for (int i = 0; i < 10; i++) { + Forum forum = new Forum(); + forum.setTitle("标题" + i); + forum.setContent("内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容"); + forum.setUsername("发帖人" + i); + forum.setTime(System.currentTimeMillis()); + forum.setReply(new Random().nextInt(100)); + forumList.add(forum); + } + ForumMyResponse response = new ForumMyResponse(); + response.setSuccess(R.string.load_forum_my_ok); + response.setBody(forumList); + return response; + } +} diff --git a/app/src/main/java/com/community/pocket/data/main/forum/ForumNewRequest.java b/app/src/main/java/com/community/pocket/data/main/forum/ForumNewRequest.java new file mode 100644 index 0000000..788d438 --- /dev/null +++ b/app/src/main/java/com/community/pocket/data/main/forum/ForumNewRequest.java @@ -0,0 +1,44 @@ +package com.community.pocket.data.main.forum; + +import com.community.pocket.R; +import com.community.pocket.data.model.Forum; +import com.community.pocket.ui.main.ui.forum.news.ForumNewResponse; + +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + +/** + * 最新帖子列表数据接口 + * TODO 完善逻辑 + */ +public class ForumNewRequest { + private static volatile ForumNewRequest instance; + + private ForumNewRequest() { + } + + public static ForumNewRequest getInstance() { + if (instance == null) { + instance = new ForumNewRequest(); + } + return instance; + } + + public ForumNewResponse loadForumNew() { + List forumList = new ArrayList<>(); + for (int i = 0; i < 10; i++) { + Forum forum = new Forum(); + forum.setTitle("标题" + i); + forum.setContent("内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容"); + forum.setUsername("发帖人" + i); + forum.setTime(System.currentTimeMillis()); + forum.setReply(new Random().nextInt(100)); + forumList.add(forum); + } + ForumNewResponse response = new ForumNewResponse(); + response.setSuccess(R.string.load_forum_new_ok); + response.setBody(forumList); + return response; + } +} diff --git a/app/src/main/java/com/community/pocket/data/model/AbstractForumHot.java b/app/src/main/java/com/community/pocket/data/model/AbstractForumHot.java new file mode 100644 index 0000000..77c01d7 --- /dev/null +++ b/app/src/main/java/com/community/pocket/data/model/AbstractForumHot.java @@ -0,0 +1,5 @@ +package com.community.pocket.data.model; + +public abstract class AbstractForumHot { + abstract int getId(); +} diff --git a/app/src/main/java/com/community/pocket/data/model/Forum.java b/app/src/main/java/com/community/pocket/data/model/Forum.java new file mode 100644 index 0000000..f678d9d --- /dev/null +++ b/app/src/main/java/com/community/pocket/data/model/Forum.java @@ -0,0 +1,75 @@ +package com.community.pocket.data.model; + +//帖子简介内容 +public class Forum { + //帖子id + private Integer forumId; + //发帖人头像 + private String headImg; + //发帖人 + private String username; + //发帖时间 + private Long time; + //帖子标题 + private String title; + //帖子内容 + private String content; + //回复数 + private Integer reply; + + public Integer getForumId() { + return forumId; + } + + public void setForumId(Integer forumId) { + this.forumId = forumId; + } + + public String getHeadImg() { + return headImg; + } + + public void setHeadImg(String headImg) { + this.headImg = headImg; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public Long getTime() { + return time; + } + + public void setTime(Long time) { + this.time = 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 Integer getReply() { + return reply; + } + + public void setReply(Integer reply) { + this.reply = reply; + } +} diff --git a/app/src/main/java/com/community/pocket/data/model/ForumHot.java b/app/src/main/java/com/community/pocket/data/model/ForumHot.java index 207d98e..60df24f 100644 --- a/app/src/main/java/com/community/pocket/data/model/ForumHot.java +++ b/app/src/main/java/com/community/pocket/data/model/ForumHot.java @@ -1,33 +1,40 @@ package com.community.pocket.data.model; -import java.util.List; +import androidx.annotation.NonNull; /** - * 热门动态实体 + * 帖子列表 */ -public class ForumHot { - //活跃用户 - private List userHots; - //热门动态 - private List topicHots; - //热门活动 - private List activeHots; - - public ForumHot(List userHots, List topicHots, List activeHots) { - this.userHots = userHots; - this.topicHots = topicHots; - this.activeHots = activeHots; +public class ForumHot extends AbstractForumHot { + //论坛ID + private Integer forumId; + //论坛标题 + private String title; + + public Integer getForumId() { + return forumId; + } + + public void setForumId(Integer forumId) { + this.forumId = forumId; + } + + public String getTitle() { + return title; } - public List getUserHots() { - return userHots; + public void setTitle(String title) { + this.title = title; } - public List getTopicHots() { - return topicHots; + @NonNull + @Override + public String toString() { + return title; } - public List getActiveHots() { - return activeHots; + @Override + int getId() { + return forumId; } } diff --git a/app/src/main/java/com/community/pocket/data/model/ForumHotList.java b/app/src/main/java/com/community/pocket/data/model/ForumHotList.java deleted file mode 100644 index 3ccc59f..0000000 --- a/app/src/main/java/com/community/pocket/data/model/ForumHotList.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.community.pocket.data.model; - -import androidx.annotation.NonNull; - -/** - * 帖子列表 - */ -public class ForumHotList { - //论坛ID - private Integer forumId; - //论坛标题 - private String title; - - public Integer getForumId() { - return forumId; - } - - public void setForumId(Integer forumId) { - this.forumId = forumId; - } - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - @NonNull - @Override - public String toString() { - return title; - } -} diff --git a/app/src/main/java/com/community/pocket/data/model/Hot.java b/app/src/main/java/com/community/pocket/data/model/Hot.java new file mode 100644 index 0000000..6df6084 --- /dev/null +++ b/app/src/main/java/com/community/pocket/data/model/Hot.java @@ -0,0 +1,33 @@ +package com.community.pocket.data.model; + +import java.util.List; + +/** + * 热门动态实体 + */ +public class Hot { + //活跃用户 + private List userHots; + //热门动态 + private List topicHots; + //热门活动 + private List activeHots; + + public Hot(List userHots, List topicHots, List activeHots) { + this.userHots = userHots; + this.topicHots = topicHots; + this.activeHots = activeHots; + } + + public List getUserHots() { + return userHots; + } + + public List getTopicHots() { + return topicHots; + } + + public List getActiveHots() { + return activeHots; + } +} diff --git a/app/src/main/java/com/community/pocket/data/model/UserHot.java b/app/src/main/java/com/community/pocket/data/model/UserHot.java index 3f9eb94..62d70a1 100644 --- a/app/src/main/java/com/community/pocket/data/model/UserHot.java +++ b/app/src/main/java/com/community/pocket/data/model/UserHot.java @@ -5,7 +5,7 @@ import androidx.annotation.NonNull; /** * 活跃用户 */ -public class UserHot { +public class UserHot extends AbstractForumHot { //用户ID private Integer userId; //用户名 @@ -32,4 +32,9 @@ public class UserHot { public String toString() { return userName; } + + @Override + int getId() { + return userId; + } } 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 deleted file mode 100644 index 3e4b536..0000000 --- a/app/src/main/java/com/community/pocket/ui/main/ui/forum/ForumMyFragment.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.community.pocket.ui.main.ui.forum; - -import android.view.View; - -import com.community.pocket.R; - -import org.xutils.view.annotation.ContentView; - -/** - * 我的帖子 - */ -@ContentView(R.layout.forum_my_fragment) -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/ForumMyViewModel.java b/app/src/main/java/com/community/pocket/ui/main/ui/forum/ForumMyViewModel.java deleted file mode 100644 index a35de28..0000000 --- a/app/src/main/java/com/community/pocket/ui/main/ui/forum/ForumMyViewModel.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.community.pocket.ui.main.ui.forum; - -import androidx.lifecycle.ViewModel; - -public class ForumMyViewModel extends ViewModel { - // TODO: Implement the ViewModel -} 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 deleted file mode 100644 index ddd2788..0000000 --- a/app/src/main/java/com/community/pocket/ui/main/ui/forum/ForumNewFragment.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.community.pocket.ui.main.ui.forum; - -import android.view.View; - -import com.community.pocket.R; - -import org.xutils.view.annotation.ContentView; - -/** - * 最新帖子 - */ -@ContentView(R.layout.forum_new_fragment) -public class ForumNewFragment extends ForumPost { - - - @Override - int own() { - return View.VISIBLE; - } -} diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/forum/ForumNewViewModel.java b/app/src/main/java/com/community/pocket/ui/main/ui/forum/ForumNewViewModel.java deleted file mode 100644 index 455b36a..0000000 --- a/app/src/main/java/com/community/pocket/ui/main/ui/forum/ForumNewViewModel.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.community.pocket.ui.main.ui.forum; - -import androidx.lifecycle.ViewModel; - -public class ForumNewViewModel extends ViewModel { - // TODO: Implement the ViewModel -} 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 index 52fc92b..5f4e80e 100644 --- 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 @@ -1,8 +1,6 @@ package com.community.pocket.ui.main.ui.forum; -import android.annotation.SuppressLint; import android.content.Intent; -import android.os.Bundle; import android.text.format.DateFormat; import android.view.View; import android.view.ViewGroup; @@ -10,56 +8,46 @@ import android.widget.Button; 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.data.model.Forum; import com.community.pocket.ui.BaseFragment; import com.community.pocket.ui.main.ui.forum.data.ForumDataActivity; import com.community.pocket.util.Param; import org.xutils.view.annotation.ViewInject; -import java.util.Date; +import java.util.List; public abstract class ForumPost extends BaseFragment { - abstract int own(); + protected 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); - } - /** * 加载帖子数据 - * TODO 测试数据 */ - @SuppressLint("SetTextI18n") - private void loadPost(View view) { + protected void loadPost(List forumList) { - for (int i = 0; i < 10; i++) { + for (int i = 0; i < forumList.size(); i++) { + Forum forum = forumList.get(i); + View childView = View.inflate(getContext(), R.layout.post, null); TextView title = childView.findViewById(R.id.post_title); - title.setText("标题" + i); + title.setText(forum.getTitle()); TextView content = childView.findViewById(R.id.post_content); - content.setText("内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容" + i); + content.setText(forum.getContent()); TextView author = childView.findViewById(R.id.poster); author.setVisibility(own()); - author.setText(getString(R.string.poster, "发帖人" + i)); + author.setText(getString(R.string.poster, forum.getUsername())); TextView postReply = childView.findViewById(R.id.post_reply); - postReply.setText(getString(R.string.post_reply, 0)); + postReply.setText(getString(R.string.post_reply, forum.getReply())); 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))); + time.setText(getString(R.string.post_time, DateFormat.format(getString(R.string.dateformat), forum.getTime()))); 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); diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/forum/hot/ForumHotFragment.java b/app/src/main/java/com/community/pocket/ui/main/ui/forum/hot/ForumHotFragment.java index 4e5d0b3..fc70ab0 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/forum/hot/ForumHotFragment.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/forum/hot/ForumHotFragment.java @@ -15,7 +15,8 @@ import androidx.lifecycle.Observer; import androidx.lifecycle.ViewModelProvider; import com.community.pocket.R; -import com.community.pocket.data.model.ForumHot; +import com.community.pocket.data.model.AbstractForumHot; +import com.community.pocket.data.model.Hot; import com.community.pocket.ui.BaseFragment; import org.xutils.view.annotation.ContentView; @@ -55,12 +56,12 @@ public class ForumHotFragment extends BaseFragment { /** * 加载热门信息 * - * @param forumHot 热门信息 + * @param hot 热门信息 */ - private void loadRank(ForumHot forumHot) { - addRank(R.id.active_user, R.id.active_user_text, forumHot.getUserHots()); - addRank(R.id.hot_topic, R.id.hot_topic_text, forumHot.getTopicHots()); - addRank(R.id.hot_events, R.id.hot_events_text, forumHot.getActiveHots()); + private void loadRank(Hot hot) { + addRank(R.id.active_user, R.id.active_user_text, hot.getUserHots()); + addRank(R.id.hot_topic, R.id.hot_topic_text, hot.getTopicHots()); + addRank(R.id.hot_events, R.id.hot_events_text, hot.getActiveHots()); } /** @@ -68,7 +69,7 @@ public class ForumHotFragment extends BaseFragment { * @param textId 标题布局id * @param ranks 排名数组 */ - private void addRank(@IdRes int constraintId, @IdRes int textId, List ranks) { + private void addRank(@IdRes int constraintId, @IdRes int textId, List ranks) { View view = getView(); if (view != null) { diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/forum/hot/ForumHotResponse.java b/app/src/main/java/com/community/pocket/ui/main/ui/forum/hot/ForumHotResponse.java index ecfa628..2042a87 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/forum/hot/ForumHotResponse.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/forum/hot/ForumHotResponse.java @@ -1,7 +1,7 @@ package com.community.pocket.ui.main.ui.forum.hot; -import com.community.pocket.data.model.ForumHot; +import com.community.pocket.data.model.Hot; import com.community.pocket.ui.main.ui.share.Response; -public class ForumHotResponse extends Response { +public class ForumHotResponse extends Response { } diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/forum/my/ForumMyFragment.java b/app/src/main/java/com/community/pocket/ui/main/ui/forum/my/ForumMyFragment.java new file mode 100644 index 0000000..38745c0 --- /dev/null +++ b/app/src/main/java/com/community/pocket/ui/main/ui/forum/my/ForumMyFragment.java @@ -0,0 +1,54 @@ +package com.community.pocket.ui.main.ui.forum.my; + +import android.os.Bundle; +import android.view.View; +import android.widget.Toast; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.lifecycle.Observer; +import androidx.lifecycle.ViewModelProvider; + +import com.community.pocket.R; +import com.community.pocket.ui.main.ui.forum.ForumPost; + +import org.xutils.view.annotation.ContentView; + +/** + * 我的帖子 + */ +@ContentView(R.layout.forum_my_fragment) +public class ForumMyFragment extends ForumPost { + + @Override + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + + ForumMyViewModel viewModel = new ViewModelProvider(this, new ViewModelProvider.NewInstanceFactory()).get(ForumMyViewModel.class); + + viewModel.loadForumMy(); + + //监听我的帖子加载状态 + viewModel.getForumMyResponse().observe(getViewLifecycleOwner(), new Observer() { + @Override + public void onChanged(ForumMyResponse forumMyResponse) { + if (forumMyResponse == null) { + return; + } + + if (forumMyResponse.getSuccess() != null) { + loadPost(forumMyResponse.getBody()); + } + + if (forumMyResponse.getError() != null) { + Toast.makeText(getContext(), forumMyResponse.getError(), Toast.LENGTH_SHORT).show(); + } + } + }); + } + + @Override + protected int own() { + return View.GONE; + } +} diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/forum/my/ForumMyResponse.java b/app/src/main/java/com/community/pocket/ui/main/ui/forum/my/ForumMyResponse.java new file mode 100644 index 0000000..bbbebf5 --- /dev/null +++ b/app/src/main/java/com/community/pocket/ui/main/ui/forum/my/ForumMyResponse.java @@ -0,0 +1,9 @@ +package com.community.pocket.ui.main.ui.forum.my; + +import com.community.pocket.data.model.Forum; +import com.community.pocket.ui.main.ui.share.Response; + +import java.util.List; + +public class ForumMyResponse extends Response> { +} diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/forum/my/ForumMyViewModel.java b/app/src/main/java/com/community/pocket/ui/main/ui/forum/my/ForumMyViewModel.java new file mode 100644 index 0000000..b9945e0 --- /dev/null +++ b/app/src/main/java/com/community/pocket/ui/main/ui/forum/my/ForumMyViewModel.java @@ -0,0 +1,27 @@ +package com.community.pocket.ui.main.ui.forum.my; + +import androidx.lifecycle.MutableLiveData; + +import com.community.pocket.data.main.forum.ForumMyRequest; +import com.community.pocket.ui.main.ui.share.BaseViewModel; + +//我的帖子UI数据管理 +public class ForumMyViewModel extends BaseViewModel { + + //我的帖子请求状态 + private MutableLiveData forumMyResponse = new MutableLiveData<>(); + + MutableLiveData getForumMyResponse() { + return forumMyResponse; + } + + void loadForumMy() { + ForumMyResponse response = getRequest().loadForumMy(); + forumMyResponse.setValue(response); + } + + @Override + protected ForumMyRequest getRequest() { + return ForumMyRequest.getInstance(); + } +} diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/forum/news/ForumNewFragment.java b/app/src/main/java/com/community/pocket/ui/main/ui/forum/news/ForumNewFragment.java new file mode 100644 index 0000000..f84dd2a --- /dev/null +++ b/app/src/main/java/com/community/pocket/ui/main/ui/forum/news/ForumNewFragment.java @@ -0,0 +1,54 @@ +package com.community.pocket.ui.main.ui.forum.news; + +import android.os.Bundle; +import android.view.View; +import android.widget.Toast; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.lifecycle.Observer; +import androidx.lifecycle.ViewModelProvider; + +import com.community.pocket.R; +import com.community.pocket.ui.main.ui.forum.ForumPost; + +import org.xutils.view.annotation.ContentView; + +/** + * 最新帖子 + */ +@ContentView(R.layout.forum_new_fragment) +public class ForumNewFragment extends ForumPost { + + @Override + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + + ForumNewViewModel viewModel = new ViewModelProvider(this, new ViewModelProvider.NewInstanceFactory()).get(ForumNewViewModel.class); + + viewModel.loadForumNew(); + + //监听最新帖子请求状态 + viewModel.getForumNewResponse().observe(getViewLifecycleOwner(), new Observer() { + @Override + public void onChanged(ForumNewResponse forumNewResponse) { + if (forumNewResponse == null) { + return; + } + + if (forumNewResponse.getSuccess() != null) { + loadPost(forumNewResponse.getBody()); + } + + if (forumNewResponse.getError() != null) { + Toast.makeText(getContext(), forumNewResponse.getError(), Toast.LENGTH_SHORT).show(); + } + } + }); + } + + @Override + protected int own() { + return View.VISIBLE; + } +} diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/forum/news/ForumNewResponse.java b/app/src/main/java/com/community/pocket/ui/main/ui/forum/news/ForumNewResponse.java new file mode 100644 index 0000000..cbd6506 --- /dev/null +++ b/app/src/main/java/com/community/pocket/ui/main/ui/forum/news/ForumNewResponse.java @@ -0,0 +1,13 @@ +package com.community.pocket.ui.main.ui.forum.news; + +import com.community.pocket.data.model.Forum; +import com.community.pocket.ui.main.ui.share.Response; + +import java.util.List; + +/** + * 最新帖子响应实体 + */ +public class ForumNewResponse extends Response> { + +} diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/forum/news/ForumNewViewModel.java b/app/src/main/java/com/community/pocket/ui/main/ui/forum/news/ForumNewViewModel.java new file mode 100644 index 0000000..fefa08f --- /dev/null +++ b/app/src/main/java/com/community/pocket/ui/main/ui/forum/news/ForumNewViewModel.java @@ -0,0 +1,29 @@ +package com.community.pocket.ui.main.ui.forum.news; + +import androidx.lifecycle.MutableLiveData; + +import com.community.pocket.data.main.forum.ForumNewRequest; +import com.community.pocket.ui.main.ui.share.BaseViewModel; + +/** + * 最新帖子 + */ +public class ForumNewViewModel extends BaseViewModel { + + //最新帖子请求状态 + private MutableLiveData forumNewResponse = new MutableLiveData<>(); + + MutableLiveData getForumNewResponse() { + return forumNewResponse; + } + + void loadForumNew() { + ForumNewResponse response = getRequest().loadForumNew(); + forumNewResponse.setValue(response); + } + + @Override + protected ForumNewRequest getRequest() { + return ForumNewRequest.getInstance(); + } +} 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 41931ca..ef2aac2 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,7 +3,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - tools:context=".ui.main.ui.forum.ForumMyFragment"> + tools:context=".ui.main.ui.forum.my.ForumMyFragment"> + tools:context=".ui.main.ui.forum.news.ForumNewFragment"> \ 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 38836b0..14546e2 100644 --- a/app/src/main/res/values-en-rUS/strings.xml +++ b/app/src/main/res/values-en-rUS/strings.xml @@ -143,4 +143,8 @@ load notice fail load hot success load hot fail + load new success + load new fail + load forum my success + load my forum fail \ 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 fdfd7cc..16df921 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -143,4 +143,8 @@ 加载公告信息失败 加载热门信息成功 加载热门信息失败 + 加载最新帖子成功 + 加载最新帖子失败 + 加载我的帖子成功 + 加载我的帖子失败 \ 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 afb7c61..8a1fa78 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -144,6 +144,10 @@ load notice fail load hot success load hot fail + load new success + load new fail + load forum my success + load my forum fail