Skip to content

Commit

Permalink
fix bug that super classes can't auto access data
Browse files Browse the repository at this point in the history
  • Loading branch information
ThirtyDegreesRay committed Nov 29, 2017
1 parent 193ee5f commit 72803b6
Show file tree
Hide file tree
Showing 12 changed files with 61 additions and 30 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
4 changes: 2 additions & 2 deletions dataautoaccess-annotations/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions dataautoaccess-compiler/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions dataautoaccess/build.gradle
Original file line number Diff line number Diff line change
@@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;

/**
* Data auto access<br>
Expand Down Expand Up @@ -70,8 +71,8 @@ public static void getData(Object targetObject, Bundle dataStore) {
return;
}

DataAccessor<Object> dataAccessor = getDataAccessor(targetObject, dataStore);
if (dataAccessor != null) {
List<DataAccessor<Object>> dataAccessors = getDataAccessors(targetObject);
for(DataAccessor<Object> dataAccessor : dataAccessors){
dataAccessor.getData(targetObject, dataStore);
}
}
Expand All @@ -87,16 +88,30 @@ public static void saveData(Object targetObject, Bundle dataStore) {
return;
}

DataAccessor<Object> dataAccessor = getDataAccessor(targetObject, dataStore);
if (dataAccessor != null) {
List<DataAccessor<Object>> dataAccessors = getDataAccessors(targetObject);
for(DataAccessor<Object> dataAccessor : dataAccessors){
dataAccessor.saveData(targetObject, dataStore);
}
}

private static DataAccessor<Object> getDataAccessor(Object targetObject, Bundle dataStore) {
private static List<DataAccessor<Object>> getDataAccessors(Object targetObject) {
List<DataAccessor<Object>> dataAccessors = new ArrayList<>();
Class<?> targetClass = targetObject.getClass();
getDataAccessors(dataAccessors, targetClass);
return dataAccessors;
}

private static List<DataAccessor<Object>> getDataAccessors(
List<DataAccessor<Object>> dataAccessors, Class<?> targetClass) {
String className = targetClass.getName() + SUFFIX;
return getDataAccessor(className);
DataAccessor<Object> dataAccessor = getDataAccessor(className);
if(dataAccessor != null){
dataAccessors.add(dataAccessor);
}
if(targetClass.getSuperclass() != null){
getDataAccessors(dataAccessors, targetClass.getSuperclass());
}
return dataAccessors;
}

private static DataAccessor<Object> getDataAccessor(String className) {
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
16 changes: 8 additions & 8 deletions sample/build.gradle
Original file line number Diff line number Diff line change
@@ -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"

Expand All @@ -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')
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -23,4 +27,5 @@ protected void onSaveInstanceState(Bundle outState) {
//save data
DataAutoAccess.saveData(this, outState);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class ExampleActivity extends BaseActivity {

private TextView tvName;
private TextView tvDescription;
private TextView tvStarted;

private Bundle testBundle;

Expand All @@ -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){
Expand Down
7 changes: 7 additions & 0 deletions sample/src/main/res/layout/activity_example.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@
android:gravity="center"
android:textColor="@android:color/black"
android:textSize="16sp" />
<TextView
android:id="@+id/tv_started"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textColor="@android:color/black"
android:textSize="16sp" />

<Button
android:layout_width="120dp"
Expand Down

0 comments on commit 72803b6

Please sign in to comment.