parent
82e2f1ec13
commit
8bb27af826
@ -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<Forum> 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; |
||||
} |
||||
} |
@ -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<Forum> 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; |
||||
} |
||||
} |
@ -0,0 +1,5 @@ |
||||
package com.community.pocket.data.model; |
||||
|
||||
public abstract class AbstractForumHot { |
||||
abstract int getId(); |
||||
} |
@ -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; |
||||
} |
||||
} |
@ -1,33 +1,40 @@ |
||||
package com.community.pocket.data.model; |
||||
|
||||
import java.util.List; |
||||
import androidx.annotation.NonNull; |
||||
|
||||
/** |
||||
* 热门动态实体 |
||||
* 帖子列表 |
||||
*/ |
||||
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 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<UserHot> getUserHots() { |
||||
return userHots; |
||||
public void setTitle(String title) { |
||||
this.title = title; |
||||
} |
||||
|
||||
public List<ForumHotList> getTopicHots() { |
||||
return topicHots; |
||||
@NonNull |
||||
@Override |
||||
public String toString() { |
||||
return title; |
||||
} |
||||
|
||||
public List<ForumHotList> getActiveHots() { |
||||
return activeHots; |
||||
@Override |
||||
int getId() { |
||||
return forumId; |
||||
} |
||||
} |
||||
|
@ -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; |
||||
} |
||||
} |
@ -0,0 +1,33 @@ |
||||
package com.community.pocket.data.model; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* 热门动态实体 |
||||
*/ |
||||
public class Hot { |
||||
//活跃用户
|
||||
private List<UserHot> userHots; |
||||
//热门动态
|
||||
private List<ForumHot> topicHots; |
||||
//热门活动
|
||||
private List<ForumHot> activeHots; |
||||
|
||||
public Hot(List<UserHot> userHots, List<ForumHot> topicHots, List<ForumHot> activeHots) { |
||||
this.userHots = userHots; |
||||
this.topicHots = topicHots; |
||||
this.activeHots = activeHots; |
||||
} |
||||
|
||||
public List<UserHot> getUserHots() { |
||||
return userHots; |
||||
} |
||||
|
||||
public List<ForumHot> getTopicHots() { |
||||
return topicHots; |
||||
} |
||||
|
||||
public List<ForumHot> getActiveHots() { |
||||
return activeHots; |
||||
} |
||||
} |
@ -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; |
||||
} |
||||
} |
@ -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
|
||||
} |
@ -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; |
||||
} |
||||
} |
@ -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
|
||||
} |
@ -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<ForumHot> { |
||||
public class ForumHotResponse extends Response<Hot> { |
||||
} |
||||
|
@ -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<ForumMyResponse>() { |
||||
@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; |
||||
} |
||||
} |
@ -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<List<Forum>> { |
||||
} |
@ -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<ForumMyRequest> { |
||||
|
||||
//我的帖子请求状态
|
||||
private MutableLiveData<ForumMyResponse> forumMyResponse = new MutableLiveData<>(); |
||||
|
||||
MutableLiveData<ForumMyResponse> getForumMyResponse() { |
||||
return forumMyResponse; |
||||
} |
||||
|
||||
void loadForumMy() { |
||||
ForumMyResponse response = getRequest().loadForumMy(); |
||||
forumMyResponse.setValue(response); |
||||
} |
||||
|
||||
@Override |
||||
protected ForumMyRequest getRequest() { |
||||
return ForumMyRequest.getInstance(); |
||||
} |
||||
} |
@ -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<ForumNewResponse>() { |
||||
@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; |
||||
} |
||||
} |
@ -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<List<Forum>> { |
||||
|
||||
} |
@ -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<ForumNewRequest> { |
||||
|
||||
//最新帖子请求状态
|
||||
private MutableLiveData<ForumNewResponse> forumNewResponse = new MutableLiveData<>(); |
||||
|
||||
MutableLiveData<ForumNewResponse> getForumNewResponse() { |
||||
return forumNewResponse; |
||||
} |
||||
|
||||
void loadForumNew() { |
||||
ForumNewResponse response = getRequest().loadForumNew(); |
||||
forumNewResponse.setValue(response); |
||||
} |
||||
|
||||
@Override |
||||
protected ForumNewRequest getRequest() { |
||||
return ForumNewRequest.getInstance(); |
||||
} |
||||
} |
Loading…
Reference in new issue