Post详情页面

This commit is contained in:
BA7LZD 2020-06-04 21:42:20 +08:00
parent 02c600a117
commit 5f4b717cee
6 changed files with 311 additions and 6 deletions

View File

@ -0,0 +1,65 @@
package com.yuxihan.sdu.comm.widget;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.ScrollView;
/**
* 自定义ScrollView
*/
public class MyScrollView extends ScrollView {
private OnScrollListener mOnScrollListener;
public MyScrollView(Context context) {
super(context);
}
public MyScrollView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MyScrollView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
/**
* 监听ScroView的滑动情况
*
* @param l 变化后的X轴位置
* @param t 变化后的Y轴的位置
* @param oldl 原先的X轴的位置
* @param oldt 原先的Y轴的位置
*/
@Override
protected void onScrollChanged(int l, int t, int oldl, int oldt) {
super.onScrollChanged(l, t, oldl, oldt);
if (null != mOnScrollListener) {
mOnScrollListener.onScroll(t);
}
}
/**
* 设置滚动接口
*
* @param listener
*/
public void setOnScrollListener(OnScrollListener listener) {
this.mOnScrollListener = listener;
}
/**
* 滚动的回调接口
*/
public interface OnScrollListener {
/**
* MyScrollView滑动的Y方向距离变化时的回调方法
*
* @param scrollY
*/
void onScroll(int scrollY);
}
}

View File

@ -1,8 +1,9 @@
package com.yuxihan.sdu.data.model;
import java.io.Serializable;
import java.util.ArrayList;
public class PostDetailBean {
public class PostDetailBean implements Serializable {
private String postId;
private String userName;
private String userHead;

View File

@ -1,15 +1,148 @@
package com.yuxihan.sdu.post;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.lzy.ninegrid.ImageInfo;
import com.lzy.ninegrid.NineGridView;
import com.sackcentury.shinebuttonlib.ShineButton;
import com.yuxihan.sdu.R;
import com.yuxihan.sdu.comm.BaseActivity;
import com.yuxihan.sdu.comm.util.TimeConvert;
import com.yuxihan.sdu.comm.widget.MyScrollView;
import com.yuxihan.sdu.data.model.PostDetailBean;
import com.yuxihan.sdu.ui.home.adapter.NineGridViewClickAdapter;
public class PostDetailActivity extends BaseActivity {
import java.util.ArrayList;
/**
* 帖子详情页
*/
public class PostDetailActivity extends BaseActivity implements MyScrollView.OnScrollListener,
View.OnClickListener {
/**
* 顶部固定的TabViewLayout
*/
private LinearLayout mTopTabViewLayout;
/**
* 跟随ScrollView的TabviewLayout
*/
private LinearLayout mTabViewLayout;
/**
* 要悬浮在顶部的View的子View
*/
private LinearLayout mTopView;
/**
* 当前post信息
*/
private PostDetailBean curPost;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_post_detail);
getIntentData();
initView();
setPostData();
}
@SuppressLint("SetTextI18n")
private void setPostData() {
if (null == curPost) {
return;
}
ImageView posterHead = findViewById(R.id.poster_head);
Glide.with(PostDetailActivity.this).load(curPost.getUserHead()).into(posterHead);
TextView posterName = findViewById(R.id.tv_poster_name);
posterName.setText(curPost.getUserName());
TextView postTime = findViewById(R.id.tv_post_time);
postTime.setText(TimeConvert.getTimeElapse(curPost.getPostTime()));
TextView postContentText = findViewById(R.id.tv_post_content_text);
postContentText.setText(curPost.getPostTextContent());
TextView tvCommentCount = findViewById(R.id.tv_comment_count);
tvCommentCount.setText(curPost.getCommentCount() + "");
ShineButton shineButton = findViewById(R.id.bt_like);
shineButton.setChecked(curPost.isLikedByCurAccount());
TextView tvLikeCount = findViewById(R.id.tv_like_count);
tvLikeCount.setText(curPost.getPostLikeCount() + "");
NineGridView ngvPicContainer = findViewById(R.id.ngv_pic_container);
ArrayList<ImageInfo> imageInfoList = new ArrayList<>();
ArrayList<String> postPicUrls = curPost.getPostPicUrls();
if (postPicUrls != null) {
for (String picUrl : postPicUrls) {
ImageInfo info = new ImageInfo();
info.setThumbnailUrl(picUrl);
info.setBigImageUrl(picUrl);
imageInfoList.add(info);
}
}
ngvPicContainer.setAdapter(new NineGridViewClickAdapter(PostDetailActivity.this,
imageInfoList));
}
private void getIntentData() {
Bundle extras = getIntent().getExtras();
if (extras != null) {
curPost = (PostDetailBean) extras.get("key");
}
}
/**
* initView
*/
private void initView() {
findViewById(R.id.iv_back).setOnClickListener(this);
MyScrollView mMyScrollView = (MyScrollView) findViewById(R.id.my_scrollview);
mTabViewLayout = (LinearLayout) findViewById(R.id.ll_tabView);
mTopTabViewLayout = (LinearLayout) findViewById(R.id.ll_tabTopView);
mTopView = (LinearLayout) findViewById(R.id.tv_topView);
//滑动监听
mMyScrollView.setOnScrollListener(this);
}
@Override
public void onScroll(int scrollY) {
int mHeight = mTabViewLayout.getTop();
//判断滑动距离scrollY是否大于0因为大于0的时候就是可以滑动了此时mTabViewLayout.getTop()才能取到值
if (scrollY > 0 && scrollY >= mHeight) {
if (mTopView.getParent() != mTopTabViewLayout) {
mTabViewLayout.removeView(mTopView);
mTopTabViewLayout.addView(mTopView);
}
} else {
if (mTopView.getParent() != mTabViewLayout) {
mTopTabViewLayout.removeView(mTopView);
mTabViewLayout.addView(mTopView);
}
}
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.iv_back:
finish();
break;
default:
break;
}
}
}

View File

@ -3,6 +3,7 @@ package com.yuxihan.sdu.ui.home.adapter;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -92,10 +93,15 @@ public class HomeListAdapter extends RecyclerView.Adapter {
ngvPicContainer.setAdapter(new NineGridViewClickAdapter(mContext, imageInfoList));
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mContext.startActivity(new Intent(mContext, PostDetailActivity.class));
public void onClick(View view) {
Intent intent = new Intent(mContext,PostDetailActivity.class);
Bundle bundle = new Bundle();
bundle.putSerializable("key",curPost);
intent.putExtras(bundle);
mContext.startActivity(intent);
}
});
}
@Override

View File

@ -42,7 +42,107 @@
android:visibility="gone" />
</RelativeLayout>
<include layout="@layout/view_divider" />
<View
android:layout_width="match_parent"
android:layout_height="1px"
android:background="@color/divider_gray" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.yuxihan.sdu.comm.widget.MyScrollView
android:id="@+id/my_scrollview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<include
android:id="@+id/ll_poster_info"
layout="@layout/item_poster_info" />
<TextView
android:id="@+id/tv_post_content_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="10dp"
android:paddingEnd="10dp"
android:paddingBottom="10dp"
android:textColor="@color/black"
android:textSize="15sp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@+id/ll_poster_info"
tools:text="若您只使用上传、下载和复制功能,则可以使用简化版的 SDK" />
<com.lzy.ninegrid.NineGridView
android:id="@+id/ngv_pic_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tv_post_content_text" />
<View
android:id="@+id/inner_divider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="@color/divider_gray"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/ngv_pic_container" />
<LinearLayout
android:id="@+id/ll_tabView"
android:layout_width="match_parent"
android:layout_height="50dp"
android:gravity="center"
android:orientation="vertical">
<LinearLayout
android:id="@+id/tv_topView"
android:layout_width="match_parent"
android:layout_height="50dp"
android:gravity="center"
android:orientation="vertical">
<include
android:id="@+id/item_post_comment"
layout="@layout/item_post_comment" />
<View
android:layout_width="match_parent"
android:layout_height="1px"
android:background="@color/divider_gray" />
</LinearLayout>
</LinearLayout>
<TextView
android:id="@+id/tv_contentView"
android:layout_width="match_parent"
android:layout_height="1500dp"
android:layout_marginTop="10dp"
android:background="@color/white"
android:gravity="top|center_horizontal"
android:paddingTop="160dp"
android:text="我是评论1111\n\n\n\n\n\n\n\n\n我是评论2222\n\n\n\n\n\n\n\n\n我是评论3333\n\n\n\n\n\n\n\n\n我是评论4444\n\n\n\n\n\n\n\n\n我是评论5555\n\n\n\n\n\n\n\n\n"
android:textSize="14sp" />
</LinearLayout>
</com.yuxihan.sdu.comm.widget.MyScrollView>
<LinearLayout
android:id="@+id/ll_tabTopView"
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="vertical" />
</FrameLayout>
</LinearLayout>

View File

@ -21,7 +21,7 @@
<string name="sign_out">注销登录</string>
<string name="account_show">账号:%1$s</string>
<string name="info_edit">资料编辑</string>
<string name="grow_record_detail">成长记录详情</string>
<string name="grow_record_detail">记录详情</string>
<string name="head_icon">头像</string>
<string name="nick_name">昵称</string>
<string name="account_id">账号</string>