Skip to content

Commit

Permalink
新增MVP相关类,新增BaseDialog类,新增 Activity 栈管理类、更新基类的几个方法
Browse files Browse the repository at this point in the history
  • Loading branch information
880634 committed Nov 29, 2018
1 parent e167b80 commit 73b9a47
Show file tree
Hide file tree
Showing 71 changed files with 1,563 additions and 358 deletions.
2 changes: 1 addition & 1 deletion AndroidBug.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
android:alwaysRetainTaskState="true"
android:launchMode="singleTop" />

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

> Android P 限制了明文流量的网络请求,非加密的流量请求都会被系统禁止掉。
如果当前应用的请求是 htttp 请求,而非 https ,这样就会导系统禁止当前应用进行该请求,如果 WebView 的 url 用 http 协议,同样会出现加载失败,https 不受影响
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@

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

#### 如果您觉得我的开源库帮你节省了大量的开发时间,请扫描下方的二维码随意打赏,要是能打赏个 10.24 :monkey_face:就太:thumbsup:了。您的支持将鼓励我继续创作:octocat:

![](picture/pay_ali.png) ![](picture/pay_wechat.png)

## License

```text
Expand Down
64 changes: 49 additions & 15 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,23 @@ android {
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

//APK 签名的那些事:https://www.jianshu.com/p/a1f8e5896aa2
// signingConfigs {
// release {
// keyAlias '密钥别称'
// keyPassword '密钥密码'
// storeFile file('E:/MySign.jks')
// storePassword '密钥库密码'
// }
//
// debug {
// keyAlias '密钥别称'
// keyPassword '密钥密码'
// storeFile file('E:/MySign.jks')
// storePassword '密钥库密码'
// }
// }
buildTypes {
release {
// 不显示Log
Expand All @@ -23,6 +40,8 @@ android {
minifyEnabled true
//加载默认混淆配置涵
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
// 正式环境签名
//signingConfig signingConfigs.release
}

debug {
Expand All @@ -32,6 +51,8 @@ android {
minifyEnabled false
//加载默认混淆配置涵
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
// 开发环境签名
//signingConfig signingConfigs.debug
}
}

Expand All @@ -49,37 +70,50 @@ android {
flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name]
}
}

// JNI 目录
sourceSets {
main {
jniLibs.srcDirs = ['libs']
}
}
}

// api 与 implementation的区别:https://www.jianshu.com/p/8962d6ba936e
dependencies {
api fileTree(include: ['*.jar'], dir: 'libs')
api project(':baselibrary')
// 依赖 libs 目录下所有 Jar 包
implementation fileTree(include: ['*.jar'], dir: 'libs')
// 基础库(不包任何第三方框架)
implementation project(':baselibrary')
// 示例:添加一个 aar 包
//api(name: 'password_dialog', ext: 'aar')
// implementation(name: 'password_dialog', ext: 'aar')

implementation "com.android.support:appcompat-v7:$rootProject.ext.supportLibraryVersion"
implementation "com.android.support:design:$rootProject.ext.supportLibraryVersion"
implementation "com.android.support:support-v4:$rootProject.ext.supportLibraryVersion"
implementation "com.android.support:cardview-v7:$rootProject.ext.supportLibraryVersion"
implementation "com.android.support.constraint:constraint-layout:$rootProject.ext.constraintlayoutVersion"

api "com.android.support:appcompat-v7:$rootProject.ext.supportLibraryVersion"
api "com.android.support:design:$rootProject.ext.supportLibraryVersion"
api "com.android.support:support-v4:$rootProject.ext.supportLibraryVersion"
api "com.android.support:cardview-v7:$rootProject.ext.supportLibraryVersion"
api "com.android.support.constraint:constraint-layout:$rootProject.ext.constraintlayoutVersion"
// Dex分包,解决 65k 问题
implementation 'com.android.support:multidex:1.0.3'

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

// 权限请求框架:https://github.com/getActivity/XXPermissions
api 'com.hjq:xxpermissions:5.2'
implementation 'com.hjq:xxpermissions:5.2'
// 标题栏:https://github.com/getActivity/TitleBar
api 'com.hjq:titlebar:3.2'
implementation 'com.hjq:titlebar:3.5'
// 吐司工具类:https://github.com/getActivity/ToastUtils
api 'com.hjq:toast:2.5'
implementation 'com.hjq:toast:5.0'

// 圆形的ImageView:https://github.com/hdodenhof/CircleImageView
api 'de.hdodenhof:circleimageview:2.2.0'
implementation 'de.hdodenhof:circleimageview:2.2.0'

// ButterKnife注解库:https://github.com/JakeWharton/butterknife
api "com.jakewharton:butterknife:$rootProject.ext.butterknifeVersion"
implementation "com.jakewharton:butterknife:$rootProject.ext.butterknifeVersion"
annotationProcessor "com.jakewharton:butterknife-compiler:$rootProject.ext.butterknifeVersion"

// 友盟统计
Expand Down
2 changes: 2 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -223,3 +223,5 @@
-keep class android.support.design.** { *; }
-keep interface android.support.design.** { *; }
-keep public class android.support.design.R$* { *; }

########################################################
21 changes: 11 additions & 10 deletions app/src/main/java/com/hjq/demo/common/CommonActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import com.hjq.bar.OnTitleBarListener;
import com.hjq.bar.TitleBar;
import com.hjq.toast.ToastUtils;
import com.umeng.analytics.MobclickAgent;

import butterknife.ButterKnife;
Expand Down Expand Up @@ -85,24 +86,17 @@ public boolean statusBarDarkFont() {
* {@link OnTitleBarListener}
*/

/**
* 标题栏左边的View被点击了
*/
// 标题栏左边的View被点击了
@Override
public void onLeftClick(View v) {
onBackPressed();
}


/**
* 标题栏中间的View被点击了
*/
// 标题栏中间的View被点击了
@Override
public void onTitleClick(View v) {}

/**
* 标题栏右边的View被点击了
*/
// 标题栏右边的View被点击了
@Override
public void onRightClick(View v) {}

Expand All @@ -129,4 +123,11 @@ protected void onDestroy() {
super.onDestroy();
if (mButterKnife != null) mButterKnife.unbind();
}

/**
* 显示一个吐司
*/
public void toast(CharSequence s) {
ToastUtils.show(s);
}
}
18 changes: 16 additions & 2 deletions app/src/main/java/com/hjq/demo/common/CommonApplication.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package com.hjq.demo.common;

import android.content.Context;
import android.support.multidex.MultiDex;

import com.hjq.baselibrary.utils.ActivityStackManager;
import com.hjq.toast.ToastUtils;
import com.umeng.analytics.MobclickAgent;

/**
* author : HJQ
* github : https://github.com/getActivity/AndroidProject
* time : 2018/10/18
* desc : 项目中的Activity基类
* desc : 项目中的Application基类
*/
public class CommonApplication extends UIApplication {

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

// 初始化吐司工具类
ToastUtils.init(getApplicationContext());
ToastUtils.init(this);

// 友盟统计
MobclickAgent.setScenarioType(getApplicationContext(), MobclickAgent.EScenarioType.E_UM_NORMAL);

// Activity 栈管理
ActivityStackManager.init(this);
}

@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
// 使用 Dex分包
MultiDex.install(this);
}
}
8 changes: 8 additions & 0 deletions app/src/main/java/com/hjq/demo/common/CommonLazyFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.view.View;
import android.view.ViewGroup;

import com.hjq.toast.ToastUtils;
import com.umeng.analytics.MobclickAgent;

import butterknife.ButterKnife;
Expand Down Expand Up @@ -47,4 +48,11 @@ public void onDestroy() {
super.onDestroy();
mButterKnife.unbind();
}

/**
* 显示一个吐司
*/
public void toast(CharSequence s) {
ToastUtils.show(s);
}
}
3 changes: 2 additions & 1 deletion app/src/main/java/com/hjq/demo/common/UIActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}

@Override
public void init(){

//初始化沉浸式状态栏
Expand Down Expand Up @@ -169,4 +170,4 @@ protected void onDestroy() {
getWindow().getDecorView().getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
}
}
}
2 changes: 1 addition & 1 deletion app/src/main/java/com/hjq/demo/common/UIApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* author : HJQ
* github : https://github.com/getActivity/AndroidProject
* time : 2018/10/18
* desc : 支持侧滑的UIApplication基类
* desc : 支持侧滑的Application基类
*/
public abstract class UIApplication extends Application {

Expand Down
3 changes: 1 addition & 2 deletions app/src/main/java/com/hjq/demo/common/UILazyFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ public abstract class UILazyFragment extends BaseLazyFragment {
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);

//初始化沉浸式状态栏
if (isVisibleToUser() && isStatusBarEnabled() && isLazyLoad()) {
if (isFragmentVisible() && isStatusBarEnabled() && isLazyLoad()) {
statusBarConfig().init();
}

Expand Down
30 changes: 30 additions & 0 deletions app/src/main/java/com/hjq/demo/mvp/IMvpView.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.hjq.demo.mvp;

/**
* author : HJQ
* github : https://github.com/getActivity/AndroidProject
* time : 2018/11/17
* desc : MVP 通用性接口
*/
public interface IMvpView {

/**
* 用于页面请求数据时显示加载状态
*/
void showLoading();

/**
* 用于请求的数据为空的状态
*/
void showEmpty();

/**
* 用于请求数据出错
*/
void showError();

/**
* 用于请求数据完成
*/
void loadingComplete();
}
34 changes: 34 additions & 0 deletions app/src/main/java/com/hjq/demo/mvp/MvpActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.hjq.demo.mvp;

import com.hjq.demo.common.CommonActivity;

/**
* author : HJQ
* github : https://github.com/getActivity/AndroidProject
* time : 2018/11/17
* desc : MVP Activity 基类
*/
public abstract class MvpActivity<P extends MvpPresenter> extends CommonActivity {

private P mPresenter;

@Override
public void init() {
mPresenter = initPresenter();
mPresenter.attach(this);
mPresenter.start();
super.init();
}

@Override
protected void onDestroy() {
mPresenter.detach();
super.onDestroy();
}

public P getPresenter() {
return mPresenter;
}

protected abstract P initPresenter();
}
34 changes: 34 additions & 0 deletions app/src/main/java/com/hjq/demo/mvp/MvpLazyFragment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.hjq.demo.mvp;

import com.hjq.demo.common.CommonLazyFragment;

/**
* author : HJQ
* github : https://github.com/getActivity/AndroidProject
* time : 2018/11/17
* desc : MVP 懒加载 Fragment 基类
*/
public abstract class MvpLazyFragment<P extends MvpPresenter> extends CommonLazyFragment {

private P mPresenter;

@Override
protected void init() {
mPresenter = initPresenter();
mPresenter.attach(this);
mPresenter.start();
super.init();
}

@Override
public void onDestroy() {
mPresenter.detach();
super.onDestroy();
}

public P getPresenter() {
return mPresenter;
}

protected abstract P initPresenter();
}
Loading

0 comments on commit 73b9a47

Please sign in to comment.