Merge branch 'master' into develop
[pub/Android/ownCloud.git] / src / com / owncloud / android / ui / activity / UploadPathActivity.java
1 /* ownCloud Android client application
2 * Copyright (C) 2012-2014 ownCloud Inc.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2,
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 */
17
18 package com.owncloud.android.ui.activity;
19
20 import android.accounts.Account;
21
22 import android.os.Bundle;
23 import android.view.View.OnClickListener;
24
25 import com.owncloud.android.datamodel.OCFile;
26 import com.owncloud.android.ui.fragment.FileFragment;
27 import com.owncloud.android.ui.fragment.OCFileListFragment;
28
29 public class UploadPathActivity extends FolderPickerActivity implements FileFragment.ContainerActivity,
30 OnClickListener, OnEnforceableRefreshListener {
31
32 public static final String KEY_INSTANT_UPLOAD_PATH = "INSTANT_UPLOAD_PATH";
33
34
35 @Override
36 protected void onCreate(Bundle savedInstanceState) {
37 super.onCreate(savedInstanceState);
38
39 String instantUploadPath = getIntent().getStringExtra(KEY_INSTANT_UPLOAD_PATH);
40
41 // The caller activity (Preferences) is not a FileActivity, so it has no OCFile, only a path.
42 OCFile folder = new OCFile(instantUploadPath);
43
44 setFile(folder);
45 }
46
47 /**
48 * Called when the ownCloud {@link Account} associated to the Activity was
49 * just updated.
50 */
51 @Override
52 protected void onAccountSet(boolean stateWasRecovered) {
53 super.onAccountSet(stateWasRecovered);
54 if (getAccount() != null) {
55
56 updateFileFromDB();
57
58 OCFile folder = getFile();
59 if (folder == null || !folder.isFolder()) {
60 // fall back to root folder
61 setFile(getStorageManager().getFileByPath(OCFile.ROOT_PATH));
62 folder = getFile();
63 }
64
65 onBrowsedDownTo(folder);
66
67 if (!stateWasRecovered) {
68 OCFileListFragment listOfFolders = getListOfFilesFragment();
69 listOfFolders.listDirectory(folder);
70
71 startSyncFolderOperation(folder, false);
72 }
73
74 updateNavigationElementsInActionBar();
75 }
76 }
77 }