Merge tag 'oc-android-1-3-22' into oauth_login
[pub/Android/ownCloud.git] / src / com / owncloud / android / ui / activity / FileDisplayActivity.java
index 1d75e69..eb218d0 100644 (file)
@@ -1,9 +1,10 @@
 /* ownCloud Android client application\r
  *   Copyright (C) 2011  Bartek Przybylski\r
+ *   Copyright (C) 2012-2013 ownCloud Inc.\r
  *\r
  *   This program is free software: you can redistribute it and/or modify\r
  *   it under the terms of the GNU General Public License as published by\r
- *   the Free Software Foundation, either version 3 of the License, or\r
+ *   the Free Software Foundation, either version 2 of the License, or\r
  *   (at your option) any later version.\r
  *\r
  *   This program is distributed in the hope that it will be useful,\r
@@ -35,6 +36,7 @@ import android.content.Intent;
 import android.content.IntentFilter;\r
 import android.content.ServiceConnection;\r
 import android.content.SharedPreferences;\r
+import android.content.SharedPreferences.Editor;\r
 import android.content.pm.PackageInfo;\r
 import android.content.pm.PackageManager.NameNotFoundException;\r
 import android.content.res.Resources.NotFoundException;\r
@@ -82,6 +84,7 @@ import com.owncloud.android.operations.RenameFileOperation;
 import com.owncloud.android.operations.SynchronizeFileOperation;\r
 import com.owncloud.android.operations.RemoteOperationResult.ResultCode;\r
 import com.owncloud.android.syncadapter.FileSyncService;\r
+import com.owncloud.android.ui.dialog.ChangelogDialog;\r
 import com.owncloud.android.ui.dialog.SslValidatorDialog;\r
 import com.owncloud.android.ui.dialog.SslValidatorDialog.OnSslValidatorListener;\r
 import com.owncloud.android.ui.fragment.FileDetailFragment;\r
@@ -124,6 +127,7 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements
     private static final int DIALOG_CHOOSE_UPLOAD_SOURCE = 4;\r
     private static final int DIALOG_SSL_VALIDATOR = 5;\r
     private static final int DIALOG_CERT_NOT_SAVED = 6;\r
+    private static final String DIALOG_CHANGELOG_TAG = "DIALOG_CHANGELOG";\r
 \r
     \r
     private static final int ACTION_SELECT_CONTENT_FROM_APPS = 1;\r
@@ -141,10 +145,10 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements
         mHandler = new Handler();\r
 \r
         /// Load of parameters from received intent\r
-        mCurrentDir = getIntent().getParcelableExtra(FileDetailFragment.EXTRA_FILE); // no check necessary, mCurrenDir == null if the parameter is not in the intent\r
         Account account = getIntent().getParcelableExtra(FileDetailFragment.EXTRA_ACCOUNT);\r
-        if (account != null)\r
-            AccountUtils.setCurrentOwnCloudAccount(this, account.name);\r
+        if (account != null && AccountUtils.setCurrentOwnCloudAccount(this, account.name)) {\r
+            mCurrentDir = getIntent().getParcelableExtra(FileDetailFragment.EXTRA_FILE); \r
+        }\r
         \r
         /// Load of saved instance state: keep this always before initDataFromCurrentAccount()\r
         if(savedInstanceState != null) {\r
@@ -185,7 +189,7 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements
         // Drop-down navigation \r
         mDirectories = new CustomArrayAdapter<String>(this, R.layout.sherlock_spinner_dropdown_item);\r
         OCFile currFile = mCurrentDir;\r
-        while(currFile != null && currFile.getFileName() != OCFile.PATH_SEPARATOR) {\r
+        while(mStorageManager != null && currFile != null && currFile.getFileName() != OCFile.PATH_SEPARATOR) {\r
             mDirectories.add(currFile.getFileName());\r
             currFile = mStorageManager.getFileById(currFile.getParentId());\r
         }\r
@@ -208,11 +212,41 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements
         actionBar.setListNavigationCallbacks(mDirectories, this);\r
         setSupportProgressBarIndeterminateVisibility(false);        // always AFTER setContentView(...) ; to workaround bug in its implementation\r
         \r
+        \r
+        // show changelog, if needed\r
+        //showChangeLog();\r
+        \r
         Log.d(getClass().toString(), "onCreate() end");\r
     }\r
 \r
     \r
     /**\r
+     * Shows a dialog with the change log of the current version after each app update\r
+     * \r
+     *  TODO make it permanent; by now, only to advice the workaround app for 4.1.x\r
+     */\r
+    private void showChangeLog() {\r
+        if (android.os.Build.VERSION.SDK_INT == android.os.Build.VERSION_CODES.JELLY_BEAN) {\r
+            final String KEY_VERSION = "version";\r
+            SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());\r
+            int currentVersionNumber = 0;\r
+            int savedVersionNumber = sharedPref.getInt(KEY_VERSION, 0);\r
+            try {\r
+                PackageInfo pi          = getPackageManager().getPackageInfo(getPackageName(), 0);\r
+                currentVersionNumber    = pi.versionCode;\r
+            } catch (Exception e) {}\r
+     \r
+            if (currentVersionNumber > savedVersionNumber) {\r
+                ChangelogDialog.newInstance(true).show(getSupportFragmentManager(), DIALOG_CHANGELOG_TAG);\r
+                Editor editor   = sharedPref.edit();\r
+                editor.putInt(KEY_VERSION, currentVersionNumber);\r
+                editor.commit();\r
+            }\r
+        }\r
+    }\r
+    \r
+\r
+    /**\r
      * Launches the account creation activity. To use when no ownCloud account is available\r
      */\r
     private void createFirstAccount() {\r