Skip to content

Commit

Permalink
Migrate to DynamicScheme
Browse files Browse the repository at this point in the history
Signed-off-by: Andy Scherzinger <[email protected]>
  • Loading branch information
AndyScherzinger committed Mar 13, 2024
1 parent 8f14fa9 commit 1f72721
Showing 1 changed file with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import androidx.annotation.ColorInt;
import androidx.annotation.IdRes;
import androidx.annotation.NonNull;
import androidx.appcompat.widget.AppCompatAutoCompleteTextView;
import androidx.appcompat.widget.SearchView;
import androidx.appcompat.widget.Toolbar;
import androidx.core.content.ContextCompat;
Expand All @@ -34,6 +35,7 @@
import com.nextcloud.android.common.ui.theme.ViewThemeUtilsBase;
import com.nextcloud.android.common.ui.theme.utils.MaterialViewThemeUtils;

import dynamiccolor.MaterialDynamicColors;
import it.niedermann.android.util.ColorUtil;
import it.niedermann.owncloud.notes.R;
import it.niedermann.owncloud.notes.main.navigation.NavigationItem;
Expand All @@ -48,14 +50,16 @@ public NotesViewThemeUtils(@NonNull MaterialSchemes schemes) {
super(schemes);
}

private final MaterialDynamicColors dynamicColor = new MaterialDynamicColors();

/**
* The Notes app uses custom navigation view items because they have several features which are
* not covered by {@link NavigationItem}.
*/
public void colorNavigationViewItem(@NonNull View view) {
withScheme(view, scheme -> {
view.setBackgroundTintList(buildColorStateList(
new Pair<>(android.R.attr.state_selected, scheme.getSecondaryContainer()),
new Pair<>(android.R.attr.state_selected, dynamicColor.secondaryContainer().getArgb(scheme)),
new Pair<>(-android.R.attr.state_selected, Color.TRANSPARENT)
));
return view;
Expand All @@ -69,8 +73,8 @@ public void colorNavigationViewItem(@NonNull View view) {
public void colorNavigationViewItemIcon(@NonNull ImageView view) {
withScheme(view, scheme -> {
view.setImageTintList(buildColorStateList(
new Pair<>(android.R.attr.state_selected, scheme.getOnSecondaryContainer()),
new Pair<>(-android.R.attr.state_selected, scheme.getOnSurfaceVariant())
new Pair<>(android.R.attr.state_selected, dynamicColor.onSecondaryContainer().getArgb(scheme)),
new Pair<>(-android.R.attr.state_selected, dynamicColor.onSurfaceVariant().getArgb(scheme))
));
return view;
});
Expand All @@ -83,8 +87,8 @@ public void colorNavigationViewItemIcon(@NonNull ImageView view) {
public void colorNavigationViewItemText(@NonNull TextView view) {
withScheme(view, scheme -> {
view.setTextColor(buildColorStateList(
new Pair<>(android.R.attr.state_selected, scheme.getOnSecondaryContainer()),
new Pair<>(-android.R.attr.state_selected, scheme.getOnSurfaceVariant())
new Pair<>(android.R.attr.state_selected, dynamicColor.onSecondaryContainer().getArgb(scheme)),
new Pair<>(-android.R.attr.state_selected, dynamicColor.onSurfaceVariant().getArgb(scheme))
));
return view;
});
Expand Down Expand Up @@ -167,7 +171,7 @@ public int getTextHighlightBackgroundColor(@NonNull Context context,
@Deprecated
public void themeSearchCardView(@NonNull MaterialCardView searchBarWrapper) {
withScheme(searchBarWrapper, scheme -> {
searchBarWrapper.setBackgroundTintList(ColorStateList.valueOf(scheme.getSurface()));
searchBarWrapper.setBackgroundTintList(ColorStateList.valueOf(dynamicColor.surface().getArgb(scheme)));
return searchBarWrapper;
});
}
Expand All @@ -179,8 +183,8 @@ public void themeSearchCardView(@NonNull MaterialCardView searchBarWrapper) {
@Deprecated
public void themeSearchToolbar(@NonNull MaterialToolbar toolbar) {
withScheme(toolbar, scheme -> {
toolbar.setNavigationIconTint(scheme.getOnSurface());
toolbar.setTitleTextColor(scheme.getOnSurface());
toolbar.setNavigationIconTint(dynamicColor.onSurface().getArgb(scheme));
toolbar.setTitleTextColor(dynamicColor.onSurface().getArgb(scheme));
return toolbar;
});
}
Expand All @@ -193,15 +197,15 @@ public void themeSearchToolbar(@NonNull MaterialToolbar toolbar) {
public void themeToolbarSearchView(@NonNull SearchView searchView) {
withScheme(searchView, scheme -> {
// hacky as no default way is provided
final var editText = (SearchView.SearchAutoComplete) searchView
final var editText = (AppCompatAutoCompleteTextView) searchView
.findViewById(androidx.appcompat.R.id.search_src_text);
final var closeButton = (ImageView) searchView.findViewById(androidx.appcompat.R.id.search_close_btn);
final var searchButton = (ImageView) searchView.findViewById(androidx.appcompat.R.id.search_button);
editText.setHintTextColor(scheme.getOnSurfaceVariant());
editText.setHighlightColor(scheme.getInverseOnSurface());
editText.setTextColor(scheme.getOnSurface());
closeButton.setColorFilter(scheme.getOnSurface());
searchButton.setColorFilter(scheme.getOnSurface());
editText.setHintTextColor(dynamicColor.onSurfaceVariant().getArgb(scheme));
editText.setHighlightColor(dynamicColor.inverseOnSurface().getArgb(scheme));
editText.setTextColor(dynamicColor.onSurface().getArgb(scheme));
closeButton.setColorFilter(dynamicColor.onSurface().getArgb(scheme));
searchButton.setColorFilter(dynamicColor.onSurface().getArgb(scheme));
return searchView;
});
}
Expand Down

0 comments on commit 1f72721

Please sign in to comment.