Browse Source

warning for corrupt accounts for 2.0.0RC users

AndyScherzinger 7 years ago
parent
commit
1c0c0a297b

+ 47 - 6
src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java

@@ -124,6 +124,7 @@ import static com.owncloud.android.db.PreferenceManager.getSortOrder;
 public class FileDisplayActivity extends HookActivity
         implements FileFragment.ContainerActivity,
         OnEnforceableRefreshListener, SortingOrderDialogFragment.OnSortingOrderListener {
+    private static final String KEY_SHOW_ACCOUNT_WARNING = "SHOW_ACCOUNT_WARNING";
 
     private SyncBroadcastReceiver mSyncBroadcastReceiver;
     private UploadFinishReceiver mUploadFinishReceiver;
@@ -274,6 +275,7 @@ public class FileDisplayActivity extends HookActivity
         // always AFTER setContentView(...) in onCreate(); to work around bug in its implementation
 
         upgradeNotificationForInstantUpload();
+        upgradeNotificationForCorruptAccounts();
     }
 
     /**
@@ -283,7 +285,7 @@ public class FileDisplayActivity extends HookActivity
     private void upgradeNotificationForInstantUpload() {
         // check for Android 6+ if legacy instant upload is activated --> disable + show info
         if (PreferenceManager.instantPictureUploadEnabled(this) ||
-                        PreferenceManager.instantPictureUploadEnabled(this)) {
+                PreferenceManager.instantPictureUploadEnabled(this)) {
 
             // remove legacy shared preferences
             SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(this).edit();
@@ -322,6 +324,45 @@ public class FileDisplayActivity extends HookActivity
         }
     }
 
+    /**
+     * TODO: remove after 2.0.0 final release
+     */
+    private void upgradeNotificationForCorruptAccounts() {
+        boolean showWarning = PreferenceManager.getDefaultSharedPreferences(this)
+                .getBoolean(KEY_SHOW_ACCOUNT_WARNING, true);
+        int version = getVersion();
+
+        // check show warning, version > 1.4.3 and <= 2.0.0RCx
+        if (showWarning && version > 10040299 && version < 20000099) {
+            final Context context = this;
+
+            // show info pop-up
+            new AlertDialog.Builder(this, R.style.Theme_ownCloud_Dialog)
+                    .setTitle(R.string.common_warning)
+                    .setMessage(R.string.corrupt_account_info)
+                    .setPositiveButton(R.string.common_ok, new DialogInterface.OnClickListener() {
+                        public void onClick(DialogInterface dialog, int which) {
+                            dialog.dismiss();
+                            PreferenceManager.getDefaultSharedPreferences(context)
+                                    .edit().putBoolean(KEY_SHOW_ACCOUNT_WARNING, false).apply();
+                        }
+                    })
+                    .setIcon(R.drawable.ic_warning)
+                    .setCancelable(false)
+                    .show();
+        }
+    }
+
+    public int getVersion() {
+        int version = 0;
+        try {
+            version = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode;
+        } catch (PackageManager.NameNotFoundException e) {
+            return version;
+        }
+        return version;
+    }
+
     @Override
     public void onRequestPermissionsResult(int requestCode,
                                            String permissions[], int[] grantResults) {
@@ -474,7 +515,7 @@ public class FileDisplayActivity extends HookActivity
     @Override
     protected void onNewIntent(Intent intent) {
         super.onNewIntent(intent);
-        if(intent.getAction()!=null && intent.getAction().equalsIgnoreCase(ACTION_DETAILS)){
+        if (intent.getAction() != null && intent.getAction().equalsIgnoreCase(ACTION_DETAILS)) {
             setIntent(intent);
             setFile(intent.getParcelableExtra(EXTRA_FILE));
         }
@@ -1034,10 +1075,10 @@ public class FileDisplayActivity extends HookActivity
             // all closed
 
             //if PreviewImageActivity called this activity and mDualPane==false  then calls PreviewImageActivity again
-            if((getIntent().getAction()!=null && getIntent().getAction().equalsIgnoreCase(ACTION_DETAILS)) && !mDualPane){
-                    getIntent().setAction(null);
-                    getIntent().putExtra(EXTRA_FILE, (OCFile) null);
-                    startImagePreview(getFile());
+            if ((getIntent().getAction() != null && getIntent().getAction().equalsIgnoreCase(ACTION_DETAILS)) && !mDualPane) {
+                getIntent().setAction(null);
+                getIntent().putExtra(EXTRA_FILE, (OCFile) null);
+                startImagePreview(getFile());
             }
 
             OCFileListFragment listOfFiles = getListOfFilesFragment();

+ 3 - 0
src/main/res/values/strings.xml

@@ -699,4 +699,7 @@
 
     <string name="foreground_service_upload">Uploading files&#8230;</string>
     <string name="foreground_service_download">Downloading files&#8230;</string>
+
+    <string name="common_warning">Warning</string>
+    <string name="corrupt_account_info">Accounts have been corrupted in case you have been using a release candidate of 2.0.0 between RC1 and RC5.\n\nWe are sorry to tell you that you need to remove the Nextcloud accounts from your device and need to re-login again completely in order to get fully working login-sessions on this device!</string>
 </resources>