Code refactoring

Change-Id: I053ab0c691295b81dc7aa0fd858fd609a69ade81
This commit is contained in:
Fabrice Di Meglio
2014-03-10 17:30:30 -07:00
parent 489362c83c
commit 2f4556e31b

View File

@@ -160,28 +160,28 @@ 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) {
final int count = array.length; synchronized (mDataToIndex) {
for (int n = 0; n < count; n++) { final int count = array.length;
addIndexableData(array[n]); for (int n = 0; n < count; n++) {
mDataToIndex.add(array[n]);
}
} }
} }
public boolean update() { public boolean update() {
final IndexTask task = new IndexTask(); synchronized (mDataToIndex) {
task.execute(); final IndexTask task = new IndexTask();
try { task.execute(mDataToIndex);
return task.get(); try {
} catch (InterruptedException e) { return task.get();
Log.e(LOG_TAG, "Cannot update index: " + e.getMessage()); } catch (InterruptedException e) {
return false; Log.e(LOG_TAG, "Cannot update index: " + e.getMessage());
} catch (ExecutionException e) { return false;
Log.e(LOG_TAG, "Cannot update index: " + e.getMessage()); } catch (ExecutionException e) {
return false; Log.e(LOG_TAG, "Cannot update index: " + e.getMessage());
return false;
}
} }
} }
@@ -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)) {