chore: Use enhanced switch and pattern variables

Signed-off-by: Stefan Niedermann <info@niedermann.it>
This commit is contained in:
Stefan Niedermann 2024-01-20 10:56:56 +01:00 committed by Andy Scherzinger
parent 064d86dca7
commit fc827d71b8
No known key found for this signature in database
GPG key ID: 6CADC7E3523C308B
23 changed files with 132 additions and 215 deletions

View file

@ -34,17 +34,10 @@ public class AboutActivity extends LockedActivity {
binding.pager.setAdapter(new TabsStateAdapter(this));
// generate title based on given position
new TabLayoutMediator(binding.tabs, binding.pager, (tab, position) -> {
switch (position) {
default: // Fall-through to credits tab
case POS_CREDITS:
tab.setText(R.string.about_credits_tab_title);
break;
case POS_CONTRIB:
tab.setText(R.string.about_contribution_tab_title);
break;
case POS_LICENSE:
tab.setText(R.string.about_license_tab_title);
break;
switch (position) { // Fall-through to credits tab
default -> tab.setText(R.string.about_credits_tab_title);
case POS_CONTRIB -> tab.setText(R.string.about_contribution_tab_title);
case POS_LICENSE -> tab.setText(R.string.about_license_tab_title);
}
}).attach();
}
@ -74,17 +67,11 @@ public class AboutActivity extends LockedActivity {
@NonNull
@Override
public Fragment createFragment(int position) {
switch (position) {
default: // Fall-through to credits tab
case POS_CREDITS:
return new AboutFragmentCreditsTab();
case POS_CONTRIB:
return new AboutFragmentContributingTab();
case POS_LICENSE:
return new AboutFragmentLicenseTab();
}
return switch (position) { // Fall-through to credits tab
default -> new AboutFragmentCreditsTab();
case POS_CONTRIB -> new AboutFragmentContributingTab();
case POS_LICENSE -> new AboutFragmentLicenseTab();
};
}
}

View file

@ -74,8 +74,7 @@ public class BrandedSwitchPreference extends SwitchPreference implements Branded
if (view instanceof Switch) {
return (Switch) view;
}
if (view instanceof ViewGroup) {
final var viewGroup = (ViewGroup) view;
if (view instanceof ViewGroup viewGroup) {
for (int i = 0; i < viewGroup.getChildCount(); i++) {
final var child = viewGroup.getChildAt(i);
if (child instanceof ViewGroup) {

View file

@ -397,17 +397,10 @@ public class EditNoteActivity extends LockedActivity implements BaseNoteFragment
@Override
public void changeMode(@NonNull Mode mode, boolean reloadNote) {
switch (mode) {
case EDIT:
launchExistingNote(getAccountId(), getNoteId(), getString(R.string.pref_value_mode_edit), reloadNote);
break;
case PREVIEW:
launchExistingNote(getAccountId(), getNoteId(), getString(R.string.pref_value_mode_preview), reloadNote);
break;
case DIRECT_EDIT:
launchExistingNote(getAccountId(), getNoteId(), getString(R.string.pref_value_mode_direct_edit), reloadNote);
break;
default:
throw new IllegalStateException("Unknown mode: " + mode);
case EDIT -> launchExistingNote(getAccountId(), getNoteId(), getString(R.string.pref_value_mode_edit), reloadNote);
case PREVIEW -> launchExistingNote(getAccountId(), getNoteId(), getString(R.string.pref_value_mode_preview), reloadNote);
case DIRECT_EDIT -> launchExistingNote(getAccountId(), getNoteId(), getString(R.string.pref_value_mode_direct_edit), reloadNote);
default -> throw new IllegalStateException("Unknown mode: " + mode);
}
}

View file

@ -16,6 +16,7 @@ import androidx.recyclerview.widget.RecyclerView;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import it.niedermann.owncloud.notes.R;
import it.niedermann.owncloud.notes.databinding.ItemCategoryBinding;
@ -50,20 +51,20 @@ public class CategoryAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
final var categoryViewHolder = (CategoryViewHolder) holder;
switch (category.id) {
case addItemId:
final var wrapDrawable = DrawableCompat.wrap(ContextCompat.getDrawable(context, category.icon));
case addItemId -> {
final var wrapDrawable = DrawableCompat.wrap(Objects.requireNonNull(ContextCompat.getDrawable(context, category.icon)));
DrawableCompat.setTint(wrapDrawable, ContextCompat.getColor(context, R.color.icon_color_default));
categoryViewHolder.getIcon().setImageDrawable(wrapDrawable);
categoryViewHolder.getCategoryWrapper().setOnClickListener((v) -> listener.onCategoryAdded());
break;
case clearItemId:
}
case clearItemId -> {
categoryViewHolder.getIcon().setImageDrawable(ContextCompat.getDrawable(context, category.icon));
categoryViewHolder.getCategoryWrapper().setOnClickListener((v) -> listener.onCategoryCleared());
break;
default:
}
default -> {
categoryViewHolder.getIcon().setImageDrawable(ContextCompat.getDrawable(context, category.icon));
categoryViewHolder.getCategoryWrapper().setOnClickListener((v) -> listener.onCategoryChosen(category.label));
break;
}
}
categoryViewHolder.getCategory().setText(NoteUtil.extendCategory(category.label));
if (category.count != null && category.count > 0) {

View file

@ -88,19 +88,13 @@ public class TipsAdapter extends RecyclerView.Adapter<TipsViewHolder> {
} else if (throwable instanceof NextcloudHttpRequestFailedException) {
final int statusCode = ((NextcloudHttpRequestFailedException) throwable).getStatusCode();
switch (statusCode) {
case 302:
case 302 -> {
add(R.string.error_dialog_server_app_enabled);
add(R.string.error_dialog_redirect);
break;
case 500:
add(R.string.error_dialog_check_server_logs);
break;
case 503:
add(R.string.error_dialog_check_maintenance);
break;
case 507:
add(R.string.error_dialog_insufficient_storage);
break;
}
case 500 -> add(R.string.error_dialog_check_server_logs);
case 503 -> add(R.string.error_dialog_check_maintenance);
case 507 -> add(R.string.error_dialog_insufficient_storage);
}
} else if (throwable instanceof UnknownErrorException) {
if ("com.nextcloud.android.sso.QueryParam".equals(throwable.getMessage())) {

View file

@ -231,26 +231,21 @@ public class MainActivity extends LockedActivity implements NoteClickListener, A
fabCreate.show();
switch (selectedCategory.getType()) {
case RECENT: {
case RECENT -> {
activityBinding.searchText.setText(getString(R.string.search_in_all));
break;
}
case FAVORITES: {
case FAVORITES -> {
activityBinding.searchText.setText(getString(R.string.search_in_category, getString(R.string.label_favorites)));
break;
}
case UNCATEGORIZED: {
case UNCATEGORIZED -> {
activityBinding.searchText.setText(getString(R.string.search_in_category, getString(R.string.action_uncategorized)));
break;
}
case DEFAULT_CATEGORY:
default: {
default -> {
final String category = selectedCategory.getCategory();
if (category == null) {
throw new IllegalStateException(NavigationCategory.class.getSimpleName() + " type is " + DEFAULT_CATEGORY + ", but category is null.");
}
activityBinding.searchText.setText(getString(R.string.search_in_category, NoteUtil.extendCategory(category)));
break;
}
}
@ -368,7 +363,7 @@ public class MainActivity extends LockedActivity implements NoteClickListener, A
try {
// It is possible that after the deletion of the last account, this onResponse gets called before the ImportAccountActivity gets started.
if (SingleAccountHelper.getCurrentSingleSignOnAccount(this) != null) {
mainViewModel.synchronizeNotes(currentAccount, new IResponseCallback<Void>() {
mainViewModel.synchronizeNotes(currentAccount, new IResponseCallback<>() {
@Override
public void onSuccess(Void v) {
Log.d(TAG, "Successfully synchronized notes for " + currentAccount.getAccountName());
@ -505,7 +500,7 @@ public class MainActivity extends LockedActivity implements NoteClickListener, A
tracker = ItemSelectionTracker.build(listView, adapter);
adapter.setTracker(tracker);
tracker.addObserver(new SelectionTracker.SelectionObserver<Long>() {
tracker.addObserver(new SelectionTracker.SelectionObserver<>() {
@Override
public void onSelectionChanged() {
super.onSelectionChanged();
@ -541,19 +536,16 @@ public class MainActivity extends LockedActivity implements NoteClickListener, A
// update current selection
if (item.type != null) {
switch (item.type) {
case RECENT: {
case RECENT -> {
mainViewModel.postSelectedCategory(new NavigationCategory(RECENT));
break;
}
case FAVORITES: {
case FAVORITES -> {
mainViewModel.postSelectedCategory(new NavigationCategory(FAVORITES));
break;
}
case UNCATEGORIZED: {
case UNCATEGORIZED -> {
mainViewModel.postSelectedCategory(new NavigationCategory(UNCATEGORIZED));
break;
}
default: {
default -> {
if (item.getClass() == NavigationItem.CategoryNavigationItem.class) {
mainViewModel.postSelectedCategory(new NavigationCategory(((NavigationItem.CategoryNavigationItem) item).accountId, ((NavigationItem.CategoryNavigationItem) item).category));
} else {
@ -670,20 +662,18 @@ public class MainActivity extends LockedActivity implements NoteClickListener, A
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case REQUEST_CODE_CREATE_NOTE: {
case REQUEST_CODE_CREATE_NOTE -> {
listView.scrollToPosition(0);
break;
}
case REQUEST_CODE_SERVER_SETTINGS: {
case REQUEST_CODE_SERVER_SETTINGS -> {
// Recreate activity completely, because theme switching makes problems when only invalidating the views.
// @see https://github.com/nextcloud/notes-android/issues/529
if (RESULT_OK == resultCode) {
ActivityCompat.recreate(this);
return;
}
break;
}
default: {
default -> {
try {
AccountImporter.onActivityResult(requestCode, resultCode, data, this, (ssoAccount) -> {
CapabilitiesWorker.update(this);
@ -695,7 +685,7 @@ public class MainActivity extends LockedActivity implements NoteClickListener, A
Log.i(TAG, "Refreshing capabilities for " + ssoAccount.name);
final var capabilities = CapabilitiesClient.getCapabilities(getApplicationContext(), ssoAccount, null, ApiProvider.getInstance());
final String displayName = CapabilitiesClient.getDisplayName(getApplicationContext(), ssoAccount, ApiProvider.getInstance());
final var status$ = mainViewModel.addAccount(ssoAccount.url, ssoAccount.userId, ssoAccount.name, capabilities, displayName, new IResponseCallback<Account>() {
final var status$ = mainViewModel.addAccount(ssoAccount.url, ssoAccount.userId, ssoAccount.name, capabilities, displayName, new IResponseCallback<>() {
@Override
public void onSuccess(Account result) {
executor.submit(() -> {

View file

@ -155,14 +155,10 @@ public class MainViewModel extends AndroidViewModel {
// Close sub categories
switch (selectedCategory.getType()) {
case RECENT:
case FAVORITES:
case UNCATEGORIZED: {
case RECENT, FAVORITES, UNCATEGORIZED -> {
postExpandedCategory(null);
break;
}
case DEFAULT_CATEGORY:
default: {
default -> {
final String category = selectedCategory.getCategory();
if (category == null) {
postExpandedCategory(null);
@ -175,7 +171,6 @@ public class MainViewModel extends AndroidViewModel {
postExpandedCategory(null);
}
}
break;
}
}
}
@ -230,29 +225,25 @@ public class MainViewModel extends AndroidViewModel {
Log.v(TAG, "[getNotesListLiveData] - sortMethod: " + sortingMethod.second);
final LiveData<List<Note>> fromDatabase;
switch (selectedCategory.getType()) {
case RECENT: {
case RECENT -> {
Log.v(TAG, "[getNotesListLiveData] - category: " + RECENT);
fromDatabase = sortingMethod.second == SORT_MODIFIED_DESC
? repo.searchRecentByModified$(accountId, searchQueryOrWildcard)
: repo.searchRecentLexicographically$(accountId, searchQueryOrWildcard);
break;
}
case FAVORITES: {
case FAVORITES -> {
Log.v(TAG, "[getNotesListLiveData] - category: " + FAVORITES);
fromDatabase = sortingMethod.second == SORT_MODIFIED_DESC
? repo.searchFavoritesByModified$(accountId, searchQueryOrWildcard)
: repo.searchFavoritesLexicographically$(accountId, searchQueryOrWildcard);
break;
}
case UNCATEGORIZED: {
case UNCATEGORIZED -> {
Log.v(TAG, "[getNotesListLiveData] - category: " + UNCATEGORIZED);
fromDatabase = sortingMethod.second == SORT_MODIFIED_DESC
? repo.searchUncategorizedByModified$(accountId, searchQueryOrWildcard)
: repo.searchUncategorizedLexicographically$(accountId, searchQueryOrWildcard);
break;
}
case DEFAULT_CATEGORY:
default: {
default -> {
final String category = selectedCategory.getCategory();
if (category == null) {
throw new IllegalStateException(NavigationCategory.class.getSimpleName() + " type is " + DEFAULT_CATEGORY + ", but category is null.");
@ -261,7 +252,6 @@ public class MainViewModel extends AndroidViewModel {
fromDatabase = sortingMethod.second == SORT_MODIFIED_DESC
? repo.searchCategoryByModified$(accountId, searchQueryOrWildcard, category)
: repo.searchCategoryLexicographically$(accountId, searchQueryOrWildcard, category);
break;
}
}
@ -382,7 +372,7 @@ public class MainViewModel extends AndroidViewModel {
public void synchronizeCapabilitiesAndNotes(@NonNull Account localAccount, @NonNull IResponseCallback<Void> callback) {
Log.i(TAG, "[synchronizeCapabilitiesAndNotes] Synchronize capabilities for " + localAccount.getAccountName());
synchronizeCapabilities(localAccount, new IResponseCallback<Void>() {
synchronizeCapabilities(localAccount, new IResponseCallback<>() {
@Override
public void onSuccess(Void v) {
Log.i(TAG, "[synchronizeCapabilitiesAndNotes] Synchronize notes for " + localAccount.getAccountName());

View file

@ -98,33 +98,31 @@ public class ItemAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> i
final LayoutInflater inflater = LayoutInflater.from(parent.getContext());
if (gridView) {
switch (viewType) {
case TYPE_SECTION: {
case TYPE_SECTION -> {
return new SectionViewHolder(ItemNotesListSectionItemBinding.inflate(inflater));
}
case TYPE_NOTE_ONLY_TITLE: {
case TYPE_NOTE_ONLY_TITLE -> {
return new NoteViewGridHolderOnlyTitle(ItemNotesListNoteItemGridOnlyTitleBinding.inflate(inflater, parent, false), noteClickListener, monospace, fontSize);
}
case TYPE_NOTE_WITH_EXCERPT:
case TYPE_NOTE_WITHOUT_EXCERPT: {
case TYPE_NOTE_WITH_EXCERPT, TYPE_NOTE_WITHOUT_EXCERPT -> {
return new NoteViewGridHolder(ItemNotesListNoteItemGridBinding.inflate(inflater, parent, false), noteClickListener, monospace, fontSize);
}
default: {
default -> {
throw new IllegalArgumentException("Not supported viewType: " + viewType);
}
}
} else {
switch (viewType) {
case TYPE_SECTION: {
case TYPE_SECTION -> {
return new SectionViewHolder(ItemNotesListSectionItemBinding.inflate(inflater));
}
case TYPE_NOTE_WITH_EXCERPT: {
case TYPE_NOTE_WITH_EXCERPT -> {
return new NoteViewHolderWithExcerpt(ItemNotesListNoteItemWithExcerptBinding.inflate(inflater, parent, false), noteClickListener);
}
case TYPE_NOTE_ONLY_TITLE:
case TYPE_NOTE_WITHOUT_EXCERPT: {
case TYPE_NOTE_ONLY_TITLE, TYPE_NOTE_WITHOUT_EXCERPT -> {
return new NoteViewHolderWithoutExcerpt(ItemNotesListNoteItemWithoutExcerptBinding.inflate(inflater, parent, false), noteClickListener);
}
default: {
default -> {
throw new IllegalArgumentException("Not supported viewType: " + viewType);
}
}
@ -144,16 +142,10 @@ public class ItemAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> i
}
}
switch (getItemViewType(position)) {
case TYPE_SECTION: {
((SectionViewHolder) holder).bind((SectionItem) itemList.get(position));
break;
}
case TYPE_NOTE_WITH_EXCERPT:
case TYPE_NOTE_WITHOUT_EXCERPT:
case TYPE_NOTE_ONLY_TITLE: {
((NoteViewHolder) holder).bind(isSelected, (Note) itemList.get(position), showCategory, color, searchQuery);
break;
}
case TYPE_SECTION ->
((SectionViewHolder) holder).bind((SectionItem) itemList.get(position));
case TYPE_NOTE_WITH_EXCERPT, TYPE_NOTE_WITHOUT_EXCERPT, TYPE_NOTE_ONLY_TITLE ->
((NoteViewHolder) holder).bind(isSelected, (Note) itemList.get(position), showCategory, color, searchQuery);
}
}

View file

@ -105,7 +105,7 @@ public abstract class NoteViewHolder extends RecyclerView.ViewHolder {
public abstract View getNoteSwipeable();
public ItemDetailsLookup.ItemDetails<Long> getItemDetails() {
return new ItemDetailsLookup.ItemDetails<Long>() {
return new ItemDetailsLookup.ItemDetails<>() {
@Override
public int getPosition() {
return getAdapterPosition();

View file

@ -71,7 +71,7 @@ public class NotesListViewItemTouchHelper extends ItemTouchHelper {
@Override
public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction) {
switch (direction) {
case ItemTouchHelper.LEFT:
case ItemTouchHelper.LEFT -> {
viewHolder.setIsRecyclable(false);
final var dbNoteWithoutContent = (Note) adapter.getItem(viewHolder.getLayoutPosition());
final var dbNoteLiveData = mainViewModel.getFullNote$(dbNoteWithoutContent.getId());
@ -92,15 +92,16 @@ public class NotesListViewItemTouchHelper extends ItemTouchHelper {
})
.show();
});
break;
case ItemTouchHelper.RIGHT:
}
case ItemTouchHelper.RIGHT -> {
viewHolder.setIsRecyclable(false);
final var adapterNote = (Note) adapter.getItem(viewHolder.getLayoutPosition());
final var toggleLiveData = mainViewModel.toggleFavoriteAndSync(adapterNote.getId());
toggleLiveData.observe(lifecycleOwner, (next) -> toggleLiveData.removeObservers(lifecycleOwner));
break;
default:
//NoOp
}
default -> {
}
//NoOp
}
}

View file

@ -2,6 +2,8 @@ package it.niedermann.owncloud.notes.main.items.section;
import androidx.annotation.NonNull;
import java.util.Objects;
import it.niedermann.owncloud.notes.shared.model.Item;
public class SectionItem implements Item {
@ -28,11 +30,9 @@ public class SectionItem implements Item {
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof SectionItem)) return false;
if (!(o instanceof SectionItem that)) return false;
SectionItem that = (SectionItem) o;
return title != null ? title.equals(that.title) : that.title == null;
return Objects.equals(title, that.title);
}
@Override

View file

@ -10,6 +10,8 @@ import it.niedermann.owncloud.notes.shared.model.ENavigationCategoryType;
import static it.niedermann.owncloud.notes.shared.model.ENavigationCategoryType.UNCATEGORIZED;
import java.util.Objects;
public class NavigationItem {
@NonNull
public String id;
@ -52,11 +54,9 @@ public class NavigationItem {
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof CategoryNavigationItem)) return false;
if (!(o instanceof CategoryNavigationItem that)) return false;
if (!super.equals(o)) return false;
CategoryNavigationItem that = (CategoryNavigationItem) o;
if (accountId != that.accountId) return false;
return category.equals(that.category);
}
@ -73,14 +73,12 @@ public class NavigationItem {
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof NavigationItem)) return false;
final var that = (NavigationItem) o;
if (!(o instanceof NavigationItem that)) return false;
if (icon != that.icon) return false;
if (!id.equals(that.id)) return false;
if (!label.equals(that.label)) return false;
if (count != null ? !count.equals(that.count) : that.count != null) return false;
if (!Objects.equals(count, that.count)) return false;
return type == that.type;
}

View file

@ -653,20 +653,16 @@ public class NotesRepository {
int orderIndex = sortingMethod.getId();
switch (selectedCategory.getType()) {
case FAVORITES: {
case FAVORITES -> {
sp.putInt(ctx.getString(R.string.action_sorting_method) + ' ' + ctx.getString(R.string.label_favorites), orderIndex);
break;
}
case UNCATEGORIZED: {
case UNCATEGORIZED -> {
sp.putInt(ctx.getString(R.string.action_sorting_method) + ' ' + ctx.getString(R.string.action_uncategorized), orderIndex);
break;
}
case RECENT: {
case RECENT -> {
sp.putInt(ctx.getString(R.string.action_sorting_method) + ' ' + ctx.getString(R.string.label_all_notes), orderIndex);
break;
}
case DEFAULT_CATEGORY:
default: {
default -> {
final String category = selectedCategory.getCategory();
if (category != null) {
if (db.getCategoryOptionsDao().modifyCategoryOrder(accountId, category, sortingMethod) == 0) {
@ -680,7 +676,6 @@ public class NotesRepository {
} else {
throw new IllegalStateException("Tried to modify category order for " + ENavigationCategoryType.DEFAULT_CATEGORY + "but category is null.");
}
break;
}
}
sp.apply();
@ -707,20 +702,16 @@ public class NotesRepository {
switch (selectedCategory.getType()) {
// TODO make this account specific
case RECENT: {
case RECENT -> {
prefKey = context.getString(R.string.action_sorting_method) + ' ' + context.getString(R.string.label_all_notes);
break;
}
case FAVORITES: {
case FAVORITES -> {
prefKey = context.getString(R.string.action_sorting_method) + ' ' + context.getString(R.string.label_favorites);
break;
}
case UNCATEGORIZED: {
case UNCATEGORIZED -> {
prefKey = context.getString(R.string.action_sorting_method) + ' ' + context.getString(R.string.action_uncategorized);
break;
}
case DEFAULT_CATEGORY:
default: {
default -> {
final String category = selectedCategory.getCategory();
if (category != null) {
return db.getCategoryOptionsDao().getCategoryOrder(selectedCategory.getAccountId(), category);
@ -814,9 +805,7 @@ public class NotesRepository {
if (account == null) {
Log.i(TAG, SingleSignOnAccount.class.getSimpleName() + " is null. Is this a local account?");
} else {
if (syncActive.get(account.getId()) == null) {
syncActive.put(account.getId(), false);
}
syncActive.putIfAbsent(account.getId(), false);
Log.d(TAG, "Sync requested (" + (onlyLocalChanges ? "onlyLocalChanges" : "full") + "; " + (Boolean.TRUE.equals(syncActive.get(account.getId())) ? "sync active" : "sync NOT active") + ") ...");
if (isSyncPossible() && (!Boolean.TRUE.equals(syncActive.get(account.getId())) || onlyLocalChanges)) {
syncActive.put(account.getId(), true);

View file

@ -118,7 +118,7 @@ abstract class NotesServerSyncTask extends Thread {
try {
Note remoteNote;
switch (note.getStatus()) {
case LOCAL_EDITED:
case LOCAL_EDITED -> {
Log.v(TAG, " ...create/edit");
if (note.getRemoteId() != null) {
Log.v(TAG, " ...Note has remoteId → try to edit");
@ -160,8 +160,8 @@ abstract class NotesServerSyncTask extends Thread {
}
// Please note, that db.updateNote() realized an optimistic conflict resolution, which is required for parallel changes of this Note from the UI.
repo.updateIfNotModifiedLocallyDuringSync(note.getId(), remoteNote.getModified().getTimeInMillis(), remoteNote.getTitle(), remoteNote.getFavorite(), remoteNote.getETag(), remoteNote.getContent(), generateNoteExcerpt(remoteNote.getContent(), remoteNote.getTitle()), note.getContent(), note.getCategory(), note.getFavorite());
break;
case LOCAL_DELETED:
}
case LOCAL_DELETED -> {
if (note.getRemoteId() == null) {
Log.v(TAG, " ...delete (only local, since it has never been synchronized)");
} else {
@ -177,9 +177,9 @@ abstract class NotesServerSyncTask extends Thread {
}
// Please note, that db.deleteNote() realizes an optimistic conflict resolution, which is required for parallel changes of this Note from the UI.
repo.deleteByNoteId(note.getId(), LOCAL_DELETED);
break;
default:
throw new IllegalStateException("Unknown State of Note " + note + ": " + note.getStatus());
}
default ->
throw new IllegalStateException("Unknown State of Note " + note + ": " + note.getStatus());
}
} catch (NextcloudHttpRequestFailedException e) {
if (e.getStatusCode() == HTTP_NOT_MODIFIED) {

View file

@ -12,6 +12,7 @@ import androidx.room.PrimaryKey;
import java.io.Serializable;
import java.util.Calendar;
import java.util.Objects;
import it.niedermann.owncloud.notes.shared.model.Capabilities;
@ -180,9 +181,7 @@ public class Account implements Serializable {
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Account)) return false;
Account account = (Account) o;
if (!(o instanceof Account account)) return false;
if (id != account.id) return false;
if (color != account.color) return false;
@ -190,15 +189,14 @@ public class Account implements Serializable {
if (!url.equals(account.url)) return false;
if (!userName.equals(account.userName)) return false;
if (!accountName.equals(account.accountName)) return false;
if (eTag != null ? !eTag.equals(account.eTag) : account.eTag != null) return false;
if (modified != null ? !modified.equals(account.modified) : account.modified != null)
if (!Objects.equals(eTag, account.eTag)) return false;
if (!Objects.equals(modified, account.modified))
return false;
if (apiVersion != null ? !apiVersion.equals(account.apiVersion) : account.apiVersion != null)
if (!Objects.equals(apiVersion, account.apiVersion))
return false;
if (capabilitiesETag != null ? !capabilitiesETag.equals(account.capabilitiesETag) : account.capabilitiesETag != null)
if (!Objects.equals(capabilitiesETag, account.capabilitiesETag))
return false;
if (directEditingAvailable != account.directEditingAvailable) return false;
return true;
return directEditingAvailable == account.directEditingAvailable;
}
@Override

View file

@ -74,9 +74,7 @@ public class CategoryOptions implements Serializable {
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof CategoryOptions)) return false;
CategoryOptions that = (CategoryOptions) o;
if (!(o instanceof CategoryOptions that)) return false;
if (accountId != that.accountId) return false;
if (!category.equals(that.category)) return false;

View file

@ -2,6 +2,8 @@ package it.niedermann.owncloud.notes.persistence.entity;
import androidx.room.Ignore;
import java.util.Objects;
public class CategoryWithNotesCount {
private long accountId;
@ -46,14 +48,12 @@ public class CategoryWithNotesCount {
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof CategoryWithNotesCount)) return false;
CategoryWithNotesCount that = (CategoryWithNotesCount) o;
if (!(o instanceof CategoryWithNotesCount that)) return false;
if (accountId != that.accountId) return false;
if (category != null ? !category.equals(that.category) : that.category != null)
if (!Objects.equals(category, that.category))
return false;
return totalNotes != null ? totalNotes.equals(that.totalNotes) : that.totalNotes == null;
return Objects.equals(totalNotes, that.totalNotes);
}
@Override

View file

@ -14,6 +14,7 @@ import com.google.gson.annotations.SerializedName;
import java.io.Serializable;
import java.util.Calendar;
import java.util.Objects;
import it.niedermann.owncloud.notes.shared.model.DBStatus;
import it.niedermann.owncloud.notes.shared.model.Item;
@ -218,23 +219,21 @@ public class Note implements Serializable, Item {
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Note)) return false;
Note note = (Note) o;
if (!(o instanceof Note note)) return false;
if (id != note.id) return false;
if (accountId != note.accountId) return false;
if (favorite != note.favorite) return false;
if (scrollY != note.scrollY) return false;
if (remoteId != null ? !remoteId.equals(note.remoteId) : note.remoteId != null)
if (!Objects.equals(remoteId, note.remoteId))
return false;
if (status != note.status) return false;
if (!title.equals(note.title)) return false;
if (!category.equals(note.category)) return false;
if (modified != null ? !modified.equals(note.modified) : note.modified != null)
if (!Objects.equals(modified, note.modified))
return false;
if (!content.equals(note.content)) return false;
if (eTag != null ? !eTag.equals(note.eTag) : note.eTag != null) return false;
if (!Objects.equals(eTag, note.eTag)) return false;
return excerpt.equals(note.excerpt);
}

View file

@ -8,6 +8,8 @@ import androidx.room.ForeignKey;
import androidx.room.Ignore;
import androidx.room.Index;
import java.util.Objects;
import it.niedermann.owncloud.notes.widget.AbstractWidgetData;
@Entity(
@ -61,13 +63,11 @@ public class NotesListWidgetData extends AbstractWidgetData {
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof NotesListWidgetData)) return false;
if (!(o instanceof NotesListWidgetData that)) return false;
if (!super.equals(o)) return false;
NotesListWidgetData that = (NotesListWidgetData) o;
if (mode != that.mode) return false;
return category != null ? category.equals(that.category) : that.category == null;
return Objects.equals(category, that.category);
}
@Override

View file

@ -51,9 +51,7 @@ public class SingleNoteWidgetData extends AbstractWidgetData {
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof SingleNoteWidgetData)) return false;
SingleNoteWidgetData that = (SingleNoteWidgetData) o;
if (!(o instanceof SingleNoteWidgetData that)) return false;
return noteId == that.noteId;
}

View file

@ -4,6 +4,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import java.io.Serializable;
import java.util.Objects;
import static it.niedermann.owncloud.notes.shared.model.ENavigationCategoryType.DEFAULT_CATEGORY;
@ -47,13 +48,11 @@ public class NavigationCategory implements Serializable {
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof NavigationCategory)) return false;
NavigationCategory that = (NavigationCategory) o;
if (!(o instanceof NavigationCategory that)) return false;
if (accountId != that.accountId) return false;
if (type != that.type) return false;
return category != null ? category.equals(that.category) : that.category == null;
return Objects.equals(category, that.category);
}
@Override

View file

@ -49,9 +49,7 @@ public abstract class AbstractWidgetData {
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof AbstractWidgetData)) return false;
AbstractWidgetData that = (AbstractWidgetData) o;
if (!(o instanceof AbstractWidgetData that)) return false;
if (id != that.id) return false;
if (accountId != that.accountId) return false;

View file

@ -60,20 +60,17 @@ public class NoteListWidgetFactory implements RemoteViewsService.RemoteViewsFact
data = repo.getNoteListWidgetData(appWidgetId);
Log.v(TAG, "--- data - " + data);
switch (data.getMode()) {
case MODE_DISPLAY_ALL:
dbNotes.addAll(repo.searchRecentByModified(data.getAccountId(), "%"));
break;
case MODE_DISPLAY_STARRED:
dbNotes.addAll(repo.searchFavoritesByModified(data.getAccountId(), "%"));
break;
case MODE_DISPLAY_CATEGORY:
default:
case MODE_DISPLAY_ALL ->
dbNotes.addAll(repo.searchRecentByModified(data.getAccountId(), "%"));
case MODE_DISPLAY_STARRED ->
dbNotes.addAll(repo.searchFavoritesByModified(data.getAccountId(), "%"));
default -> {
if (data.getCategory() != null) {
dbNotes.addAll(repo.searchCategoryByModified(data.getAccountId(), "%", data.getCategory()));
} else {
dbNotes.addAll(repo.searchUncategorizedByModified(data.getAccountId(), "%"));
}
break;
}
}
} catch (IllegalArgumentException e) {
e.printStackTrace();
@ -144,17 +141,13 @@ public class NoteListWidgetFactory implements RemoteViewsService.RemoteViewsFact
@NonNull
private static String getCategoryTitle(@NonNull Context context, int displayMode, String category) {
switch (displayMode) {
case MODE_DISPLAY_STARRED:
return context.getString(R.string.label_favorites);
case MODE_DISPLAY_CATEGORY:
return "".equals(category)
? context.getString(R.string.action_uncategorized)
: category;
case MODE_DISPLAY_ALL:
default:
return context.getString(R.string.app_name);
}
return switch (displayMode) {
case MODE_DISPLAY_STARRED -> context.getString(R.string.label_favorites);
case MODE_DISPLAY_CATEGORY -> "".equals(category)
? context.getString(R.string.action_uncategorized)
: category;
default -> context.getString(R.string.app_name);
};
}
@Override