Răsfoiți Sursa

bit better handling of filelist

Bartek Przybylski 13 ani în urmă
părinte
comite
e28442c87d

+ 2 - 1
res/layout-port/files.xml

@@ -3,7 +3,8 @@
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:background="#F7F7F7"
-    android:orientation="vertical" >
+    android:orientation="vertical" 
+    android:id="@+id/file_list_container">
 
     <fragment
         android:id="@+id/fileList"

+ 14 - 23
res/layout/files.xml

@@ -9,33 +9,24 @@
         android:id="@+id/linearLayout1"
         android:layout_width="fill_parent"
         android:layout_height="fill_parent"
-        android:orientation="vertical" >
+        android:orientation="horizontal" >
 
         <LinearLayout
-            android:id="@+id/linearLayout2"
-            android:layout_width="fill_parent"
-            android:layout_height="wrap_content" >
-
-            <fragment
-                android:id="@+id/fileList"
-                android:layout_width="0dp"
-                android:layout_height="fill_parent"
-                android:layout_weight="1"
-                class="eu.alefzero.owncloud.ui.fragment.FileList" >
-
-                <!-- Preview: layout=@layout/list_layout -->
-            </fragment>
+            android:id="@+id/file_list_container"
+            android:layout_width="0dp"
+            android:layout_height="wrap_content" 
+            android:layout_weight="1">
+        </LinearLayout>
 
-            <fragment
-                android:id="@+id/fileDetail"
-                android:layout_width="0dp"
-                android:layout_height="fill_parent"
-                android:layout_weight="2"
-                class="eu.alefzero.owncloud.ui.fragment.FileDetail" >
+        <fragment
+            android:id="@+id/fileDetail"
+            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>
-        </LinearLayout>
+            <!-- Preview: layout=@layout/file_details -->
+        </fragment>
     </LinearLayout>
 
 </LinearLayout>

+ 4 - 0
src/eu/alefzero/owncloud/ui/FragmentListView.java

@@ -24,6 +24,10 @@ public class FragmentListView extends Fragment implements OnItemClickListener {
     mList.setAdapter(listAdapter);
     mList.invalidate();
   }
+  
+  public ListView getListView() {
+    return mList;
+  }
 
   @Override
   public View onCreateView(LayoutInflater inflater, ViewGroup container,

+ 6 - 28
src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java

@@ -112,7 +112,7 @@ public class FileDisplayActivity extends android.support.v4.app.FragmentActivity
     getActionBar().setListNavigationCallbacks(mDirectories, this);
     
     FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
-    ft.add(R.id.fileList, mFileList);
+    ft.add(R.id.file_list_container, mFileList);
     if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
       ft.add(R.id.fileDetail, new FileDetail());
     }
@@ -200,7 +200,6 @@ public class FileDisplayActivity extends android.support.v4.app.FragmentActivity
         public void onClick(DialogInterface dialog, int item) {
             mAccount = accMan.getAccountsByType(AccountAuthenticator.ACCOUNT_TYPE)[item];
             dialog.dismiss();
-            populateFileList();
         }
     });
     builder.setOnCancelListener(new OnCancelListener() {
@@ -346,35 +345,16 @@ public class FileDisplayActivity extends android.support.v4.app.FragmentActivity
     //}
 //  }
   
-  private void populateFileList() {
-    if (mParents.empty()) {
-      mCursor = getContentResolver().query(ProviderTableMeta.CONTENT_URI,
-                                           null,
-                                           ProviderTableMeta.FILE_ACCOUNT_OWNER+"=?",
-                                           new String[]{mAccount.name},
-                                           null);
-    } else {
-      mCursor = getContentResolver().query(Uri.withAppendedPath(ProviderTableMeta.CONTENT_URI_DIR, mParents.peek()),
-                                           null,
-                                           ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?",
-                                           new String[]{mAccount.name}, null);
-      if (!mIsDisplayingFile) {
-        //PathLayout pl = (PathLayout) findViewById(R.id.pathLayout1);
-        //for (String s : mPath) {
-        //  pl.push(s);
-       // }
-      }
-    }
+ 
 //    setListAdapter(new FileListListAdapter(mCursor, this));
 //    getListView().invalidate();
-  }
 
   @Override
   public boolean onNavigationItemSelected(int itemPosition, long itemId) {
     int i = itemPosition;
     while (i-- != 0) {
       popPath();
-      mFileList.onBackPressed();
+      //mFileList.onBackPressed();
     }
     return true;
   }
@@ -382,10 +362,9 @@ public class FileDisplayActivity extends android.support.v4.app.FragmentActivity
   @Override
   public void onBackPressed() {
     popPath();
-    if (mDirectories.isEmpty()) {
-      super.onBackPressed();
-    }
-    mFileList.onBackPressed();
+    //getSupportFragmentManager().popBackStack();
+    //super.onBackPressed();
+    getSupportFragmentManager().popBackStackImmediate();
   }
   
   //@Override
@@ -400,5 +379,4 @@ public class FileDisplayActivity extends android.support.v4.app.FragmentActivity
     outState.putSerializable("path", mPath);
     outState.putBoolean("isDisplayingFile", mIsDisplayingFile);
   }*/
-
 }

+ 0 - 6
src/eu/alefzero/owncloud/ui/fragment/FileDetail.java

@@ -55,12 +55,6 @@ public class FileDetail extends Fragment {
     super.onCreate(savedInstanceState);
   }
 
-  @Override
-  public void onActivityCreated(Bundle savedInstanceState) {
-    // TODO Auto-generated method stub
-    super.onActivityCreated(savedInstanceState);
-  }
-
   @Override
   public View onCreateView(LayoutInflater inflater, ViewGroup container,
       Bundle savedInstanceState) {

+ 38 - 78
src/eu/alefzero/owncloud/ui/fragment/FileList.java

@@ -17,40 +17,27 @@
  */
 package eu.alefzero.owncloud.ui.fragment;
 
-import java.util.ListIterator;
-import java.util.Stack;
-
-import eu.alefzero.owncloud.DisplayUtils;
-import eu.alefzero.owncloud.R;
-import eu.alefzero.owncloud.R.id;
-import eu.alefzero.owncloud.authenticator.AccountAuthenticator;
-import eu.alefzero.owncloud.db.ProviderMeta.ProviderTableMeta;
-import eu.alefzero.owncloud.ui.FragmentListView;
-import eu.alefzero.owncloud.ui.activity.FileDetailActivity;
-import eu.alefzero.owncloud.ui.activity.FileDisplayActivity;
-import eu.alefzero.owncloud.ui.adapter.FileListListAdapter;
-import eu.alefzero.owncloud.ui.fragment.ActionBar;
 import android.accounts.Account;
 import android.accounts.AccountManager;
-import android.app.Activity;
+import android.app.FragmentManager;
 import android.app.Service;
 import android.content.Intent;
 import android.database.Cursor;
 import android.net.Uri;
 import android.os.Bundle;
 import android.support.v4.app.FragmentTransaction;
-import android.support.v4.app.Fragment;
-import android.support.v4.app.ListFragment;
-import android.util.Log;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.AdapterView;
-import android.widget.ArrayAdapter;
-import android.widget.ListView;
 import android.widget.TextView;
-import android.widget.Toast;
-import android.widget.AdapterView.OnItemClickListener;
+import eu.alefzero.owncloud.R;
+import eu.alefzero.owncloud.authenticator.AccountAuthenticator;
+import eu.alefzero.owncloud.db.ProviderMeta.ProviderTableMeta;
+import eu.alefzero.owncloud.ui.FragmentListView;
+import eu.alefzero.owncloud.ui.activity.FileDetailActivity;
+import eu.alefzero.owncloud.ui.activity.FileDisplayActivity;
+import eu.alefzero.owncloud.ui.adapter.FileListListAdapter;
 
 /**
  * A Fragment that lists all files and folders in a given path.
@@ -61,98 +48,71 @@ public class FileList extends FragmentListView {
   private Cursor mCursor;
   private Account mAccount;
   private AccountManager mAccountManager;
-  private View mheaderView;
-  private Stack<String> mParentsIds;
-  private Stack<String> mDirNames;
+  private String mDirName;
+  private String mParentId;
+
+  public FileList() {
+    mDirName = null;
+    mParentId = null;
+  }
 
+  public FileList(String dirName, String parentId) {
+    mDirName = dirName;
+    mParentId = parentId;
+  }
+  
   @Override
   public void onCreate(Bundle savedInstanceState) {
-    // TODO Auto-generated method stub
     super.onCreate(savedInstanceState);
-    
-    mParentsIds = new Stack<String>();
-    mDirNames = new Stack<String>();
+
     mAccountManager = (AccountManager)getActivity().getSystemService(Service.ACCOUNT_SERVICE);
     mAccount = mAccountManager.getAccountsByType(AccountAuthenticator.ACCOUNT_TYPE)[0];
     populateFileList();
   }
   
-  @Override
-  public void onActivityCreated(Bundle savedInstanceState) {
-    // TODO Auto-generated method stub
-    super.onActivityCreated(savedInstanceState);
-  }
-  
   @Override
   public void onItemClick(AdapterView<?> l, View v, int position, long id) {
-    FileDetail fd = (FileDetail) getFragmentManager().findFragmentById(R.id.fileDetail);
+    FileDetail fd = (FileDetail) getFragmentManager().findFragmentById(R.id.fileDetail); 
     if (!mCursor.moveToPosition(position)) {
       throw new IndexOutOfBoundsException("Incorrect item selected");
     }
     
     if (mCursor.getString(mCursor.getColumnIndex(ProviderTableMeta.FILE_CONTENT_TYPE)).equals("DIR")) {
         String id_ = mCursor.getString(mCursor.getColumnIndex(ProviderTableMeta._ID));
-        mParentsIds.push(id_);
         String dirname = mCursor.getString(mCursor.getColumnIndex(ProviderTableMeta.FILE_NAME));
-        mDirNames.push(dirname);
-        ((FileDisplayActivity)getActivity()).pushPath(DisplayUtils.HtmlDecode(dirname));
-        mCursor = getActivity().managedQuery(Uri.withAppendedPath(ProviderTableMeta.CONTENT_URI_DIR, id_),
-                               null,
-                               ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?",
-                               new String[]{mAccount.name}, null);
-        setListAdapter(new FileListListAdapter(mCursor, getActivity()));
-        //super.onListItemClick(l, v, position, id);
+
+        FileList fl = new FileList(dirname, id_);
+        ((FileDisplayActivity)getActivity()).pushPath(dirname);
+
+        FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
+        ft.addToBackStack(null);
+        ft.replace(R.id.file_list_container, fl);
+        ft.commit();
+        getSupportFragmentManager().executePendingTransactions();
         return;
     }
     Intent i = new Intent(getActivity(), FileDetailActivity.class);
     i.putExtra("FILE_NAME", ((TextView)v.findViewById(R.id.Filename)).getText());
     if (fd != null) {
       fd.setStuff(i);
-      //fd.use(((TextView)v.findViewById(R.id.Filename)).getText());
     } else {
-      i.putExtra("FILE_NAME", ((TextView)v.findViewById(R.id.Filename)).getText());
       startActivity(i);
     }
-    FragmentTransaction ft = getFragmentManager().beginTransaction();
-    ft.replace(R.id.fileList, this);
-    ft.commitAllowingStateLoss();
-    //super.onListItemClick(l, v, position, id);
-    
-  }
-  
-  @Override
-  public void onDestroyView() {
-    setListAdapter(null);
-    super.onDestroyView();
   }
   
   private void populateFileList() {
-    mCursor = getActivity().getContentResolver().query(ProviderTableMeta.CONTENT_URI,
+    if (mParentId == null || mDirName == null) {
+      mCursor = getActivity().getContentResolver().query(ProviderTableMeta.CONTENT_URI,
         null,
         ProviderTableMeta.FILE_ACCOUNT_OWNER+"=?",
         new String[]{mAccount.name},
         null);
-    
-    setListAdapter(new FileListListAdapter(mCursor, getActivity()));
-  }
-  
-  public void onBackPressed() {
-    if (!mParentsIds.empty()) {
-      mParentsIds.pop();
-      mDirNames.pop();
-    }
-    if (!mParentsIds.empty()) {
-      
-      String id_ = mParentsIds.peek();
-      String dirname = mDirNames.peek();
-      mCursor = getActivity().managedQuery(Uri.withAppendedPath(ProviderTableMeta.CONTENT_URI_DIR, id_),
-                             null,
-                             ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?",
-                             new String[]{mAccount.name}, null);
-      setListAdapter(new FileListListAdapter(mCursor, getActivity()));
     } else {
-      populateFileList();
+      mCursor = getActivity().managedQuery(Uri.withAppendedPath(ProviderTableMeta.CONTENT_URI_DIR, mParentId),
+          null,
+          ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?",
+          new String[]{mAccount.name}, null);
     }
-      
+    setListAdapter(new FileListListAdapter(mCursor, getActivity()));
   }
 }