- android-19
before_install:
- rm pom.xml
- - ./setup_env.sh gradle
script:
- - ./gradlew clean build
- ./setup_env.sh ant
- ant clean
- ant debug
along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<manifest package="com.owncloud.android"
- android:versionCode="10600100"
- android:versionName="1.6.1" xmlns:android="http://schemas.android.com/apk/res/android">
+ android:versionCode="10600200"
+ android:versionName="1.6.2" xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
android:icon="@drawable/copy_link"/>
<activity
- android:name=".ui.activity.MoveActivity"
+ android:name=".ui.activity.FolderPickerActivity"
+ android:label="@string/app_name"/>
+
+ <activity
+ android:name=".ui.activity.UploadPathActivity"
android:label="@string/app_name"/>
</application>
Make sure you read [SETUP.md][1] when you start working on this project.
[0]: https://github.com/owncloud/core
-[1]: https://raw.github.com/owncloud/android/master/SETUP.md
\ No newline at end of file
+[1]: https://github.com/owncloud/android/blob/master/SETUP.md
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.owncloud.android.workaround.accounts"
- android:versionCode="0100019"
- android:versionName="1.0.19" >
+ android:versionCode="0100020"
+ android:versionName="1.0.20" >
<uses-sdk
android:minSdkVersion="16"
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:background="@color/background_color"
+ android:orientation="vertical" >
+
+ <FrameLayout
+ android:layout_width="match_parent"
+ android:layout_height="0dip"
+ android:layout_weight="1"
+ android:id="@+id/fragment_container" />
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:gravity="center"
+ android:orientation="horizontal" >
+
+ <Button
+ android:id="@+id/folder_picker_btn_cancel"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:text="@string/common_cancel" />
+
+ <Button
+ android:id="@+id/folder_picker_btn_choose"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:text="@string/folder_picker_choose_button_text" />
+
+ </LinearLayout>
+
+ </LinearLayout>
\ No newline at end of file
+++ /dev/null
-<?xml version="1.0" encoding="utf-8"?>
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:background="@color/background_color"
- android:orientation="vertical" >
-
- <FrameLayout
- android:layout_width="match_parent"
- android:layout_height="0dip"
- android:layout_weight="1"
- android:id="@+id/fragment_container" />
-
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:gravity="center"
- android:orientation="horizontal" >
-
- <Button
- android:id="@+id/move_files_btn_cancel"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:text="@string/common_cancel" />
-
- <Button
- android:id="@+id/move_files_btn_choose"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:text="@string/move_choose_button_text" />
-
- </LinearLayout>
-
- </LinearLayout>
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="wrap_content"
+ android:layout_height="56dp"
+ android:layout_gravity="center_horizontal"
+ android:gravity="center_horizontal"
+ android:orientation="vertical"
+ android:showDividers="none" >
+
+ <TextView
+ android:id="@+id/footerText"
+ android:layout_width="match_parent"
+ android:layout_height="56dp"
+ android:layout_gravity="center"
+ android:gravity="center"
+ android:textColor="@color/setup_text_hint" />
+
+</LinearLayout>
\ No newline at end of file
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipe_refresh_files"
android:layout_width="match_parent"
- android:layout_height="match_parent" >
-
+ android:layout_height="match_parent"
+ android:layout_weight="1"
+ android:footerDividersEnabled="false" >
+
<com.owncloud.android.ui.ExtendedListView
android:id="@+id/list_root"
android:layout_width="match_parent"
android:layout_height="match_parent" />
-
+
</android.support.v4.widget.SwipeRefreshLayout>
-
- <android.support.v4.widget.SwipeRefreshLayout
+
+ <android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipe_refresh_files_emptyView"
android:layout_width="match_parent"
android:layout_height="match_parent"
<string name="file_list_empty">Nothing in here. Upload something!</string>
<string name="file_list_loading">Loading...</string>
<string name="local_file_list_empty">There are no files in this folder.</string>
+ <string name="file_list_folder">folder</string>
+ <string name="file_list_folders">folders</string>
+ <string name="file_list_file">file</string>
+ <string name="file_list_files">files</string>
<string name="filedetails_select_file">Tap on a file to display additional information.</string>
<string name="filedetails_size">Size:</string>
<string name="filedetails_type">Type:</string>
<string name="saml_authentication_wrong_pass">Wrong password</string>
<string name="actionbar_move">Move</string>
<string name="file_list_empty_moving">Nothing in here. You can add a folder!</string>
- <string name="move_choose_button_text">Choose</string>
+ <string name="folder_picker_choose_button_text">Choose</string>
<string name="move_file_not_found">Unable to move. Please check whether the file exists</string>
<string name="move_file_invalid_into_descendent">It is not possible to move a folder into a descendant</string>
<string name="prefs_category_instant_uploading">Instant Uploads</string>
<string name="prefs_category_security">Security</string>
+
+ <string name="prefs_instant_video_upload_path_title">Upload Video Path</string>
+
</resources>
</PreferenceCategory>
<PreferenceCategory android:title="@string/prefs_category_instant_uploading">
- <EditTextPreference android:title="@string/prefs_instant_upload_path_title"
- android:defaultValue="@string/instant_upload_path"
- android:key="instant_upload_path"/>
+ <com.owncloud.android.ui.PreferenceWithLongSummary
+ android:title="@string/prefs_instant_upload_path_title"
+ android:key="instant_upload_path" />
<com.owncloud.android.ui.CheckBoxPreferenceWithLongTitle android:key="instant_uploading"
android:title="@string/prefs_instant_upload"
android:summary="@string/prefs_instant_upload_summary"/>
android:disableDependentsState="true"
android:title="@string/instant_upload_on_wifi"
android:key="instant_upload_on_wifi"/>
+ <com.owncloud.android.ui.PreferenceWithLongSummary
+ android:title="@string/prefs_instant_video_upload_path_title"
+ android:key="instant_video_upload_path" />
<com.owncloud.android.ui.CheckBoxPreferenceWithLongTitle android:key="instant_video_uploading"
android:title="@string/prefs_instant_video_upload"
android:summary="@string/prefs_instant_video_upload_summary"/>
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
+import java.util.List;
import java.util.Vector;
import com.owncloud.android.MainApp;
import com.owncloud.android.lib.resources.files.FileUtils;
import com.owncloud.android.utils.FileStorageUtils;
-
import android.accounts.Account;
import android.content.ContentProviderClient;
import android.content.ContentProviderOperation;
import android.content.ContentResolver;
import android.content.ContentUris;
import android.content.ContentValues;
+import android.content.Intent;
import android.content.OperationApplicationException;
import android.database.Cursor;
import android.net.Uri;
).withSelection(where, whereArgs).build());
if (file.isDown()) {
- new File(file.getStoragePath()).delete();
+ String path = file.getStoragePath();
+ new File(path).delete();
+ triggerMediaScan(path); // notify MediaScanner about removed file
}
}
}
}
success &= (deleted > 0);
}
- if (removeLocalCopy && file.isDown() && file.getStoragePath() != null && success) {
- success = new File(file.getStoragePath()).delete();
+ String localPath = file.getStoragePath();
+ if (removeLocalCopy && file.isDown() && localPath != null && success) {
+ success = new File(localPath).delete();
+ if (success) {
+ triggerMediaScan(localPath);
+ }
if (!removeDBData && success) {
// maybe unnecessary, but should be checked TODO remove if unnecessary
file.setStoragePath(null);
success &= removeLocalFolder(file);
} else {
if (file.isDown()) {
+ String path = file.getStoragePath();
File localFile = new File(file.getStoragePath());
success &= localFile.delete();
if (success) {
file.setStoragePath(null);
saveFile(file);
+ triggerMediaScan(path); // notify MediaScanner about removed file
}
}
}
if (localFile.isDirectory()) {
success &= removeLocalFolder(localFile);
} else {
+ String path = localFile.getAbsolutePath();
success &= localFile.delete();
+ triggerMediaScan(path); // notify MediaScanner about removed file
}
}
}
return success;
}
+
/**
- * Updates database for a folder that was moved to a different location.
+ * Updates database and file system for a file or folder that was moved to a different location.
*
* TODO explore better (faster) implementations
* TODO throw exceptions up !
*/
- public void moveFolder(OCFile folder, String newPath) {
- // TODO check newPath
-
- if ( folder != null && folder.isFolder() &&
- folder.fileExists() && !OCFile.ROOT_PATH.equals(folder.getFileName())
- ) {
- /// 1. get all the descendants of 'dir' in a single QUERY (including 'dir')
- Cursor c = null;
- if (getContentProviderClient() != null) {
- try {
- c = getContentProviderClient().query (
- ProviderTableMeta.CONTENT_URI,
- null,
- ProviderTableMeta.FILE_ACCOUNT_OWNER + "=? AND " +
- ProviderTableMeta.FILE_PATH + " LIKE ? ",
- new String[] { mAccount.name, folder.getRemotePath() + "%" },
- ProviderTableMeta.FILE_PATH + " ASC "
- );
- } catch (RemoteException e) {
- Log_OC.e(TAG, e.getMessage());
- }
- } else {
- c = getContentResolver().query (
- ProviderTableMeta.CONTENT_URI,
- null,
- ProviderTableMeta.FILE_ACCOUNT_OWNER + "=? AND " +
- ProviderTableMeta.FILE_PATH + " LIKE ? ",
- new String[] { mAccount.name, folder.getRemotePath() + "%" },
- ProviderTableMeta.FILE_PATH + " ASC "
- );
- }
-
- /// 2. prepare a batch of update operations to change all the descendants
- ArrayList<ContentProviderOperation> operations =
- new ArrayList<ContentProviderOperation>(c.getCount());
- int lengthOfOldPath = folder.getRemotePath().length();
- String defaultSavePath = FileStorageUtils.getSavePath(mAccount.name);
- int lengthOfOldStoragePath = defaultSavePath.length() + lengthOfOldPath;
- if (c.moveToFirst()) {
- do {
- ContentValues cv = new ContentValues(); // keep the constructor in the loop
- OCFile child = createFileInstance(c);
- cv.put(
- ProviderTableMeta.FILE_PATH,
- newPath + child.getRemotePath().substring(lengthOfOldPath)
- );
- if ( child.getStoragePath() != null &&
- child.getStoragePath().startsWith(defaultSavePath) ) {
- cv.put(
- ProviderTableMeta.FILE_STORAGE_PATH,
- defaultSavePath + newPath +
- child.getStoragePath().substring(lengthOfOldStoragePath)
- );
- }
- operations.add(
- ContentProviderOperation.
- newUpdate(ProviderTableMeta.CONTENT_URI).
- withValues(cv).
- withSelection(
- ProviderTableMeta._ID + "=?",
- new String[] { String.valueOf(child.getFileId()) }
- ).
- build()
- );
- } while (c.moveToNext());
- }
- c.close();
-
- /// 3. apply updates in batch
- try {
- if (getContentResolver() != null) {
- getContentResolver().applyBatch(MainApp.getAuthority(), operations);
-
- } else {
- getContentProviderClient().applyBatch(operations);
- }
-
- } catch (OperationApplicationException e) {
- Log_OC.e(TAG, "Fail to update descendants of " +
- folder.getFileId() + " in database", e);
-
- } catch (RemoteException e) {
- Log_OC.e(TAG, "Fail to update desendants of " +
- folder.getFileId() + " in database", e);
- }
-
- }
- }
-
-
public void moveLocalFile(OCFile file, String targetPath, String targetParentPath) {
if (file != null && file.fileExists() && !OCFile.ROOT_PATH.equals(file.getFileName())) {
OCFile targetParent = getFileByPath(targetParentPath);
if (targetParent == null) {
- // TODO panic
+ throw new IllegalStateException("Parent folder of the target path does not exist!!");
}
/// 1. get all the descendants of the moved element in a single QUERY
ArrayList<ContentProviderOperation> operations =
new ArrayList<ContentProviderOperation>(c.getCount());
String defaultSavePath = FileStorageUtils.getSavePath(mAccount.name);
+ List<String> originalPathsToTriggerMediaScan = new ArrayList<String>();
+ List<String> newPathsToTriggerMediaScan = new ArrayList<String>();
if (c.moveToFirst()) {
int lengthOfOldPath = file.getRemotePath().length();
int lengthOfOldStoragePath = defaultSavePath.length() + lengthOfOldPath;
if (child.getStoragePath() != null &&
child.getStoragePath().startsWith(defaultSavePath)) {
// update link to downloaded content - but local move is not done here!
- cv.put(
- ProviderTableMeta.FILE_STORAGE_PATH,
- defaultSavePath + targetPath +
- child.getStoragePath().substring(lengthOfOldStoragePath)
- );
+ String targetLocalPath = defaultSavePath + targetPath +
+ child.getStoragePath().substring(lengthOfOldStoragePath);
+
+ cv.put(ProviderTableMeta.FILE_STORAGE_PATH, targetLocalPath);
+
+ originalPathsToTriggerMediaScan.add(child.getStoragePath());
+ newPathsToTriggerMediaScan.add(targetLocalPath);
+
}
if (child.getRemotePath().equals(file.getRemotePath())) {
cv.put(
}
} catch (Exception e) {
- Log_OC.e(
- TAG,
- "Fail to update " + file.getFileId() + " and descendants in database",
- e
- );
+ Log_OC.e(TAG, "Fail to update " + file.getFileId() + " and descendants in database", e);
}
/// 4. move in local file system
- String localPath = FileStorageUtils.getDefaultSavePathFor(mAccount.name, file);
- File localFile = new File(localPath);
+ String originalLocalPath = FileStorageUtils.getDefaultSavePathFor(mAccount.name, file);
+ String targetLocalPath = defaultSavePath + targetPath;
+ File localFile = new File(originalLocalPath);
boolean renamed = false;
if (localFile.exists()) {
- File targetFile = new File(defaultSavePath + targetPath);
+ File targetFile = new File(targetLocalPath);
File targetFolder = targetFile.getParentFile();
if (!targetFolder.exists()) {
targetFolder.mkdirs();
}
renamed = localFile.renameTo(targetFile);
}
- Log_OC.d(TAG, "Local file RENAMED : " + renamed);
-
+
+ if (renamed) {
+ Iterator<String> it = originalPathsToTriggerMediaScan.iterator();
+ while (it.hasNext()) {
+ // Notify MediaScanner about removed file
+ triggerMediaScan(it.next());
+ }
+ it = newPathsToTriggerMediaScan.iterator();
+ while (it.hasNext()) {
+ // Notify MediaScanner about new file/folder
+ triggerMediaScan(it.next());
+ }
+ }
}
}
//}
}
+ public void triggerMediaScan(String path) {
+ Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
+ intent.setData(Uri.fromFile(new File(path)));
+ MainApp.getAppContext().sendBroadcast(intent);
+ }
+
}
import java.io.File;
import third_parties.daveKoeller.AlphanumComparator;
-
public class OCFile implements Parcelable, Comparable<OCFile> {
public static final Parcelable.Creator<OCFile> CREATOR = new Parcelable.Creator<OCFile>() {
Intent i = new Intent(context, FileUploader.class);
i.putExtra(FileUploader.KEY_ACCOUNT, account);
i.putExtra(FileUploader.KEY_LOCAL_FILE, file_path);
- i.putExtra(FileUploader.KEY_REMOTE_FILE, FileStorageUtils.getInstantUploadFilePath(context, file_name));
+ i.putExtra(FileUploader.KEY_REMOTE_FILE, FileStorageUtils.getInstantVideoUploadFilePath(context, file_name));
i.putExtra(FileUploader.KEY_UPLOAD_TYPE, FileUploader.UPLOAD_SINGLE_FILE);
i.putExtra(FileUploader.KEY_MIME_TYPE, mime_type);
i.putExtra(FileUploader.KEY_INSTANT_UPLOAD, true);
file.setFileLength((new File(mCurrentDownload.getSavePath()).length()));
file.setRemoteId(mCurrentDownload.getFile().getRemoteId());
mStorageManager.saveFile(file);
+ mStorageManager.triggerMediaScan(file.getStoragePath());
}
import android.content.Context;
import android.net.Uri;
-import android.util.Log;
/**
* Operation to find out what authentication method requires
newFile = new File(getSavePath());
newFile.getParentFile().mkdirs();
moved = tmpFile.renameTo(newFile);
-
if (!moved)
result = new RemoteOperationResult(RemoteOperationResult.ResultCode.LOCAL_STORAGE_NOT_MOVED);
}
Log_OC.i(TAG, "Download of " + mFile.getRemotePath() + " to " + getSavePath() + ": " + result.getLogMessage());
-
return result;
}
import com.owncloud.android.operations.common.SyncOperation;
import com.owncloud.android.utils.FileStorageUtils;
-import android.accounts.Account;
-
/**
* Remote operation performing the rename of a remote file (or folder?) in the ownCloud server.
private OCFile mFile;
private String mRemotePath;
- private Account mAccount;
private String mNewName;
private String mNewRemotePath;
* @param account OwnCloud account containing the remote file
* @param newName New name to set as the name of file.
*/
- public RenameFileOperation(String remotePath, Account account, String newName) {
+ public RenameFileOperation(String remotePath, String newName) {
mRemotePath = remotePath;
- mAccount = account;
mNewName = newName;
mNewRemotePath = null;
}
if (result.isSuccess()) {
if (mFile.isFolder()) {
- saveLocalDirectory();
+ getStorageManager().moveLocalFile(mFile, mNewRemotePath, parent);
+ //saveLocalDirectory();
} else {
saveLocalFile();
return result;
}
-
- private void saveLocalDirectory() {
- getStorageManager().moveFolder(mFile, mNewRemotePath);
- String localPath = FileStorageUtils.getDefaultSavePathFor(mAccount.name, mFile);
- File localDir = new File(localPath);
- if (localDir.exists()) {
- localDir.renameTo(new File(FileStorageUtils.getSavePath(mAccount.name) + mNewRemotePath));
- // TODO - if renameTo fails, children files that are already down will result unlinked
- }
- }
-
private void saveLocalFile() {
mFile.setFileName(mNewName);
// try to rename the local copy of the file
if (mFile.isDown()) {
- File f = new File(mFile.getStoragePath());
+ String oldPath = mFile.getStoragePath();
+ File f = new File(oldPath);
String parentStoragePath = f.getParent();
if (!parentStoragePath.endsWith(File.separator))
parentStoragePath += File.separator;
if (f.renameTo(new File(parentStoragePath + mNewName))) {
- mFile.setStoragePath(parentStoragePath + mNewName);
+ String newPath = parentStoragePath + mNewName;
+ mFile.setStoragePath(newPath);
+
+ // notify MediaScanner about removed file - TODO really works?
+ getStorageManager().triggerMediaScan(oldPath);
+ // notify to scan about new file
+ getStorageManager().triggerMediaScan(newPath);
}
// else - NOTHING: the link to the local file is kept although the local name can't be updated
// TODO - study conditions when this could be a problem
import java.util.HashMap;
import com.owncloud.android.R;
-import com.owncloud.android.datamodel.ThumbnailsCacheManager;
import com.owncloud.android.db.ProviderMeta;
import com.owncloud.android.db.ProviderMeta.ProviderTableMeta;
import com.owncloud.android.lib.common.utils.Log_OC;
// Rename file or folder
String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
String newName = operationIntent.getStringExtra(EXTRA_NEWNAME);
- operation = new RenameFileOperation(remotePath, account, newName);
+ operation = new RenameFileOperation(remotePath, newName);
} else if (action.equals(ACTION_REMOVE)) {
// Remove file or folder
--- /dev/null
+/* ownCloud Android client application
+ * Copyright (C) 2014 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,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package com.owncloud.android.ui;
+
+import android.content.Context;
+import android.text.TextUtils;
+import android.util.AttributeSet;
+import android.view.View;
+import android.widget.TextView;
+import android.preference.Preference;
+
+public class PreferenceWithLongSummary extends Preference{
+
+ public PreferenceWithLongSummary(Context context) {
+ super(context);
+ }
+
+ public PreferenceWithLongSummary(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+ public PreferenceWithLongSummary(Context context, AttributeSet attrs, int defStyle) {
+ super(context, attrs, defStyle);
+ }
+
+ @Override
+ protected void onBindView(View view) {
+ super.onBindView(view);
+ TextView titleView = (TextView) view.findViewById(android.R.id.summary);
+ titleView.setSingleLine(true);
+ titleView.setMaxLines(1);
+ titleView.setEllipsize(TextUtils.TruncateAt.MIDDLE);
+ }
+}
\ No newline at end of file
} else if (requestCode == ACTION_SELECT_MULTIPLE_FILES && (resultCode == RESULT_OK || resultCode == UploadFilesActivity.RESULT_OK_AND_MOVE)) {
requestMultipleUpload(data, resultCode);
- } else if (requestCode == ACTION_MOVE_FILES && (resultCode == RESULT_OK ||
- resultCode == MoveActivity.RESULT_OK_AND_MOVE)) {
+ } else if (requestCode == ACTION_MOVE_FILES && resultCode == RESULT_OK) {
final Intent fData = data;
final int fResultCode = resultCode;
* @param resultCode Result code received
*/
private void requestMoveOperation(Intent data, int resultCode) {
- OCFile folderToMoveAt = (OCFile) data.getParcelableExtra(MoveActivity.EXTRA_CURRENT_FOLDER);
- OCFile targetFile = (OCFile) data.getParcelableExtra(MoveActivity.EXTRA_TARGET_FILE);
+ OCFile folderToMoveAt = (OCFile) data.getParcelableExtra(FolderPickerActivity.EXTRA_FOLDER);
+ OCFile targetFile = (OCFile) data.getParcelableExtra(FolderPickerActivity.EXTRA_FILE);
getFileOperationsHelper().moveFile(folderToMoveAt, targetFile);
}
--- /dev/null
+/* ownCloud Android client application
+ * Copyright (C) 2012-2014 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,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package com.owncloud.android.ui.activity;
+
+import java.io.IOException;
+
+import android.accounts.Account;
+import android.accounts.AccountManager;
+import android.accounts.AuthenticatorException;
+import android.accounts.OperationCanceledException;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.res.Resources.NotFoundException;
+import android.os.Bundle;
+import android.os.Parcelable;
+import android.support.v4.app.Fragment;
+import android.support.v4.app.FragmentTransaction;
+import android.util.Log;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.Button;
+import android.widget.Toast;
+
+import com.actionbarsherlock.app.ActionBar;
+import com.actionbarsherlock.view.Menu;
+import com.actionbarsherlock.view.MenuInflater;
+import com.actionbarsherlock.view.MenuItem;
+import com.actionbarsherlock.view.Window;
+import com.owncloud.android.R;
+import com.owncloud.android.datamodel.OCFile;
+import com.owncloud.android.lib.common.OwnCloudAccount;
+import com.owncloud.android.lib.common.OwnCloudClient;
+import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
+import com.owncloud.android.lib.common.OwnCloudCredentials;
+import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException;
+import com.owncloud.android.lib.common.operations.RemoteOperation;
+import com.owncloud.android.lib.common.operations.RemoteOperationResult;
+import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
+import com.owncloud.android.lib.common.utils.Log_OC;
+import com.owncloud.android.operations.CreateFolderOperation;
+import com.owncloud.android.operations.SynchronizeFolderOperation;
+import com.owncloud.android.syncadapter.FileSyncAdapter;
+import com.owncloud.android.ui.dialog.CreateFolderDialogFragment;
+import com.owncloud.android.ui.fragment.FileFragment;
+import com.owncloud.android.ui.fragment.OCFileListFragment;
+import com.owncloud.android.utils.DisplayUtils;
+import com.owncloud.android.utils.ErrorMessageAdapter;
+
+public class FolderPickerActivity extends FileActivity implements FileFragment.ContainerActivity,
+ OnClickListener, OnEnforceableRefreshListener {
+
+ public static final String EXTRA_FOLDER = UploadFilesActivity.class.getCanonicalName()
+ + ".EXTRA_FOLDER";
+ public static final String EXTRA_FILE = UploadFilesActivity.class.getCanonicalName()
+ + ".EXTRA_FILE";
+ //TODO: Think something better
+
+ private SyncBroadcastReceiver mSyncBroadcastReceiver;
+
+ private static final String TAG = FolderPickerActivity.class.getSimpleName();
+
+ private static final String TAG_LIST_OF_FOLDERS = "LIST_OF_FOLDERS";
+
+ private boolean mSyncInProgress = false;
+
+ protected Button mCancelBtn;
+ protected Button mChooseBtn;
+
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ Log_OC.d(TAG, "onCreate() start");
+ requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
+
+ super.onCreate(savedInstanceState);
+
+ setContentView(R.layout.files_folder_picker);
+
+ if (savedInstanceState == null) {
+ createFragments();
+ }
+
+ // sets callback listeners for UI elements
+ initControls();
+
+ // Action bar setup
+ ActionBar actionBar = getSupportActionBar();
+ actionBar.setDisplayShowTitleEnabled(true);
+ actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
+ setSupportProgressBarIndeterminateVisibility(mSyncInProgress);
+ // always AFTER setContentView(...) ; to work around bug in its implementation
+
+ // sets message for empty list of folders
+ setBackgroundText();
+
+ Log_OC.d(TAG, "onCreate() end");
+
+ }
+
+ @Override
+ protected void onStart() {
+ super.onStart();
+ getSupportActionBar().setIcon(DisplayUtils.getSeasonalIconId());
+ }
+
+ /**
+ * Called when the ownCloud {@link Account} associated to the Activity was just updated.
+ */
+ @Override
+ 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();
+ }
+
+ if (!stateWasRecovered) {
+ OCFileListFragment listOfFolders = getListOfFilesFragment();
+ listOfFolders.listDirectory(folder);
+
+ startSyncFolderOperation(folder, false);
+ }
+
+ updateNavigationElementsInActionBar();
+ }
+ }
+
+ private void createFragments() {
+ OCFileListFragment listOfFiles = new OCFileListFragment();
+ Bundle args = new Bundle();
+ args.putBoolean(OCFileListFragment.ARG_JUST_FOLDERS, true);
+ args.putBoolean(OCFileListFragment.ARG_ALLOW_CONTEXTUAL_ACTIONS, false);
+ listOfFiles.setArguments(args);
+ FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
+ transaction.add(R.id.fragment_container, listOfFiles, TAG_LIST_OF_FOLDERS);
+ transaction.commit();
+ }
+
+ /**
+ * Show a text message on screen view for notifying user if content is
+ * loading or folder is empty
+ */
+ private void setBackgroundText() {
+ OCFileListFragment listFragment = getListOfFilesFragment();
+ if (listFragment != null) {
+ int message = R.string.file_list_loading;
+ if (!mSyncInProgress) {
+ // In case folder list is empty
+ message = R.string.file_list_empty_moving;
+ }
+ listFragment.setMessageForEmptyList(getString(message));
+ } else {
+ Log.e(TAG, "OCFileListFragment is null");
+ }
+ }
+
+ protected OCFileListFragment getListOfFilesFragment() {
+ Fragment listOfFiles = getSupportFragmentManager().findFragmentByTag(FolderPickerActivity.TAG_LIST_OF_FOLDERS);
+ if (listOfFiles != null) {
+ return (OCFileListFragment)listOfFiles;
+ }
+ Log_OC.wtf(TAG, "Access to unexisting list of files fragment!!");
+ return null;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ *
+ * Updates action bar and second fragment, if in dual pane mode.
+ */
+ @Override
+ public void onBrowsedDownTo(OCFile directory) {
+ setFile(directory);
+ updateNavigationElementsInActionBar();
+ // Sync Folder
+ startSyncFolderOperation(directory, false);
+
+ }
+
+
+ public void startSyncFolderOperation(OCFile folder, boolean ignoreETag) {
+ long currentSyncTime = System.currentTimeMillis();
+
+ mSyncInProgress = true;
+
+ // perform folder synchronization
+ RemoteOperation synchFolderOp = new SynchronizeFolderOperation( folder,
+ currentSyncTime,
+ false,
+ getFileOperationsHelper().isSharedSupported(),
+ ignoreETag,
+ getStorageManager(),
+ getAccount(),
+ getApplicationContext()
+ );
+ synchFolderOp.execute(getAccount(), this, null, null);
+
+ setSupportProgressBarIndeterminateVisibility(true);
+
+ setBackgroundText();
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ Log_OC.e(TAG, "onResume() start");
+
+ // refresh list of files
+ refreshListOfFilesFragment();
+
+ // Listen for sync messages
+ IntentFilter syncIntentFilter = new IntentFilter(FileSyncAdapter.EVENT_FULL_SYNC_START);
+ syncIntentFilter.addAction(FileSyncAdapter.EVENT_FULL_SYNC_END);
+ syncIntentFilter.addAction(FileSyncAdapter.EVENT_FULL_SYNC_FOLDER_CONTENTS_SYNCED);
+ syncIntentFilter.addAction(SynchronizeFolderOperation.EVENT_SINGLE_FOLDER_CONTENTS_SYNCED);
+ syncIntentFilter.addAction(SynchronizeFolderOperation.EVENT_SINGLE_FOLDER_SHARES_SYNCED);
+ mSyncBroadcastReceiver = new SyncBroadcastReceiver();
+ registerReceiver(mSyncBroadcastReceiver, syncIntentFilter);
+
+ Log_OC.d(TAG, "onResume() end");
+ }
+
+ @Override
+ protected void onPause() {
+ Log_OC.e(TAG, "onPause() start");
+ if (mSyncBroadcastReceiver != null) {
+ unregisterReceiver(mSyncBroadcastReceiver);
+ //LocalBroadcastManager.getInstance(this).unregisterReceiver(mSyncBroadcastReceiver);
+ mSyncBroadcastReceiver = null;
+ }
+
+ Log_OC.d(TAG, "onPause() end");
+ super.onPause();
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ MenuInflater inflater = getSherlock().getMenuInflater();
+ inflater.inflate(R.menu.main_menu, menu);
+ menu.findItem(R.id.action_upload).setVisible(false);
+ menu.findItem(R.id.action_settings).setVisible(false);
+ menu.findItem(R.id.action_sync_account).setVisible(false);
+ menu.findItem(R.id.action_logger).setVisible(false);
+ menu.findItem(R.id.action_sort).setVisible(false);
+ return true;
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ boolean retval = true;
+ switch (item.getItemId()) {
+ case R.id.action_create_dir: {
+ CreateFolderDialogFragment dialog =
+ CreateFolderDialogFragment.newInstance(getCurrentFolder());
+ dialog.show(
+ getSupportFragmentManager(),
+ CreateFolderDialogFragment.CREATE_FOLDER_FRAGMENT
+ );
+ break;
+ }
+ case android.R.id.home: {
+ OCFile currentDir = getCurrentFolder();
+ if(currentDir != null && currentDir.getParentId() != 0) {
+ onBackPressed();
+ }
+ break;
+ }
+ default:
+ retval = super.onOptionsItemSelected(item);
+ }
+ return retval;
+ }
+
+ protected OCFile getCurrentFolder() {
+ OCFile file = getFile();
+ if (file != null) {
+ if (file.isFolder()) {
+ return file;
+ } else if (getStorageManager() != null) {
+ String parentPath = file.getRemotePath().substring(0, file.getRemotePath().lastIndexOf(file.getFileName()));
+ return getStorageManager().getFileByPath(parentPath);
+ }
+ }
+ return null;
+ }
+
+ protected void refreshListOfFilesFragment() {
+ OCFileListFragment fileListFragment = getListOfFilesFragment();
+ if (fileListFragment != null) {
+ fileListFragment.listDirectory();
+ }
+ }
+
+ public void browseToRoot() {
+ OCFileListFragment listOfFiles = getListOfFilesFragment();
+ if (listOfFiles != null) { // should never be null, indeed
+ OCFile root = getStorageManager().getFileByPath(OCFile.ROOT_PATH);
+ listOfFiles.listDirectory(root);
+ setFile(listOfFiles.getCurrentFile());
+ updateNavigationElementsInActionBar();
+ startSyncFolderOperation(root, false);
+ }
+ }
+
+ @Override
+ public void onBackPressed() {
+ OCFileListFragment listOfFiles = getListOfFilesFragment();
+ if (listOfFiles != null) { // should never be null, indeed
+ int levelsUp = listOfFiles.onBrowseUp();
+ if (levelsUp == 0) {
+ finish();
+ return;
+ }
+ setFile(listOfFiles.getCurrentFile());
+ updateNavigationElementsInActionBar();
+ }
+ }
+
+ protected void updateNavigationElementsInActionBar() {
+ ActionBar actionBar = getSupportActionBar();
+ OCFile currentDir = getCurrentFolder();
+ boolean atRoot = (currentDir == null || currentDir.getParentId() == 0);
+ actionBar.setDisplayHomeAsUpEnabled(!atRoot);
+ actionBar.setHomeButtonEnabled(!atRoot);
+ actionBar.setTitle(
+ atRoot
+ ? getString(R.string.default_display_name_for_root_folder)
+ : currentDir.getFileName()
+ );
+ }
+
+ /**
+ * Set per-view controllers
+ */
+ private void initControls(){
+ mCancelBtn = (Button) findViewById(R.id.folder_picker_btn_cancel);
+ mCancelBtn.setOnClickListener(this);
+ mChooseBtn = (Button) findViewById(R.id.folder_picker_btn_choose);
+ mChooseBtn.setOnClickListener(this);
+ }
+
+ @Override
+ public void onClick(View v) {
+ if (v == mCancelBtn) {
+ finish();
+ } else if (v == mChooseBtn) {
+ Intent i = getIntent();
+ Parcelable targetFile = i.getParcelableExtra(FolderPickerActivity.EXTRA_FILE);
+
+ Intent data = new Intent();
+ data.putExtra(EXTRA_FOLDER, getCurrentFolder());
+ if (targetFile != null) {
+ data.putExtra(EXTRA_FILE, targetFile);
+ }
+ setResult(RESULT_OK, data);
+ finish();
+ }
+ }
+
+
+ @Override
+ public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationResult result) {
+ super.onRemoteOperationFinish(operation, result);
+
+ if (operation instanceof CreateFolderOperation) {
+ onCreateFolderOperationFinish((CreateFolderOperation)operation, result);
+
+ }
+ }
+
+
+ /**
+ * Updates the view associated to the activity after the finish of an operation trying
+ * to create a new folder.
+ *
+ * @param operation Creation operation performed.
+ * @param result Result of the creation.
+ */
+ private void onCreateFolderOperationFinish(
+ CreateFolderOperation operation, RemoteOperationResult result
+ ) {
+
+ if (result.isSuccess()) {
+ dismissLoadingDialog();
+ refreshListOfFilesFragment();
+ } else {
+ dismissLoadingDialog();
+ try {
+ Toast msg = Toast.makeText(FolderPickerActivity.this,
+ ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()),
+ Toast.LENGTH_LONG);
+ msg.show();
+
+ } catch (NotFoundException e) {
+ Log_OC.e(TAG, "Error while trying to show fail message " , e);
+ }
+ }
+ }
+
+
+
+ private class SyncBroadcastReceiver extends BroadcastReceiver {
+
+ /**
+ * {@link BroadcastReceiver} to enable syncing feedback in UI
+ */
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ try {
+ String event = intent.getAction();
+ Log_OC.d(TAG, "Received broadcast " + event);
+ String accountName = intent.getStringExtra(FileSyncAdapter.EXTRA_ACCOUNT_NAME);
+ String synchFolderRemotePath = intent.getStringExtra(FileSyncAdapter.EXTRA_FOLDER_PATH);
+ RemoteOperationResult synchResult = (RemoteOperationResult)intent.
+ getSerializableExtra(FileSyncAdapter.EXTRA_RESULT);
+ boolean sameAccount = (getAccount() != null &&
+ accountName.equals(getAccount().name) && getStorageManager() != null);
+
+ if (sameAccount) {
+
+ if (FileSyncAdapter.EVENT_FULL_SYNC_START.equals(event)) {
+ mSyncInProgress = true;
+
+ } else {
+ OCFile currentFile = (getFile() == null) ? null :
+ getStorageManager().getFileByPath(getFile().getRemotePath());
+ OCFile currentDir = (getCurrentFolder() == null) ? null :
+ getStorageManager().getFileByPath(getCurrentFolder().getRemotePath());
+
+ if (currentDir == null) {
+ // current folder was removed from the server
+ Toast.makeText( FolderPickerActivity.this,
+ String.format(
+ getString(R.string.sync_current_folder_was_removed),
+ getCurrentFolder().getFileName()),
+ Toast.LENGTH_LONG)
+ .show();
+ browseToRoot();
+
+ } else {
+ if (currentFile == null && !getFile().isFolder()) {
+ // currently selected file was removed in the server, and now we know it
+ currentFile = currentDir;
+ }
+
+ if (synchFolderRemotePath != null && currentDir.getRemotePath().
+ equals(synchFolderRemotePath)) {
+ OCFileListFragment fileListFragment = getListOfFilesFragment();
+ if (fileListFragment != null) {
+ fileListFragment.listDirectory(currentDir);
+ }
+ }
+ setFile(currentFile);
+ }
+
+ mSyncInProgress = (!FileSyncAdapter.EVENT_FULL_SYNC_END.equals(event) &&
+ !SynchronizeFolderOperation.EVENT_SINGLE_FOLDER_SHARES_SYNCED.equals(event));
+
+ if (SynchronizeFolderOperation.EVENT_SINGLE_FOLDER_CONTENTS_SYNCED.
+ equals(event) &&
+ /// TODO refactor and make common
+ synchResult != null && !synchResult.isSuccess() &&
+ (synchResult.getCode() == ResultCode.UNAUTHORIZED ||
+ synchResult.isIdPRedirection() ||
+ (synchResult.isException() && synchResult.getException()
+ instanceof AuthenticatorException))) {
+
+ OwnCloudClient client = null;
+ try {
+ OwnCloudAccount ocAccount =
+ new OwnCloudAccount(getAccount(), context);
+ client = (OwnCloudClientManagerFactory.getDefaultSingleton().
+ removeClientFor(ocAccount));
+ // TODO get rid of these exceptions
+ } catch (AccountNotFoundException e) {
+ e.printStackTrace();
+ } catch (AuthenticatorException e) {
+ e.printStackTrace();
+ } catch (OperationCanceledException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ if (client != null) {
+ OwnCloudCredentials cred = client.getCredentials();
+ if (cred != null) {
+ AccountManager am = AccountManager.get(context);
+ if (cred.authTokenExpires()) {
+ am.invalidateAuthToken(
+ getAccount().type,
+ cred.getAuthToken()
+ );
+ } else {
+ am.clearPassword(getAccount());
+ }
+ }
+ }
+
+ requestCredentialsUpdate();
+
+ }
+ }
+ removeStickyBroadcast(intent);
+ Log_OC.d(TAG, "Setting progress visibility to " + mSyncInProgress);
+ setSupportProgressBarIndeterminateVisibility(mSyncInProgress /*|| mRefreshSharesInProgress*/);
+
+ setBackgroundText();
+
+ }
+
+ } catch (RuntimeException e) {
+ // avoid app crashes after changing the serial id of RemoteOperationResult
+ // in owncloud library with broadcast notifications pending to process
+ removeStickyBroadcast(intent);
+ }
+ }
+ }
+
+
+
+ /**
+ * Shows the information of the {@link OCFile} received as a
+ * parameter in the second fragment.
+ *
+ * @param file {@link OCFile} whose details will be shown
+ */
+ @Override
+ public void showDetails(OCFile file) {
+
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void onTransferStateChanged(OCFile file, boolean downloading, boolean uploading) {
+
+ }
+
+ @Override
+ public void onRefresh() {
+ refreshList(true);
+ }
+
+ @Override
+ public void onRefresh(boolean enforced) {
+ refreshList(enforced);
+ }
+
+ private void refreshList(boolean ignoreETag) {
+ OCFileListFragment listOfFiles = getListOfFilesFragment();
+ if (listOfFiles != null) {
+ OCFile folder = listOfFiles.getCurrentFile();
+ if (folder != null) {
+ startSyncFolderOperation(folder, ignoreETag);
+ }
+ }
+ }
+}
+++ /dev/null
-/* ownCloud Android client application
- * Copyright (C) 2012-2014 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,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-package com.owncloud.android.ui.activity;
-
-import java.io.IOException;
-
-import android.accounts.Account;
-import android.accounts.AccountManager;
-import android.accounts.AuthenticatorException;
-import android.accounts.OperationCanceledException;
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.content.res.Resources.NotFoundException;
-import android.os.Bundle;
-import android.support.v4.app.Fragment;
-import android.support.v4.app.FragmentTransaction;
-import android.util.Log;
-import android.view.View;
-import android.view.View.OnClickListener;
-import android.widget.Button;
-import android.widget.Toast;
-
-import com.actionbarsherlock.app.ActionBar;
-import com.actionbarsherlock.view.Menu;
-import com.actionbarsherlock.view.MenuInflater;
-import com.actionbarsherlock.view.MenuItem;
-import com.actionbarsherlock.view.Window;
-import com.owncloud.android.R;
-import com.owncloud.android.datamodel.OCFile;
-import com.owncloud.android.lib.common.OwnCloudAccount;
-import com.owncloud.android.lib.common.OwnCloudClient;
-import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
-import com.owncloud.android.lib.common.OwnCloudCredentials;
-import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException;
-import com.owncloud.android.lib.common.operations.RemoteOperation;
-import com.owncloud.android.lib.common.operations.RemoteOperationResult;
-import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
-import com.owncloud.android.operations.CreateFolderOperation;
-import com.owncloud.android.operations.SynchronizeFolderOperation;
-import com.owncloud.android.syncadapter.FileSyncAdapter;
-import com.owncloud.android.ui.dialog.CreateFolderDialogFragment;
-import com.owncloud.android.ui.fragment.FileFragment;
-import com.owncloud.android.ui.fragment.OCFileListFragment;
-import com.owncloud.android.utils.DisplayUtils;
-import com.owncloud.android.utils.ErrorMessageAdapter;
-import com.owncloud.android.lib.common.utils.Log_OC;
-
-public class MoveActivity extends HookActivity implements FileFragment.ContainerActivity,
- OnClickListener, OnEnforceableRefreshListener {
-
- public static final String EXTRA_CURRENT_FOLDER = UploadFilesActivity.class.getCanonicalName() + ".EXTRA_CURRENT_FOLDER";
- public static final String EXTRA_TARGET_FILE = UploadFilesActivity.class.getCanonicalName() + "EXTRA_TARGET_FILE";
-
- public static final int RESULT_OK_AND_MOVE = 1;
-
- private SyncBroadcastReceiver mSyncBroadcastReceiver;
-
- private static final String TAG = MoveActivity.class.getSimpleName();
-
- private static final String TAG_LIST_OF_FOLDERS = "LIST_OF_FOLDERS";
-
- private boolean mSyncInProgress = false;
-
- private Button mCancelBtn;
- private Button mChooseBtn;
-
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- Log_OC.d(TAG, "onCreate() start");
- requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
-
- super.onCreate(savedInstanceState);
-
- setContentView(R.layout.files_move);
-
- if (savedInstanceState == null) {
- createFragments();
- }
-
- // sets callback listeners for UI elements
- initControls();
-
- // Action bar setup
- ActionBar actionBar = getSupportActionBar();
- actionBar.setDisplayShowTitleEnabled(true);
- actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
- setSupportProgressBarIndeterminateVisibility(mSyncInProgress);
- // always AFTER setContentView(...) ; to work around bug in its implementation
-
- // sets message for empty list of folders
- setBackgroundText();
-
- Log_OC.d(TAG, "onCreate() end");
-
- }
-
- @Override
- protected void onStart() {
- super.onStart();
- getSupportActionBar().setIcon(DisplayUtils.getSeasonalIconId());
- }
-
- @Override
- protected void onDestroy() {
- super.onDestroy();
- }
-
- /**
- * Called when the ownCloud {@link Account} associated to the Activity was just updated.
- */
- @Override
- 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();
- }
-
- if (!stateWasRecovered) {
- OCFileListFragment listOfFolders = getListOfFilesFragment();
- listOfFolders.listDirectory(folder);
-
- startSyncFolderOperation(folder, false);
- }
-
- updateNavigationElementsInActionBar();
- }
- }
-
- private void createFragments() {
- OCFileListFragment listOfFiles = new OCFileListFragment();
- Bundle args = new Bundle();
- args.putBoolean(OCFileListFragment.ARG_JUST_FOLDERS, true);
- args.putBoolean(OCFileListFragment.ARG_ALLOW_CONTEXTUAL_ACTIONS, false);
- listOfFiles.setArguments(args);
- FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
- transaction.add(R.id.fragment_container, listOfFiles, TAG_LIST_OF_FOLDERS);
- transaction.commit();
- }
-
- /**
- * Show a text message on screen view for notifying user if content is
- * loading or folder is empty
- */
- private void setBackgroundText() {
- OCFileListFragment listFragment = getListOfFilesFragment();
- if (listFragment != null) {
- int message = R.string.file_list_loading;
- if (!mSyncInProgress) {
- // In case folder list is empty
- message = R.string.file_list_empty_moving;
- }
- listFragment.setMessageForEmptyList(getString(message));
- } else {
- Log.e(TAG, "OCFileListFragment is null");
- }
- }
-
- private OCFileListFragment getListOfFilesFragment() {
- Fragment listOfFiles = getSupportFragmentManager().findFragmentByTag(MoveActivity.TAG_LIST_OF_FOLDERS);
- if (listOfFiles != null) {
- return (OCFileListFragment)listOfFiles;
- }
- Log_OC.wtf(TAG, "Access to unexisting list of files fragment!!");
- return null;
- }
-
-
- /**
- * {@inheritDoc}
- *
- * Updates action bar and second fragment, if in dual pane mode.
- */
- @Override
- public void onBrowsedDownTo(OCFile directory) {
- setFile(directory);
- updateNavigationElementsInActionBar();
- // Sync Folder
- startSyncFolderOperation(directory, false);
-
- }
-
-
- public void startSyncFolderOperation(OCFile folder, boolean ignoreETag) {
- long currentSyncTime = System.currentTimeMillis();
-
- mSyncInProgress = true;
-
- // perform folder synchronization
- RemoteOperation synchFolderOp = new SynchronizeFolderOperation( folder,
- currentSyncTime,
- false,
- getFileOperationsHelper().isSharedSupported(),
- ignoreETag,
- getStorageManager(),
- getAccount(),
- getApplicationContext()
- );
- synchFolderOp.execute(getAccount(), this, null, null);
-
- setSupportProgressBarIndeterminateVisibility(true);
-
- setBackgroundText();
- }
-
- @Override
- protected void onResume() {
- super.onResume();
- Log_OC.e(TAG, "onResume() start");
-
- // refresh list of files
- refreshListOfFilesFragment();
-
- // Listen for sync messages
- IntentFilter syncIntentFilter = new IntentFilter(FileSyncAdapter.EVENT_FULL_SYNC_START);
- syncIntentFilter.addAction(FileSyncAdapter.EVENT_FULL_SYNC_END);
- syncIntentFilter.addAction(FileSyncAdapter.EVENT_FULL_SYNC_FOLDER_CONTENTS_SYNCED);
- syncIntentFilter.addAction(SynchronizeFolderOperation.EVENT_SINGLE_FOLDER_CONTENTS_SYNCED);
- syncIntentFilter.addAction(SynchronizeFolderOperation.EVENT_SINGLE_FOLDER_SHARES_SYNCED);
- mSyncBroadcastReceiver = new SyncBroadcastReceiver();
- registerReceiver(mSyncBroadcastReceiver, syncIntentFilter);
-
- Log_OC.d(TAG, "onResume() end");
- }
-
- @Override
- protected void onPause() {
- Log_OC.e(TAG, "onPause() start");
- if (mSyncBroadcastReceiver != null) {
- unregisterReceiver(mSyncBroadcastReceiver);
- //LocalBroadcastManager.getInstance(this).unregisterReceiver(mSyncBroadcastReceiver);
- mSyncBroadcastReceiver = null;
- }
-
- Log_OC.d(TAG, "onPause() end");
- super.onPause();
- }
-
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- MenuInflater inflater = getSherlock().getMenuInflater();
- inflater.inflate(R.menu.main_menu, menu);
- menu.findItem(R.id.action_upload).setVisible(false);
- menu.findItem(R.id.action_settings).setVisible(false);
- menu.findItem(R.id.action_sync_account).setVisible(false);
- return true;
- }
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- boolean retval = true;
- switch (item.getItemId()) {
- case R.id.action_create_dir: {
- CreateFolderDialogFragment dialog =
- CreateFolderDialogFragment.newInstance(getCurrentFolder());
- dialog.show(
- getSupportFragmentManager(),
- CreateFolderDialogFragment.CREATE_FOLDER_FRAGMENT
- );
- break;
- }
- case android.R.id.home: {
- OCFile currentDir = getCurrentFolder();
- if(currentDir != null && currentDir.getParentId() != 0) {
- onBackPressed();
- }
- break;
- }
- default:
- retval = super.onOptionsItemSelected(item);
- }
- return retval;
- }
-
- private OCFile getCurrentFolder() {
- OCFile file = getFile();
- if (file != null) {
- if (file.isFolder()) {
- return file;
- } else if (getStorageManager() != null) {
- String parentPath = file.getRemotePath().substring(0, file.getRemotePath().lastIndexOf(file.getFileName()));
- return getStorageManager().getFileByPath(parentPath);
- }
- }
- return null;
- }
-
- protected void refreshListOfFilesFragment() {
- OCFileListFragment fileListFragment = getListOfFilesFragment();
- if (fileListFragment != null) {
- fileListFragment.listDirectory();
- }
- }
-
- public void browseToRoot() {
- OCFileListFragment listOfFiles = getListOfFilesFragment();
- if (listOfFiles != null) { // should never be null, indeed
- OCFile root = getStorageManager().getFileByPath(OCFile.ROOT_PATH);
- listOfFiles.listDirectory(root);
- setFile(listOfFiles.getCurrentFile());
- updateNavigationElementsInActionBar();
- startSyncFolderOperation(root, false);
- }
- }
-
- @Override
- public void onBackPressed() {
- OCFileListFragment listOfFiles = getListOfFilesFragment();
- if (listOfFiles != null) { // should never be null, indeed
- int levelsUp = listOfFiles.onBrowseUp();
- if (levelsUp == 0) {
- finish();
- return;
- }
- setFile(listOfFiles.getCurrentFile());
- updateNavigationElementsInActionBar();
- }
- }
-
- private void updateNavigationElementsInActionBar() {
- ActionBar actionBar = getSupportActionBar();
- OCFile currentDir = getCurrentFolder();
- boolean atRoot = (currentDir == null || currentDir.getParentId() == 0);
- actionBar.setDisplayHomeAsUpEnabled(!atRoot);
- actionBar.setHomeButtonEnabled(!atRoot);
- actionBar.setTitle(
- atRoot
- ? getString(R.string.default_display_name_for_root_folder)
- : currentDir.getFileName()
- );
- }
-
- /**
- * Set per-view controllers
- */
- private void initControls(){
- mCancelBtn = (Button) findViewById(R.id.move_files_btn_cancel);
- mCancelBtn.setOnClickListener(this);
- mChooseBtn = (Button) findViewById(R.id.move_files_btn_choose);
- mChooseBtn.setOnClickListener(this);
- }
-
- @Override
- public void onClick(View v) {
- if (v == mCancelBtn) {
- finish();
- } else if (v == mChooseBtn) {
- Intent i = getIntent();
- OCFile targetFile = (OCFile) i.getParcelableExtra(MoveActivity.EXTRA_TARGET_FILE);
-
- Intent data = new Intent();
- data.putExtra(EXTRA_CURRENT_FOLDER, getCurrentFolder());
- data.putExtra(EXTRA_TARGET_FILE, targetFile);
- setResult(RESULT_OK_AND_MOVE, data);
- finish();
- }
- }
-
-
- @Override
- public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationResult result) {
- super.onRemoteOperationFinish(operation, result);
-
- if (operation instanceof CreateFolderOperation) {
- onCreateFolderOperationFinish((CreateFolderOperation)operation, result);
-
- }
- }
-
-
- /**
- * Updates the view associated to the activity after the finish of an operation trying
- * to create a new folder.
- *
- * @param operation Creation operation performed.
- * @param result Result of the creation.
- */
- private void onCreateFolderOperationFinish(
- CreateFolderOperation operation, RemoteOperationResult result
- ) {
-
- if (result.isSuccess()) {
- dismissLoadingDialog();
- refreshListOfFilesFragment();
- } else {
- dismissLoadingDialog();
- try {
- Toast msg = Toast.makeText(MoveActivity.this,
- ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()),
- Toast.LENGTH_LONG);
- msg.show();
-
- } catch (NotFoundException e) {
- Log_OC.e(TAG, "Error while trying to show fail message " , e);
- }
- }
- }
-
-
-
- private class SyncBroadcastReceiver extends BroadcastReceiver {
-
- /**
- * {@link BroadcastReceiver} to enable syncing feedback in UI
- */
- @Override
- public void onReceive(Context context, Intent intent) {
- try {
- String event = intent.getAction();
- Log_OC.d(TAG, "Received broadcast " + event);
- String accountName = intent.getStringExtra(FileSyncAdapter.EXTRA_ACCOUNT_NAME);
- String synchFolderRemotePath = intent.getStringExtra(FileSyncAdapter.EXTRA_FOLDER_PATH);
- RemoteOperationResult synchResult = (RemoteOperationResult)intent.getSerializableExtra(FileSyncAdapter.EXTRA_RESULT);
- boolean sameAccount = (getAccount() != null && accountName.equals(getAccount().name) && getStorageManager() != null);
-
- if (sameAccount) {
-
- if (FileSyncAdapter.EVENT_FULL_SYNC_START.equals(event)) {
- mSyncInProgress = true;
-
- } else {
- OCFile currentFile = (getFile() == null) ? null : getStorageManager().getFileByPath(getFile().getRemotePath());
- OCFile currentDir = (getCurrentFolder() == null) ? null : getStorageManager().getFileByPath(getCurrentFolder().getRemotePath());
-
- if (currentDir == null) {
- // current folder was removed from the server
- Toast.makeText( MoveActivity.this,
- String.format(getString(R.string.sync_current_folder_was_removed), getCurrentFolder().getFileName()),
- Toast.LENGTH_LONG)
- .show();
- browseToRoot();
-
- } else {
- if (currentFile == null && !getFile().isFolder()) {
- // currently selected file was removed in the server, and now we know it
- currentFile = currentDir;
- }
-
- if (synchFolderRemotePath != null && currentDir.getRemotePath().equals(synchFolderRemotePath)) {
- OCFileListFragment fileListFragment = getListOfFilesFragment();
- if (fileListFragment != null) {
- fileListFragment.listDirectory(currentDir);
- }
- }
- setFile(currentFile);
- }
-
- mSyncInProgress = (!FileSyncAdapter.EVENT_FULL_SYNC_END.equals(event) && !SynchronizeFolderOperation.EVENT_SINGLE_FOLDER_SHARES_SYNCED.equals(event));
-
- if (SynchronizeFolderOperation.EVENT_SINGLE_FOLDER_CONTENTS_SYNCED.
- equals(event) &&
- /// TODO refactor and make common
- synchResult != null && !synchResult.isSuccess() &&
- (synchResult.getCode() == ResultCode.UNAUTHORIZED ||
- synchResult.isIdPRedirection() ||
- (synchResult.isException() && synchResult.getException()
- instanceof AuthenticatorException))) {
-
- OwnCloudClient client = null;
- try {
- OwnCloudAccount ocAccount =
- new OwnCloudAccount(getAccount(), context);
- client = (OwnCloudClientManagerFactory.getDefaultSingleton().
- removeClientFor(ocAccount));
- // TODO get rid of these exceptions
- } catch (AccountNotFoundException e) {
- e.printStackTrace();
- } catch (AuthenticatorException e) {
- e.printStackTrace();
- } catch (OperationCanceledException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
-
- if (client != null) {
- OwnCloudCredentials cred = client.getCredentials();
- if (cred != null) {
- AccountManager am = AccountManager.get(context);
- if (cred.authTokenExpires()) {
- am.invalidateAuthToken(
- getAccount().type,
- cred.getAuthToken()
- );
- } else {
- am.clearPassword(getAccount());
- }
- }
- }
-
- requestCredentialsUpdate();
-
- }
- }
- removeStickyBroadcast(intent);
- Log_OC.d(TAG, "Setting progress visibility to " + mSyncInProgress);
- setSupportProgressBarIndeterminateVisibility(mSyncInProgress /*|| mRefreshSharesInProgress*/);
-
- setBackgroundText();
-
- }
-
- } catch (RuntimeException e) {
- // avoid app crashes after changing the serial id of RemoteOperationResult
- // in owncloud library with broadcast notifications pending to process
- removeStickyBroadcast(intent);
- }
- }
- }
-
-
-
- /**
- * Shows the information of the {@link OCFile} received as a
- * parameter in the second fragment.
- *
- * @param file {@link OCFile} whose details will be shown
- */
- @Override
- public void showDetails(OCFile file) {
-
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void onTransferStateChanged(OCFile file, boolean downloading, boolean uploading) {
-
- }
-
- @Override
- public void onRefresh() {
- refreshList(true);
- }
-
- @Override
- public void onRefresh(boolean enforced) {
- refreshList(enforced);
- }
-
- private void refreshList(boolean ignoreETag) {
- OCFileListFragment listOfFiles = getListOfFilesFragment();
- if (listOfFiles != null) {
- OCFile folder = listOfFiles.getCurrentFile();
- if (folder != null) {
- startSyncFolderOperation(folder, ignoreETag);
- }
- }
- }
-}
import com.owncloud.android.R;
import com.owncloud.android.authentication.AccountUtils;
import com.owncloud.android.authentication.AuthenticatorActivity;
+import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.db.DbHandler;
import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.ui.LongClickableCheckBoxPreference;
private static final String TAG = "OwnCloudPreferences";
+ private static final int ACTION_SELECT_UPLOAD_PATH = 1;
+ private static final int ACTION_SELECT_UPLOAD_VIDEO_PATH = 2;
+
private DbHandler mDbHandler;
private CheckBoxPreference pCode;
private Preference pAboutApp;
private String mAccountName;
private boolean mShowContextMenu = false;
private String mUploadPath;
+ private Preference mPrefInstantUploadPath;
+ private Preference mPrefInstantVideoUploadPath;
+ private String mUploadVideoPath;
@SuppressWarnings("deprecation")
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setTitle(R.string.actionbar_settings);
- loadInstantUploadPath();
-
// Load the accounts category for adding the list of accounts
mAccountsPrefCategory = (PreferenceCategory) findPreference("accounts_category");
}
}
- Preference pInstantUploadPathApp = (Preference) findPreference("instant_upload_path");
+ mPrefInstantUploadPath = findPreference("instant_upload_path");
+ if (mPrefInstantUploadPath != null){
- pInstantUploadPathApp.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
- @Override
- public boolean onPreferenceChange(Preference preference, Object newValue) {
- mUploadPath = updateInstantUploadPath(newValue.toString());
- return true;
- }
- });
+ mPrefInstantUploadPath.setOnPreferenceClickListener(new OnPreferenceClickListener() {
+ @Override
+ public boolean onPreferenceClick(Preference preference) {
+ if (!mUploadPath.endsWith(OCFile.PATH_SEPARATOR)) {
+ mUploadPath += OCFile.PATH_SEPARATOR;
+ }
+ Intent intent = new Intent(Preferences.this, UploadPathActivity.class);
+ intent.putExtra(UploadPathActivity.KEY_INSTANT_UPLOAD_PATH, mUploadPath);
+ startActivityForResult(intent, ACTION_SELECT_UPLOAD_PATH);
+ return true;
+ }
+ });
+ }
+
+ mPrefInstantVideoUploadPath = findPreference("instant_video_upload_path");
+ if (mPrefInstantVideoUploadPath != null){
+
+ mPrefInstantVideoUploadPath.setOnPreferenceClickListener(new OnPreferenceClickListener() {
+ @Override
+ public boolean onPreferenceClick(Preference preference) {
+ if (!mUploadVideoPath.endsWith(OCFile.PATH_SEPARATOR)) {
+ mUploadVideoPath += OCFile.PATH_SEPARATOR;
+ }
+ Intent intent = new Intent(Preferences.this, UploadPathActivity.class);
+ intent.putExtra(UploadPathActivity.KEY_INSTANT_UPLOAD_PATH, mUploadVideoPath);
+ startActivityForResult(intent, ACTION_SELECT_UPLOAD_VIDEO_PATH);
+ return true;
+ }
+ });
+ }
/* About App */
pAboutApp = (Preference) findPreference("about_app");
Log_OC.e(TAG, "Error while showing about dialog", e);
}
}
+
+ loadInstantUploadPath();
+ loadInstantUploadVideoPath();
+
}
@Override
protected void onPause() {
- saveInstantUploadPathOnPreferences();
super.onPause();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
+
+ if (requestCode == ACTION_SELECT_UPLOAD_PATH && resultCode == RESULT_OK){
+
+ OCFile folderToUpload = (OCFile) data.getParcelableExtra(UploadPathActivity.EXTRA_FOLDER);
+
+ mUploadPath = folderToUpload.getRemotePath();
+
+ mUploadPath = DisplayUtils.getPathWithoutLastSlash(mUploadPath);
+
+ // Show the path on summary preference
+ mPrefInstantUploadPath.setSummary(mUploadPath);
+
+ saveInstantUploadPathOnPreferences();
+
+ } else if (requestCode == ACTION_SELECT_UPLOAD_VIDEO_PATH && resultCode == RESULT_OK){
+
+ OCFile folderToUploadVideo = (OCFile) data.getParcelableExtra(UploadPathActivity.EXTRA_FOLDER);
+
+ mUploadVideoPath = folderToUploadVideo.getRemotePath();
+
+ mUploadVideoPath = DisplayUtils.getPathWithoutLastSlash(mUploadVideoPath);
+
+ // Show the video path on summary preference
+ mPrefInstantVideoUploadPath.setSummary(mUploadVideoPath);
+
+ saveInstantUploadVideoPathOnPreferences();
+ }
}
@Override
}
/**
- * Update the upload path checking that it is a correct path
- * @param uploadPath: path write by user
- * @return String: uploadPath
- */
- private String updateInstantUploadPath(String uploadPath) {
- String slashString = "/";
-
- // If slashes are duplicated, replace them for only one slash
- uploadPath = uploadPath.replaceAll("/+", slashString);
-
- // Remove last slash from path
- if (uploadPath.length() > 0 && uploadPath.charAt(uploadPath.length()-1) == slashString.charAt(0)) {
- uploadPath = uploadPath.substring(0, uploadPath.length()-1);
- }
-
- if (uploadPath.isEmpty()) { // Set default instant upload path
- uploadPath = getString(R.string.instant_upload_path);
- }else {
- if (!uploadPath.startsWith(slashString)) { // Add initial slash on path if necessary
- uploadPath = slashString.concat(uploadPath);
- }
- }
- return uploadPath;
- }
-
- /**
* Load upload path set on preferences
*/
private void loadInstantUploadPath() {
SharedPreferences appPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
mUploadPath = appPrefs.getString("instant_upload_path", getString(R.string.instant_upload_path));
+ mPrefInstantUploadPath.setSummary(mUploadPath);
}
/**
editor.putString("instant_upload_path", mUploadPath);
editor.commit();
}
+
+ /**
+ * Load upload video path set on preferences
+ */
+ private void loadInstantUploadVideoPath() {
+ SharedPreferences appPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
+ mUploadVideoPath = appPrefs.getString("instant_video_upload_path", getString(R.string.instant_upload_path));
+ mPrefInstantVideoUploadPath.setSummary(mUploadVideoPath);
+ }
+
+ /**
+ * Save the "Instant Video Upload Path" on preferences
+ */
+ private void saveInstantUploadVideoPathOnPreferences() {
+ SharedPreferences appPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
+ SharedPreferences.Editor editor = appPrefs.edit();
+ editor.putString("instant_video_upload_path", mUploadVideoPath);
+ editor.commit();
+ }
}
--- /dev/null
+/* ownCloud Android client application
+ * Copyright (C) 2012-2014 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,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package com.owncloud.android.ui.activity;
+
+import android.accounts.Account;
+
+import android.os.Bundle;
+import android.view.View.OnClickListener;
+
+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 static final String KEY_INSTANT_UPLOAD_PATH = "INSTANT_UPLOAD_PATH";
+
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ 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);
+
+ setFile(folder);
+ }
+
+ /**
+ * Called when the ownCloud {@link Account} associated to the Activity was
+ * just updated.
+ */
+ @Override
+ 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();
+ listOfFolders.listDirectory(folder);
+
+ startSyncFolderOperation(folder, false);
+ }
+
+ updateNavigationElementsInActionBar();
+ }
+ }
+}
import com.owncloud.android.datamodel.ThumbnailsCacheManager.AsyncDrawable;\r
import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;\r
import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;\r
-import com.owncloud.android.lib.common.utils.Log_OC;\r
import com.owncloud.android.ui.activity.ComponentsGetter;\r
import com.owncloud.android.utils.DisplayUtils;\r
import com.owncloud.android.utils.FileStorageUtils;\r
*/
import java.util.Vector;
+import android.app.Dialog;
+import android.os.Bundle;
+
import com.owncloud.android.R;
import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.ui.activity.ComponentsGetter;
import com.owncloud.android.ui.dialog.ConfirmationDialogFragment.ConfirmationDialogFragmentListener;
-import android.app.Dialog;
-import android.os.Bundle;
-
public class RemoveFileDialogFragment extends ConfirmationDialogFragment
implements ConfirmationDialogFragmentListener {
@Override
public void onNeutral(String callerTag) {
ComponentsGetter cg = (ComponentsGetter)getSherlockActivity();
- cg.getFileOperationsHelper()
- .removeFile(mTargetFile, true);
+ cg.getFileOperationsHelper().removeFile(mTargetFile, true);
FileDataStorageManager storageManager = cg.getStorageManager();
// nothing to do here
}
-}
+}
\ No newline at end of file
*
* Triggers the rename operation.
*/
-import com.actionbarsherlock.app.SherlockDialogFragment;
-import com.owncloud.android.R;
-import com.owncloud.android.datamodel.OCFile;
-import com.owncloud.android.lib.resources.files.FileUtils;
-import com.owncloud.android.ui.activity.ComponentsGetter;
-
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.widget.TextView;
import android.widget.Toast;
+import com.actionbarsherlock.app.SherlockDialogFragment;
+import com.owncloud.android.R;
+import com.owncloud.android.datamodel.OCFile;
+import com.owncloud.android.lib.resources.files.FileUtils;
+import com.owncloud.android.ui.activity.ComponentsGetter;
+
/**
* Dialog to input a new name for a file or folder to rename.
Toast.LENGTH_LONG).show();
return;
}
-
- ((ComponentsGetter)getSherlockActivity()).
- getFileOperationsHelper().renameFile(mTargetFile, newFileName);
-
-
+
+ ((ComponentsGetter)getSherlockActivity()).getFileOperationsHelper().renameFile(mTargetFile, newFileName);
}
}
-
}
import com.owncloud.android.ui.activity.OnEnforceableRefreshListener;
/**
- * TODO extending SherlockListFragment instead of SherlockFragment
+ * TODO extending SherlockListFragment instead of SherlockFragment
*/
public class ExtendedListFragment extends SherlockFragment
implements OnItemClickListener, OnEnforceableRefreshListener {
-
+
private static final String TAG = ExtendedListFragment.class.getSimpleName();
- private static final String KEY_SAVED_LIST_POSITION = "SAVED_LIST_POSITION";
+ private static final String KEY_SAVED_LIST_POSITION = "SAVED_LIST_POSITION";
private static final String KEY_INDEXES = "INDEXES";
private static final String KEY_FIRST_POSITIONS= "FIRST_POSITIONS";
private static final String KEY_TOPS = "TOPS";
private static final String KEY_EMPTY_LIST_MESSAGE = "EMPTY_LIST_MESSAGE";
protected ExtendedListView mList;
-
+
private SwipeRefreshLayout mRefreshLayout;
private SwipeRefreshLayout mRefreshEmptyLayout;
private TextView mEmptyListMessage;
mList.invalidate();
}
+ public void setFooterView(View footer) {
+ mList.addFooterView(footer, null, false);
+ mList.invalidate();
+ }
+
public ListView getListView() {
return mList;
}
-
-
+
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
Log_OC.e(TAG, "onCreateView");
-
+
View v = inflater.inflate(R.layout.list_fragment, null);
mEmptyListMessage = (TextView) v.findViewById(R.id.empty_list_view);
- mList = (ExtendedListView)(v.findViewById(R.id.list_root));
+ mList = (ExtendedListView) (v.findViewById(R.id.list_root));
mList.setOnItemClickListener(this);
mList.setDivider(getResources().getDrawable(R.drawable.uploader_list_separator));
int referencePosition = savedInstanceState.getInt(KEY_SAVED_LIST_POSITION);
setReferencePosition(referencePosition);
}
-
+
// Pull down refresh
mRefreshLayout = (SwipeRefreshLayout) v.findViewById(R.id.swipe_refresh_files);
mRefreshEmptyLayout = (SwipeRefreshLayout) v.findViewById(R.id.swipe_refresh_files_emptyView);
return v;
}
-
/**
* {@inheritDoc}
*/
savedInstanceState.putString(KEY_EMPTY_LIST_MESSAGE, getEmptyViewText());
}
-
/**
- * Calculates the position of the item that will be used as a reference to reposition the visible items in the list when
- * the device is turned to other position.
+ * Calculates the position of the item that will be used as a reference to
+ * reposition the visible items in the list when the device is turned to
+ * other position.
*
- * THe current policy is take as a reference the visible item in the center of the screen.
+ * THe current policy is take as a reference the visible item in the center
+ * of the screen.
*
- * @return The position in the list of the visible item in the center of the screen.
+ * @return The position in the list of the visible item in the center of the
+ * screen.
*/
protected int getReferencePosition() {
if (mList != null) {
}
}
-
/**
* Sets the visible part of the list from the reference position.
*
- * @param position Reference position previously returned by {@link LocalFileListFragment#getReferencePosition()}
+ * @param position Reference position previously returned by
+ * {@link LocalFileListFragment#getReferencePosition()}
*/
protected void setReferencePosition(int position) {
if (mList != null) {
@Override
public void onItemClick (AdapterView<?> parent, View view, int position, long id) {
- // to be @overriden
+ // to be @overriden
}
@Override
mOnRefreshListener.onRefresh();
}
}
-
public void setOnRefreshListener(OnEnforceableRefreshListener listener) {
mOnRefreshListener = listener;
}
package com.owncloud.android.ui.fragment;
import java.io.File;
+import java.util.Vector;
import android.app.Activity;
+import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.AdapterContextMenuInfo;
+import android.widget.TextView;
+import android.view.LayoutInflater;
import com.owncloud.android.R;
import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.files.FileMenuFilter;
import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.ui.activity.FileDisplayActivity;
-import com.owncloud.android.ui.activity.MoveActivity;
+import com.owncloud.android.ui.activity.FolderPickerActivity;
import com.owncloud.android.ui.activity.OnEnforceableRefreshListener;
import com.owncloud.android.ui.adapter.FileListListAdapter;
import com.owncloud.android.ui.dialog.ConfirmationDialogFragment;
private OCFile mFile = null;
private FileListListAdapter mAdapter;
+ private View mFooterView;
private OCFile mTargetFile;
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
Log_OC.e(TAG, "onActivityCreated() start");
-
+
if (savedInstanceState != null) {
mFile = savedInstanceState.getParcelable(KEY_FILE);
}
-
+
+ mFooterView = ((LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(
+ R.layout.list_footer, null, false);
+ setFooterView(mFooterView);
+
Bundle args = getArguments();
boolean justFolders = (args == null) ? false : args.getBoolean(ARG_JUST_FOLDERS, false);
mAdapter = new FileListListAdapter(
justFolders,
getSherlockActivity(),
mContainerActivity
- );
+ );
setListAdapter(mAdapter);
registerForContextMenu(getListView());
getListView().setOnCreateContextMenuListener(this);
- }
-
+ }
+
/**
* Saves the current listed folder.
*/
return true;
}
case R.id.action_move: {
- Intent action = new Intent(getActivity(), MoveActivity.class);
+ Intent action = new Intent(getActivity(), FolderPickerActivity.class);
// Pass mTargetFile that contains info of selected file/folder
- action.putExtra(MoveActivity.EXTRA_TARGET_FILE, mTargetFile);
+ action.putExtra(FolderPickerActivity.EXTRA_FILE, mTargetFile);
getActivity().startActivityForResult(action, FileDisplayActivity.ACTION_MOVE_FILES);
return true;
}
mList.setSelectionFromTop(0, 0);
}
mFile = directory;
+
+ // Update Footer
+ TextView footerText = (TextView) mFooterView.findViewById(R.id.footerText);
+ Log_OC.d("footer", String.valueOf(System.currentTimeMillis()));
+ footerText.setText(generateFooterText(directory));
+ Log_OC.d("footer", String.valueOf(System.currentTimeMillis()));
}
}
+ private String generateFooterText(OCFile directory) {
+ Integer files = 0;
+ Integer folders = 0;
+
+ FileDataStorageManager storageManager = mContainerActivity.getStorageManager();
+ Vector<OCFile> mFiles = storageManager.getFolderContent(mFile);
+
+ for (OCFile ocFile : mFiles) {
+ if (ocFile.isFolder()) {
+ folders++;
+ } else {
+ files++;
+ }
+ }
+
+ String output = "";
+
+ if (files > 0){
+ if (files == 1) {
+ output = output + files.toString() + " " + getResources().getString(R.string.file_list_file);
+ } else {
+ output = output + files.toString() + " " + getResources().getString(R.string.file_list_files);
+ }
+ }
+ if (folders > 0 && files > 0){
+ output = output + ", ";
+ }
+ if (folders == 1) {
+ output = output + folders.toString() + " " + getResources().getString(R.string.file_list_folder);
+ } else if (folders > 1) {
+ output = output + folders.toString() + " " + getResources().getString(R.string.file_list_folders);
+ }
+
+ return output;
+ }
+
public void sortByName(boolean descending) {
mAdapter.setSortOrder(FileListListAdapter.SORT_NAME, descending);
}
finish();
}
-
+
private class BitmapLoader extends AsyncTask<String, Void, Bitmap> {
/**
import android.annotation.TargetApi;\r
import android.content.Context;\r
import android.os.Build;\r
-import android.text.format.DateFormat;\r
import android.text.format.DateUtils;\r
\r
import com.owncloud.android.MainApp;\r
import com.owncloud.android.R;\r
+import com.owncloud.android.datamodel.OCFile;\r
\r
/**\r
* A helper class for some string operations.\r
\r
return dateString.toString().split(",")[0];
}\r
+\r
+ /**\r
+ * Update the passed path removing the last "/" if it is not the root folder\r
+ * @param path\r
+ */\r
+ public static String getPathWithoutLastSlash(String path) {\r
+\r
+ // Remove last slash from path\r
+ if (path.length() > 1 && path.charAt(path.length()-1) == OCFile.PATH_SEPARATOR.charAt(0)) {\r
+ path = path.substring(0, path.length()-1);\r
+ }\r
+ return path;\r
+ }\r
}\r
String value = uploadPath + OCFile.PATH_SEPARATOR + (fileName == null ? "" : fileName);
return value;
}
+
+ /**
+ * Gets the composed path when video is or must be stored
+ * @param context
+ * @param fileName: video file name
+ * @return String: video file path composed
+ */
+ public static String getInstantVideoUploadFilePath(Context context, String fileName) {
+ SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
+ String uploadVideoPathdef = context.getString(R.string.instant_upload_path);
+ String uploadVideoPath = pref.getString("instant_video_upload_path", uploadVideoPathdef);
+ String value = uploadVideoPath + OCFile.PATH_SEPARATOR + (fileName == null ? "" : fileName);
+ return value;
+ }
public static String getParentPath(String remotePath) {
String parentPath = new File(remotePath).getParent();