Browse Source

hide outdated version warning if extended support is enabled

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
tobiasKaminsky 5 years ago
parent
commit
b649ec38c4

+ 3 - 2
src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java

@@ -1249,8 +1249,9 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
 
             // show outdated warning
             if (getResources().getBoolean(R.bool.show_outdated_server_warning) &&
-                MainApp.OUTDATED_SERVER_VERSION.compareTo(mServerInfo.mVersion) >= 0) {
-                DisplayUtils.showServerOutdatedSnackbar(this);
+                MainApp.OUTDATED_SERVER_VERSION.compareTo(mServerInfo.mVersion) >= 0 &&
+                !mServerInfo.hasExtendedSupport) {
+                DisplayUtils.showServerOutdatedSnackbar(this, Snackbar.LENGTH_INDEFINITE);
             }
 
             webViewLoginMethod = mServerInfo.mVersion.isWebLoginSupported() && !forceOldLoginMethod;

+ 3 - 0
src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java

@@ -1917,6 +1917,7 @@ public class FileDataStorageManager {
         cv.put(ProviderTableMeta.CAPABILITIES_VERSION_MICRO, capability.getVersionMicro());
         cv.put(ProviderTableMeta.CAPABILITIES_VERSION_STRING, capability.getVersionString());
         cv.put(ProviderTableMeta.CAPABILITIES_VERSION_EDITION, capability.getVersionEdition());
+        cv.put(ProviderTableMeta.CAPABILITIES_EXTENDED_SUPPORT, capability.getExtendedSupport().getValue());
         cv.put(ProviderTableMeta.CAPABILITIES_CORE_POLLINTERVAL, capability.getCorePollInterval());
         cv.put(ProviderTableMeta.CAPABILITIES_SHARING_API_ENABLED, capability.getFilesSharingApiEnabled().getValue());
         cv.put(ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_ENABLED,
@@ -2072,6 +2073,8 @@ public class FileDataStorageManager {
                     .getColumnIndex(ProviderTableMeta.CAPABILITIES_VERSION_STRING)));
             capability.setVersionEdition(c.getString(c
                     .getColumnIndex(ProviderTableMeta.CAPABILITIES_VERSION_EDITION)));
+            capability.setExtendedSupport(CapabilityBooleanType.fromValue(c.getInt(c
+                                                                                       .getColumnIndex(ProviderTableMeta.CAPABILITIES_EXTENDED_SUPPORT))));
             capability.setCorePollInterval(c.getInt(c
                     .getColumnIndex(ProviderTableMeta.CAPABILITIES_CORE_POLLINTERVAL)));
             capability.setFilesSharingApiEnabled(CapabilityBooleanType.fromValue(c.getInt(c

+ 2 - 1
src/main/java/com/owncloud/android/db/ProviderMeta.java

@@ -31,7 +31,7 @@ import com.owncloud.android.MainApp;
  */
 public class ProviderMeta {
     public static final String DB_NAME = "filelist";
-    public static final int DB_VERSION = 48;
+    public static final int DB_VERSION = 49;
 
     private ProviderMeta() {
         // No instance
@@ -151,6 +151,7 @@ public class ProviderMeta {
         public static final String CAPABILITIES_VERSION_MICRO = "version_micro";
         public static final String CAPABILITIES_VERSION_STRING = "version_string";
         public static final String CAPABILITIES_VERSION_EDITION = "version_edition";
+        public static final String CAPABILITIES_EXTENDED_SUPPORT = "extended_support";
         public static final String CAPABILITIES_CORE_POLLINTERVAL = "core_pollinterval";
         public static final String CAPABILITIES_SHARING_API_ENABLED = "sharing_api_enabled";
         public static final String CAPABILITIES_SHARING_PUBLIC_ENABLED = "sharing_public_enabled";

+ 24 - 23
src/main/java/com/owncloud/android/operations/GetServerInfoOperation.java

@@ -38,58 +38,58 @@ import java.util.Locale;
 
 /**
  * Get basic information from an ownCloud server given its URL.
- * 
- * Checks the existence of a configured ownCloud server in the URL, gets its version 
+ *
+ * Checks the existence of a configured ownCloud server in the URL, gets its version
  * and finds out what authentication method is needed to access files in it.
  */
 
 public class GetServerInfoOperation extends RemoteOperation {
-    
+
     private static final String TAG = GetServerInfoOperation.class.getSimpleName();
-    
+
     private String mUrl;
     private Context mContext;
     private ServerInfo mResultData;
 
-    /** 
+    /**
      * Constructor.
-     * 
+     *
      * @param url               URL to an ownCloud server.
      * @param context           Android context; needed to check network state
-     *                          TODO ugly dependency, get rid of it. 
+     *                          TODO ugly dependency, get rid of it.
      */
     public GetServerInfoOperation(String url, Context context) {
         mUrl = trimWebdavSuffix(url);
         mContext = context;
         mResultData = new ServerInfo();
     }
-    
+
     /**
      * Performs the operation
-     * 
-     * @return      Result of the operation. If successful, includes an instance of 
-     *              {@link ServerInfo} with the information retrieved from the server. 
+     *
+     * @return Result of the operation. If successful, includes an instance of
+     *              {@link ServerInfo} with the information retrieved from the server.
      *              Call {@link RemoteOperationResult#getData()}.get(0) to get it.
      */
 	@Override
 	protected RemoteOperationResult run(OwnCloudClient client) {
-	    
+
 	    // first: check the status of the server (including its version)
 	    GetRemoteStatusOperation getStatus = new GetRemoteStatusOperation(mContext);
 
 	    RemoteOperationResult result = getStatus.execute(client);
-	    
+
         if (result.isSuccess()) {
             // second: get authentication method required by the server
-            mResultData.mVersion = (OwnCloudVersion)(result.getData().get(0));
+            mResultData.mVersion = (OwnCloudVersion) result.getData().get(0);
+            mResultData.hasExtendedSupport = (boolean) result.getData().get(1);
             mResultData.mIsSslConn = result.getCode() == ResultCode.OK_SSL;
             mResultData.mBaseUrl = normalizeProtocolPrefix(mUrl, mResultData.mIsSslConn);
             RemoteOperationResult detectAuthResult = detectAuthorizationMethod(client);
-            
+
             // third: merge results
             if (detectAuthResult.isSuccess()) {
-                mResultData.mAuthMethod = 
-                        (AuthenticationMethod)detectAuthResult.getData().get(0);
+                mResultData.mAuthMethod = (AuthenticationMethod) detectAuthResult.getData().get(0);
                 ArrayList<Object> data = new ArrayList<Object>();
                 data.add(mResultData);
                 result.setData(data);
@@ -100,10 +100,10 @@ public class GetServerInfoOperation extends RemoteOperation {
         return result;
 	}
 
-	
+
     private RemoteOperationResult detectAuthorizationMethod(OwnCloudClient client) {
         Log_OC.d(TAG, "Trying empty authorization to detect authentication method");
-        DetectAuthenticationMethodOperation operation = 
+        DetectAuthenticationMethodOperation operation =
                 new DetectAuthenticationMethodOperation(mContext);
         return operation.execute(client);
     }
@@ -125,7 +125,7 @@ public class GetServerInfoOperation extends RemoteOperation {
         return trimmedUrl;
     }
 
-    
+
     private String normalizeProtocolPrefix(String url, boolean isSslConn) {
         if (!url.toLowerCase(Locale.ROOT).startsWith("http://") &&
                 !url.toLowerCase(Locale.ROOT).startsWith("https://")) {
@@ -137,13 +137,14 @@ public class GetServerInfoOperation extends RemoteOperation {
         }
         return url;
     }
-    
-    
+
+
     public static class ServerInfo {
         public OwnCloudVersion mVersion;
+        public boolean hasExtendedSupport;
         public String mBaseUrl = "";
         public AuthenticationMethod mAuthMethod = AuthenticationMethod.UNKNOWN;
         public boolean mIsSslConn;
     }
-	
+
 }

+ 19 - 0
src/main/java/com/owncloud/android/providers/FileContentProvider.java

@@ -738,6 +738,7 @@ public class FileContentProvider extends ContentProvider {
                        + ProviderTableMeta.CAPABILITIES_VERSION_MICRO + INTEGER
                        + ProviderTableMeta.CAPABILITIES_VERSION_STRING + TEXT
                        + ProviderTableMeta.CAPABILITIES_VERSION_EDITION + TEXT
+                       + ProviderTableMeta.CAPABILITIES_EXTENDED_SUPPORT + INTEGER
                        + ProviderTableMeta.CAPABILITIES_CORE_POLLINTERVAL + INTEGER
                        + ProviderTableMeta.CAPABILITIES_SHARING_API_ENABLED + INTEGER // boolean
                        + ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_ENABLED + INTEGER  // boolean
@@ -1985,6 +1986,24 @@ public class FileContentProvider extends ContentProvider {
             if (!upgraded) {
                 Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
             }
+
+            if (oldVersion < 49 && newVersion >= 49) {
+                Log_OC.i(SQL, "Entering in the #49 add extended support to capabilities table");
+                db.beginTransaction();
+                try {
+                    db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
+                                   ADD_COLUMN + ProviderTableMeta.CAPABILITIES_EXTENDED_SUPPORT + " INTEGER ");
+
+                    upgraded = true;
+                    db.setTransactionSuccessful();
+                } finally {
+                    db.endTransaction();
+                }
+            }
+
+            if (!upgraded) {
+                Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
+            }
         }
 
         @Override

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

@@ -63,11 +63,8 @@ import com.nextcloud.client.appinfo.AppInfo;
 import com.nextcloud.client.di.Injectable;
 import com.nextcloud.client.network.ConnectivityService;
 import com.nextcloud.client.preferences.AppPreferences;
-import com.nextcloud.client.preferences.AppPreferencesImpl;
-import com.owncloud.android.BuildConfig;
 import com.owncloud.android.MainApp;
 import com.owncloud.android.R;
-import com.owncloud.android.datamodel.ArbitraryDataProvider;
 import com.owncloud.android.datamodel.FileDataStorageManager;
 import com.owncloud.android.datamodel.OCFile;
 import com.owncloud.android.datamodel.VirtualFolderType;
@@ -373,27 +370,17 @@ public class FileDisplayActivity extends FileActivity
         Account account = getAccount();
 
         if (getResources().getBoolean(R.bool.show_outdated_server_warning) && account != null) {
-            ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(getContentResolver());
+            OwnCloudVersion serverVersion = AccountUtils.getServerVersionForAccount(account, this);
 
-            int lastSeenVersion = arbitraryDataProvider.getIntegerValue(account,
-                                                                        AppPreferencesImpl.AUTO_PREF__LAST_SEEN_VERSION_CODE);
-
-            if (BuildConfig.VERSION_CODE > lastSeenVersion) {
-                OwnCloudVersion serverVersion = AccountUtils.getServerVersionForAccount(account, this);
-
-                if (serverVersion == null) {
-                    serverVersion = getCapabilities().getVersion();
-                }
-
-                if (MainApp.OUTDATED_SERVER_VERSION.compareTo(serverVersion) >= 0) {
-                    DisplayUtils.showServerOutdatedSnackbar(this);
-                }
+            if (serverVersion == null) {
+                serverVersion = getCapabilities().getVersion();
+            }
 
-                arbitraryDataProvider.storeOrUpdateKeyValue(
-                    account.name,
-                    AppPreferencesImpl.AUTO_PREF__LAST_SEEN_VERSION_CODE,
-                    appInfo.getFormattedVersionCode()
-                );
+            // show outdated warning
+            if (getResources().getBoolean(R.bool.show_outdated_server_warning) &&
+                MainApp.OUTDATED_SERVER_VERSION.compareTo(serverVersion) >= 0 &&
+                getCapabilities().getExtendedSupport().isFalse()) {
+                DisplayUtils.showServerOutdatedSnackbar(this, Snackbar.LENGTH_LONG);
             }
         }
     }

+ 2 - 2
src/main/java/com/owncloud/android/utils/DisplayUtils.java

@@ -783,9 +783,9 @@ public final class DisplayUtils {
         return (int) (dp * ((float) metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT));
     }
 
-    static public void showServerOutdatedSnackbar(Activity activity) {
+    static public void showServerOutdatedSnackbar(Activity activity, int length) {
         Snackbar.make(activity.findViewById(android.R.id.content),
-                R.string.outdated_server, Snackbar.LENGTH_INDEFINITE)
+                      R.string.outdated_server, length)
                 .setAction(R.string.dismiss, v -> {
                 })
                 .show();