增加我的帖子界面

0515
panqihua 5 years ago
parent 189c764cb7
commit 4e92a2d41d
  1. 11
      app/src/main/java/com/community/pocket/ui/main/ui/forum/ForumMyFragment.java
  2. 52
      app/src/main/java/com/community/pocket/ui/main/ui/forum/ForumNewFragment.java
  3. 64
      app/src/main/java/com/community/pocket/ui/main/ui/forum/ForumPost.java
  4. 21
      app/src/main/res/layout/main/layout/forum/layout/forum_my_fragment.xml
  5. 6
      app/src/main/res/layout/main/layout/visitor/layout/visitor_titlebar.xml

@ -1,7 +1,8 @@
package com.community.pocket.ui.main.ui.forum; package com.community.pocket.ui.main.ui.forum;
import android.view.View;
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;
@ -9,7 +10,9 @@ import org.xutils.view.annotation.ContentView;
* 我的帖子 * 我的帖子
*/ */
@ContentView(R.layout.forum_my_fragment) @ContentView(R.layout.forum_my_fragment)
public class ForumMyFragment extends BaseFragment { public class ForumMyFragment extends ForumPost {
@Override
int own() {
return View.GONE;
}
} }

@ -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);
}
}
}

@ -3,4 +3,23 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context=".ui.main.ui.forum.ForumMyFragment" /> tools:context=".ui.main.ui.forum.ForumMyFragment">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:ignore="UselessParent">
<LinearLayout
android:id="@+id/post_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<SearchView
android:id="@+id/search"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</ScrollView>
</FrameLayout>

@ -12,7 +12,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:background="@color/colorAccent" android:background="@color/colorAccent"
android:text="@string/forum_hot" android:text="@string/visitor_appointment"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
@ -24,7 +24,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:background="@color/button_unchecked" android:background="@color/button_unchecked"
android:text="@string/forum_new" android:text="@string/visitor_reservation"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@id/forum_hot" app:layout_constraintStart_toEndOf="@id/forum_hot"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
@ -36,7 +36,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:background="@color/button_unchecked" android:background="@color/button_unchecked"
android:text="@string/forum_post" android:text="@string/visitor_visitor"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@id/forum_new" app:layout_constraintStart_toEndOf="@id/forum_new"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />

Loading…
Cancel
Save