Skip to content

Commit b37d60e

Browse files
committed
添加分类查看
1 parent df7d355 commit b37d60e

6 files changed

Lines changed: 217 additions & 28 deletions

File tree

diycode-app/src/main/AndroidManifest.xml

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,29 +63,31 @@
6363
android:theme="@style/AppTheme.NoActionBar">
6464
</activity>
6565
<activity
66-
android:theme="@style/AppTheme.NoActionBar"
67-
android:name=".activity.WebActivity">
66+
android:name=".activity.WebActivity"
67+
android:theme="@style/AppTheme.NoActionBar">
6868
</activity>
6969
<activity
70-
android:theme="@style/AppTheme.NoActionBar"
7170
android:name=".activity.LoginActivity"
71+
android:theme="@style/AppTheme.NoActionBar"
7272
android:windowSoftInputMode="adjustPan">
7373
</activity>
7474
<activity
75-
android:theme="@style/AppTheme.NoActionBar"
76-
android:name=".activity.SettingActivity">
75+
android:name=".activity.SettingActivity"
76+
android:theme="@style/AppTheme.NoActionBar">
7777
</activity>
7878
<activity
79-
android:theme="@style/AppTheme.NoActionBar"
80-
android:name=".activity.MyTopicActivity">
79+
android:name=".activity.MyTopicActivity"
80+
android:theme="@style/AppTheme.NoActionBar">
8181
</activity>
8282
<activity
83-
android:theme="@style/AppTheme.NoActionBar"
84-
android:name=".activity.AboutActivity">
83+
android:name=".activity.AboutActivity"
84+
android:theme="@style/AppTheme.NoActionBar">
8585
</activity>
8686
<activity
87-
android:theme="@style/AppTheme.NoActionBar"
88-
android:name=".activity.NotificationActivity">
87+
android:name=".activity.NotificationActivity"
88+
android:theme="@style/AppTheme.NoActionBar">
89+
</activity>
90+
<activity android:name=".activity.TopicActivity">
8991
</activity>
9092
</application>
9193

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright 2017 GcsSloop
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* Last modified 2017-04-09 19:39:57
17+
*
18+
* GitHub: https://github.com/GcsSloop
19+
* Website: http://www.gcssloop.com
20+
* Weibo: http://weibo.com/GcsSloop
21+
*/
22+
23+
package com.gcssloop.diycode.activity;
24+
25+
import android.content.Context;
26+
import android.content.Intent;
27+
import android.support.v4.app.FragmentManager;
28+
import android.support.v4.app.FragmentTransaction;
29+
import android.view.View;
30+
31+
import com.gcssloop.diycode.R;
32+
import com.gcssloop.diycode.base.app.BaseActivity;
33+
import com.gcssloop.diycode.base.app.ViewHolder;
34+
import com.gcssloop.diycode.fragment.NodeTopicListFragment;
35+
36+
public class TopicActivity extends BaseActivity {
37+
private static String Key_Node_ID = "Key_Node_ID";
38+
private static String Key_Node_Name = "Key_Node_Name";
39+
40+
public static void newInstance(Context context, int nodeId, String nodeName) {
41+
Intent intent = new Intent(context, TopicActivity.class);
42+
intent.putExtra(Key_Node_ID, nodeId);
43+
intent.putExtra(Key_Node_Name, nodeName);
44+
context.startActivity(intent);
45+
}
46+
47+
@Override protected int getLayoutId() {
48+
return R.layout.activity_topic;
49+
}
50+
51+
@Override protected void initViews(ViewHolder holder, View root) {
52+
Intent intent = getIntent();
53+
int NodeId = intent.getIntExtra(Key_Node_ID, 0);
54+
String NodeName = intent.getStringExtra(Key_Node_Name);
55+
setTitle(NodeName);
56+
NodeTopicListFragment fragment = NodeTopicListFragment.newInstance(NodeId);
57+
FragmentManager fragmentManager = getSupportFragmentManager();
58+
FragmentTransaction transaction = fragmentManager.beginTransaction();
59+
transaction.add(R.id.fragment, fragment);
60+
transaction.commit();
61+
}
62+
}

diycode-app/src/main/java/com/gcssloop/diycode/base/app/RefreshRecyclerFragment.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ protected void refresh() {
129129

130130
protected void loadMore() {
131131
if (!loadMoreEnable) return;
132+
if (mState == STATE_NO_MORE) return;
132133
String uuid = request(pageIndex * pageCount, pageCount);
133134
mPostTypes.put(uuid, POST_LOAD_MORE);
134135
pageIndex++;
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* Copyright 2017 GcsSloop
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* Last modified 2017-04-09 19:30:45
17+
*
18+
* GitHub: https://github.com/GcsSloop
19+
* Website: http://www.gcssloop.com
20+
* Weibo: http://weibo.com/GcsSloop
21+
*/
22+
23+
package com.gcssloop.diycode.fragment;
24+
25+
import android.content.Context;
26+
import android.os.Bundle;
27+
import android.support.annotation.NonNull;
28+
import android.support.v7.widget.RecyclerView;
29+
30+
import com.gcssloop.diycode.base.app.RefreshRecyclerFragment;
31+
import com.gcssloop.diycode.base.recyclerview.SpeedyLinearLayoutManager;
32+
import com.gcssloop.diycode.fragment.provider.TopicProvider;
33+
import com.gcssloop.diycode_sdk.api.topic.bean.Topic;
34+
import com.gcssloop.diycode_sdk.api.topic.event.GetTopicsListEvent;
35+
import com.gcssloop.recyclerview.adapter.multitype.HeaderFooterAdapter;
36+
37+
public class NodeTopicListFragment extends RefreshRecyclerFragment<Topic, GetTopicsListEvent> {
38+
private static String Key_Node_ID = "Key_Node_ID";
39+
private int mNodeId = 0;
40+
41+
public static NodeTopicListFragment newInstance(int nodeId) {
42+
Bundle args = new Bundle();
43+
args.putInt(Key_Node_ID, nodeId);
44+
NodeTopicListFragment fragment = new NodeTopicListFragment();
45+
fragment.setArguments(args);
46+
return fragment;
47+
}
48+
49+
@Override public void initData(HeaderFooterAdapter adapter) {
50+
mNodeId = getArguments().getInt(Key_Node_ID, 0);
51+
loadMore();
52+
}
53+
54+
@Override
55+
protected void setRecyclerViewAdapter(Context context, RecyclerView recyclerView,
56+
HeaderFooterAdapter adapter) {
57+
adapter.register(Topic.class, new TopicProvider(getContext()));
58+
}
59+
60+
@NonNull @Override protected RecyclerView.LayoutManager getRecyclerViewLayoutManager() {
61+
return new SpeedyLinearLayoutManager(getContext());
62+
}
63+
64+
@NonNull @Override protected String request(int offset, int limit) {
65+
return mDiycode.getTopicsList(null, mNodeId, offset, limit);
66+
}
67+
68+
@Override protected void onRefresh(GetTopicsListEvent event, HeaderFooterAdapter adapter) {
69+
adapter.clearDatas();
70+
adapter.addDatas(event.getBean());
71+
}
72+
73+
@Override protected void onLoadMore(GetTopicsListEvent event, HeaderFooterAdapter adapter) {
74+
adapter.addDatas(event.getBean());
75+
}
76+
77+
@Override protected void onError(GetTopicsListEvent event, String postType) {
78+
toast("加载错误");
79+
}
80+
}

diycode-app/src/main/java/com/gcssloop/diycode/fragment/provider/TopicProvider.java

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@
2323
package com.gcssloop.diycode.fragment.provider;
2424

2525
import android.content.Context;
26-
import android.content.Intent;
2726
import android.support.annotation.NonNull;
2827
import android.view.View;
2928
import android.widget.ImageView;
3029

3130
import com.bumptech.glide.Glide;
3231
import com.bumptech.glide.load.engine.DiskCacheStrategy;
3332
import com.gcssloop.diycode.R;
33+
import com.gcssloop.diycode.activity.TopicActivity;
3434
import com.gcssloop.diycode.activity.TopicContentActivity;
3535
import com.gcssloop.diycode.activity.UserActivity;
3636
import com.gcssloop.diycode.utils.TimeUtil;
@@ -40,11 +40,9 @@
4040
import com.gcssloop.recyclerview.adapter.multitype.BaseViewProvider;
4141

4242
public class TopicProvider extends BaseViewProvider<Topic> {
43-
private Context mContext;
4443

4544
public TopicProvider(@NonNull Context context) {
4645
super(context, R.layout.item_topic);
47-
mContext = context;
4846
}
4947

5048
/**
@@ -69,23 +67,26 @@ public void onBindView(RecyclerViewHolder holder, final Topic bean) {
6967
url2 = url.replace("large_avatar", "avatar");
7068
Glide.with(mContext).load(url2).diskCacheStrategy(DiskCacheStrategy.RESULT).into(imageView);
7169

72-
String state = "评论 "+bean.getReplies_count();
70+
String state = "评论 " + bean.getReplies_count();
7371
holder.setText(R.id.state, state);
7472

75-
holder.setOnClickListener(new View.OnClickListener() {
76-
@Override
77-
public void onClick(View v) {
78-
Intent intent = new Intent(mContext, UserActivity.class);
79-
intent.putExtra(UserActivity.USER, user);
80-
mContext.startActivity(intent);
73+
View.OnClickListener listener = new View.OnClickListener() {
74+
@Override public void onClick(View v) {
75+
switch (v.getId()) {
76+
case R.id.avatar:
77+
case R.id.username:
78+
UserActivity.newInstance(mContext, user);
79+
break;
80+
case R.id.item:
81+
TopicContentActivity.newInstance(mContext, bean);
82+
break;
83+
case R.id.node_name:
84+
TopicActivity.newInstance(mContext, bean.getNode_id(), bean.getNode_name());
85+
break;
86+
}
8187
}
82-
}, R.id.avatar, R.id.username);
88+
};
8389

84-
holder.get(R.id.item).setOnClickListener(new View.OnClickListener() {
85-
@Override
86-
public void onClick(View v) {
87-
TopicContentActivity.newInstance(mContext, bean);
88-
}
89-
});
90+
holder.setOnClickListener(listener, R.id.avatar, R.id.username, R.id.item, R.id.node_name);
9091
}
9192
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
~ Copyright 2017 GcsSloop
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License");
6+
~ you may not use this file except in compliance with the License.
7+
~ You may obtain a copy of the License at
8+
~
9+
~ http://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
~
17+
~ Last modified 2017-04-09 19:39:57
18+
~
19+
~ GitHub: https://github.com/GcsSloop
20+
~ Website: http://www.gcssloop.com
21+
~ Weibo: http://weibo.com/GcsSloop
22+
-->
23+
24+
<LinearLayout
25+
xmlns:android="http://schemas.android.com/apk/res/android"
26+
xmlns:tools="http://schemas.android.com/tools"
27+
android:id="@+id/activity_topic"
28+
android:layout_width="match_parent"
29+
android:layout_height="match_parent"
30+
android:orientation="vertical"
31+
tools:context="com.gcssloop.diycode.activity.TopicActivity">
32+
33+
<android.support.v7.widget.Toolbar
34+
android:id="@+id/toolbar"
35+
android:layout_width="match_parent"
36+
android:layout_height="wrap_content"/>
37+
38+
<FrameLayout
39+
android:id="@+id/fragment"
40+
android:layout_width="match_parent"
41+
android:layout_height="match_parent"/>
42+
43+
</LinearLayout>

0 commit comments

Comments
 (0)