You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
92 lines
3.6 KiB
92 lines
3.6 KiB
package com.community.pocket.ui.main.ui.forum;
|
|
|
|
import android.content.Intent;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import android.widget.Button;
|
|
import android.widget.LinearLayout;
|
|
import android.widget.TextView;
|
|
import android.widget.Toast;
|
|
|
|
import com.community.pocket.R;
|
|
import com.community.pocket.data.model.Forum;
|
|
import com.community.pocket.data.model.Page;
|
|
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;
|
|
|
|
public abstract class ForumPost extends BaseFragment {
|
|
|
|
//显示发帖人
|
|
protected abstract int showAuthor();
|
|
|
|
//显示审核状态
|
|
protected abstract int showStatus();
|
|
|
|
@ViewInject(R.id.post_layout)
|
|
private LinearLayout layout;
|
|
|
|
/**
|
|
* 加载帖子数据
|
|
*/
|
|
protected void loadPost(Page<Forum> forumList) {
|
|
|
|
if (forumList.isEmpty()) {
|
|
Toast.makeText(getContext(), R.string.no_more_forum, Toast.LENGTH_LONG).show();
|
|
} else {
|
|
layout.removeViews(1, layout.getChildCount() - 1);
|
|
for (int i = 0; i < forumList.getList().size(); i++) {
|
|
final Forum forum = forumList.getList().get(i);
|
|
|
|
View childView = View.inflate(getContext(), R.layout.post, null);
|
|
TextView status = childView.findViewById(R.id.check_status);
|
|
status.setVisibility(showStatus());
|
|
switch (forum.getStatus()) {
|
|
case ok:
|
|
status.setText(R.string.forum_status_ok);
|
|
break;
|
|
case fail:
|
|
status.setText(R.string.forum_status_fail);
|
|
break;
|
|
case uncheck:
|
|
status.setText(R.string.forum_status_uncheck);
|
|
break;
|
|
}
|
|
|
|
TextView title = childView.findViewById(R.id.post_title);
|
|
title.setText(forum.getTitle());
|
|
TextView content = childView.findViewById(R.id.post_content);
|
|
content.setText(forum.getContent());
|
|
TextView author = childView.findViewById(R.id.poster);
|
|
author.setVisibility(showAuthor());
|
|
author.setText(getString(R.string.poster, forum.getUsername()));
|
|
|
|
TextView postReply = childView.findViewById(R.id.post_reply);
|
|
postReply.setText(getString(R.string.post_reply, forum.getReply()));
|
|
TextView time = childView.findViewById(R.id.post_time);
|
|
time.setText(getString(R.string.post_time, formatUnix(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);
|
|
|
|
|
|
//打开帖子
|
|
Button button = childView.findViewById(R.id.showAll);
|
|
button.setOnClickListener(new View.OnClickListener() {
|
|
@Override
|
|
public void onClick(View v) {
|
|
Intent intent = new Intent(getContext(), ForumDataActivity.class);
|
|
intent.putExtra(Param.forumId.name(), forum.getId());
|
|
startActivityForResult(intent, 1);
|
|
// startActivity(intent);
|
|
}
|
|
});
|
|
|
|
layout.addView(childView);
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|