浏览代码

话题详情开发

huyuguo 5 年之前
父节点
当前提交
d55e574519

+ 34 - 1
app/src/main/java/com/electric/chargingpile/activity/TopicDetailActivity.java

@ -3,22 +3,55 @@ package com.electric.chargingpile.activity;
3 3
import android.os.Bundle;
4 4
import android.support.annotation.Nullable;
5 5
import android.support.v7.app.AppCompatActivity;
6
import android.support.v7.widget.RecyclerView;
6 7
import android.view.View;
8
import android.widget.TextView;
9
10
import com.andview.refreshview.XRefreshView;
7 11
import com.electric.chargingpile.R;
8 12
9 13
/**
10 14
 * @desc 话题详情
11 15
 */
12 16
public class TopicDetailActivity extends AppCompatActivity implements View.OnClickListener {
17
18
    private TextView titleTextView;
19
    private XRefreshView xRefreshView;
20
    private RecyclerView recyclerView;
21
13 22
    @Override
14 23
    protected void onCreate(@Nullable Bundle savedInstanceState) {
15 24
        super.onCreate(savedInstanceState);
16
        setContentView(R.layout.activity_topic_details_info);
25
        setContentView(R.layout.activity_topic_detail);
26
        initView();
27
        initListener();
28
    }
29
30
    private void initView() {
31
        titleTextView = findViewById(R.id.titleTextView);
32
        xRefreshView = findViewById(R.id.xRefreshView);
33
        recyclerView = findViewById(R.id.recyclerView);
17 34
    }
18 35
36
    private void initListener() {
37
        findViewById(R.id.backImageView).setOnClickListener(this);
38
        findViewById(R.id.shareTextView).setOnClickListener(this);
39
    }
19 40
20 41
    @Override
21 42
    public void onClick(View view) {
43
        switch (view.getId()) {
44
            case R.id.backImageView:
45
                finish();
46
                break;
47
            case R.id.shareTextView:
48
                shareInfo();
49
                break;
50
        }
51
52
    }
22 53
54
    private void shareInfo() {
55
        // TODO by huyuguo share information
23 56
    }
24 57
}

+ 111 - 0
app/src/main/java/com/electric/chargingpile/adapter/TopicDetailAdapter.java

@ -0,0 +1,111 @@
1
package com.electric.chargingpile.adapter;
2
3
import android.content.Context;
4
import android.support.v7.widget.RecyclerView;
5
import android.view.LayoutInflater;
6
import android.view.View;
7
import android.view.ViewGroup;
8
import android.widget.ArrayAdapter;
9
10
import com.aspsine.irecyclerview.IViewHolder;
11
import com.electric.chargingpile.R;
12
import com.electric.chargingpile.data.ChatRecommendBean;
13
import com.electric.chargingpile.data.TopicDetailBeanLab;
14
15
import java.util.ArrayList;
16
17
public class TopicDetailAdapter extends RecyclerView.Adapter<IViewHolder> {
18
    public static final int TOPIC_DETAIL_HEADER = 1;
19
    public static final int TOPIC_DETAIL_CONTENT = 2;
20
    private Context context;
21
    private LayoutInflater layoutInflater;
22
    private final TopicDetailBeanLab beanLab;
23
    private ChatRecommendBean topicDetailBean;
24
25
    public TopicDetailAdapter(Context context) {
26
        this.context = context;
27
        this.layoutInflater = LayoutInflater.from(context);
28
        beanLab = TopicDetailBeanLab.get(context);
29
    }
30
31
    @Override
32
    public IViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
33
        View itemView = null;
34
        IViewHolder viewHolder = null;
35
        switch (viewType) {
36
            case TOPIC_DETAIL_HEADER:
37
                itemView = layoutInflater.inflate(R.layout.activity_topic_detail_header, parent, false);
38
                viewHolder = new HeaderViewHolder(itemView);
39
                break;
40
            case TOPIC_DETAIL_CONTENT:
41
                itemView = layoutInflater.inflate(R.layout.activity_chat_content, parent, false);
42
                viewHolder = new ContentViewHolder(itemView);
43
                break;
44
        }
45
        return viewHolder;
46
    }
47
48
    @Override
49
    public void onBindViewHolder(IViewHolder viewHolder, int position) {
50
        switch (viewHolder.getItemViewType()) {
51
            case TOPIC_DETAIL_HEADER:
52
                bindHeaderViewHolder(viewHolder, position);
53
                break;
54
            case TOPIC_DETAIL_CONTENT:
55
                bindContentViewHolder(viewHolder, position);
56
                break;
57
        }
58
    }
59
60
    @Override
61
    public int getItemCount() {
62
        return beanLab.beans().size() + 1;
63
    }
64
65
    @Override
66
    public int getItemViewType(int position) {
67
        return position == 0 ? TOPIC_DETAIL_HEADER : TOPIC_DETAIL_CONTENT;
68
    }
69
70
    private void bindHeaderViewHolder(IViewHolder viewHolder, int position) {
71
        HeaderViewHolder headerViewHolder = (HeaderViewHolder)viewHolder;
72
73
    }
74
75
    private void bindContentViewHolder(IViewHolder viewHolder, int position) {
76
77
    }
78
79
    public void setContentData(ArrayList<ChatRecommendBean> beans) {
80
        beanLab.clear();
81
        beanLab.add(beans);
82
        notifyDataSetChanged();
83
    }
84
85
    public void addContentData(ArrayList<ChatRecommendBean> beans) {
86
        int startSize = beanLab.beans().size();
87
        beanLab.add(beans);
88
        int endSize = beanLab.beans().size();
89
        notifyItemRangeChanged(startSize, endSize);
90
    }
91
92
    public void setHeaderData(ChatRecommendBean bean) {
93
        topicDetailBean = bean;
94
    }
95
96
    class HeaderViewHolder extends IViewHolder {
97
        public HeaderViewHolder(View itemView) {
98
            super(itemView);
99
        }
100
101
    }
102
103
    class ContentViewHolder extends IViewHolder {
104
105
        public ContentViewHolder(View itemView) {
106
            super(itemView);
107
        }
108
    }
109
110
111
}

+ 45 - 0
app/src/main/java/com/electric/chargingpile/data/TopicDetailBeanLab.java

@ -0,0 +1,45 @@
1
package com.electric.chargingpile.data;
2
3
import android.content.Context;
4
5
import java.util.ArrayList;
6
import java.util.List;
7
8
public class TopicDetailBeanLab {
9
    private static TopicDetailBeanLab topicDetailBeanLab;
10
    private List<ChatRecommendBean> beans;
11
12
    public static TopicDetailBeanLab get(Context context) {
13
        if (topicDetailBeanLab == null) {
14
            topicDetailBeanLab = new TopicDetailBeanLab(context);
15
        }
16
17
        return topicDetailBeanLab;
18
    }
19
20
    private TopicDetailBeanLab(Context context) {
21
        beans = new ArrayList<>();
22
    }
23
24
    public List<ChatRecommendBean> beans() {
25
        return beans;
26
    }
27
28
    public ChatRecommendBean bean(int topicId) {
29
        for (ChatRecommendBean bean : beans) {
30
            if (bean.topicId == topicId) {
31
                return bean;
32
            }
33
        }
34
        return null;
35
    }
36
37
    public void clear() {
38
        beans.clear();
39
    }
40
41
42
    public void add(List<ChatRecommendBean> list) {
43
        beans.addAll(list);
44
    }
45
}

二进制
app/src/main/res/drawable-hdpi/app_publish_item_qa.png


二进制
app/src/main/res/drawable-hdpi/chat_publish_tips.png


二进制
app/src/main/res/drawable-hdpi/提问.png


app/src/main/res/drawable-mdpi/提问.png → app/src/main/res/drawable-mdpi/app_publish_item_qa.png


二进制
app/src/main/res/drawable-mdpi/chat_publish_tips.png


app/src/main/res/drawable-xhdpi/提问.png → app/src/main/res/drawable-xhdpi/app_publish_item_qa.png


二进制
app/src/main/res/drawable-xhdpi/chat_publish_tips.png


app/src/main/res/drawable-xxhdpi/提问.png → app/src/main/res/drawable-xxhdpi/app_publish_item_qa.png


二进制
app/src/main/res/drawable-xxhdpi/chat_publish_tips.png


app/src/main/res/drawable-xxxhdpi/提问.png → app/src/main/res/drawable-xxxhdpi/app_publish_item_qa.png


app/src/main/res/drawable-xxxhdpi/发布.png → app/src/main/res/drawable-xxxhdpi/chat_publish_icon.png


二进制
app/src/main/res/drawable-xxxhdpi/chat_publish_tips.png


+ 6 - 0
app/src/main/res/layout/activity_chat_content.xml

@ -0,0 +1,6 @@
1
<?xml version="1.0" encoding="utf-8"?>
2
<android.support.constraint.ConstraintLayout
3
    xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
4
    android:layout_height="match_parent">
5
6
</android.support.constraint.ConstraintLayout>

+ 100 - 0
app/src/main/res/layout/activity_topic_detail.xml

@ -0,0 +1,100 @@
1
<?xml version="1.0" encoding="utf-8"?>
2
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
    xmlns:app="http://schemas.android.com/apk/res-auto"
4
    xmlns:tools="http://schemas.android.com/tools"
5
    android:layout_width="match_parent"
6
    android:layout_height="match_parent"
7
    android:background="#f4f4f4"
8
    tools:context=".activity.TopicDetailActivity">
9
10
    <android.support.constraint.ConstraintLayout
11
        android:id="@+id/navBar"
12
        android:layout_width="0dp"
13
        android:layout_height="44dp"
14
        app:layout_constraintEnd_toEndOf="parent"
15
        app:layout_constraintStart_toStartOf="parent"
16
        app:layout_constraintTop_toTopOf="parent">
17
18
        <ImageView
19
            android:id="@+id/backImageView"
20
            android:layout_width="wrap_content"
21
            android:layout_height="wrap_content"
22
            android:paddingLeft="16dp"
23
            android:paddingTop="5dp"
24
            android:paddingRight="16dp"
25
            android:paddingBottom="5dp"
26
            app:layout_constraintBottom_toBottomOf="parent"
27
            app:layout_constraintStart_toStartOf="parent"
28
            app:layout_constraintTop_toTopOf="parent"
29
            app:srcCompat="@drawable/icon_lvback1119" />
30
31
        <TextView
32
            android:id="@+id/shareTextView"
33
            android:layout_width="wrap_content"
34
            android:layout_height="0dp"
35
            android:gravity="center"
36
            android:paddingLeft="16dp"
37
            android:paddingRight="16dp"
38
            android:text="分享"
39
            android:textColor="#222222"
40
            android:textSize="15sp"
41
            app:layout_constraintBottom_toBottomOf="parent"
42
            app:layout_constraintEnd_toEndOf="parent"
43
            app:layout_constraintTop_toTopOf="parent" />
44
45
        <TextView
46
            android:id="@+id/titleTextView"
47
            android:layout_width="wrap_content"
48
            android:layout_height="0dp"
49
            android:layout_marginStart="8dp"
50
            android:layout_marginEnd="8dp"
51
            android:gravity="center"
52
            android:textColor="#222222"
53
            android:textSize="17sp"
54
            android:textStyle="bold"
55
            app:layout_constraintBottom_toBottomOf="parent"
56
            app:layout_constraintEnd_toStartOf="@+id/shareTextView"
57
            app:layout_constraintStart_toEndOf="@+id/backImageView"
58
            app:layout_constraintTop_toTopOf="parent"
59
            tools:text="TextView" />
60
    </android.support.constraint.ConstraintLayout>
61
62
    <com.andview.refreshview.XRefreshView
63
        android:id="@+id/xRefreshView"
64
        android:layout_width="0dp"
65
        android:layout_height="0dp"
66
        app:layout_constraintBottom_toBottomOf="parent"
67
        app:layout_constraintEnd_toEndOf="parent"
68
        app:layout_constraintStart_toStartOf="parent"
69
        app:layout_constraintTop_toBottomOf="@+id/navBar">
70
71
        <android.support.v7.widget.RecyclerView
72
            android:id="@+id/recyclerView"
73
            android:layout_width="match_parent"
74
            android:layout_height="match_parent"
75
            android:scrollbars="vertical" />
76
77
    </com.andview.refreshview.XRefreshView>
78
79
    <ImageView
80
        android:id="@+id/chatPublishIcon"
81
        android:layout_width="wrap_content"
82
        android:layout_height="wrap_content"
83
        android:layout_marginRight="20dp"
84
        android:layout_marginBottom="30dp"
85
        android:src="@drawable/chat_publish_icon"
86
        app:layout_constraintBottom_toBottomOf="parent"
87
        app:layout_constraintRight_toRightOf="parent" />
88
89
    <ImageView
90
        android:id="@+id/chatPublishTips"
91
        android:layout_width="wrap_content"
92
        android:layout_height="wrap_content"
93
        android:layout_marginRight="5dp"
94
        android:src="@drawable/chat_publish_tips"
95
        app:layout_constraintBottom_toBottomOf="@+id/chatPublishIcon"
96
        app:layout_constraintRight_toLeftOf="@+id/chatPublishIcon"
97
        app:layout_constraintTop_toTopOf="@+id/chatPublishIcon" />
98
99
100
</android.support.constraint.ConstraintLayout>

+ 119 - 0
app/src/main/res/layout/activity_topic_detail_header.xml

@ -0,0 +1,119 @@
1
<?xml version="1.0" encoding="utf-8"?>
2
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
    xmlns:app="http://schemas.android.com/apk/res-auto"
4
    xmlns:tools="http://schemas.android.com/tools"
5
    android:layout_width="match_parent"
6
    android:layout_height="260dp">
7
8
    <android.support.constraint.ConstraintLayout
9
        android:layout_width="0dp"
10
        android:layout_height="200dp"
11
        android:background="#ffffff"
12
        app:layout_constraintEnd_toEndOf="parent"
13
        app:layout_constraintStart_toStartOf="parent"
14
        app:layout_constraintTop_toTopOf="parent">
15
16
        <ImageView
17
            android:id="@+id/headImage"
18
            android:layout_width="71dp"
19
            android:layout_height="60dp"
20
            android:layout_marginStart="15dp"
21
            android:layout_marginTop="15dp"
22
            app:layout_constraintStart_toStartOf="parent"
23
            app:layout_constraintTop_toTopOf="parent"
24
            tools:srcCompat="@tools:sample/avatars" />
25
26
        <TextView
27
            android:id="@+id/title"
28
            android:layout_width="0dp"
29
            android:layout_height="0dp"
30
            android:layout_marginStart="5dp"
31
            android:layout_marginTop="5dp"
32
            android:layout_marginEnd="15dp"
33
            android:layout_marginBottom="5dp"
34
            android:gravity="center_vertical"
35
            android:maxLines="2"
36
            android:textColor="#222222"
37
            android:textSize="17sp"
38
            android:textStyle="bold"
39
            app:layout_constraintBottom_toBottomOf="@+id/headImage"
40
            app:layout_constraintEnd_toEndOf="parent"
41
            app:layout_constraintStart_toEndOf="@+id/headImage"
42
            app:layout_constraintTop_toTopOf="@+id/headImage"
43
            tools:text="#车主说车#" />
44
45
        <TextView
46
            android:id="@+id/desc"
47
            android:layout_width="0dp"
48
            android:layout_height="wrap_content"
49
            android:layout_marginStart="15dp"
50
            android:layout_marginTop="15dp"
51
            android:layout_marginEnd="15dp"
52
            android:maxLines="3"
53
            android:textColor="#555555"
54
            android:textSize="15sp"
55
            app:layout_constraintEnd_toEndOf="parent"
56
            app:layout_constraintStart_toStartOf="parent"
57
            app:layout_constraintTop_toBottomOf="@+id/headImage"
58
            tools:text="电动小汽车,炫13.98万元起,魅15.98万元起,太值了!NEDC综合续航510km" />
59
60
        <TextView
61
            android:id="@+id/readLabel"
62
            android:layout_width="wrap_content"
63
            android:layout_height="wrap_content"
64
            android:layout_marginStart="15dp"
65
            android:layout_marginBottom="14dp"
66
            android:text="阅读"
67
            android:textColor="#555555"
68
            android:textSize="12sp"
69
            app:layout_constraintBottom_toBottomOf="parent"
70
            app:layout_constraintStart_toStartOf="parent" />
71
72
        <TextView
73
            android:id="@+id/readTextView"
74
            android:layout_width="wrap_content"
75
            android:layout_height="wrap_content"
76
            android:layout_marginStart="5dp"
77
            android:gravity="center_vertical"
78
            android:textSize="12sp"
79
            app:layout_constraintBottom_toBottomOf="@+id/readLabel"
80
            app:layout_constraintLeft_toRightOf="@+id/readLabel"
81
            app:layout_constraintTop_toTopOf="@+id/readLabel"
82
            tools:text="8" />
83
84
        <TextView
85
            android:id="@+id/joinLabel"
86
            android:layout_width="wrap_content"
87
            android:layout_height="wrap_content"
88
            android:layout_marginStart="30dp"
89
            android:gravity="center_vertical"
90
            android:text="参与"
91
            android:textColor="#555555"
92
            android:textSize="12sp"
93
            app:layout_constraintBottom_toBottomOf="@+id/readTextView"
94
            app:layout_constraintStart_toEndOf="@+id/readTextView"
95
            app:layout_constraintTop_toTopOf="@+id/readTextView" />
96
97
        <TextView
98
            android:id="@+id/joinTextView"
99
            android:layout_width="wrap_content"
100
            android:layout_height="wrap_content"
101
            android:layout_marginStart="5dp"
102
            android:gravity="center_vertical"
103
            android:text="32"
104
            android:textColor="#555555"
105
            android:textSize="12sp"
106
            app:layout_constraintBottom_toBottomOf="@+id/joinLabel"
107
            app:layout_constraintStart_toEndOf="@+id/joinLabel"
108
            app:layout_constraintTop_toTopOf="@+id/joinLabel" />
109
    </android.support.constraint.ConstraintLayout>
110
111
    <LinearLayout
112
        android:layout_width="0dp"
113
        android:layout_height="50dp"
114
        android:background="#ff00ff"
115
        android:orientation="horizontal"
116
        app:layout_constraintBottom_toBottomOf="parent"
117
        app:layout_constraintEnd_toEndOf="parent"
118
        app:layout_constraintStart_toStartOf="parent"></LinearLayout>
119
</android.support.constraint.ConstraintLayout>

+ 0 - 19
app/src/main/res/layout/activity_topic_details_info.xml

@ -1,19 +0,0 @@
1
<?xml version="1.0" encoding="utf-8"?>
2
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
    xmlns:app="http://schemas.android.com/apk/res-auto"
4
    xmlns:tools="http://schemas.android.com/tools"
5
    android:layout_width="match_parent"
6
    android:layout_height="match_parent"
7
    tools:context=".activity.TopicDetailActivity">
8
9
    <com.andview.refreshview.XRefreshView
10
        android:layout_width="0dp"
11
        android:layout_height="0dp"
12
        app:layout_constraintBottom_toBottomOf="parent"
13
        app:layout_constraintEnd_toEndOf="parent"
14
        app:layout_constraintStart_toStartOf="parent"
15
        app:layout_constraintTop_toTopOf="parent">
16
17
    </com.andview.refreshview.XRefreshView>
18
19
</android.support.constraint.ConstraintLayout>