along with this program. If not, see <http://www.gnu.org/licenses/>.\r
-->\r
<manifest package="com.owncloud.android"\r
- android:versionCode="103004"\r
- android:versionName="1.3.4" xmlns:android="http://schemas.android.com/apk/res/android">\r
+ android:versionCode="103005"\r
+ android:versionName="1.3.5" xmlns:android="http://schemas.android.com/apk/res/android">\r
\r
<uses-permission android:name="android.permission.GET_ACCOUNTS" />\r
<uses-permission android:name="android.permission.USE_CREDENTIALS" />\r
<category android:name="android.intent.category.LAUNCHER" />\r
</intent-filter>\r
</activity>\r
+ <activity android:name=".ui.activity.UploadFilesActivity">\r
+ </activity>\r
<activity android:name=".Uploader" >\r
<intent-filter>\r
<action android:name="android.intent.action.SEND" >\r
android:id="@+id/fileList"\r
android:layout_width="fill_parent"\r
android:layout_height="fill_parent"\r
- class="com.owncloud.android.ui.fragment.FileListFragment" >\r
+ class="com.owncloud.android.ui.fragment.OCFileListFragment" >\r
\r
<!-- Preview: layout=@layout/list_layout -->\r
</fragment>\r
android:id="@+id/fileList"\r
android:layout_width="fill_parent"\r
android:layout_height="fill_parent"\r
- class="com.owncloud.android.ui.fragment.FileListFragment" >\r
+ class="com.owncloud.android.ui.fragment.OCFileListFragment" >\r
\r
<!-- Preview: layout=@layout/list_layout -->\r
</fragment>\r
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- ownCloud Android client application
-
- Copyright (C) 2012 Bartek Przybylski
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- 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/>.
- -->
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@+id/ListItemLayout"
- android:layout_width="fill_parent"
- android:background="@drawable/list_selector"
- android:orientation="horizontal"
- android:layout_height="56dp">
-
- <FrameLayout
- android:layout_width="wrap_content"
- android:layout_height="56dp"
- android:focusable="false"
- android:focusableInTouchMode="false">
-
- <ImageView
- android:id="@+id/imageView2"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:src="@drawable/local_file_indicator"/>
-
- <!-- ImageView
- android:id="@+id/imageView4"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:src="@drawable/downloading_file_indicator"/ >
-
- <ImageView
- android:id="@+id/imageView5"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:src="@drawable/uploading_file_indicator"/ -->
-
- <ImageView
- android:id="@+id/imageView1"
- android:layout_width="20dp"
- android:layout_height="20dp"
- android:layout_gravity="center_vertical|center"
- android:layout_margin="4dp"
- android:src="@drawable/ic_menu_archive" />
-
- <ImageView
- android:id="@+id/imageView3"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="bottom"
- android:layout_weight=".1"
- android:maxHeight="15dip"
- android:src="@drawable/ic_favorite" />
-
- </FrameLayout>
-
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical"
- android:gravity="center_vertical">
-
- <TextView
- android:id="@+id/Filename"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="center_vertical"
- android:layout_marginLeft="4dp"
- android:layout_marginRight="4dp"
- android:ellipsize="middle"
- android:singleLine="true"
- android:text="TextView"
- android:textColor="#303030"
- android:textSize="16dip" />
-
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_marginLeft="4dp"
- android:layout_marginRight="4dp"
- android:weightSum="1">
-
- <TextView
- android:id="@+id/last_mod"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="TextView"
- android:layout_weight=".5"
- android:textSize="12dip"/>
-
- <TextView
- android:id="@+id/file_size"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:gravity="right"
- android:text="TextView"
- android:layout_weight=".5"
- android:textSize="12dip"/>
-
- </LinearLayout>
-
- </LinearLayout>
-
-</LinearLayout>
+<?xml version="1.0" encoding="UTF-8"?>\r
+<!-- \r
+ ownCloud Android client application\r
+\r
+ Copyright (C) 2012 Bartek Przybylski\r
+ This program is free software: you can redistribute it and/or modify\r
+ it under the terms of the GNU General Public License as published by\r
+ the Free Software Foundation, either version 3 of the License, or\r
+ (at your option) any later version.\r
+\r
+ This program is distributed in the hope that it will be useful,\r
+ but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ GNU General Public License for more details.\r
+\r
+ You should have received a copy of the GNU General Public License\r
+ along with this program. If not, see <http://www.gnu.org/licenses/>.\r
+ -->\r
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"\r
+ android:id="@+id/ListItemLayout"\r
+ android:layout_width="fill_parent"\r
+ android:background="@drawable/list_selector"\r
+ android:orientation="horizontal"\r
+ android:layout_height="56dp">\r
+\r
+ <FrameLayout\r
+ android:layout_width="wrap_content"\r
+ android:layout_height="56dp"\r
+ android:focusable="false"\r
+ android:focusableInTouchMode="false">\r
+ \r
+ <ImageView\r
+ android:id="@+id/imageView2"\r
+ android:layout_width="wrap_content"\r
+ android:layout_height="wrap_content"\r
+ android:src="@drawable/local_file_indicator"/>\r
+\r
+ <ImageView\r
+ android:id="@+id/imageView1"\r
+ android:layout_width="20dp"\r
+ android:layout_height="20dp"\r
+ android:layout_gravity="center_vertical|center"\r
+ android:layout_margin="4dp"\r
+ android:src="@drawable/ic_menu_archive" />\r
+\r
+ <ImageView\r
+ android:id="@+id/imageView3"\r
+ android:layout_width="wrap_content"\r
+ android:layout_height="wrap_content"\r
+ android:layout_gravity="bottom"\r
+ android:layout_weight=".1"\r
+ android:maxHeight="15dip"\r
+ android:src="@drawable/ic_favorite" />\r
+ \r
+ </FrameLayout>\r
+\r\r\r\r
+ <LinearLayout\r
+ android:layout_width="0dp"\r
+ android:layout_height="match_parent"\r
+ android:layout_weight="1"\r
+ android:gravity="center_vertical"\r
+ android:orientation="vertical" >\r
+\r\r
+ <TextView\r
+ android:id="@+id/Filename"\r
+ android:layout_width="wrap_content"\r
+ android:layout_height="wrap_content"\r
+ android:layout_gravity="center_vertical"\r
+ android:layout_marginLeft="4dp"\r
+ android:layout_marginRight="4dp"\r
+ android:ellipsize="middle"\r
+ android:singleLine="true"\r
+ android:text="TextView"\r
+ android:textColor="#303030"\r
+ android:textSize="16dip" />\r
+\r
+ <LinearLayout\r
+ android:layout_width="match_parent"\r
+ android:layout_height="wrap_content"\r
+ android:layout_marginLeft="4dp"\r
+ android:layout_marginRight="4dp"\r
+ android:weightSum="1">\r
+\r
+ <TextView\r
+ android:id="@+id/last_mod"\r
+ android:layout_width="wrap_content"\r
+ android:layout_height="wrap_content"\r
+ android:text="TextView"\r
+ android:layout_weight=".5"\r
+ android:textSize="12dip"/>\r
+\r
+ <TextView\r
+ android:id="@+id/file_size"\r
+ android:layout_width="wrap_content"\r
+ android:layout_height="wrap_content"\r
+ android:gravity="right"\r
+ android:text="TextView"\r
+ android:layout_weight=".5"\r
+ android:textSize="12dip"/>\r
+\r
+ </LinearLayout>\r
+\r
+ </LinearLayout>\r
+\r\r\r\r
+ <ImageView\r
+ android:id="@+id/custom_checkbox"\r
+ android:layout_width="wrap_content"\r
+ android:layout_height="wrap_content"\r
+ android:layout_gravity="center_vertical"\r
+ android:layout_marginLeft="4dp"\r
+ android:layout_marginRight="4dp"\r
+ android:gravity=""\r
+ android:src="@android:drawable/checkbox_off_background" />\r
+\r
+</LinearLayout>\r
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>\r
+<!-- \r
+ ownCloud Android client application\r
+\r
+ Copyright (C) 2012 Bartek Przybylski\r
+ This program is free software: you can redistribute it and/or modify\r
+ it under the terms of the GNU General Public License as published by\r
+ the Free Software Foundation, either version 3 of the License, or\r
+ (at your option) any later version.\r
+\r
+ This program is distributed in the hope that it will be useful,\r
+ but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ GNU General Public License for more details.\r
+\r
+ You should have received a copy of the GNU General Public License\r
+ along with this program. If not, see <http://www.gnu.org/licenses/>.\r
+ -->\r
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"\r
+ android:id="@+id/upload_files_layout"\r
+ android:layout_width="fill_parent"\r
+ android:layout_height="fill_parent"\r
+ android:background="@color/owncloud_white"\r
+ android:orientation="vertical" >\r
+
+ <fragment\r
+ android:id="@+id/local_files_list"\r
+ android:layout_width="match_parent"\r
+ android:layout_height="0dip"\r
+ android:layout_weight="1"\r
+ class="com.owncloud.android.ui.fragment.LocalFileListFragment" />\r
+
+ <LinearLayout\r
+ android:layout_width="match_parent"\r
+ android:layout_height="wrap_content"\r
+ android:gravity="center"\r
+ android:orientation="horizontal" >\r
+\r <Button\r
+ android:id="@+id/upload_files_btn_cancel"\r
+ android:layout_width="wrap_content"\r
+ android:layout_height="wrap_content"\r
+ android:layout_weight="1"\r
+ android:text="@string/common_cancel" />\r
+\r <Button\r
+ android:id="@+id/upload_files_btn_upload"\r
+ android:layout_width="wrap_content"\r
+ android:layout_height="wrap_content"\r
+ android:layout_weight="1"\r
+ android:text="@string/uploader_btn_upload_text" />\r
+ \r
+ </LinearLayout>\r
+ \r
+</LinearLayout>\r
<string name="main_tit_accsetup">Konto einrichten</string>
<string name="main_wrn_accsetup">Auf deinem Gerät sind keine Konten eingerichtet. Bitte erstelle ein Konto, um diese App nutzen zu können.</string>
<string name="actionbar_sync">Neuladen</string>
- <string name="actionbar_upload">Datei hochladen</string>
+ <string name="actionbar_upload">Hochladen</string>
+ <string name="actionbar_upload_files">Datei</string>
<string name="actionbar_mkdir">Verzeichnis erstellen</string>
<string name="actionbar_search">Suche</string>
<string name="actionbar_settings">Einstellungen</string>
<string name="main_tit_accsetup">Configuración de cuenta</string>
<string name="main_wrn_accsetup">No hay cuentas de ownCloud en tu dispositivo. Para usar esta aplicación, necesitas crear una.</string>
<string name="actionbar_sync">Sincronización de cuenta</string>
- <string name="actionbar_upload">Subir archivo</string>
+ <string name="actionbar_upload">Subir</string>
+ <string name="actionbar_upload_from_apps">Contenido de otras apps</string>
+ <string name="actionbar_upload_files">Ficheros</string>
<string name="actionbar_mkdir">Crear directorio</string>
<string name="actionbar_search">Buscar</string>
<string name="actionbar_settings">Ajustes</string>
<string name="main_wrn_accsetup">There are no ownCloud accounts on your device. In order to use this App, you need to create one.</string>
<string name="actionbar_sync">Refresh</string>
- <string name="actionbar_upload">Upload file</string>
+ <string name="actionbar_upload">Upload</string>
+ <string name="actionbar_upload_from_apps">Content from other apps</string>
+ <string name="actionbar_upload_files">Files</string>
<string name="actionbar_mkdir">Create directory</string>
<string name="actionbar_search">Search</string>
<string name="actionbar_settings">Settings</string>
<string name="delete_account">Delete account</string>
<string name="create_account">Create account</string>
- <string name="upload_chooser_title">Upload file from …</string>
+ <string name="upload_chooser_title">Upload from …</string>
<string name="uploader_info_dirname">Directory name</string>
<string name="uploader_upload_in_progress_ticker">Uploading …</string>
<string name="uploader_upload_in_progress_content">%1$d%% Uploading %2$s</string>
<string name="wait_a_moment">Wait a moment</string>
<string name="filedisplay_unexpected_bad_get_content">"Unexpected problem ; please, try other app to select the file"</string>
+ <string name="filedisplay_no_file_selected">No file was selected</string>
</resources>
public class FragmentListView extends SherlockFragment implements
OnItemClickListener, OnItemLongClickListener {
- ListView mList;
+ protected ListView mList;
@Override
public void onCreate(Bundle savedInstanceState) {
import com.owncloud.android.files.services.FileUploader;\r
import com.owncloud.android.syncadapter.FileSyncService;\r
import com.owncloud.android.ui.fragment.FileDetailFragment;\r
-import com.owncloud.android.ui.fragment.FileListFragment;\r
+import com.owncloud.android.ui.fragment.OCFileListFragment;\r
\r
import com.owncloud.android.R;\r
import eu.alefzero.webdav.WebdavClient;\r
*/\r
\r
public class FileDisplayActivity extends SherlockFragmentActivity implements\r
- FileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNavigationListener {\r
+ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNavigationListener {\r
\r
private ArrayAdapter<String> mDirectories;\r
private OCFile mCurrentDir;\r
private UploadFinishReceiver mUploadFinishReceiver;\r
private DownloadFinishReceiver mDownloadFinishReceiver;\r
\r
- private FileListFragment mFileList;\r
+ private OCFileListFragment mFileList;\r
\r
private boolean mDualPane;\r
\r
private static final int DIALOG_CREATE_DIR = 1;\r
private static final int DIALOG_ABOUT_APP = 2;\r
public static final int DIALOG_SHORT_WAIT = 3;\r
+ private static final int DIALOG_CHOOSE_UPLOAD_SOURCE = 4;\r
\r
- private static final int ACTION_SELECT_FILE = 1;\r
+ private static final int ACTION_SELECT_CONTENT_FROM_APPS = 1;\r
+ private static final int ACTION_SELECT_MULTIPLE_FILES = 2;\r
\r
private static final String TAG = "FileDisplayActivity";\r
\r
mDirectories = new CustomArrayAdapter<String>(this, R.layout.sherlock_spinner_dropdown_item);\r
OCFile currFile = mCurrentDir;\r
while(currFile != null && currFile.getFileName() != OCFile.PATH_SEPARATOR) {\r
- mDirectories.insert(currFile.getFileName(), 0);\r
+ mDirectories.add(currFile.getFileName());\r
currFile = mStorageManager.getFileById(currFile.getParentId());\r
}\r
- mDirectories.insert(OCFile.PATH_SEPARATOR, 0);\r
+ mDirectories.add(OCFile.PATH_SEPARATOR);\r
\r
// Inflate and set the layout view\r
setContentView(R.layout.files); \r
- mFileList = (FileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList);\r
+ mFileList = (OCFileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList);\r
mDualPane = (findViewById(R.id.file_details_container) != null);\r
if (mDualPane && getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG) == null) {\r
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();\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, getString(R.string.upload_chooser_title)),\r
- ACTION_SELECT_FILE);\r
+ showDialog(DIALOG_CHOOSE_UPLOAD_SOURCE);\r
break;\r
}\r
case R.id.action_settings: {\r
* Called, when the user selected something for uploading\r
*/\r
public void onActivityResult(int requestCode, int resultCode, Intent data) {\r
- if (requestCode == ACTION_SELECT_FILE) {\r
- if (resultCode == RESULT_OK) {\r
- String filepath = null;\r
- try {\r
- Uri selectedImageUri = data.getData();\r
- \r
- String filemanagerstring = selectedImageUri.getPath();\r
- String selectedImagePath = getPath(selectedImageUri);\r
- \r
- if (selectedImagePath != null)\r
- filepath = selectedImagePath;\r
- else\r
- filepath = filemanagerstring;\r
- \r
- } catch (Exception e) {\r
- Log.e("FileDisplay", "Unexpected exception when trying to read the result of Intent.ACTION_GET_CONTENT", e);\r
- e.printStackTrace();\r
- \r
- } finally {\r
- if (filepath == null) {\r
- Log.e("FileDisplay", "Couldnt resolve path to file");\r
- Toast t = Toast.makeText(this, getString(R.string.filedisplay_unexpected_bad_get_content), Toast.LENGTH_LONG);\r
- t.show();\r
- return;\r
- }\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 += OCFile.PATH_SEPARATOR + mDirectories.getItem(j);\r
- }\r
- if (!remotepath.endsWith(OCFile.PATH_SEPARATOR))\r
- remotepath += OCFile.PATH_SEPARATOR;\r
- remotepath += new File(filepath).getName();\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
+ if (requestCode == ACTION_SELECT_CONTENT_FROM_APPS && resultCode == RESULT_OK) {\r
+ requestSimpleUpload(data);\r
+ \r
+ } else if (requestCode == ACTION_SELECT_MULTIPLE_FILES && resultCode == RESULT_OK) {\r
+ requestMultipleUpload(data);\r
+ \r
+ }\r
+ }\r
+\r
+ private void requestMultipleUpload(Intent data) {\r
+ String[] filePaths = data.getStringArrayExtra(UploadFilesActivity.EXTRA_CHOSEN_FILES);\r
+ if (filePaths != null) {\r
+ String[] remotePaths = new String[filePaths.length];\r
+ String remotePathBase = "";\r
+ for (int j = mDirectories.getCount() - 2; j >= 0; --j) {\r
+ remotePathBase += OCFile.PATH_SEPARATOR + mDirectories.getItem(j);\r
+ }\r
+ if (!remotePathBase.endsWith(OCFile.PATH_SEPARATOR))\r
+ remotePathBase += OCFile.PATH_SEPARATOR;\r
+ for (int j = 0; j< remotePaths.length; j++) {\r
+ remotePaths[j] = remotePathBase + (new File(filePaths[j])).getName();\r
}\r
+\r
+ Intent i = new Intent(this, FileUploader.class);\r
+ i.putExtra(FileUploader.KEY_ACCOUNT, AccountUtils.getCurrentOwnCloudAccount(this));\r
+ i.putExtra(FileUploader.KEY_LOCAL_FILE, filePaths);\r
+ i.putExtra(FileUploader.KEY_REMOTE_FILE, remotePaths);\r
+ i.putExtra(FileUploader.KEY_UPLOAD_TYPE, FileUploader.UPLOAD_MULTIPLE_FILES);\r
+ startService(i);\r
+ \r
+ } else {\r
+ Log.d("FileDisplay", "User clicked on 'Update' with no selection");\r
+ Toast t = Toast.makeText(this, getString(R.string.filedisplay_no_file_selected), Toast.LENGTH_LONG);\r
+ t.show();\r
+ return;\r
+ }\r
+ }\r
+\r
+\r
+ private void requestSimpleUpload(Intent data) {\r
+ String filepath = null;\r
+ try {\r
+ Uri selectedImageUri = data.getData();\r
+\r
+ String filemanagerstring = selectedImageUri.getPath();\r
+ String selectedImagePath = getPath(selectedImageUri);\r
+\r
+ if (selectedImagePath != null)\r
+ filepath = selectedImagePath;\r
+ else\r
+ filepath = filemanagerstring;\r
+ \r
+ } catch (Exception e) {\r
+ Log.e("FileDisplay", "Unexpected exception when trying to read the result of Intent.ACTION_GET_CONTENT", e);\r
+ e.printStackTrace();\r
\r
- }/* dvelasco: WIP - not working as expected ... yet :)\r
- else if (requestCode == ACTION_CREATE_FIRST_ACCOUNT) {\r
- if (resultCode != RESULT_OK) {\r
- finish(); // the user cancelled the AuthenticatorActivity\r
+ } finally {\r
+ if (filepath == null) {\r
+ Log.e("FileDisplay", "Couldnt resolve path to file");\r
+ Toast t = Toast.makeText(this, getString(R.string.filedisplay_unexpected_bad_get_content), Toast.LENGTH_LONG);\r
+ t.show();\r
+ return;\r
}\r
- }*/\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 += OCFile.PATH_SEPARATOR + mDirectories.getItem(j);\r
+ }\r
+ if (!remotepath.endsWith(OCFile.PATH_SEPARATOR))\r
+ remotepath += OCFile.PATH_SEPARATOR;\r
+ remotepath += new File(filepath).getName();\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
@Override\r
public void onBackPressed() {\r
if (mDirectories.getCount() <= 1) {\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
\r
// Create directory\r
path += directoryName + OCFile.PATH_SEPARATOR;\r
- Thread thread = new Thread(new DirectoryCreator(path, a, new Handler()));\r
+ Thread thread = new Thread(new DirectoryCreator(path, AccountUtils.getCurrentOwnCloudAccount(FileDisplayActivity.this), new Handler()));\r
thread.start();\r
\r
dialog.dismiss();\r
dialog = working_dialog;\r
break;\r
}\r
+ case DIALOG_CHOOSE_UPLOAD_SOURCE: {\r
+ final String [] items = { getString(R.string.actionbar_upload_files), \r
+ getString(R.string.actionbar_upload_from_apps) }; \r
+ builder = new AlertDialog.Builder(this);\r
+ builder.setTitle(R.string.actionbar_upload);\r
+ builder.setItems(items, new DialogInterface.OnClickListener() {\r
+ public void onClick(DialogInterface dialog, int item) {\r
+ if (item == 0) {\r
+ //if (!mDualPane) { \r
+ Intent action = new Intent(FileDisplayActivity.this, UploadFilesActivity.class);\r
+ startActivityForResult(action, ACTION_SELECT_MULTIPLE_FILES);\r
+ //} else {\r
+ // TODO create and handle new fragment LocalFileListFragment\r
+ //}\r
+ } else if (item == 1) {\r
+ Intent action = new Intent(Intent.ACTION_GET_CONTENT);\r
+ action = action.setType("*/*")\r
+ .addCategory(Intent.CATEGORY_OPENABLE);\r
+ startActivityForResult(\r
+ Intent.createChooser(action, getString(R.string.upload_chooser_title)),\r
+ ACTION_SELECT_CONTENT_FROM_APPS);\r
+ }\r
+ }\r
+ });\r
+ dialog = builder.create();\r
+ break;\r
+ }\r
default:\r
dialog = null;\r
}\r
|| fillBlankRoot ) {\r
if (!fillBlankRoot) \r
mCurrentDir = getStorageManager().getFileByPath(synchFolderRemotePath);\r
- FileListFragment fileListFragment = (FileListFragment) getSupportFragmentManager()\r
+ OCFileListFragment fileListFragment = (OCFileListFragment) getSupportFragmentManager()\r
.findFragmentById(R.id.fileList);\r
if (fileListFragment != null) {\r
fileListFragment.listDirectory(mCurrentDir); \r
parentDir.equals(mCurrentDir)\r
)\r
) {\r
- FileListFragment fileListFragment = (FileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList);\r
+ OCFileListFragment fileListFragment = (OCFileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList);\r
if (fileListFragment != null) { \r
fileListFragment.listDirectory();\r
}\r
\r
if (accountName.equals(AccountUtils.getCurrentOwnCloudAccount(context).name) &&\r
mCurrentDir != null && mCurrentDir.getFileId() == mStorageManager.getFileByPath(downloadedRemotePath).getParentId()) {\r
- FileListFragment fileListFragment = (FileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList);\r
+ OCFileListFragment fileListFragment = (OCFileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList);\r
if (fileListFragment != null) { \r
fileListFragment.listDirectory();\r
}\r
*/\r
@Override\r
public void onFileStateChanged() {\r
- FileListFragment fileListFragment = (FileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList);\r
+ OCFileListFragment fileListFragment = (OCFileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList);\r
if (fileListFragment != null) { \r
fileListFragment.listDirectory();\r
}\r
--- /dev/null
+/* ownCloud Android client application
+ * Copyright (C) 2011 Bartek Przybylski
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * 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.File;
+
+import android.content.Intent;
+import android.os.Bundle;
+import android.os.Environment;
+import android.util.Log;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.view.ViewGroup;
+import android.widget.ArrayAdapter;
+import android.widget.Button;
+import android.widget.TextView;
+
+import com.actionbarsherlock.app.ActionBar;
+import com.actionbarsherlock.app.ActionBar.OnNavigationListener;
+import com.actionbarsherlock.app.SherlockFragmentActivity;
+import com.actionbarsherlock.view.MenuItem;
+import com.owncloud.android.ui.fragment.LocalFileListFragment;
+
+import com.owncloud.android.R;
+
+/**
+ * Displays local files and let the user choose what of them wants to upload
+ * to the current ownCloud account
+ *
+ * @author David A. Velasco
+ *
+ */
+
+public class UploadFilesActivity extends SherlockFragmentActivity implements
+ LocalFileListFragment.ContainerActivity, OnNavigationListener, OnClickListener {
+
+ private ArrayAdapter<String> mDirectories;
+ private File mCurrentDir = null;
+ private LocalFileListFragment mFileListFragment;
+ private Button mCancelBtn;
+ private Button mUploadBtn;
+
+ public static final String EXTRA_DIRECTORY_PATH = "com.owncloud.android.Directory";
+ public static final String EXTRA_CHOSEN_FILES = "com.owncloud.android.ChosenFiles";
+
+ private static final String TAG = "UploadFilesActivity";
+
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ Log.d(TAG, "onCreate() start");
+ super.onCreate(savedInstanceState);
+
+ if(savedInstanceState != null) {
+ mCurrentDir = new File(savedInstanceState.getString(UploadFilesActivity.EXTRA_DIRECTORY_PATH));
+ } else {
+ mCurrentDir = Environment.getExternalStorageDirectory();
+ }
+
+ /// USER INTERFACE
+
+ // Drop-down navigation
+ mDirectories = new CustomArrayAdapter<String>(this, R.layout.sherlock_spinner_dropdown_item);
+ File currDir = mCurrentDir;
+ while(currDir != null && currDir.getParentFile() != null) {
+ mDirectories.add(currDir.getName());
+ currDir = currDir.getParentFile();
+ }
+ mDirectories.add(File.separator);
+
+ // Inflate and set the layout view
+ setContentView(R.layout.upload_files_layout);
+ mFileListFragment = (LocalFileListFragment) getSupportFragmentManager().findFragmentById(R.id.local_files_list);
+
+ // Set input controllers
+ mCancelBtn = (Button) findViewById(R.id.upload_files_btn_cancel);
+ mCancelBtn.setOnClickListener(this);
+ mUploadBtn = (Button) findViewById(R.id.upload_files_btn_upload);
+ mUploadBtn.setOnClickListener(this);
+
+ // Action bar setup
+ ActionBar actionBar = getSupportActionBar();
+ actionBar.setHomeButtonEnabled(true); // mandatory since Android ICS, according to the official documentation
+ actionBar.setDisplayHomeAsUpEnabled(mCurrentDir != null && mCurrentDir.getName() != null);
+ actionBar.setDisplayShowTitleEnabled(false);
+ actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
+ actionBar.setListNavigationCallbacks(mDirectories, this);
+
+ Log.d(TAG, "onCreate() end");
+ }
+
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ boolean retval = true;
+ switch (item.getItemId()) {
+ case android.R.id.home: {
+ if(mCurrentDir != null && mCurrentDir.getParentFile() != null){
+ onBackPressed();
+ }
+ break;
+ }
+ default:
+ retval = false;
+ }
+ return retval;
+ }
+
+
+ @Override
+ public boolean onNavigationItemSelected(int itemPosition, long itemId) {
+ int i = itemPosition;
+ while (i-- != 0) {
+ onBackPressed();
+ }
+ // the next operation triggers a new call to this method, but it's necessary to
+ // ensure that the name exposed in the action bar is the current directory when the
+ // user selected it in the navigation list
+ if (itemPosition != 0)
+ getSupportActionBar().setSelectedNavigationItem(0);
+ return true;
+ }
+
+
+ @Override
+ public void onBackPressed() {
+ if (mDirectories.getCount() <= 1) {
+ finish();
+ return;
+ }
+ popDirname();
+ mFileListFragment.onNavigateUp();
+ mCurrentDir = mFileListFragment.getCurrentDirectory();
+
+ if(mCurrentDir.getParentFile() == null){
+ ActionBar actionBar = getSupportActionBar();
+ actionBar.setDisplayHomeAsUpEnabled(false);
+ }
+ }
+
+
+ @Override
+ protected void onSaveInstanceState(Bundle outState) {
+ // responsibility of restore is preferred in onCreate() before than in onRestoreInstanceState when there are Fragments involved
+ Log.d(TAG, "onSaveInstanceState() start");
+ super.onSaveInstanceState(outState);
+ outState.putString(UploadFilesActivity.EXTRA_DIRECTORY_PATH, mCurrentDir.getAbsolutePath());
+ Log.d(TAG, "onSaveInstanceState() end");
+ }
+
+ @Override
+ protected void onResume() {
+ Log.d(TAG, "onResume() start");
+ super.onResume();
+
+ // List current directory
+ mFileListFragment.listDirectory(mCurrentDir);
+
+ Log.d(TAG, "onResume() end");
+ }
+
+
+ /**
+ * Pushes a directory to the drop down list
+ * @param directory to push
+ * @throws IllegalArgumentException If the {@link File#isDirectory()} returns false.
+ */
+ public void pushDirname(File directory) {
+ if(!directory.isDirectory()){
+ throw new IllegalArgumentException("Only directories may be pushed!");
+ }
+ mDirectories.insert(directory.getName(), 0);
+ mCurrentDir = directory;
+ }
+
+ /**
+ * Pops a directory name from the drop down list
+ * @return True, unless the stack is empty
+ */
+ public boolean popDirname() {
+ mDirectories.remove(mDirectories.getItem(0));
+ return !mDirectories.isEmpty();
+ }
+
+
+ // Custom array adapter to override text colors
+ private class CustomArrayAdapter<T> extends ArrayAdapter<T> {
+
+ public CustomArrayAdapter(UploadFilesActivity ctx, int view) {
+ super(ctx, view);
+ }
+
+ public View getView(int position, View convertView, ViewGroup parent) {
+ View v = super.getView(position, convertView, parent);
+
+ ((TextView) v).setTextColor(getResources().getColorStateList(
+ android.R.color.white));
+ return v;
+ }
+
+ public View getDropDownView(int position, View convertView,
+ ViewGroup parent) {
+ View v = super.getDropDownView(position, convertView, parent);
+
+ ((TextView) v).setTextColor(getResources().getColorStateList(
+ android.R.color.white));
+
+ return v;
+ }
+
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void onDirectoryClick(File directory) {
+ pushDirname(directory);
+ ActionBar actionBar = getSupportActionBar();
+ actionBar.setDisplayHomeAsUpEnabled(true);
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void onFileClick(File file) {
+ // nothing to do
+ }
+
+
+ /**
+ * Performs corresponding action when user presses 'Cancel' or 'Upload' button
+ */
+ @Override
+ public void onClick(View v) {
+ if (v.getId() == R.id.upload_files_btn_cancel) {
+ setResult(RESULT_CANCELED);
+ finish();
+
+ } else if (v.getId() == R.id.upload_files_btn_upload) {
+ Intent data = new Intent();
+ data.putExtra(EXTRA_CHOSEN_FILES, mFileListFragment.getCheckedFilePaths());
+ setResult(RESULT_OK, data);
+ finish();
+ }
+ }
+
+}
import android.view.LayoutInflater;\r
import android.view.View;\r
import android.view.ViewGroup;\r
+import android.widget.CheckedTextView;\r
import android.widget.ImageView;\r
import android.widget.ListAdapter;\r
+import android.widget.ListView;\r
import android.widget.TextView;\r
\r
/**\r
} else {\r
localStateView.setVisibility(View.INVISIBLE);\r
}\r
- /*\r
- ImageView down = (ImageView) view.findViewById(R.id.imageView2);\r
- ImageView downloading = (ImageView) view.findViewById(R.id.imageView4);\r
- ImageView uploading = (ImageView) view.findViewById(R.id.imageView5);\r
- if (FileDownloader.isDownloading(mAccount, file.getRemotePath())) {\r
- down.setVisibility(View.INVISIBLE);\r
- downloading.setVisibility(View.VISIBLE);\r
- uploading.setVisibility(View.INVISIBLE);\r
- } else if (FileUploader.isUploading(mAccount, file.getRemotePath())) {\r
- down.setVisibility(View.INVISIBLE);\r
- downloading.setVisibility(View.INVISIBLE);\r
- uploading.setVisibility(View.VISIBLE);\r
- } else if (file.isDown()) {\r
- down.setVisibility(View.VISIBLE);\r
- downloading.setVisibility(View.INVISIBLE);\r
- uploading.setVisibility(View.INVISIBLE);\r
- } else {\r
- down.setVisibility(View.INVISIBLE);\r
- downloading.setVisibility(View.INVISIBLE);\r
- uploading.setVisibility(View.INVISIBLE);\r
- }*/\r
- \r
+\r
+ \r
+ TextView fileSizeV = (TextView) view.findViewById(R.id.file_size);\r
+ TextView lastModV = (TextView) view.findViewById(R.id.last_mod);\r
+ ImageView checkBoxV = (ImageView) view.findViewById(R.id.custom_checkbox);\r
+ \r
if (!file.isDirectory()) {\r
- view.findViewById(R.id.file_size).setVisibility(View.VISIBLE);\r
- view.findViewById(R.id.last_mod).setVisibility(View.VISIBLE);\r
- ((TextView)view.findViewById(R.id.file_size)).setText(DisplayUtils.bytesToHumanReadable(file.getFileLength()));\r
- ((TextView)view.findViewById(R.id.last_mod)).setText(DisplayUtils.unixTimeToHumanReadable(file.getModificationTimestamp()));\r
+ fileSizeV.setVisibility(View.VISIBLE);\r
+ fileSizeV.setText(DisplayUtils.bytesToHumanReadable(file.getFileLength()));\r
+ lastModV.setVisibility(View.VISIBLE);\r
+ lastModV.setText(DisplayUtils.unixTimeToHumanReadable(file.getModificationTimestamp()));\r
// this if-else is needed even thoe fav icon is visible by default\r
// because android reuses views in listview\r
if (!file.keepInSync()) {\r
} else {\r
view.findViewById(R.id.imageView3).setVisibility(View.VISIBLE);\r
}\r
+ \r
+ ListView parentList = (ListView)parent;\r
+ if (parentList.getChoiceMode() == ListView.CHOICE_MODE_NONE) { \r
+ checkBoxV.setVisibility(View.GONE);\r
+ } else {\r
+ checkBoxV.setVisibility(View.VISIBLE);\r
+ if (parentList.isItemChecked(position)) {\r
+ checkBoxV.setImageResource(android.R.drawable.checkbox_on_background);\r
+ } else {\r
+ checkBoxV.setImageResource(android.R.drawable.checkbox_off_background);\r
+ }\r
+ }\r
+ \r
} else {\r
- view.findViewById(R.id.file_size).setVisibility(View.GONE);\r
- view.findViewById(R.id.last_mod).setVisibility(View.GONE);\r
+ fileSizeV.setVisibility(View.GONE);\r
+ lastModV.setVisibility(View.GONE);\r
+ checkBoxV.setVisibility(View.GONE);\r
view.findViewById(R.id.imageView3).setVisibility(View.GONE);\r
}\r
}\r
--- /dev/null
+/* ownCloud Android client application
+ * Copyright (C) 2011 Bartek Przybylski
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * 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.adapter;
+
+import java.io.File;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import com.owncloud.android.DisplayUtils;
+import com.owncloud.android.R;
+
+import android.content.Context;
+import android.database.DataSetObserver;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.BaseAdapter;
+import android.widget.ImageView;
+import android.widget.ListAdapter;
+import android.widget.ListView;
+import android.widget.TextView;
+
+/**
+ * This Adapter populates a ListView with all files and directories contained
+ * in a local directory
+ *
+ * @author David A. Velasco
+ *
+ */
+public class LocalFileListAdapter extends BaseAdapter implements ListAdapter {
+
+ private Context mContext;
+ private File mDirectory;
+ private File[] mFiles = null;
+ private Set<DataSetObserver> mObservers = new HashSet<DataSetObserver>();
+
+ public LocalFileListAdapter(File directory, Context context) {
+ mContext = context;
+ swapDirectory(directory);
+ }
+
+ @Override
+ public boolean areAllItemsEnabled() {
+ return true;
+ }
+
+ @Override
+ public boolean isEnabled(int position) {
+ return true;
+ }
+
+ @Override
+ public int getCount() {
+ return mFiles != null ? mFiles.length : 0;
+ }
+
+ @Override
+ public Object getItem(int position) {
+ if (mFiles == null || mFiles.length <= position)
+ return null;
+ return mFiles[position];
+ }
+
+ @Override
+ public long getItemId(int position) {
+ return mFiles != null && mFiles.length <= position ? position : -1;
+ }
+
+ @Override
+ public int getItemViewType(int position) {
+ return 0;
+ }
+
+ @Override
+ public View getView(int position, View convertView, ViewGroup parent) {
+ View view = convertView;
+ if (view == null) {
+ LayoutInflater inflator = (LayoutInflater) mContext
+ .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+ view = inflator.inflate(R.layout.list_layout, null);
+ }
+ if (mFiles != null && mFiles.length > position) {
+ File file = mFiles[position];
+
+ TextView fileName = (TextView) view.findViewById(R.id.Filename);
+ String name = file.getName();
+ fileName.setText(name);
+
+ ImageView fileIcon = (ImageView) view.findViewById(R.id.imageView1);
+ if (!file.isDirectory()) {
+ fileIcon.setImageResource(R.drawable.file);
+ } else {
+ fileIcon.setImageResource(R.drawable.ic_menu_archive);
+ }
+
+ TextView fileSizeV = (TextView) view.findViewById(R.id.file_size);
+ TextView lastModV = (TextView) view.findViewById(R.id.last_mod);
+ ImageView checkBoxV = (ImageView) view.findViewById(R.id.custom_checkbox);
+ if (!file.isDirectory()) {
+ fileSizeV.setVisibility(View.VISIBLE);
+ fileSizeV.setText(DisplayUtils.bytesToHumanReadable(file.length()));
+ lastModV.setVisibility(View.VISIBLE);
+ lastModV.setText(DisplayUtils.unixTimeToHumanReadable(file.lastModified()));
+ ListView parentList = (ListView)parent;
+ if (parentList.getChoiceMode() == ListView.CHOICE_MODE_NONE) {
+ checkBoxV.setVisibility(View.GONE);
+ } else {
+ checkBoxV.setVisibility(View.VISIBLE);
+ if (parentList.isItemChecked(position)) {
+ checkBoxV.setImageResource(android.R.drawable.checkbox_on_background);
+ } else {
+ checkBoxV.setImageResource(android.R.drawable.checkbox_off_background);
+ }
+ }
+
+ } else {
+ fileSizeV.setVisibility(View.GONE);
+ lastModV.setVisibility(View.GONE);
+ checkBoxV.setVisibility(View.GONE);
+ }
+
+ view.findViewById(R.id.imageView2).setVisibility(View.INVISIBLE); // not GONE; the alignment changes; ugly way to keep it
+ view.findViewById(R.id.imageView3).setVisibility(View.GONE);
+ }
+
+ return view;
+ }
+
+ @Override
+ public int getViewTypeCount() {
+ return 1;
+ }
+
+ @Override
+ public boolean hasStableIds() {
+ return false;
+ }
+
+ @Override
+ public boolean isEmpty() {
+ return (mFiles == null || mFiles.length == 0);
+ }
+
+ @Override
+ public void registerDataSetObserver(DataSetObserver observer) {
+ mObservers.add(observer);
+ }
+
+ @Override
+ public void unregisterDataSetObserver(DataSetObserver observer) {
+ mObservers.remove(observer);
+ }
+
+ /**
+ * Change the adapted directory for a new one
+ * @param directory New file to adapt.
+ */
+ public void swapDirectory(File directory) {
+ mDirectory = directory;
+ mFiles = mDirectory.listFiles();
+ if (mFiles != null) {
+ Arrays.sort(mFiles, new Comparator<File>() {
+ @Override
+ public int compare(File lhs, File rhs) {
+ if (lhs.isDirectory() && !rhs.isDirectory()) {
+ return -1;
+ } else if (!lhs.isDirectory() && rhs.isDirectory()) {
+ return 1;
+ }
+ return compareNames(lhs, rhs);
+ }
+
+ private int compareNames(File lhs, File rhs) {
+ return lhs.getName().toLowerCase().compareTo(rhs.getName().toLowerCase());
+ }
+
+ });
+ }
+ Iterator<DataSetObserver> it = mObservers.iterator();
+ while (it.hasNext()) {
+ it.next().onChanged();
+ }
+ }
+}
+++ /dev/null
-/* ownCloud Android client application\r
- * Copyright (C) 2011 Bartek Przybylski\r
- *\r
- * This program is free software: you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation, either version 3 of the License, or\r
- * (at your option) any later version.\r
- *\r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program. If not, see <http://www.gnu.org/licenses/>.\r
- *\r
- */\r
-package com.owncloud.android.ui.fragment;\r
-\r
-import java.util.Vector;\r
-\r
-import com.owncloud.android.datamodel.DataStorageManager;\r
-import com.owncloud.android.datamodel.OCFile;\r
-import com.owncloud.android.ui.FragmentListView;\r
-import com.owncloud.android.ui.adapter.FileListListAdapter;\r
-\r
-import android.app.Activity;\r
-import android.os.Bundle;\r
-import android.util.Log;\r
-import android.view.LayoutInflater;\r
-import android.view.View;\r
-import android.view.ViewGroup;\r
-import android.widget.AdapterView;\r
-import com.owncloud.android.R;\r
-\r
-/**\r
- * A Fragment that lists all files and folders in a given path.\r
- * \r
- * @author Bartek Przybylski\r
- * \r
- */\r
-public class FileListFragment extends FragmentListView {\r
- private static final String TAG = "FileListFragment";\r
- \r
- private FileListFragment.ContainerActivity mContainerActivity;\r
- \r
- private OCFile mFile = null;\r
- private FileListListAdapter mAdapter;\r
-\r
- \r
- /**\r
- * {@inheritDoc}\r
- */\r
- @Override\r
- public void onAttach(Activity activity) {\r
- super.onAttach(activity);\r
- try {\r
- mContainerActivity = (ContainerActivity) activity;\r
- } catch (ClassCastException e) {\r
- throw new ClassCastException(activity.toString() + " must implement FileListFragment.ContainerActivity");\r
- }\r
- }\r
- \r
- \r
- @Override\r
- public View onCreateView(LayoutInflater inflater, ViewGroup container,\r
- Bundle savedInstanceState) {\r
- Log.i(getClass().toString(), "onCreateView() start");\r
- super.onCreateView(inflater, container, savedInstanceState);\r
- getListView().setDivider(getResources().getDrawable(R.drawable.uploader_list_separator));\r
- getListView().setDividerHeight(1);\r
- \r
- Log.i(getClass().toString(), "onCreateView() end");\r
- return getListView();\r
- } \r
-\r
-\r
- @Override\r
- public void onActivityCreated(Bundle savedInstanceState) {\r
- Log.i(getClass().toString(), "onActivityCreated() start");\r
- \r
- super.onCreate(savedInstanceState);\r
- //mAdapter = new FileListListAdapter();\r
- \r
- Log.i(getClass().toString(), "onActivityCreated() stop");\r
- }\r
- \r
- \r
- @Override\r
- public void onItemClick(AdapterView<?> l, View v, int position, long id) {\r
- OCFile file = (OCFile) mAdapter.getItem(position);\r
- if (file != null) {\r
- /// Click on a directory\r
- if (file.getMimetype().equals("DIR")) {\r
- // just local updates\r
- mFile = file;\r
- listDirectory(file);\r
- // any other updates are let to the container Activity\r
- mContainerActivity.onDirectoryClick(file);\r
- \r
- } else { /// Click on a file\r
- mContainerActivity.onFileClick(file);\r
- }\r
- \r
- } else {\r
- Log.d(TAG, "Null object in ListAdapter!!");\r
- }\r
- \r
- }\r
-\r
- /**\r
- * Call this, when the user presses the up button\r
- */\r
- public void onNavigateUp() {\r
- OCFile parentDir = null;\r
- \r
- if(mFile != null){\r
- DataStorageManager storageManager = mContainerActivity.getStorageManager();\r
- parentDir = storageManager.getFileById(mFile.getParentId());\r
- mFile = parentDir;\r
- }\r
- listDirectory(parentDir);\r
- }\r
-\r
- /**\r
- * Use this to query the {@link OCFile} that is currently\r
- * being displayed by this fragment\r
- * @return The currently viewed OCFile\r
- */\r
- public OCFile getCurrentFile(){\r
- return mFile;\r
- }\r
- \r
- /**\r
- * Calls {@link FileListFragment#listDirectory(OCFile)} with a null parameter\r
- */\r
- public void listDirectory(){\r
- listDirectory(null);\r
- }\r
- \r
- /**\r
- * Lists the given directory on the view. When the input parameter is null,\r
- * it will either refresh the last known directory, or list the root\r
- * if there never was a directory.\r
- * \r
- * @param directory File to be listed\r
- */\r
- public void listDirectory(OCFile directory) {\r
- \r
- DataStorageManager storageManager = mContainerActivity.getStorageManager();\r
-\r
- // Check input parameters for null\r
- if(directory == null){\r
- if(mFile != null){\r
- directory = mFile;\r
- } else {\r
- directory = storageManager.getFileByPath("/");\r
- if (directory == null) return; // no files, wait for sync\r
- }\r
- }\r
- \r
- \r
- // If that's not a directory -> List its parent\r
- if(!directory.isDirectory()){\r
- Log.w(TAG, "You see, that is not a directory -> " + directory.toString());\r
- directory = storageManager.getFileById(directory.getParentId());\r
- }\r
-\r
- mFile = directory;\r
- \r
- mAdapter = new FileListListAdapter(directory, storageManager, getActivity());\r
- setListAdapter(mAdapter);\r
- }\r
- \r
- \r
- \r
- /**\r
- * Interface to implement by any Activity that includes some instance of FileListFragment\r
- * \r
- * @author David A. Velasco\r
- */\r
- public interface ContainerActivity {\r
-\r
- /**\r
- * Callback method invoked when a directory is clicked by the user on the files list\r
- * \r
- * @param file\r
- */\r
- public void onDirectoryClick(OCFile file);\r
- \r
- /**\r
- * Callback method invoked when a file (non directory) is clicked by the user on the files list\r
- * \r
- * @param file\r
- */\r
- public void onFileClick(OCFile file);\r
-\r
- /**\r
- * Getter for the current DataStorageManager in the container activity\r
- */\r
- public DataStorageManager getStorageManager();\r
- \r
- }\r
-\r
-}\r
--- /dev/null
+/* ownCloud Android client application
+ * Copyright (C) 2011 Bartek Przybylski
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * 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.fragment;
+
+import java.io.File;
+
+import com.owncloud.android.ui.FragmentListView;
+import com.owncloud.android.ui.adapter.LocalFileListAdapter;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.os.Environment;
+import android.util.Log;
+import android.util.SparseBooleanArray;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.AdapterView;
+import android.widget.ListView;
+
+import com.owncloud.android.R;
+
+/**
+ * A Fragment that lists all files and folders in a given LOCAL path.
+ *
+ * @author David A. Velasco
+ *
+ */
+public class LocalFileListFragment extends FragmentListView {
+ private static final String TAG = "LocalFileListFragment";
+
+ /** Reference to the Activity which this fragment is attached to. For callbacks */
+ private LocalFileListFragment.ContainerActivity mContainerActivity;
+
+ /** Directory to show */
+ private File mDirectory = null;
+
+ /** Adapter to connect the data from the directory with the View object */
+ private LocalFileListAdapter mAdapter = null;
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void onAttach(Activity activity) {
+ super.onAttach(activity);
+ try {
+ mContainerActivity = (ContainerActivity) activity;
+ } catch (ClassCastException e) {
+ throw new ClassCastException(activity.toString() + " must implement " + LocalFileListFragment.ContainerActivity.class.getCanonicalName());
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
+ Log.i(getClass().toString(), "onCreateView() start");
+ super.onCreateView(inflater, container, savedInstanceState);
+ getListView().setDivider(getResources().getDrawable(R.drawable.uploader_list_separator));
+ getListView().setDividerHeight(1);
+ getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
+
+ if (savedInstanceState != null) {
+ // TODO recover previous state; or maybe in onActivityCreated
+ }
+
+ Log.i(getClass().toString(), "onCreateView() end");
+ return getListView();
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void onActivityCreated(Bundle savedInstanceState) {
+ Log.i(getClass().toString(), "onActivityCreated() start");
+
+ super.onCreate(savedInstanceState);
+
+ Log.i(getClass().toString(), "onActivityCreated() stop");
+ }
+
+
+ /**
+ * Checks the file clicked over. Browses inside if it is a directory. Notifies the container activity in any case.
+ */
+ @Override
+ public void onItemClick(AdapterView<?> l, View v, int position, long id) {
+ File file = (File) mAdapter.getItem(position);
+ if (file != null) {
+ /// Click on a directory
+ if (file.isDirectory()) {
+ // just local updates
+ listDirectory(file);
+ // notify the click to container Activity
+ mContainerActivity.onDirectoryClick(file);
+
+ } else { /// Click on a file
+ // notify the change to the container Activity
+ mContainerActivity.onFileClick(file);
+ }
+
+ } else {
+ Log.w(TAG, "Null object in ListAdapter!!");
+ }
+ }
+
+
+ /**
+ * Call this, when the user presses the up button
+ */
+ public void onNavigateUp() {
+ File parentDir = null;
+ if(mDirectory != null) {
+ parentDir = mDirectory.getParentFile(); // can be null
+ }
+ listDirectory(parentDir);
+ }
+
+
+ /**
+ * Use this to query the {@link File} object for the directory
+ * that is currently being displayed by this fragment
+ *
+ * @return File The currently displayed directory
+ */
+ public File getCurrentDirectory(){
+ return mDirectory;
+ }
+
+
+ /**
+ * Calls {@link LocalFileListFragment#listDirectory(File)} with a null parameter
+ * to refresh the current directory.
+ */
+ public void listDirectory(){
+ listDirectory(null);
+ }
+
+
+ /**
+ * Lists the given directory on the view. When the input parameter is null,
+ * it will either refresh the last known directory, or list the root
+ * if there never was a directory.
+ *
+ * @param directory Directory to be listed
+ */
+ public void listDirectory(File directory) {
+
+ // Check input parameters for null
+ if(directory == null) {
+ if(mDirectory != null){
+ directory = mDirectory;
+ } else {
+ directory = Environment.getExternalStorageDirectory(); // TODO be careful with the state of the storage; could not be available
+ if (directory == null) return; // no files, wait for sync
+ }
+ }
+
+
+ // if that's not a directory -> List its parent
+ if(!directory.isDirectory()){
+ Log.w(TAG, "You see, that is not a directory -> " + directory.toString());
+ directory = directory.getParentFile();
+ }
+
+ mDirectory = directory;
+ if (mAdapter == null) {
+ mAdapter = new LocalFileListAdapter(mDirectory, getActivity());
+ setListAdapter(mAdapter);
+ } else {
+ mList.clearChoices(); // by now, only files in the same directory will be kept as selected
+ mAdapter.swapDirectory(mDirectory);
+ }
+
+ }
+
+
+ /**
+ * Returns the fule paths to the files checked by the user
+ *
+ * @return File paths to the files checked by the user.
+ */
+ public String[] getCheckedFilePaths() {
+ String [] result = null;
+ SparseBooleanArray positions = mList.getCheckedItemPositions();
+ if (positions.size() > 0) {
+ Log.d(TAG, "Returning " + positions.size() + " selected files");
+ result = new String[positions.size()];
+ for (int i=0; i<positions.size(); i++) {
+ result[i] = ((File) mList.getItemAtPosition(positions.keyAt(i))).getAbsolutePath();
+ }
+ }
+ return result;
+ }
+
+
+ /**
+ * Interface to implement by any Activity that includes some instance of LocalFileListFragment
+ *
+ * @author David A. Velasco
+ */
+ public interface ContainerActivity {
+
+ /**
+ * Callback method invoked when a directory is clicked by the user on the files list
+ *
+ * @param file
+ */
+ public void onDirectoryClick(File directory);
+
+ /**
+ * Callback method invoked when a file (non directory) is clicked by the user on the files list
+ *
+ * @param file
+ */
+ public void onFileClick(File file);
+
+ }
+
+
+}
--- /dev/null
+/* ownCloud Android client application
+ * Copyright (C) 2011 Bartek Przybylski
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * 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.fragment;
+
+import com.owncloud.android.datamodel.DataStorageManager;
+import com.owncloud.android.datamodel.OCFile;
+import com.owncloud.android.ui.FragmentListView;
+import com.owncloud.android.ui.adapter.FileListListAdapter;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.AdapterView;
+import com.owncloud.android.R;
+
+/**
+ * A Fragment that lists all files and folders in a given path.
+ *
+ * @author Bartek Przybylski
+ *
+ */
+public class OCFileListFragment extends FragmentListView {
+ private static final String TAG = "FileListFragment";
+
+ private OCFileListFragment.ContainerActivity mContainerActivity;
+
+ private OCFile mFile = null;
+ private FileListListAdapter mAdapter;
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void onAttach(Activity activity) {
+ super.onAttach(activity);
+ try {
+ mContainerActivity = (ContainerActivity) activity;
+ } catch (ClassCastException e) {
+ throw new ClassCastException(activity.toString() + " must implement FileListFragment.ContainerActivity");
+ }
+ }
+
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ Log.i(getClass().toString(), "onCreateView() start");
+ super.onCreateView(inflater, container, savedInstanceState);
+ getListView().setDivider(getResources().getDrawable(R.drawable.uploader_list_separator));
+ getListView().setDividerHeight(1);
+
+ Log.i(getClass().toString(), "onCreateView() end");
+ return getListView();
+ }
+
+
+ @Override
+ public void onActivityCreated(Bundle savedInstanceState) {
+ Log.i(getClass().toString(), "onActivityCreated() start");
+
+ super.onCreate(savedInstanceState);
+ //mAdapter = new FileListListAdapter();
+
+ Log.i(getClass().toString(), "onActivityCreated() stop");
+ }
+
+
+ @Override
+ public void onItemClick(AdapterView<?> l, View v, int position, long id) {
+ OCFile file = (OCFile) mAdapter.getItem(position);
+ if (file != null) {
+ /// Click on a directory
+ if (file.getMimetype().equals("DIR")) {
+ // just local updates
+ mFile = file;
+ listDirectory(file);
+ // any other updates are let to the container Activity
+ mContainerActivity.onDirectoryClick(file);
+
+ } else { /// Click on a file
+ mContainerActivity.onFileClick(file);
+ }
+
+ } else {
+ Log.d(TAG, "Null object in ListAdapter!!");
+ }
+
+ }
+
+ /**
+ * Call this, when the user presses the up button
+ */
+ public void onNavigateUp() {
+ OCFile parentDir = null;
+
+ if(mFile != null){
+ DataStorageManager storageManager = mContainerActivity.getStorageManager();
+ parentDir = storageManager.getFileById(mFile.getParentId());
+ mFile = parentDir;
+ }
+ listDirectory(parentDir);
+ }
+
+ /**
+ * Use this to query the {@link OCFile} that is currently
+ * being displayed by this fragment
+ * @return The currently viewed OCFile
+ */
+ public OCFile getCurrentFile(){
+ return mFile;
+ }
+
+ /**
+ * Calls {@link OCFileListFragment#listDirectory(OCFile)} with a null parameter
+ */
+ public void listDirectory(){
+ listDirectory(null);
+ }
+
+ /**
+ * Lists the given directory on the view. When the input parameter is null,
+ * it will either refresh the last known directory, or list the root
+ * if there never was a directory.
+ *
+ * @param directory File to be listed
+ */
+ public void listDirectory(OCFile directory) {
+
+ DataStorageManager storageManager = mContainerActivity.getStorageManager();
+
+ // Check input parameters for null
+ if(directory == null){
+ if(mFile != null){
+ directory = mFile;
+ } else {
+ directory = storageManager.getFileByPath("/");
+ if (directory == null) return; // no files, wait for sync
+ }
+ }
+
+
+ // If that's not a directory -> List its parent
+ if(!directory.isDirectory()){
+ Log.w(TAG, "You see, that is not a directory -> " + directory.toString());
+ directory = storageManager.getFileById(directory.getParentId());
+ }
+
+ mFile = directory;
+
+ mAdapter = new FileListListAdapter(directory, storageManager, getActivity());
+ setListAdapter(mAdapter);
+ }
+
+
+
+ /**
+ * Interface to implement by any Activity that includes some instance of FileListFragment
+ *
+ * @author David A. Velasco
+ */
+ public interface ContainerActivity {
+
+ /**
+ * Callback method invoked when a directory is clicked by the user on the files list
+ *
+ * @param file
+ */
+ public void onDirectoryClick(OCFile file);
+
+ /**
+ * Callback method invoked when a file (non directory) is clicked by the user on the files list
+ *
+ * @param file
+ */
+ public void onFileClick(OCFile file);
+
+ /**
+ * Getter for the current DataStorageManager in the container activity
+ */
+ public DataStorageManager getStorageManager();
+
+ }
+
+}