Merge pull request #1088 from owncloud/updated_docs_about_target_of_PRs
[pub/Android/ownCloud.git] / src / com / owncloud / android / ui / activity / UploadPathActivity.java
index 2a49352..db704d1 100644 (file)
@@ -1,5 +1,7 @@
-/* ownCloud Android client application
- *   Copyright (C) 2012-2014 ownCloud Inc.
+/**
+ *   ownCloud Android client application
+ *
+ *   Copyright (C) 2015 ownCloud Inc.
  *
  *   This program is free software: you can redistribute it and/or modify
  *   it under the terms of the GNU General Public License version 2,
 
 package com.owncloud.android.ui.activity;
 
-import android.content.Intent;
-
+import android.accounts.Account;
 import android.os.Bundle;
-import android.view.View;
 import android.view.View.OnClickListener;
-import android.widget.Toast;
-
-
 
 import com.owncloud.android.datamodel.OCFile;
 import com.owncloud.android.ui.fragment.FileFragment;
+import com.owncloud.android.ui.fragment.OCFileListFragment;
 
+public class UploadPathActivity extends FolderPickerActivity implements FileFragment.ContainerActivity,
+        OnClickListener, OnEnforceableRefreshListener {
 
-public class UploadPathActivity extends FolderPickerActivity implements FileFragment.ContainerActivity, 
-    OnClickListener, OnEnforceableRefreshListener {
-
-    public static final int RESULT_OK_SET_UPLOAD_PATH = 1;
+    public static final String KEY_INSTANT_UPLOAD_PATH = "INSTANT_UPLOAD_PATH";
 
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
-        
-        Intent intent = getIntent();
-        String instantUploadPath = intent.getStringExtra("instant_upload_path");
-        
+
+        String instantUploadPath = getIntent().getStringExtra(KEY_INSTANT_UPLOAD_PATH);
+
+        // The caller activity (Preferences) is not a FileActivity, so it has no OCFile, only a path.
         OCFile folder = new OCFile(instantUploadPath);
-        
-        Toast.makeText(getApplicationContext(), instantUploadPath, Toast.LENGTH_LONG).show();
-        
-//        onBrowsedDownTo(folder);
-    }
 
+        setFile(folder);
+    }
 
+    /**
+     * Called when the ownCloud {@link Account} associated to the Activity was
+     * just updated.
+     */
     @Override
-    public void onClick(View v) {
-        if (v == mCancelBtn) {
-            finish();
-        } else if (v == mChooseBtn) {
-            Intent i = getIntent();
-            OCFile targetFile = (OCFile) i.getParcelableExtra(UploadPathActivity.EXTRA_TARGET_FILE);
-
-            Intent data = new Intent();
-            data.putExtra(EXTRA_CURRENT_FOLDER, getCurrentFolder());
-            data.putExtra(EXTRA_TARGET_FILE, targetFile);
-            setResult(RESULT_OK_SET_UPLOAD_PATH, data);
-            finish();
+    protected void onAccountSet(boolean stateWasRecovered) {
+        super.onAccountSet(stateWasRecovered);
+        if (getAccount() != null) {
+
+            updateFileFromDB();
+
+            OCFile folder = getFile();
+            if (folder == null || !folder.isFolder()) {
+                // fall back to root folder
+                setFile(getStorageManager().getFileByPath(OCFile.ROOT_PATH));
+                folder = getFile();
+            }
+
+            onBrowsedDownTo(folder);
+
+            if (!stateWasRecovered) {
+                OCFileListFragment listOfFolders = getListOfFilesFragment();
+                // TODO Enable when "On Device" is recovered ?
+                listOfFolders.listDirectory(folder/*, false*/);
+
+                startSyncFolderOperation(folder, false);
+            }
+
+            updateNavigationElementsInActionBar();
         }
     }
 }