Merge "Revert "Precompute cursor indexes in DocumentsUI and improve perf by 2.7%."" into nyc-dev
am: ee6d8be
* commit 'ee6d8be53e1dabf7669150e7e7e39daa58cac542':
Revert "Precompute cursor indexes in DocumentsUI and improve perf by 2.7%."
Change-Id: I62bb1b479d521b24d1cf1ef05675ba887973867b
This commit is contained in:
@@ -156,7 +156,8 @@ public final class Shared {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Compare two strings against each other using system default collator in a
|
* Compare two strings against each other using system default collator in a
|
||||||
* case-insensitive mode.
|
* case-insensitive mode. Clusters strings prefixed with {@link DIR_PREFIX}
|
||||||
|
* before other items.
|
||||||
*/
|
*/
|
||||||
public static int compareToIgnoreCaseNullable(String lhs, String rhs) {
|
public static int compareToIgnoreCaseNullable(String lhs, String rhs) {
|
||||||
final boolean leftEmpty = TextUtils.isEmpty(lhs);
|
final boolean leftEmpty = TextUtils.isEmpty(lhs);
|
||||||
@@ -169,14 +170,6 @@ public final class Shared {
|
|||||||
return sCollator.compare(lhs, rhs);
|
return sCollator.compare(lhs, rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Compare two strings against each other using system default collator in a
|
|
||||||
* case-insensitive mode.
|
|
||||||
*/
|
|
||||||
public static int compareToIgnoreCase(String lhs, String rhs) {
|
|
||||||
return sCollator.compare(lhs, rhs);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isHardwareKeyboardAvailable(Context context) {
|
public static boolean isHardwareKeyboardAvailable(Context context) {
|
||||||
return context.getResources().getConfiguration().keyboard != Configuration.KEYBOARD_NOKEYS;
|
return context.getResources().getConfiguration().keyboard != Configuration.KEYBOARD_NOKEYS;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ import static com.android.documentsui.Shared.DEBUG;
|
|||||||
import static com.android.documentsui.State.SORT_ORDER_DISPLAY_NAME;
|
import static com.android.documentsui.State.SORT_ORDER_DISPLAY_NAME;
|
||||||
import static com.android.documentsui.State.SORT_ORDER_LAST_MODIFIED;
|
import static com.android.documentsui.State.SORT_ORDER_LAST_MODIFIED;
|
||||||
import static com.android.documentsui.State.SORT_ORDER_SIZE;
|
import static com.android.documentsui.State.SORT_ORDER_SIZE;
|
||||||
|
import static com.android.documentsui.model.DocumentInfo.getCursorLong;
|
||||||
|
import static com.android.documentsui.model.DocumentInfo.getCursorString;
|
||||||
|
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.database.MergeCursor;
|
import android.database.MergeCursor;
|
||||||
@@ -48,7 +50,6 @@ import java.util.Map;
|
|||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public class Model {
|
public class Model {
|
||||||
private static final String TAG = "Model";
|
private static final String TAG = "Model";
|
||||||
private static final String EMPTY = "";
|
|
||||||
|
|
||||||
private boolean mIsLoading;
|
private boolean mIsLoading;
|
||||||
private List<UpdateListener> mUpdateListeners = new ArrayList<>();
|
private List<UpdateListener> mUpdateListeners = new ArrayList<>();
|
||||||
@@ -63,13 +64,6 @@ public class Model {
|
|||||||
private String mIds[] = new String[0];
|
private String mIds[] = new String[0];
|
||||||
private int mSortOrder = SORT_ORDER_DISPLAY_NAME;
|
private int mSortOrder = SORT_ORDER_DISPLAY_NAME;
|
||||||
|
|
||||||
private int mAuthorityIndex = -1;
|
|
||||||
private int mDocIdIndex = -1;
|
|
||||||
private int mMimeTypeIndex = -1;
|
|
||||||
private int mDisplayNameIndex = -1;
|
|
||||||
private int mSizeIndex = -1;
|
|
||||||
private int mLastModifiedIndex = -1;
|
|
||||||
|
|
||||||
@Nullable String info;
|
@Nullable String info;
|
||||||
@Nullable String error;
|
@Nullable String error;
|
||||||
@Nullable DocumentInfo doc;
|
@Nullable DocumentInfo doc;
|
||||||
@@ -111,14 +105,6 @@ public class Model {
|
|||||||
mCursor = result.cursor;
|
mCursor = result.cursor;
|
||||||
mCursorCount = mCursor.getCount();
|
mCursorCount = mCursor.getCount();
|
||||||
mSortOrder = result.sortOrder;
|
mSortOrder = result.sortOrder;
|
||||||
mAuthorityIndex = mCursor.getColumnIndex(RootCursorWrapper.COLUMN_AUTHORITY);
|
|
||||||
assert(mAuthorityIndex != -1);
|
|
||||||
mDocIdIndex = mCursor.getColumnIndex(Document.COLUMN_DOCUMENT_ID);
|
|
||||||
mMimeTypeIndex = mCursor.getColumnIndex(Document.COLUMN_MIME_TYPE);
|
|
||||||
mDisplayNameIndex = mCursor.getColumnIndex(Document.COLUMN_DISPLAY_NAME);
|
|
||||||
mLastModifiedIndex = mCursor.getColumnIndex(Document.COLUMN_LAST_MODIFIED);
|
|
||||||
mSizeIndex = mCursor.getColumnIndex(Document.COLUMN_SIZE);
|
|
||||||
|
|
||||||
doc = result.doc;
|
doc = result.doc;
|
||||||
|
|
||||||
updateModelData();
|
updateModelData();
|
||||||
@@ -171,23 +157,26 @@ public class Model {
|
|||||||
// If the cursor is a merged cursor over multiple authorities, then prefix the ids
|
// If the cursor is a merged cursor over multiple authorities, then prefix the ids
|
||||||
// with the authority to avoid collisions.
|
// with the authority to avoid collisions.
|
||||||
if (mCursor instanceof MergeCursor) {
|
if (mCursor instanceof MergeCursor) {
|
||||||
mIds[pos] = getStringOrEmpty(mAuthorityIndex) + "|" + getStringOrEmpty(mDocIdIndex);
|
mIds[pos] = getCursorString(mCursor, RootCursorWrapper.COLUMN_AUTHORITY) + "|" +
|
||||||
|
getCursorString(mCursor, Document.COLUMN_DOCUMENT_ID);
|
||||||
} else {
|
} else {
|
||||||
mIds[pos] = getStringOrEmpty(mDocIdIndex);
|
mIds[pos] = getCursorString(mCursor, Document.COLUMN_DOCUMENT_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
mimeType = getStringOrEmpty(mMimeTypeIndex);
|
mimeType = getCursorString(mCursor, Document.COLUMN_MIME_TYPE);
|
||||||
isDirs[pos] = Document.MIME_TYPE_DIR.equals(mimeType);
|
isDirs[pos] = Document.MIME_TYPE_DIR.equals(mimeType);
|
||||||
|
|
||||||
switch (mSortOrder) {
|
switch(mSortOrder) {
|
||||||
case SORT_ORDER_DISPLAY_NAME:
|
case SORT_ORDER_DISPLAY_NAME:
|
||||||
displayNames[pos] = getStringOrEmpty(mDisplayNameIndex);
|
final String displayName = getCursorString(
|
||||||
|
mCursor, Document.COLUMN_DISPLAY_NAME);
|
||||||
|
displayNames[pos] = displayName;
|
||||||
break;
|
break;
|
||||||
case SORT_ORDER_LAST_MODIFIED:
|
case SORT_ORDER_LAST_MODIFIED:
|
||||||
longValues[pos] = getLastModified();
|
longValues[pos] = getLastModified(mCursor);
|
||||||
break;
|
break;
|
||||||
case SORT_ORDER_SIZE:
|
case SORT_ORDER_SIZE:
|
||||||
longValues[pos] = getDocSize();
|
longValues[pos] = getCursorLong(mCursor, Document.COLUMN_SIZE);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -243,7 +232,7 @@ public class Model {
|
|||||||
} else {
|
} else {
|
||||||
final String lhs = pivotValue;
|
final String lhs = pivotValue;
|
||||||
final String rhs = sortKey[mid];
|
final String rhs = sortKey[mid];
|
||||||
compare = Shared.compareToIgnoreCase(lhs, rhs);
|
compare = Shared.compareToIgnoreCaseNullable(lhs, rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (compare < 0) {
|
if (compare < 0) {
|
||||||
@@ -363,43 +352,14 @@ public class Model {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return Value of the string column, or an empty string if no value, or empty value.
|
|
||||||
*/
|
|
||||||
private String getStringOrEmpty(int columnIndex) {
|
|
||||||
if (columnIndex == -1)
|
|
||||||
return EMPTY;
|
|
||||||
final String result = mCursor.getString(columnIndex);
|
|
||||||
return result != null ? result : EMPTY;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Timestamp for the given document. Some docs (e.g. active downloads) have a null
|
* @return Timestamp for the given document. Some docs (e.g. active downloads) have a null
|
||||||
* or missing timestamp - these will be replaced with MAX_LONG so that such files get sorted to
|
* timestamp - these will be replaced with MAX_LONG so that such files get sorted to the top
|
||||||
* the top when sorting by date.
|
* when sorting by date.
|
||||||
*/
|
*/
|
||||||
private long getLastModified() {
|
long getLastModified(Cursor cursor) {
|
||||||
if (mLastModifiedIndex == -1)
|
long l = getCursorLong(mCursor, Document.COLUMN_LAST_MODIFIED);
|
||||||
return Long.MAX_VALUE;
|
return (l == -1) ? Long.MAX_VALUE : l;
|
||||||
try {
|
|
||||||
final long result = mCursor.getLong(mLastModifiedIndex);
|
|
||||||
return result > 0 ? result : Long.MAX_VALUE;
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
return Long.MAX_VALUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return Size for the given document. If the size is unknown or invalid, returns 0.
|
|
||||||
*/
|
|
||||||
private long getDocSize() {
|
|
||||||
if (mSizeIndex == -1)
|
|
||||||
return 0;
|
|
||||||
try {
|
|
||||||
return mCursor.getLong(mSizeIndex);
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public @Nullable Cursor getItem(String modelId) {
|
public @Nullable Cursor getItem(String modelId) {
|
||||||
|
|||||||
Reference in New Issue
Block a user