Skip to content

Commit fe4d898

Browse files
style(M3): adapt to latest M3 styling
Signed-off-by: Andy Scherzinger <[email protected]>
1 parent 182ebb0 commit fe4d898

20 files changed

+987
-384
lines changed

app/src/main/java/it/niedermann/owncloud/notes/branding/NotesViewThemeUtils.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,10 @@ public void themeCard(@NonNull MaterialCardView view) {
255255
new Pair<>(android.R.attr.state_activated, dynamicColor.secondaryContainer().getArgb(scheme)),
256256
new Pair<>(-android.R.attr.state_activated, dynamicColor.surface().getArgb(scheme)))
257257
);
258-
view.setStrokeColor(dynamicColor.outlineVariant().getArgb(scheme));
258+
view.setStrokeColor(buildColorStateList(
259+
new Pair<>(android.R.attr.state_activated, dynamicColor.onSecondaryContainer().getArgb(scheme)),
260+
new Pair<>(-android.R.attr.state_activated, dynamicColor.outlineVariant().getArgb(scheme)))
261+
);
259262
return view;
260263
});
261264
}

app/src/main/java/it/niedermann/owncloud/notes/main/MainActivity.java

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -226,20 +226,20 @@ protected void onCreate(Bundle savedInstanceState) {
226226

227227
switch (selectedCategory.getType()) {
228228
case RECENT -> {
229-
activityBinding.searchText.setText(getString(R.string.search_in_all));
229+
activityBinding.searchBar.searchText.setText(getString(R.string.search_in_all));
230230
}
231231
case FAVORITES -> {
232-
activityBinding.searchText.setText(getString(R.string.search_in_category, getString(R.string.label_favorites)));
232+
activityBinding.searchBar.searchText.setText(getString(R.string.search_in_category, getString(R.string.label_favorites)));
233233
}
234234
case UNCATEGORIZED -> {
235-
activityBinding.searchText.setText(getString(R.string.search_in_category, getString(R.string.action_uncategorized)));
235+
activityBinding.searchBar.searchText.setText(getString(R.string.search_in_category, getString(R.string.action_uncategorized)));
236236
}
237237
default -> {
238238
final String category = selectedCategory.getCategory();
239239
if (category == null) {
240240
throw new IllegalStateException(NavigationCategory.class.getSimpleName() + " type is " + DEFAULT_CATEGORY + ", but category is null.");
241241
}
242-
activityBinding.searchText.setText(getString(R.string.search_in_category, NoteUtil.extendCategory(category)));
242+
activityBinding.searchBar.searchText.setText(getString(R.string.search_in_category, NoteUtil.extendCategory(category)));
243243
}
244244
}
245245

@@ -280,7 +280,7 @@ protected void onCreate(Bundle savedInstanceState) {
280280
mainViewModel.getSearchTerm().observe(this, adapter::setHighlightSearchQuery);
281281
mainViewModel.getCategorySortingMethodOfSelectedCategory().observe(this, methodOfCategory -> {
282282
updateSortMethodIcon(methodOfCategory.second);
283-
activityBinding.sortingMethod.setOnClickListener((v) -> {
283+
activityBinding.searchBar.sortingMethod.setOnClickListener((v) -> {
284284
if (methodOfCategory.first != null) {
285285
int newId = 0;
286286
if (methodOfCategory.second != null)
@@ -303,7 +303,7 @@ protected void onCreate(Bundle savedInstanceState) {
303303
.placeholder(R.drawable.ic_account_circle_grey_24dp)
304304
.error(R.drawable.ic_account_circle_grey_24dp)
305305
.apply(RequestOptions.circleCropTransform())
306-
.into(activityBinding.launchAccountSwitcher);
306+
.into(activityBinding.searchBar.launchAccountSwitcher);
307307

308308
mainViewModel.synchronizeNotes(this, nextAccount, new IResponseCallback<>() {
309309
@Override
@@ -331,7 +331,7 @@ public void onError(@NonNull Throwable t) {
331331
}
332332
});
333333
fabCreate.show();
334-
activityBinding.launchAccountSwitcher.setOnClickListener((v) -> AccountSwitcherDialog.newInstance(nextAccount.getId()).show(getSupportFragmentManager(), AccountSwitcherDialog.class.getSimpleName()));
334+
activityBinding.searchBar.launchAccountSwitcher.setOnClickListener((v) -> AccountSwitcherDialog.newInstance(nextAccount.getId()).show(getSupportFragmentManager(), AccountSwitcherDialog.class.getSimpleName()));
335335

336336
if (menuAdapter == null) {
337337
menuAdapter = new MenuAdapter(getApplicationContext(), nextAccount, REQUEST_CODE_SERVER_SETTINGS, (menuItem) -> {
@@ -484,13 +484,13 @@ protected void onRestoreInstanceState(@NonNull Bundle savedInstanceState) {
484484

485485
private void setupToolbars() {
486486
setSupportActionBar(binding.activityNotesListView.searchToolbar);
487-
activityBinding.homeToolbar.setOnClickListener((v) -> {
487+
activityBinding.searchBar.homeToolbar.setOnClickListener((v) -> {
488488
if (activityBinding.searchToolbar.getVisibility() == GONE) {
489489
updateToolbars(true);
490490
}
491491
});
492492

493-
final var toggle = new ActionBarDrawerToggle(this, binding.drawerLayout, activityBinding.homeToolbar, 0, 0);
493+
final var toggle = new ActionBarDrawerToggle(this, binding.drawerLayout, activityBinding.searchBar.homeToolbar, 0, 0);
494494
binding.drawerLayout.addDrawerListener(toggle);
495495
toggle.syncState();
496496

@@ -525,7 +525,7 @@ private void setupNotesList() {
525525
listView.setLayoutManager(gridLayoutManager);
526526
listView.addItemDecoration(new GridItemDecoration(adapter, spanCount,
527527
getResources().getDimensionPixelSize(R.dimen.spacer_3x),
528-
getResources().getDimensionPixelSize(R.dimen.spacer_5x),
528+
getResources().getDimensionPixelSize(R.dimen.spacer_3x),
529529
getResources().getDimensionPixelSize(R.dimen.spacer_3x),
530530
getResources().getDimensionPixelSize(R.dimen.spacer_1x),
531531
getResources().getDimensionPixelSize(R.dimen.spacer_activity_sides) + getResources().getDimensionPixelSize(R.dimen.spacer_1x)
@@ -535,7 +535,7 @@ private void setupNotesList() {
535535
listView.setLayoutManager(layoutManager);
536536
listView.addItemDecoration(new SectionItemDecoration(adapter,
537537
getResources().getDimensionPixelSize(R.dimen.spacer_activity_sides) + getResources().getDimensionPixelSize(R.dimen.spacer_1x) + getResources().getDimensionPixelSize(R.dimen.spacer_3x) + getResources().getDimensionPixelSize(R.dimen.spacer_2x),
538-
getResources().getDimensionPixelSize(R.dimen.spacer_5x),
538+
getResources().getDimensionPixelSize(R.dimen.spacer_3x),
539539
getResources().getDimensionPixelSize(R.dimen.spacer_1x),
540540
0
541541
));
@@ -684,11 +684,11 @@ public void applyBrand(int color) {
684684
util.platform.colorCircularProgressBar(activityBinding.progressCircular, ColorRole.PRIMARY);
685685
util.platform.colorNavigationView(binding.navigationView);
686686
util.material.themeFAB(activityBinding.fabCreate);
687-
util.notes.themeSearchCardView(binding.activityNotesListView.searchBarWrapper);
688-
util.platform.colorViewBackground(getWindow().getDecorView());
689-
util.platform.colorViewBackground(binding.getRoot());
690-
util.platform.colorViewBackground(binding.activityNotesListView.activityNotesListView);
691-
util.platform.colorTextView(binding.activityNotesListView.searchText, ColorRole.ON_SURFACE_VARIANT);
687+
util.notes.themeSearchCardView(binding.activityNotesListView.searchBar.searchBarCardWrapper);
688+
util.platform.colorViewBackground(getWindow().getDecorView(), ColorRole.SURFACE_CONTAINER);
689+
util.platform.colorViewBackground(binding.getRoot(), ColorRole.SURFACE_CONTAINER);
690+
util.platform.colorViewBackground(binding.activityNotesListView.activityNotesListView, ColorRole.SURFACE_CONTAINER);
691+
util.platform.colorTextView(binding.activityNotesListView.searchBar.searchText, ColorRole.ON_SURFACE_VARIANT);
692692
util.notes.themeSearchToolbar(binding.activityNotesListView.searchToolbar);
693693
util.notes.themeToolbarSearchView(binding.activityNotesListView.searchView);
694694

@@ -723,29 +723,29 @@ private void updateSortMethodIcon(CategorySortingMethod method) {
723723
CategorySortingMethod newMethod = (method != null) ? method: CategorySortingMethod.SORT_MODIFIED_DESC;
724724
switch (newMethod){
725725
case SORT_MODIFIED_DESC :
726-
activityBinding.sortingMethod.setImageResource(R.drawable.modification_desc);
727-
activityBinding.sortingMethod.setContentDescription(getString(R.string.sort_alphabetically));
726+
activityBinding.searchBar.sortingMethod.setImageResource(R.drawable.modification_desc);
727+
activityBinding.searchBar.sortingMethod.setContentDescription(getString(R.string.sort_alphabetically));
728728
if (SDK_INT >= O) {
729-
activityBinding.sortingMethod.setTooltipText(getString(R.string.sort_alphabetically));
729+
activityBinding.searchBar.sortingMethod.setTooltipText(getString(R.string.sort_alphabetically));
730730
}
731731
break;
732732
case SORT_LEXICOGRAPHICAL_ASC:
733-
activityBinding.sortingMethod.setImageResource(R.drawable.alphabetical_asc);
734-
activityBinding.sortingMethod.setContentDescription(getString(R.string.sort_alphabetically));
733+
activityBinding.searchBar.sortingMethod.setImageResource(R.drawable.alphabetical_asc);
734+
activityBinding.searchBar.sortingMethod.setContentDescription(getString(R.string.sort_alphabetically));
735735
if (SDK_INT >= O) {
736-
activityBinding.sortingMethod.setTooltipText(getString(R.string.sort_alphabetically));
736+
activityBinding.searchBar.sortingMethod.setTooltipText(getString(R.string.sort_alphabetically));
737737
}
738738
break;
739739
case SORT_LEXICOGRAPHICAL_DESC:
740-
activityBinding.sortingMethod.setImageResource(R.drawable.alphabetical_desc);
741-
activityBinding.sortingMethod.setContentDescription(getString(R.string.sort_last_modified));
740+
activityBinding.searchBar.sortingMethod.setImageResource(R.drawable.alphabetical_desc);
741+
activityBinding.searchBar.sortingMethod.setContentDescription(getString(R.string.sort_last_modified));
742742
if (SDK_INT >= O) {
743-
activityBinding.sortingMethod.setTooltipText(getString(R.string.sort_last_modified));
743+
activityBinding.searchBar.sortingMethod.setTooltipText(getString(R.string.sort_last_modified));
744744
}
745745
break;
746746
default: throw new IllegalStateException("Unknown method: " + method.name());
747747
}
748-
brandingUtil().platform.colorImageView(activityBinding.sortingMethod, ColorRole.ON_SURFACE);
748+
brandingUtil().platform.colorImageView(activityBinding.searchBar.sortingMethod, ColorRole.ON_SURFACE);
749749
}
750750

751751
@Override
@@ -883,7 +883,7 @@ public void onNoteFavoriteClick(int position, View view) {
883883
}
884884

885885
private void updateToolbars(boolean enableSearch) {
886-
activityBinding.homeToolbar.setVisibility(enableSearch ? GONE : VISIBLE);
886+
activityBinding.searchBar.searchBarWrapper.setVisibility(enableSearch ? GONE : VISIBLE);
887887
activityBinding.searchToolbar.setVisibility(enableSearch ? VISIBLE : GONE);
888888
activityBinding.appBar.setStateListAnimator(AnimatorInflater.loadStateListAnimator(activityBinding.appBar.getContext(), enableSearch
889889
? R.animator.appbar_elevation_on

app/src/main/java/it/niedermann/owncloud/notes/main/items/ItemAdapter.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import androidx.recyclerview.selection.SelectionTracker;
2929
import androidx.recyclerview.widget.RecyclerView;
3030

31+
import com.google.android.material.card.MaterialCardView;
3132
import com.nextcloud.android.common.ui.theme.utils.ColorRole;
3233

3334
import java.util.ArrayList;
@@ -120,12 +121,12 @@ public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int
120121
}
121122
case TYPE_NOTE_ONLY_TITLE -> {
122123
ItemNotesListNoteItemGridOnlyTitleBinding binding = ItemNotesListNoteItemGridOnlyTitleBinding.inflate(inflater, parent, false);
123-
BrandingUtil.of(color, parent.getContext()).notes.themeCard(binding.card);
124+
BrandingUtil.of(color, parent.getContext()).notes.themeCard(binding.noteCard);
124125
return new NoteViewGridHolderOnlyTitle(binding, noteClickListener, monospace, fontSize);
125126
}
126127
case TYPE_NOTE_WITH_EXCERPT, TYPE_NOTE_WITHOUT_EXCERPT -> {
127128
ItemNotesListNoteItemGridBinding binding = ItemNotesListNoteItemGridBinding.inflate(inflater, parent, false);
128-
BrandingUtil.of(color, parent.getContext()).notes.themeCard(binding.card);
129+
BrandingUtil.of(color, parent.getContext()).notes.themeCard(binding.noteCard);
129130
return new NoteViewGridHolder(binding, noteClickListener, monospace, fontSize);
130131
}
131132
default -> {
@@ -141,12 +142,12 @@ public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int
141142
}
142143
case TYPE_NOTE_WITH_EXCERPT -> {
143144
ItemNotesListNoteItemWithExcerptBinding binding = ItemNotesListNoteItemWithExcerptBinding.inflate(inflater, parent, false);
144-
BrandingUtil.of(color, parent.getContext()).notes.themeBackgroundItemView(binding.noteSwipeable);
145+
BrandingUtil.of(color, parent.getContext()).notes.themeCard(binding.noteCard);
145146
return new NoteViewHolderWithExcerpt(binding, noteClickListener);
146147
}
147148
case TYPE_NOTE_ONLY_TITLE, TYPE_NOTE_WITHOUT_EXCERPT -> {
148149
ItemNotesListNoteItemWithoutExcerptBinding binding = ItemNotesListNoteItemWithoutExcerptBinding.inflate(inflater, parent, false);
149-
BrandingUtil.of(color, parent.getContext()).notes.themeBackgroundItemView(binding.noteSwipeable);
150+
BrandingUtil.of(color, parent.getContext()).notes.themeCard(binding.noteCard);
150151
return new NoteViewHolderWithoutExcerpt(binding, noteClickListener);
151152
}
152153
default -> {
@@ -175,8 +176,10 @@ public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder holder, int
175176
holder.itemView.findViewById(R.id.custom_checkbox).setVisibility(tracker != null && tracker.hasSelection() ? View.VISIBLE : View.GONE);
176177
holder.itemView.setSelected(isSelected);
177178
if (isSelected) {
179+
((MaterialCardView) holder.itemView.findViewById(R.id.noteCard)).setStrokeWidth((int) holder.itemView.getResources().getDimension(R.dimen.card_stroke_width_selected));
178180
((ImageView) holder.itemView.findViewById(R.id.custom_checkbox)).setImageDrawable(BrandingUtil.getInstance(holder.itemView.getContext()).platform.tintDrawable(holder.itemView.getContext(), R.drawable.ic_checkbox_marked, ColorRole.PRIMARY));
179181
} else {
182+
((MaterialCardView) holder.itemView.findViewById(R.id.noteCard)).setStrokeWidth((int) holder.itemView.getResources().getDimension(R.dimen.card_stroke_width));
180183
((ImageView) holder.itemView.findViewById(R.id.custom_checkbox)).setImageResource(R.drawable.ic_checkbox_blank_outline);
181184
}
182185
holder.itemView.findViewById(R.id.custom_checkbox).setVisibility(isMultiSelect ? View.VISIBLE : View.GONE);

app/src/main/java/it/niedermann/owncloud/notes/main/items/NoteViewHolder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ protected void bindSearchableContent(@NonNull Context context, @NonNull TextView
112112
}
113113
}
114114

115-
public abstract void showSwipe(boolean left);
115+
public abstract void showSwipe(float dX);
116116

117117
@Nullable
118118
public abstract View getNoteSwipeable();

app/src/main/java/it/niedermann/owncloud/notes/main/items/grid/NoteViewGridHolder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public NoteViewGridHolder(@NonNull ItemNotesListNoteItemGridBinding binding, @No
4242
}
4343
}
4444

45-
public void showSwipe(boolean left) {
45+
public void showSwipe(float dX) {
4646
throw new UnsupportedOperationException(NoteViewGridHolder.class.getSimpleName() + " does not support swiping");
4747
}
4848

app/src/main/java/it/niedermann/owncloud/notes/main/items/grid/NoteViewGridHolderOnlyTitle.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public NoteViewGridHolderOnlyTitle(@NonNull ItemNotesListNoteItemGridOnlyTitleBi
3434
}
3535
}
3636

37-
public void showSwipe(boolean left) {
37+
public void showSwipe(float dX) {
3838
throw new UnsupportedOperationException(NoteViewGridHolderOnlyTitle.class.getSimpleName() + " does not support swiping");
3939
}
4040

app/src/main/java/it/niedermann/owncloud/notes/main/items/list/NoteViewHolderWithExcerpt.java

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
*/
77
package it.niedermann.owncloud.notes.main.items.list;
88

9+
import android.content.res.Resources;
910
import android.view.View;
1011

1112
import androidx.annotation.ColorInt;
1213
import androidx.annotation.NonNull;
1314
import androidx.annotation.Nullable;
15+
import androidx.core.content.res.ResourcesCompat;
1416

1517
import it.niedermann.owncloud.notes.R;
1618
import it.niedermann.owncloud.notes.databinding.ItemNotesListNoteItemWithExcerptBinding;
@@ -23,21 +25,37 @@ public class NoteViewHolderWithExcerpt extends NoteViewHolder {
2325
@NonNull
2426
private final ItemNotesListNoteItemWithExcerptBinding binding;
2527

28+
private final int defaultSwipeBackgroundColor;
29+
private final int starSwipeBackgroundColor;
30+
private final int deleteSwipeBackgroundColor;
31+
32+
2633
public NoteViewHolderWithExcerpt(@NonNull ItemNotesListNoteItemWithExcerptBinding binding, @NonNull NoteClickListener noteClickListener) {
2734
super(binding.getRoot(), noteClickListener);
2835
this.binding = binding;
36+
Resources resources = binding.getRoot().getContext().getResources();
37+
this.defaultSwipeBackgroundColor = ResourcesCompat.getColor(resources, R.color.transparent, null);
38+
this.starSwipeBackgroundColor = ResourcesCompat.getColor(resources, R.color.bg_warning, null);
39+
this.deleteSwipeBackgroundColor = ResourcesCompat.getColor(resources, R.color.bg_attention, null);
2940
}
3041

31-
public void showSwipe(boolean left) {
32-
binding.noteFavoriteLeft.setVisibility(left ? View.VISIBLE : View.INVISIBLE);
33-
binding.noteDeleteRight.setVisibility(left ? View.INVISIBLE : View.VISIBLE);
34-
binding.noteSwipeFrame.setBackgroundResource(left ? R.color.bg_warning : R.color.bg_attention);
42+
public void showSwipe(float dX) {
43+
if (dX == 0.0f) {
44+
binding.noteFavoriteLeft.setVisibility(View.INVISIBLE);
45+
binding.noteDeleteRight.setVisibility(View.INVISIBLE);
46+
binding.noteSwipeFrame.setCardBackgroundColor(defaultSwipeBackgroundColor);
47+
} else {
48+
boolean left = dX > 0;
49+
binding.noteFavoriteLeft.setVisibility(left ? View.VISIBLE : View.INVISIBLE);
50+
binding.noteDeleteRight.setVisibility(left ? View.INVISIBLE : View.VISIBLE);
51+
binding.noteSwipeFrame.setCardBackgroundColor(left ? starSwipeBackgroundColor : deleteSwipeBackgroundColor);
52+
}
3553
}
3654

3755
public void bind(boolean isSelected, @NonNull Note note, boolean showCategory, @ColorInt int color, @Nullable CharSequence searchQuery) {
3856
super.bind(isSelected, note, showCategory, color, searchQuery);
3957
@NonNull final var context = itemView.getContext();
40-
binding.noteSwipeable.setAlpha(DBStatus.LOCAL_DELETED.equals(note.getStatus()) ? 0.5f : 1.0f);
58+
binding.noteCard.setAlpha(DBStatus.LOCAL_DELETED.equals(note.getStatus()) ? 0.5f : 1.0f);
4159
bindCategory(context, binding.noteCategory, showCategory, note.getCategory(), color);
4260
bindStatus(binding.noteStatus, note.getStatus(), color);
4361
bindFavorite(binding.noteFavorite, note.getFavorite());
@@ -49,6 +67,6 @@ public void bind(boolean isSelected, @NonNull Note note, boolean showCategory, @
4967

5068
@NonNull
5169
public View getNoteSwipeable() {
52-
return binding.noteSwipeable;
70+
return binding.noteCard;
5371
}
54-
}
72+
}

0 commit comments

Comments
 (0)