mirror of
https://github.com/nextcloud/android.git
synced 2024-11-27 17:46:37 +03:00
use background image from theming app in drawer
This commit is contained in:
parent
b72d900d7d
commit
d84c13a176
6 changed files with 57 additions and 10 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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<Drawable>() {
|
||||
@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 <code>null</code> 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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
License along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
-->
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/drawer_header_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/nav_drawer_header_height"
|
||||
android:background="@drawable/background"
|
||||
|
|
Loading…
Reference in a new issue