mirror of
https://github.com/nextcloud/notes-android.git
synced 2024-11-23 21:36:07 +03:00
parent
e908abf9b8
commit
674621b11e
4 changed files with 46 additions and 9 deletions
|
@ -81,7 +81,7 @@ public class NoteListWidgetConfigurationActivity extends LockedActivity {
|
||||||
RecyclerView recyclerView;
|
RecyclerView recyclerView;
|
||||||
RecyclerView.LayoutManager layoutManager;
|
RecyclerView.LayoutManager layoutManager;
|
||||||
|
|
||||||
adapterCategories = new NavigationAdapter(new NavigationAdapter.ClickListener() {
|
adapterCategories = new NavigationAdapter(this, new NavigationAdapter.ClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onItemClick(NavigationAdapter.NavigationItem item) {
|
public void onItemClick(NavigationAdapter.NavigationItem item) {
|
||||||
SharedPreferences.Editor sp = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit();
|
SharedPreferences.Editor sp = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit();
|
||||||
|
|
|
@ -4,6 +4,9 @@ import android.app.SearchManager;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.database.sqlite.SQLiteConstraintException;
|
import android.database.sqlite.SQLiteConstraintException;
|
||||||
|
import android.graphics.Color;
|
||||||
|
import android.graphics.PorterDuff;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
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.LoadNotesListTask.NotesLoadedListener;
|
||||||
import it.niedermann.owncloud.notes.persistence.NoteServerSyncHelper;
|
import it.niedermann.owncloud.notes.persistence.NoteServerSyncHelper;
|
||||||
import it.niedermann.owncloud.notes.persistence.NotesDatabase;
|
import it.niedermann.owncloud.notes.persistence.NotesDatabase;
|
||||||
|
import it.niedermann.owncloud.notes.util.ColorUtil;
|
||||||
import it.niedermann.owncloud.notes.util.NoteUtil;
|
import it.niedermann.owncloud.notes.util.NoteUtil;
|
||||||
|
|
||||||
import static it.niedermann.owncloud.notes.util.SSOUtil.askForNewAccount;
|
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());
|
activityBinding = ActivityNotesListViewBinding.bind(binding.activityNotesListView.getRoot());
|
||||||
|
|
||||||
setContentView(binding.getRoot());
|
setContentView(binding.getRoot());
|
||||||
|
|
||||||
this.coordinatorLayout = binding.activityNotesListView.activityNotesListView;
|
this.coordinatorLayout = binding.activityNotesListView.activityNotesListView;
|
||||||
this.swipeRefreshLayout = binding.activityNotesListView.swiperefreshlayout;
|
this.swipeRefreshLayout = binding.activityNotesListView.swiperefreshlayout;
|
||||||
this.fabCreate = binding.activityNotesListView.fabCreate;
|
this.fabCreate = binding.activityNotesListView.fabCreate;
|
||||||
|
@ -358,7 +363,7 @@ public class NotesListViewActivity extends LockedActivity implements ItemAdapter
|
||||||
private void setupNavigationList(final String selectedItem) {
|
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);
|
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);
|
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
|
@Override
|
||||||
public void onItemClick(NavigationItem item) {
|
public void onItemClick(NavigationItem item) {
|
||||||
selectItem(item, true);
|
selectItem(item, true);
|
||||||
|
@ -433,7 +438,26 @@ public class NotesListViewActivity extends LockedActivity implements ItemAdapter
|
||||||
applyBrandToPrimaryToolbar(mainColor, textColor, activityBinding.notesListActivityActionBar);
|
applyBrandToPrimaryToolbar(mainColor, textColor, activityBinding.notesListActivityActionBar);
|
||||||
applyBrandToFAB(mainColor, textColor, activityBinding.fabCreate);
|
applyBrandToFAB(mainColor, textColor, activityBinding.fabCreate);
|
||||||
binding.headerViewBackground.setBackgroundColor(mainColor);
|
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);
|
adapter.applyBrand(mainColor, textColor);
|
||||||
|
adapterCategories.applyBrand(mainColor, textColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class LoadCategoryListTask extends AsyncTask<Void, Void, List<NavigationItem>> {
|
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 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);
|
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(itemTrashbin);
|
||||||
itemsMenu.add(itemSettings);
|
itemsMenu.add(itemSettings);
|
||||||
itemsMenu.add(itemAbout);
|
itemsMenu.add(itemAbout);
|
||||||
|
|
||||||
NavigationAdapter adapterMenu = new NavigationAdapter(new NavigationAdapter.ClickListener() {
|
NavigationAdapter adapterMenu = new NavigationAdapter(this, new NavigationAdapter.ClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onItemClick(NavigationItem item) {
|
public void onItemClick(NavigationItem item) {
|
||||||
if (itemSettings.equals(item)) {
|
if (itemSettings.equals(item)) {
|
||||||
|
@ -661,7 +685,7 @@ public class NotesListViewActivity extends LockedActivity implements ItemAdapter
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return true;
|
return super.onCreateOptionsMenu(menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -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
|
* 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
|
@ColorInt
|
||||||
public static int
|
public static int getSecondaryForegroundColorDependingOnTheme(@NonNull Context context, @ColorInt int mainColor) {
|
||||||
getSecondaryForegroundColorDependingOnTheme(@NonNull Context context, @ColorInt int mainColor) {
|
|
||||||
final boolean isDarkTheme = Notes.getAppTheme(context) == DarkModeSetting.DARK;
|
final boolean isDarkTheme = Notes.getAppTheme(context) == DarkModeSetting.DARK;
|
||||||
if (isDarkTheme && !contrastRatioIsSufficient(mainColor, Color.BLACK)) {
|
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.");
|
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.");
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package it.niedermann.owncloud.notes.model;
|
package it.niedermann.owncloud.notes.model;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
@ -7,6 +8,7 @@ import android.view.ViewGroup;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import androidx.annotation.ColorInt;
|
||||||
import androidx.annotation.DrawableRes;
|
import androidx.annotation.DrawableRes;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
@ -17,11 +19,16 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import it.niedermann.owncloud.notes.R;
|
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.databinding.ItemNavigationBinding;
|
||||||
import it.niedermann.owncloud.notes.util.NoteUtil;
|
import it.niedermann.owncloud.notes.util.NoteUtil;
|
||||||
|
|
||||||
public class NavigationAdapter extends RecyclerView.Adapter<NavigationAdapter.ViewHolder> {
|
public class NavigationAdapter extends RecyclerView.Adapter<NavigationAdapter.ViewHolder> {
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
private final Context context;
|
||||||
|
@ColorInt
|
||||||
|
private int mainColor;
|
||||||
@DrawableRes
|
@DrawableRes
|
||||||
public static final int ICON_FOLDER = R.drawable.ic_folder_grey600_24dp;
|
public static final int ICON_FOLDER = R.drawable.ic_folder_grey600_24dp;
|
||||||
@DrawableRes
|
@DrawableRes
|
||||||
|
@ -35,6 +42,11 @@ public class NavigationAdapter extends RecyclerView.Adapter<NavigationAdapter.Vi
|
||||||
@DrawableRes
|
@DrawableRes
|
||||||
public static final int ICON_SUB_MULTIPLE = R.drawable.ic_create_new_folder_grey600_18dp;
|
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 {
|
public static class NavigationItem {
|
||||||
@NonNull
|
@NonNull
|
||||||
public String id;
|
public String id;
|
||||||
|
@ -90,7 +102,7 @@ public class NavigationAdapter extends RecyclerView.Adapter<NavigationAdapter.Vi
|
||||||
icon.setVisibility(View.GONE);
|
icon.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
view.setBackgroundColor(isSelected ? view.getResources().getColor(R.color.bg_highlighted) : Color.TRANSPARENT);
|
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);
|
name.setTextColor(textColor);
|
||||||
count.setTextColor(textColor);
|
count.setTextColor(textColor);
|
||||||
|
@ -110,7 +122,9 @@ public class NavigationAdapter extends RecyclerView.Adapter<NavigationAdapter.Vi
|
||||||
@NonNull
|
@NonNull
|
||||||
private final ClickListener clickListener;
|
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;
|
this.clickListener = clickListener;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue