Skip to content

Commit 74b1f08

Browse files
author
Tneciv
committed
add swipe back
1 parent bd9231b commit 74b1f08

32 files changed

+622
-71
lines changed

app/build.gradle

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,21 @@ dependencies {
4141
compile fileTree(include: ['*.jar'], dir: 'libs')
4242
testCompile 'junit:junit:4.12'
4343
compile files('libs/Bughd_android_sdk_v1.3.7.jar')
44-
compile 'com.android.support:appcompat-v7:23.3.0'
45-
compile 'com.android.support:design:23.3.0'
46-
compile 'com.android.support:recyclerview-v7:23.3.0'
47-
compile 'com.android.support:support-v4:23.3.0'
48-
compile 'com.android.support:cardview-v7:23.3.0'
49-
compile 'com.android.support:palette-v7:23.3.0'
50-
compile 'com.google.code.gson:gson:2.5'
5144
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta2'
5245
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.4-beta2'
5346
testCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta2'
47+
provided 'de.greenrobot:eventbus-annotation-processor:3.0.0-beta1'
48+
compile 'com.android.support:appcompat-v7:23.4.0'
49+
compile 'com.android.support:design:23.4.0'
50+
compile 'com.android.support:recyclerview-v7:23.4.0'
51+
compile 'com.android.support:support-v4:23.4.0'
52+
compile 'com.android.support:cardview-v7:23.4.0'
53+
compile 'com.android.support:palette-v7:23.4.0'
54+
compile 'com.google.code.gson:gson:2.5'
5455
compile 'com.squareup.okhttp3:okhttp:3.2.0'
5556
compile 'com.squareup.okhttp3:okhttp-urlconnection:3.2.0'
5657
compile 'com.squareup.picasso:picasso:2.5.2'
5758
compile 'de.greenrobot:eventbus:3.0.0-beta1'
58-
provided 'de.greenrobot:eventbus-annotation-processor:3.0.0-beta1'
5959
compile 'com.jakewharton:butterknife:7.0.1'
6060
compile 'com.jakewharton:disklrucache:2.0.2'
6161
compile 'com.github.paolorotolo:appintro:3.4.0'
@@ -65,4 +65,5 @@ dependencies {
6565
compile 'com.nineoldandroids:library:2.4.0'
6666
compile 'net.yslibrary.licenseadapter:licenseadapter:1.2.1'
6767
compile 'com.google.guava:guava-io:r03'
68+
compile 'com.jude:swipebackhelper:3.0.4'
6869
}

app/src/main/AndroidManifest.xml

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3-
package="com.tneciv.zhihudaily">
3+
package="com.tneciv.zhihudaily">
44

5-
<uses-permission android:name="android.permission.INTERNET" />
6-
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
7-
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
8-
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
9-
<uses-permission android:name="android.permission.VIBRATE" />
5+
<uses-permission android:name="android.permission.INTERNET"/>
6+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
7+
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
8+
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
9+
<uses-permission android:name="android.permission.VIBRATE"/>
1010
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
11-
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
11+
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
1212

1313
<application
1414
android:name=".MyApplication"
@@ -22,9 +22,9 @@
2222
android:label="@string/app_name"
2323
android:theme="@style/AppTheme.NoActionBar">
2424
<intent-filter>
25-
<action android:name="android.intent.action.MAIN" />
25+
<action android:name="android.intent.action.MAIN"/>
2626

27-
<category android:name="android.intent.category.LAUNCHER" />
27+
<category android:name="android.intent.category.LAUNCHER"/>
2828
</intent-filter>
2929
</activity>
3030
<activity
@@ -34,16 +34,16 @@
3434
android:theme="@style/AppTheme.NoActionBar">
3535
<meta-data
3636
android:name="android.support.PARENT_ACTIVITY"
37-
android:value="com.tneciv.zhihudaily.home.view.MainActivity" />
37+
android:value="com.tneciv.zhihudaily.home.view.MainActivity"/>
3838
</activity>
3939
<activity
4040
android:name=".history.view.HistoryActivity"
4141
android:label="@string/HistoryDaily"
42-
android:theme="@style/AppTheme.NoActionBar" />
42+
android:theme="@style/AppTheme.NoActionBar"/>
4343
<activity
4444
android:name=".theme.view.ThemeActivity"
4545
android:label="@string/allSections"
46-
android:theme="@style/AppTheme.NoActionBar" />
46+
android:theme="@style/AppTheme.NoActionBar"/>
4747
<activity
4848
android:name=".about.AboutActivity"
4949
android:label="Welcome"
@@ -57,13 +57,21 @@
5757
android:theme="@style/AppTheme.NoActionBar">
5858
<meta-data
5959
android:name="android.support.PARENT_ACTIVITY"
60-
android:value="com.tneciv.zhihudaily.home.view.MainActivity" />
60+
android:value="com.tneciv.zhihudaily.home.view.MainActivity"/>
6161
</activity>
6262

6363
<meta-data
6464
android:name="BUG_HD_SDK_GENERAL_KEY"
65-
android:value="f6ca063d703f8e69a7a6f501de3373fc" />
65+
android:value="f6ca063d703f8e69a7a6f501de3373fc"/>
6666

67+
<activity
68+
android:name=".setting.view.SettingsActivity"
69+
android:label="@string/title_activity_settings"
70+
android:parentActivityName=".home.view.MainActivity">
71+
<meta-data
72+
android:name="android.support.PARENT_ACTIVITY"
73+
android:value="com.tneciv.zhihudaily.home.view.MainActivity"/>
74+
</activity>
6775
</application>
6876

6977
</manifest>

app/src/main/java/com/tneciv/zhihudaily/about/AboutActivity.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.tneciv.zhihudaily.about;
22

3+
import android.Manifest;
34
import android.content.Context;
45
import android.content.Intent;
56
import android.content.SharedPreferences;
@@ -25,6 +26,9 @@ public void init(@Nullable Bundle savedInstanceState) {
2526

2627
setSkipText("忽略");
2728
setDoneText("开始");
29+
30+
askForPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
31+
askForPermissions(new String[]{Manifest.permission.READ_PHONE_STATE}, 2);
2832
}
2933

3034
@Override

app/src/main/java/com/tneciv/zhihudaily/detail/view/DetailActivity.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import android.content.SharedPreferences;
66
import android.os.Bundle;
77
import android.support.annotation.NonNull;
8+
import android.support.annotation.Nullable;
89
import android.support.design.widget.AppBarLayout;
910
import android.support.design.widget.CollapsingToolbarLayout;
1011
import android.support.design.widget.FloatingActionButton;
@@ -21,6 +22,7 @@
2122
import com.daimajia.androidanimations.library.Techniques;
2223
import com.daimajia.androidanimations.library.YoYo;
2324
import com.google.gson.Gson;
25+
import com.jude.swipbackhelper.SwipeBackHelper;
2426
import com.squareup.leakcanary.RefWatcher;
2527
import com.squareup.picasso.Picasso;
2628
import com.tneciv.zhihudaily.MyApplication;
@@ -64,6 +66,7 @@ protected void onCreate(Bundle savedInstanceState) {
6466
super.onCreate(savedInstanceState);
6567
setContentView(R.layout.activity_detail);
6668
ButterKnife.bind(this);
69+
SwipeBackHelper.onCreate(this);
6770
EventBus.getDefault().register(this);
6871
SharedPreferences preferences = getSharedPreferences("config", Context.MODE_PRIVATE);
6972
noImagesMode = preferences.getBoolean("noImagesMode", false);
@@ -84,11 +87,18 @@ protected void onCreate(Bundle savedInstanceState) {
8487
protected void onDestroy() {
8588
super.onDestroy();
8689
EventBus.getDefault().unregister(this);
90+
SwipeBackHelper.onDestroy(this);
8791
ButterKnife.unbind(this);
8892
RefWatcher watcher = MyApplication.getRefWatcher(this);
8993
watcher.watch(this);
9094
}
9195

96+
@Override
97+
protected void onPostCreate(@Nullable Bundle savedInstanceState) {
98+
super.onPostCreate(savedInstanceState);
99+
SwipeBackHelper.onPostCreate(this);
100+
}
101+
92102
private void initView() {
93103

94104
setSupportActionBar(toolbar);

app/src/main/java/com/tneciv/zhihudaily/home/view/MainActivity.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,16 +203,16 @@ public void onBackPressed() {
203203

204204
@Override
205205
public boolean onCreateOptionsMenu(Menu menu) {
206-
// getMenuInflater().inflate(R.menu.main, menu);
206+
// getMenuInflater().inflate(R.menu.main, menu);
207207
return true;
208208
}
209209

210210
@Override
211211
public boolean onOptionsItemSelected(MenuItem item) {
212212
int id = item.getItemId();
213213

214-
// if (id == R.id.action_nightMode) {
215-
// }
214+
// if (id == R.id.action_nightMode) {
215+
// }
216216

217217
return super.onOptionsItemSelected(item);
218218
}
@@ -288,7 +288,7 @@ private void askForPermission() {
288288
if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
289289
if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
290290
}
291-
requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE},
291+
requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
292292
PERMISSION_WRITE_EXT);
293293
}
294294

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
package com.tneciv.zhihudaily.setting.view;
2+
3+
import android.content.res.Configuration;
4+
import android.os.Bundle;
5+
import android.preference.PreferenceActivity;
6+
import android.support.annotation.LayoutRes;
7+
import android.support.annotation.Nullable;
8+
import android.support.v7.app.ActionBar;
9+
import android.support.v7.app.AppCompatDelegate;
10+
import android.support.v7.widget.Toolbar;
11+
import android.view.MenuInflater;
12+
import android.view.View;
13+
import android.view.ViewGroup;
14+
15+
/**
16+
* A {@link android.preference.PreferenceActivity} which implements and proxies the necessary calls
17+
* to be used with AppCompat.
18+
*/
19+
public abstract class AppCompatPreferenceActivity extends PreferenceActivity {
20+
21+
private AppCompatDelegate mDelegate;
22+
23+
@Override
24+
protected void onCreate(Bundle savedInstanceState) {
25+
getDelegate().installViewFactory();
26+
getDelegate().onCreate(savedInstanceState);
27+
super.onCreate(savedInstanceState);
28+
}
29+
30+
private AppCompatDelegate getDelegate() {
31+
if (mDelegate == null) {
32+
mDelegate = AppCompatDelegate.create(this, null);
33+
}
34+
return mDelegate;
35+
}
36+
37+
@Override
38+
protected void onPostCreate(Bundle savedInstanceState) {
39+
super.onPostCreate(savedInstanceState);
40+
getDelegate().onPostCreate(savedInstanceState);
41+
}
42+
43+
public ActionBar getSupportActionBar() {
44+
return getDelegate().getSupportActionBar();
45+
}
46+
47+
public void setSupportActionBar(@Nullable Toolbar toolbar) {
48+
getDelegate().setSupportActionBar(toolbar);
49+
}
50+
51+
@Override
52+
public MenuInflater getMenuInflater() {
53+
return getDelegate().getMenuInflater();
54+
}
55+
56+
@Override
57+
public void setContentView(@LayoutRes int layoutResID) {
58+
getDelegate().setContentView(layoutResID);
59+
}
60+
61+
@Override
62+
public void setContentView(View view) {
63+
getDelegate().setContentView(view);
64+
}
65+
66+
@Override
67+
public void setContentView(View view, ViewGroup.LayoutParams params) {
68+
getDelegate().setContentView(view, params);
69+
}
70+
71+
@Override
72+
public void addContentView(View view, ViewGroup.LayoutParams params) {
73+
getDelegate().addContentView(view, params);
74+
}
75+
76+
@Override
77+
protected void onPostResume() {
78+
super.onPostResume();
79+
getDelegate().onPostResume();
80+
}
81+
82+
@Override
83+
protected void onTitleChanged(CharSequence title, int color) {
84+
super.onTitleChanged(title, color);
85+
getDelegate().setTitle(title);
86+
}
87+
88+
@Override
89+
public void onConfigurationChanged(Configuration newConfig) {
90+
super.onConfigurationChanged(newConfig);
91+
getDelegate().onConfigurationChanged(newConfig);
92+
}
93+
94+
@Override
95+
protected void onStop() {
96+
super.onStop();
97+
getDelegate().onStop();
98+
}
99+
100+
@Override
101+
protected void onDestroy() {
102+
super.onDestroy();
103+
getDelegate().onDestroy();
104+
}
105+
106+
public void invalidateOptionsMenu() {
107+
getDelegate().invalidateOptionsMenu();
108+
}
109+
}

0 commit comments

Comments
 (0)