diff options
Diffstat (limited to 'app/src/main/java/it/niedermann/nextcloud')
7 files changed, 65 insertions, 13 deletions
diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/model/internal/FilterInformation.java b/app/src/main/java/it/niedermann/nextcloud/deck/model/internal/FilterInformation.java index 81aa8cd80..9a8d389c6 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/model/internal/FilterInformation.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/model/internal/FilterInformation.java @@ -31,6 +31,8 @@ public class FilterInformation implements Serializable { private List<OcsProject> projects = new ArrayList<>(); @NonNull private EArchiveStatus archiveStatus = EArchiveStatus.NON_ARCHIVED; + @NonNull + private String filterText = ""; public FilterInformation() { // Default constructor @@ -47,9 +49,19 @@ public class FilterInformation implements Serializable { this.archiveStatus = filterInformation.getArchiveStatus(); this.noAssignedProject = filterInformation.isNoAssignedProject(); this.projects = filterInformation.getProjects(); + this.filterText = filterInformation.getFilterText(); } } + public void setFilterText(@NonNull String filterText) { + this.filterText = filterText; + } + + @NonNull + public String getFilterText() { + return this.filterText; + } + @NonNull public EDueType getDueType() { return dueType; @@ -145,11 +157,12 @@ public class FilterInformation implements Serializable { ", users=" + users + ", labels=" + labels + ", archiveStatus=" + archiveStatus + + ", filterText=" + filterText + '}'; } /** - * @return whether or not the given {@param filterInformation} has any actual filters set + * @return whether or not the given {@param filterInformation} has any actual filters except {@link #filterText} */ public static boolean hasActiveFilter(@Nullable FilterInformation filterInformation) { if (filterInformation == null) { diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/DataBaseAdapter.java b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/DataBaseAdapter.java index 827fcee39..e83a44752 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/DataBaseAdapter.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/DataBaseAdapter.java @@ -8,6 +8,7 @@ import androidx.annotation.AnyThread; import androidx.annotation.ColorInt; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.annotation.UiThread; import androidx.annotation.WorkerThread; import androidx.lifecycle.LiveData; import androidx.sqlite.db.SimpleSQLiteQuery; @@ -318,7 +319,7 @@ public class DataBaseAdapter { } } if (filter.getArchiveStatus() != FilterInformation.EArchiveStatus.ALL) { - query.append(" and c.archived = " + (filter.getArchiveStatus() == FilterInformation.EArchiveStatus.ARCHIVED ? 1 : 0)); + query.append(" and c.archived = ").append(filter.getArchiveStatus() == FilterInformation.EArchiveStatus.ARCHIVED ? 1 : 0); } query.append(" and status<>3 order by accountId asc, stackId asc, `order`, createdAt asc;"); return new SimpleSQLiteQuery(query.toString(), args.toArray()); @@ -361,7 +362,7 @@ public class DataBaseAdapter { notifyFilterWidgetsAboutChangedEntity(FilterWidget.EChangedEntityType.USER, user.getLocalId()); } - @AnyThread + @UiThread public LiveData<Label> getLabelByRemoteId(long accountId, long remoteId) { return distinctUntilChanged(db.getLabelDao().getLabelByRemoteId(accountId, remoteId)); } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/MainActivity.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/MainActivity.java index d4fe623b3..1f65043d6 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/MainActivity.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/MainActivity.java @@ -12,6 +12,8 @@ import android.net.NetworkInfo; import android.net.NetworkRequest; import android.net.Uri; import android.os.Bundle; +import android.text.Editable; +import android.text.TextWatcher; import android.view.Menu; import android.view.MenuItem; import android.view.View; @@ -100,6 +102,8 @@ import it.niedermann.nextcloud.deck.ui.stack.StackAdapter; import it.niedermann.nextcloud.deck.ui.stack.StackFragment; import it.niedermann.nextcloud.deck.util.DrawerMenuUtil; +import static androidx.lifecycle.Transformations.distinctUntilChanged; +import static androidx.lifecycle.Transformations.map; import static androidx.lifecycle.Transformations.switchMap; import static it.niedermann.nextcloud.deck.DeckApplication.NO_ACCOUNT_ID; import static it.niedermann.nextcloud.deck.DeckApplication.NO_BOARD_ID; @@ -199,6 +203,23 @@ public class MainActivity extends BrandedActivity implements DeleteStackListener DrawableCompat.setTint(headerBinding.copyDebugLogs.getDrawable(), headerTextColor); }); + binding.currentBoardName.addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + filterViewModel.setFilterText(s.toString()); + } + + @Override + public void afterTextChanged(Editable s) { + + } + }); + mainViewModel.isDebugModeEnabled().observe(this, (enabled) -> headerBinding.copyDebugLogs.setVisibility(enabled ? View.VISIBLE : View.GONE)); headerBinding.copyDebugLogs.setOnClickListener((v) -> { try { @@ -379,8 +400,8 @@ public class MainActivity extends BrandedActivity implements DeleteStackListener } } }); - filterViewModel.getFilterInformation().observe(this, (info) -> - binding.filterIndicator.setVisibility(filterViewModel.getFilterInformation().getValue() == null ? View.GONE : View.VISIBLE)); + distinctUntilChanged(map(filterViewModel.getFilterInformation(), FilterInformation::hasActiveFilter)) + .observe(this, (hasActiveFilter) -> binding.filterIndicator.setVisibility(hasActiveFilter ? View.VISIBLE : View.GONE)); binding.archivedCards.setOnClickListener((v) -> startActivity(ArchivedCardsActvitiy.createIntent(this, mainViewModel.getCurrentAccount(), mainViewModel.getCurrentBoardLocalId(), mainViewModel.currentBoardHasEditPermission()))); @@ -563,7 +584,7 @@ public class MainActivity extends BrandedActivity implements DeleteStackListener } protected void clearCurrentBoard() { - binding.toolbar.setTitle(R.string.app_name_short); + binding.currentBoardName.setHint(R.string.app_name_short); binding.swipeRefreshLayout.setVisibility(View.GONE); binding.listMenuButton.setVisibility(View.GONE); binding.emptyContentViewStacks.setVisibility(View.GONE); @@ -576,13 +597,13 @@ public class MainActivity extends BrandedActivity implements DeleteStackListener } saveBrandColors(this, board.getColor()); mainViewModel.setCurrentBoard(board); - filterViewModel.clearFilterInformation(); + filterViewModel.clearFilterInformation(true); lastBoardId = board.getLocalId(); saveCurrentBoardId(this, mainViewModel.getCurrentAccount().getId(), mainViewModel.getCurrentBoardLocalId()); binding.navigationView.setCheckedItem(boardsList.indexOf(board)); - binding.toolbar.setTitle(board.getTitle()); + binding.currentBoardName.setHint(board.getTitle()); if (mainViewModel.currentBoardHasEditPermission()) { binding.fab.show(); @@ -912,6 +933,10 @@ public class MainActivity extends BrandedActivity implements DeleteStackListener public void onBackPressed() { if (binding.drawerLayout.isDrawerOpen(GravityCompat.START)) { binding.drawerLayout.closeDrawer(GravityCompat.START); + } else if(binding.currentBoardName.hasFocus()) { + binding.currentBoardName.setText(null); + binding.currentBoardName.clearFocus(); + binding.toolbar.requestFocus(); } else { super.onBackPressed(); } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/filter/FilterDialogFragment.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/filter/FilterDialogFragment.java index 647dfd651..bc730363e 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/filter/FilterDialogFragment.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/filter/FilterDialogFragment.java @@ -93,7 +93,7 @@ public class FilterDialogFragment extends BrandedDialogFragment { .setTitle(R.string.simple_filter) .setView(binding.getRoot()) .setNeutralButton(android.R.string.cancel, null) - .setNegativeButton(R.string.simple_clear, (a, b) -> filterViewModel.clearFilterInformation()) + .setNegativeButton(R.string.simple_clear, (a, b) -> filterViewModel.clearFilterInformation(false)) .setPositiveButton(R.string.simple_filter, (a, b) -> filterViewModel.publishFilterInformationDraft()) .create(); } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/filter/FilterViewModel.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/filter/FilterViewModel.java index c42a61ebd..8a2555eb5 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/filter/FilterViewModel.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/filter/FilterViewModel.java @@ -10,6 +10,7 @@ import androidx.lifecycle.MutableLiveData; import java.util.List; +import it.niedermann.nextcloud.deck.DeckLog; import it.niedermann.nextcloud.deck.model.Label; import it.niedermann.nextcloud.deck.model.User; import it.niedermann.nextcloud.deck.model.enums.EDueType; @@ -40,8 +41,13 @@ public class FilterViewModel extends AndroidViewModel { this.filterInformation.postValue(hasActiveFilter(filterInformationDraft.getValue()) ? filterInformationDraft.getValue() : null); } - public void clearFilterInformation() { - this.filterInformationDraft.setValue(new FilterInformation()); + public void clearFilterInformation(boolean alsoFilterText) { + final FilterInformation newFilterInformation = new FilterInformation(); + if (alsoFilterText) { + final FilterInformation oldFilterInformation = this.filterInformation.getValue(); + newFilterInformation.setFilterText(oldFilterInformation != null ? oldFilterInformation.getFilterText() : ""); + } + this.filterInformationDraft.setValue(newFilterInformation); this.publishFilterInformationDraft(); this.currentFilterTab = 0; } @@ -106,6 +112,13 @@ public class FilterViewModel extends AndroidViewModel { this.currentFilterTab = newFilterTab; } + public void setFilterText(@NonNull String filterText) { + DeckLog.info("New filterText:", filterText); + FilterInformation newDraft = new FilterInformation(filterInformation.getValue()); + newDraft.setFilterText(filterText); + this.filterInformation.postValue(newDraft); + } + @IntRange(from = 0, to = 2) public int getCurrentFilterTab() { return this.currentFilterTab; diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/sharetarget/ShareTargetActivity.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/sharetarget/ShareTargetActivity.java index 21aafed30..1bae469dc 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/sharetarget/ShareTargetActivity.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/sharetarget/ShareTargetActivity.java @@ -192,7 +192,7 @@ public class ShareTargetActivity extends MainActivity implements SelectCardListe super.setCurrentBoard(board); binding.listMenuButton.setVisibility(View.GONE); binding.fab.setVisibility(View.GONE); - binding.toolbar.setTitle(R.string.simple_select); + binding.currentBoardName.setHint(R.string.simple_select); } @Override diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/widget/singlecard/SelectCardForWidgetActivity.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/widget/singlecard/SelectCardForWidgetActivity.java index fe6e969e7..47dfbdf34 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/widget/singlecard/SelectCardForWidgetActivity.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/widget/singlecard/SelectCardForWidgetActivity.java @@ -60,7 +60,7 @@ public class SelectCardForWidgetActivity extends MainActivity implements SelectC super.setCurrentBoard(board); binding.listMenuButton.setVisibility(View.GONE); binding.fab.setVisibility(View.GONE); - binding.toolbar.setTitle(R.string.simple_select); + binding.currentBoardName.setHint(R.string.simple_select); } @Override |