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.SortModel; 26 import com.android.documentsui.sorting.SortDimension.SortDirection; 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 35 // Null when viewing Recents directory. 36 @Nullable DocumentInfo mDocument; 37 // Here we save the clip details of moveTo/copyTo actions when picker shows up. 38 // This will be written to saved instance. 39 @Nullable FileOperation mPendingOperation; 40 int mLastSortDimensionId = SortModel.SORT_DIMENSION_ID_UNKNOWN; 41 @SortDirection int mLastSortDirection; 42 43 private RootInfo mRoot; 44 private String mConfigKey; 45 restore(Bundle bundle)46 public void restore(Bundle bundle) { 47 mRoot = bundle.getParcelable(Shared.EXTRA_ROOT); 48 mDocument = bundle.getParcelable(Shared.EXTRA_DOC); 49 mPendingOperation = bundle.getParcelable(FileOperationService.EXTRA_OPERATION); 50 mLastSortDimensionId = bundle.getInt(EXTRA_SORT_DIMENSION_ID); 51 mLastSortDirection = bundle.getInt(EXTRA_SORT_DIRECTION); 52 } 53 save(Bundle bundle)54 public void save(Bundle bundle) { 55 bundle.putParcelable(Shared.EXTRA_ROOT, mRoot); 56 bundle.putParcelable(Shared.EXTRA_DOC, mDocument); 57 bundle.putParcelable(FileOperationService.EXTRA_OPERATION, mPendingOperation); 58 bundle.putInt(EXTRA_SORT_DIMENSION_ID, mLastSortDimensionId); 59 bundle.putInt(EXTRA_SORT_DIRECTION, mLastSortDirection); 60 } 61 claimPendingOperation()62 public FileOperation claimPendingOperation() { 63 FileOperation op = mPendingOperation; 64 mPendingOperation = null; 65 return op; 66 } 67 update(RootInfo root, DocumentInfo doc)68 public void update(RootInfo root, DocumentInfo doc) { 69 mRoot = root; 70 mDocument = doc; 71 } 72 getConfigKey()73 String getConfigKey() { 74 if (mConfigKey == null) { 75 final StringBuilder builder = new StringBuilder(); 76 builder.append(mRoot != null ? mRoot.authority : "null").append(';'); 77 builder.append(mRoot != null ? mRoot.rootId : "null").append(';'); 78 builder.append(mDocument != null ? mDocument.documentId : "null"); 79 mConfigKey = builder.toString(); 80 } 81 return mConfigKey; 82 } 83 }