增加公告信息、热门信息UI数据管理

0515
panqihua 5 years ago
parent b4df990bcf
commit 82e2f1ec13
  1. 53
      app/src/main/java/com/community/pocket/data/main/forum/ForumHotRequest.java
  2. 52
      app/src/main/java/com/community/pocket/data/main/forum/ForumPostRequest.java
  3. 47
      app/src/main/java/com/community/pocket/data/main/forum/ForumRequest.java
  4. 33
      app/src/main/java/com/community/pocket/data/model/ForumHot.java
  5. 35
      app/src/main/java/com/community/pocket/data/model/ForumHotList.java
  6. 35
      app/src/main/java/com/community/pocket/data/model/UserHot.java
  7. 63
      app/src/main/java/com/community/pocket/ui/main/ui/forum/ForumHotFragment.java
  8. 7
      app/src/main/java/com/community/pocket/ui/main/ui/forum/ForumHotViewModel.java
  9. 19
      app/src/main/java/com/community/pocket/ui/main/ui/forum/ForumViewModel.java
  10. 2
      app/src/main/java/com/community/pocket/ui/main/ui/forum/data/ForumDataActivity.java
  11. 96
      app/src/main/java/com/community/pocket/ui/main/ui/forum/hot/ForumHotFragment.java
  12. 7
      app/src/main/java/com/community/pocket/ui/main/ui/forum/hot/ForumHotResponse.java
  13. 28
      app/src/main/java/com/community/pocket/ui/main/ui/forum/hot/ForumHotViewModel.java
  14. 53
      app/src/main/java/com/community/pocket/ui/main/ui/forum/main/ForumFragment.java
  15. 10
      app/src/main/java/com/community/pocket/ui/main/ui/forum/main/ForumNoticeResponse.java
  16. 28
      app/src/main/java/com/community/pocket/ui/main/ui/forum/main/ForumViewModel.java
  17. 8
      app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostActiveViewModel.java
  18. 10
      app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostComplainViewModel.java
  19. 4
      app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostContent.java
  20. 8
      app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostTopicViewModel.java
  21. 8
      app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostViewModel.java
  22. 8
      app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostViewModelFactory.java
  23. 2
      app/src/main/java/com/community/pocket/ui/main/ui/info/InfoFragment.java
  24. 8
      app/src/main/java/com/community/pocket/ui/main/ui/share/BaseViewModel.java
  25. 45
      app/src/main/java/com/community/pocket/ui/main/ui/share/Response.java
  26. 2
      app/src/main/java/com/community/pocket/ui/main/ui/share/ShowWordCount.java
  27. 2
      app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorAppointmentFragment.java
  28. 5
      app/src/main/res/layout/main/layout/forum/layout/forum.xml
  29. 2
      app/src/main/res/layout/main/layout/forum/layout/forum_hot_fragment.xml
  30. 2
      app/src/main/res/layout/main/layout/visitor/layout/visitor.xml
  31. 2
      app/src/main/res/navigation/forum_navigation.xml
  32. 2
      app/src/main/res/navigation/nav_mainmenu.xml
  33. 4
      app/src/main/res/values-en-rUS/strings.xml
  34. 4
      app/src/main/res/values-zh-rCN/strings.xml
  35. 4
      app/src/main/res/values/strings.xml

@ -0,0 +1,53 @@
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.UserHot;
import com.community.pocket.ui.main.ui.forum.hot.ForumHotResponse;
import java.util.ArrayList;
import java.util.List;
/**
* 热门动态接口请求
* TODO 完善逻辑
*/
public class ForumHotRequest {
private static volatile ForumHotRequest instance;
private ForumHotRequest() {
}
public static ForumHotRequest getInstance() {
if (instance == null) {
instance = new ForumHotRequest();
}
return instance;
}
//加载热门信息
public ForumHotResponse loadHot() {
List<UserHot> userHots = new ArrayList<>();
List<ForumHotList> topicHots = new ArrayList<>();
List<ForumHotList> 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.setForumId(i);
forumHot.setTitle("topIc" + i);
topicHots.add(forumHot);
ForumHotList activeHot = new ForumHotList();
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));
return response;
}
}

@ -0,0 +1,52 @@
package com.community.pocket.data.main.forum;
import com.community.pocket.R;
import com.community.pocket.ui.main.ui.forum.post.ForumPostResponse;
import com.community.pocket.util.Valid;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
/**
* 发表帖子请求接口
* TODO 完善逻辑
*/
public class ForumPostRequest {
private static volatile ForumPostRequest instance;
private ForumPostRequest() {
}
public static ForumPostRequest getInstance() {
if (instance == null) {
instance = new ForumPostRequest();
}
return instance;
}
//发送活动贴
public Valid sendActive(String type, String title, String content, String activeStartTime, String activeEndTime, String activeScore) {
return Valid.ok;
}
//发送投诉贴
public Valid sendComplain(String title, String content, String complain) {
return Valid.ok;
}
//发送动态贴
public Valid sendTopic(String title, String content) {
return Valid.ok;
}
//检索投诉人
public ForumPostResponse<List<String>> searchPeople(String name) {
return new ForumPostResponse<List<String>>().setSuccess(R.string.search_complain_name).setBody(new ArrayList<String>() {{
add("a" + new Random().nextInt(100000));
add("a" + new Random().nextInt(100000));
add("a" + new Random().nextInt(100000));
}});
}
}

@ -1,16 +1,14 @@
package com.community.pocket.data.main.forum;
import com.community.pocket.R;
import com.community.pocket.ui.main.ui.forum.post.ForumPostResponse;
import com.community.pocket.util.Valid;
import com.community.pocket.data.model.Notice;
import com.community.pocket.ui.main.ui.forum.main.ForumNoticeResponse;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
/**
* 发表帖子请求接口
* 论坛接口管理
* TODO 完善逻辑
*/
public class ForumRequest {
@ -26,27 +24,22 @@ public class ForumRequest {
return instance;
}
//发送活动贴
public Valid sendActive(String type, String title, String content, String activeStartTime, String activeEndTime, String activeScore) {
return Valid.ok;
}
//发送投诉贴
public Valid sendComplain(String title, String content, String complain) {
return Valid.ok;
}
//发送动态贴
public Valid sendTopic(String title, String content) {
return Valid.ok;
}
//检索投诉人
public ForumPostResponse<List<String>> searchPeople(String name) {
return new ForumPostResponse<List<String>>().setSuccess(R.string.search_complain_name).setBody(new ArrayList<String>() {{
add("a" + new Random().nextInt(100000));
add("a" + new Random().nextInt(100000));
add("a" + new Random().nextInt(100000));
}});
//加载公告数据
public ForumNoticeResponse loadNotices() {
List<Notice> notices = new ArrayList<Notice>() {{
for (int i = 0; i < 10; i++) {
Notice notice = new Notice();
notice.setTime(System.currentTimeMillis());
notice.setAuthor("作者" + i);
notice.setTitle("标题" + i);
notice.setContent("内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容" + i);
add(notice);
}
}};
ForumNoticeResponse forumNoticeResponse = new ForumNoticeResponse();
forumNoticeResponse.setSuccess(R.string.load_notice_ok);
forumNoticeResponse.setBody(notices);
return forumNoticeResponse;
}
}

@ -0,0 +1,33 @@
package com.community.pocket.data.model;
import java.util.List;
/**
* 热门动态实体
*/
public class ForumHot {
//活跃用户
private List<UserHot> userHots;
//热门动态
private List<ForumHotList> topicHots;
//热门活动
private List<ForumHotList> activeHots;
public ForumHot(List<UserHot> userHots, List<ForumHotList> topicHots, List<ForumHotList> activeHots) {
this.userHots = userHots;
this.topicHots = topicHots;
this.activeHots = activeHots;
}
public List<UserHot> getUserHots() {
return userHots;
}
public List<ForumHotList> getTopicHots() {
return topicHots;
}
public List<ForumHotList> getActiveHots() {
return activeHots;
}
}

@ -0,0 +1,35 @@
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;
}
}

@ -0,0 +1,35 @@
package com.community.pocket.data.model;
import androidx.annotation.NonNull;
/**
* 活跃用户
*/
public class UserHot {
//用户ID
private Integer userId;
//用户名
private String userName;
public Integer getUserId() {
return userId;
}
public void setUserId(Integer userId) {
this.userId = userId;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
@NonNull
@Override
public String toString() {
return userName;
}
}

@ -1,63 +0,0 @@
package com.community.pocket.ui.main.ui.forum;
import android.content.Context;
import android.os.Bundle;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.IdRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.ConstraintLayout;
import com.community.pocket.R;
import com.community.pocket.ui.BaseFragment;
import org.xutils.view.annotation.ContentView;
/**
* 热门帖子
*/
@ContentView(R.layout.forum_hot_fragment)
public class ForumHotFragment extends BaseFragment {
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
addRank(view, R.id.active_user, R.id.active_user_text, new String[]{"aaaa", "bbbb", "ccccc"});
addRank(view, R.id.hot_topic, R.id.hot_topic_text, new String[]{"xxxx", "123", "fuckadsf"});
addRank(view, R.id.hot_events, R.id.hot_events_text, new String[]{"sadf", "fsd12", "123f"});
}
/**
* @param constraintId 约束布局id
* @param textId 标题布局id
* @param ranks 排名数组
*/
private void addRank(View view, @IdRes int constraintId, @IdRes int textId, String[] ranks) {
ConstraintLayout layout = view.findViewById(constraintId);
Context context = view.getContext();
int id = 0;
for (int i = 1; i <= ranks.length; i++) {
TextView textView = new TextView(context);
textView.setText(context.getString(R.string.hot_rank, i, ranks[i - 1]));
//文本居中
textView.setGravity(Gravity.CENTER | Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);
//字体大小
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
textView.setId(View.generateViewId());
//设置约束
ConstraintLayout.LayoutParams layoutParams = new ConstraintLayout.LayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
layoutParams.topToBottom = i == 1 ? textId : id;
layoutParams.setMargins(0, 10, 0, 0);
textView.setLayoutParams(layoutParams);
layout.addView(textView);
id = textView.getId();
}
}
}

@ -1,7 +0,0 @@
package com.community.pocket.ui.main.ui.forum;
import androidx.lifecycle.ViewModel;
public class ForumHotViewModel extends ViewModel {
// TODO: Implement the ViewModel
}

@ -1,19 +0,0 @@
package com.community.pocket.ui.main.ui.forum;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;
public class ForumViewModel extends ViewModel {
private MutableLiveData<String> mText;
public ForumViewModel() {
mText = new MutableLiveData<>();
mText.setValue("This is home fragment");
}
LiveData<String> getText() {
return mText;
}
}

@ -25,7 +25,7 @@ import com.community.pocket.R;
import com.community.pocket.data.model.ForumContent;
import com.community.pocket.ui.BaseActivity;
import com.community.pocket.ui.listener.MyTextChange;
import com.community.pocket.ui.main.ui.forum.ShowWordCount;
import com.community.pocket.ui.main.ui.share.ShowWordCount;
import com.community.pocket.util.Param;
import org.xutils.view.annotation.ContentView;

@ -0,0 +1,96 @@
package com.community.pocket.ui.main.ui.forum.hot;
import android.os.Bundle;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.IdRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import com.community.pocket.R;
import com.community.pocket.data.model.ForumHot;
import com.community.pocket.ui.BaseFragment;
import org.xutils.view.annotation.ContentView;
import java.util.List;
/**
* 热门帖子
*/
@ContentView(R.layout.forum_hot_fragment)
public class ForumHotFragment extends BaseFragment {
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
ForumHotViewModel viewModel = new ViewModelProvider(this, new ViewModelProvider.NewInstanceFactory()).get(ForumHotViewModel.class);
viewModel.loadHot();
//加载热门信息
viewModel.getForumHotResponse().observe(getViewLifecycleOwner(), new Observer<ForumHotResponse>() {
@Override
public void onChanged(ForumHotResponse forumHotResponse) {
if (forumHotResponse == null) {
return;
}
if (forumHotResponse.getSuccess() != null) {
loadRank(forumHotResponse.getBody());
}
}
});
}
/**
* 加载热门信息
*
* @param forumHot 热门信息
*/
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());
}
/**
* @param constraintId 约束布局id
* @param textId 标题布局id
* @param ranks 排名数组
*/
private void addRank(@IdRes int constraintId, @IdRes int textId, List ranks) {
View view = getView();
if (view != null) {
ConstraintLayout layout = view.findViewById(constraintId);
int id = 0;
for (int i = 1; i <= ranks.size(); i++) {
TextView textView = new TextView(view.getContext());
textView.setText(view.getContext().getString(R.string.hot_rank, i, ranks.get(i - 1)));
//文本居中
textView.setGravity(Gravity.CENTER | Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);
//字体大小
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
textView.setId(View.generateViewId());
//设置约束
ConstraintLayout.LayoutParams layoutParams = new ConstraintLayout.LayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
layoutParams.topToBottom = i == 1 ? textId : id;
layoutParams.setMargins(0, 10, 0, 0);
textView.setLayoutParams(layoutParams);
layout.addView(textView);
id = textView.getId();
}
}
}
}

@ -0,0 +1,7 @@
package com.community.pocket.ui.main.ui.forum.hot;
import com.community.pocket.data.model.ForumHot;
import com.community.pocket.ui.main.ui.share.Response;
public class ForumHotResponse extends Response<ForumHot> {
}

@ -0,0 +1,28 @@
package com.community.pocket.ui.main.ui.forum.hot;
import androidx.lifecycle.MutableLiveData;
import com.community.pocket.data.main.forum.ForumHotRequest;
import com.community.pocket.ui.main.ui.share.BaseViewModel;
//热门动态UI数据管理
public class ForumHotViewModel extends BaseViewModel<ForumHotRequest> {
//热门动态请求状态
private MutableLiveData<ForumHotResponse> forumHotResponse = new MutableLiveData<>();
MutableLiveData<ForumHotResponse> getForumHotResponse() {
return forumHotResponse;
}
//加载热门信息
void loadHot() {
ForumHotResponse response = getRequest().loadHot();
forumHotResponse.setValue(response);
}
@Override
protected ForumHotRequest getRequest() {
return ForumHotRequest.getInstance();
}
}

@ -1,12 +1,16 @@
package com.community.pocket.ui.main.ui.forum;
package com.community.pocket.ui.main.ui.forum.main;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.core.widget.NestedScrollView;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import androidx.viewpager2.widget.ViewPager2;
import com.community.pocket.R;
@ -18,7 +22,6 @@ 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;
/**
@ -30,32 +33,51 @@ public class ForumFragment extends MainFragment {
@ViewInject(R.id.paper)
private ViewPager2 viewPager2;
@ViewInject(R.id.scroll_body)
private NestedScrollView nestedScrollView;
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
initNotice();
ForumViewModel viewModel = new ViewModelProvider(this, new ViewModelProvider.NewInstanceFactory()).get(ForumViewModel.class);
viewModel.loadNotice();
//监控公告信息请求状态
viewModel.getNoticeDataResponse().observe(getViewLifecycleOwner(), new Observer<ForumNoticeResponse>() {
@Override
public void onChanged(ForumNoticeResponse forumNoticeResponse) {
if (forumNoticeResponse == null) {
return;
}
if (forumNoticeResponse.getSuccess() != null) {
initNotice(forumNoticeResponse.getBody());
}
if (forumNoticeResponse.getError() != null) {
Toast.makeText(getContext(), R.string.load_notice_fail, Toast.LENGTH_SHORT).show();
}
}
});
}
//加载公告信息
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);
}
private void initNotice(List<Notice> notices) {
viewPager2.setAdapter(new NoticeAdpter(notices));
}
private void scrollTop() {
nestedScrollView.fling(0);
nestedScrollView.smoothScrollTo(0, 0);
}
//跳转热榜界面
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
@Event(value = R.id.forum_hot)
private void hot(View view) {
scrollTop();
ctrl().navigate(R.id.forumHotFragment);
changeColor(view);
}
@ -64,6 +86,7 @@ public class ForumFragment extends MainFragment {
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
@Event(value = R.id.forum_new)
private void _new(View view) {
scrollTop();
ctrl().navigate(R.id.forumNewFragment);
changeColor(view);
}
@ -73,6 +96,7 @@ public class ForumFragment extends MainFragment {
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
@Event(value = R.id.forum_post)
private void post(View view) {
scrollTop();
ctrl().navigate(R.id.forumPostFragment);
changeColor(view);
}
@ -81,6 +105,7 @@ public class ForumFragment extends MainFragment {
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
@Event(value = R.id.forum_my)
private void my(View view) {
scrollTop();
ctrl().navigate(R.id.forumMyFragment);
changeColor(view);
}

@ -0,0 +1,10 @@
package com.community.pocket.ui.main.ui.forum.main;
import com.community.pocket.data.model.Notice;
import com.community.pocket.ui.main.ui.share.Response;
import java.util.List;
public class ForumNoticeResponse extends Response<List<Notice>> {
}

@ -0,0 +1,28 @@
package com.community.pocket.ui.main.ui.forum.main;
import androidx.lifecycle.MutableLiveData;
import com.community.pocket.data.main.forum.ForumRequest;
import com.community.pocket.ui.main.ui.share.BaseViewModel;
/**
* 论坛基本布局UI数据管理
*/
public class ForumViewModel extends BaseViewModel<ForumRequest> {
//公告数据请求状态
private MutableLiveData<ForumNoticeResponse> noticeDataResponse = new MutableLiveData<>();
MutableLiveData<ForumNoticeResponse> getNoticeDataResponse() {
return noticeDataResponse;
}
void loadNotice() {
ForumNoticeResponse response = getRequest().loadNotices();
noticeDataResponse.setValue(response);
}
@Override
protected ForumRequest getRequest() {
return ForumRequest.getInstance();
}
}

@ -3,7 +3,7 @@ package com.community.pocket.ui.main.ui.forum.post;
import androidx.lifecycle.MutableLiveData;
import com.community.pocket.R;
import com.community.pocket.data.main.forum.ForumRequest;
import com.community.pocket.data.main.forum.ForumPostRequest;
import com.community.pocket.util.Valid;
import com.community.pocket.util.ValidUtil;
@ -12,8 +12,8 @@ class ForumPostActiveViewModel extends ForumPostViewModel {
//表单校验状态
private MutableLiveData<ForumPostFormState.Active> forumPostFormState = new MutableLiveData<>();
ForumPostActiveViewModel(ForumRequest forumRequest) {
super(forumRequest);
ForumPostActiveViewModel(ForumPostRequest forumPostRequest) {
super(forumPostRequest);
}
@ -40,7 +40,7 @@ class ForumPostActiveViewModel extends ForumPostViewModel {
//发帖请求状态
void sendPost(String type, String title, String content, String activeStartTime, String activeEndTime, String activeScore) {
Valid valid = forumRequest.sendActive(type, title, content, activeStartTime, activeEndTime, activeScore);
Valid valid = forumPostRequest.sendActive(type, title, content, activeStartTime, activeEndTime, activeScore);
if (valid == Valid.ok) {
forumPostResponse.setValue(new ForumPostResponse().setSuccess(R.string.forum_post_ok));
} else {

@ -3,7 +3,7 @@ package com.community.pocket.ui.main.ui.forum.post;
import androidx.lifecycle.MutableLiveData;
import com.community.pocket.R;
import com.community.pocket.data.main.forum.ForumRequest;
import com.community.pocket.data.main.forum.ForumPostRequest;
import com.community.pocket.util.Valid;
import com.community.pocket.util.ValidUtil;
@ -20,8 +20,8 @@ class ForumPostComplainViewModel extends ForumPostViewModel {
//检索投诉人
private MutableLiveData<ForumPostResponse<List<String>>> searchPeople = new MutableLiveData<>();
ForumPostComplainViewModel(ForumRequest forumRequest) {
super(forumRequest);
ForumPostComplainViewModel(ForumPostRequest forumPostRequest) {
super(forumPostRequest);
}
MutableLiveData<ForumPostFormState.Complain> getForumPostFormState() {
@ -55,7 +55,7 @@ class ForumPostComplainViewModel extends ForumPostViewModel {
* @param complain 投诉人
*/
void sendComplain(String title, String content, String complain) {
Valid valid = forumRequest.sendComplain(title, content, complain);
Valid valid = forumPostRequest.sendComplain(title, content, complain);
if (valid == Valid.ok) {
forumPostResponse.setValue(new ForumPostResponse().setSuccess(R.string.forum_post_ok));
} else {
@ -69,7 +69,7 @@ class ForumPostComplainViewModel extends ForumPostViewModel {
* @param name 投诉人
*/
void searchPeople(String name) {
ForumPostResponse<List<String>> forumPostResponse = forumRequest.searchPeople(name);
ForumPostResponse<List<String>> forumPostResponse = forumPostRequest.searchPeople(name);
searchPeople.setValue(forumPostResponse);
}
}

@ -16,8 +16,8 @@ import androidx.lifecycle.Observer;
import com.community.pocket.R;
import com.community.pocket.ui.BaseFragment;
import com.community.pocket.ui.main.ui.forum.ForumFragment;
import com.community.pocket.ui.main.ui.forum.ShowWordCount;
import com.community.pocket.ui.main.ui.forum.main.ForumFragment;
import com.community.pocket.ui.main.ui.share.ShowWordCount;
import org.xutils.view.annotation.ViewInject;

@ -3,7 +3,7 @@ package com.community.pocket.ui.main.ui.forum.post;
import androidx.lifecycle.MutableLiveData;
import com.community.pocket.R;
import com.community.pocket.data.main.forum.ForumRequest;
import com.community.pocket.data.main.forum.ForumPostRequest;
import com.community.pocket.util.Valid;
import com.community.pocket.util.ValidUtil;
@ -14,8 +14,8 @@ class ForumPostTopicViewModel extends ForumPostViewModel {
private MutableLiveData<ForumPostFormState> forumPostFormState = new MutableLiveData<>();
ForumPostTopicViewModel(ForumRequest forumRequest) {
super(forumRequest);
ForumPostTopicViewModel(ForumPostRequest forumPostRequest) {
super(forumPostRequest);
}
MutableLiveData<ForumPostFormState> getForumPostFormState() {
@ -35,7 +35,7 @@ class ForumPostTopicViewModel extends ForumPostViewModel {
//发送动态贴
void sendTopic(String title, String content) {
Valid valid = forumRequest.sendTopic(title, content);
Valid valid = forumPostRequest.sendTopic(title, content);
if (valid == Valid.ok) {
forumPostResponse.setValue(new ForumPostResponse().setSuccess(R.string.forum_post_ok));
} else {

@ -3,7 +3,7 @@ package com.community.pocket.ui.main.ui.forum.post;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;
import com.community.pocket.data.main.forum.ForumRequest;
import com.community.pocket.data.main.forum.ForumPostRequest;
//发送帖子UI数据管理
abstract class ForumPostViewModel extends ViewModel {
@ -13,14 +13,14 @@ abstract class ForumPostViewModel extends ViewModel {
MutableLiveData<ForumPostResponse> forumPostResponse = new MutableLiveData<>();
//请求接口处理
ForumRequest forumRequest;
ForumPostRequest forumPostRequest;
MutableLiveData<ForumPostResponse> getForumPostResponse() {
return forumPostResponse;
}
ForumPostViewModel(ForumRequest forumRequest) {
this.forumRequest = forumRequest;
ForumPostViewModel(ForumPostRequest forumPostRequest) {
this.forumPostRequest = forumPostRequest;
}

@ -4,7 +4,7 @@ import androidx.annotation.NonNull;
import androidx.lifecycle.ViewModel;
import androidx.lifecycle.ViewModelProvider;
import com.community.pocket.data.main.forum.ForumRequest;
import com.community.pocket.data.main.forum.ForumPostRequest;
public class ForumPostViewModelFactory implements ViewModelProvider.Factory {
@ -13,11 +13,11 @@ public class ForumPostViewModelFactory implements ViewModelProvider.Factory {
@SuppressWarnings("unchecked")
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
if (modelClass.isAssignableFrom(ForumPostActiveViewModel.class)) {
return (T) new ForumPostActiveViewModel(ForumRequest.getInstance());
return (T) new ForumPostActiveViewModel(ForumPostRequest.getInstance());
} else if (modelClass.isAssignableFrom(ForumPostTopicViewModel.class)) {
return (T) new ForumPostTopicViewModel(ForumRequest.getInstance());
return (T) new ForumPostTopicViewModel(ForumPostRequest.getInstance());
} else if (modelClass.isAssignableFrom(ForumPostComplainViewModel.class)) {
return (T) new ForumPostComplainViewModel(ForumRequest.getInstance());
return (T) new ForumPostComplainViewModel(ForumPostRequest.getInstance());
} else {
throw new IllegalArgumentException("Unknown ViewModel class");
}

@ -169,7 +169,7 @@ public class InfoFragment extends BaseFragment {
}
if (myInfoInfoResponse.getSuccess() != null) {
Toast.makeText(getContext(), R.string.load_info_ok, Toast.LENGTH_LONG).show();
// Toast.makeText(getContext(), R.string.load_info_ok, Toast.LENGTH_SHORT).show();
loadInfo(myInfoInfoResponse.getBody());
}

@ -0,0 +1,8 @@
package com.community.pocket.ui.main.ui.share;
import androidx.lifecycle.ViewModel;
public abstract class BaseViewModel<T> extends ViewModel {
protected abstract T getRequest();
}

@ -0,0 +1,45 @@
package com.community.pocket.ui.main.ui.share;
import androidx.annotation.Nullable;
/**
* 响应体父类
*
* @param <T>
*/
public abstract class Response<T> {
//成功描述
@Nullable
private Integer success;
//失败描述
@Nullable
private Integer error;
//响应体
private T body;
@Nullable
public Integer getSuccess() {
return success;
}
public void setSuccess(@Nullable Integer success) {
this.success = success;
}
@Nullable
public Integer getError() {
return error;
}
public void setError(@Nullable Integer error) {
this.error = error;
}
public T getBody() {
return body;
}
public void setBody(T body) {
this.body = body;
}
}

@ -1,4 +1,4 @@
package com.community.pocket.ui.main.ui.forum;
package com.community.pocket.ui.main.ui.share;
import android.text.Html;
import android.view.View;

@ -26,7 +26,7 @@ import com.community.pocket.R;
import com.community.pocket.data.adapter.VisitorAdpter;
import com.community.pocket.ui.BaseFragment;
import com.community.pocket.ui.listener.MyTextChange;
import com.community.pocket.ui.main.ui.forum.ShowWordCount;
import com.community.pocket.ui.main.ui.share.ShowWordCount;
import com.community.pocket.util.PropertiesUtil;
import org.jetbrains.annotations.NotNull;

@ -4,7 +4,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.main.ui.forum.ForumFragment">
tools:context=".ui.main.ui.forum.main.ForumFragment">
<include
android:id="@+id/titlebar"
@ -14,8 +14,9 @@
tools:layout_constraintEnd_toEndOf="parent" />
<androidx.core.widget.NestedScrollView
android:id="@+id/scroll_body"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="0dp"
android:fillViewport="true"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/titlebar"

@ -4,7 +4,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.main.ui.forum.ForumHotFragment">
tools:context=".ui.main.ui.forum.hot.ForumHotFragment">
<androidx.core.widget.NestedScrollView

@ -4,7 +4,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.main.ui.forum.ForumFragment">
tools:context=".ui.main.ui.forum.main.ForumFragment">
<include
android:id="@+id/titlebar"

@ -8,7 +8,7 @@
<fragment
android:id="@+id/forumHotFragment"
android:name="com.community.pocket.ui.main.ui.forum.ForumHotFragment"
android:name="com.community.pocket.ui.main.ui.forum.hot.ForumHotFragment"
android:label="forum_hot_fragment"
tools:layout="@layout/forum_hot_fragment" />
<fragment

@ -7,7 +7,7 @@
<fragment
android:id="@+id/navigation_home"
android:name="com.community.pocket.ui.main.ui.forum.ForumFragment"
android:name="com.community.pocket.ui.main.ui.forum.main.ForumFragment"
android:label="@string/title_home"
tools:layout="@layout/forum" />

@ -139,4 +139,8 @@
<string name="modify_pwd_fail">modify password error</string>
<string name="load_info_ok">load my info success</string>
<string name="load_info_fail">load my info error</string>
<string name="load_notice_ok">load notice success</string>
<string name="load_notice_fail">load notice fail</string>
<string name="load_hot_ok">load hot success</string>
<string name="load_hot_fail">load hot fail</string>
</resources>

@ -139,4 +139,8 @@
<string name="modify_pwd_fail">修改密码失败</string>
<string name="load_info_ok">加载个人信息成功</string>
<string name="load_info_fail">加载个人信息失败</string>
<string name="load_notice_ok">加载公告信息成功</string>
<string name="load_notice_fail">加载公告信息失败</string>
<string name="load_hot_ok">加载热门信息成功</string>
<string name="load_hot_fail">加载热门信息失败</string>
</resources>

@ -140,6 +140,10 @@
<string name="modify_pwd_fail">modify password error</string>
<string name="load_info_ok">load my info success</string>
<string name="load_info_fail">load my info error</string>
<string name="load_notice_ok">load notice success</string>
<string name="load_notice_fail">load notice fail</string>
<string name="load_hot_ok">load hot success</string>
<string name="load_hot_fail">load hot fail</string>
<!-- Strings used for fragments for navigation -->
<!-- Strings used for fragments for navigation -->

Loading…
Cancel
Save