Skip to content

Commit 315129a

Browse files
committed
首页
1 parent a1fd64c commit 315129a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+715
-35
lines changed

.idea/modules.xml

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
apply plugin: 'com.android.application'
2+
apply plugin: 'com.jakewharton.butterknife'
23

34
android {
45
compileSdkVersion 24
56
buildToolsVersion "25.0.0"
67

78
defaultConfig {
89
applicationId "com.rae.cnblogs"
9-
minSdkVersion 14
10+
minSdkVersion 15
1011
targetSdkVersion 24
1112
versionCode 1
1213
versionName "1.0"
@@ -20,13 +21,20 @@ android {
2021
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
2122
}
2223
}
24+
sourceSets { main { assets.srcDirs = ['src/main/assets', 'src/main/assets/'] } }
2325
}
2426

2527
dependencies {
26-
compile fileTree(dir: 'libs', include: ['*.jar'])
28+
compile fileTree(include: ['*.jar'], dir: 'libs')
2729
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
2830
exclude group: 'com.android.support', module: 'support-annotations'
2931
})
32+
compile project(':sdk')
3033
compile 'com.android.support:appcompat-v7:24.2.1'
3134
testCompile 'junit:junit:4.12'
35+
compile 'com.android.support:design:24.2.1'
36+
compile 'com.jakewharton:butterknife:8.4.0'
37+
annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'
38+
compile 'in.srain.cube:ultra-ptr:1.0.11'
39+
compile 'com.jcodecraeer:xrecyclerview:1.3.2'
3240
}

app/src/main/AndroidManifest.xml

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
package="com.rae.cnblogs">
44

55
<application
6+
android:name=".CnblogsApplication"
67
android:allowBackup="true"
78
android:icon="@mipmap/ic_launcher"
89
android:label="@string/app_name"
910
android:supportsRtl="true"
1011
android:theme="@style/AppTheme">
11-
<activity android:name=".MainActivity">
12+
<activity android:name=".activity.MainActivity">
1213
<intent-filter>
1314
<action android:name="android.intent.action.MAIN"/>
1415

app/src/main/assets/fonts/cnblogs.ttf

10.5 MB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.rae.cnblogs;
2+
3+
import android.app.Application;
4+
5+
/**
6+
* 应用程序
7+
* Created by ChenRui on 2016/12/1 21:35.
8+
*/
9+
public class CnblogsApplication extends Application {
10+
}

app/src/main/java/com/rae/cnblogs/MainActivity.java

-13
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.rae.cnblogs.activity;
2+
3+
import android.support.v7.app.AppCompatActivity;
4+
5+
import butterknife.ButterKnife;
6+
7+
/**
8+
* 基类
9+
* Created by ChenRui on 2016/12/1 21:35.
10+
*/
11+
public abstract class BaseActivity extends AppCompatActivity {
12+
13+
protected void bindView() {
14+
ButterKnife.bind(this);
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package com.rae.cnblogs.activity;
2+
3+
import android.os.Bundle;
4+
import android.support.design.widget.TabLayout;
5+
import android.support.v4.app.Fragment;
6+
import android.support.v4.view.ViewPager;
7+
import android.view.View;
8+
import android.widget.TextView;
9+
10+
import com.rae.cnblogs.R;
11+
import com.rae.cnblogs.fragment.HomeFragment;
12+
import com.rae.core.fm.RaeFragmentAdapter;
13+
14+
import butterknife.BindView;
15+
16+
public class MainActivity extends BaseActivity {
17+
18+
@BindView(R.id.vp_main)
19+
ViewPager mViewPager;
20+
21+
@BindView(R.id.tab_main)
22+
TabLayout mTabLayout;
23+
24+
private RaeFragmentAdapter mFragmentAdapter;
25+
26+
@Override
27+
protected void onCreate(Bundle savedInstanceState) {
28+
super.onCreate(savedInstanceState);
29+
setContentView(R.layout.activity_main);
30+
bindView();
31+
32+
mFragmentAdapter = new RaeFragmentAdapter(getSupportFragmentManager());
33+
34+
// 初始化TAB
35+
addTab(R.string.tab_home, R.drawable.tab_home, new HomeFragment());
36+
addTab(R.string.tab_news, R.drawable.tab_news, new HomeFragment());
37+
addTab(R.string.tab_library, R.drawable.tab_library, new HomeFragment());
38+
addTab(R.string.tab_mine, R.drawable.tab_mine, new HomeFragment());
39+
40+
mViewPager.setOffscreenPageLimit(4);
41+
mViewPager.setAdapter(mFragmentAdapter);
42+
43+
// 联动
44+
mTabLayout.addOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(mViewPager));
45+
mViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(mTabLayout));
46+
47+
}
48+
49+
private void addTab(int resId, int iconId, Fragment fragment) {
50+
TabLayout.Tab tab = mTabLayout.newTab();
51+
View tabView = getLayoutInflater().inflate(R.layout.tab_view, null);
52+
TextView v = (TextView) tabView.findViewById(R.id.tv_tab_view);
53+
v.setText(resId);
54+
v.setCompoundDrawablesWithIntrinsicBounds(0, iconId, 0, 0);
55+
tab.setCustomView(tabView);
56+
mTabLayout.addTab(tab);
57+
mFragmentAdapter.add(getString(resId), fragment);
58+
}
59+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.rae.cnblogs.fragment;
2+
3+
import android.os.Bundle;
4+
import android.support.annotation.Nullable;
5+
import android.support.v4.app.Fragment;
6+
import android.view.LayoutInflater;
7+
import android.view.View;
8+
import android.view.ViewGroup;
9+
10+
import butterknife.ButterKnife;
11+
12+
/**
13+
* Created by ChenRui on 2016/12/1 23:51.
14+
*/
15+
public abstract class BaseFragment extends Fragment {
16+
17+
@Nullable
18+
@Override
19+
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
20+
View view = inflater.inflate(getLayoutId(), container, false);
21+
ButterKnife.bind(this, view);
22+
return view;
23+
}
24+
25+
protected abstract int getLayoutId();
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
package com.rae.cnblogs.fragment;
2+
3+
import android.os.Bundle;
4+
import android.support.annotation.Nullable;
5+
import android.support.v7.widget.RecyclerView;
6+
7+
import com.rae.cnblogs.R;
8+
import com.rae.cnblogs.presenter.CnblogsPresenterFactory;
9+
import com.rae.cnblogs.presenter.IBlogListPresenter;
10+
import com.rae.cnblogs.sdk.bean.Blog;
11+
import com.rae.cnblogs.widget.AppLayout;
12+
13+
import java.util.List;
14+
15+
import butterknife.BindView;
16+
17+
/**
18+
* Created by ChenRui on 2016/12/2 00:33.
19+
*/
20+
public class BlogListFragment extends BaseFragment implements IBlogListPresenter.IBlogListView {
21+
22+
private String mId;
23+
private String mParentId;
24+
25+
public static BlogListFragment newInstance(String id, String parentId) {
26+
27+
Bundle args = new Bundle();
28+
args.putString("id", id);
29+
args.putString("parentId", parentId);
30+
BlogListFragment fragment = new BlogListFragment();
31+
fragment.setArguments(args);
32+
return fragment;
33+
}
34+
35+
@BindView(R.id.content)
36+
AppLayout mAppLayout;
37+
38+
@BindView(R.id.rec_blog_list)
39+
RecyclerView mRecyclerView;
40+
41+
private IBlogListPresenter mBlogListPresenter;
42+
43+
@Override
44+
protected int getLayoutId() {
45+
return R.layout.fm_blog_list;
46+
}
47+
48+
@Override
49+
public void onCreate(@Nullable Bundle savedInstanceState) {
50+
super.onCreate(savedInstanceState);
51+
mBlogListPresenter = CnblogsPresenterFactory.getBlogListPresenter(getContext(), this);
52+
mId = getArguments().getString("id");
53+
mParentId = getArguments().getString("parentId");
54+
}
55+
56+
@Override
57+
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
58+
super.onActivityCreated(savedInstanceState);
59+
}
60+
61+
@Override
62+
public void onLoadBlogList(List<Blog> data) {
63+
64+
}
65+
66+
@Override
67+
public void onLoadFailed(String msg) {
68+
69+
}
70+
71+
@Override
72+
public int getPage() {
73+
return 1;
74+
}
75+
76+
@Override
77+
public String getCategoryId() {
78+
return mId;
79+
}
80+
81+
@Override
82+
public String getParentId() {
83+
return mParentId;
84+
}
85+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package com.rae.cnblogs.fragment;
2+
3+
import android.os.Bundle;
4+
import android.support.annotation.Nullable;
5+
import android.support.design.widget.TabLayout;
6+
import android.support.v4.view.ViewPager;
7+
import android.support.v7.widget.Toolbar;
8+
9+
import com.rae.cnblogs.R;
10+
import com.rae.cnblogs.presenter.CnblogsPresenterFactory;
11+
import com.rae.cnblogs.presenter.IHomePresenter;
12+
import com.rae.cnblogs.sdk.bean.Category;
13+
import com.rae.core.fm.RaeFragmentAdapter;
14+
15+
import java.util.List;
16+
17+
import butterknife.BindView;
18+
19+
/**
20+
* 首页
21+
* Created by ChenRui on 2016/12/1 22:34.
22+
*/
23+
public class HomeFragment extends BaseFragment implements IHomePresenter.IHomeView {
24+
25+
@BindView(R.id.tool_bar)
26+
Toolbar mToolbar;
27+
28+
@BindView(R.id.tab_category)
29+
TabLayout mTabLayout;
30+
31+
@BindView(R.id.vp_blog_list)
32+
ViewPager mViewPager;
33+
34+
private IHomePresenter mHomePresenter;
35+
36+
@Override
37+
protected int getLayoutId() {
38+
return R.layout.fm_home;
39+
}
40+
41+
@Override
42+
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
43+
super.onActivityCreated(savedInstanceState);
44+
mHomePresenter = CnblogsPresenterFactory.getHomePresenter(getContext(), this);
45+
mHomePresenter.start();
46+
}
47+
48+
@Override
49+
public void onLoadCategory(List<Category> data) {
50+
RaeFragmentAdapter adapter = new RaeFragmentAdapter(getChildFragmentManager());
51+
52+
for (Category category : data) {
53+
adapter.add(category.getName(), BlogListFragment.newInstance(category.getCategoryId(), category.getParentId()));
54+
}
55+
56+
mViewPager.setAdapter(adapter);
57+
mTabLayout.setupWithViewPager(mViewPager);
58+
59+
}
60+
61+
@Override
62+
public void onLoadFailed(String msg) {
63+
64+
}
65+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.rae.cnblogs.presenter;
2+
3+
import android.content.Context;
4+
5+
import com.rae.cnblogs.presenter.impl.BlogListPresenterImpl;
6+
import com.rae.cnblogs.presenter.impl.HomePresenterImpl;
7+
8+
/**
9+
* Created by ChenRui on 2016/12/2 00:23.
10+
*/
11+
public final class CnblogsPresenterFactory {
12+
13+
public static IHomePresenter getHomePresenter(Context context, IHomePresenter.IHomeView view) {
14+
return new HomePresenterImpl(context, view);
15+
}
16+
17+
public static IBlogListPresenter getBlogListPresenter(Context context, IBlogListPresenter.IBlogListView view) {
18+
return new BlogListPresenterImpl(context, view);
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.rae.cnblogs.presenter;
2+
3+
import com.rae.cnblogs.sdk.bean.Blog;
4+
5+
import java.util.List;
6+
7+
/**
8+
* 首页
9+
* Created by ChenRui on 2016/12/2 00:21.
10+
*/
11+
public interface IBlogListPresenter extends IRaePresenter {
12+
13+
interface IBlogListView {
14+
15+
void onLoadBlogList(List<Blog> data);
16+
17+
void onLoadFailed(String msg);
18+
19+
int getPage();
20+
21+
String getCategoryId();
22+
23+
String getParentId();
24+
}
25+
}

0 commit comments

Comments
 (0)