Browse Source

fix file display, fix syncing, fix authenticator & other stuff

Bartek Przybylski 13 years ago
parent
commit
7cf441258b

+ 3 - 0
src/eu/alefzero/owncloud/authenticator/AuthUtils.java

@@ -244,6 +244,9 @@ public class AuthUtils {
 				  break;
 			  }
 		  }
+	  } else if (ocAccounts.length != 0) {
+	    // we at least need to take first account as fallback
+	    defaultAccount = ocAccounts[0];
 	  }
 	  
 	return defaultAccount;

+ 12 - 5
src/eu/alefzero/owncloud/datamodel/FileDataStorageManager.java

@@ -90,7 +90,7 @@ public class FileDataStorageManager implements DataStorageManager {
     cv.put(ProviderTableMeta.FILE_PATH, file.getPath());
     cv.put(ProviderTableMeta.FILE_STORAGE_PATH, file.getStoragePath());
     cv.put(ProviderTableMeta.FILE_ACCOUNT_OWNER, mAccount.name);
-    
+
     if (fileExists(file.getPath())) {
       overriden = true;
       if (getContentResolver() != null) {
@@ -109,15 +109,20 @@ public class FileDataStorageManager implements DataStorageManager {
         }
       }
     } else {
+      Uri result_uri = null;
       if (getContentResolver() != null) {
-        getContentResolver().insert(ProviderTableMeta.CONTENT_URI_FILE, cv);
+        result_uri = getContentResolver().insert(ProviderTableMeta.CONTENT_URI_FILE, cv);
       } else {
         try {
-          getContentProvider().insert(ProviderTableMeta.CONTENT_URI_FILE, cv);
+          result_uri = getContentProvider().insert(ProviderTableMeta.CONTENT_URI_FILE, cv);
         } catch (RemoteException e) {
           Log.e(TAG, "Fail to insert insert file to database " + e.getMessage());
         }
       }
+      if (result_uri != null) {
+        long new_id = Long.parseLong(result_uri.getPathSegments().get(1));
+        file.setFileId(new_id);
+      }
     }
     
     if (file.isDirectory() && file.needsUpdatingWhileSaving())
@@ -158,6 +163,7 @@ public class FileDataStorageManager implements DataStorageManager {
       Uri req_uri = Uri.withAppendedPath(
           ProviderTableMeta.CONTENT_URI_DIR, String.valueOf(f.getFileId()));
       Cursor c = null;
+      
       if (getContentProvider() != null) {
         try {
           c = getContentProvider().query(req_uri, null, null, null, null);
@@ -169,12 +175,13 @@ public class FileDataStorageManager implements DataStorageManager {
         c = getContentResolver().query(req_uri, null, null, null, null);
       }
 
-      if (c.moveToFirst())
+      if (c.moveToFirst()) {
         do {
           OCFile child = createFileInstance(c);
           ret.add(child);
         } while (c.moveToNext());
-
+      }
+      
       c.close();
       return ret;
     }

+ 1 - 1
src/eu/alefzero/owncloud/datamodel/OCFile.java

@@ -38,9 +38,9 @@ public class OCFile {
 	 * @param path The remote path of the file
 	 */
 	public OCFile(String path) {
+	  resetData();
 	  update_while_saving_ = false;
 		path_ = path;
-		resetData();
 	}
 
 	/**

+ 2 - 1
src/eu/alefzero/owncloud/syncadapter/AbstractOwnCloudSyncAdapter.java

@@ -222,6 +222,7 @@ public abstract class AbstractOwnCloudSyncAdapter extends
 				Log.d(TAG, "No update for file/dir " + file.getFileName()
 						+ " is needed");
 			} else {
+			  file = new OCFile(n.getProperty(NodeProperty.PATH));
 				Log.d(TAG, "File " + n.getProperty(NodeProperty.PATH)
 						+ " will be "
 						+ (file.fileExists() ? "updated" : "created"));
@@ -231,7 +232,7 @@ public abstract class AbstractOwnCloudSyncAdapter extends
 				long create = n.getProperty(NodeProperty.CREATE_DATE) == null ? 0
 						: Long.parseLong(n
 								.getProperty(NodeProperty.CREATE_DATE));
-				file = new OCFile(n.getProperty(NodeProperty.PATH));
+
 				file.setFileLength(len);
 				file.setCreationTimestamp(create);
 				file.setModificationTimestamp(mod);

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

@@ -23,6 +23,7 @@ import java.util.Vector;
 import android.accounts.Account;
 import android.content.Intent;
 import android.os.Bundle;
+import android.util.Log;
 import android.view.View;
 import android.widget.AdapterView;
 import eu.alefzero.owncloud.R;
@@ -56,8 +57,6 @@ public class FileListFragment extends FragmentListView {
 
     mAccount = AuthUtils.getCurrentOwnCloudAccount(getActivity());
     populateFileList();
-    // TODO: Remove this testing stuff
-    //addContact(mAccount, "Bartek Przybylski", "czlowiek");
   }
   
   @Override
@@ -80,6 +79,7 @@ public class FileListFragment extends FragmentListView {
     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) {
@@ -103,10 +103,10 @@ public class FileListFragment extends FragmentListView {
   private void populateFileList() {
     String s = "/";
     for (String a : mDirNames)
-      s+= a+"/";
+      s+= a + "/";
 
     mStorageManager = new FileDataStorageManager(mAccount, getActivity().getContentResolver());
-    OCFile file = new OCFile(s);
+    OCFile file = mStorageManager.getFileByPath(s);
     mFiles = mStorageManager.getDirectoryContent(file);
     setListAdapter(new FileListListAdapter(file, mStorageManager, getActivity()));
   }