Skip to content

Commit 1f97b24

Browse files
author
Othershe
committed
整理代码
1 parent 19bc6e7 commit 1f97b24

29 files changed

+293
-44
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package="com.otherhshe.niceread">
44

55
<uses-permission android:name="android.permission.INTERNET" />
6+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
67

78
<application
89
android:name=".NiceReadApplication"
@@ -25,8 +26,9 @@
2526

2627
<activity android:name=".ui.activity.GankDetailActivity" />
2728
<activity android:name=".ui.activity.GirlDetailActivity" />
29+
<activity android:name=".ui.activity.SetActivity" />
2830

29-
<service android:name=".sevice.DataService"/>
31+
<service android:name=".sevice.DataService" />
3032
</application>
3133

3234
</manifest>

app/src/main/java/com/otherhshe/niceread/presenter/GankItemPresenter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.otherhshe.niceread.presenter;
22

33
import com.otherhshe.niceread.data.GankItemData;
4+
import com.otherhshe.niceread.model.IGankItemModel;
45
import com.otherhshe.niceread.model.impl.GankItemModelImpl;
56
import com.otherhshe.niceread.rx.RxManager;
67
import com.otherhshe.niceread.rx.RxSubscriber;
@@ -13,7 +14,7 @@
1314
* Time: 2016/8/12 14:29
1415
*/
1516
public class GankItemPresenter extends BasePresenter<GankItemView> {
16-
private GankItemModelImpl mModel;
17+
private IGankItemModel mModel;
1718

1819
public GankItemPresenter() {
1920
mModel = new GankItemModelImpl();

app/src/main/java/com/otherhshe/niceread/presenter/GirlDetailPresenter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.otherhshe.niceread.presenter;
22

3+
import com.otherhshe.niceread.model.IGirlDetailModel;
34
import com.otherhshe.niceread.model.impl.GirlDetailModelImpl;
45
import com.otherhshe.niceread.rx.RxManager;
56
import com.otherhshe.niceread.rx.RxSubscriber;
@@ -11,7 +12,7 @@
1112
* Time: 2016/8/12 14:29
1213
*/
1314
public class GirlDetailPresenter extends BasePresenter<GirlDetailView> {
14-
private GirlDetailModelImpl mModel;
15+
private IGirlDetailModel mModel;
1516

1617
public GirlDetailPresenter() {
1718
mModel = new GirlDetailModelImpl();

app/src/main/java/com/otherhshe/niceread/presenter/GirlItemPresenter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.otherhshe.niceread.presenter;
22

3+
import com.otherhshe.niceread.model.IGirlItemModel;
34
import com.otherhshe.niceread.model.impl.GirlItemModelImpl;
45
import com.otherhshe.niceread.rx.RxManager;
56
import com.otherhshe.niceread.rx.RxSubscriber;
@@ -11,7 +12,7 @@
1112
* Time: 2016/8/12 14:29
1213
*/
1314
public class GirlItemPresenter extends BasePresenter<GirlItemView> {
14-
private GirlItemModelImpl mModel;
15+
private IGirlItemModel mModel;
1516

1617
public GirlItemPresenter() {
1718
mModel = new GirlItemModelImpl();

app/src/main/java/com/otherhshe/niceread/presenter/SplashPresenter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.otherhshe.niceread.presenter;
22

33
import com.otherhshe.niceread.data.SplashData;
4+
import com.otherhshe.niceread.model.ISplashModel;
45
import com.otherhshe.niceread.model.impl.SplashModelImpl;
56
import com.otherhshe.niceread.rx.RxManager;
67
import com.otherhshe.niceread.rx.RxSubscriber;
@@ -11,7 +12,7 @@
1112
* Time: 2016/8/11 11:26
1213
*/
1314
public class SplashPresenter extends BasePresenter<SplashView> {
14-
private SplashModelImpl mModel;
15+
private ISplashModel mModel;
1516

1617
public SplashPresenter() {
1718
mModel = new SplashModelImpl();

app/src/main/java/com/otherhshe/niceread/ui/activity/BaseActivity.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
package com.otherhshe.niceread.ui.activity;
22

33
import android.content.Context;
4+
import android.graphics.Color;
5+
import android.os.Build;
46
import android.os.Bundle;
57
import android.support.annotation.Nullable;
68
import android.support.v7.app.AppCompatActivity;
9+
import android.view.View;
10+
import android.view.Window;
11+
import android.view.WindowManager;
712

813
import butterknife.ButterKnife;
914
import butterknife.Unbinder;
@@ -31,11 +36,25 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
3136
mContext = this;
3237
mUnbinder = ButterKnife.bind(this);
3338

39+
40+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {//5.0 全透明状态栏
41+
View decorView = getWindow().getDecorView();
42+
int option = View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
43+
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
44+
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
45+
decorView.setSystemUiVisibility(option);
46+
getWindow().setNavigationBarColor(Color.TRANSPARENT);
47+
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {//4.4 全透明状态栏
48+
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
49+
}
50+
51+
3452
initData();
3553

3654
initView();
3755
}
3856

57+
3958
@Override
4059
protected void onDestroy() {
4160
mUnbinder.unbind();

app/src/main/java/com/otherhshe/niceread/ui/activity/MainActivity.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.otherhshe.niceread.ui.activity;
22

3+
import android.content.Intent;
34
import android.os.Handler;
45
import android.support.design.widget.NavigationView;
56
import android.support.v4.app.FragmentTransaction;
@@ -96,12 +97,11 @@ public boolean onNavigationItemSelected(MenuItem item) {
9697
case R.id.nav_girl:
9798
doReplace(ResourceUtil.resToStr(mContext, R.string.girl));
9899
break;
99-
case R.id.nav_video:
100-
doReplace(ResourceUtil.resToStr(mContext, R.string.video));
101-
break;
102100
case R.id.nav_share:
101+
103102
break;
104103
case R.id.nav_set:
104+
openSet();
105105
break;
106106
case R.id.nav_about:
107107
break;
@@ -126,6 +126,11 @@ private void replaceFragment(BaseFragment fragment, String tag) {
126126
transaction.commit();
127127
}
128128

129+
private void openSet() {
130+
Intent intent = new Intent(mContext, SetActivity.class);
131+
startActivity(intent);
132+
}
133+
129134
@Override
130135
public void onBackPressed() {
131136
if (mDrawerLayout.isDrawerOpen(GravityCompat.START)) {

app/src/main/java/com/otherhshe/niceread/ui/activity/SetActivity.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,38 @@
11
package com.otherhshe.niceread.ui.activity;
22

3+
import android.support.v7.widget.Toolbar;
4+
import android.view.View;
5+
6+
import com.otherhshe.niceread.R;
7+
8+
import butterknife.BindView;
9+
310
/**
411
* Author: Othershe
512
* Time: 2016/8/22 17:45
613
*/
714
public class SetActivity extends BaseActivity {
15+
@BindView(R.id.set_toolbar)
16+
Toolbar mToolbar;
17+
818
@Override
919
protected int initLayoutId() {
10-
return 0;
20+
return R.layout.activity_set;
1121
}
1222

1323
@Override
1424
protected void initView() {
25+
setSupportActionBar(mToolbar);
26+
if (getSupportActionBar() != null) {
27+
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
28+
}
1529

30+
mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
31+
@Override
32+
public void onClick(View view) {
33+
finish();
34+
}
35+
});
1636
}
1737

1838
@Override

app/src/main/java/com/otherhshe/niceread/ui/activity/SplashActivity.java

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@
77
import com.otherhshe.niceread.R;
88
import com.otherhshe.niceread.data.SplashData;
99
import com.otherhshe.niceread.presenter.SplashPresenter;
10+
import com.otherhshe.niceread.ui.fragemnt.SetFragment;
1011
import com.otherhshe.niceread.ui.view.SplashView;
12+
import com.otherhshe.niceread.utils.DateUtil;
1113
import com.otherhshe.niceread.utils.ImageLoader;
14+
import com.otherhshe.niceread.utils.NetUtil;
15+
import com.otherhshe.niceread.utils.SPUtil;
1216

1317
import butterknife.BindView;
1418

@@ -17,6 +21,8 @@
1721
* Time: 2016/8/11 11:22
1822
*/
1923
public class SplashActivity extends BaseMvpActivity<SplashView, SplashPresenter> implements SplashView {
24+
private String mTimeLine;
25+
2026
@BindView(R.id.splash_iv)
2127
ImageView mSplashIv;
2228

@@ -27,7 +33,9 @@ protected SplashPresenter initPresenter() {
2733

2834
@Override
2935
protected void fetchData() {
30-
mPresenter.getSplashPic();
36+
if (!DateUtil.formatDate().equals(mTimeLine)) {
37+
mPresenter.getSplashPic();
38+
}
3139
}
3240

3341
@Override
@@ -37,18 +45,32 @@ protected int initLayoutId() {
3745

3846
@Override
3947
protected void initView() {
48+
if (!(Boolean) SPUtil.get(SetFragment.SPLASH, false) || !NetUtil.isConnected(mContext)) {
49+
ImageLoader.load(mContext, R.drawable.original_splash, mSplashIv);
50+
} else {
51+
ImageLoader.load(mContext, (String) SPUtil.get("splash_url", ""), mSplashIv);
52+
}
4053

54+
startDelay();
4155
}
4256

4357
@Override
4458
protected void initData() {
45-
59+
mTimeLine = (String) SPUtil.get("splash_time", "");
4660
}
4761

4862
@Override
4963
public void onSuccess(SplashData data) {
50-
ImageLoader.load(mContext, data.getUrl(), mSplashIv);
64+
SPUtil.save("splash_time", DateUtil.formatDate());
65+
SPUtil.save("splash_url", data.getUrl());
66+
}
67+
68+
@Override
69+
public void onError() {
5170

71+
}
72+
73+
private void startDelay() {
5274
new Handler().postDelayed(new Runnable() {
5375
@Override
5476
public void run() {
@@ -58,9 +80,4 @@ public void run() {
5880
}
5981
}, 2000);
6082
}
61-
62-
@Override
63-
public void onError() {
64-
finish();
65-
}
6683
}

app/src/main/java/com/otherhshe/niceread/ui/fragemnt/GankItemFragment.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
109109
super.onScrollStateChanged(recyclerView, newState);
110110
if (newState == RecyclerView.SCROLL_STATE_IDLE) {
111111
mLastVisibleItemPosition = layoutManager.findLastVisibleItemPosition();
112+
//防止重复请求
113+
if (PAGE_COUNT == mTempPageCount) {
114+
return;
115+
}
116+
112117
if (mLastVisibleItemPosition > 0 && mLastVisibleItemPosition + 1 == mGankItemAdapter.getItemCount()) {
113118
//已到达底部,开始加载更多
114119
isLoadMore = true;

app/src/main/java/com/otherhshe/niceread/ui/fragemnt/GirlDetailFragment.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,11 @@
1818
public class GirlDetailFragment extends BaseFragment {
1919
private static final String URL = "url";
2020

21-
private boolean mIsViewInitiated;
22-
private boolean mIsVisibleToUser;
23-
private boolean mIsDataInitiated;
24-
2521
private String mUrl;
2622

2723
@BindView(R.id.girl_detail_iv)
2824
PhotoView mImageView;
2925

30-
@OnClick(R.id.girl_detail_iv)
31-
void onClic() {
32-
33-
}
34-
3526
@Override
3627
protected int initLayoutId() {
3728
return R.layout.fragment_girl_detail;

app/src/main/java/com/otherhshe/niceread/ui/fragemnt/GirlItemFragment.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
104104
super.onScrollStateChanged(recyclerView, newState);
105105

106106
int[] lastVisiblePositions = layoutManager.findLastVisibleItemPositions(new int[layoutManager.getSpanCount()]);
107+
//防止重复请求
108+
if (PAGE_COUNT == mTempPageCount) {
109+
return;
110+
}
111+
107112
if (findMax(lastVisiblePositions) + 1 == mGirlItemAdapter.getItemCount() && mGirlItemAdapter.getItemCount() > 1) {
108113
//已到达底部,开始加载更多
109114
isLoadMore = true;
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package com.otherhshe.niceread.ui.fragemnt;
2+
3+
import android.content.Context;
4+
import android.content.Intent;
5+
import android.net.Uri;
6+
import android.os.Bundle;
7+
import android.preference.Preference;
8+
import android.preference.PreferenceFragment;
9+
10+
import com.otherhshe.niceread.R;
11+
import com.otherhshe.niceread.utils.FileUtil;
12+
13+
import java.io.File;
14+
15+
/**
16+
* Author: Othershe
17+
* Time: 2016/8/23 11:00
18+
*/
19+
public class SetFragment extends PreferenceFragment implements Preference.OnPreferenceClickListener, Preference.OnPreferenceChangeListener {
20+
private static final String CLEAR_CACHE = "clear_cache";
21+
public static final String SPLASH = "original_splash";
22+
23+
@Override
24+
public void onCreate(Bundle savedInstanceState) {
25+
super.onCreate(savedInstanceState);
26+
getPreferenceManager().setSharedPreferencesName("niceread");//设置参数与值保存文件
27+
addPreferencesFromResource(R.xml.set_preference);
28+
29+
init();
30+
}
31+
32+
private void init() {
33+
Preference clearCache = findPreference(CLEAR_CACHE);
34+
clearCache.setSummary(clearCache.getSummary() + getCacheSize());
35+
clearCache.setOnPreferenceClickListener(this);
36+
37+
Preference splash = findPreference(SPLASH);
38+
splash.setOnPreferenceChangeListener(this);
39+
}
40+
41+
private String getCacheSize() {
42+
File file = getActivity().getApplicationContext().getCacheDir();
43+
return FileUtil.getFileSize(file);
44+
}
45+
46+
@Override
47+
public boolean onPreferenceClick(Preference preference) {
48+
switch (preference.getKey()) {
49+
case CLEAR_CACHE:
50+
openAppInfo(getActivity());
51+
break;
52+
}
53+
return true;
54+
}
55+
56+
public static void openAppInfo(Context context) {
57+
Intent i = new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
58+
i.addCategory(Intent.CATEGORY_DEFAULT);
59+
i.setData(Uri.parse("package:" + context.getApplicationContext().getPackageName()));
60+
context.startActivity(i);
61+
}
62+
63+
@Override
64+
public boolean onPreferenceChange(Preference preference, Object o) {
65+
return true;
66+
}
67+
}

0 commit comments

Comments
 (0)