Skip to content

Commit 81a0c65

Browse files
committed
Merge branch 'yargray-master'
2 parents f4a8bde + 8817904 commit 81a0c65

22 files changed

+1014
-106
lines changed

Diff for: CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Android ContentProvider Generator Changelog
22
===========================================
33

4-
v1.9.3 (not yet released)
4+
v1.9.3 (2015-07-18)
55
------
66
- Updated content provider template to support ${applicationId} variable that is supported in the
77
new manifest merger build tool (thanks almilli!).

Diff for: README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ https://github.com/BoD/android-contentprovider-generator/releases/latest
124124

125125
### Run the tool
126126

127-
`java -jar android_contentprovider_generator-1.9.2-bundle.jar -i <input folder> -o <output folder>`
127+
`java -jar android_contentprovider_generator-1.9.3-bundle.jar -i <input folder> -o <output folder>`
128128
- Input folder: where to find `_config.json` and your entity json files
129129
- Output folder: where the resulting files will be generated
130130

@@ -150,7 +150,7 @@ Long age = person.getAge();
150150

151151
```java
152152
PersonSelection where = new PersonSelection();
153-
where.firstName("John").or().age(42);
153+
where.firstName("John").or().age(42).orderByFirstName();
154154
PersonCursor person = where.query(getContentResolver());
155155
person.moveToNext();
156156
String lastName = person.getLastName();
@@ -224,7 +224,7 @@ You need maven to build this tool.
224224

225225
`mvn package`
226226

227-
This will produce `android_contentprovider_generator-1.9.2-bundle.jar` in the `target` folder.
227+
This will produce `android_contentprovider_generator-1.9.3-bundle.jar` in the `target` folder.
228228

229229

230230
Similar tools

Diff for: etc/sample/app/src/org/jraf/androidcontentprovidergenerator/sample/app/SampleActivity.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,10 @@ private void queryPeople() {
127127
}
128128
c.close();
129129

130-
// Like / startsWitdh / contains / endsWith
130+
// Like / startsWitdh / contains / endsWith + order by
131131
Log.d(TAG, "---");
132132
personSelection = new PersonSelection();
133-
personSelection.lastNameEndsWith("SON").or().firstNameContains("ar", "ae");
133+
personSelection.lastNameEndsWith("SON").or().firstNameContains("ar", "ae").orderByLastName();
134134
c = personSelection.query(getContentResolver(), projection);
135135
while (c.moveToNext()) {
136136
Log.d(TAG, c.getId() + " - " + c.getFirstName() + " " + c.getLastName() + " (age: " + c.getAge() + ")");
@@ -191,7 +191,7 @@ private void queryPeopleWithTeamAndCompany() {
191191

192192
private void queryTeamsWithCompany() {
193193
TeamSelection teamSelection = new TeamSelection();
194-
teamSelection.name("Red Legends");
194+
teamSelection.name("Red Legends").orderByCompanySerialNumberId(true);
195195
String[] projection = { TeamColumns._ID, TeamColumns.NAME, CompanyColumns.NAME, };
196196
TeamCursor c = teamSelection.query(getContentResolver(), projection);
197197
while (c.moveToNext()) {

Diff for: etc/sample/app/src/org/jraf/androidcontentprovidergenerator/sample/provider/base/AbstractContentValues.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
*/
2525
package org.jraf.androidcontentprovidergenerator.sample.provider.base;
2626

27+
import android.content.Context;
2728
import android.content.ContentResolver;
2829
import android.content.ContentValues;
2930
import android.net.Uri;
@@ -45,10 +46,19 @@ public ContentValues values() {
4546

4647
/**
4748
* Inserts a row into a table using the values stored by this object.
48-
*
49+
*
4950
* @param contentResolver The content resolver to use.
5051
*/
5152
public Uri insert(ContentResolver contentResolver) {
5253
return contentResolver.insert(uri(), values());
5354
}
55+
56+
/**
57+
* Inserts a row into a table using the values stored by this object.
58+
*
59+
* @param context The context to use.
60+
*/
61+
public Uri insert(Context context) {
62+
return context.getContentResolver().insert(uri(), values());
63+
}
5464
}

Diff for: etc/sample/app/src/org/jraf/androidcontentprovidergenerator/sample/provider/base/AbstractSelection.java

+52
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828
import java.util.Date;
2929
import java.util.List;
3030

31+
import android.content.Context;
3132
import android.content.ContentResolver;
33+
import android.database.Cursor;
3234
import android.net.Uri;
3335

3436
public abstract class AbstractSelection<T extends AbstractSelection<?>> {
@@ -51,10 +53,14 @@ public abstract class AbstractSelection<T extends AbstractSelection<?>> {
5153
private static final String CONTAINS = " LIKE '%' || ? || '%'";
5254
private static final String STARTS = " LIKE ? || '%'";
5355
private static final String ENDS = " LIKE '%' || ?";
56+
private static final String COUNT = "COUNT(*)";
57+
private static final String DESC = " DESC";
5458

5559
private final StringBuilder mSelection = new StringBuilder();
5660
private final List<String> mSelectionArgs = new ArrayList<String>(5);
5761

62+
private final StringBuilder mOrderBy = new StringBuilder();
63+
5864
Boolean mNotify;
5965
String mGroupBy;
6066
String mHaving;
@@ -294,6 +300,12 @@ public String[] args() {
294300
return mSelectionArgs.toArray(new String[size]);
295301
}
296302

303+
/**
304+
* Returns the order string produced by this object.
305+
*/
306+
public String order() {
307+
return mOrderBy.length() > 0 ? mOrderBy.toString() : null;
308+
}
297309

298310
/**
299311
* Returns the {@code uri} argument to pass to the {@code ContentResolver} methods.
@@ -319,6 +331,16 @@ public int delete(ContentResolver contentResolver) {
319331
return contentResolver.delete(uri(), sel(), args());
320332
}
321333

334+
/**
335+
* Deletes row(s) specified by this selection.
336+
*
337+
* @param context The context to use.
338+
* @return The number of rows deleted.
339+
*/
340+
public int delete(Context context) {
341+
return context.getContentResolver().delete(uri(), sel(), args());
342+
}
343+
322344
@SuppressWarnings("unchecked")
323345
public T notify(boolean notify) {
324346
mNotify = notify;
@@ -342,4 +364,34 @@ public T limit(int limit) {
342364
mLimit = limit;
343365
return (T) this;
344366
}
367+
368+
@SuppressWarnings("unchecked")
369+
public T orderBy(String order, boolean desc) {
370+
if (mOrderBy.length() > 0) mOrderBy.append(COMMA);
371+
mOrderBy.append(order);
372+
if (desc) mOrderBy.append(DESC);
373+
return (T) this;
374+
}
375+
376+
public T orderBy(String order) {
377+
return orderBy(order, false);
378+
}
379+
380+
@SuppressWarnings("unchecked")
381+
public T orderBy(String... orders) {
382+
for (String order : orders) {
383+
orderBy(order, false);
384+
}
385+
return (T) this;
386+
}
387+
388+
public int count(ContentResolver resolver) {
389+
Cursor cursor = resolver.query(uri(), new String[] { COUNT }, sel(), args(), null);
390+
if (cursor == null) return 0;
391+
try {
392+
return cursor.moveToFirst() ? cursor.getInt(0) : 0;
393+
} finally {
394+
cursor.close();
395+
}
396+
}
345397
}

Diff for: etc/sample/app/src/org/jraf/androidcontentprovidergenerator/sample/provider/company/CompanyContentValues.java

+11
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
import java.util.Date;
2828

29+
import android.content.Context;
2930
import android.content.ContentResolver;
3031
import android.net.Uri;
3132
import android.support.annotation.NonNull;
@@ -52,6 +53,16 @@ public int update(ContentResolver contentResolver, @Nullable CompanySelection wh
5253
return contentResolver.update(uri(), values(), where == null ? null : where.sel(), where == null ? null : where.args());
5354
}
5455

56+
/**
57+
* Update row(s) using the values stored by this object and the given selection.
58+
*
59+
* @param contentResolver The content resolver to use.
60+
* @param where The selection to use (can be {@code null}).
61+
*/
62+
public int update(Context context, @Nullable CompanySelection where) {
63+
return context.getContentResolver().update(uri(), values(), where == null ? null : where.sel(), where == null ? null : where.args());
64+
}
65+
5566
/**
5667
* The commercial name of this company.
5768
*/

Diff for: etc/sample/app/src/org/jraf/androidcontentprovidergenerator/sample/provider/company/CompanySelection.java

+86-10
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
import java.util.Date;
2828

29+
import android.content.Context;
2930
import android.content.ContentResolver;
3031
import android.database.Cursor;
3132
import android.net.Uri;
@@ -47,28 +48,39 @@ protected Uri baseUri() {
4748
*
4849
* @param contentResolver The content resolver to query.
4950
* @param projection A list of which columns to return. Passing null will return all columns, which is inefficient.
50-
* @param sortOrder How to order the rows, formatted as an SQL ORDER BY clause (excluding the ORDER BY itself). Passing null will use the default sort
51-
* order, which may be unordered.
5251
* @return A {@code CompanyCursor} object, which is positioned before the first entry, or null.
5352
*/
54-
public CompanyCursor query(ContentResolver contentResolver, String[] projection, String sortOrder) {
55-
Cursor cursor = contentResolver.query(uri(), projection, sel(), args(), sortOrder);
53+
public CompanyCursor query(ContentResolver contentResolver, String[] projection) {
54+
Cursor cursor = contentResolver.query(uri(), projection, sel(), args(), order());
5655
if (cursor == null) return null;
5756
return new CompanyCursor(cursor);
5857
}
5958

6059
/**
61-
* Equivalent of calling {@code query(contentResolver, projection, null)}.
60+
* Equivalent of calling {@code query(contentResolver, null)}.
6261
*/
63-
public CompanyCursor query(ContentResolver contentResolver, String[] projection) {
64-
return query(contentResolver, projection, null);
62+
public CompanyCursor query(ContentResolver contentResolver) {
63+
return query(contentResolver, null);
6564
}
6665

6766
/**
68-
* Equivalent of calling {@code query(contentResolver, projection, null, null)}.
67+
* Query the given content resolver using this selection.
68+
*
69+
* @param context The context to use for the query.
70+
* @param projection A list of which columns to return. Passing null will return all columns, which is inefficient.
71+
* @return A {@code CompanyCursor} object, which is positioned before the first entry, or null.
6972
*/
70-
public CompanyCursor query(ContentResolver contentResolver) {
71-
return query(contentResolver, null, null);
73+
public CompanyCursor query(Context context, String[] projection) {
74+
Cursor cursor = context.getContentResolver().query(uri(), projection, sel(), args(), order());
75+
if (cursor == null) return null;
76+
return new CompanyCursor(cursor);
77+
}
78+
79+
/**
80+
* Equivalent of calling {@code query(context, null)}.
81+
*/
82+
public CompanyCursor query(Context context) {
83+
return query(context, null);
7284
}
7385

7486

@@ -77,6 +89,20 @@ public CompanySelection id(long... value) {
7789
return this;
7890
}
7991

92+
public CompanySelection idNot(long... value) {
93+
addNotEquals("company." + CompanyColumns._ID, toObjectArray(value));
94+
return this;
95+
}
96+
97+
public CompanySelection orderById(boolean desc) {
98+
orderBy("company." + CompanyColumns._ID, desc);
99+
return this;
100+
}
101+
102+
public CompanySelection orderById() {
103+
return orderById(false);
104+
}
105+
80106
public CompanySelection name(String... value) {
81107
addEquals(CompanyColumns.NAME, value);
82108
return this;
@@ -107,6 +133,16 @@ public CompanySelection nameEndsWith(String... value) {
107133
return this;
108134
}
109135

136+
public CompanySelection orderByName(boolean desc) {
137+
orderBy(CompanyColumns.NAME, desc);
138+
return this;
139+
}
140+
141+
public CompanySelection orderByName() {
142+
orderBy(CompanyColumns.NAME, false);
143+
return this;
144+
}
145+
110146
public CompanySelection address(String... value) {
111147
addEquals(CompanyColumns.ADDRESS, value);
112148
return this;
@@ -137,6 +173,16 @@ public CompanySelection addressEndsWith(String... value) {
137173
return this;
138174
}
139175

176+
public CompanySelection orderByAddress(boolean desc) {
177+
orderBy(CompanyColumns.ADDRESS, desc);
178+
return this;
179+
}
180+
181+
public CompanySelection orderByAddress() {
182+
orderBy(CompanyColumns.ADDRESS, false);
183+
return this;
184+
}
185+
140186
public CompanySelection serialNumberId(long... value) {
141187
addEquals(CompanyColumns.SERIAL_NUMBER_ID, toObjectArray(value));
142188
return this;
@@ -167,6 +213,16 @@ public CompanySelection serialNumberIdLtEq(long value) {
167213
return this;
168214
}
169215

216+
public CompanySelection orderBySerialNumberId(boolean desc) {
217+
orderBy(CompanyColumns.SERIAL_NUMBER_ID, desc);
218+
return this;
219+
}
220+
221+
public CompanySelection orderBySerialNumberId() {
222+
orderBy(CompanyColumns.SERIAL_NUMBER_ID, false);
223+
return this;
224+
}
225+
170226
public CompanySelection serialNumberPart0(String... value) {
171227
addEquals(SerialNumberColumns.PART0, value);
172228
return this;
@@ -197,6 +253,16 @@ public CompanySelection serialNumberPart0EndsWith(String... value) {
197253
return this;
198254
}
199255

256+
public CompanySelection orderBySerialNumberPart0(boolean desc) {
257+
orderBy(SerialNumberColumns.PART0, desc);
258+
return this;
259+
}
260+
261+
public CompanySelection orderBySerialNumberPart0() {
262+
orderBy(SerialNumberColumns.PART0, false);
263+
return this;
264+
}
265+
200266
public CompanySelection serialNumberPart1(String... value) {
201267
addEquals(SerialNumberColumns.PART1, value);
202268
return this;
@@ -226,4 +292,14 @@ public CompanySelection serialNumberPart1EndsWith(String... value) {
226292
addEndsWith(SerialNumberColumns.PART1, value);
227293
return this;
228294
}
295+
296+
public CompanySelection orderBySerialNumberPart1(boolean desc) {
297+
orderBy(SerialNumberColumns.PART1, desc);
298+
return this;
299+
}
300+
301+
public CompanySelection orderBySerialNumberPart1() {
302+
orderBy(SerialNumberColumns.PART1, false);
303+
return this;
304+
}
229305
}

Diff for: etc/sample/app/src/org/jraf/androidcontentprovidergenerator/sample/provider/manual/ManualContentValues.java

+11
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
import java.util.Date;
2828

29+
import android.content.Context;
2930
import android.content.ContentResolver;
3031
import android.net.Uri;
3132
import android.support.annotation.NonNull;
@@ -52,6 +53,16 @@ public int update(ContentResolver contentResolver, @Nullable ManualSelection whe
5253
return contentResolver.update(uri(), values(), where == null ? null : where.sel(), where == null ? null : where.args());
5354
}
5455

56+
/**
57+
* Update row(s) using the values stored by this object and the given selection.
58+
*
59+
* @param contentResolver The content resolver to use.
60+
* @param where The selection to use (can be {@code null}).
61+
*/
62+
public int update(Context context, @Nullable ManualSelection where) {
63+
return context.getContentResolver().update(uri(), values(), where == null ? null : where.sel(), where == null ? null : where.args());
64+
}
65+
5566
public ManualContentValues putTitle(@NonNull String value) {
5667
if (value == null) throw new IllegalArgumentException("title must not be null");
5768
mContentValues.put(ManualColumns.TITLE, value);

0 commit comments

Comments
 (0)