浏览代码

add support for slightly modified nc13 background (bigger dots)

Signed-off-by: tobiaskaminsky <tobias@kaminsky.me>
tobiaskaminsky 7 年之前
父节点
当前提交
2e4fcd3f39

+ 13 - 5
src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java

@@ -1,18 +1,18 @@
-/**
+/*
  * ownCloud Android client application
- * <p>
+ * 
  * Copyright (C) 2012  Bartek Przybylski
  * Copyright (C) 2015 ownCloud Inc.
- * <p>
+ * 
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2,
  * as published by the Free Software Foundation.
- * <p>
+ * 
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- * <p>
+ * 
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
@@ -1937,6 +1937,10 @@ public class FileDataStorageManager {
         cv.put(ProviderTableMeta.CAPABILITIES_SERVER_BACKGROUND_URL, capability.getServerBackground());
         cv.put(ProviderTableMeta.CAPABILITIES_SERVER_SLOGAN, capability.getServerSlogan());
         cv.put(ProviderTableMeta.CAPABILITIES_END_TO_END_ENCRYPTION, capability.getEndToEndEncryption().getValue());
+        cv.put(ProviderTableMeta.CAPABILITIES_SERVER_BACKGROUND_DEFAULT, capability.getServerBackgroundDefault()
+                .getValue());
+        cv.put(ProviderTableMeta.CAPABILITIES_SERVER_BACKGROUND_PLAIN, capability.getServerBackgroundPlain()
+                .getValue());
 
         if (capabilityExists(mAccount.name)) {
             if (getContentResolver() != null) {
@@ -2087,6 +2091,10 @@ public class FileDataStorageManager {
             capability.setServerSlogan(c.getString(c.getColumnIndex(ProviderTableMeta.CAPABILITIES_SERVER_SLOGAN)));
             capability.setEndToEndEncryption(CapabilityBooleanType.fromValue(c.getInt(c
                     .getColumnIndex(ProviderTableMeta.CAPABILITIES_END_TO_END_ENCRYPTION))));
+            capability.setServerBackgroundDefault(CapabilityBooleanType.fromValue(
+                    c.getInt(c.getColumnIndex(ProviderTableMeta.CAPABILITIES_SERVER_BACKGROUND_DEFAULT))));
+            capability.setServerBackgroundPlain(CapabilityBooleanType.fromValue(
+                    c.getInt(c.getColumnIndex(ProviderTableMeta.CAPABILITIES_SERVER_BACKGROUND_PLAIN))));
         }
         return capability;
     }

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

@@ -32,7 +32,7 @@ import com.owncloud.android.MainApp;
 public class ProviderMeta {
 
     public static final String DB_NAME = "filelist";
-    public static final int DB_VERSION = 27;
+    public static final int DB_VERSION = 29;
 
     private ProviderMeta() {
     }
@@ -165,6 +165,9 @@ public class ProviderMeta {
         public static final String CAPABILITIES_SERVER_ELEMENT_COLOR = "server_element_color";
         public static final String CAPABILITIES_SERVER_BACKGROUND_URL = "background_url";
         public static final String CAPABILITIES_SERVER_SLOGAN = "server_slogan";
+        public static final String CAPABILITIES_SERVER_BACKGROUND_DEFAULT = "background_default";
+        public static final String CAPABILITIES_SERVER_BACKGROUND_PLAIN = "background_plain";
+        
         public static final String CAPABILITIES_END_TO_END_ENCRYPTION = "end_to_end_encryption";
 
         public static final String CAPABILITIES_DEFAULT_SORT_ORDER = CAPABILITIES_ACCOUNT_NAME

+ 28 - 1
src/main/java/com/owncloud/android/providers/FileContentProvider.java

@@ -798,7 +798,9 @@ public class FileContentProvider extends ContentProvider {
                 + ProviderTableMeta.CAPABILITIES_SERVER_ELEMENT_COLOR + TEXT
                 + ProviderTableMeta.CAPABILITIES_SERVER_SLOGAN + TEXT
                 + ProviderTableMeta.CAPABILITIES_SERVER_BACKGROUND_URL + TEXT
-                + ProviderTableMeta.CAPABILITIES_END_TO_END_ENCRYPTION + " INTEGER );");
+                + ProviderTableMeta.CAPABILITIES_END_TO_END_ENCRYPTION + INTEGER
+                + ProviderTableMeta.CAPABILITIES_SERVER_BACKGROUND_DEFAULT + INTEGER
+                + ProviderTableMeta.CAPABILITIES_SERVER_BACKGROUND_PLAIN + " INTEGER );");
     }
 
     private void createUploadsTable(SQLiteDatabase db) {
@@ -1549,6 +1551,10 @@ public class FileContentProvider extends ContentProvider {
                 Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
             }
 
+            if (!upgraded) {
+                Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
+            }
+
             if (oldVersion < 27 && newVersion >= 27) {
                 Log_OC.i(SQL, "Entering in the #27 Adding token to ocUpload");
                 db.beginTransaction();
@@ -1584,6 +1590,27 @@ public class FileContentProvider extends ContentProvider {
                 Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
             }
 
+            if (oldVersion < 29 && newVersion >= 29) {
+                Log_OC.i(SQL, "Entering in the #29 Adding background default/plain to capabilities");
+                db.beginTransaction();
+                try {
+                    db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
+                            ADD_COLUMN + ProviderTableMeta.CAPABILITIES_SERVER_BACKGROUND_DEFAULT + " INTEGER ");
+
+                    db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
+                            ADD_COLUMN + ProviderTableMeta.CAPABILITIES_SERVER_BACKGROUND_PLAIN + " INTEGER ");
+
+                    upgraded = true;
+                    db.setTransactionSuccessful();
+                } finally {
+                    db.endTransaction();
+                }
+            }
+
+            if (!upgraded) {
+                Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
+            }
+
         }
 
         @Override

+ 53 - 29
src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java

@@ -32,7 +32,6 @@ import android.content.res.Configuration;
 import android.graphics.drawable.ColorDrawable;
 import android.graphics.drawable.Drawable;
 import android.graphics.drawable.LayerDrawable;
-import android.os.Build;
 import android.os.Bundle;
 import android.os.Handler;
 import android.support.design.widget.NavigationView;
@@ -70,6 +69,9 @@ import com.owncloud.android.lib.common.operations.RemoteOperation;
 import com.owncloud.android.lib.common.operations.RemoteOperationResult;
 import com.owncloud.android.lib.common.utils.Log_OC;
 import com.owncloud.android.lib.resources.files.SearchOperation;
+import com.owncloud.android.lib.resources.status.CapabilityBooleanType;
+import com.owncloud.android.lib.resources.status.OCCapability;
+import com.owncloud.android.lib.resources.status.OwnCloudVersion;
 import com.owncloud.android.lib.resources.users.GetRemoteUserInfoOperation;
 import com.owncloud.android.operations.GetCapabilitiesOperarion;
 import com.owncloud.android.ui.TextDrawable;
@@ -1049,38 +1051,60 @@ public abstract class DrawerActivity extends ToolbarActivity implements DisplayU
             final ViewGroup navigationHeader = (ViewGroup) findNavigationViewChildById(R.id.drawer_header_view);
 
             if (navigationHeader != null) {
-                String background = getStorageManager().getCapability(getAccount().name).getServerBackground();
+                OCCapability capability = getStorageManager().getCapability(getAccount().name);
+                String background = capability.getServerBackground();
+                CapabilityBooleanType backgroundDefault = capability.getServerBackgroundDefault();
+                CapabilityBooleanType backgroundPlain = capability.getServerBackgroundPlain();
                 int primaryColor = ThemeUtils.primaryColor(getAccount());
 
-                if (URLUtil.isValidUrl(background) || background.isEmpty()) {
-                    // background image
-                    SimpleTarget target = new SimpleTarget<Drawable>() {
-                        @Override
-                        public void onResourceReady(Drawable resource, GlideAnimation glideAnimation) {
-                            Drawable[] drawables = {new ColorDrawable(primaryColor), resource};
-                            LayerDrawable layerDrawable = new LayerDrawable(drawables);
-                            setNavigationHeaderBackground(layerDrawable, navigationHeader);
-                        }
+                if (backgroundDefault.isTrue() && backgroundPlain.isTrue()) {
+                    // use only solid color
+                    setNavigationHeaderBackground(new ColorDrawable(primaryColor), navigationHeader);
+                } else if (backgroundDefault.isTrue() && backgroundPlain.isFalse()) {
+                    // use nc13 background image with themed color
+                    Drawable[] drawables = {new ColorDrawable(primaryColor),
+                            getResources().getDrawable(R.drawable.background_nc13)};
+                    LayerDrawable layerDrawable = new LayerDrawable(drawables);
+                    setNavigationHeaderBackground(layerDrawable, navigationHeader);
+                } else {
+                    // use url 
+                    if (URLUtil.isValidUrl(background) || background.isEmpty()) {
+                        // background image
+                        SimpleTarget target = new SimpleTarget<Drawable>() {
+                            @Override
+                            public void onResourceReady(Drawable resource, GlideAnimation glideAnimation) {
+                                Drawable[] drawables = {new ColorDrawable(primaryColor), resource};
+                                LayerDrawable layerDrawable = new LayerDrawable(drawables);
+                                setNavigationHeaderBackground(layerDrawable, navigationHeader);
+                            }
 
-                        @Override
-                        public void onLoadFailed(Exception e, Drawable errorDrawable) {
-                            Drawable[] drawables = {new ColorDrawable(primaryColor),
-                                    getResources().getDrawable(R.drawable.background)};
-                            LayerDrawable layerDrawable = new LayerDrawable(drawables);
-                            setNavigationHeaderBackground(layerDrawable, navigationHeader);
+                            @Override
+                            public void onLoadFailed(Exception e, Drawable errorDrawable) {
+                                Drawable[] drawables = {new ColorDrawable(primaryColor), errorDrawable};
+                                LayerDrawable layerDrawable = new LayerDrawable(drawables);
+                                setNavigationHeaderBackground(layerDrawable, navigationHeader);
+                            }
+                        };
+
+                        int backgroundResource;
+                        OwnCloudVersion ownCloudVersion = AccountUtils.getServerVersion(getAccount());
+                        if (ownCloudVersion.compareTo(OwnCloudVersion.nextcloud_13) >= 0) {
+                            backgroundResource = R.drawable.background_nc13;
+                        } else {
+                            backgroundResource = R.drawable.background;
                         }
-                    };
 
-                    Glide.with(this)
-                            .load(background)
-                            .centerCrop()
-                            .placeholder(R.drawable.background)
-                            .error(R.drawable.background)
-                            .crossFade()
-                            .into(target);
-                } else {
-                    // plain color
-                    setNavigationHeaderBackground(new ColorDrawable(primaryColor), navigationHeader);
+                        Glide.with(this)
+                                .load(background)
+                                .centerCrop()
+                                .placeholder(backgroundResource)
+                                .error(backgroundResource)
+                                .crossFade()
+                                .into(target);
+                    } else {
+                        // plain color
+                        setNavigationHeaderBackground(new ColorDrawable(primaryColor), navigationHeader);
+                    }
                 }
             }
         }
@@ -1350,7 +1374,7 @@ public abstract class DrawerActivity extends ToolbarActivity implements DisplayU
 
                     int count = arbitraryDataProvider.getIntegerValue(FilesSyncHelper.GLOBAL,
                             FileActivity.APP_OPENED_COUNT);
-                    
+
                     if (count > 10 || count == -1 || force) {
                         if (force) {
                             Log_OC.d("ExternalLinks", "force update");

二进制
src/main/res/drawable-xxxhdpi/background_nc13.png