Skip to content

Commit 73b9a47

Browse files
committed
新增MVP相关类,新增BaseDialog类,新增 Activity 栈管理类、更新基类的几个方法
1 parent e167b80 commit 73b9a47

File tree

71 files changed

+1563
-358
lines changed

Some content is hidden

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

71 files changed

+1563
-358
lines changed

AndroidBug.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
android:alwaysRetainTaskState="true"
6666
android:launchMode="singleTop" />
6767

68-
#### 修复 Android P 限制 Http 明文请求的问题
68+
#### 修复 Android 9.0 限制 Http 明文请求的问题
6969

7070
> Android P 限制了明文流量的网络请求,非加密的流量请求都会被系统禁止掉。
7171
如果当前应用的请求是 htttp 请求,而非 https ,这样就会导系统禁止当前应用进行该请求,如果 WebView 的 url 用 http 协议,同样会出现加载失败,https 不受影响

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@
7474

7575
#### Android技术讨论Q群:78797078
7676

77+
#### 如果您觉得我的开源库帮你节省了大量的开发时间,请扫描下方的二维码随意打赏,要是能打赏个 10.24 :monkey_face:就太:thumbsup:了。您的支持将鼓励我继续创作:octocat:
78+
79+
![](picture/pay_ali.png) ![](picture/pay_wechat.png)
80+
7781
## License
7882

7983
```text

app/build.gradle

Lines changed: 49 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,23 @@ android {
1111
versionName "1.0"
1212
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
1313
}
14+
15+
//APK 签名的那些事:https://www.jianshu.com/p/a1f8e5896aa2
16+
// signingConfigs {
17+
// release {
18+
// keyAlias '密钥别称'
19+
// keyPassword '密钥密码'
20+
// storeFile file('E:/MySign.jks')
21+
// storePassword '密钥库密码'
22+
// }
23+
//
24+
// debug {
25+
// keyAlias '密钥别称'
26+
// keyPassword '密钥密码'
27+
// storeFile file('E:/MySign.jks')
28+
// storePassword '密钥库密码'
29+
// }
30+
// }
1431
buildTypes {
1532
release {
1633
// 不显示Log
@@ -23,6 +40,8 @@ android {
2340
minifyEnabled true
2441
//加载默认混淆配置涵
2542
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
43+
// 正式环境签名
44+
//signingConfig signingConfigs.release
2645
}
2746

2847
debug {
@@ -32,6 +51,8 @@ android {
3251
minifyEnabled false
3352
//加载默认混淆配置涵
3453
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
54+
// 开发环境签名
55+
//signingConfig signingConfigs.debug
3556
}
3657
}
3758

@@ -49,37 +70,50 @@ android {
4970
flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name]
5071
}
5172
}
73+
74+
// JNI 目录
75+
sourceSets {
76+
main {
77+
jniLibs.srcDirs = ['libs']
78+
}
79+
}
5280
}
5381

82+
// api 与 implementation的区别:https://www.jianshu.com/p/8962d6ba936e
5483
dependencies {
55-
api fileTree(include: ['*.jar'], dir: 'libs')
56-
api project(':baselibrary')
84+
// 依赖 libs 目录下所有 Jar 包
85+
implementation fileTree(include: ['*.jar'], dir: 'libs')
86+
// 基础库(不包任何第三方框架)
87+
implementation project(':baselibrary')
5788
// 示例:添加一个 aar 包
58-
//api(name: 'password_dialog', ext: 'aar')
89+
// implementation(name: 'password_dialog', ext: 'aar')
90+
91+
implementation "com.android.support:appcompat-v7:$rootProject.ext.supportLibraryVersion"
92+
implementation "com.android.support:design:$rootProject.ext.supportLibraryVersion"
93+
implementation "com.android.support:support-v4:$rootProject.ext.supportLibraryVersion"
94+
implementation "com.android.support:cardview-v7:$rootProject.ext.supportLibraryVersion"
95+
implementation "com.android.support.constraint:constraint-layout:$rootProject.ext.constraintlayoutVersion"
5996

60-
api "com.android.support:appcompat-v7:$rootProject.ext.supportLibraryVersion"
61-
api "com.android.support:design:$rootProject.ext.supportLibraryVersion"
62-
api "com.android.support:support-v4:$rootProject.ext.supportLibraryVersion"
63-
api "com.android.support:cardview-v7:$rootProject.ext.supportLibraryVersion"
64-
api "com.android.support.constraint:constraint-layout:$rootProject.ext.constraintlayoutVersion"
97+
// Dex分包,解决 65k 问题
98+
implementation 'com.android.support:multidex:1.0.3'
6599

66100
// 状态栏沉浸:https://github.com/gyf-dev/ImmersionBar
67-
api 'com.gyf.barlibrary:barlibrary:2.3.0'
101+
implementation 'com.gyf.barlibrary:barlibrary:2.3.0'
68102
// 侧滑功能:https://github.com/bingoogolapple/BGASwipeBackLayout-Android
69-
api 'cn.bingoogolapple:bga-swipebacklayout:1.1.9@aar'
103+
implementation 'cn.bingoogolapple:bga-swipebacklayout:1.1.9@aar'
70104

71105
// 权限请求框架:https://github.com/getActivity/XXPermissions
72-
api 'com.hjq:xxpermissions:5.2'
106+
implementation 'com.hjq:xxpermissions:5.2'
73107
// 标题栏:https://github.com/getActivity/TitleBar
74-
api 'com.hjq:titlebar:3.2'
108+
implementation 'com.hjq:titlebar:3.5'
75109
// 吐司工具类:https://github.com/getActivity/ToastUtils
76-
api 'com.hjq:toast:2.5'
110+
implementation 'com.hjq:toast:5.0'
77111

78112
// 圆形的ImageView:https://github.com/hdodenhof/CircleImageView
79-
api 'de.hdodenhof:circleimageview:2.2.0'
113+
implementation 'de.hdodenhof:circleimageview:2.2.0'
80114

81115
// ButterKnife注解库:https://github.com/JakeWharton/butterknife
82-
api "com.jakewharton:butterknife:$rootProject.ext.butterknifeVersion"
116+
implementation "com.jakewharton:butterknife:$rootProject.ext.butterknifeVersion"
83117
annotationProcessor "com.jakewharton:butterknife-compiler:$rootProject.ext.butterknifeVersion"
84118

85119
// 友盟统计

app/proguard-rules.pro

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,3 +223,5 @@
223223
-keep class android.support.design.** { *; }
224224
-keep interface android.support.design.** { *; }
225225
-keep public class android.support.design.R$* { *; }
226+
227+
########################################################

app/src/main/java/com/hjq/demo/common/CommonActivity.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import com.hjq.bar.OnTitleBarListener;
77
import com.hjq.bar.TitleBar;
8+
import com.hjq.toast.ToastUtils;
89
import com.umeng.analytics.MobclickAgent;
910

1011
import butterknife.ButterKnife;
@@ -85,24 +86,17 @@ public boolean statusBarDarkFont() {
8586
* {@link OnTitleBarListener}
8687
*/
8788

88-
/**
89-
* 标题栏左边的View被点击了
90-
*/
89+
// 标题栏左边的View被点击了
9190
@Override
9291
public void onLeftClick(View v) {
9392
onBackPressed();
9493
}
9594

96-
97-
/**
98-
* 标题栏中间的View被点击了
99-
*/
95+
// 标题栏中间的View被点击了
10096
@Override
10197
public void onTitleClick(View v) {}
10298

103-
/**
104-
* 标题栏右边的View被点击了
105-
*/
99+
// 标题栏右边的View被点击了
106100
@Override
107101
public void onRightClick(View v) {}
108102

@@ -129,4 +123,11 @@ protected void onDestroy() {
129123
super.onDestroy();
130124
if (mButterKnife != null) mButterKnife.unbind();
131125
}
126+
127+
/**
128+
* 显示一个吐司
129+
*/
130+
public void toast(CharSequence s) {
131+
ToastUtils.show(s);
132+
}
132133
}
Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
package com.hjq.demo.common;
22

3+
import android.content.Context;
4+
import android.support.multidex.MultiDex;
5+
6+
import com.hjq.baselibrary.utils.ActivityStackManager;
37
import com.hjq.toast.ToastUtils;
48
import com.umeng.analytics.MobclickAgent;
59

610
/**
711
* author : HJQ
812
* github : https://github.com/getActivity/AndroidProject
913
* time : 2018/10/18
10-
* desc : 项目中的Activity基类
14+
* desc : 项目中的Application基类
1115
*/
1216
public class CommonApplication extends UIApplication {
1317

@@ -16,9 +20,19 @@ public void onCreate() {
1620
super.onCreate();
1721

1822
// 初始化吐司工具类
19-
ToastUtils.init(getApplicationContext());
23+
ToastUtils.init(this);
2024

2125
// 友盟统计
2226
MobclickAgent.setScenarioType(getApplicationContext(), MobclickAgent.EScenarioType.E_UM_NORMAL);
27+
28+
// Activity 栈管理
29+
ActivityStackManager.init(this);
30+
}
31+
32+
@Override
33+
protected void attachBaseContext(Context base) {
34+
super.attachBaseContext(base);
35+
// 使用 Dex分包
36+
MultiDex.install(this);
2337
}
2438
}

app/src/main/java/com/hjq/demo/common/CommonLazyFragment.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import android.view.View;
77
import android.view.ViewGroup;
88

9+
import com.hjq.toast.ToastUtils;
910
import com.umeng.analytics.MobclickAgent;
1011

1112
import butterknife.ButterKnife;
@@ -47,4 +48,11 @@ public void onDestroy() {
4748
super.onDestroy();
4849
mButterKnife.unbind();
4950
}
51+
52+
/**
53+
* 显示一个吐司
54+
*/
55+
public void toast(CharSequence s) {
56+
ToastUtils.show(s);
57+
}
5058
}

app/src/main/java/com/hjq/demo/common/UIActivity.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ protected void onCreate(Bundle savedInstanceState) {
3030
super.onCreate(savedInstanceState);
3131
}
3232

33+
@Override
3334
public void init(){
3435

3536
//初始化沉浸式状态栏
@@ -169,4 +170,4 @@ protected void onDestroy() {
169170
getWindow().getDecorView().getViewTreeObserver().removeOnGlobalLayoutListener(this);
170171
}
171172
}
172-
}
173+
}

app/src/main/java/com/hjq/demo/common/UIApplication.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* author : HJQ
99
* github : https://github.com/getActivity/AndroidProject
1010
* time : 2018/10/18
11-
* desc : 支持侧滑的UIApplication基类
11+
* desc : 支持侧滑的Application基类
1212
*/
1313
public abstract class UIApplication extends Application {
1414

app/src/main/java/com/hjq/demo/common/UILazyFragment.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@ public abstract class UILazyFragment extends BaseLazyFragment {
2121
@Override
2222
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
2323
super.onViewCreated(view, savedInstanceState);
24-
2524
//初始化沉浸式状态栏
26-
if (isVisibleToUser() && isStatusBarEnabled() && isLazyLoad()) {
25+
if (isFragmentVisible() && isStatusBarEnabled() && isLazyLoad()) {
2726
statusBarConfig().init();
2827
}
2928

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.hjq.demo.mvp;
2+
3+
/**
4+
* author : HJQ
5+
* github : https://github.com/getActivity/AndroidProject
6+
* time : 2018/11/17
7+
* desc : MVP 通用性接口
8+
*/
9+
public interface IMvpView {
10+
11+
/**
12+
* 用于页面请求数据时显示加载状态
13+
*/
14+
void showLoading();
15+
16+
/**
17+
* 用于请求的数据为空的状态
18+
*/
19+
void showEmpty();
20+
21+
/**
22+
* 用于请求数据出错
23+
*/
24+
void showError();
25+
26+
/**
27+
* 用于请求数据完成
28+
*/
29+
void loadingComplete();
30+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.hjq.demo.mvp;
2+
3+
import com.hjq.demo.common.CommonActivity;
4+
5+
/**
6+
* author : HJQ
7+
* github : https://github.com/getActivity/AndroidProject
8+
* time : 2018/11/17
9+
* desc : MVP Activity 基类
10+
*/
11+
public abstract class MvpActivity<P extends MvpPresenter> extends CommonActivity {
12+
13+
private P mPresenter;
14+
15+
@Override
16+
public void init() {
17+
mPresenter = initPresenter();
18+
mPresenter.attach(this);
19+
mPresenter.start();
20+
super.init();
21+
}
22+
23+
@Override
24+
protected void onDestroy() {
25+
mPresenter.detach();
26+
super.onDestroy();
27+
}
28+
29+
public P getPresenter() {
30+
return mPresenter;
31+
}
32+
33+
protected abstract P initPresenter();
34+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.hjq.demo.mvp;
2+
3+
import com.hjq.demo.common.CommonLazyFragment;
4+
5+
/**
6+
* author : HJQ
7+
* github : https://github.com/getActivity/AndroidProject
8+
* time : 2018/11/17
9+
* desc : MVP 懒加载 Fragment 基类
10+
*/
11+
public abstract class MvpLazyFragment<P extends MvpPresenter> extends CommonLazyFragment {
12+
13+
private P mPresenter;
14+
15+
@Override
16+
protected void init() {
17+
mPresenter = initPresenter();
18+
mPresenter.attach(this);
19+
mPresenter.start();
20+
super.init();
21+
}
22+
23+
@Override
24+
public void onDestroy() {
25+
mPresenter.detach();
26+
super.onDestroy();
27+
}
28+
29+
public P getPresenter() {
30+
return mPresenter;
31+
}
32+
33+
protected abstract P initPresenter();
34+
}

0 commit comments

Comments
 (0)