Commit 596e143c by 罗翻

增加baseLibrary

parent d61a1969
...@@ -6,7 +6,7 @@ apply plugin: 'kotlin-android-extensions' ...@@ -6,7 +6,7 @@ apply plugin: 'kotlin-android-extensions'
android { android {
compileSdkVersion 25 compileSdkVersion 26
buildToolsVersion '26.0.2' buildToolsVersion '26.0.2'
aaptOptions { aaptOptions {
cruncherEnabled = false cruncherEnabled = false
...@@ -97,7 +97,7 @@ dependencies { ...@@ -97,7 +97,7 @@ dependencies {
//mutidex //mutidex
compile 'com.android.support:multidex:1.0.2' compile 'com.android.support:multidex:1.0.2'
compile 'com.android.support:design:25.4.0' compile 'com.android.support:design:26.1.0'
//greendao数据库 //greendao数据库
compile 'org.greenrobot:greendao:3.2.0' compile 'org.greenrobot:greendao:3.2.0'
......
...@@ -42,6 +42,10 @@ public class Api { ...@@ -42,6 +42,10 @@ public class Api {
return service; return service;
} }
public static <T> T getService(Class<T> clz) {
return getRetrofit().create(clz);
}
private static Retrofit getRetrofit() { private static Retrofit getRetrofit() {
if (retrofit == null) { if (retrofit == null) {
Gson gson = new GsonBuilder() Gson gson = new GsonBuilder()
......
package com.dayu.bigfish.base;
import com.dayu.bigfish.api.APIException;
import com.dayu.bigfish.utils.ProgressUtil;
import io.reactivex.Observer;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;
/**
* Created by luofan on 17/11/02.
*/
public abstract class CorePresenter<V> {
protected static final String TAG = "BasePresenter";
protected V mView;
protected CompositeDisposable mComDisposable = new CompositeDisposable();
public void setView(V v) {
this.mView = v;
this.onAttached();
}
public abstract void onAttached();
public void onDetached() {
mComDisposable.dispose();
}
/**
* 创建观察者
*
* @param consumer
* @return
*/
public <M> Observer baseObserver(final Consumer<? super M> consumer) {
return new Observer<M>() {
@Override
public void onSubscribe(Disposable d) {
mComDisposable.add(d);
}
@Override
public void onNext(M o) {
ProgressUtil.stopLoad();
try {
consumer.accept(o);
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void onError(Throwable e) {
ProgressUtil.stopLoad();
processException(e);
}
@Override
public void onComplete() {
}
};
}
/**
* 创建带错误的观察者
*
* @param consumer
* @return
*/
public <M> Observer baseObserver(final Consumer<? super M> consumer, final Consumer<APIException.ResponeThrowable> tconsumer) {
return new Observer<M>() {
@Override
public void onSubscribe(Disposable d) {
mComDisposable.add(d);
}
@Override
public void onNext(M o) {
ProgressUtil.stopLoad();
try {
consumer.accept(o);
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void onError(Throwable e) {
APIException.ResponeThrowable exception = processException(e);
ProgressUtil.stopLoad();
try {
tconsumer.accept(exception);
} catch (Exception e1) {
e1.printStackTrace();
}
}
@Override
public void onComplete() {
}
};
}
public abstract APIException.ResponeThrowable processException(Throwable e);
public void dumpBack() {
if (mView instanceof BaseActivity) {
((BaseActivity) mView).dumpBack();
}
}
}
apply plugin: 'com.android.library'
android {
compileSdkVersion 26
defaultConfig {
minSdkVersion 16
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:design:26.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
package com.dayu.base;
import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() throws Exception {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();
assertEquals("com.dayu.base.test", appContext.getPackageName());
}
}
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.dayu.base" />
<resources>
<string name="app_name">BaseLibrary</string>
</resources>
package com.dayu.base;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Example local unit test, which will execute on the development machine (host).
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() throws Exception {
assertEquals(4, 2 + 2);
}
}
\ No newline at end of file
...@@ -5,6 +5,7 @@ buildscript { ...@@ -5,6 +5,7 @@ buildscript {
ext.gradle_version = '3.0.1' ext.gradle_version = '3.0.1'
repositories { repositories {
jcenter() jcenter()
google()
} }
dependencies { dependencies {
classpath "com.android.tools.build:gradle:$gradle_version" classpath "com.android.tools.build:gradle:$gradle_version"
...@@ -19,6 +20,7 @@ allprojects { ...@@ -19,6 +20,7 @@ allprojects {
repositories { repositories {
jcenter() jcenter()
maven { url 'https://jitpack.io' } maven { url 'https://jitpack.io' }
google()
} }
} }
......
include ':app',':apt', ':annotation_lib' include ':app',':apt', ':annotation_lib', ':baselibrary'
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment