diff --git a/README.md b/README.md index bd913e1..4eb3f8f 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,6 @@ # DataAutoAccess +[![Releases](https://img.shields.io/github/release/ThirtyDegreesRay/DataAutoAccess.svg)](https://github.com/ThirtyDegreesRay/DataAutoAccess/releases/latest) + 自动存取Android Bundle中数据——给需要自动存取的变量添加注解,编译时会通过注解处理自动生成存取的代码 * Activity或Service启动时自动取出Intent中的数据,并赋值给相应的field @@ -59,8 +61,8 @@ Then, apply the 'android-apt' plugin in your module-level build.gradle and add t } dependencies { - compile 'com.thirtydegreesray:dataautoaccess:1.2.6' - apt 'com.thirtydegreesray:dataautoaccess-compiler:1.2.6' + compile 'com.thirtydegreesray:dataautoaccess:latestVersion' + apt 'com.thirtydegreesray:dataautoaccess-compiler:latestVersion' } ## Proguard diff --git a/build.gradle b/build.gradle index 7b0ff71..c2631c4 100644 --- a/build.gradle +++ b/build.gradle @@ -6,8 +6,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.1.3' - classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' + classpath 'com.android.tools.build:gradle:2.3.3' classpath "com.github.dcendents:android-maven-gradle-plugin:1.5" classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0' diff --git a/dataautoaccess-annotations/build.gradle b/dataautoaccess-annotations/build.gradle index 363468d..bbbb4c0 100644 --- a/dataautoaccess-annotations/build.gradle +++ b/dataautoaccess-annotations/build.gradle @@ -8,8 +8,8 @@ dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) } -sourceCompatibility = "1.6" -targetCompatibility = "1.6" +targetCompatibility = '1.7' +sourceCompatibility = '1.7' def siteUrl = 'https://github.com/ThirtyDegreesRay/DataAutoAccess' // 项目的主页 def gitUrl = 'https://github.com/ThirtyDegreesRay/DataAutoAccess.git' // Git仓库的url diff --git a/dataautoaccess-compiler/build.gradle b/dataautoaccess-compiler/build.gradle index 8d4a7a0..6601667 100644 --- a/dataautoaccess-compiler/build.gradle +++ b/dataautoaccess-compiler/build.gradle @@ -10,8 +10,8 @@ dependencies { compile project(':dataautoaccess-annotations') } -sourceCompatibility = "1.6" -targetCompatibility = "1.6" +targetCompatibility = '1.7' +sourceCompatibility = '1.7' def siteUrl = 'https://github.com/ThirtyDegreesRay/DataAutoAccess' // 项目的主页 def gitUrl = 'https://github.com/ThirtyDegreesRay/DataAutoAccess.git' // Git仓库的url diff --git a/dataautoaccess/build.gradle b/dataautoaccess/build.gradle index 7f83b11..fbbd1f5 100644 --- a/dataautoaccess/build.gradle +++ b/dataautoaccess/build.gradle @@ -1,16 +1,15 @@ apply plugin: 'com.android.library' - apply plugin: 'com.github.dcendents.android-maven' apply plugin: 'com.jfrog.bintray' version = VERSION_NAME android { - compileSdkVersion 24 - buildToolsVersion "24.0.2" + compileSdkVersion 26 + buildToolsVersion "26.0.2" defaultConfig { minSdkVersion 9 - targetSdkVersion 24 + targetSdkVersion 26 versionCode VERSION_CODE as int versionName VERSION_NAME diff --git a/dataautoaccess/src/main/java/com/thirtydegreesray/dataautoaccess/DataAutoAccess.java b/dataautoaccess/src/main/java/com/thirtydegreesray/dataautoaccess/DataAutoAccess.java index d5f30cd..857171d 100644 --- a/dataautoaccess/src/main/java/com/thirtydegreesray/dataautoaccess/DataAutoAccess.java +++ b/dataautoaccess/src/main/java/com/thirtydegreesray/dataautoaccess/DataAutoAccess.java @@ -8,6 +8,7 @@ import java.util.ArrayList; import java.util.LinkedHashMap; +import java.util.List; /** * Data auto access
@@ -70,8 +71,8 @@ public static void getData(Object targetObject, Bundle dataStore) { return; } - DataAccessor dataAccessor = getDataAccessor(targetObject, dataStore); - if (dataAccessor != null) { + List> dataAccessors = getDataAccessors(targetObject); + for(DataAccessor dataAccessor : dataAccessors){ dataAccessor.getData(targetObject, dataStore); } } @@ -87,16 +88,30 @@ public static void saveData(Object targetObject, Bundle dataStore) { return; } - DataAccessor dataAccessor = getDataAccessor(targetObject, dataStore); - if (dataAccessor != null) { + List> dataAccessors = getDataAccessors(targetObject); + for(DataAccessor dataAccessor : dataAccessors){ dataAccessor.saveData(targetObject, dataStore); } } - private static DataAccessor getDataAccessor(Object targetObject, Bundle dataStore) { + private static List> getDataAccessors(Object targetObject) { + List> dataAccessors = new ArrayList<>(); Class targetClass = targetObject.getClass(); + getDataAccessors(dataAccessors, targetClass); + return dataAccessors; + } + + private static List> getDataAccessors( + List> dataAccessors, Class targetClass) { String className = targetClass.getName() + SUFFIX; - return getDataAccessor(className); + DataAccessor dataAccessor = getDataAccessor(className); + if(dataAccessor != null){ + dataAccessors.add(dataAccessor); + } + if(targetClass.getSuperclass() != null){ + getDataAccessors(dataAccessors, targetClass.getSuperclass()); + } + return dataAccessors; } private static DataAccessor getDataAccessor(String className) { diff --git a/gradle.properties b/gradle.properties index 4224a0e..c2b86c2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -17,6 +17,6 @@ org.gradle.jvmargs=-Xmx1536m # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # org.gradle.parallel=true -VERSION_NAME = 1.2.6 -VERSION_CODE = 16 +VERSION_NAME = 1.2.7 +VERSION_CODE = 17 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 04e285f..69eeffb 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Mon Dec 28 10:00:20 PST 2015 +#Tue Jul 25 21:40:01 CST 2017 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip \ No newline at end of file diff --git a/sample/build.gradle b/sample/build.gradle index f4080a3..c038938 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -1,14 +1,13 @@ apply plugin: 'com.android.application' -apply plugin: 'android-apt' android { - compileSdkVersion 24 - buildToolsVersion "24.0.2" + compileSdkVersion 26 + buildToolsVersion "26.0.2" defaultConfig { applicationId "com.thirtydegreesray.dataautoaccess.sample" - minSdkVersion 9 - targetSdkVersion 24 + minSdkVersion 14 + targetSdkVersion 26 versionCode 1 versionName "1.0" @@ -32,8 +31,9 @@ dependencies { androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) - compile 'com.android.support:appcompat-v7:24.2.0' + compile 'com.android.support:appcompat-v7:26.+' testCompile 'junit:junit:4.12' - compile project(':dataautoaccess') - apt project(':dataautoaccess-compiler') + compile project(path: ':dataautoaccess') + compile project(path: ':dataautoaccess-annotations') + annotationProcessor project(path: ':dataautoaccess-compiler') } diff --git a/sample/src/main/java/com/thirtydegreesray/dataautoaccess/sample/BaseActivity.java b/sample/src/main/java/com/thirtydegreesray/dataautoaccess/sample/BaseActivity.java index 0a11ed8..771460d 100644 --- a/sample/src/main/java/com/thirtydegreesray/dataautoaccess/sample/BaseActivity.java +++ b/sample/src/main/java/com/thirtydegreesray/dataautoaccess/sample/BaseActivity.java @@ -5,12 +5,16 @@ import android.support.v7.app.AppCompatActivity; import com.thirtydegreesray.dataautoaccess.DataAutoAccess; +import com.thirtydegreesray.dataautoaccess.annotation.AutoAccess; /** * Created by ThirtyDegreesRay on 2016/9/1 09:58 */ public class BaseActivity extends AppCompatActivity { + + @AutoAccess protected boolean started ; + @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -23,4 +27,5 @@ protected void onSaveInstanceState(Bundle outState) { //save data DataAutoAccess.saveData(this, outState); } + } diff --git a/sample/src/main/java/com/thirtydegreesray/dataautoaccess/sample/ExampleActivity.java b/sample/src/main/java/com/thirtydegreesray/dataautoaccess/sample/ExampleActivity.java index 7942dfd..b6a5059 100644 --- a/sample/src/main/java/com/thirtydegreesray/dataautoaccess/sample/ExampleActivity.java +++ b/sample/src/main/java/com/thirtydegreesray/dataautoaccess/sample/ExampleActivity.java @@ -19,6 +19,7 @@ public class ExampleActivity extends BaseActivity { private TextView tvName; private TextView tvDescription; + private TextView tvStarted; private Bundle testBundle; @@ -29,11 +30,14 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { tvName = (TextView) findViewById(R.id.tv_name); tvDescription = (TextView) findViewById(R.id.tv_description); + tvStarted = (TextView) findViewById(R.id.tv_started); tvName.setText(name); tvDescription.setText(description); + tvStarted.setText(started ? "started" : "starting"); testBundle = new Bundle(); DataAutoAccess.saveData(this, testBundle); + started = true; } public void onSaveDataClick(View view){ diff --git a/sample/src/main/res/layout/activity_example.xml b/sample/src/main/res/layout/activity_example.xml index 71140c0..0d8acaf 100644 --- a/sample/src/main/res/layout/activity_example.xml +++ b/sample/src/main/res/layout/activity_example.xml @@ -20,6 +20,13 @@ android:gravity="center" android:textColor="@android:color/black" android:textSize="16sp" /> +