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.
70 lines
2.5 KiB
70 lines
2.5 KiB
package com.community.pocket.ui.main.ui.forum;
|
|
|
|
import android.content.Intent;
|
|
import android.text.format.DateFormat;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import android.widget.Button;
|
|
import android.widget.LinearLayout;
|
|
import android.widget.TextView;
|
|
|
|
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.List;
|
|
|
|
public abstract class ForumPost extends BaseFragment {
|
|
|
|
|
|
protected abstract int own();
|
|
|
|
|
|
@ViewInject(R.id.post_layout)
|
|
private LinearLayout layout;
|
|
|
|
/**
|
|
* 加载帖子数据
|
|
*/
|
|
protected void loadPost(List<Forum> forumList) {
|
|
|
|
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(forum.getTitle());
|
|
TextView content = childView.findViewById(R.id.post_content);
|
|
content.setText(forum.getContent());
|
|
TextView author = childView.findViewById(R.id.poster);
|
|
author.setVisibility(own());
|
|
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, 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);
|
|
|
|
|
|
//打开帖子
|
|
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(), 1);
|
|
startActivity(intent);
|
|
}
|
|
});
|
|
|
|
layout.addView(childView);
|
|
}
|
|
}
|
|
}
|
|
|