浏览代码

proper file list handling, file basic stuff dispaying

Bartek Przybylski 13 年之前
父节点
当前提交
dbaff80211

+ 0 - 10
res/layout-port/files.xml

@@ -6,14 +6,4 @@
     android:orientation="vertical" 
     android:id="@+id/file_list_container">
 
-    <fragment
-        android:id="@+id/fileList"
-        android:layout_width="fill_parent"
-        android:layout_height="fill_parent"
-        class="eu.alefzero.owncloud.ui.fragment.FileList" >
-
-        <!-- Preview: layout=@layout/list_layout -->
-    </fragment>
-    <!-- </LinearLayout> -->
-
 </LinearLayout>

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

@@ -86,7 +86,6 @@ public class FileDisplayActivity extends android.support.v4.app.FragmentActivity
   private Cursor mCursor;
   private boolean mIsDisplayingFile;
   private ArrayAdapter<String> mDirectories;
-  private FileList mFileList;
  
   private static final int DIALOG_CHOOSE_ACCOUNT = 0;
   
@@ -105,14 +104,13 @@ public class FileDisplayActivity extends android.support.v4.app.FragmentActivity
     super.onCreate(savedInstanceState);
     mDirectories = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item);
     mDirectories.add("/");
-    mFileList = new FileList();
     setContentView(R.layout.files);
     getActionBar().setNavigationMode(android.support.v4.app.ActionBar.NAVIGATION_MODE_LIST);
     getActionBar().setDisplayShowTitleEnabled(false);
     getActionBar().setListNavigationCallbacks(mDirectories, this);
     
     FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
-    ft.add(R.id.file_list_container, mFileList);
+    ft.add(R.id.file_list_container, new FileList());
     if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
       ft.add(R.id.fileDetail, new FileDetail());
     }
@@ -362,9 +360,12 @@ public class FileDisplayActivity extends android.support.v4.app.FragmentActivity
   @Override
   public void onBackPressed() {
     popPath();
-    //getSupportFragmentManager().popBackStack();
-    //super.onBackPressed();
-    getSupportFragmentManager().popBackStackImmediate();
+    if (mDirectories.getCount() == 0)
+    {
+      super.onBackPressed();
+      return;
+    }
+    ((FileList)getSupportFragmentManager().findFragmentById(id.file_list_container)).onBackPressed();
   }
   
   //@Override

+ 34 - 11
src/eu/alefzero/owncloud/ui/fragment/FileDetail.java

@@ -17,10 +17,15 @@
  */
 package eu.alefzero.owncloud.ui.fragment;
 
+import eu.alefzero.owncloud.DisplayUtils;
 import eu.alefzero.owncloud.R;
+import eu.alefzero.owncloud.cp;
 import eu.alefzero.owncloud.R.id;
 import eu.alefzero.owncloud.R.layout;
+import eu.alefzero.owncloud.db.ProviderMeta.ProviderTableMeta;
 import android.content.Intent;
+import android.database.Cursor;
+import android.net.Uri;
 import android.os.Bundle;
 import android.support.v4.app.Fragment;
 import android.util.Log;
@@ -40,19 +45,25 @@ public class FileDetail extends Fragment {
   public Intent mIntent;
   
   public void setStuff(Intent intent) {
-    setStuff(intent, getView());
+    mIntent = intent;
+    setStuff(getView());
   }
   
-  private void setStuff(Intent intent, View view) {
-    String filename = intent.getStringExtra("FILE_NAME");
-    String filepath = intent.getStringExtra("FILE_PATH");
+  private void setStuff(View view) {
+    String id = mIntent.getStringExtra("FILE_ID");
+    String account_name = mIntent.getStringExtra("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();
+    
+    String filename = c.getString(c.getColumnIndex(ProviderTableMeta.FILE_NAME));
     setFilename(filename, view);
-  }
-  
-  @Override
-  public void onCreate(Bundle savedInstanceState) {
-    // TODO Auto-generated method stub
-    super.onCreate(savedInstanceState);
+    String mimetype = c.getString(c.getColumnIndex(ProviderTableMeta.FILE_CONTENT_TYPE));
+    setFiletype(DisplayUtils.convertMIMEtoPrettyPrint(mimetype), view);
   }
 
   @Override
@@ -60,7 +71,10 @@ public class FileDetail extends Fragment {
       Bundle savedInstanceState) {
     View v = inflater.inflate(R.layout.file_details, container, false);
     
-    if (getActivity().getIntent() != null) setStuff(getActivity().getIntent(), v);
+    if (getActivity().getIntent() != null) {
+      mIntent = getActivity().getIntent();
+      setStuff(v);
+    }
     return v;
   }
 
@@ -69,7 +83,16 @@ public class FileDetail extends Fragment {
     if (tv != null) tv.setText(filename);
   }
   
+  private void setFiletype(String mimetype, View target_view) {
+    TextView tv = (TextView) target_view.findViewById(R.id.textView2);
+    if (tv != null) tv.setText(mimetype);
+  }
+  
   public void setFilename(String filename) {
     setFilename(filename, getView());
   }
+  
+  public void setFiletype(String filename) {
+    setFiletype(filename, getView());
+  }
 }

+ 24 - 22
src/eu/alefzero/owncloud/ui/fragment/FileList.java

@@ -17,6 +17,8 @@
  */
 package eu.alefzero.owncloud.ui.fragment;
 
+import java.util.Stack;
+
 import android.accounts.Account;
 import android.accounts.AccountManager;
 import android.app.FragmentManager;
@@ -26,6 +28,7 @@ import android.database.Cursor;
 import android.net.Uri;
 import android.os.Bundle;
 import android.support.v4.app.FragmentTransaction;
+import android.util.Log;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
@@ -48,17 +51,12 @@ public class FileList extends FragmentListView {
   private Cursor mCursor;
   private Account mAccount;
   private AccountManager mAccountManager;
-  private String mDirName;
-  private String mParentId;
+  private Stack<String> mDirNames;
+  private Stack<String> mParentsIds;
 
   public FileList() {
-    mDirName = null;
-    mParentId = null;
-  }
-
-  public FileList(String dirName, String parentId) {
-    mDirName = dirName;
-    mParentId = parentId;
+    mDirNames = new Stack<String>();
+    mParentsIds = new Stack<String>();
   }
   
   @Override
@@ -72,43 +70,47 @@ public class FileList extends FragmentListView {
   
   @Override
   public void onItemClick(AdapterView<?> l, View v, int position, long id) {
-    FileDetail fd = (FileDetail) getFragmentManager().findFragmentById(R.id.fileDetail); 
     if (!mCursor.moveToPosition(position)) {
       throw new IndexOutOfBoundsException("Incorrect item selected");
     }
-    
+    String id_ = mCursor.getString(mCursor.getColumnIndex(ProviderTableMeta._ID));
     if (mCursor.getString(mCursor.getColumnIndex(ProviderTableMeta.FILE_CONTENT_TYPE)).equals("DIR")) {
-        String id_ = mCursor.getString(mCursor.getColumnIndex(ProviderTableMeta._ID));
         String dirname = mCursor.getString(mCursor.getColumnIndex(ProviderTableMeta.FILE_NAME));
 
-        FileList fl = new FileList(dirname, id_);
+        mDirNames.push(dirname);
+        mParentsIds.push(id_);
         ((FileDisplayActivity)getActivity()).pushPath(dirname);
-
-        FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
-        ft.addToBackStack(null);
-        ft.replace(R.id.file_list_container, fl);
-        ft.commit();
-        getSupportFragmentManager().executePendingTransactions();
+        
+        populateFileList();
         return;
     }
     Intent i = new Intent(getActivity(), FileDetailActivity.class);
     i.putExtra("FILE_NAME", ((TextView)v.findViewById(R.id.Filename)).getText());
+    i.putExtra("FILE_ID", id_);
+    i.putExtra("ACCOUNT_NAME", mAccount.name);
+    FileDetail fd = (FileDetail) getFragmentManager().findFragmentById(R.id.fileDetail);
     if (fd != null) {
       fd.setStuff(i);
     } else {
       startActivity(i);
     }
   }
-  
+
+  public void onBackPressed() {
+    mParentsIds.pop();
+    mDirNames.pop();
+    populateFileList();
+  }
+
   private void populateFileList() {
-    if (mParentId == null || mDirName == null) {
+    if (mParentsIds.empty()) {
       mCursor = getActivity().getContentResolver().query(ProviderTableMeta.CONTENT_URI,
         null,
         ProviderTableMeta.FILE_ACCOUNT_OWNER+"=?",
         new String[]{mAccount.name},
         null);
     } else {
-      mCursor = getActivity().managedQuery(Uri.withAppendedPath(ProviderTableMeta.CONTENT_URI_DIR, mParentId),
+      mCursor = getActivity().managedQuery(Uri.withAppendedPath(ProviderTableMeta.CONTENT_URI_DIR, mParentsIds.peek()),
           null,
           ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?",
           new String[]{mAccount.name}, null);