Change copy/move destination to Downloads when home directory is hidden.

Bug: 27791217
Change-Id: If196441a57053ada9875c6cc29d4c7f13fcb57e8
This commit is contained in:
Aga Wronska
2016-03-22 14:18:43 -07:00
parent 0f4ab53a53
commit 4e62716904
5 changed files with 29 additions and 22 deletions

View File

@@ -438,6 +438,17 @@ public abstract class BaseActivity extends Activity
return mState;
}
/*
* Get the default directory to be presented after starting the activity.
* Method can be overridden if the change of the behavior of the the child activity is needed.
*/
public Uri getDefaultRoot() {
return Shared.isHomeRootHidden(this)
? DocumentsContract.buildRootUri("com.android.providers.downloads.documents",
"downloads")
: DocumentsContract.buildHomeUri();
}
void setDisplayFileSize(boolean display) {
LocalPreferences.setDisplayFileSize(this, display);
mState.showSize = display;

View File

@@ -108,9 +108,7 @@ public class DocumentsActivity extends BaseActivity {
// we restore the stack as last used from that app.
if (mState.action == ACTION_PICK_COPY_DESTINATION) {
if (DEBUG) Log.d(TAG, "Launching directly into Home directory.");
Uri homeUri = DocumentsContract.buildHomeUri();
new LoadRootTask(this, homeUri).executeOnExecutor(
ProviderExecutor.forAuthority(homeUri.getAuthority()));
loadRoot(getDefaultRoot());
} else {
if (DEBUG) Log.d(TAG, "Attempting to load last used stack for calling package.");
new LoadLastUsedStackTask(this).execute();

View File

@@ -109,9 +109,7 @@ public class FilesActivity extends BaseActivity {
loadRoot(uri);
} else {
if (DEBUG) Log.d(TAG, "All other means skipped. Launching into default directory.");
Uri defaultUri = DocumentsContract.buildRootUri(
"com.android.providers.downloads.documents", "downloads");
loadRoot(defaultUri);
loadRoot(getDefaultRoot());
}
final @DialogType int dialogType = intent.getIntExtra(

View File

@@ -318,9 +318,9 @@ public class RootsFragment extends Fragment {
for (final RootInfo root : roots) {
final RootItem item = new RootItem(root);
if (root.isHome() && isHomeRootHidden(context)) {
if (root.isHome() && Shared.isHomeRootHidden(context)) {
continue;
} else if (root.isAdvanced() && areAdvancedRootsHidden(context)) {
} else if (root.isAdvanced() && Shared.areAdvancedRootsHidden(context)) {
continue;
} else if (root.isLibrary()) {
if (DEBUG) Log.d(TAG, "Adding " + root + " as library.");
@@ -372,20 +372,6 @@ public class RootsFragment extends Fragment {
}
}
/*
* Indicates if the home directory should be hidden in the roots list.
*/
private boolean isHomeRootHidden(Context context) {
return context.getResources().getBoolean(R.bool.home_root_hidden);
}
/*
* Indicates if the advanced roots should be hidden.
*/
private boolean areAdvancedRootsHidden(Context context) {
return context.getResources().getBoolean(R.bool.advanced_roots_hidden);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final Item item = getItem(position);

View File

@@ -169,4 +169,18 @@ public final class Shared {
}
}
/*
* Indicates if the home directory should be hidden in the roots list.
*/
public static boolean isHomeRootHidden(Context context) {
return context.getResources().getBoolean(R.bool.home_root_hidden);
}
/*
* Indicates if the advanced roots should be hidden.
*/
public static boolean areAdvancedRootsHidden(Context context) {
return context.getResources().getBoolean(R.bool.advanced_roots_hidden);
}
}