|
@@ -20,6 +20,10 @@ package com.owncloud.android.ui.fragment;
|
|
import java.io.File;
|
|
import java.io.File;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
+import com.owncloud.android.Log_OC;
|
|
|
|
+import com.owncloud.android.R;
|
|
|
|
+import com.owncloud.android.ui.adapter.LocalFileListAdapter;
|
|
|
|
+
|
|
import android.app.Activity;
|
|
import android.app.Activity;
|
|
import android.os.Bundle;
|
|
import android.os.Bundle;
|
|
import android.os.Environment;
|
|
import android.os.Environment;
|
|
@@ -31,9 +35,6 @@ import android.widget.AdapterView;
|
|
import android.widget.ImageView;
|
|
import android.widget.ImageView;
|
|
import android.widget.ListView;
|
|
import android.widget.ListView;
|
|
|
|
|
|
-import com.owncloud.android.Log_OC;
|
|
|
|
-import com.owncloud.android.R;
|
|
|
|
-import com.owncloud.android.ui.adapter.LocalFileListAdapter;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
* A Fragment that lists all files and folders in a given LOCAL path.
|
|
* A Fragment that lists all files and folders in a given LOCAL path.
|
|
@@ -43,19 +44,17 @@ import com.owncloud.android.ui.adapter.LocalFileListAdapter;
|
|
*/
|
|
*/
|
|
public class LocalFileListFragment extends ExtendedListFragment {
|
|
public class LocalFileListFragment extends ExtendedListFragment {
|
|
private static final String TAG = "LocalFileListFragment";
|
|
private static final String TAG = "LocalFileListFragment";
|
|
-
|
|
|
|
- /**
|
|
|
|
- * Reference to the Activity which this fragment is attached to. For
|
|
|
|
- * callbacks
|
|
|
|
- */
|
|
|
|
|
|
+
|
|
|
|
+ /** Reference to the Activity which this fragment is attached to. For callbacks */
|
|
private LocalFileListFragment.ContainerActivity mContainerActivity;
|
|
private LocalFileListFragment.ContainerActivity mContainerActivity;
|
|
-
|
|
|
|
|
|
+
|
|
/** Directory to show */
|
|
/** Directory to show */
|
|
private File mDirectory = null;
|
|
private File mDirectory = null;
|
|
-
|
|
|
|
|
|
+
|
|
/** Adapter to connect the data from the directory with the View object */
|
|
/** Adapter to connect the data from the directory with the View object */
|
|
private LocalFileListAdapter mAdapter = null;
|
|
private LocalFileListAdapter mAdapter = null;
|
|
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* {@inheritDoc}
|
|
* {@inheritDoc}
|
|
*/
|
|
*/
|
|
@@ -65,11 +64,11 @@ public class LocalFileListFragment extends ExtendedListFragment {
|
|
try {
|
|
try {
|
|
mContainerActivity = (ContainerActivity) activity;
|
|
mContainerActivity = (ContainerActivity) activity;
|
|
} catch (ClassCastException e) {
|
|
} catch (ClassCastException e) {
|
|
- throw new ClassCastException(activity.toString() + " must implement "
|
|
|
|
- + LocalFileListFragment.ContainerActivity.class.getSimpleName());
|
|
|
|
|
|
+ throw new ClassCastException(activity.toString() + " must implement " + LocalFileListFragment.ContainerActivity.class.getSimpleName());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* {@inheritDoc}
|
|
* {@inheritDoc}
|
|
*/
|
|
*/
|
|
@@ -80,7 +79,8 @@ public class LocalFileListFragment extends ExtendedListFragment {
|
|
getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
|
|
getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
|
|
Log_OC.i(TAG, "onCreateView() end");
|
|
Log_OC.i(TAG, "onCreateView() end");
|
|
return v;
|
|
return v;
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
|
|
/**
|
|
/**
|
|
* {@inheritDoc}
|
|
* {@inheritDoc}
|
|
@@ -88,30 +88,30 @@ public class LocalFileListFragment extends ExtendedListFragment {
|
|
@Override
|
|
@Override
|
|
public void onActivityCreated(Bundle savedInstanceState) {
|
|
public void onActivityCreated(Bundle savedInstanceState) {
|
|
Log_OC.i(TAG, "onActivityCreated() start");
|
|
Log_OC.i(TAG, "onActivityCreated() start");
|
|
-
|
|
|
|
|
|
+
|
|
super.onCreate(savedInstanceState);
|
|
super.onCreate(savedInstanceState);
|
|
mAdapter = new LocalFileListAdapter(mContainerActivity.getInitialDirectory(), getActivity());
|
|
mAdapter = new LocalFileListAdapter(mContainerActivity.getInitialDirectory(), getActivity());
|
|
setListAdapter(mAdapter);
|
|
setListAdapter(mAdapter);
|
|
-
|
|
|
|
|
|
+
|
|
Log_OC.i(TAG, "onActivityCreated() stop");
|
|
Log_OC.i(TAG, "onActivityCreated() stop");
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+
|
|
/**
|
|
/**
|
|
- * Checks the file clicked over. Browses inside if it is a directory.
|
|
|
|
- * Notifies the container activity in any case.
|
|
|
|
|
|
+ * Checks the file clicked over. Browses inside if it is a directory. Notifies the container activity in any case.
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
public void onItemClick(AdapterView<?> l, View v, int position, long id) {
|
|
public void onItemClick(AdapterView<?> l, View v, int position, long id) {
|
|
- File file = (File) mAdapter.getItem(position);
|
|
|
|
|
|
+ File file = (File) mAdapter.getItem(position);
|
|
if (file != null) {
|
|
if (file != null) {
|
|
- // / Click on a directory
|
|
|
|
|
|
+ /// Click on a directory
|
|
if (file.isDirectory()) {
|
|
if (file.isDirectory()) {
|
|
// just local updates
|
|
// just local updates
|
|
listDirectory(file);
|
|
listDirectory(file);
|
|
// notify the click to container Activity
|
|
// notify the click to container Activity
|
|
mContainerActivity.onDirectoryClick(file);
|
|
mContainerActivity.onDirectoryClick(file);
|
|
-
|
|
|
|
- } else { // / Click on a file
|
|
|
|
|
|
+
|
|
|
|
+ } else { /// Click on a file
|
|
ImageView checkBoxV = (ImageView) v.findViewById(R.id.custom_checkbox);
|
|
ImageView checkBoxV = (ImageView) v.findViewById(R.id.custom_checkbox);
|
|
if (checkBoxV != null) {
|
|
if (checkBoxV != null) {
|
|
if (getListView().isItemChecked(position)) {
|
|
if (getListView().isItemChecked(position)) {
|
|
@@ -123,90 +123,84 @@ public class LocalFileListFragment extends ExtendedListFragment {
|
|
// notify the change to the container Activity
|
|
// notify the change to the container Activity
|
|
mContainerActivity.onFileClick(file);
|
|
mContainerActivity.onFileClick(file);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
} else {
|
|
} else {
|
|
Log_OC.w(TAG, "Null object in ListAdapter!!");
|
|
Log_OC.w(TAG, "Null object in ListAdapter!!");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Call this, when the user presses the up button
|
|
* Call this, when the user presses the up button
|
|
*/
|
|
*/
|
|
public void onNavigateUp() {
|
|
public void onNavigateUp() {
|
|
File parentDir = null;
|
|
File parentDir = null;
|
|
- if (mDirectory != null) {
|
|
|
|
- parentDir = mDirectory.getParentFile(); // can be null
|
|
|
|
|
|
+ if(mDirectory != null) {
|
|
|
|
+ parentDir = mDirectory.getParentFile(); // can be null
|
|
}
|
|
}
|
|
listDirectory(parentDir);
|
|
listDirectory(parentDir);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
- * Use this to query the {@link File} object for the directory that is
|
|
|
|
- * currently being displayed by this fragment
|
|
|
|
|
|
+ * 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
|
|
|
|
|
|
+ * @return File The currently displayed directory
|
|
*/
|
|
*/
|
|
- public File getCurrentDirectory() {
|
|
|
|
|
|
+ public File getCurrentDirectory(){
|
|
return mDirectory;
|
|
return mDirectory;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+
|
|
/**
|
|
/**
|
|
- * Calls {@link LocalFileListFragment#listDirectory(File)} with a null
|
|
|
|
- * parameter to refresh the current directory.
|
|
|
|
|
|
+ * Calls {@link LocalFileListFragment#listDirectory(File)} with a null parameter
|
|
|
|
+ * to refresh the current directory.
|
|
*/
|
|
*/
|
|
- public void listDirectory() {
|
|
|
|
|
|
+ public void listDirectory(){
|
|
listDirectory(null);
|
|
listDirectory(null);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Lists the given directory on the view. When the input parameter is null,
|
|
* Lists the given directory on the view. When the input parameter is null,
|
|
- * it will either refresh the last known directory. list the root if there
|
|
|
|
- * never was a directory.
|
|
|
|
|
|
+ * it will either refresh the last known directory. list the root
|
|
|
|
+ * if there never was a directory.
|
|
*
|
|
*
|
|
- * @param directory Directory to be listed
|
|
|
|
|
|
+ * @param directory Directory to be listed
|
|
*/
|
|
*/
|
|
public void listDirectory(File directory) {
|
|
public void listDirectory(File directory) {
|
|
-
|
|
|
|
|
|
+
|
|
// Check input parameters for null
|
|
// Check input parameters for null
|
|
- if (directory == null) {
|
|
|
|
- if (mDirectory != null) {
|
|
|
|
|
|
+ if(directory == null) {
|
|
|
|
+ if(mDirectory != null){
|
|
directory = mDirectory;
|
|
directory = mDirectory;
|
|
} else {
|
|
} else {
|
|
- directory = Environment.getExternalStorageDirectory(); // TODO
|
|
|
|
- // be
|
|
|
|
- // careful
|
|
|
|
- // with
|
|
|
|
- // the
|
|
|
|
- // state
|
|
|
|
- // of the
|
|
|
|
- // storage;
|
|
|
|
- // could
|
|
|
|
- // not be
|
|
|
|
- // available
|
|
|
|
- if (directory == null)
|
|
|
|
- return; // no files to show
|
|
|
|
|
|
+ directory = Environment.getExternalStorageDirectory(); // TODO be careful with the state of the storage; could not be available
|
|
|
|
+ if (directory == null) return; // no files to show
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+
|
|
// if that's not a directory -> List its parent
|
|
// if that's not a directory -> List its parent
|
|
- if (!directory.isDirectory()) {
|
|
|
|
|
|
+ if(!directory.isDirectory()){
|
|
Log_OC.w(TAG, "You see, that is not a directory -> " + directory.toString());
|
|
Log_OC.w(TAG, "You see, that is not a directory -> " + directory.toString());
|
|
directory = directory.getParentFile();
|
|
directory = directory.getParentFile();
|
|
}
|
|
}
|
|
|
|
|
|
- mList.clearChoices(); // by now, only files in the same directory will
|
|
|
|
- // be kept as selected
|
|
|
|
|
|
+ mList.clearChoices(); // by now, only files in the same directory will be kept as selected
|
|
mAdapter.swapDirectory(directory);
|
|
mAdapter.swapDirectory(directory);
|
|
if (mDirectory == null || !mDirectory.equals(directory)) {
|
|
if (mDirectory == null || !mDirectory.equals(directory)) {
|
|
mList.setSelectionFromTop(0, 0);
|
|
mList.setSelectionFromTop(0, 0);
|
|
}
|
|
}
|
|
mDirectory = directory;
|
|
mDirectory = directory;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
|
|
/**
|
|
/**
|
|
* Returns the fule paths to the files checked by the user
|
|
* Returns the fule paths to the files checked by the user
|
|
*
|
|
*
|
|
- * @return File paths to the files checked by the user.
|
|
|
|
|
|
+ * @return File paths to the files checked by the user.
|
|
*/
|
|
*/
|
|
public String[] getCheckedFilePaths() {
|
|
public String[] getCheckedFilePaths() {
|
|
ArrayList<String> result = new ArrayList<String>();
|
|
ArrayList<String> result = new ArrayList<String>();
|
|
@@ -223,38 +217,37 @@ public class LocalFileListFragment extends ExtendedListFragment {
|
|
return result.toArray(new String[result.size()]);
|
|
return result.toArray(new String[result.size()]);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
- * Interface to implement by any Activity that includes some instance of
|
|
|
|
- * LocalFileListFragment
|
|
|
|
|
|
+ * Interface to implement by any Activity that includes some instance of LocalFileListFragment
|
|
*
|
|
*
|
|
* @author David A. Velasco
|
|
* @author David A. Velasco
|
|
*/
|
|
*/
|
|
public interface ContainerActivity {
|
|
public interface ContainerActivity {
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Callback method invoked when a directory is clicked by the user on
|
|
|
|
- * the files list
|
|
|
|
- *
|
|
|
|
|
|
+ * Callback method invoked when a directory is clicked by the user on the files list
|
|
|
|
+ *
|
|
* @param file
|
|
* @param file
|
|
*/
|
|
*/
|
|
public void onDirectoryClick(File directory);
|
|
public void onDirectoryClick(File directory);
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
- * Callback method invoked when a file (non directory) is clicked by the
|
|
|
|
- * user on the files list
|
|
|
|
- *
|
|
|
|
|
|
+ * Callback method invoked when a file (non directory) is clicked by the user on the files list
|
|
|
|
+ *
|
|
* @param file
|
|
* @param file
|
|
*/
|
|
*/
|
|
public void onFileClick(File file);
|
|
public void onFileClick(File file);
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+
|
|
/**
|
|
/**
|
|
- * Callback method invoked when the parent activity is fully created to
|
|
|
|
- * get the directory to list firstly.
|
|
|
|
|
|
+ * Callback method invoked when the parent activity is fully created to get the directory to list firstly.
|
|
*
|
|
*
|
|
- * @return Directory to list firstly. Can be NULL.
|
|
|
|
|
|
+ * @return Directory to list firstly. Can be NULL.
|
|
*/
|
|
*/
|
|
public File getInitialDirectory();
|
|
public File getInitialDirectory();
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
}
|
|
}
|