Tablet fixes. Goal is to get tapping on a file to display its details.
authorLennart Rosam <lennart@familie-rosam.de>
Tue, 15 May 2012 21:12:07 +0000 (23:12 +0200)
committerLennart Rosam <lennart@familie-rosam.de>
Tue, 15 May 2012 21:12:07 +0000 (23:12 +0200)
Does not work yet - WIP. Also code optimization: Make
FileDetailFragment less complex by passing in a OCFile directly instead
of reconstructing it.

res/layout-large-land/files.xml
src/eu/alefzero/owncloud/datamodel/OCFile.java
src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java
src/eu/alefzero/owncloud/ui/fragment/FileListFragment.java

index d0ccfe8..68f8c86 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>\r
-<!-- \r
+<!--\r
   ownCloud Android client application\r
 \r
   Copyright (C) 2011  Bartek Przybylski\r
@@ -14,8 +14,8 @@
   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
+  along with this program.  If not, see <http://www.gnu.org/licenses/>.\r\r
+-->\r
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"\r
     android:layout_width="fill_parent"\r
     android:layout_height="fill_parent"\r
         android:layout_width="0dp"\r
         android:layout_height="wrap_content"\r
         android:layout_weight="1" >\r
+\r
+        <fragment\r
+            android:id="@+id/fileList"\r
+            android:layout_width="fill_parent"\r
+            android:layout_height="fill_parent"\r
+            class="eu.alefzero.owncloud.ui.fragment.FileListFragment" >\r
+\r
+            <!-- Preview: layout=@layout/list_layout -->\r
+        </fragment>\r
     </LinearLayout>\r
 \r
-    <fragment\r
-        android:id="@+id/fileDetail"\r
+    <LinearLayout android:id="@+id/file_details_container"\r
         android:layout_width="0dp"\r
-        android:layout_height="fill_parent"\r
-        android:layout_weight="2"\r
-        class="eu.alefzero.owncloud.ui.fragment.FileDetail" >\r
-        <!-- Preview: layout=@layout/file_details -->\r
-    </fragment>\r
+        android:layout_height="wrap_content"\r
+        android:layout_weight="2" >\r
+\r
+        <fragment\r
+            android:id="@+id/fileDetail"\r
+            android:layout_width="fill_parent"\r
+            android:layout_height="fill_parent"\r
+            class="eu.alefzero.owncloud.ui.fragment.FileDetailFragment" >\r
+\r
+            <!-- Preview: layout=@layout/file_details_empty -->\r
+        </fragment>\r
+    </LinearLayout>\r
 \r
 </LinearLayout>
\ No newline at end of file
index b9be3ad..04a153b 100644 (file)
@@ -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
+       }
+       
 }
index f667204..90f1175 100644 (file)
  */\r
 package eu.alefzero.owncloud.ui.fragment;\r
 \r
-import android.accounts.Account;\r
+import android.app.FragmentTransaction;\r
 import android.content.BroadcastReceiver;\r
 import android.content.Context;\r
 import android.content.Intent;\r
 import android.content.IntentFilter;\r
-import android.database.Cursor;\r
 import android.graphics.Bitmap;\r
 import android.graphics.BitmapFactory;\r
-import android.net.Uri;\r
 import android.os.Bundle;\r
 import android.view.LayoutInflater;\r
 import android.view.View;\r
@@ -41,134 +39,189 @@ import com.actionbarsherlock.app.SherlockFragment;
 import eu.alefzero.owncloud.DisplayUtils;\r
 import eu.alefzero.owncloud.FileDownloader;\r
 import eu.alefzero.owncloud.R;\r
-import eu.alefzero.owncloud.db.ProviderMeta.ProviderTableMeta;\r
+import eu.alefzero.owncloud.datamodel.OCFile;\r
 \r
 /**\r
  * This Fragment is used to display the details about a file.\r
+ * \r
  * @author Bartek Przybylski\r
- *\r
+ * \r
  */\r
-public class FileDetailFragment extends SherlockFragment implements OnClickListener {\r
-  \r
-  private Intent mIntent;\r
-  private View mView;\r
-  private DownloadFinishReceiver dfr;\r
-  \r
-  @Override\r
-  public void onResume() {\r
-    super.onResume();\r
-    dfr = new DownloadFinishReceiver();\r
-    IntentFilter filter = new IntentFilter(FileDownloader.DOWNLOAD_FINISH_MESSAGE);\r
-    getActivity().registerReceiver(dfr, filter);\r
-  }\r
-  \r
-  @Override\r
-  public void onPause() {\r
-    super.onPause();\r
-    getActivity().unregisterReceiver(dfr);\r
-    dfr = null;\r
-  }\r
-  \r
-  public void setStuff(Intent intent) {\r
-    mIntent = intent;\r
-    setStuff(getView());\r
-  }\r
-  \r
-  private void setStuff(View view) {\r
-    mView = view;\r
-    String id = mIntent.getStringExtra("FILE_ID");\r
-    Account account = mIntent.getParcelableExtra("ACCOUNT");\r
-    String account_name = account.name;\r
-    Cursor c = getActivity().managedQuery(\r
-        Uri.withAppendedPath(ProviderTableMeta.CONTENT_URI_FILE, id),\r
-        null,\r
-        ProviderTableMeta.FILE_ACCOUNT_OWNER+"=?",\r
-        new String[]{account_name},\r
-        null);\r
-    c.moveToFirst();\r
-\r
-    // Retrieve details from DB\r
-    String filename = c.getString(c.getColumnIndex(ProviderTableMeta.FILE_NAME));\r
-    String mimetype = c.getString(c.getColumnIndex(ProviderTableMeta.FILE_CONTENT_TYPE));\r
-    String path = c.getString(c.getColumnIndex(ProviderTableMeta.FILE_STORAGE_PATH));\r
-    long filesize = c.getLong(c.getColumnIndex(ProviderTableMeta.FILE_CONTENT_LENGTH));\r
-\r
-    // set file details\r
-    setFilename(filename);\r
-    setFiletype(DisplayUtils.convertMIMEtoPrettyPrint(mimetype));\r
-    setFilesize(filesize);\r
-    \r
-    // set file preview if available and possible\r
-    View w = view.findViewById(R.id.videoView1);\r
-    w.setVisibility(View.INVISIBLE);\r
-    if (path == null) {\r
-      ImageView v = (ImageView) getView().findViewById(R.id.imageView2);\r
-      v.setImageResource(R.drawable.download);\r
-      v.setOnClickListener(this);\r
-    } else {\r
-      if (mimetype.startsWith("image/")) {\r
-        ImageView v = (ImageView) view.findViewById(R.id.imageView2);\r
-        Bitmap bmp = BitmapFactory.decodeFile(path);\r
-        v.setImageBitmap(bmp);\r
-      } else if (mimetype.startsWith("video/")) {\r
-        VideoView v = (VideoView) view.findViewById(R.id.videoView1);\r
-        v.setVisibility(View.VISIBLE);\r
-        v.setVideoPath(path);\r
-        v.start();\r
-      }\r
-    }\r
-  }\r
-\r
-  @Override\r
-  public View onCreateView(LayoutInflater inflater, ViewGroup container,\r
-      Bundle savedInstanceState) {\r
-    View v = null;\r
-    \r
-    if (getActivity().getIntent() != null && getActivity().getIntent().getStringExtra("FILE_ID") != null) {\r
-       v = inflater.inflate(R.layout.file_details_fragment, container, false);\r
-       mIntent = getActivity().getIntent();\r
-       setStuff(v);\r
-    } else {\r
-       v = inflater.inflate(R.layout.file_details_empty, container, false);\r
-    }\r
-    return v;\r
-  }\r
-\r
-  @Override\r
-  public View getView() {\r
-    return mView == null ? super.getView() : mView;\r
-  };\r
-  \r
-  public void setFilename(String filename) {\r
-    TextView tv = (TextView) getView().findViewById(R.id.textView1);\r
-    if (tv != null) tv.setText(filename);\r
-  }\r
-  \r
-  public void setFiletype(String mimetype) {\r
-    TextView tv = (TextView) getView().findViewById(R.id.textView2);\r
-    if (tv != null) tv.setText(mimetype);\r
-  }\r
-  \r
-  public void setFilesize(long filesize) {\r
-    TextView tv = (TextView) getView().findViewById(R.id.textView3);\r
-    if (tv != null) tv.setText(DisplayUtils.bitsToHumanReadable(filesize));\r
-  }\r
-\r
-  @Override\r
-  public void onClick(View v) {\r
-    Toast.makeText(getActivity(), "Downloading", Toast.LENGTH_LONG).show();\r
-    Intent i = new Intent(getActivity(), FileDownloader.class);\r
-    i.putExtra(FileDownloader.EXTRA_ACCOUNT, mIntent.getParcelableExtra("ACCOUNT"));\r
-    i.putExtra(FileDownloader.EXTRA_FILE_PATH, mIntent.getStringExtra("FULL_PATH"));\r
-    getActivity().startService(i);\r
-  }\r
-  \r
-  private class DownloadFinishReceiver extends BroadcastReceiver {\r
-    @Override\r
-    public void onReceive(Context context, Intent intent) {\r
-      setStuff(getView());\r
-    }\r
-    \r
-  }\r
-  \r
+public class FileDetailFragment extends SherlockFragment implements\r
+               OnClickListener {\r
+\r
+       public static final String FILE = "FILE";\r
+\r
+       private Intent mIntent;\r
+       private View mView;\r
+       private DownloadFinishReceiver mDownloadFinishReceiver;\r
+       private OCFile mFile;\r
+\r
+       private int mLayout;\r
+       private boolean mEmptyLayout;\r
+\r
+       /**\r
+        * Default constructor. When inflated by android -> display empty layout\r
+        */\r
+       public FileDetailFragment() {\r
+               mLayout = R.layout.file_details_empty;\r
+               mEmptyLayout = true;\r
+       }\r
+\r
+       /**\r
+        * Custom construtor. Use with a {@link FragmentTransaction}.\r
+        * The intent has to contain {@link FileDetailFragment#FILE} with an OCFile\r
+        * and also {@link FileDownloader#EXTRA_ACCOUNT} with the account.\r
+        * \r
+        * @param nonEmptyFragment\r
+        *            True, to enable file detail rendering\r
+        */\r
+       public FileDetailFragment(Intent intent) {\r
+               mLayout = R.layout.file_details_fragment;\r
+               mIntent = intent;\r
+               mEmptyLayout = false;\r
+       }\r
+\r
+       @Override\r
+       public void onResume() {\r
+               super.onResume();\r
+               mDownloadFinishReceiver = new DownloadFinishReceiver();\r
+               IntentFilter filter = new IntentFilter(\r
+                               FileDownloader.DOWNLOAD_FINISH_MESSAGE);\r
+               getActivity().registerReceiver(mDownloadFinishReceiver, filter);\r
+       }\r
+\r
+       @Override\r
+       public void onPause() {\r
+               super.onPause();\r
+               getActivity().unregisterReceiver(mDownloadFinishReceiver);\r
+               mDownloadFinishReceiver = null;\r
+       }\r
+\r
+       /**\r
+        * Use this method to signal this Activity that it shall update its view.\r
+        * \r
+        * @param intent\r
+        *            The {@link Intent} that contains extra information about this\r
+        *            file The intent needs to have these extras:\r
+        *            <p>\r
+        * \r
+        *            {@link FileDetailFragment#FILE}: An {@link OCFile}\r
+        *            {@link FileDownloader#EXTRA_ACCOUNT}: The Account that file\r
+        *            belongs to (required for downloading)\r
+        */\r
+       public void updateFileDetails(Intent intent) {\r
+               mIntent = intent;\r
+               updateFileDetails();\r
+       }\r
+\r
+       private void updateFileDetails() {\r
+               mFile = mIntent.getParcelableExtra(FILE);\r
+\r
+               if (mFile != null) {\r
+                       // set file details\r
+                       setFilename(mFile.getFileName());\r
+                       setFiletype(DisplayUtils.convertMIMEtoPrettyPrint(mFile\r
+                                       .getMimetype()));\r
+                       setFilesize(mFile.getFileLength());\r
+\r
+                       // set file preview if available and possible\r
+                       VideoView videoView = (VideoView) mView\r
+                                       .findViewById(R.id.videoView1);\r
+                       videoView.setVisibility(View.INVISIBLE);\r
+                       if (mFile.getPath() == null) {\r
+                               ImageView imageView = (ImageView) getView().findViewById(\r
+                                               R.id.imageView2);\r
+                               imageView.setImageResource(R.drawable.download);\r
+                               imageView.setOnClickListener(this);\r
+                       } else {\r
+                               if (mFile.getMimetype().startsWith("image/")) {\r
+                                       ImageView imageView = (ImageView) mView\r
+                                                       .findViewById(R.id.imageView2);\r
+                                       Bitmap bmp = BitmapFactory.decodeFile(mFile.getPath());\r
+                                       imageView.setImageBitmap(bmp);\r
+                               } else if (mFile.getMimetype().startsWith("video/")) {\r
+                                       videoView.setVisibility(View.VISIBLE);\r
+                                       videoView.setVideoPath(mFile.getPath());\r
+                                       videoView.start();\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+\r
+       @Override\r
+       public View onCreateView(LayoutInflater inflater, ViewGroup container,\r
+                       Bundle savedInstanceState) {\r
+               View view = null;\r
+\r
+               view = inflater.inflate(mLayout, container, false);\r
+               mIntent = getActivity().getIntent();\r
+               mView = view;\r
+\r
+               // make sure we are not using the empty layout\r
+               if (mEmptyLayout == false) {\r
+                       updateFileDetails();\r
+               }\r
+\r
+               return view;\r
+       }\r
+\r
+       @Override\r
+       public View getView() {\r
+               return mView == null ? super.getView() : mView;\r
+       };\r
+\r
+       private void setFilename(String filename) {\r
+               TextView tv = (TextView) getView().findViewById(R.id.textView1);\r
+               if (tv != null)\r
+                       tv.setText(filename);\r
+       }\r
+\r
+       private void setFiletype(String mimetype) {\r
+               TextView tv = (TextView) getView().findViewById(R.id.textView2);\r
+               if (tv != null)\r
+                       tv.setText(mimetype);\r
+       }\r
+\r
+       private void setFilesize(long filesize) {\r
+               TextView tv = (TextView) getView().findViewById(R.id.textView3);\r
+               if (tv != null)\r
+                       tv.setText(DisplayUtils.bitsToHumanReadable(filesize));\r
+       }\r
+\r
+       /**\r
+        * Use this to check if the correct layout is loaded. When android\r
+        * instanciates this class using the default constructor, the layout will be\r
+        * empty.\r
+        * \r
+        * Once a user touches a file for the first time, you must instanciate a new\r
+        * Fragment with the new FileDetailFragment(true) to inflate the actual\r
+        * details\r
+        * \r
+        * @return If the layout is empty, this method will return true, otherwise\r
+        *         false\r
+        */\r
+       public boolean isEmptyLayout() {\r
+               return mEmptyLayout;\r
+       }\r
+\r
+       @Override\r
+       public void onClick(View v) {\r
+               Toast.makeText(getActivity(), "Downloading", Toast.LENGTH_LONG).show();\r
+               Intent i = new Intent(getActivity(), FileDownloader.class);\r
+               i.putExtra(FileDownloader.EXTRA_ACCOUNT,\r
+                               mIntent.getParcelableExtra(FileDownloader.EXTRA_ACCOUNT));\r
+               i.putExtra(FileDownloader.EXTRA_FILE_PATH,\r
+                               mIntent.getStringExtra(FileDownloader.EXTRA_FILE_PATH));\r
+               getActivity().startService(i);\r
+       }\r
+\r
+       private class DownloadFinishReceiver extends BroadcastReceiver {\r
+               @Override\r
+               public void onReceive(Context context, Intent intent) {\r
+                       updateFileDetails();\r
+               }\r
+\r
+       }\r
+\r
 }\r
index 3ad899b..100e9c5 100644 (file)
@@ -25,11 +25,13 @@ import android.content.ClipData;
 import android.content.ClipDescription;\r
 import android.content.Intent;\r
 import android.os.Bundle;\r
+import android.support.v4.app.FragmentTransaction;\r
 import android.util.Log;\r
 import android.view.View;\r
 import android.widget.AdapterView;\r
 import android.widget.Toast;\r
 import eu.alefzero.owncloud.AccountUtils;\r
+import eu.alefzero.owncloud.FileDownloader;\r
 import eu.alefzero.owncloud.R;\r
 import eu.alefzero.owncloud.datamodel.DataStorageManager;\r
 import eu.alefzero.owncloud.datamodel.FileDataStorageManager;\r
@@ -41,129 +43,164 @@ import eu.alefzero.owncloud.ui.adapter.FileListListAdapter;
 \r
 /**\r
  * A Fragment that lists all files and folders in a given path.\r
+ * \r
  * @author Bartek Przybylski\r
- *\r
+ * \r
  */\r
 public class FileListFragment extends FragmentListView {\r
-  private Account mAccount;\r
-  private Stack<String> mDirNames;\r
-  private Vector<OCFile> mFiles;\r
-  private DataStorageManager mStorageManager;\r
-\r
-  public FileListFragment() {\r
-    mDirNames = new Stack<String>();\r
-  }\r
-  \r
-  @Override\r
-  public void onCreate(Bundle savedInstanceState) {\r
-    super.onCreate(savedInstanceState);\r
-\r
-    mAccount = AccountUtils.getCurrentOwnCloudAccount(getActivity());\r
-    getListView().setDivider(getResources().getDrawable(R.drawable.uploader_list_separator));\r
-    getListView().setDividerHeight(1);\r
-    \r
-    populateFileList();\r
-  }\r
-  \r
-  @Override\r
-  public void onItemClick(AdapterView<?> l, View v, int position, long id) {\r
-    if (mFiles.size() <= position) {\r
-      throw new IndexOutOfBoundsException("Incorrect item selected");\r
-    }\r
-    OCFile file = mFiles.get(position);\r
-    String id_ = String.valueOf(file.getFileId());\r
-    if (file.getMimetype().equals("DIR")) {\r
-        String dirname = file.getFileName();\r
-\r
-        mDirNames.push(dirname);\r
-        ((FileDisplayActivity)getActivity()).pushPath(dirname);\r
-        \r
-        populateFileList();\r
-        return;\r
-    }\r
-    Intent i = new Intent(getActivity(), FileDetailActivity.class);\r
-    i.putExtra("FILE_NAME", file.getFileName());\r
-    i.putExtra("FULL_PATH", file.getPath());\r
-    i.putExtra("FILE_ID", id_);\r
-    Log.e("ASD", mAccount+"");\r
-    i.putExtra("ACCOUNT", mAccount);\r
-    FileDetailFragment fd = (FileDetailFragment) getFragmentManager().findFragmentById(R.id.fileDetail);\r
-    if (fd != null) {\r
-      fd.setStuff(i);\r
-    } else {\r
-      startActivity(i);\r
-    }\r
-  }\r
-  \r
-  @Override\r
-  public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {\r
-    ClipData.Item item = new ClipData.Item("ASD");\r
-    ClipDescription cd = new ClipDescription("ASD", new String[]{ClipDescription.MIMETYPE_TEXT_PLAIN});\r
-    ClipData dragData = new ClipData(cd, item);\r
-    arg1.startDrag(dragData, new View.DragShadowBuilder(arg0.getChildAt(arg2)), null, 0);\r
-    return true;\r
-  }\r
-  \r
-  /**\r
-   * Call this, when the user presses the up button\r
-   */\r
-  public void onNavigateUp() {\r
-    mDirNames.pop();\r
-    populateFileList();\r
-  }\r
-\r
-  /**\r
-   * Lists the directory\r
-   */\r
-  public void populateFileList() {\r
-    String s = "/";\r
-    for (String a : mDirNames)\r
-      s+= a + "/";\r
-    Log.e("ASD", s);\r
-\r
-    mStorageManager = new FileDataStorageManager(mAccount, getActivity().getContentResolver());\r
-    OCFile file = mStorageManager.getFileByPath(s);\r
-    mFiles = mStorageManager.getDirectoryContent(file);\r
-    if (mFiles == null || mFiles.size() == 0) {\r
-      Toast.makeText(getActivity(), "There are no files here", Toast.LENGTH_LONG).show();\r
-    }\r
-    setListAdapter(new FileListListAdapter(file, mStorageManager, getActivity()));\r
-  }\r
-  \r
-  //TODO: Delete this testing stuff.\r
-  /*private  void addContact(Account account, String name, String username) {\r
-    Log.i("ASD", "Adding contact: " + name);\r
-    ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>();\r
-    \r
-    //Create our RawContact\r
-    ContentProviderOperation.Builder builder = ContentProviderOperation.newInsert(RawContacts.CONTENT_URI);\r
-    builder.withValue(RawContacts.ACCOUNT_NAME, account.name);\r
-    builder.withValue(RawContacts.ACCOUNT_TYPE, account.type);\r
-    builder.withValue(RawContacts.SYNC1, username);\r
-    operationList.add(builder.build());\r
-    \r
-    //Create a Data record of common type 'StructuredName' for our RawContact\r
-    builder = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI);\r
-    builder.withValueBackReference(ContactsContract.CommonDataKinds.StructuredName.RAW_CONTACT_ID, 0);\r
-    builder.withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE);\r
-    builder.withValue(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME, name);\r
-    operationList.add(builder.build());\r
-    \r
-    //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\r
-    builder = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI);\r
-    builder.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0);\r
-    builder.withValue(ContactsContract.Data.MIMETYPE, "vnd.android.cursor.item/vnd.owncloud.contact.profile");\r
-    builder.withValue(ContactsContract.Data.DATA1, username);\r
-    builder.withValue(ContactsContract.Data.DATA2, "Last.fm Profile");\r
-    builder.withValue(ContactsContract.Data.DATA3, "View profile");\r
-    operationList.add(builder.build());\r
-    \r
-    try {\r
-     getActivity().getContentResolver().applyBatch(ContactsContract.AUTHORITY, operationList);\r
-    } catch (Exception e) {\r
-     Log.e("ASD", "Something went wrong during creation! " + e);\r
-     e.printStackTrace();\r
-    }\r
-   }*/\r
-  \r
+       private Account mAccount;\r
+       private Stack<String> mDirNames;\r
+       private Vector<OCFile> mFiles;\r
+       private DataStorageManager mStorageManager;\r
+\r
+       public FileListFragment() {\r
+               mDirNames = new Stack<String>();\r
+       }\r
+\r
+       @Override\r
+       public void onCreate(Bundle savedInstanceState) {\r
+               super.onCreate(savedInstanceState);\r
+\r
+               mAccount = AccountUtils.getCurrentOwnCloudAccount(getActivity());\r
+               getListView().setDivider(\r
+                               getResources().getDrawable(R.drawable.uploader_list_separator));\r
+               getListView().setDividerHeight(1);\r
+\r
+               populateFileList();\r
+       }\r
+\r
+       @Override\r
+       public void onItemClick(AdapterView<?> l, View v, int position, long id) {\r
+               if (mFiles.size() <= position) {\r
+                       throw new IndexOutOfBoundsException("Incorrect item selected");\r
+               }\r
+               OCFile file = mFiles.get(position);\r
+\r
+               // Update ActionBarPath\r
+               if (file.getMimetype().equals("DIR")) {\r
+                       String dirname = file.getFileName();\r
+\r
+                       mDirNames.push(dirname);\r
+                       ((FileDisplayActivity) getActivity()).pushPath(dirname);\r
+\r
+                       populateFileList();\r
+                       return;\r
+               }\r
+\r
+               Intent showDetailsIntent = new Intent(getActivity(),\r
+                               FileDetailActivity.class);\r
+               showDetailsIntent.putExtra(FileDetailFragment.FILE, file);\r
+               showDetailsIntent.putExtra(FileDownloader.EXTRA_ACCOUNT, mAccount);\r
+               \r
+               // Try to find by tag first\r
+               FileDetailFragment fd = (FileDetailFragment) getFragmentManager()\r
+                               .findFragmentByTag("FileDetails");\r
+               \r
+               // Could be the first time the user has touched a file. find by id\r
+               if(fd == null){\r
+                       fd = (FileDetailFragment) getFragmentManager().findFragmentById(R.id.fileDetail);\r
+               }\r
+\r
+               // Tablets will have this fragment, phones not. Could still be null\r
+               if (fd != null) {\r
+                       \r
+                       if(fd.isEmptyLayout()){\r
+                               // True, if this is the first time a user taps on a file\r
+                               fd = new FileDetailFragment(showDetailsIntent);\r
+                               FragmentTransaction transaction = getFragmentManager().beginTransaction();\r
+                               transaction.replace(R.id.file_details_container, fd, "FileDetails");\r
+                               transaction.commit();\r
+                       } else {\r
+                               fd.updateFileDetails(showDetailsIntent);\r
+                       }\r
+                       \r
+               } else {\r
+                       startActivity(showDetailsIntent);\r
+               }\r
+       }\r
+\r
+       @Override\r
+       public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int arg2,\r
+                       long arg3) {\r
+               ClipData.Item item = new ClipData.Item("ASD");\r
+               ClipDescription cd = new ClipDescription("ASD",\r
+                               new String[] { ClipDescription.MIMETYPE_TEXT_PLAIN });\r
+               ClipData dragData = new ClipData(cd, item);\r
+               arg1.startDrag(dragData,\r
+                               new View.DragShadowBuilder(arg0.getChildAt(arg2)), null, 0);\r
+               return true;\r
+       }\r
+\r
+       /**\r
+        * Call this, when the user presses the up button\r
+        */\r
+       public void onNavigateUp() {\r
+               mDirNames.pop();\r
+               populateFileList();\r
+       }\r
+\r
+       /**\r
+        * Lists the directory\r
+        */\r
+       public void populateFileList() {\r
+               String s = "/";\r
+               for (String a : mDirNames)\r
+                       s += a + "/";\r
+               Log.e("ASD", s);\r
+\r
+               mStorageManager = new FileDataStorageManager(mAccount, getActivity()\r
+                               .getContentResolver());\r
+               OCFile file = mStorageManager.getFileByPath(s);\r
+               mFiles = mStorageManager.getDirectoryContent(file);\r
+               if (mFiles == null || mFiles.size() == 0) {\r
+                       Toast.makeText(getActivity(), "There are no files here",\r
+                                       Toast.LENGTH_LONG).show();\r
+               }\r
+               setListAdapter(new FileListListAdapter(file, mStorageManager,\r
+                               getActivity()));\r
+       }\r
+\r
+       // TODO: Delete this testing stuff.\r
+       /*\r
+        * private void addContact(Account account, String name, String username) {\r
+        * Log.i("ASD", "Adding contact: " + name);\r
+        * ArrayList<ContentProviderOperation> operationList = new\r
+        * ArrayList<ContentProviderOperation>();\r
+        * \r
+        * //Create our RawContact ContentProviderOperation.Builder builder =\r
+        * ContentProviderOperation.newInsert(RawContacts.CONTENT_URI);\r
+        * builder.withValue(RawContacts.ACCOUNT_NAME, account.name);\r
+        * builder.withValue(RawContacts.ACCOUNT_TYPE, account.type);\r
+        * builder.withValue(RawContacts.SYNC1, username);\r
+        * operationList.add(builder.build());\r
+        * \r
+        * //Create a Data record of common type 'StructuredName' for our RawContact\r
+        * builder =\r
+        * ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI);\r
+        * builder\r
+        * .withValueBackReference(ContactsContract.CommonDataKinds.StructuredName\r
+        * .RAW_CONTACT_ID, 0); builder.withValue(ContactsContract.Data.MIMETYPE,\r
+        * ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE);\r
+        * builder\r
+        * .withValue(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME,\r
+        * name); operationList.add(builder.build());\r
+        * \r
+        * //Create a Data record of custom type\r
+        * "vnd.android.cursor.item/vnd.fm.last.android.profile" to display a link\r
+        * to the Last.fm profile builder =\r
+        * ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI);\r
+        * builder.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0);\r
+        * builder.withValue(ContactsContract.Data.MIMETYPE,\r
+        * "vnd.android.cursor.item/vnd.owncloud.contact.profile");\r
+        * builder.withValue(ContactsContract.Data.DATA1, username);\r
+        * builder.withValue(ContactsContract.Data.DATA2, "Last.fm Profile");\r
+        * builder.withValue(ContactsContract.Data.DATA3, "View profile");\r
+        * operationList.add(builder.build());\r
+        * \r
+        * try {\r
+        * getActivity().getContentResolver().applyBatch(ContactsContract.AUTHORITY,\r
+        * operationList); } catch (Exception e) { Log.e("ASD",\r
+        * "Something went wrong during creation! " + e); e.printStackTrace(); } }\r
+        */\r
+\r
 }\r