Skip to content

Commit 43957e6

Browse files
committed
add zhihu
1 parent 0f1697a commit 43957e6

File tree

12 files changed

+304
-0
lines changed

12 files changed

+304
-0
lines changed

app/src/main/java/com/codeest/geeknews/base/BaseActivity.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
/**
2222
* Created by codeest on 2016/8/2.
23+
* MVP activity基类
2324
*/
2425
public abstract class BaseActivity<T extends BasePresenter> extends SwipeBackActivity implements BaseView{
2526

app/src/main/java/com/codeest/geeknews/base/BaseFragment.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
import android.view.View;
1111
import android.view.ViewGroup;
1212

13+
import com.codeest.geeknews.app.App;
14+
import com.codeest.geeknews.di.component.DaggerFragmentComponent;
15+
import com.codeest.geeknews.di.component.FragmentComponent;
16+
import com.codeest.geeknews.di.module.FragmentModule;
1317
import com.umeng.analytics.MobclickAgent;
1418

1519
import javax.inject.Inject;
@@ -19,6 +23,7 @@
1923

2024
/**
2125
* Created by codeest on 2016/8/2.
26+
* MVP Fragment基类
2227
*/
2328
public abstract class BaseFragment<T extends BasePresenter> extends SwipeBackFragment implements BaseView{
2429

@@ -52,6 +57,16 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
5257
}
5358
}
5459

60+
protected FragmentComponent getFragmentComponent(){
61+
return DaggerFragmentComponent.builder()
62+
.appComponent(App.getAppComponent())
63+
.fragmentModule(getFragmentModule())
64+
.build();
65+
}
66+
67+
protected FragmentModule getFragmentModule(){
68+
return new FragmentModule(this);
69+
}
5570

5671
@Override
5772
public void onSaveInstanceState(Bundle outState) {

app/src/main/java/com/codeest/geeknews/base/BasePresenter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
/**
44
* Created by codeest on 2016/8/2.
5+
* Presenter基类
56
*/
67
public interface BasePresenter<T extends BaseView>{
78

app/src/main/java/com/codeest/geeknews/base/BaseView.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
/**
44
* Created by codeest on 2016/8/2.
5+
* View基类
56
*/
67
public interface BaseView {
78

app/src/main/java/com/codeest/geeknews/base/RxPresenter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
/**
77
* Created by codeest on 2016/8/2.
8+
* 基于Rx的Presenter封装
89
*/
910
public class RxPresenter<T extends BaseView> implements BasePresenter<T> {
1011

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package com.codeest.geeknews.base;
2+
3+
import android.app.Activity;
4+
import android.os.Bundle;
5+
import android.support.annotation.Nullable;
6+
import android.support.v7.widget.Toolbar;
7+
import android.view.View;
8+
9+
import com.codeest.geeknews.app.App;
10+
import com.codeest.geeknews.di.component.ActivityComponent;
11+
import com.codeest.geeknews.di.component.DaggerActivityComponent;
12+
import com.codeest.geeknews.di.module.ActivityModule;
13+
import com.umeng.analytics.MobclickAgent;
14+
15+
import butterknife.ButterKnife;
16+
import me.yokeyword.fragmentation_swipeback.SwipeBackActivity;
17+
18+
/**
19+
* Created by codeest on 16/8/11.
20+
* 无MVP的activity基类
21+
*/
22+
23+
public abstract class SimpleActivity extends SwipeBackActivity {
24+
25+
protected Activity mContext;
26+
27+
@Override
28+
protected void onCreate(@Nullable Bundle savedInstanceState) {
29+
super.onCreate(savedInstanceState);
30+
setContentView(getLayout());
31+
ButterKnife.bind(this);
32+
mContext = this;
33+
App.getInstance().addActivity(this);
34+
initEventAndData();
35+
}
36+
37+
@Override
38+
protected void onResume() {
39+
super.onResume();
40+
MobclickAgent.onResume(this);
41+
}
42+
43+
protected void setToolBar(Toolbar toolbar, String title) {
44+
toolbar.setTitle(title);
45+
setSupportActionBar(toolbar);
46+
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
47+
getSupportActionBar().setDisplayShowHomeEnabled(true);
48+
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
49+
@Override
50+
public void onClick(View view) {
51+
onBackPressed();
52+
}
53+
});
54+
}
55+
56+
protected ActivityComponent getActivityComponent(){
57+
return DaggerActivityComponent.builder()
58+
.appComponent(App.getAppComponent())
59+
.activityModule(getActivityModule())
60+
.build();
61+
}
62+
63+
protected ActivityModule getActivityModule(){
64+
return new ActivityModule(this);
65+
}
66+
67+
@Override
68+
protected void onPause() {
69+
super.onPause();
70+
MobclickAgent.onPause(this);
71+
}
72+
73+
@Override
74+
protected void onDestroy() {
75+
super.onDestroy();
76+
App.getInstance().removeActivity(this);
77+
}
78+
79+
protected abstract int getLayout();
80+
protected abstract void initEventAndData();
81+
}
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
package com.codeest.geeknews.base;
2+
3+
import android.app.Activity;
4+
import android.content.Context;
5+
import android.os.Bundle;
6+
import android.support.annotation.Nullable;
7+
import android.support.v4.app.FragmentTransaction;
8+
import android.view.LayoutInflater;
9+
import android.view.View;
10+
import android.view.ViewGroup;
11+
12+
import com.codeest.geeknews.app.App;
13+
import com.codeest.geeknews.di.component.DaggerFragmentComponent;
14+
import com.codeest.geeknews.di.component.FragmentComponent;
15+
import com.codeest.geeknews.di.module.FragmentModule;
16+
import com.umeng.analytics.MobclickAgent;
17+
18+
import butterknife.ButterKnife;
19+
import me.yokeyword.fragmentation_swipeback.SwipeBackFragment;
20+
21+
/**
22+
* Created by codeest on 16/8/11.
23+
* 无MVP的Fragment基类
24+
*/
25+
26+
public abstract class SimpleFragment extends SwipeBackFragment{
27+
28+
protected View mView;
29+
protected Activity mActivity;
30+
protected Context mContext;
31+
32+
private static final String STATE_SAVE_IS_HIDDEN = "STATE_SAVE_IS_HIDDEN";
33+
34+
@Override
35+
public void onAttach(Context context) {
36+
mActivity = (Activity) context;
37+
mContext = context;
38+
super.onAttach(context);
39+
}
40+
41+
@Override
42+
public void onCreate(@Nullable Bundle savedInstanceState) {
43+
super.onCreate(savedInstanceState);
44+
if (savedInstanceState != null) {
45+
boolean isSupportHidden = savedInstanceState.getBoolean(STATE_SAVE_IS_HIDDEN);
46+
FragmentTransaction ft = getFragmentManager().beginTransaction();
47+
if (isSupportHidden) {
48+
ft.hide(this);
49+
} else {
50+
ft.show(this);
51+
}
52+
ft.commit();
53+
}
54+
}
55+
56+
protected FragmentComponent getFragmentComponent(){
57+
return DaggerFragmentComponent.builder()
58+
.appComponent(App.getAppComponent())
59+
.fragmentModule(getFragmentModule())
60+
.build();
61+
}
62+
63+
protected FragmentModule getFragmentModule(){
64+
return new FragmentModule(this);
65+
}
66+
67+
@Override
68+
public void onSaveInstanceState(Bundle outState) {
69+
outState.putBoolean(STATE_SAVE_IS_HIDDEN, isHidden());
70+
}
71+
72+
@Nullable
73+
@Override
74+
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
75+
mView = inflater.inflate(getLayoutId(), null);
76+
initInject();
77+
return attachToSwipeBack(mView);
78+
}
79+
80+
@Override
81+
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
82+
super.onViewCreated(view, savedInstanceState);
83+
ButterKnife.bind(this, view);
84+
initEventAndData();
85+
}
86+
87+
@Override
88+
public void onResume() {
89+
super.onResume();
90+
MobclickAgent.onPageStart("Fragment");
91+
}
92+
93+
@Override
94+
public void onPause() {
95+
super.onPause();
96+
MobclickAgent.onPageEnd("Fragment");
97+
}
98+
99+
@Override
100+
public void onDestroyView() {
101+
super.onDestroyView();
102+
}
103+
104+
protected abstract void initInject();
105+
protected abstract int getLayoutId();
106+
protected abstract void initEventAndData();
107+
}

app/src/main/java/com/codeest/geeknews/di/component/FragmentComponent.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.codeest.geeknews.di.FragmentScope;
66
import com.codeest.geeknews.di.module.FragmentModule;
77
import com.codeest.geeknews.model.http.RetrofitHelper;
8+
import com.codeest.geeknews.ui.zhihu.fragment.ZhihuMainFragment;
89

910
import dagger.Component;
1011

@@ -20,4 +21,6 @@ public interface FragmentComponent {
2021

2122
Activity getActivity();
2223

24+
void inject(ZhihuMainFragment zhihuMainFragment);
25+
2326
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.codeest.geeknews.ui.zhihu.adapter;
2+
3+
import android.support.v4.app.Fragment;
4+
import android.support.v4.app.FragmentManager;
5+
import android.support.v4.app.FragmentPagerAdapter;
6+
7+
/**
8+
* Created by codeest on 16/8/11.
9+
*/
10+
11+
public class ZhihuMainAdapter extends FragmentPagerAdapter{
12+
public ZhihuMainAdapter(FragmentManager fm) {
13+
super(fm);
14+
}
15+
16+
@Override
17+
public Fragment getItem(int position) {
18+
return null;
19+
}
20+
21+
@Override
22+
public int getCount() {
23+
return 0;
24+
}
25+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.codeest.geeknews.ui.zhihu.fragment;
2+
3+
/**
4+
* Created by codeest on 16/8/11.
5+
*/
6+
7+
public class ZhihuChildFragment {
8+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.codeest.geeknews.ui.zhihu.fragment;
2+
3+
import android.support.design.widget.TabLayout;
4+
import android.support.v4.view.ViewPager;
5+
6+
import com.codeest.geeknews.R;
7+
import com.codeest.geeknews.base.SimpleFragment;
8+
9+
import butterknife.BindView;
10+
11+
/**
12+
* Created by codeest on 16/8/11.
13+
*/
14+
15+
public class ZhihuMainFragment extends SimpleFragment{
16+
17+
@BindView(R.id.tab_zhihu_main)
18+
TabLayout mTabLayout;
19+
@BindView(R.id.vp_zhihu_main)
20+
ViewPager mViewPager;
21+
22+
@Override
23+
protected void initInject() {
24+
getFragmentComponent().inject(this);
25+
}
26+
27+
@Override
28+
protected int getLayoutId() {
29+
return R.layout.fragment_zhihu_main;
30+
}
31+
32+
@Override
33+
protected void initEventAndData() {
34+
35+
}
36+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:layout_width="match_parent"
4+
android:layout_height="match_parent"
5+
xmlns:app="http://schemas.android.com/apk/res-auto"
6+
android:orientation="vertical">
7+
8+
<android.support.design.widget.TabLayout
9+
android:id="@+id/tab_zhihu_main"
10+
android:layout_width="match_parent"
11+
android:layout_height="wrap_content"
12+
android:background="@color/colorPrimary"
13+
app:tabIndicatorColor="@android:color/white"
14+
app:tabSelectedTextColor="@android:color/white"
15+
app:tabTextColor="@android:color/white"
16+
/>
17+
18+
<android.support.v4.view.ViewPager
19+
android:id="@+id/vp_zhihu_main"
20+
android:layout_width="fill_parent"
21+
android:layout_height="0dp"
22+
android:layout_weight="1"
23+
/>
24+
25+
</LinearLayout>

0 commit comments

Comments
 (0)