Changes after CR
[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 import android.content.Intent;
22
23 import android.os.Bundle;
24 import android.view.View;
25 import android.view.View.OnClickListener;
26
27 import com.owncloud.android.datamodel.OCFile;
28 import com.owncloud.android.ui.fragment.FileFragment;
29 import com.owncloud.android.ui.fragment.OCFileListFragment;
30
31 public class UploadPathActivity extends FolderPickerActivity implements FileFragment.ContainerActivity,
32 OnClickListener, OnEnforceableRefreshListener {
33
34 public static final String KEY_INSTANT_UPLOAD_PATH = "INSTANT_UPLOAD_PATH";
35
36 public static final int RESULT_OK_SET_UPLOAD_PATH = 1;
37
38 @Override
39 protected void onCreate(Bundle savedInstanceState) {
40 super.onCreate(savedInstanceState);
41
42 String instantUploadPath = getIntent().getStringExtra(KEY_INSTANT_UPLOAD_PATH);
43
44 OCFile folder = new OCFile(instantUploadPath);
45
46 setFile(folder);
47 }
48
49 /**
50 * Called when the ownCloud {@link Account} associated to the Activity was
51 * just updated.
52 */
53 @Override
54 protected void onAccountSet(boolean stateWasRecovered) {
55 super.onAccountSet(stateWasRecovered);
56 if (getAccount() != null) {
57
58 updateFileFromDB();
59
60 OCFile folder = getFile();
61 if (folder == null || !folder.isFolder()) {
62 // fall back to root folder
63 setFile(getStorageManager().getFileByPath(OCFile.ROOT_PATH));
64 folder = getFile();
65 }
66
67 onBrowsedDownTo(folder);
68
69 if (!stateWasRecovered) {
70 OCFileListFragment listOfFolders = getListOfFilesFragment();
71 listOfFolders.listDirectory(folder);
72
73 startSyncFolderOperation(folder, false);
74 }
75
76 updateNavigationElementsInActionBar();
77 }
78 }
79
80 @Override
81 public void onClick(View v) {
82 if (v == mCancelBtn) {
83 finish();
84 } else if (v == mChooseBtn) {
85 Intent data = new Intent();
86 data.putExtra(EXTRA_CURRENT_FOLDER, getCurrentFolder());
87 setResult(RESULT_OK_SET_UPLOAD_PATH, data);
88 finish();
89 }
90 }
91 }