Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash app when Android Version 8+ about new Content Provider #555

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
57 changes: 47 additions & 10 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,17 +1,54 @@
apply plugin: 'java'
apply from: 'gradle-mvn-push.gradle'
apply plugin: 'maven'

targetCompatibility = '1.6'
sourceCompatibility = '1.6'
group = 'com.github.matheusbristot'

sourceSets {
main {
java {
srcDir 'src'
}
}
sourceCompatibility = 1.8 // java 8
targetCompatibility = 1.8


repositories {
mavenCentral()
}

dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.google.guava:guava:18.0'
}

task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}

task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}

artifacts {
archives sourcesJar
archives javadocJar
}

// To specify a license in the pom:
install {
repositories.mavenInstaller {
pom.project {
groupId "com.github.matheusbristot"
artifactId "com.activeandroid"
version "3.2.9"
licenses {
license {
name 'The Apache Software License, Version 2.0'
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
distribution 'repo'
}
}
scm {
connection = 'scm:[email protected]:matheusbristot/ActiveAndroid.git'
developerConnection = 'scm:[email protected]:matheusbristot/ActiveAndroid.git'
url = 'https://github.com/matheusbristot/ActiveAndroid'
}
}
}
}
32 changes: 0 additions & 32 deletions build.xml

This file was deleted.

18 changes: 0 additions & 18 deletions gradle.properties

This file was deleted.

2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=http\://services.gradle.org/distributions/gradle-1.8-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
93 changes: 0 additions & 93 deletions pom-child.xml

This file was deleted.

38 changes: 0 additions & 38 deletions pom.xml

This file was deleted.

32 changes: 19 additions & 13 deletions src/com/activeandroid/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,15 @@ public final Long getId() {
}

public final void delete() {
Cache.openDatabase().delete(mTableInfo.getTableName(), idName+"=?", new String[] { getId().toString() });
Cache.removeEntity(this);

Cache.getContext().getContentResolver()
.notifyChange(ContentProvider.createUri(mTableInfo.getType(), mId), null);
try {
Cache.openDatabase().delete(mTableInfo.getTableName(), idName + "=?", new String[]{getId().toString()});
Cache.removeEntity(this);

Cache.getContext().getContentResolver()
.notifyChange(ContentProvider.createUri(mTableInfo.getType(), mId), null);
} catch (Throwable t){
t.printStackTrace()
}
}

public final Long save() {
Expand Down Expand Up @@ -151,15 +155,17 @@ else if (ReflectionUtils.isSubclassOf(fieldType, Enum.class)) {
}
}

if (mId == null) {
mId = db.insert(mTableInfo.getTableName(), null, values);
}
else {
db.update(mTableInfo.getTableName(), values, idName+"=" + mId, null);
try {
if (mId == null) {
mId = db.insert(mTableInfo.getTableName(), null, values);
} else {
db.update(mTableInfo.getTableName(), values, idName + "=" + mId, null);
}
Cache.getContext().getContentResolver()
.notifyChange(ContentProvider.createUri(mTableInfo.getType(), mId), null);
} catch (Throwable t){
t.printStackTrace()
}

Cache.getContext().getContentResolver()
.notifyChange(ContentProvider.createUri(mTableInfo.getType(), mId), null);
return mId;
}

Expand Down
16 changes: 6 additions & 10 deletions src/com/activeandroid/content/ContentProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,18 +147,14 @@ public Cursor query(Uri uri, String[] projection, String selection, String[] sel
//////////////////////////////////////////////////////////////////////////////////////

public static Uri createUri(Class<? extends Model> type, Long id) {
final StringBuilder uri = new StringBuilder();
uri.append("content://");
uri.append(sAuthority);
uri.append("/");
uri.append(Cache.getTableName(type).toLowerCase());

Uri.Builder uriBuilder = new Uri.Builder();
uriBuilder.authority(sAuthority);
uriBuilder.scheme("content");
uriBuilder.appendPath(Cache.getTableName(type).toLowerCase());
if (id != null) {
uri.append("/");
uri.append(id.toString());
uriBuilder.appendPath(id.toString());
}

return Uri.parse(uri.toString());
return uriBuilder.build();
}

//////////////////////////////////////////////////////////////////////////////////////
Expand Down
Loading