Skip to content

Commit f508614

Browse files
author
xiaoqi
committed
update to 1.0.2
1 parent 544417e commit f508614

9 files changed

Lines changed: 84 additions & 34 deletions

File tree

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ ext {
3535
userOrg = 'noober'
3636
groupId = 'com.noober'
3737
uploadName = 'AutoSaver'
38-
publishVersion = '1.0.0'
38+
publishVersion = '1.0.2'
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

sample/build.gradle

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ dependencies {
3030
})
3131
implementation 'com.android.support:appcompat-v7:+'
3232
testImplementation 'junit:junit:4.12'
33-
implementation 'com.noober:savehelper:1.0.0'
34-
annotationProcessor 'com.noober:processor:1.0.0'
35-
implementation 'com.noober:savehelper-api:1.0.0'
33+
implementation 'com.noober:savehelper:1.0.2'
34+
annotationProcessor 'com.noober:processor:1.0.2'
35+
implementation 'com.noober:savehelper-api:1.0.2'
36+
// implementation project(':savehelper')
37+
// implementation project(':savehelper-api')
38+
// annotationProcessor project(':savehelper-processor')
3639
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.recover.autosavesample;
2+
3+
import android.os.Bundle;
4+
import android.support.v7.app.AppCompatActivity;
5+
6+
import com.noober.savehelper.SaveHelper;
7+
8+
/**
9+
* Created by Administrator on 2017/12/26.
10+
*/
11+
12+
public class BaseActivity extends AppCompatActivity {
13+
14+
15+
@Override
16+
protected void onRestoreInstanceState(Bundle savedInstanceState) {
17+
super.onRestoreInstanceState(savedInstanceState);
18+
SaveHelper.recover(this, savedInstanceState);
19+
}
20+
21+
@Override
22+
protected void onSaveInstanceState(Bundle outState) {
23+
SaveHelper.save(this, outState);
24+
super.onSaveInstanceState(outState);
25+
}
26+
}

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,40 +12,40 @@
1212
public class SampleActivity extends AppCompatActivity {
1313

1414
@NeedSave
15-
public String test;
15+
String test;
1616
@NeedSave
17-
private boolean b;
17+
public boolean b;
1818
@NeedSave
19-
public Boolean c;
19+
protected Boolean c;
2020
@NeedSave
21-
public ArrayList<String> t;
21+
private ArrayList<String> t;
2222
@NeedSave
23-
public Integer i;
23+
Integer i;
2424
@NeedSave(isParcelable = true)
25-
public Example example;
25+
Example example;
2626
@NeedSave
27-
public Float f1;
27+
Float f1;
2828
@NeedSave
29-
public float f2;
29+
float f2;
3030
@NeedSave
31-
public char achar;
31+
char achar;
3232
@NeedSave
33-
public char achars[];
33+
char achars[];
3434
@NeedSave
35-
public int sssss[];
35+
int sssss[];
3636
@NeedSave
37-
public int[] sasa;
37+
int[] sasa;
3838
@NeedSave
39-
public Bundle bundle;
39+
Bundle bundle;
4040
@NeedSave
41-
public int a;
41+
int a;
4242

4343
@Override
4444
protected void onCreate(Bundle savedInstanceState) {
4545
super.onCreate(savedInstanceState);
4646
setContentView(R.layout.activity_main);
4747
initData();
48-
SaveHelper.bind(this,savedInstanceState);
48+
SaveHelper.recover(this,savedInstanceState);
4949
}
5050

5151
private void initData() {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public class SampleFragment extends Fragment {
4242
@Override
4343
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle
4444
savedInstanceState) {
45-
SaveHelper.bind(this,savedInstanceState);
45+
SaveHelper.recover(this,savedInstanceState);
4646
return super.onCreateView(inflater, container, savedInstanceState);
4747
}
4848

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,26 @@
11
package com.recover.autosavesample;
22

3-
import android.support.v7.app.AppCompatActivity;
43
import android.os.Bundle;
54
import android.view.View;
65
import android.widget.Button;
76
import android.widget.TextView;
87

98
import com.noober.api.NeedSave;
10-
import com.noober.savehelper.SaveHelper;
119

12-
public class TestActivity extends AppCompatActivity {
10+
public class TestActivity extends BaseActivity {
1311

1412
private TextView textView;
1513
private Button button;
1614
private final static String testContent = "This is a test code:";
1715

1816
@NeedSave
19-
public String testString = "11111111";
17+
String testString = "11111111";
2018
@Override
2119
protected void onCreate(Bundle savedInstanceState) {
2220
super.onCreate(savedInstanceState);
2321
setContentView(R.layout.activity_test);
24-
SaveHelper.bind(this, savedInstanceState);
2522
textView = findViewById(R.id.tv_content);
2623
button = findViewById(R.id.button);
27-
textView.setText(testContent + testString);
2824
button.setOnClickListener(new View.OnClickListener() {
2925
@Override
3026
public void onClick(View v) {
@@ -35,8 +31,8 @@ public void onClick(View v) {
3531
}
3632

3733
@Override
38-
protected void onSaveInstanceState(Bundle outState) {
39-
SaveHelper.save(this, outState);
40-
super.onSaveInstanceState(outState);
34+
protected void onResume() {
35+
super.onResume();
36+
textView.setText(testContent + testString);
4137
}
4238
}

savehelper-processor/src/main/java/com/noober/helper/HelperClass.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public JavaFile generateCode(){
6161
String fieldType = value.getFieldType().toString();
6262
String type = HelperConfig.getFieldType(fieldType);
6363
//only support public field
64-
if(!value.isPublic()){
64+
if(value.isPrivate()){
6565
continue;
6666
}
6767
if(!type.equals("unKnow")){

savehelper-processor/src/main/java/com/noober/helper/HelperSavedValues.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,14 @@ public boolean isPublic(){
4141
}
4242
return false;
4343
}
44+
45+
public boolean isPrivate(){
46+
Set<Modifier> set = ((Element)encloseElement).getModifiers();
47+
for(Modifier modifier : set){
48+
if(modifier.equals(Modifier.PRIVATE)){
49+
return true;
50+
}
51+
}
52+
return false;
53+
}
4454
}

savehelper/src/main/java/com/noober/savehelper/SaveHelper.java

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,21 @@ public class SaveHelper {
1111

1212
private final static String HELPER_END = "_SaveStateHelper";
1313

14+
/**
15+
* Equate to{@link SaveHelper#recover}, it's just renamed to make it easier to understand
16+
*/
17+
@Deprecated
1418
public static <T> void bind(T recover, Bundle savedInstanceState){
19+
recover(recover, savedInstanceState);
20+
}
21+
22+
/**
23+
* added where need to recover data
24+
*
25+
* @param recover current Activity or Fragment
26+
* @param savedInstanceState Bundle
27+
*/
28+
public static <T> void recover(T recover, Bundle savedInstanceState){
1529
if(savedInstanceState != null){
1630
ISaveInstanceStateHelper<T> saveInstanceStateHelper = findSaveHelper(recover);
1731
if(saveInstanceStateHelper != null){
@@ -21,9 +35,11 @@ public static <T> void bind(T recover, Bundle savedInstanceState){
2135
}
2236

2337
public static <T> void save(T save, Bundle outState){
24-
ISaveInstanceStateHelper<T> saveInstanceStateHelper = findSaveHelper(save);
25-
if(saveInstanceStateHelper != null){
26-
saveInstanceStateHelper.save(outState, save);
38+
if(outState != null){
39+
ISaveInstanceStateHelper<T> saveInstanceStateHelper = findSaveHelper(save);
40+
if(saveInstanceStateHelper != null){
41+
saveInstanceStateHelper.save(outState, save);
42+
}
2743
}
2844
}
2945

@@ -39,7 +55,6 @@ private static <T> ISaveInstanceStateHelper<T> findSaveHelper(T cl) {
3955
helperCache.put(clazz,saveInstanceStateHelper);
4056
} catch (ClassNotFoundException e) {
4157
e.printStackTrace();
42-
throw new RuntimeException(String.format(" not find %s.class",clazz + HELPER_END));
4358
} catch (InstantiationException e) {
4459
e.printStackTrace();
4560
} catch (IllegalAccessException e) {

0 commit comments

Comments
 (0)