Browse Source

Fixed update of double pane view when download in notification bar is pressed in landspace mode

David A. Velasco 12 years ago
parent
commit
7382fa84b0

+ 1 - 1
src/com/owncloud/android/files/services/FileDownloader.java

@@ -312,7 +312,7 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis
         /// includes a pending intent in the notification showing the details view of the file
         /// includes a pending intent in the notification showing the details view of the file
         Intent showDetailsIntent = new Intent(this, FileDetailActivity.class);
         Intent showDetailsIntent = new Intent(this, FileDetailActivity.class);
         showDetailsIntent.putExtra(FileDetailFragment.EXTRA_FILE, download.getFile());
         showDetailsIntent.putExtra(FileDetailFragment.EXTRA_FILE, download.getFile());
-        showDetailsIntent.putExtra(FileDownloader.EXTRA_ACCOUNT, download.getAccount());
+        showDetailsIntent.putExtra(FileDetailFragment.EXTRA_ACCOUNT, download.getAccount());
         showDetailsIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
         showDetailsIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
         mNotification.contentIntent = PendingIntent.getActivity(getApplicationContext(), 0, showDetailsIntent, PendingIntent.FLAG_UPDATE_CURRENT);
         mNotification.contentIntent = PendingIntent.getActivity(getApplicationContext(), 0, showDetailsIntent, PendingIntent.FLAG_UPDATE_CURRENT);
         
         

+ 2 - 1
src/com/owncloud/android/ui/activity/FileDetailActivity.java

@@ -74,7 +74,7 @@ public class FileDetailActivity extends SherlockFragmentActivity implements File
             actionBar.setDisplayHomeAsUpEnabled(true);
             actionBar.setDisplayHomeAsUpEnabled(true);
 
 
             OCFile file = getIntent().getParcelableExtra(FileDetailFragment.EXTRA_FILE);
             OCFile file = getIntent().getParcelableExtra(FileDetailFragment.EXTRA_FILE);
-            Account account = getIntent().getParcelableExtra(FileDownloader.EXTRA_ACCOUNT);
+            Account account = getIntent().getParcelableExtra(FileDetailFragment.EXTRA_ACCOUNT);
             FileDetailFragment mFileDetail = new FileDetailFragment(file, account);
             FileDetailFragment mFileDetail = new FileDetailFragment(file, account);
         
         
             FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
             FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
@@ -147,6 +147,7 @@ public class FileDetailActivity extends SherlockFragmentActivity implements File
         Intent intent = new Intent(this, FileDisplayActivity.class);
         Intent intent = new Intent(this, FileDisplayActivity.class);
         intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
         intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
         intent.putExtra(FileDetailFragment.EXTRA_FILE, getIntent().getParcelableExtra(FileDetailFragment.EXTRA_FILE));
         intent.putExtra(FileDetailFragment.EXTRA_FILE, getIntent().getParcelableExtra(FileDetailFragment.EXTRA_FILE));
+        intent.putExtra(FileDetailFragment.EXTRA_ACCOUNT, getIntent().getParcelableExtra(FileDetailFragment.EXTRA_ACCOUNT));
         startActivity(intent);
         startActivity(intent);
         finish();
         finish();
     }
     }

+ 60 - 22
src/com/owncloud/android/ui/activity/FileDisplayActivity.java

@@ -88,7 +88,8 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements
     OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNavigationListener {
     OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNavigationListener {
     
     
     private ArrayAdapter<String> mDirectories;
     private ArrayAdapter<String> mDirectories;
-    private OCFile mCurrentDir;
+    private OCFile mCurrentDir = null;
+    private OCFile mCurrentFile = null;
 
 
     private DataStorageManager mStorageManager;
     private DataStorageManager mStorageManager;
     private SyncBroadcastReceiver mSyncBroadcastReceiver;
     private SyncBroadcastReceiver mSyncBroadcastReceiver;
@@ -116,8 +117,15 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements
         Log.d(getClass().toString(), "onCreate() start");
         Log.d(getClass().toString(), "onCreate() start");
         super.onCreate(savedInstanceState);
         super.onCreate(savedInstanceState);
 
 
-        /// saved instance state: keep this always before initDataFromCurrentAccount()
+        /// Load of parameters from received intent
+        mCurrentDir = getIntent().getParcelableExtra(FileDetailFragment.EXTRA_FILE); // no check necessary, mCurrenDir == null if the parameter is not in the intent
+        Account account = getIntent().getParcelableExtra(FileDetailFragment.EXTRA_ACCOUNT);
+        if (account != null)
+            AccountUtils.setCurrentOwnCloudAccount(this, account.name);
+        
+        /// Load of saved instance state: keep this always before initDataFromCurrentAccount()
         if(savedInstanceState != null) {
         if(savedInstanceState != null) {
+            // TODO - test if savedInstanceState should take precedence over file in the intent ALWAYS (now), NEVER, or SOME TIMES
             mCurrentDir = savedInstanceState.getParcelable(FileDetailFragment.EXTRA_FILE);
             mCurrentDir = savedInstanceState.getParcelable(FileDetailFragment.EXTRA_FILE);
         }
         }
         
         
@@ -128,10 +136,11 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements
             
             
         } else {    /// at least an account is available
         } else {    /// at least an account is available
             
             
-            bindService(new Intent(this, FileDownloader.class), mConnection, Context.BIND_AUTO_CREATE);
-            initDataFromCurrentAccount();
+            initDataFromCurrentAccount();   // it checks mCurrentDir and mCurrentFile with the current account
             
             
         }
         }
+        
+        bindService(new Intent(this, FileDownloader.class), mConnection, Context.BIND_AUTO_CREATE);
 
 
         // PIN CODE request ;  best location is to decide, let's try this first
         // PIN CODE request ;  best location is to decide, let's try this first
         if (getIntent().getAction() != null && getIntent().getAction().equals(Intent.ACTION_MAIN) && savedInstanceState == null) {
         if (getIntent().getAction() != null && getIntent().getAction().equals(Intent.ACTION_MAIN) && savedInstanceState == null) {
@@ -160,10 +169,8 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements
         setContentView(R.layout.files);    
         setContentView(R.layout.files);    
         mFileList = (OCFileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList);
         mFileList = (OCFileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList);
         mDualPane = (findViewById(R.id.file_details_container) != null);
         mDualPane = (findViewById(R.id.file_details_container) != null);
-        if (mDualPane && getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG) == null) {
-            FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
-            transaction.replace(R.id.file_details_container, new FileDetailFragment(null, null)); // empty FileDetailFragment
-            transaction.commit();
+        if (mDualPane) {
+            initFileDetailsInDualPane();
         }
         }
             
             
         // Action bar setup
         // Action bar setup
@@ -198,20 +205,41 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements
                 AccountUtils.getCurrentOwnCloudAccount(this),
                 AccountUtils.getCurrentOwnCloudAccount(this),
                 getContentResolver());
                 getContentResolver());
 
 
-        /// State recovery - CURRENT DIRECTORY ; priority: 1/ getIntent(), 2/ savedInstanceState (in onCreate()), 3/ root dir
-        if(getIntent().hasExtra(FileDetailFragment.EXTRA_FILE)) {
-            mCurrentDir = (OCFile) getIntent().getParcelableExtra(FileDetailFragment.EXTRA_FILE);
-            if(mCurrentDir != null && !mCurrentDir.isDirectory()){
-                mCurrentDir = mStorageManager.getFileById(mCurrentDir.getParentId());
-            }
-            // clear intent extra, so rotating the screen will not return us to this directory
-            getIntent().removeExtra(FileDetailFragment.EXTRA_FILE);
+        /// Check if mCurrentDir is a directory
+        if(mCurrentDir != null && !mCurrentDir.isDirectory()) {
+            mCurrentFile = mCurrentDir;
+            mCurrentDir = mStorageManager.getFileById(mCurrentDir.getParentId());
+        }
+        
+        /// Check if mCurrentDir and mCurrentFile are in the current account, and update them
+        if (mCurrentDir != null) {
+            mCurrentDir = mStorageManager.getFileByPath(mCurrentDir.getRemotePath());   // mCurrentDir == null if it is not in the current account
+        }
+        if (mCurrentFile != null) {
+            mCurrentFile = mStorageManager.getFileByPath(mCurrentFile.getRemotePath());   // mCurrentFile == null if it is not in the current account
+        }
+        
+        /// Default to root if mCurrentDir was not found
+        if (mCurrentDir == null) {
+            mCurrentDir = mStorageManager.getFileByPath("/"); // will be NULL if the database was never synchronized
         }
         }
-        if (mCurrentDir == null)
-            mCurrentDir = mStorageManager.getFileByPath("/");   // this will return NULL if the database has not ever synchronized
     }
     }
         
         
     
     
+    private void initFileDetailsInDualPane() {
+        if (mDualPane && getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG) == null) {
+            FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
+            if (mCurrentFile != null) {
+                transaction.replace(R.id.file_details_container, new FileDetailFragment(mCurrentFile, AccountUtils.getCurrentOwnCloudAccount(this)), FileDetailFragment.FTAG); // empty FileDetailFragment
+                mCurrentFile = null;
+            } else {
+                transaction.replace(R.id.file_details_container, new FileDetailFragment(null, null), FileDetailFragment.FTAG); // empty FileDetailFragment
+            }
+            transaction.commit();
+        }
+    }
+    
+    
     @Override
     @Override
     public void onDestroy() {
     public void onDestroy() {
         super.onDestroy();
         super.onDestroy();
@@ -386,7 +414,7 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements
             if (fileDetails != null && !fileDetails.isEmpty()) {
             if (fileDetails != null && !fileDetails.isEmpty()) {
                 FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
                 FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
                 transaction.remove(fileDetails);
                 transaction.remove(fileDetails);
-                transaction.add(R.id.file_details_container, new FileDetailFragment(null, null));
+                transaction.add(R.id.file_details_container, new FileDetailFragment(null, null), FileDetailFragment.FTAG);
                 transaction.commit();
                 transaction.commit();
             }
             }
         }
         }
@@ -403,6 +431,13 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements
         Log.d(getClass().toString(), "onSaveInstanceState() start");
         Log.d(getClass().toString(), "onSaveInstanceState() start");
         super.onSaveInstanceState(outState);
         super.onSaveInstanceState(outState);
         outState.putParcelable(FileDetailFragment.EXTRA_FILE, mCurrentDir);
         outState.putParcelable(FileDetailFragment.EXTRA_FILE, mCurrentDir);
+        if (mDualPane) {
+            FileDetailFragment fragment = (FileDetailFragment) getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG);
+            OCFile file = fragment.getDisplayedFile();
+            if (file != null) {
+                outState.putParcelable(FileDetailFragment.EXTRA_FILE, file);
+            }
+        }
         Log.d(getClass().toString(), "onSaveInstanceState() end");
         Log.d(getClass().toString(), "onSaveInstanceState() end");
     }
     }
 
 
@@ -416,6 +451,9 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements
             if (mStorageManager == null) {
             if (mStorageManager == null) {
                 // this is necessary for handling the come back to FileDisplayActivity when the first ownCloud account is created 
                 // this is necessary for handling the come back to FileDisplayActivity when the first ownCloud account is created 
                 initDataFromCurrentAccount();
                 initDataFromCurrentAccount();
+                if (mDualPane) {
+                    initFileDetailsInDualPane();
+                }
             }
             }
             
             
             // Listen for sync messages
             // Listen for sync messages
@@ -445,6 +483,7 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements
         Log.d(getClass().toString(), "onResume() end");
         Log.d(getClass().toString(), "onResume() end");
     }
     }
 
 
+    
     @Override
     @Override
     protected void onPause() {
     protected void onPause() {
         Log.d(getClass().toString(), "onPause() start");
         Log.d(getClass().toString(), "onPause() start");
@@ -465,7 +504,6 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements
             dismissDialog(DIALOG_SETUP_ACCOUNT);
             dismissDialog(DIALOG_SETUP_ACCOUNT);
         }
         }
         
         
-        getIntent().putExtra(FileDetailFragment.EXTRA_FILE, mCurrentDir);
         Log.d(getClass().toString(), "onPause() end");
         Log.d(getClass().toString(), "onPause() end");
     }
     }
 
 
@@ -836,7 +874,7 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements
             if (fileDetails != null && !fileDetails.isEmpty()) {
             if (fileDetails != null && !fileDetails.isEmpty()) {
                 FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
                 FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
                 transaction.remove(fileDetails);
                 transaction.remove(fileDetails);
-                transaction.add(R.id.file_details_container, new FileDetailFragment(null, null));
+                transaction.add(R.id.file_details_container, new FileDetailFragment(null, null), FileDetailFragment.FTAG);
                 transaction.commit();
                 transaction.commit();
             }
             }
         }
         }
@@ -860,7 +898,7 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements
         } else {    // small or medium screen device -> new Activity
         } else {    // small or medium screen device -> new Activity
             Intent showDetailsIntent = new Intent(this, FileDetailActivity.class);
             Intent showDetailsIntent = new Intent(this, FileDetailActivity.class);
             showDetailsIntent.putExtra(FileDetailFragment.EXTRA_FILE, file);
             showDetailsIntent.putExtra(FileDetailFragment.EXTRA_FILE, file);
-            showDetailsIntent.putExtra(FileDownloader.EXTRA_ACCOUNT, AccountUtils.getCurrentOwnCloudAccount(this));
+            showDetailsIntent.putExtra(FileDetailFragment.EXTRA_ACCOUNT, AccountUtils.getCurrentOwnCloudAccount(this));
             startActivity(showDetailsIntent);
             startActivity(showDetailsIntent);
         }
         }
     }
     }

+ 1 - 0
src/com/owncloud/android/ui/fragment/FileDetailFragment.java

@@ -173,6 +173,7 @@ public class FileDetailFragment extends SherlockFragment implements
             mPreview = (ImageView)mView.findViewById(R.id.fdPreview);
             mPreview = (ImageView)mView.findViewById(R.id.fdPreview);
         }
         }
         
         
+        updateFileDetails();
         return view;
         return view;
     }
     }