Skip to content

Commit f04df02

Browse files
author
xiaoqi
committed
update to 2.0.0
1 parent 6837914 commit f04df02

18 files changed

Lines changed: 358 additions & 108 deletions

File tree

README.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,18 @@
1212
onSaveInstanceState 和 onRestoreInstanceState 统一添加SaveHelper.save和SaveHelper.recover方法。
1313
1.0.3 优化代码生成,如果一个activity或者fragment中没有有效的@NeedSave注解,但是添加了SaveHelper.recover和SaveHelper.save
1414
方法,现在就不会自动生成这个类的SaveStateHelper类,减少了无用SaveStateHelper类,便于在Base类中统一集成。
15+
16+
2.0.0 去掉NeedSave注解中的isParcelable字段,自动可以支持不同类型;
17+
如果字段被标记为private在编译的时候会抛异常;
18+
支持基本所有bundle可以传入的类型,包括SparseParcelableArray等, 如果传入的类型bundle不支持会抛异常(如果有遗漏的类型,请在github 提出issue);
1519

1620

1721
引入方式,在app的gradle中加入下面依赖即可:
1822

1923

20-
compile 'com.noober:savehelper:1.0.3'
21-
compile 'com.noober:savehelper-api:1.0.3'
22-
annotationProcessor 'com.noober:processor:1.0.3'
24+
compile 'com.noober:savehelper:2.0.0'
25+
compile 'com.noober:savehelper-api:2.0.0'
26+
annotationProcessor 'com.noober:processor:2.0.0'
2327

2428
# 引入
2529

@@ -68,7 +72,7 @@ android 内存被回收是一个开发者的常见问题。当我们**跳转到
6872
public ArrayList<String> t;
6973
@NeedSave
7074
public Integer i;
71-
@NeedSave(isParcelable = true)
75+
@NeedSave
7276
public ParcelableObject example;
7377
@NeedSave
7478
public SerializableObject example;
@@ -143,7 +147,7 @@ android 内存被回收是一个开发者的常见问题。当我们**跳转到
143147
这是一个注解,这个注解只能使用在全局变量中,特别注意,~~被加上这个注解的变量必须是**public**,否则会不生效~~
144148
1.0.1更新为只要非private即可。
145149

146-
当前支持保存的类型有:
150+
~~当前支持保存的类型有:~~
147151

148152
String
149153
boolean Boolean
@@ -155,7 +159,9 @@ android 内存被回收是一个开发者的常见问题。当我们**跳转到
155159
char[] char
156160
Bundle
157161

158-
注意,如果是Parcelable类型,需要特别在注解中加入 @NeedSave(isParcelable = true) 这样标记
162+
~~注意,如果是Parcelable类型,需要特别在注解中加入 @NeedSave(isParcelable = true) 这样标记~~
163+
**目前已经自动支持所有的类型,isParcelable已经弃用。**
164+
159165
## SaveHelper.recover(this,savedInstanceState);
160166
这个方法其实是恢复数据的时候去调用的。
161167

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ buildscript {
99
}
1010
}
1111
dependencies {
12-
classpath 'com.android.tools.build:gradle:3.0.0'
12+
classpath 'com.android.tools.build:gradle:3.0.1'
1313
classpath 'com.novoda:bintray-release:0.5.0'
1414
// NOTE: Do not place your application dependencies here; they belong
1515
// in the individual module build.gradle files
@@ -35,7 +35,7 @@ ext {
3535
userOrg = 'noober'
3636
groupId = 'com.noober'
3737
uploadName = 'AutoSaver'
38-
publishVersion = '1.0.3'
38+
publishVersion = '2.0.0'
3939
desc = "A light weight framework can automatically generate 'OnSaveInstanceState' code"
4040
website = 'https://github.com/JavaNoober/AutoSave'
4141
// gradlew clean build bintrayUpload -PbintrayUser=xiaoqiandroid -PbintrayKey=xxxxxxxxxxxxxxxx -PdryRun=false

gradle.properties

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99

1010
# Specifies the JVM arguments used for the daemon process.
1111
# The setting is particularly useful for tweaking memory settings.
12-
org.gradle.jvmargs=-Xmx1536m
13-
12+
#org.gradle.jvmargs=-Xmx1536m
13+
org.gradle.jvmargs= -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5006
14+
org.gradle.parallel=true
1415
# When configured, Gradle will run in incubating parallel mode.
1516
# This option should only be used with decoupled projects. More details, visit
1617
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects

sample/build.gradle

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ android {
2121
}
2222
}
2323

24-
2524
dependencies {
2625
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
2726
compile fileTree(include: ['*.jar'], dir: 'libs')
@@ -30,10 +29,10 @@ dependencies {
3029
})
3130
implementation 'com.android.support:appcompat-v7:+'
3231
testImplementation 'junit:junit:4.12'
33-
implementation 'com.noober:savehelper:1.0.3'
34-
annotationProcessor 'com.noober:processor:1.0.3'
35-
implementation 'com.noober:savehelper-api:1.0.3'
36-
// implementation project(':savehelper')
37-
// implementation project(':savehelper-api')
38-
// annotationProcessor project(':savehelper-processor')
32+
implementation 'com.noober:savehelper:2.0.0'
33+
annotationProcessor 'com.noober:processor:2.0.0'
34+
implementation 'com.noober:savehelper-api:2.0.0'
35+
// implementation project(':savehelper')
36+
// implementation project(':savehelper-api')
37+
// annotationProcessor project(':savehelper-processor')
3938
}

sample/src/main/java/com/recover/autosavesample/Example.java

Lines changed: 0 additions & 36 deletions
This file was deleted.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.recover.autosavesample;
2+
3+
import android.os.Parcel;
4+
import android.os.Parcelable;
5+
6+
/**
7+
* Created by xiaoqi on 2018/2/9
8+
*/
9+
10+
public class Model implements Parcelable {
11+
12+
String name;
13+
14+
15+
@Override
16+
public int describeContents() {
17+
return 0;
18+
}
19+
20+
@Override
21+
public void writeToParcel(Parcel dest, int flags) {
22+
dest.writeString(this.name);
23+
}
24+
25+
public Model() {
26+
}
27+
28+
protected Model(Parcel in) {
29+
this.name = in.readString();
30+
}
31+
32+
public static final Parcelable.Creator<Model> CREATOR = new Parcelable.Creator<Model>() {
33+
@Override
34+
public Model createFromParcel(Parcel source) {
35+
return new Model(source);
36+
}
37+
38+
@Override
39+
public Model[] newArray(int size) {
40+
return new Model[size];
41+
}
42+
};
43+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.recover.autosavesample;
2+
3+
import android.os.Parcel;
4+
import android.os.Parcelable;
5+
6+
/**
7+
* Created by xiaoqi on 2017/1/10.
8+
*/
9+
10+
public class ParcelableExample implements Parcelable{
11+
protected ParcelableExample(Parcel in) {
12+
}
13+
14+
public static final Creator<ParcelableExample> CREATOR = new Creator<ParcelableExample>() {
15+
@Override
16+
public ParcelableExample createFromParcel(Parcel in) {
17+
return new ParcelableExample(in);
18+
}
19+
20+
@Override
21+
public ParcelableExample[] newArray(int size) {
22+
return new ParcelableExample[size];
23+
}
24+
};
25+
26+
@Override
27+
public int describeContents() {
28+
return 0;
29+
}
30+
31+
@Override
32+
public void writeToParcel(Parcel dest, int flags) {
33+
}
34+
}

sample/src/main/java/com/recover/autosavesample/SampleActivity.java

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
import android.support.v7.app.AppCompatActivity;
44
import android.os.Bundle;
5+
import android.util.Size;
6+
import android.util.SizeF;
7+
import android.util.SparseArray;
58

69

710
import com.noober.api.NeedSave;
@@ -18,11 +21,11 @@ public class SampleActivity extends AppCompatActivity {
1821
@NeedSave
1922
protected Boolean c;
2023
@NeedSave
21-
private ArrayList<String> t;
24+
ArrayList<String> t;
2225
@NeedSave
2326
Integer i;
24-
@NeedSave(isParcelable = true)
25-
Example example;
27+
@NeedSave
28+
ParcelableExample parcelableExample;
2629
@NeedSave
2730
Float f1;
2831
@NeedSave
@@ -39,6 +42,28 @@ public class SampleActivity extends AppCompatActivity {
3942
Bundle bundle;
4043
@NeedSave
4144
int a;
45+
@NeedSave
46+
SerializableExample serializableExample;
47+
48+
@NeedSave
49+
ArrayList<SerializableExample> serializableExamples;
50+
@NeedSave
51+
ArrayList<ParcelableExample> parcelableExamples;
52+
@NeedSave
53+
ParcelableExample[] parcelableArray;
54+
@NeedSave
55+
SparseArray<ParcelableExample> sparseArray;
56+
@NeedSave
57+
byte[] bytes;
58+
@NeedSave
59+
String[] stringArray;
60+
@NeedSave
61+
long[] longArray;
62+
@NeedSave
63+
Size size;
64+
@NeedSave
65+
SizeF sizeFS;
66+
4267

4368
@Override
4469
protected void onCreate(Bundle savedInstanceState) {

sample/src/main/java/com/recover/autosavesample/SampleFragment.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,16 @@ public class SampleFragment extends Fragment {
2626
public ArrayList<String> t;
2727
@NeedSave
2828
public Integer i;
29-
@NeedSave(isParcelable = true)
30-
public Example example;
29+
@NeedSave()
30+
public ParcelableExample parcelableExample;
3131
@NeedSave
3232
public Float f1;
3333
@NeedSave
3434
public float f2;
3535
@NeedSave
3636
public char achar;
3737
@NeedSave
38-
private char achars[];
38+
char achars[];
3939

4040

4141
@Nullable
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.recover.autosavesample;
2+
3+
import java.io.Serializable;
4+
5+
/**
6+
* Created by xiaoqi on 2018/2/9
7+
*/
8+
9+
public class SerializableExample implements Serializable {
10+
11+
12+
}

0 commit comments

Comments
 (0)