parent
189c764cb7
commit
4e92a2d41d
@ -1,66 +1,20 @@ |
|||||||
package com.community.pocket.ui.main.ui.forum; |
package com.community.pocket.ui.main.ui.forum; |
||||||
|
|
||||||
import android.annotation.SuppressLint; |
|
||||||
import android.os.Bundle; |
|
||||||
import android.text.format.DateFormat; |
|
||||||
import android.view.View; |
import android.view.View; |
||||||
import android.view.ViewGroup; |
|
||||||
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.R; |
||||||
import com.community.pocket.ui.BaseFragment; |
|
||||||
|
|
||||||
import org.xutils.view.annotation.ContentView; |
import org.xutils.view.annotation.ContentView; |
||||||
import org.xutils.view.annotation.ViewInject; |
|
||||||
|
|
||||||
import java.util.Date; |
|
||||||
|
|
||||||
/** |
/** |
||||||
* 最新帖子 |
* 最新帖子 |
||||||
*/ |
*/ |
||||||
@ContentView(R.layout.forum_new_fragment) |
@ContentView(R.layout.forum_new_fragment) |
||||||
public class ForumNewFragment extends BaseFragment { |
public class ForumNewFragment extends ForumPost { |
||||||
|
|
||||||
@ViewInject(R.id.post_layout) |
|
||||||
private LinearLayout layout; |
|
||||||
|
|
||||||
@Override |
@Override |
||||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { |
int own() { |
||||||
super.onViewCreated(view, savedInstanceState); |
return View.VISIBLE; |
||||||
|
|
||||||
loadPost(view); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* 加载最新帖子 |
|
||||||
*/ |
|
||||||
@SuppressLint("SetTextI18n") |
|
||||||
private void loadPost(View view) { |
|
||||||
//TODO 测试数据
|
|
||||||
for (int i = 0; i < 10; i++) { |
|
||||||
View childView = View.inflate(getContext(), R.layout.post, null); |
|
||||||
TextView title = childView.findViewById(R.id.post_title); |
|
||||||
title.setText("标题" + i); |
|
||||||
TextView content = childView.findViewById(R.id.post_content); |
|
||||||
content.setText("内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容" + i); |
|
||||||
TextView author = childView.findViewById(R.id.poster); |
|
||||||
author.setText(getString(R.string.poster, "发帖人" + i)); |
|
||||||
TextView postReply = childView.findViewById(R.id.post_reply); |
|
||||||
postReply.setText(getString(R.string.post_reply, 0)); |
|
||||||
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))); |
|
||||||
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); |
|
||||||
layout.addView(childView); |
|
||||||
|
|
||||||
|
|
||||||
} |
|
||||||
} |
} |
||||||
} |
} |
||||||
|
@ -0,0 +1,64 @@ |
|||||||
|
package com.community.pocket.ui.main.ui.forum; |
||||||
|
|
||||||
|
import android.annotation.SuppressLint; |
||||||
|
import android.os.Bundle; |
||||||
|
import android.text.format.DateFormat; |
||||||
|
import android.view.View; |
||||||
|
import android.view.ViewGroup; |
||||||
|
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.ui.BaseFragment; |
||||||
|
|
||||||
|
import org.xutils.view.annotation.ViewInject; |
||||||
|
|
||||||
|
import java.util.Date; |
||||||
|
|
||||||
|
public abstract class ForumPost extends BaseFragment { |
||||||
|
|
||||||
|
|
||||||
|
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); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 加载最新帖子 |
||||||
|
*/ |
||||||
|
@SuppressLint("SetTextI18n") |
||||||
|
private void loadPost(View view) { |
||||||
|
//TODO 测试数据
|
||||||
|
for (int i = 0; i < 10; i++) { |
||||||
|
View childView = View.inflate(getContext(), R.layout.post, null); |
||||||
|
TextView title = childView.findViewById(R.id.post_title); |
||||||
|
title.setText("标题" + i); |
||||||
|
TextView content = childView.findViewById(R.id.post_content); |
||||||
|
content.setText("内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容" + i); |
||||||
|
TextView author = childView.findViewById(R.id.poster); |
||||||
|
author.setVisibility(own()); |
||||||
|
author.setText(getString(R.string.poster, "发帖人" + i)); |
||||||
|
|
||||||
|
TextView postReply = childView.findViewById(R.id.post_reply); |
||||||
|
postReply.setText(getString(R.string.post_reply, 0)); |
||||||
|
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))); |
||||||
|
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); |
||||||
|
layout.addView(childView); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue