Skip to content

Commit

Permalink
Anthology sort order changed (#1151)
Browse files Browse the repository at this point in the history
* Added sort field to Anthology to properly sort the list

* Reverted insert method for Anthology
  • Loading branch information
mXaln authored and jsarabia committed Jul 15, 2019
1 parent ce3f260 commit 1bd5e71
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 12 deletions.
1 change: 1 addition & 0 deletions translationRecorder/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />

<application
android:name=".TranslationRecorderApp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,6 @@
"chunk_plugin": {
"jar" : "biblechunk.jar",
"class": "org.wycliffeassociates.translationrecorder.biblechunk.BibleChunkPlugin"
}
},
"sort": 2
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@
"chunk_plugin": {
"jar" : "obschunk.jar",
"class": "org.wycliffeassociates.translationrecorder.obschunk.ObsChunkPlugin"
}
},
"sort": 3
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,6 @@
"chunk_plugin": {
"jar" : "biblechunk.jar",
"class": "org.wycliffeassociates.translationrecorder.biblechunk.BibleChunkPlugin"
}
},
"sort": 1
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public static abstract class AnthologyEntry implements BaseColumns {
public static final String ANTHOLOGY_SLUG = "slug";
public static final String ANTHOLOGY_NAME = "name";
public static final String ANTHOLOGY_RESOURCE = "resource";
public static final String ANTHOLOGY_SORT = "sort";
public static final String ANTHOLOGY_REGEX = "regex";
public static final String ANTHOLOGY_GROUPS = "groups";
public static final String ANTHOLOGY_MASK = "mask";
Expand All @@ -63,6 +64,7 @@ public static abstract class AnthologyEntry implements BaseColumns {
+ ANTHOLOGY_SLUG + TEXTCOMMA
+ ANTHOLOGY_NAME + TEXTCOMMA
+ ANTHOLOGY_RESOURCE + TEXTCOMMA
+ ANTHOLOGY_SORT + INTCOMMA
+ ANTHOLOGY_REGEX + TEXTCOMMA
+ ANTHOLOGY_GROUPS + TEXTCOMMA
+ ANTHOLOGY_MASK + TEXTCOMMA
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -605,12 +605,13 @@ public Anthology getAnthology(int id) throws IllegalArgumentException {
String anthologySlug = cursor.getString(cursor.getColumnIndex(ProjectContract.AnthologyEntry.ANTHOLOGY_SLUG));
String anthologyName = cursor.getString(cursor.getColumnIndex(ProjectContract.AnthologyEntry.ANTHOLOGY_NAME));
String resourceSlug = cursor.getString(cursor.getColumnIndex(ProjectContract.AnthologyEntry.ANTHOLOGY_RESOURCE));
int sort = cursor.getInt(cursor.getColumnIndex(ProjectContract.AnthologyEntry.ANTHOLOGY_SORT));
String regex = cursor.getString(cursor.getColumnIndex(ProjectContract.AnthologyEntry.ANTHOLOGY_REGEX));
String groups = cursor.getString(cursor.getColumnIndex(ProjectContract.AnthologyEntry.ANTHOLOGY_GROUPS));
String mask = cursor.getString(cursor.getColumnIndex(ProjectContract.AnthologyEntry.ANTHOLOGY_MASK));
String pluginClassName = cursor.getString(cursor.getColumnIndex(ProjectContract.AnthologyEntry.PLUGIN_CLASS));
String pluginJarName = cursor.getString(cursor.getColumnIndex(ProjectContract.AnthologyEntry.PLUGIN_JAR));
anthology = new Anthology(anthologySlug, anthologyName, resourceSlug, regex, groups, mask, pluginJarName, pluginClassName);
anthology = new Anthology(anthologySlug, anthologyName, resourceSlug, sort, regex, groups, mask, pluginJarName, pluginClassName);
} else {
throw new IllegalArgumentException("Anthology id " + id + " not found in database.");
}
Expand Down Expand Up @@ -668,13 +669,14 @@ public void addLanguages(Language[] languages) {
}
}

public void addAnthology(String anthologySlug, String name, String resource,
public void addAnthology(String anthologySlug, String name, String resource, int sort,
String regex, String groups, String mask, String jarName, String className) {
SQLiteDatabase db = getWritableDatabase();
ContentValues cv = new ContentValues();
cv.put(ProjectContract.AnthologyEntry.ANTHOLOGY_SLUG, anthologySlug);
cv.put(ProjectContract.AnthologyEntry.ANTHOLOGY_NAME, name);
cv.put(ProjectContract.AnthologyEntry.ANTHOLOGY_RESOURCE, resource);
cv.put(ProjectContract.AnthologyEntry.ANTHOLOGY_SORT, sort);
cv.put(ProjectContract.AnthologyEntry.ANTHOLOGY_REGEX, regex);
cv.put(ProjectContract.AnthologyEntry.ANTHOLOGY_GROUPS, groups);
cv.put(ProjectContract.AnthologyEntry.ANTHOLOGY_MASK, mask);
Expand Down Expand Up @@ -1625,7 +1627,8 @@ public Language[] getLanguages() {

public Anthology[] getAnthologies() {
List<Anthology> anthologyList = new ArrayList<>();
String query = "SELECT * FROM " + ProjectContract.AnthologyEntry.TABLE_ANTHOLOGY;
String query = "SELECT * FROM " + ProjectContract.AnthologyEntry.TABLE_ANTHOLOGY +
" ORDER BY " + ProjectContract.AnthologyEntry.ANTHOLOGY_SORT + " ASC";
SQLiteDatabase db = getReadableDatabase();
db.beginTransaction();
Cursor cursor = db.rawQuery(query, null);
Expand All @@ -1634,12 +1637,13 @@ public Anthology[] getAnthologies() {
String anthologySlug = cursor.getString(cursor.getColumnIndex(ProjectContract.AnthologyEntry.ANTHOLOGY_SLUG));
String anthologyName = cursor.getString(cursor.getColumnIndex(ProjectContract.AnthologyEntry.ANTHOLOGY_NAME));
String resource = cursor.getString(cursor.getColumnIndex(ProjectContract.AnthologyEntry.ANTHOLOGY_RESOURCE));
int sort = cursor.getInt(cursor.getColumnIndex(ProjectContract.AnthologyEntry.ANTHOLOGY_SORT));
String regex = cursor.getString(cursor.getColumnIndex(ProjectContract.AnthologyEntry.ANTHOLOGY_REGEX));
String groups = cursor.getString(cursor.getColumnIndex(ProjectContract.AnthologyEntry.ANTHOLOGY_GROUPS));
String mask = cursor.getString(cursor.getColumnIndex(ProjectContract.AnthologyEntry.ANTHOLOGY_MASK));
String jarName = cursor.getString(cursor.getColumnIndex(ProjectContract.AnthologyEntry.PLUGIN_JAR));
String className = cursor.getString(cursor.getColumnIndex(ProjectContract.AnthologyEntry.PLUGIN_CLASS));
anthologyList.add(new Anthology(anthologySlug, anthologyName, resource, regex, groups, mask, jarName, className));
anthologyList.add(new Anthology(anthologySlug, anthologyName, resource, sort, regex, groups, mask, jarName, className));
} while (cursor.moveToNext());
}
cursor.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class ProjectPlugin {
String jarPath;
String className;
String versionsPath;
int sort;

//groups
int language = -1;
Expand Down Expand Up @@ -127,7 +128,7 @@ private List<Version> readVersions(JsonReader jsonReader) throws IOException {

private void importPluginToDatabase(Context ctx, Book[] books, Version[] versions, Mode[] modes) {
ProjectDatabaseHelper db = new ProjectDatabaseHelper(ctx);
db.addAnthology(slug, name, resource, regex, groups, mask, jarPath, className);
db.addAnthology(slug, name, resource, sort, regex, groups, mask, jarPath, className);
db.addBooks(books);
db.addVersions(versions);
db.addModes(modes, slug);
Expand Down Expand Up @@ -174,6 +175,8 @@ private void readPlugin(JsonReader jsonReader) throws IOException {
readModesSection(jsonReader);
} else if (key.equals("chunk_plugin")) {
readChunkSection(jsonReader);
} else if (key.equals("sort")) {
sort = jsonReader.nextInt();
}
}
jsonReader.endObject();
Expand Down Expand Up @@ -265,6 +268,7 @@ public void readChunkSection(JsonReader jsonReader) throws IOException
className = jsonReader.nextString();
}
}
jsonReader.endObject();
}
public String getBooksPath() {
return booksPath;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ public class Anthology extends ProjectComponent implements Parcelable {
private String mPluginClassName;
private String mPluginJarName;
private String mResource;
private int mSort;
private String mRegex;
private String mGroups;
private String mMask;

public Anthology(String slug, String name, String resource,
public Anthology(String slug, String name, String resource, int sort,
String regex, String groups, String mask, String pluginJarName, String pluginClassName) {
super(slug, name);
super(slug, name, sort);
mResource = resource;
mSort = sort;
mRegex = regex;
mGroups = groups;
mMask = mask;
Expand All @@ -37,6 +39,10 @@ public String getResource(){
return mResource;
}

public int getSort(){
return mSort;
}

public String getRegex() {
return mRegex;
}
Expand Down Expand Up @@ -75,6 +81,7 @@ public void writeToParcel(Parcel dest, int flags) {
dest.writeString(mSlug);
dest.writeString(mName);
dest.writeString(mResource);
dest.writeInt(mSort);
dest.writeString(mRegex);
dest.writeString(mGroups);
dest.writeString(mMask);
Expand All @@ -95,6 +102,7 @@ public Anthology[] newArray(int size) {
public Anthology(Parcel in) {
super(in);
mResource = in.readString();
mSort = in.readInt();
mRegex = in.readString();
mGroups = in.readString();
mMask = in.readString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,19 @@ public abstract class ProjectComponent implements Comparable, Parcelable {

protected String mSlug;
protected String mName;
protected int mSort;

public ProjectComponent(String slug, String name) {
mSlug = slug;
mName = name;
}

public ProjectComponent(String slug, String name, int sort) {
mSlug = slug;
mName = name;
mSort = sort;
}

public String getSlug() {
return mSlug;
}
Expand All @@ -25,12 +32,21 @@ public String getName() {
return mName;
}

public int getSort() {
return mSort;
}

public abstract String getLabel();

@Override
public int compareTo(Object another) {
String anotherCode = ((ProjectComponent)another).getSlug();
return mSlug.compareToIgnoreCase(anotherCode);
if(this instanceof Anthology) {
int anotherSort = ((ProjectComponent)another).getSort();
return mSort - anotherSort;
} else {
String anotherCode = ((ProjectComponent)another).getSlug();
return mSlug.compareToIgnoreCase(anotherCode);
}
}

public boolean displayMoreIcon() {
Expand Down

0 comments on commit 1bd5e71

Please sign in to comment.