+ } catch (NotFoundException e) {
+ Log_OC.e(TAG, "Error while trying to show fail message " , e);
+ }
+ }
+ }
+
+
+ /**
+ * Loads the target folder initialize shown to the user.
+ *
+ * The target account has to be chosen before this method is called.
+ */
+ private void initTargetFolder() {
+ if (getStorageManager() == null) {
+ throw new IllegalStateException("Do not call this method before " +
+ "initializing mStorageManager");
+ }
+
+ SharedPreferences appPreferences = PreferenceManager
+ .getDefaultSharedPreferences(getApplicationContext());
+
+ String last_path = appPreferences.getString("last_upload_path", "");
+ // "/" equals root-directory
+ if(last_path.equals("/")) {
+ mParents.add("");
+ } else{
+ String[] dir_names = last_path.split("/");
+ mParents.clear();
+ for (String dir : dir_names)
+ mParents.add(dir);
+ }
+ //Make sure that path still exists, if it doesn't pop the stack and try the previous path
+ while(!getStorageManager().fileExists(generatePath(mParents)) && mParents.size() > 1){
+ mParents.pop();
+ }
+ }
+
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ boolean retval = true;
+ switch (item.getItemId()) {
+ case android.R.id.home:
+ if((mParents.size() > 1)) {
+ onBackPressed();
+ }
+ break;
+
+ default:
+ retval = super.onOptionsItemSelected(item);
+ }
+ return retval;
+ }
+
+
+ /**
+ * Process the result of CopyTmpFileAsyncTask
+ * @param result
+ * @param index
+ */
+ @Override
+ public void onTmpFileCopied(String result, int index) {
+ if (mNumCacheFile -- == 0) {
+ dismissWaitingCopyDialog();
+ }
+ if (result != null) {
+ Intent intent = new Intent(getApplicationContext(), FileUploader.class);
+ intent.putExtra(FileUploader.KEY_UPLOAD_TYPE, FileUploader.UPLOAD_SINGLE_FILE);
+ intent.putExtra(FileUploader.KEY_LOCAL_FILE, result);
+ intent.putExtra(FileUploader.KEY_REMOTE_FILE, mRemoteCacheData.get(index));
+ intent.putExtra(FileUploader.KEY_ACCOUNT, getAccount());
+ startService(intent);
+
+ } else {
+ String message = String.format(getString(R.string.uploader_error_forbidden_content),
+ getString(R.string.app_name));
+ Toast.makeText(this, message, Toast.LENGTH_LONG).show();
+ Log_OC.d(TAG, message);
+ }
+
+ }
+/**
+ * Show waiting for copy dialog
+ */
+ public void showWaitingCopyDialog() {
+ // Construct dialog
+ LoadingDialog loading = new LoadingDialog(
+ getResources().getString(R.string.wait_for_tmp_copy_from_private_storage));
+ FragmentManager fm = getSupportFragmentManager();
+ FragmentTransaction ft = fm.beginTransaction();
+ loading.show(ft, DIALOG_WAIT_COPY_FILE);
+
+ }
+
+
+ /**
+ * Dismiss waiting for copy dialog
+ */
+ public void dismissWaitingCopyDialog(){
+ Fragment frag = getSupportFragmentManager().findFragmentByTag(DIALOG_WAIT_COPY_FILE);
+ if (frag != null) {
+ LoadingDialog loading = (LoadingDialog) frag;
+ loading.dismiss();
+ }
+ }