Code refactoring
Change-Id: I053ab0c691295b81dc7aa0fd858fd609a69ade81
This commit is contained in:
@@ -160,20 +160,19 @@ public class Index {
|
|||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addIndexableData(IndexableData data) {
|
|
||||||
mDataToIndex.add(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addIndexableData(IndexableData[] array) {
|
public void addIndexableData(IndexableData[] array) {
|
||||||
|
synchronized (mDataToIndex) {
|
||||||
final int count = array.length;
|
final int count = array.length;
|
||||||
for (int n = 0; n < count; n++) {
|
for (int n = 0; n < count; n++) {
|
||||||
addIndexableData(array[n]);
|
mDataToIndex.add(array[n]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean update() {
|
public boolean update() {
|
||||||
|
synchronized (mDataToIndex) {
|
||||||
final IndexTask task = new IndexTask();
|
final IndexTask task = new IndexTask();
|
||||||
task.execute();
|
task.execute(mDataToIndex);
|
||||||
try {
|
try {
|
||||||
return task.get();
|
return task.get();
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
@@ -184,6 +183,7 @@ public class Index {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private SQLiteDatabase getReadableDatabase() {
|
private SQLiteDatabase getReadableDatabase() {
|
||||||
return IndexDatabaseHelper.getInstance(mContext).getReadableDatabase();
|
return IndexDatabaseHelper.getInstance(mContext).getReadableDatabase();
|
||||||
@@ -196,7 +196,7 @@ public class Index {
|
|||||||
/**
|
/**
|
||||||
* A private class for updating the Index database
|
* A private class for updating the Index database
|
||||||
*/
|
*/
|
||||||
private class IndexTask extends AsyncTask<Void, Integer, Boolean> {
|
private class IndexTask extends AsyncTask<List<IndexableData>, Integer, Boolean> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPreExecute() {
|
protected void onPreExecute() {
|
||||||
@@ -211,9 +211,13 @@ public class Index {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Boolean doInBackground(Void... params) {
|
protected Boolean doInBackground(List<IndexableData>... params) {
|
||||||
final SQLiteDatabase database = getWritableDatabase();
|
|
||||||
boolean result = false;
|
boolean result = false;
|
||||||
|
final List<IndexableData> dataToIndex = params[0];
|
||||||
|
if (null == dataToIndex || dataToIndex.size() == 0) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
final SQLiteDatabase database = getWritableDatabase();
|
||||||
final Locale locale = Locale.getDefault();
|
final Locale locale = Locale.getDefault();
|
||||||
final String localeStr = locale.toString();
|
final String localeStr = locale.toString();
|
||||||
if (isLocaleAlreadyIndexed(database, locale)) {
|
if (isLocaleAlreadyIndexed(database, locale)) {
|
||||||
|
Reference in New Issue
Block a user