From d84c13a1761a6cca2e5aba6d24764777ad4dada6 Mon Sep 17 00:00:00 2001 From: tobiasKaminsky Date: Mon, 22 May 2017 14:57:57 +0200 Subject: [PATCH] use background image from theming app in drawer --- .../datamodel/FileDataStorageManager.java | 3 ++ .../com/owncloud/android/db/ProviderMeta.java | 1 + .../providers/FileContentProvider.java | 5 ++- .../android/ui/activity/DrawerActivity.java | 40 ++++++++++++++++++- .../owncloud/android/utils/DisplayUtils.java | 17 ++++---- src/main/res/layout/drawer_header.xml | 1 + 6 files changed, 57 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java b/src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java index c641261706..64ce14cffa 100644 --- a/src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java +++ b/src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java @@ -1910,6 +1910,7 @@ public class FileDataStorageManager { cv.put(ProviderTableMeta.CAPABILITIES_EXTERNAL_LINKS, capability.getExternalLinks().getValue()); cv.put(ProviderTableMeta.CAPABILITIES_SERVER_NAME, capability.getServerName()); cv.put(ProviderTableMeta.CAPABILITIES_SERVER_COLOR, capability.getServerColor()); + cv.put(ProviderTableMeta.CAPABILITIES_SERVER_BACKGROUND_URL, capability.getServerBackground()); if (capabilityExists(mAccount.name)) { if (getContentResolver() != null) { @@ -2051,6 +2052,8 @@ public class FileDataStorageManager { .getColumnIndex(ProviderTableMeta.CAPABILITIES_EXTERNAL_LINKS)))); capability.setServerName(c.getString(c.getColumnIndex(ProviderTableMeta.CAPABILITIES_SERVER_NAME))); capability.setServerColor(c.getString(c.getColumnIndex(ProviderTableMeta.CAPABILITIES_SERVER_COLOR))); + capability.setServerBackground(c.getString(c.getColumnIndex( + ProviderTableMeta.CAPABILITIES_SERVER_BACKGROUND_URL))); } return capability; } diff --git a/src/main/java/com/owncloud/android/db/ProviderMeta.java b/src/main/java/com/owncloud/android/db/ProviderMeta.java index bf37de8a58..9242bdbbdb 100644 --- a/src/main/java/com/owncloud/android/db/ProviderMeta.java +++ b/src/main/java/com/owncloud/android/db/ProviderMeta.java @@ -149,6 +149,7 @@ public class ProviderMeta { public static final String CAPABILITIES_EXTERNAL_LINKS = "external_links"; public static final String CAPABILITIES_SERVER_NAME = "server_name"; public static final String CAPABILITIES_SERVER_COLOR = "server_color"; + public static final String CAPABILITIES_SERVER_BACKGROUND_URL = "background_url"; public static final String CAPABILITIES_DEFAULT_SORT_ORDER = CAPABILITIES_ACCOUNT_NAME + " collate nocase asc"; diff --git a/src/main/java/com/owncloud/android/providers/FileContentProvider.java b/src/main/java/com/owncloud/android/providers/FileContentProvider.java index 3dfe873d80..32bfee5b09 100644 --- a/src/main/java/com/owncloud/android/providers/FileContentProvider.java +++ b/src/main/java/com/owncloud/android/providers/FileContentProvider.java @@ -1019,6 +1019,8 @@ public class FileContentProvider extends ContentProvider { ADD_COLUMN + ProviderTableMeta.CAPABILITIES_SERVER_NAME + " TEXT "); db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME + ADD_COLUMN + ProviderTableMeta.CAPABILITIES_SERVER_COLOR + " TEXT "); + db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME + + ADD_COLUMN + ProviderTableMeta.CAPABILITIES_SERVER_BACKGROUND_URL + " TEXT "); upgraded = true; db.setTransactionSuccessful(); } finally { @@ -1111,7 +1113,8 @@ public class FileContentProvider extends ContentProvider { + ProviderTableMeta.CAPABILITIES_FILES_DROP + INTEGER // boolean + ProviderTableMeta.CAPABILITIES_EXTERNAL_LINKS + INTEGER // boolean + ProviderTableMeta.CAPABILITIES_SERVER_NAME + TEXT - + ProviderTableMeta.CAPABILITIES_SERVER_COLOR + " TEXT );"); + + ProviderTableMeta.CAPABILITIES_SERVER_COLOR + TEXT + + ProviderTableMeta.CAPABILITIES_SERVER_BACKGROUND_URL + " TEXT );"); } private void createUploadsTable(SQLiteDatabase db) { diff --git a/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java b/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java index fe7b8ec9b1..c51e53a994 100644 --- a/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java +++ b/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java @@ -45,6 +45,7 @@ import android.widget.LinearLayout; import android.widget.ProgressBar; import android.widget.TextView; +import com.bumptech.glide.Glide; import com.bumptech.glide.request.animation.GlideAnimation; import com.bumptech.glide.request.target.SimpleTarget; import com.owncloud.android.MainApp; @@ -1000,6 +1001,36 @@ public abstract class DrawerActivity extends ToolbarActivity implements DisplayU } } + public void updateHeaderBackground() { + if (getAccount() != null && + getStorageManager().getCapability(getAccount().name).getServerBackground() != null) { + String backgroundUrl = getStorageManager().getCapability(getAccount().name).getServerBackground(); + + final LinearLayout navigationHeader = (LinearLayout) findNavigationViewChildById(R.id.drawer_header_view); + + SimpleTarget target = new SimpleTarget() { + @Override + public void onResourceReady(Drawable resource, GlideAnimation glideAnimation) { + if (navigationHeader != null) { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { + navigationHeader.setBackgroundDrawable(resource); + } else { + navigationHeader.setBackground(resource); + } + } + } + }; + + Glide.with(this) + .load(backgroundUrl) + .centerCrop() + .placeholder(R.drawable.background) + .error(R.drawable.background) + .crossFade() + .into(target); + } + } + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -1058,6 +1089,7 @@ public abstract class DrawerActivity extends ToolbarActivity implements DisplayU updateAccountList(); updateExternalLinksInDrawer(); updateQuotaLink(); + updateHeaderBackground(); } @Override @@ -1111,7 +1143,13 @@ public abstract class DrawerActivity extends ToolbarActivity implements DisplayU * @return The view if found or null otherwise. */ private View findNavigationViewChildById(int id) { - return ((NavigationView) findViewById(R.id.nav_view)).getHeaderView(0).findViewById(id); + NavigationView view = ((NavigationView) findViewById(R.id.nav_view)); + + if (view != null) { + return view.getHeaderView(0).findViewById(id); + } else { + return null; + } } /** diff --git a/src/main/java/com/owncloud/android/utils/DisplayUtils.java b/src/main/java/com/owncloud/android/utils/DisplayUtils.java index fce3222a8a..6102b7ea65 100644 --- a/src/main/java/com/owncloud/android/utils/DisplayUtils.java +++ b/src/main/java/com/owncloud/android/utils/DisplayUtils.java @@ -693,18 +693,19 @@ public class DisplayUtils { } public static Drawable tintDrawable(@DrawableRes int id, @ColorRes int color) { - int colorToUse; + int colorToUse = MainApp.getAppContext().getResources().getColor(color); Account account = AccountUtils.getCurrentOwnCloudAccount(MainApp.getAppContext()); - Context context = MainApp.getAppContext(); - FileDataStorageManager storageManager = new FileDataStorageManager(account, context.getContentResolver()); - OCCapability capability = storageManager.getCapability(account.name); + if (account != null) { + Context context = MainApp.getAppContext(); - if (capability.getServerColor().isEmpty()) { - colorToUse = MainApp.getAppContext().getResources().getColor(color); - } else { - colorToUse = Color.parseColor(capability.getServerColor()); + FileDataStorageManager storageManager = new FileDataStorageManager(account, context.getContentResolver()); + OCCapability capability = storageManager.getCapability(account.name); + + if (!capability.getServerColor().isEmpty()) { + colorToUse = Color.parseColor(capability.getServerColor()); + } } Drawable drawable = ResourcesCompat.getDrawable(MainApp.getAppContext().getResources(), id, null); diff --git a/src/main/res/layout/drawer_header.xml b/src/main/res/layout/drawer_header.xml index 7359a42b87..374ce6fb4b 100644 --- a/src/main/res/layout/drawer_header.xml +++ b/src/main/res/layout/drawer_header.xml @@ -19,6 +19,7 @@ License along with this program. If not, see . -->