Skip to content

Commit

Permalink
整理代码
Browse files Browse the repository at this point in the history
  • Loading branch information
FaceAI committed Jan 24, 2019
1 parent ae5de42 commit bbfaef6
Show file tree
Hide file tree
Showing 116 changed files with 800 additions and 7,365 deletions.
8 changes: 4 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ android {
}


ndk {
//设置支持的SO库架构
abiFilters 'armeabi' //, 'x86', 'armeabi-v7a', 'x86_64', 'arm64-v8a'
}
// ndk {
// //设置支持的SO库架构
// abiFilters 'armeabi' //, 'x86', 'armeabi-v7a', 'x86_64', 'arm64-v8a'
// }

}

Expand Down
15 changes: 9 additions & 6 deletions baselib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
defaultConfig {
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
// versionCode 1
// versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

// multiDexEnabled true
Expand All @@ -20,6 +20,8 @@ android {
}
}


// //假如设置了abiFilters ,是否有问题
// ndk {
// //设置支持的SO库架构
// abiFilters 'armeabi' //, 'x86', 'armeabi-v7a', 'x86_64', 'arm64-v8a'
Expand All @@ -32,7 +34,7 @@ android {

debug {
debuggable true
resValue("string", "PORT_NUMBER", "8089") //数据库调试
resValue("string", "PORT_NUMBER", "8765") //数据库调试
}

}
Expand Down Expand Up @@ -70,14 +72,14 @@ dependencies {
api "com.android.support:cardview-v7:$rootProject.ext.supportLibraryVersion"

api 'com.squareup.retrofit2:retrofit:2.5.0' //为了更好的研究Retrofit 改用源码的方式
api 'com.squareup.okhttp3:logging-interceptor:3.8.1'
api 'com.squareup.okhttp3:logging-interceptor:3.10.0'

api 'com.squareup.retrofit2:adapter-rxjava2:2.5.0'
api 'com.squareup.retrofit2:converter-gson:2.5.0'

//RxJava
api 'com.trello.rxlifecycle2:rxlifecycle-components:2.1.0'
api 'io.reactivex.rxjava2:rxjava:2.1.16'
api 'io.reactivex.rxjava2:rxjava:2.2.2'
api 'io.reactivex.rxjava2:rxandroid:2.0.2'

//Router
Expand All @@ -90,7 +92,7 @@ dependencies {

//Toast & GSON
api 'com.github.GrenderG:Toasty:1.2.5'
api 'com.google.code.gson:gson:2.8.2'
api 'com.google.code.gson:gson:2.8.4'

api 'com.kingja.loadsir:loadsir:1.3.5'

Expand Down Expand Up @@ -131,5 +133,6 @@ dependencies {

implementation 'com.android.support:multidex:1.0.3'
annotationProcessor 'com.alibaba:arouter-compiler:1.1.4' //!!!!
debugImplementation 'com.amitshekhar.android:debug-db:1.0.4'

}
9 changes: 0 additions & 9 deletions baselib/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.zlb.httplib">



<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />


<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.INTERNET" />
Expand Down
10 changes: 5 additions & 5 deletions baselib/src/main/java/com/zlb/base/BaseActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ protected void onCreate(Bundle savedInstanceState) {
* @param <T>
* @return
*/
public <T extends View> T $(@IdRes int resId) {
public final <T extends View> T $(@IdRes int resId) {
return (T) super.findViewById(resId);
}

Expand Down Expand Up @@ -141,7 +141,7 @@ public final void goWebView(String link) {
// startActivity(intent);
}

public Context getContext() {
public final Context getContext() {
return mContext;
}

Expand All @@ -159,7 +159,7 @@ public final Toolbar getToolbar() {
*
* @param title
*/
public void setToolBarTitle(CharSequence title) {
public final void setToolBarTitle(CharSequence title) {
getToolbar().setTitle(title);
setSupportActionBar(getToolbar());
}
Expand All @@ -170,7 +170,7 @@ public void setToolBarTitle(CharSequence title) {
*
* @param visible
*/
public void setToolBarVisible(int visible) {
public final void setToolBarVisible(int visible) {
getToolbar().setVisibility(visible);
setSupportActionBar(getToolbar());

Expand All @@ -193,7 +193,7 @@ private void showBack() {
*
* @return
*/
protected boolean isShowBacking() {
protected boolean isShowBacking() {
return true;
}

Expand Down
31 changes: 28 additions & 3 deletions baselib/src/main/java/com/zlb/http/HttpRetrofit.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
import com.zlb.Sp.SPDao;
import com.zlb.Sp.SPKey;
import com.zlb.httplib.MyHttpLoggingInterceptor;
import com.zlb.utils.MD5Util;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import okhttp3.Authenticator;
Expand Down Expand Up @@ -43,9 +46,11 @@ public static void setToken(String token) {
TOKEN = token;
}

public static Map<String, Long> requestIdsMap = new HashMap<>();

/**
* 每次都要invoke 这个方法不是很繁琐吗?
*
* @param spDao
* @param mContext
* @return
*/
public static Retrofit getRetrofit(SPDao spDao, Context mContext) {
Expand Down Expand Up @@ -97,8 +102,25 @@ public Response intercept(Chain chain) throws IOException {
.build();

//拦截处理重复的HTTP 请求
String requestKey = MD5Util.getUpperMD5Str(authorisedRequest.toString());

long lastRequestTime = 0;
if (null != requestIdsMap.get(requestKey)) {
lastRequestTime = requestIdsMap.get(requestKey);
}
long nowTime = System.currentTimeMillis();

if (nowTime - lastRequestTime < 40 * 1000) {
// authorisedRequest = originalRequest.newBuilder()
// .url("")
// .build();
} else {
requestIdsMap.put(requestKey, nowTime);
}

//在这里全局的处理重复的Http 请求


//拦截处理重复的HTTP 请求

Response originalResponse = chain.proceed(authorisedRequest);

Expand All @@ -109,6 +131,7 @@ public Response intercept(Chain chain) throws IOException {
}
};


/**
* 如果不喜欢系统的Http 的打印方式,可以自己去实现Interceptor 接口
* 但是统一拦截的header 是无法打印的,因为是在请求发出后统一拦截打印的。
Expand All @@ -117,6 +140,8 @@ public Response intercept(Chain chain) throws IOException {
MyHttpLoggingInterceptor loggingInterceptor = new MyHttpLoggingInterceptor();
loggingInterceptor.setLevel(MyHttpLoggingInterceptor.Level.BODY);

//Retrofit 默认的网络请求执行期(callFactory)就是OkHttpClient
//这里仍然需要指定是因为参数,行为的设置等
OkHttpClient okHttpClient = new OkHttpClient.Builder()
.retryOnConnectionFailure(true)
.connectTimeout(7, TimeUnit.SECONDS)
Expand Down
17 changes: 14 additions & 3 deletions baselib/src/main/java/com/zlb/httplib/BaseObserver.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,22 +79,23 @@ public final void onSubscribe(Disposable d) {
@Override
public final void onNext(HttpResponse<T> response) {

Log.e("Thread-io",Thread.currentThread().getName());

Log.e("Thread-io",Thread.currentThread().getName()); //

HttpUiTips.dismissDialog(mContext);

if (!disposable.isDisposed()) {
disposable.dispose();
}

if (response.getCode() == RESPONSE_CODE_OK || response.getCode() == 200) { //response.getCode() == 200 GOOD LIFE 的API真够奇怪的
if (response.getCode() == RESPONSE_CODE_OK || response.getCode() == 200) {
//response.getCode() == 200 GOOD LIFE 的API真够奇怪的
// 这里拦截一下使用测试

onSuccess(response.getResult());
} else {
onFailure(response.getCode(), response.getError());
}

}

/**
Expand Down Expand Up @@ -146,6 +147,7 @@ public final void onError(Throwable t) {
*/
@Override
public final void onComplete() {
int complete=11;
// HttpUiTips.dismissDialog(mContext);
}

Expand All @@ -167,6 +169,15 @@ public void onFailure(int code, String message) {
}


/**
* 处理重复的请求
*/
public void onRepeatCall() {
//尝试全局的拦截重复的请求

}


/**
* 对通用问题的统一拦截处理,Demo 项目的特定的做法
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,20 @@
import android.util.Log;

import com.zlb.persistence.dbmaster.DaoMaster;

import com.zlb.persistence.dbmaster.SysAlertMess2Dao;
import com.zlb.persistence.dbmaster.SysAlertMessDao;

/**
* 数据库的升级策略,一般的只会增加一些字段和添加表,字段名 是很少修改的
* FBI WARMING,如果新加的字段是int ,boolean,目前你需要修改为Integer,Boolean
*
* 当某张表需要添加一个int类型的列时,升级数据库则会报NOT NULL约束不通过,
* 原因是 GreenDao建表时Int 类型 加了NOT NULL。而再数据转移的时候并没有Insert 该列
*
* INTEGER NOT NULL
*
* 数据库还是有很多问题
*
* Created by [email protected] on 2017/1/3.
* Created by zenglb on 2017/1/3.
*/
public class MySQLiteOpenHelper extends DaoMaster.OpenHelper {

Expand All @@ -20,24 +28,19 @@ public MySQLiteOpenHelper(Context context, String name, SQLiteDatabase.CursorFac

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
//数据库 的管理最好能组件化

MigrationHelper.migrate(db,

SysAlertMess2Dao.class,
SysAlertMessDao.class
); //升级

if (oldVersion == newVersion) {
Log.d("onUpgrade", "数据库是最新版本" + oldVersion + ",不需要升级");
Log.d("onUpgrade", "数据库是最新版本:" + oldVersion + ", 不需要升级");
return;
}

Log.d("onUpgrade", "数据库从版本" + oldVersion + "升级到版本" + newVersion);
switch (oldVersion) {
case 1:

break;
case 2:
Log.d("onUpgrade", "数据库从版本:" + oldVersion + " 升级到版本:" + newVersion);

break;
default:
break;
}
}
}
Loading

0 comments on commit bbfaef6

Please sign in to comment.