• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.android.documentsui.dirlist;
17 
18 import android.os.Bundle;
19 
20 import com.android.documentsui.base.DocumentInfo;
21 import com.android.documentsui.base.RootInfo;
22 import com.android.documentsui.base.Shared;
23 import com.android.documentsui.services.FileOperation;
24 import com.android.documentsui.services.FileOperationService;
25 import com.android.documentsui.sorting.SortDimension.SortDirection;
26 import com.android.documentsui.sorting.SortModel;
27 
28 import javax.annotation.Nullable;
29 
30 final class DirectoryState {
31 
32     private static final String EXTRA_SORT_DIMENSION_ID = "sortDimensionId";
33     private static final String EXTRA_SORT_DIRECTION = "sortDirection";
34     private static final String EXTRA_SELECTION_ID = "selectionId";
35 
36     // Null when viewing Recents directory.
37     @Nullable DocumentInfo mDocument;
38     // Here we save the clip details of moveTo/copyTo actions when picker shows up.
39     // This will be written to saved instance.
40     @Nullable FileOperation mPendingOperation;
41     int mLastSortDimensionId = SortModel.SORT_DIMENSION_ID_UNKNOWN;
42     @SortDirection int mLastSortDirection;
43 
44     // The unique id to identify the selection. It is null when the corresponding
45     // container (fragment/activity) is the first launch.
46     @Nullable String mSelectionId;
47 
48     private RootInfo mRoot;
49     private String mConfigKey;
50 
restore(Bundle bundle)51     public void restore(Bundle bundle) {
52         mRoot = bundle.getParcelable(Shared.EXTRA_ROOT);
53         mDocument = bundle.getParcelable(Shared.EXTRA_DOC);
54         mPendingOperation = bundle.getParcelable(FileOperationService.EXTRA_OPERATION);
55         mLastSortDimensionId = bundle.getInt(EXTRA_SORT_DIMENSION_ID);
56         mLastSortDirection = bundle.getInt(EXTRA_SORT_DIRECTION);
57         mSelectionId = bundle.getString(EXTRA_SELECTION_ID);
58     }
59 
save(Bundle bundle)60     public void save(Bundle bundle) {
61         bundle.putParcelable(Shared.EXTRA_ROOT, mRoot);
62         bundle.putParcelable(Shared.EXTRA_DOC, mDocument);
63         bundle.putParcelable(FileOperationService.EXTRA_OPERATION, mPendingOperation);
64         bundle.putInt(EXTRA_SORT_DIMENSION_ID, mLastSortDimensionId);
65         bundle.putInt(EXTRA_SORT_DIRECTION, mLastSortDirection);
66         bundle.putString(EXTRA_SELECTION_ID, mSelectionId);
67     }
68 
claimPendingOperation()69     public FileOperation claimPendingOperation() {
70         FileOperation op = mPendingOperation;
71         mPendingOperation = null;
72         return op;
73     }
74 
getConfigKey()75     String getConfigKey() {
76         if (mConfigKey == null) {
77             final StringBuilder builder = new StringBuilder();
78             builder.append(mRoot != null ? mRoot.authority : "null").append(';');
79             builder.append(mRoot != null ? mRoot.rootId : "null").append(';');
80             builder.append(mDocument != null ? mDocument.documentId : "null");
81             mConfigKey = builder.toString();
82         }
83         return mConfigKey;
84     }
85 }