- 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, AccountUtils.getCurrentOwnCloudAccount(this));\r
- String remotepath = new String();\r
- for (int j = mDirectories.getCount() - 2; j >= 0; --j) {\r
- remotepath += "/" + mDirectories.getItem(j);\r
- }\r
- if (!remotepath.endsWith("/")) remotepath += "/";\r
- remotepath += 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
- 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
- {\r
- int column_index = cursor\r
- .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);\r
- cursor.moveToFirst();\r
- return cursor.getString(column_index);\r
- }\r
- else return null;\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
- public boolean onNavigationItemSelected(int itemPosition, long itemId) {\r
- int i = itemPosition;\r
- while (i-- != 0) {\r
- onBackPressed();\r
- }\r
- return true;\r
- }\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
+ if(mCurrentDir != null && mCurrentDir.getParentId() != 0){\r
+ action_bar.setDisplayHomeAsUpEnabled(true);\r
+ } else {\r
+ action_bar.setDisplayHomeAsUpEnabled(false);\r
+ }\r
+ \r
+ // List dir here\r
+ mFileList.listDirectory(mCurrentDir);\r
+ }\r