diff options
| author | Xin Li <delphij@google.com> | 2021-10-06 22:53:54 +0000 |
|---|---|---|
| committer | Xin Li <delphij@google.com> | 2021-10-06 22:53:54 +0000 |
| commit | 8c348c41a50cb3fe83e9d2403cc34db5d5ddcb70 (patch) | |
| tree | 2ba30a68b1e5a2246c7e071219139cea61cab0e6 /src/com/android/documentsui/Model.java | |
| parent | 4bc189377da5f3cb27fb439d677cb89f3390a7a6 (diff) | |
| parent | 84af7ecf6ae45a2ab3aba9b0019baa191b430af5 (diff) | |
| download | platform_packages_apps_DocumentsUI-master.tar.gz platform_packages_apps_DocumentsUI-master.tar.bz2 platform_packages_apps_DocumentsUI-master.zip | |
Bug: 202323961
Merged-In: I64e7be8bd815a3f3bf84277ffb9ea801a5dceb24
Change-Id: Ib2ecaa196b974cec584f6ae5c1e8b4092818d73a
Diffstat (limited to 'src/com/android/documentsui/Model.java')
| -rw-r--r-- | src/com/android/documentsui/Model.java | 43 |
1 files changed, 12 insertions, 31 deletions
diff --git a/src/com/android/documentsui/Model.java b/src/com/android/documentsui/Model.java index 49e3c9b26..fdcebae3c 100644 --- a/src/com/android/documentsui/Model.java +++ b/src/com/android/documentsui/Model.java @@ -16,7 +16,6 @@ package com.android.documentsui; -import static com.android.documentsui.base.DocumentInfo.getCursorString; import static com.android.documentsui.base.SharedMinimal.DEBUG; import static com.android.documentsui.base.SharedMinimal.VERBOSE; @@ -25,7 +24,6 @@ import android.database.Cursor; import android.net.Uri; import android.os.Bundle; import android.provider.DocumentsContract; -import android.provider.DocumentsContract.Document; import android.util.Log; import androidx.annotation.IntDef; @@ -125,11 +123,21 @@ public class Model { return; } - mCursor = result.cursor; + mCursor = result.getCursor(); mCursorCount = mCursor.getCount(); doc = result.doc; - updateModelData(); + if (result.getModelIds() != null && result.getFileNames() != null) { + mIds = result.getModelIds(); + mFileNames.clear(); + mFileNames.addAll(result.getFileNames()); + + // Populate the positions. + mPositions.clear(); + for (int i = 0; i < mCursorCount; ++i) { + mPositions.put(mIds[i], i); + } + } final Bundle extras = mCursor.getExtras(); if (extras != null) { @@ -146,33 +154,6 @@ public class Model { return mCursorCount; } - /** - * Scan over the incoming cursor data, generate Model IDs for each row, and sort the IDs - * according to the current sort order. - */ - private void updateModelData() { - mIds = new String[mCursorCount]; - mFileNames.clear(); - mCursor.moveToPosition(-1); - for (int pos = 0; pos < mCursorCount; ++pos) { - if (!mCursor.moveToNext()) { - Log.e(TAG, "Fail to move cursor to next pos: " + pos); - return; - } - // Generates a Model ID for a cursor entry that refers to a document. The Model ID is a - // unique string that can be used to identify the document referred to by the cursor. - // Prefix the ids with the authority to avoid collisions. - mIds[pos] = ModelId.build(mCursor); - mFileNames.add(getCursorString(mCursor, Document.COLUMN_DISPLAY_NAME)); - } - - // Populate the positions. - mPositions.clear(); - for (int i = 0; i < mCursorCount; ++i) { - mPositions.put(mIds[i], i); - } - } - public boolean hasFileWithName(String name) { return mFileNames.contains(name); } |
