Skip to content

Commit

Permalink
asynctask compatibility
Browse files Browse the repository at this point in the history
* use thread pool executor on sdk > 10
* update tests
  • Loading branch information
FabianTerhorst committed Jan 10, 2016
1 parent b47267f commit fe0a5f2
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ apply plugin: 'com.neenbedankt.android-apt'
Add dependencies to your application gradle build file (only compile 'io.fabianterhorst:iron:0.5.2' is required)

```groovy
compile 'io.fabianterhorst:iron:0.6.0'
compile 'io.fabianterhorst:iron:0.6.1'
compile 'io.fabianterhorst:iron-retrofit:0.4'
compile 'io.fabianterhorst:iron-encryption:0.4'
//is only required for using the compiler
Expand Down
2 changes: 1 addition & 1 deletion iron/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ dependencies {
compile 'com.esotericsoftware:kryo:3.0.3'//3.0.2
compile 'de.javakaffee:kryo-serializers:0.37'//0.33

//androidTestCompile 'io.fabianterhorst:iron-encryption:0.3@aar'
androidTestCompile 'io.fabianterhorst:iron-encryption:0.4@aar'
androidTestCompile 'com.orhanobut:hawk:1.14'
androidTestCompile 'com.android.support.test:runner:0.3'
androidTestCompile 'com.squareup.assertj:assertj-android:1.0.0'
Expand Down
11 changes: 6 additions & 5 deletions iron/src/androidTest/java/io/fabianterhorst/iron/DataTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.List;
import java.util.Map;

import io.fabianterhorst.iron.encryption.IronEncryption;
import io.fabianterhorst.iron.testdata.ClassWithoutPublicNoArgConstructor;
import io.fabianterhorst.iron.testdata.Person;

Expand All @@ -34,10 +35,10 @@ public class DataTest {
@Before
public void setUp() throws Exception {
Iron.init(getTargetContext());
Iron.setCache(new LruCache());
Iron.chest("keys").destroy();
Iron.chest().destroy();
Iron.setCache(new LruCache());
//Iron.setEncryptionExtension(new IronEncryption());
Iron.setEncryptionExtension(new IronEncryption());
}

@Test
Expand All @@ -54,20 +55,20 @@ public void testReadEmptyListInEmptyChest() {
Iron.setCache(new LruCache());
Iron.chest("keys").destroy();
Iron.chest().destroy();
//Iron.setEncryptionExtension(new IronEncryption());
Iron.setEncryptionExtension(new IronEncryption());
assertThat(Iron.chest().<List>read("persons2")).isNull();
assertThat(Iron.chest().read("persons2", new ArrayList<Person>())).isNotNull();
Iron.chest().write("persons2", genPersonList(1));
Iron.chest().invalidateCache("persons2");
Iron.init(getTargetContext());
Iron.setCache(new LruCache());
//Iron.setEncryptionExtension(new IronEncryption());
Iron.setEncryptionExtension(new IronEncryption());
assertThat(Iron.chest().read("persons2")).isNotNull();
assertThat(Iron.chest().<List>read("persons2")).isNotEmpty();
Iron.chest().invalidateCache("persons2");
Iron.init(getTargetContext());
Iron.setCache(new LruCache());
//Iron.setEncryptionExtension(new IronEncryption());
Iron.setEncryptionExtension(new IronEncryption());
assertThat(Iron.chest().read("persons2")).isNotNull();
assertThat(Iron.chest().<List>read("persons2")).isNotEmpty();
}
Expand Down
31 changes: 26 additions & 5 deletions iron/src/main/java/io/fabianterhorst/iron/Chest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.content.Context;
import android.os.AsyncTask;
import android.os.Build;

import java.util.ArrayList;
import java.util.Iterator;
Expand Down Expand Up @@ -78,7 +79,11 @@ protected Void doInBackground(Object... objects) {
return null;
}
};
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, key, value);
if(Build.VERSION.SDK_INT > 10) {
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, key, value);
} else {
task.execute(key, value);
}
return this;
}

Expand Down Expand Up @@ -127,7 +132,11 @@ protected void onPostExecute(T value) {
mReadCallback.onResult(value);
}
};
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, key, readCallback, defaultObject);
if(Build.VERSION.SDK_INT > 10) {
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, key, readCallback, defaultObject);
} else {
task.execute(key, readCallback, defaultObject);
}
}

synchronized public <T> void execute(String key, Transaction<T> transaction, Object defaultObject) {
Expand All @@ -147,7 +156,11 @@ protected Void doInBackground(Object... objects) {
return null;
}
};
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, key, transaction, defaultObject);
if(Build.VERSION.SDK_INT > 10) {
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, key, transaction, defaultObject);
} else {
task.execute(key, transaction, defaultObject);
}
}

synchronized public void remove(String key) {
Expand All @@ -159,7 +172,11 @@ protected Void doInBackground(Object... objects) {
return null;
}
};
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, key);
if(Build.VERSION.SDK_INT > 10) {
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, key);
} else {
task.execute(key);
}
}

synchronized public void removeAll() {
Expand All @@ -170,7 +187,11 @@ protected Void doInBackground(Void... voids) {
return null;
}
};
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
if(Build.VERSION.SDK_INT > 10) {
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} else {
task.execute();
}
}

synchronized public void execute(String key, Transaction transaction) {
Expand Down
2 changes: 1 addition & 1 deletion publish-encryption.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apply plugin: 'com.jfrog.bintray'
def siteUrl = 'https://github.com/FabianTerhorst/Iron'
def gitUrl = 'https://github.com/FabianTerhorst/Iron.git'

version = "0.3"
version = "0.4"
group = "io.fabianterhorst"

install {
Expand Down
2 changes: 1 addition & 1 deletion publish-retrofit.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apply plugin: 'com.jfrog.bintray'
def siteUrl = 'https://github.com/FabianTerhorst/Iron'
def gitUrl = 'https://github.com/FabianTerhorst/Iron.git'

version = "0.3"
version = "0.4"
group = "io.fabianterhorst"

install {
Expand Down
2 changes: 1 addition & 1 deletion publish.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apply plugin: 'com.jfrog.bintray'
def siteUrl = 'https://github.com/FabianTerhorst/Iron'
def gitUrl = 'https://github.com/FabianTerhorst/Iron.git'

version = "0.6.0"
version = "0.6.1"
group = "io.fabianterhorst"

install {
Expand Down

0 comments on commit fe0a5f2

Please sign in to comment.