Răsfoiți Sursa

Tablet fixes. Goal is to get tapping on a file to display its details.
Does not work yet - WIP. Also code optimization: Make
FileDetailFragment less complex by passing in a OCFile directly instead
of reconstructing it.

Lennart Rosam 13 ani în urmă
părinte
comite
020d2885ce

+ 25 - 10
res/layout-large-land/files.xml

@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
-<!-- 
+<!--
   ownCloud Android client application
 
   Copyright (C) 2011  Bartek Przybylski
@@ -14,8 +14,8 @@
   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/>.
- -->
+  along with this program.  If not, see <http://www.gnu.org/licenses/>.

+-->
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
@@ -26,15 +26,30 @@
         android:layout_width="0dp"
         android:layout_height="wrap_content"
         android:layout_weight="1" >
+
+        <fragment
+            android:id="@+id/fileList"
+            android:layout_width="fill_parent"
+            android:layout_height="fill_parent"
+            class="eu.alefzero.owncloud.ui.fragment.FileListFragment" >
+
+            <!-- Preview: layout=@layout/list_layout -->
+        </fragment>
     </LinearLayout>
 
-    <fragment
-        android:id="@+id/fileDetail"
+    <LinearLayout android:id="@+id/file_details_container"
         android:layout_width="0dp"
-        android:layout_height="fill_parent"
-        android:layout_weight="2"
-        class="eu.alefzero.owncloud.ui.fragment.FileDetail" >
-        <!-- Preview: layout=@layout/file_details -->
-    </fragment>
+        android:layout_height="wrap_content"
+        android:layout_weight="2" >
+
+        <fragment
+            android:id="@+id/fileDetail"
+            android:layout_width="fill_parent"
+            android:layout_height="fill_parent"
+            class="eu.alefzero.owncloud.ui.fragment.FileDetailFragment" >
+
+            <!-- Preview: layout=@layout/file_details_empty -->
+        </fragment>
+    </LinearLayout>
 
 </LinearLayout>

+ 104 - 39
src/eu/alefzero/owncloud/datamodel/OCFile.java

@@ -20,8 +20,23 @@ package eu.alefzero.owncloud.datamodel;
 
 import java.io.File;
 
-public class OCFile {
+import android.os.Parcel;
+import android.os.Parcelable;
 
+public class OCFile implements Parcelable {
+
+	public static final Parcelable.Creator<OCFile> CREATOR = new Parcelable.Creator<OCFile>() {
+		@Override
+		public OCFile createFromParcel(Parcel source) {
+			return new OCFile(source);
+		}
+
+		@Override
+		public OCFile[] newArray(int size) {
+			return new OCFile[size];
+		}
+	};
+	
 	private long id;
 	private long parentId;
 	private long length;
@@ -35,13 +50,30 @@ public class OCFile {
 	/**
 	 * Create new {@link OCFile} with given path
 	 * 
-	 * @param path The remote path of the file
+	 * @param path
+	 *            The remote path of the file
 	 */
 	public OCFile(String path) {
-	  resetData();
-	  needsUpdating = false;
+		resetData();
+		needsUpdating = false;
 		remotePath = path;
 	}
+	
+	/**
+	 * Reconstruct from parcel
+	 * @param source The source parcel
+	 */
+	private OCFile(Parcel source){
+		id = source.readLong();
+		parentId = source.readLong();
+		length = source.readLong();
+		creationTimestamp = source.readLong();
+		modifiedTimestamp = source.readLong();
+		remotePath = source.readString();
+		localPath = source.readString();
+		mimeType = source.readString();
+		needsUpdating = source.readInt() == 0;
+	}
 
 	/**
 	 * Gets the ID of the file
@@ -172,8 +204,10 @@ public class OCFile {
 	 * Adds a file to this directory. If this file is not a directory, an
 	 * exception gets thrown.
 	 * 
-	 * @param file to add
-	 * @throws IllegalStateException if you try to add a something and this is not a directory
+	 * @param file
+	 *            to add
+	 * @throws IllegalStateException
+	 *             if you try to add a something and this is not a directory
 	 */
 	public void addFile(OCFile file) throws IllegalStateException {
 		if (isDirectory()) {
@@ -181,7 +215,8 @@ public class OCFile {
 			needsUpdating = true;
 			return;
 		}
-		throw new IllegalStateException("This is not a directory where you can add stuff to!");
+		throw new IllegalStateException(
+				"This is not a directory where you can add stuff to!");
 	}
 
 	/**
@@ -200,57 +235,87 @@ public class OCFile {
 
 	/**
 	 * Sets the ID of the file
-	 * @param file_id to set
+	 * 
+	 * @param file_id
+	 *            to set
 	 */
 	public void setFileId(long file_id) {
-	  id = file_id;
+		id = file_id;
 	}
-	
+
 	/**
-	 * Sets the Mime-Type of the 
-	 * @param mimetype to set
+	 * Sets the Mime-Type of the
+	 * 
+	 * @param mimetype
+	 *            to set
 	 */
 	public void setMimetype(String mimetype) {
-	  mimeType = mimetype;
+		mimeType = mimetype;
 	}
-	
+
 	/**
 	 * Sets the ID of the parent folder
-	 * @param parent_id to set
+	 * 
+	 * @param parent_id
+	 *            to set
 	 */
 	public void setParentId(long parent_id) {
-	  parentId = parent_id;
+		parentId = parent_id;
 	}
-	
+
 	/**
 	 * Sets the file size in bytes
-	 * @param file_len to set
+	 * 
+	 * @param file_len
+	 *            to set
 	 */
 	public void setFileLength(long file_len) {
-	  length = file_len;
+		length = file_len;
 	}
-	
+
 	/**
 	 * Returns the size of the file in bytes
+	 * 
 	 * @return The filesize in bytes
 	 */
-  public long getFileLength() {
-    return length;
-  }
-  
-  /**
-   * Returns the ID of the parent Folder
-   * @return The ID
-   */
-  public long getParentId() {
-    return parentId;
-  }
-  
-  /**
-   * Check, if this file needs updating
-   * @return
-   */
-  public boolean needsUpdatingWhileSaving() {
-    return needsUpdating;
-  }
+	public long getFileLength() {
+		return length;
+	}
+
+	/**
+	 * Returns the ID of the parent Folder
+	 * 
+	 * @return The ID
+	 */
+	public long getParentId() {
+		return parentId;
+	}
+
+	/**
+	 * Check, if this file needs updating
+	 * 
+	 * @return
+	 */
+	public boolean needsUpdatingWhileSaving() {
+		return needsUpdating;
+	}
+
+	@Override
+	public int describeContents() {
+		return this.hashCode();
+	}
+
+	@Override
+	public void writeToParcel(Parcel dest, int flags) {
+		dest.writeLong(id);
+		dest.writeLong(parentId);
+		dest.writeLong(length);
+		dest.writeLong(creationTimestamp);
+		dest.writeLong(modifiedTimestamp);
+		dest.writeString(remotePath);
+		dest.writeString(localPath);
+		dest.writeString(mimeType);
+		dest.writeInt(needsUpdating ? 0 : 1 ); // No writeBoolean method exists - yay :D
+	}
+	
 }

+ 181 - 128
src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java

@@ -17,15 +17,13 @@
  */
 package eu.alefzero.owncloud.ui.fragment;
 
-import android.accounts.Account;
+import android.app.FragmentTransaction;
 import android.content.BroadcastReceiver;
 import android.content.Context;
 import android.content.Intent;
 import android.content.IntentFilter;
-import android.database.Cursor;
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
-import android.net.Uri;
 import android.os.Bundle;
 import android.view.LayoutInflater;
 import android.view.View;
@@ -41,134 +39,189 @@ import com.actionbarsherlock.app.SherlockFragment;
 import eu.alefzero.owncloud.DisplayUtils;
 import eu.alefzero.owncloud.FileDownloader;
 import eu.alefzero.owncloud.R;
-import eu.alefzero.owncloud.db.ProviderMeta.ProviderTableMeta;
+import eu.alefzero.owncloud.datamodel.OCFile;
 
 /**
  * This Fragment is used to display the details about a file.
+ * 
  * @author Bartek Przybylski
- *
+ * 
  */
-public class FileDetailFragment extends SherlockFragment implements OnClickListener {
-  
-  private Intent mIntent;
-  private View mView;
-  private DownloadFinishReceiver dfr;
-  
-  @Override
-  public void onResume() {
-    super.onResume();
-    dfr = new DownloadFinishReceiver();
-    IntentFilter filter = new IntentFilter(FileDownloader.DOWNLOAD_FINISH_MESSAGE);
-    getActivity().registerReceiver(dfr, filter);
-  }
-  
-  @Override
-  public void onPause() {
-    super.onPause();
-    getActivity().unregisterReceiver(dfr);
-    dfr = null;
-  }
-  
-  public void setStuff(Intent intent) {
-    mIntent = intent;
-    setStuff(getView());
-  }
-  
-  private void setStuff(View view) {
-    mView = view;
-    String id = mIntent.getStringExtra("FILE_ID");
-    Account account = mIntent.getParcelableExtra("ACCOUNT");
-    String account_name = account.name;
-    Cursor c = getActivity().managedQuery(
-        Uri.withAppendedPath(ProviderTableMeta.CONTENT_URI_FILE, id),
-        null,
-        ProviderTableMeta.FILE_ACCOUNT_OWNER+"=?",
-        new String[]{account_name},
-        null);
-    c.moveToFirst();
-
-    // Retrieve details from DB
-    String filename = c.getString(c.getColumnIndex(ProviderTableMeta.FILE_NAME));
-    String mimetype = c.getString(c.getColumnIndex(ProviderTableMeta.FILE_CONTENT_TYPE));
-    String path = c.getString(c.getColumnIndex(ProviderTableMeta.FILE_STORAGE_PATH));
-    long filesize = c.getLong(c.getColumnIndex(ProviderTableMeta.FILE_CONTENT_LENGTH));
-
-    // set file details
-    setFilename(filename);
-    setFiletype(DisplayUtils.convertMIMEtoPrettyPrint(mimetype));
-    setFilesize(filesize);
-    
-    // set file preview if available and possible
-    View w = view.findViewById(R.id.videoView1);
-    w.setVisibility(View.INVISIBLE);
-    if (path == null) {
-      ImageView v = (ImageView) getView().findViewById(R.id.imageView2);
-      v.setImageResource(R.drawable.download);
-      v.setOnClickListener(this);
-    } else {
-      if (mimetype.startsWith("image/")) {
-        ImageView v = (ImageView) view.findViewById(R.id.imageView2);
-        Bitmap bmp = BitmapFactory.decodeFile(path);
-        v.setImageBitmap(bmp);
-      } else if (mimetype.startsWith("video/")) {
-        VideoView v = (VideoView) view.findViewById(R.id.videoView1);
-        v.setVisibility(View.VISIBLE);
-        v.setVideoPath(path);
-        v.start();
-      }
-    }
-  }
-
-  @Override
-  public View onCreateView(LayoutInflater inflater, ViewGroup container,
-      Bundle savedInstanceState) {
-    View v = null;
-    
-    if (getActivity().getIntent() != null && getActivity().getIntent().getStringExtra("FILE_ID") != null) {
-    	v = inflater.inflate(R.layout.file_details_fragment, container, false);
-    	mIntent = getActivity().getIntent();
-    	setStuff(v);
-    } else {
-    	v = inflater.inflate(R.layout.file_details_empty, container, false);
-    }
-    return v;
-  }
-
-  @Override
-  public View getView() {
-    return mView == null ? super.getView() : mView;
-  };
-  
-  public void setFilename(String filename) {
-    TextView tv = (TextView) getView().findViewById(R.id.textView1);
-    if (tv != null) tv.setText(filename);
-  }
-  
-  public void setFiletype(String mimetype) {
-    TextView tv = (TextView) getView().findViewById(R.id.textView2);
-    if (tv != null) tv.setText(mimetype);
-  }
-  
-  public void setFilesize(long filesize) {
-    TextView tv = (TextView) getView().findViewById(R.id.textView3);
-    if (tv != null) tv.setText(DisplayUtils.bitsToHumanReadable(filesize));
-  }
-
-  @Override
-  public void onClick(View v) {
-    Toast.makeText(getActivity(), "Downloading", Toast.LENGTH_LONG).show();
-    Intent i = new Intent(getActivity(), FileDownloader.class);
-    i.putExtra(FileDownloader.EXTRA_ACCOUNT, mIntent.getParcelableExtra("ACCOUNT"));
-    i.putExtra(FileDownloader.EXTRA_FILE_PATH, mIntent.getStringExtra("FULL_PATH"));
-    getActivity().startService(i);
-  }
-  
-  private class DownloadFinishReceiver extends BroadcastReceiver {
-    @Override
-    public void onReceive(Context context, Intent intent) {
-      setStuff(getView());
-    }
-    
-  }
-  
+public class FileDetailFragment extends SherlockFragment implements
+		OnClickListener {
+
+	public static final String FILE = "FILE";
+
+	private Intent mIntent;
+	private View mView;
+	private DownloadFinishReceiver mDownloadFinishReceiver;
+	private OCFile mFile;
+
+	private int mLayout;
+	private boolean mEmptyLayout;
+
+	/**
+	 * Default constructor. When inflated by android -> display empty layout
+	 */
+	public FileDetailFragment() {
+		mLayout = R.layout.file_details_empty;
+		mEmptyLayout = true;
+	}
+
+	/**
+	 * Custom construtor. Use with a {@link FragmentTransaction}.
+	 * The intent has to contain {@link FileDetailFragment#FILE} with an OCFile
+	 * and also {@link FileDownloader#EXTRA_ACCOUNT} with the account.
+	 * 
+	 * @param nonEmptyFragment
+	 *            True, to enable file detail rendering
+	 */
+	public FileDetailFragment(Intent intent) {
+		mLayout = R.layout.file_details_fragment;
+		mIntent = intent;
+		mEmptyLayout = false;
+	}
+
+	@Override
+	public void onResume() {
+		super.onResume();
+		mDownloadFinishReceiver = new DownloadFinishReceiver();
+		IntentFilter filter = new IntentFilter(
+				FileDownloader.DOWNLOAD_FINISH_MESSAGE);
+		getActivity().registerReceiver(mDownloadFinishReceiver, filter);
+	}
+
+	@Override
+	public void onPause() {
+		super.onPause();
+		getActivity().unregisterReceiver(mDownloadFinishReceiver);
+		mDownloadFinishReceiver = null;
+	}
+
+	/**
+	 * Use this method to signal this Activity that it shall update its view.
+	 * 
+	 * @param intent
+	 *            The {@link Intent} that contains extra information about this
+	 *            file The intent needs to have these extras:
+	 *            <p>
+	 * 
+	 *            {@link FileDetailFragment#FILE}: An {@link OCFile}
+	 *            {@link FileDownloader#EXTRA_ACCOUNT}: The Account that file
+	 *            belongs to (required for downloading)
+	 */
+	public void updateFileDetails(Intent intent) {
+		mIntent = intent;
+		updateFileDetails();
+	}
+
+	private void updateFileDetails() {
+		mFile = mIntent.getParcelableExtra(FILE);
+
+		if (mFile != null) {
+			// set file details
+			setFilename(mFile.getFileName());
+			setFiletype(DisplayUtils.convertMIMEtoPrettyPrint(mFile
+					.getMimetype()));
+			setFilesize(mFile.getFileLength());
+
+			// set file preview if available and possible
+			VideoView videoView = (VideoView) mView
+					.findViewById(R.id.videoView1);
+			videoView.setVisibility(View.INVISIBLE);
+			if (mFile.getPath() == null) {
+				ImageView imageView = (ImageView) getView().findViewById(
+						R.id.imageView2);
+				imageView.setImageResource(R.drawable.download);
+				imageView.setOnClickListener(this);
+			} else {
+				if (mFile.getMimetype().startsWith("image/")) {
+					ImageView imageView = (ImageView) mView
+							.findViewById(R.id.imageView2);
+					Bitmap bmp = BitmapFactory.decodeFile(mFile.getPath());
+					imageView.setImageBitmap(bmp);
+				} else if (mFile.getMimetype().startsWith("video/")) {
+					videoView.setVisibility(View.VISIBLE);
+					videoView.setVideoPath(mFile.getPath());
+					videoView.start();
+				}
+			}
+		}
+	}
+
+	@Override
+	public View onCreateView(LayoutInflater inflater, ViewGroup container,
+			Bundle savedInstanceState) {
+		View view = null;
+
+		view = inflater.inflate(mLayout, container, false);
+		mIntent = getActivity().getIntent();
+		mView = view;
+
+		// make sure we are not using the empty layout
+		if (mEmptyLayout == false) {
+			updateFileDetails();
+		}
+
+		return view;
+	}
+
+	@Override
+	public View getView() {
+		return mView == null ? super.getView() : mView;
+	};
+
+	private void setFilename(String filename) {
+		TextView tv = (TextView) getView().findViewById(R.id.textView1);
+		if (tv != null)
+			tv.setText(filename);
+	}
+
+	private void setFiletype(String mimetype) {
+		TextView tv = (TextView) getView().findViewById(R.id.textView2);
+		if (tv != null)
+			tv.setText(mimetype);
+	}
+
+	private void setFilesize(long filesize) {
+		TextView tv = (TextView) getView().findViewById(R.id.textView3);
+		if (tv != null)
+			tv.setText(DisplayUtils.bitsToHumanReadable(filesize));
+	}
+
+	/**
+	 * Use this to check if the correct layout is loaded. When android
+	 * instanciates this class using the default constructor, the layout will be
+	 * empty.
+	 * 
+	 * Once a user touches a file for the first time, you must instanciate a new
+	 * Fragment with the new FileDetailFragment(true) to inflate the actual
+	 * details
+	 * 
+	 * @return If the layout is empty, this method will return true, otherwise
+	 *         false
+	 */
+	public boolean isEmptyLayout() {
+		return mEmptyLayout;
+	}
+
+	@Override
+	public void onClick(View v) {
+		Toast.makeText(getActivity(), "Downloading", Toast.LENGTH_LONG).show();
+		Intent i = new Intent(getActivity(), FileDownloader.class);
+		i.putExtra(FileDownloader.EXTRA_ACCOUNT,
+				mIntent.getParcelableExtra(FileDownloader.EXTRA_ACCOUNT));
+		i.putExtra(FileDownloader.EXTRA_FILE_PATH,
+				mIntent.getStringExtra(FileDownloader.EXTRA_FILE_PATH));
+		getActivity().startService(i);
+	}
+
+	private class DownloadFinishReceiver extends BroadcastReceiver {
+		@Override
+		public void onReceive(Context context, Intent intent) {
+			updateFileDetails();
+		}
+
+	}
+
 }

+ 159 - 122
src/eu/alefzero/owncloud/ui/fragment/FileListFragment.java

@@ -25,11 +25,13 @@ import android.content.ClipData;
 import android.content.ClipDescription;
 import android.content.Intent;
 import android.os.Bundle;
+import android.support.v4.app.FragmentTransaction;
 import android.util.Log;
 import android.view.View;
 import android.widget.AdapterView;
 import android.widget.Toast;
 import eu.alefzero.owncloud.AccountUtils;
+import eu.alefzero.owncloud.FileDownloader;
 import eu.alefzero.owncloud.R;
 import eu.alefzero.owncloud.datamodel.DataStorageManager;
 import eu.alefzero.owncloud.datamodel.FileDataStorageManager;
@@ -41,129 +43,164 @@ import eu.alefzero.owncloud.ui.adapter.FileListListAdapter;
 
 /**
  * A Fragment that lists all files and folders in a given path.
+ * 
  * @author Bartek Przybylski
- *
+ * 
  */
 public class FileListFragment extends FragmentListView {
-  private Account mAccount;
-  private Stack<String> mDirNames;
-  private Vector<OCFile> mFiles;
-  private DataStorageManager mStorageManager;
-
-  public FileListFragment() {
-    mDirNames = new Stack<String>();
-  }
-  
-  @Override
-  public void onCreate(Bundle savedInstanceState) {
-    super.onCreate(savedInstanceState);
-
-    mAccount = AccountUtils.getCurrentOwnCloudAccount(getActivity());
-    getListView().setDivider(getResources().getDrawable(R.drawable.uploader_list_separator));
-    getListView().setDividerHeight(1);
-    
-    populateFileList();
-  }
-  
-  @Override
-  public void onItemClick(AdapterView<?> l, View v, int position, long id) {
-    if (mFiles.size() <= position) {
-      throw new IndexOutOfBoundsException("Incorrect item selected");
-    }
-    OCFile file = mFiles.get(position);
-    String id_ = String.valueOf(file.getFileId());
-    if (file.getMimetype().equals("DIR")) {
-        String dirname = file.getFileName();
-
-        mDirNames.push(dirname);
-        ((FileDisplayActivity)getActivity()).pushPath(dirname);
-        
-        populateFileList();
-        return;
-    }
-    Intent i = new Intent(getActivity(), FileDetailActivity.class);
-    i.putExtra("FILE_NAME", file.getFileName());
-    i.putExtra("FULL_PATH", file.getPath());
-    i.putExtra("FILE_ID", id_);
-    Log.e("ASD", mAccount+"");
-    i.putExtra("ACCOUNT", mAccount);
-    FileDetailFragment fd = (FileDetailFragment) getFragmentManager().findFragmentById(R.id.fileDetail);
-    if (fd != null) {
-      fd.setStuff(i);
-    } else {
-      startActivity(i);
-    }
-  }
-  
-  @Override
-  public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
-    ClipData.Item item = new ClipData.Item("ASD");
-    ClipDescription cd = new ClipDescription("ASD", new String[]{ClipDescription.MIMETYPE_TEXT_PLAIN});
-    ClipData dragData = new ClipData(cd, item);
-    arg1.startDrag(dragData, new View.DragShadowBuilder(arg0.getChildAt(arg2)), null, 0);
-    return true;
-  }
-  
-  /**
-   * Call this, when the user presses the up button
-   */
-  public void onNavigateUp() {
-    mDirNames.pop();
-    populateFileList();
-  }
-
-  /**
-   * Lists the directory
-   */
-  public void populateFileList() {
-    String s = "/";
-    for (String a : mDirNames)
-      s+= a + "/";
-    Log.e("ASD", s);
-
-    mStorageManager = new FileDataStorageManager(mAccount, getActivity().getContentResolver());
-    OCFile file = mStorageManager.getFileByPath(s);
-    mFiles = mStorageManager.getDirectoryContent(file);
-    if (mFiles == null || mFiles.size() == 0) {
-      Toast.makeText(getActivity(), "There are no files here", Toast.LENGTH_LONG).show();
-    }
-    setListAdapter(new FileListListAdapter(file, mStorageManager, getActivity()));
-  }
-  
-  //TODO: Delete this testing stuff.
-  /*private  void addContact(Account account, String name, String username) {
-    Log.i("ASD", "Adding contact: " + name);
-    ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>();
-    
-    //Create our RawContact
-    ContentProviderOperation.Builder builder = ContentProviderOperation.newInsert(RawContacts.CONTENT_URI);
-    builder.withValue(RawContacts.ACCOUNT_NAME, account.name);
-    builder.withValue(RawContacts.ACCOUNT_TYPE, account.type);
-    builder.withValue(RawContacts.SYNC1, username);
-    operationList.add(builder.build());
-    
-    //Create a Data record of common type 'StructuredName' for our RawContact
-    builder = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI);
-    builder.withValueBackReference(ContactsContract.CommonDataKinds.StructuredName.RAW_CONTACT_ID, 0);
-    builder.withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE);
-    builder.withValue(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME, name);
-    operationList.add(builder.build());
-    
-    //Create a Data record of custom type "vnd.android.cursor.item/vnd.fm.last.android.profile" to display a link to the Last.fm profile
-    builder = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI);
-    builder.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0);
-    builder.withValue(ContactsContract.Data.MIMETYPE, "vnd.android.cursor.item/vnd.owncloud.contact.profile");
-    builder.withValue(ContactsContract.Data.DATA1, username);
-    builder.withValue(ContactsContract.Data.DATA2, "Last.fm Profile");
-    builder.withValue(ContactsContract.Data.DATA3, "View profile");
-    operationList.add(builder.build());
-    
-    try {
-     getActivity().getContentResolver().applyBatch(ContactsContract.AUTHORITY, operationList);
-    } catch (Exception e) {
-     Log.e("ASD", "Something went wrong during creation! " + e);
-     e.printStackTrace();
-    }
-   }*/
-  
+	private Account mAccount;
+	private Stack<String> mDirNames;
+	private Vector<OCFile> mFiles;
+	private DataStorageManager mStorageManager;
+
+	public FileListFragment() {
+		mDirNames = new Stack<String>();
+	}
+
+	@Override
+	public void onCreate(Bundle savedInstanceState) {
+		super.onCreate(savedInstanceState);
+
+		mAccount = AccountUtils.getCurrentOwnCloudAccount(getActivity());
+		getListView().setDivider(
+				getResources().getDrawable(R.drawable.uploader_list_separator));
+		getListView().setDividerHeight(1);
+
+		populateFileList();
+	}
+
+	@Override
+	public void onItemClick(AdapterView<?> l, View v, int position, long id) {
+		if (mFiles.size() <= position) {
+			throw new IndexOutOfBoundsException("Incorrect item selected");
+		}
+		OCFile file = mFiles.get(position);
+
+		// Update ActionBarPath
+		if (file.getMimetype().equals("DIR")) {
+			String dirname = file.getFileName();
+
+			mDirNames.push(dirname);
+			((FileDisplayActivity) getActivity()).pushPath(dirname);
+
+			populateFileList();
+			return;
+		}
+
+		Intent showDetailsIntent = new Intent(getActivity(),
+				FileDetailActivity.class);
+		showDetailsIntent.putExtra(FileDetailFragment.FILE, file);
+		showDetailsIntent.putExtra(FileDownloader.EXTRA_ACCOUNT, mAccount);
+		
+		// Try to find by tag first
+		FileDetailFragment fd = (FileDetailFragment) getFragmentManager()
+				.findFragmentByTag("FileDetails");
+		
+		// Could be the first time the user has touched a file. find by id
+		if(fd == null){
+			fd = (FileDetailFragment) getFragmentManager().findFragmentById(R.id.fileDetail);
+		}
+
+		// Tablets will have this fragment, phones not. Could still be null
+		if (fd != null) {
+			
+			if(fd.isEmptyLayout()){
+				// True, if this is the first time a user taps on a file
+				fd = new FileDetailFragment(showDetailsIntent);
+				FragmentTransaction transaction = getFragmentManager().beginTransaction();
+				transaction.replace(R.id.file_details_container, fd, "FileDetails");
+				transaction.commit();
+			} else {
+				fd.updateFileDetails(showDetailsIntent);
+			}
+			
+		} else {
+			startActivity(showDetailsIntent);
+		}
+	}
+
+	@Override
+	public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int arg2,
+			long arg3) {
+		ClipData.Item item = new ClipData.Item("ASD");
+		ClipDescription cd = new ClipDescription("ASD",
+				new String[] { ClipDescription.MIMETYPE_TEXT_PLAIN });
+		ClipData dragData = new ClipData(cd, item);
+		arg1.startDrag(dragData,
+				new View.DragShadowBuilder(arg0.getChildAt(arg2)), null, 0);
+		return true;
+	}
+
+	/**
+	 * Call this, when the user presses the up button
+	 */
+	public void onNavigateUp() {
+		mDirNames.pop();
+		populateFileList();
+	}
+
+	/**
+	 * Lists the directory
+	 */
+	public void populateFileList() {
+		String s = "/";
+		for (String a : mDirNames)
+			s += a + "/";
+		Log.e("ASD", s);
+
+		mStorageManager = new FileDataStorageManager(mAccount, getActivity()
+				.getContentResolver());
+		OCFile file = mStorageManager.getFileByPath(s);
+		mFiles = mStorageManager.getDirectoryContent(file);
+		if (mFiles == null || mFiles.size() == 0) {
+			Toast.makeText(getActivity(), "There are no files here",
+					Toast.LENGTH_LONG).show();
+		}
+		setListAdapter(new FileListListAdapter(file, mStorageManager,
+				getActivity()));
+	}
+
+	// TODO: Delete this testing stuff.
+	/*
+	 * private void addContact(Account account, String name, String username) {
+	 * Log.i("ASD", "Adding contact: " + name);
+	 * ArrayList<ContentProviderOperation> operationList = new
+	 * ArrayList<ContentProviderOperation>();
+	 * 
+	 * //Create our RawContact ContentProviderOperation.Builder builder =
+	 * ContentProviderOperation.newInsert(RawContacts.CONTENT_URI);
+	 * builder.withValue(RawContacts.ACCOUNT_NAME, account.name);
+	 * builder.withValue(RawContacts.ACCOUNT_TYPE, account.type);
+	 * builder.withValue(RawContacts.SYNC1, username);
+	 * operationList.add(builder.build());
+	 * 
+	 * //Create a Data record of common type 'StructuredName' for our RawContact
+	 * builder =
+	 * ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI);
+	 * builder
+	 * .withValueBackReference(ContactsContract.CommonDataKinds.StructuredName
+	 * .RAW_CONTACT_ID, 0); builder.withValue(ContactsContract.Data.MIMETYPE,
+	 * ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE);
+	 * builder
+	 * .withValue(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME,
+	 * name); operationList.add(builder.build());
+	 * 
+	 * //Create a Data record of custom type
+	 * "vnd.android.cursor.item/vnd.fm.last.android.profile" to display a link
+	 * to the Last.fm profile builder =
+	 * ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI);
+	 * builder.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0);
+	 * builder.withValue(ContactsContract.Data.MIMETYPE,
+	 * "vnd.android.cursor.item/vnd.owncloud.contact.profile");
+	 * builder.withValue(ContactsContract.Data.DATA1, username);
+	 * builder.withValue(ContactsContract.Data.DATA2, "Last.fm Profile");
+	 * builder.withValue(ContactsContract.Data.DATA3, "View profile");
+	 * operationList.add(builder.build());
+	 * 
+	 * try {
+	 * getActivity().getContentResolver().applyBatch(ContactsContract.AUTHORITY,
+	 * operationList); } catch (Exception e) { Log.e("ASD",
+	 * "Something went wrong during creation! " + e); e.printStackTrace(); } }
+	 */
+
 }