Fixed: Rotating screen after viewing a file would return you to the
[pub/Android/ownCloud.git] / src / eu / alefzero / owncloud / ui / activity / FileDisplayActivity.java
index 10a8671..47dae5f 100644 (file)
 \r
 package eu.alefzero.owncloud.ui.activity;\r
 \r
+import java.io.File;\r
+import java.net.URLDecoder;\r
+import java.net.URLEncoder;\r
+import java.util.ArrayList;\r
+import java.util.Arrays;\r
+\r
 import android.accounts.Account;\r
 import android.accounts.AccountManager;\r
 import android.app.AlertDialog;\r
 import android.app.AlertDialog.Builder;\r
 import android.app.Dialog;\r
+import android.content.BroadcastReceiver;\r
+import android.content.ContentResolver;\r
+import android.content.Context;\r
 import android.content.DialogInterface;\r
-import android.content.DialogInterface.OnCancelListener;\r
 import android.content.DialogInterface.OnClickListener;\r
 import android.content.Intent;\r
+import android.content.IntentFilter;\r
+import android.database.Cursor;\r
 import android.net.Uri;\r
 import android.os.Bundle;\r
+import android.provider.MediaStore;\r
+import android.util.Log;\r
 import android.view.View;\r
 import android.view.ViewGroup;\r
 import android.widget.ArrayAdapter;\r
@@ -41,11 +53,17 @@ import com.actionbarsherlock.app.SherlockFragmentActivity;
 import com.actionbarsherlock.view.Menu;\r
 import com.actionbarsherlock.view.MenuInflater;\r
 import com.actionbarsherlock.view.MenuItem;\r
+import com.actionbarsherlock.view.Window;\r
 \r
+import eu.alefzero.owncloud.AccountUtils;\r
 import eu.alefzero.owncloud.R;\r
 import eu.alefzero.owncloud.authenticator.AccountAuthenticator;\r
-import eu.alefzero.owncloud.authenticator.AuthUtils;\r
+import eu.alefzero.owncloud.datamodel.DataStorageManager;\r
+import eu.alefzero.owncloud.datamodel.FileDataStorageManager;\r
 import eu.alefzero.owncloud.datamodel.OCFile;\r
+import eu.alefzero.owncloud.files.services.FileUploader;\r
+import eu.alefzero.owncloud.syncadapter.FileSyncService;\r
+import eu.alefzero.owncloud.ui.fragment.FileDetailFragment;\r
 import eu.alefzero.owncloud.ui.fragment.FileListFragment;\r
 import eu.alefzero.webdav.WebdavClient;\r
 \r
@@ -57,219 +75,476 @@ import eu.alefzero.webdav.WebdavClient;
  */\r
 \r
 public class FileDisplayActivity extends SherlockFragmentActivity implements\r
-               OnNavigationListener {\r
-       private ArrayAdapter<String> mDirectories;\r
-\r
-       private static final int DIALOG_CHOOSE_ACCOUNT = 0;\r
-\r
-       public void pushPath(String path) {\r
-               mDirectories.insert(path, 0);\r
-       }\r
-\r
-       public boolean popPath() {\r
-               mDirectories.remove(mDirectories.getItem(0));\r
-               return !mDirectories.isEmpty();\r
-       }\r
-\r
-       @Override\r
-       protected Dialog onCreateDialog(int id, Bundle args) {\r
-               final AlertDialog.Builder builder = new Builder(this);\r
-               final EditText dirName = new EditText(getBaseContext());\r
-               final Account a = AuthUtils.getCurrentOwnCloudAccount(this);\r
-               builder.setView(dirName);\r
-               builder.setTitle(R.string.uploader_info_dirname);\r
-               dirName.setTextColor(R.color.setup_text_typed);\r
-\r
-               builder.setPositiveButton(R.string.common_ok, new OnClickListener() {\r
-                       public void onClick(DialogInterface dialog, int which) {\r
-                               String s = dirName.getText().toString();\r
-                               if (s.trim().isEmpty()) {\r
-                                       dialog.cancel();\r
-                                       return;\r
-                               }\r
-\r
-                               String path = "";\r
-                               for (int i = mDirectories.getCount() - 2; i >= 0; --i) {\r
-                                       path += "/" + mDirectories.getItem(i);\r
-                               }\r
-                               OCFile parent = new OCFile(getContentResolver(), a, path + "/");\r
-                               path += "/" + s + "/";\r
-                               Thread thread = new Thread(new DirectoryCreator(path, a));\r
-                               thread.start();\r
-                               OCFile.createNewFile(getContentResolver(), a, path, 0, 0, 0,\r
-                                               "DIR", parent.getFileId()).save();\r
-\r
-                               dialog.dismiss();\r
-                       }\r
-               });\r
-               builder.setNegativeButton(R.string.common_cancel,\r
-                               new OnClickListener() {\r
-                                       public void onClick(DialogInterface dialog, int which) {\r
-                                               dialog.cancel();\r
-                                       }\r
-                               });\r
-               return builder.create();\r
-       }\r
-\r
-       @Override\r
-       public void onCreate(Bundle savedInstanceState) {\r
-               super.onCreate(savedInstanceState);\r
-               mDirectories = new CustomArrayAdapter<String>(this,\r
-                               R.layout.sherlock_spinner_dropdown_item);\r
-               mDirectories.add("/");\r
-               setContentView(R.layout.files);\r
-               ActionBar action_bar = getSupportActionBar();\r
-               action_bar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);\r
-               action_bar.setDisplayShowTitleEnabled(false);\r
-               action_bar.setListNavigationCallbacks(mDirectories, this);\r
-               action_bar.setDisplayHomeAsUpEnabled(true);\r
-       }\r
-\r
-       @Override\r
-       public boolean onOptionsItemSelected(MenuItem item) {\r
-               switch (item.getItemId()) {\r
-               case R.id.settingsItem: {\r
-                       Intent i = new Intent(this, Preferences.class);\r
-                       startActivity(i);\r
-                       break;\r
-               }\r
-               case R.id.createDirectoryItem: {\r
-                       showDialog(0);\r
-                       break;\r
-               }\r
-               case android.R.id.home: {\r
-                       onBackPressed();\r
-                       break;\r
-               }\r
-                       \r
-               }\r
-               return true;\r
-       }\r
-       \r
-       @Override\r
-       public void onBackPressed(){\r
-               popPath();\r
-               if(mDirectories.getCount() == 0) {\r
-                       Intent intent = new Intent(this, LandingActivity.class);\r
-                       startActivity(intent);\r
-                       return;\r
-               }\r
-               ((FileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList))\r
-                               .onNavigateUp();\r
-       }\r
-\r
-       @Override\r
-       protected Dialog onCreateDialog(int id) {\r
-               switch (id) {\r
-               case DIALOG_CHOOSE_ACCOUNT:\r
-                       return createChooseAccountDialog();\r
-               default:\r
-                       throw new IllegalArgumentException("Unknown dialog id: " + id);\r
-               }\r
-       }\r
-\r
-       @Override\r
-       public boolean onCreateOptionsMenu(Menu menu) {\r
-               MenuInflater inflater = getSherlock().getMenuInflater();\r
-               inflater.inflate(R.menu.menu, menu);\r
-               return true;\r
-       }\r
-\r
-       private Dialog createChooseAccountDialog() {\r
-               final AccountManager accMan = AccountManager.get(this);\r
-               CharSequence[] items = new CharSequence[accMan\r
-                               .getAccountsByType(AccountAuthenticator.ACCOUNT_TYPE).length];\r
-               int i = 0;\r
-               for (Account a : accMan\r
-                               .getAccountsByType(AccountAuthenticator.ACCOUNT_TYPE)) {\r
-                       items[i++] = a.name;\r
-               }\r
-\r
-               AlertDialog.Builder builder = new AlertDialog.Builder(this);\r
-               builder.setTitle(R.string.common_choose_account);\r
-               builder.setCancelable(true);\r
-               builder.setItems(items, new DialogInterface.OnClickListener() {\r
-                       public void onClick(DialogInterface dialog, int item) {\r
-                               // mAccount =\r
-                               // accMan.getAccountsByType(AccountAuthenticator.ACCOUNT_TYPE)[item];\r
-                               dialog.dismiss();\r
-                       }\r
-               });\r
-               builder.setOnCancelListener(new OnCancelListener() {\r
-                       public void onCancel(DialogInterface dialog) {\r
-                               FileDisplayActivity.this.finish();\r
-                       }\r
-               });\r
-               AlertDialog alert = builder.create();\r
-               return alert;\r
-       }\r
-\r
-       @Override\r
-       public boolean onNavigationItemSelected(int itemPosition, long itemId) {\r
-               int i = itemPosition;\r
-               while (i-- != 0) {\r
-                       onBackPressed();\r
-               }\r
-               return true;\r
-       }\r
-\r
-       private class DirectoryCreator implements Runnable {\r
-               private String mTargetPath;\r
-               private Account mAccount;\r
-               private AccountManager mAm;\r
-\r
-               public DirectoryCreator(String targetPath, Account account) {\r
-                       mTargetPath = targetPath;\r
-                       mAccount = account;\r
-                       mAm = (AccountManager) getSystemService(ACCOUNT_SERVICE);\r
-               }\r
-\r
-               @Override\r
-               public void run() {\r
-                       WebdavClient wdc = new WebdavClient(Uri.parse(mAm.getUserData(\r
-                                       mAccount, AccountAuthenticator.KEY_OC_URL)));\r
-\r
-                       String username = mAccount.name.substring(0,\r
-                                       mAccount.name.lastIndexOf('@'));\r
-                       String password = mAm.getPassword(mAccount);\r
-\r
-                       wdc.setCredentials(username, password);\r
-                       wdc.allowUnsignedCertificates();\r
-                       wdc.createDirectory(mTargetPath);\r
-               }\r
+        OnNavigationListener, OnClickListener {\r
+    private ArrayAdapter<String> mDirectories;\r
+    private DataStorageManager mStorageManager;\r
+    private FileListFragment mFileList;\r
+    private OCFile mCurrentDir;\r
+    private String[] mDirs = null;\r
+\r
+    private SyncBroadcastReceiver syncBroadcastRevceiver;\r
+\r
+    private static final String KEY_DIR_ARRAY = "DIR_ARRAY";\r
+    private static final String KEY_CURRENT_DIR = "DIR";\r
+    \r
+    private static final int DIALOG_SETUP_ACCOUNT = 0;\r
+    private static final int DIALOG_CREATE_DIR = 1;\r
+    private static final int ACTION_SELECT_FILE = 1;\r
+\r
+    @Override\r
+    public void onCreate(Bundle savedInstanceState) {\r
+        super.onCreate(savedInstanceState);\r
+\r
+        if (!accountsAreSetup()) {\r
+            showDialog(DIALOG_SETUP_ACCOUNT);\r
+            return;\r
+        }\r
 \r
-       }\r
+        requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);\r
+        setProgressBarIndeterminateVisibility(false);\r
+        \r
+        if(savedInstanceState != null){\r
+            mCurrentDir = (OCFile) savedInstanceState.getParcelable(KEY_CURRENT_DIR);\r
+        }\r
+        \r
+        setContentView(R.layout.files);\r
+    }\r
+\r
+    @Override\r
+    public boolean onCreateOptionsMenu(Menu menu) {\r
+        MenuInflater inflater = getSherlock().getMenuInflater();\r
+        inflater.inflate(R.menu.menu, menu);\r
+        return true;\r
+    }\r
+\r
+    @Override\r
+    public boolean onOptionsItemSelected(MenuItem item) {\r
+        boolean retval = true;\r
+        switch (item.getItemId()) {\r
+            case R.id.createDirectoryItem: {\r
+                showDialog(DIALOG_CREATE_DIR);\r
+                break;\r
+            }\r
+            case R.id.startSync: {\r
+                Bundle bundle = new Bundle();\r
+                bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);\r
+                ContentResolver.requestSync(\r
+                        AccountUtils.getCurrentOwnCloudAccount(this),\r
+                        "org.owncloud", bundle);\r
+                break;\r
+            }\r
+            case R.id.action_upload: {\r
+                Intent action = new Intent(Intent.ACTION_GET_CONTENT);\r
+                action = action.setType("*/*")\r
+                        .addCategory(Intent.CATEGORY_OPENABLE);\r
+                startActivityForResult(\r
+                        Intent.createChooser(action, "Upload file from..."),\r
+                        ACTION_SELECT_FILE);\r
+                break;\r
+            }\r
+    \r
+            case android.R.id.home: {\r
+                Intent i = new Intent(this, AccountSelectActivity.class);\r
+                startActivity(i);\r
+                finish();\r
+                break;\r
+            }\r
+            default:\r
+                retval = false;\r
+        }\r
+        return retval;\r
+    }\r
+\r
+    @Override\r
+    public boolean onNavigationItemSelected(int itemPosition, long itemId) {\r
+        int i = itemPosition;\r
+        while (i-- != 0) {\r
+            onBackPressed();\r
+        }\r
+        return true;\r
+    }\r
+\r
+    /**\r
+     * Called, when the user selected something for uploading\r
+     */\r
+    public void onActivityResult(int requestCode, int resultCode, Intent data) {\r
+        if (resultCode == RESULT_OK) {\r
+            if (requestCode == ACTION_SELECT_FILE) {\r
+                Uri selectedImageUri = data.getData();\r
+    \r
+                String filemanagerstring = selectedImageUri.getPath();\r
+                String selectedImagePath = getPath(selectedImageUri);\r
+                String filepath;\r
+    \r
+                if (selectedImagePath != null)\r
+                    filepath = selectedImagePath;\r
+                else\r
+                    filepath = filemanagerstring;\r
+    \r
+                if (filepath == null) {\r
+                    Log.e("FileDisplay", "Couldnt resolve path to file");\r
+                    return;\r
+                }\r
+    \r
+                Intent i = new Intent(this, FileUploader.class);\r
+                i.putExtra(FileUploader.KEY_ACCOUNT,\r
+                        AccountUtils.getCurrentOwnCloudAccount(this));\r
+                String remotepath = new String();\r
+                for (int j = mDirectories.getCount() - 2; j >= 0; --j) {\r
+                    remotepath += "/" + URLEncoder.encode(mDirectories.getItem(j));\r
+                }\r
+                if (!remotepath.endsWith("/"))\r
+                    remotepath += "/";\r
+                remotepath += URLEncoder.encode(new File(filepath).getName());\r
+                Log.e("ASD", remotepath + "");\r
+    \r
+                i.putExtra(FileUploader.KEY_LOCAL_FILE, filepath);\r
+                i.putExtra(FileUploader.KEY_REMOTE_FILE, remotepath);\r
+                i.putExtra(FileUploader.KEY_UPLOAD_TYPE, FileUploader.UPLOAD_SINGLE_FILE);\r
+                startService(i);\r
+            }\r
+        }\r
+    }\r
 \r
-       // Custom array adapter to override text colors\r
-       private class CustomArrayAdapter<T> extends ArrayAdapter<T> {\r
-               \r
-               public CustomArrayAdapter(FileDisplayActivity ctx,\r
-                               int view) {\r
-                       super(ctx, view);\r
-               }\r
+    @Override\r
+    public void onBackPressed() {\r
+        if (mDirectories.getCount() == 1) {\r
+            finish();\r
+            return;\r
+        }\r
+        popDirname();\r
+        mFileList.onNavigateUp();\r
+        mCurrentDir = mFileList.getCurrentFile();\r
+    }\r
+\r
+    @Override\r
+    protected void onRestoreInstanceState(Bundle savedInstanceState) {\r
+        super.onRestoreInstanceState(savedInstanceState);\r
+        // Check, if there are ownCloud accounts\r
+        if (!accountsAreSetup()) {\r
+            showDialog(DIALOG_SETUP_ACCOUNT);\r
+        }\r
+        mDirs = savedInstanceState.getStringArray(KEY_DIR_ARRAY);\r
+        mDirectories = new CustomArrayAdapter<String>(this, R.layout.sherlock_spinner_dropdown_item);\r
+        mDirectories.add("/");\r
+        if (mDirs != null)\r
+            for (String s : mDirs)\r
+                mDirectories.insert(s, 0);\r
+    }\r
+    \r
+    @Override\r
+    protected void onSaveInstanceState(Bundle outState) {\r
+        super.onSaveInstanceState(outState);\r
+        if(mDirectories != null){\r
+            mDirs = new String[mDirectories.getCount()-1];\r
+            for (int j = mDirectories.getCount() - 2, i = 0; j >= 0; --j, ++i) {\r
+                mDirs[i] = mDirectories.getItem(j);\r
+            }\r
+        }\r
+        outState.putStringArray(KEY_DIR_ARRAY, mDirs);\r
+        outState.putParcelable(KEY_CURRENT_DIR, mCurrentDir);\r
+    }\r
+\r
+    @Override\r
+    protected void onResume() {\r
+        super.onResume();\r
+        \r
+        //TODO: Dialog useless -> get rid of this\r
+        if (!accountsAreSetup()) {\r
+            showDialog(DIALOG_SETUP_ACCOUNT);\r
+            return;\r
+        }\r
 \r
-               public View getView(int position, View convertView,\r
-                ViewGroup parent) {\r
+        // Listen for sync messages\r
+        IntentFilter syncIntentFilter = new IntentFilter(FileSyncService.SYNC_MESSAGE);\r
+        syncBroadcastRevceiver = new SyncBroadcastReceiver();\r
+        registerReceiver(syncBroadcastRevceiver, syncIntentFilter);\r
+        \r
+        // Storage manager initialization\r
+        mStorageManager = new FileDataStorageManager(\r
+                AccountUtils.getCurrentOwnCloudAccount(this),\r
+                getContentResolver());\r
+        \r
+        // File list\r
+        mFileList = (FileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList);\r
+        \r
+        // Figure out what directory to list. \r
+        // Priority: Intent (here), savedInstanceState (onCreate), root dir (dir is null)\r
+        if(getIntent().hasExtra(FileDetailFragment.EXTRA_FILE)){\r
+            mCurrentDir = (OCFile) getIntent().getParcelableExtra(FileDetailFragment.EXTRA_FILE);\r
+            if(!mCurrentDir.isDirectory()){\r
+                mCurrentDir = mStorageManager.getFileById(mCurrentDir.getParentId());\r
+            }\r
+            \r
+            // Clear intent extra, so rotating the screen will not return us to this directory\r
+            getIntent().removeExtra(FileDetailFragment.EXTRA_FILE);\r
+        } \r
+                \r
+        // Drop-Down navigation and file list restore\r
+        mDirectories = new CustomArrayAdapter<String>(this, R.layout.sherlock_spinner_dropdown_item);\r
+        \r
+        \r
+        // Given the case we have a file to display:\r
+        if(mCurrentDir != null){\r
+            ArrayList<OCFile> files = new ArrayList<OCFile>();\r
+            OCFile currFile = mCurrentDir;\r
+            while(currFile != null){\r
+                files.add(currFile);\r
+                currFile = mStorageManager.getFileById(currFile.getParentId());\r
+            }\r
+            \r
+            // Insert in mDirs\r
+            mDirs = new String[files.size()];\r
+            for(int i = files.size() - 1; i >= 0; i--){\r
+                mDirs[i] = files.get(i).getFileName();\r
+            }\r
+        }\r
+        \r
+        if (mDirs != null) {\r
+            for (String s : mDirs)\r
+                mDirectories.add(s);\r
+        } else {\r
+            mDirectories.add("/");\r
+        }\r
+               \r
+        // Actionbar setup\r
+        ActionBar action_bar = getSupportActionBar();\r
+        action_bar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);\r
+        action_bar.setDisplayShowTitleEnabled(false);\r
+        action_bar.setListNavigationCallbacks(mDirectories, this);\r
+        action_bar.setDisplayHomeAsUpEnabled(true);\r
+        \r
+        // List dir here\r
+        mFileList.listDirectory(mCurrentDir);\r
+    }\r
+\r
+    @Override\r
+    protected void onPause() {\r
+        super.onPause();\r
+        if (syncBroadcastRevceiver != null) {\r
+            unregisterReceiver(syncBroadcastRevceiver);\r
+            syncBroadcastRevceiver = null;\r
+        }\r
+    \r
+    }\r
+\r
+    @Override\r
+    protected Dialog onCreateDialog(int id) {\r
+        Dialog dialog;\r
+        AlertDialog.Builder builder;\r
+        switch (id) {\r
+        case DIALOG_SETUP_ACCOUNT:\r
+            builder = new AlertDialog.Builder(this);\r
+            builder.setTitle(R.string.main_tit_accsetup);\r
+            builder.setMessage(R.string.main_wrn_accsetup);\r
+            builder.setCancelable(false);\r
+            builder.setPositiveButton(android.R.string.ok, this);\r
+            builder.setNegativeButton(android.R.string.cancel, this);\r
+            dialog = builder.create();\r
+            break;\r
+        case DIALOG_CREATE_DIR: {\r
+            builder = new Builder(this);\r
+            final EditText dirNameInput = new EditText(getBaseContext());\r
+            final Account a = AccountUtils.getCurrentOwnCloudAccount(this);\r
+            builder.setView(dirNameInput);\r
+            builder.setTitle(R.string.uploader_info_dirname);\r
+            int typed_color = getResources().getColor(R.color.setup_text_typed);\r
+            dirNameInput.setTextColor(typed_color);\r
+    \r
+            builder.setPositiveButton(android.R.string.ok,\r
+                    new OnClickListener() {\r
+                        public void onClick(DialogInterface dialog, int which) {\r
+                            String directoryName = dirNameInput.getText().toString();\r
+                            if (directoryName.trim().length() == 0) {\r
+                                dialog.cancel();\r
+                                return;\r
+                            }\r
+    \r
+                            // Figure out the path where the dir needs to be created\r
+                            String path = mCurrentDir.getRemotePath();\r
+                            \r
+                            // Create directory\r
+                            path += directoryName + "/";\r
+                            Thread thread = new Thread(new DirectoryCreator(\r
+                                    path, a));\r
+                            thread.start();\r
+    \r
+                            // Save new directory in local database\r
+                            OCFile newDir = new OCFile(path);\r
+                            newDir.setMimetype("DIR");\r
+                            newDir.setParentId(mCurrentDir.getFileId());\r
+                            mStorageManager.saveFile(newDir);\r
+    \r
+                            // Display the new folder right away\r
+                            dialog.dismiss();\r
+                            mFileList.listDirectory(mCurrentDir);\r
+                        }\r
+                    });\r
+            builder.setNegativeButton(R.string.common_cancel,\r
+                    new OnClickListener() {\r
+                        public void onClick(DialogInterface dialog, int which) {\r
+                            dialog.cancel();\r
+                        }\r
+                    });\r
+            dialog = builder.create();\r
+            break;\r
+        }\r
+        default:\r
+            dialog = null;\r
+        }\r
+    \r
+        return dialog;\r
+    }\r
+\r
+    \r
+    /**\r
+     * Responds to the "There are no ownCloud Accounts setup" dialog\r
+     * TODO: Dialog is 100% useless -> Remove\r
+     */\r
+    @Override\r
+    public void onClick(DialogInterface dialog, int which) {\r
+        // In any case - we won't need it anymore\r
+        dialog.dismiss();\r
+        switch (which) {\r
+        case DialogInterface.BUTTON_POSITIVE:\r
+            Intent intent = new Intent("android.settings.ADD_ACCOUNT_SETTINGS");\r
+            intent.putExtra("authorities",\r
+                    new String[] { AccountAuthenticator.AUTH_TOKEN_TYPE });\r
+            startActivity(intent);\r
+            break;\r
+        case DialogInterface.BUTTON_NEGATIVE:\r
+            finish();\r
+        }\r
+    \r
+    }\r
+\r
+    /**\r
+     * Translates a content URI of an image to a physical path\r
+     * on the disk\r
+     * @param uri The URI to resolve\r
+     * @return The path to the image or null if it could not be found\r
+     */\r
+    public String getPath(Uri uri) {\r
+        String[] projection = { MediaStore.Images.Media.DATA };\r
+        Cursor cursor = managedQuery(uri, projection, null, null, null);\r
+        if (cursor != null) {\r
+            int column_index = cursor\r
+                    .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);\r
+            cursor.moveToFirst();\r
+            return cursor.getString(column_index);\r
+        } \r
+        return null;\r
+    }\r
+    \r
+    /**\r
+     * Pushes a directory to the drop down list\r
+     * @param directory to push\r
+     * @throws IllegalArgumentException If the {@link OCFile#isDirectory()} returns false.\r
+     */\r
+    public void pushDirname(OCFile directory) {\r
+        if(!directory.isDirectory()){\r
+            throw new IllegalArgumentException("Only directories may be pushed!");\r
+        }\r
+        mDirectories.insert(directory.getFileName(), 0);\r
+        mCurrentDir = directory;\r
+    }\r
+\r
+    /**\r
+     * Pops a directory name from the drop down list\r
+     * @return True, unless the stack is empty\r
+     */\r
+    public boolean popDirname() {\r
+        mDirectories.remove(mDirectories.getItem(0));\r
+        return !mDirectories.isEmpty();\r
+    }\r
+\r
+    /**\r
+     * Checks, whether or not there are any ownCloud accounts setup.\r
+     * \r
+     * @return true, if there is at least one account.\r
+     */\r
+    private boolean accountsAreSetup() {\r
+        AccountManager accMan = AccountManager.get(this);\r
+        Account[] accounts = accMan\r
+                .getAccountsByType(AccountAuthenticator.ACCOUNT_TYPE);\r
+        return accounts.length > 0;\r
+    }\r
+\r
+    private class DirectoryCreator implements Runnable {\r
+        private String mTargetPath;\r
+        private Account mAccount;\r
+        private AccountManager mAm;\r
+    \r
+        public DirectoryCreator(String targetPath, Account account) {\r
+            mTargetPath = targetPath;\r
+            mAccount = account;\r
+            mAm = (AccountManager) getSystemService(ACCOUNT_SERVICE);\r
+        }\r
+    \r
+        @Override\r
+        public void run() {\r
+            WebdavClient wdc = new WebdavClient(Uri.parse(mAm.getUserData(\r
+                    mAccount, AccountAuthenticator.KEY_OC_URL)));\r
+    \r
+            String username = mAccount.name.substring(0,\r
+                    mAccount.name.lastIndexOf('@'));\r
+            String password = mAm.getPassword(mAccount);\r
+    \r
+            wdc.setCredentials(username, password);\r
+            wdc.allowUnsignedCertificates();\r
+            wdc.createDirectory(mTargetPath);\r
+        }\r
+    \r
+    }\r
+\r
+    // Custom array adapter to override text colors\r
+    private class CustomArrayAdapter<T> extends ArrayAdapter<T> {\r
+    \r
+        public CustomArrayAdapter(FileDisplayActivity ctx, int view) {\r
+            super(ctx, view);\r
+        }\r
+    \r
+        public View getView(int position, View convertView, ViewGroup parent) {\r
             View v = super.getView(position, convertView, parent);\r
-\r
-            ((TextView) v).setTextColor(\r
-                    getResources()\r
-                    .getColorStateList(android.R.color.white));\r
+    \r
+            ((TextView) v).setTextColor(getResources().getColorStateList(\r
+                    android.R.color.white));\r
             return v;\r
         }\r
-               \r
-               public View getDropDownView(int position, View convertView,\r
+    \r
+        public View getDropDownView(int position, View convertView,\r
                 ViewGroup parent) {\r
-            View v = super.getDropDownView(position, convertView,\r
-                    parent);\r
-\r
+            View v = super.getDropDownView(position, convertView, parent);\r
+    \r
             ((TextView) v).setTextColor(getResources().getColorStateList(\r
-                            android.R.color.white));\r
-\r
+                    android.R.color.white));\r
+    \r
             return v;\r
         }\r
+    \r
+    }\r
+\r
+    private class SyncBroadcastReceiver extends BroadcastReceiver {\r
+        /**\r
+         * {@link BroadcastReceiver} to enable syncing feedback in UI\r
+         */\r
+        @Override\r
+        public void onReceive(Context context, Intent intent) {\r
+            boolean inProgress = intent.getBooleanExtra(\r
+                    FileSyncService.IN_PROGRESS, false);\r
+            String account_name = intent\r
+                    .getStringExtra(FileSyncService.ACCOUNT_NAME);\r
+            Log.d("FileDisplay", "sync of account " + account_name\r
+                    + " is in_progress: " + inProgress);\r
+            setProgressBarIndeterminateVisibility(inProgress);\r
+            if (!inProgress) {\r
+                FileListFragment fileListFramgent = (FileListFragment) getSupportFragmentManager()\r
+                        .findFragmentById(R.id.fileList);\r
+                if (fileListFramgent != null)\r
+                    fileListFramgent.listDirectory();\r
+            }\r
+        }\r
 \r
+    }\r
 \r
-               \r
-       }\r
-}
\ No newline at end of file
+}\r