Drawer header
This commit is contained in:
Stefan Niedermann 2020-05-01 22:33:39 +02:00
parent e908abf9b8
commit 674621b11e
4 changed files with 46 additions and 9 deletions

View file

@ -81,7 +81,7 @@ public class NoteListWidgetConfigurationActivity extends LockedActivity {
RecyclerView recyclerView;
RecyclerView.LayoutManager layoutManager;
adapterCategories = new NavigationAdapter(new NavigationAdapter.ClickListener() {
adapterCategories = new NavigationAdapter(this, new NavigationAdapter.ClickListener() {
@Override
public void onItemClick(NavigationAdapter.NavigationItem item) {
SharedPreferences.Editor sp = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit();

View file

@ -4,6 +4,9 @@ import android.app.SearchManager;
import android.content.Intent;
import android.content.res.Configuration;
import android.database.sqlite.SQLiteConstraintException;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
@ -68,6 +71,7 @@ import it.niedermann.owncloud.notes.persistence.LoadNotesListTask;
import it.niedermann.owncloud.notes.persistence.LoadNotesListTask.NotesLoadedListener;
import it.niedermann.owncloud.notes.persistence.NoteServerSyncHelper;
import it.niedermann.owncloud.notes.persistence.NotesDatabase;
import it.niedermann.owncloud.notes.util.ColorUtil;
import it.niedermann.owncloud.notes.util.NoteUtil;
import static it.niedermann.owncloud.notes.util.SSOUtil.askForNewAccount;
@ -139,6 +143,7 @@ public class NotesListViewActivity extends LockedActivity implements ItemAdapter
activityBinding = ActivityNotesListViewBinding.bind(binding.activityNotesListView.getRoot());
setContentView(binding.getRoot());
this.coordinatorLayout = binding.activityNotesListView.activityNotesListView;
this.swipeRefreshLayout = binding.activityNotesListView.swiperefreshlayout;
this.fabCreate = binding.activityNotesListView.fabCreate;
@ -358,7 +363,7 @@ public class NotesListViewActivity extends LockedActivity implements ItemAdapter
private void setupNavigationList(final String selectedItem) {
itemRecent = new NavigationItem(ADAPTER_KEY_RECENT, getString(R.string.label_all_notes), null, R.drawable.ic_access_time_grey600_24dp);
itemFavorites = new NavigationItem(ADAPTER_KEY_STARRED, getString(R.string.label_favorites), null, R.drawable.ic_star_yellow_24dp);
adapterCategories = new NavigationAdapter(new NavigationAdapter.ClickListener() {
adapterCategories = new NavigationAdapter(this, new NavigationAdapter.ClickListener() {
@Override
public void onItemClick(NavigationItem item) {
selectItem(item, true);
@ -433,7 +438,26 @@ public class NotesListViewActivity extends LockedActivity implements ItemAdapter
applyBrandToPrimaryToolbar(mainColor, textColor, activityBinding.notesListActivityActionBar);
applyBrandToFAB(mainColor, textColor, activityBinding.fabCreate);
binding.headerViewBackground.setBackgroundColor(mainColor);
binding.appName.setTextColor(textColor);
binding.account.setTextColor(textColor);
final boolean isDarkTextColor = ColorUtil.isColorDark(textColor);
if (isDarkTextColor) {
binding.appName.setShadowLayer(2, 0.5f, 0, Color.WHITE);
binding.account.setShadowLayer(2, 0.5f, 0, Color.WHITE);
} else {
binding.appName.setShadowLayer(2, 0.5f, 0, Color.BLACK);
binding.account.setShadowLayer(2, 0.5f, 0, Color.BLACK);
}
final Drawable overflowDrawable = binding.accountArrow.getDrawable();
if (overflowDrawable != null) {
overflowDrawable.setColorFilter(textColor, PorterDuff.Mode.SRC_ATOP);
binding.accountArrow.setImageDrawable(overflowDrawable);
}
adapter.applyBrand(mainColor, textColor);
adapterCategories.applyBrand(mainColor, textColor);
}
private class LoadCategoryListTask extends AsyncTask<Void, Void, List<NavigationItem>> {
@ -526,12 +550,12 @@ public class NotesListViewActivity extends LockedActivity implements ItemAdapter
final NavigationItem itemSettings = new NavigationItem("settings", getString(R.string.action_settings), null, R.drawable.ic_settings_grey600_24dp);
final NavigationItem itemAbout = new NavigationItem("about", getString(R.string.simple_about), null, R.drawable.ic_info_outline_grey600_24dp);
ArrayList<NavigationItem> itemsMenu = new ArrayList<>();
ArrayList<NavigationItem> itemsMenu = new ArrayList<>(3);
itemsMenu.add(itemTrashbin);
itemsMenu.add(itemSettings);
itemsMenu.add(itemAbout);
NavigationAdapter adapterMenu = new NavigationAdapter(new NavigationAdapter.ClickListener() {
NavigationAdapter adapterMenu = new NavigationAdapter(this, new NavigationAdapter.ClickListener() {
@Override
public void onItemClick(NavigationItem item) {
if (itemSettings.equals(item)) {
@ -661,7 +685,7 @@ public class NotesListViewActivity extends LockedActivity implements ItemAdapter
return true;
}
});
return true;
return super.onCreateOptionsMenu(menu);
}
@Override

View file

@ -75,8 +75,7 @@ public class BrandingUtil {
* Since we may collide with dark theme in this area, we have to make sure that the color is visible depending on the background
*/
@ColorInt
public static int
getSecondaryForegroundColorDependingOnTheme(@NonNull Context context, @ColorInt int mainColor) {
public static int getSecondaryForegroundColorDependingOnTheme(@NonNull Context context, @ColorInt int mainColor) {
final boolean isDarkTheme = Notes.getAppTheme(context) == DarkModeSetting.DARK;
if (isDarkTheme && !contrastRatioIsSufficient(mainColor, Color.BLACK)) {
Log.v(TAG, "Contrast ratio between brand color " + String.format("#%06X", (0xFFFFFF & mainColor)) + " and dark theme is too low. Falling back to WHITE as brand color.");

View file

@ -1,5 +1,6 @@
package it.niedermann.owncloud.notes.model;
import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
@ -7,6 +8,7 @@ import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.ColorInt;
import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@ -17,11 +19,16 @@ import java.util.ArrayList;
import java.util.List;
import it.niedermann.owncloud.notes.R;
import it.niedermann.owncloud.notes.branding.BrandingUtil;
import it.niedermann.owncloud.notes.databinding.ItemNavigationBinding;
import it.niedermann.owncloud.notes.util.NoteUtil;
public class NavigationAdapter extends RecyclerView.Adapter<NavigationAdapter.ViewHolder> {
@NonNull
private final Context context;
@ColorInt
private int mainColor;
@DrawableRes
public static final int ICON_FOLDER = R.drawable.ic_folder_grey600_24dp;
@DrawableRes
@ -35,6 +42,11 @@ public class NavigationAdapter extends RecyclerView.Adapter<NavigationAdapter.Vi
@DrawableRes
public static final int ICON_SUB_MULTIPLE = R.drawable.ic_create_new_folder_grey600_18dp;
public void applyBrand(int mainColor, int textColor) {
this.mainColor = BrandingUtil.getSecondaryForegroundColorDependingOnTheme(context, mainColor);
notifyDataSetChanged();
}
public static class NavigationItem {
@NonNull
public String id;
@ -90,7 +102,7 @@ public class NavigationAdapter extends RecyclerView.Adapter<NavigationAdapter.Vi
icon.setVisibility(View.GONE);
}
view.setBackgroundColor(isSelected ? view.getResources().getColor(R.color.bg_highlighted) : Color.TRANSPARENT);
int textColor = view.getResources().getColor(isSelected ? R.color.primary_dark : R.color.fg_default);
int textColor = isSelected ? mainColor : view.getResources().getColor(R.color.fg_default);
name.setTextColor(textColor);
count.setTextColor(textColor);
@ -110,7 +122,9 @@ public class NavigationAdapter extends RecyclerView.Adapter<NavigationAdapter.Vi
@NonNull
private final ClickListener clickListener;
public NavigationAdapter(@NonNull ClickListener clickListener) {
public NavigationAdapter(@NonNull Context context, @NonNull ClickListener clickListener) {
this.context = context;
this.mainColor = BrandingUtil.getSecondaryForegroundColorDependingOnTheme(context, BrandingUtil.readBrandMainColor(context));
this.clickListener = clickListener;
}