diff options
author | Stefan Niedermann <info@niedermann.it> | 2021-03-26 20:31:04 +0300 |
---|---|---|
committer | Niedermann IT-Dienstleistungen <stefan-niedermann@users.noreply.github.com> | 2021-03-28 20:00:49 +0300 |
commit | 04a4167f58c7b9b99dd42192cff1807c2ac9e749 (patch) | |
tree | 04e964cbce90a42f7cf43413f28d9bd5c51bcfe1 /app/src | |
parent | 49f173b6023a294d8a33ffcd6a7d4c185805fbfd (diff) |
#630 Search - UI
Signed-off-by: Stefan Niedermann <info@niedermann.it>
Diffstat (limited to 'app/src')
8 files changed, 167 insertions, 76 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 diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index b414437d1..b4e771185 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -102,72 +102,111 @@ android:layout_width="match_parent" android:layout_height="wrap_content"> - <androidx.appcompat.widget.Toolbar - android:id="@+id/toolbar" + <com.google.android.material.card.MaterialCardView android:layout_width="match_parent" - android:layout_height="?attr/actionBarSize" - tools:title="Deck"> - - <ImageView - android:id="@+id/accountSwitcher" - android:layout_width="?attr/actionBarSize" - android:layout_height="?attr/actionBarSize" - android:layout_gravity="center_vertical|end" - android:background="?attr/selectableItemBackgroundBorderless" - android:contentDescription="@string/choose_account" - android:padding="12dp" - android:tooltipText="@string/choose_account" - app:srcCompat="@drawable/ic_baseline_account_circle_24" - tools:targetApi="o" /> - - <FrameLayout - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_gravity="center_vertical|end" - android:translationX="6dp"> + android:layout_height="wrap_content" + android:layout_marginStart="@dimen/spacer_1x" + android:layout_marginTop="@dimen/spacer_1hx" + android:layout_marginEnd="@dimen/spacer_1x" + android:layout_marginBottom="@dimen/spacer_1hx" + android:elevation="@dimen/spacer_2x" + app:cardCornerRadius="@dimen/spacer_2x"> - <ImageView - android:id="@+id/filter" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:background="?attr/selectableItemBackgroundBorderless" - android:contentDescription="@string/simple_filter" - android:padding="12dp" - android:tooltipText="@string/simple_filter" - app:srcCompat="@drawable/ic_filter_list_white_24dp" - app:tint="?attr/colorAccent" - tools:targetApi="o" /> - - <ImageView - android:id="@+id/filter_indicator" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_gravity="bottom|end" - android:layout_marginEnd="12dp" - android:layout_marginBottom="12dp" - android:contentDescription="@null" - android:src="@drawable/circle_grey600_8dp" - android:visibility="gone" - app:tint="@color/defaultBrand" - tools:visibility="visible" /> - </FrameLayout> - - <ImageView - android:id="@+id/archivedCards" - android:layout_width="wrap_content" + <androidx.appcompat.widget.Toolbar + android:id="@+id/toolbar" + android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_gravity="center_vertical|end" - android:background="?attr/selectableItemBackgroundBorderless" - android:contentDescription="@string/action_archived_cards" - android:padding="12dp" - android:tooltipText="@string/action_archived_cards" - android:translationX="12dp" - android:visibility="gone" - app:srcCompat="@drawable/ic_archive_white_24dp" - app:tint="?attr/colorAccent" - tools:targetApi="o" - tools:visibility="visible" /> - </androidx.appcompat.widget.Toolbar> + android:layout_gravity="center_vertical"> + + <androidx.constraintlayout.widget.ConstraintLayout + android:layout_width="match_parent" + android:layout_height="?attr/actionBarSize" + tools:title="Deck"> + + <EditText + android:id="@+id/currentBoardName" + android:layout_width="0dp" + android:background="@android:color/transparent" + android:layout_height="wrap_content" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toStartOf="@id/archivedCards" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" + android:inputType="text"> + + </EditText> + + <ImageView + android:id="@+id/archivedCards" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center_vertical|end" + android:background="?attr/selectableItemBackgroundBorderless" + android:contentDescription="@string/action_archived_cards" + android:padding="12dp" + android:tooltipText="@string/action_archived_cards" + android:visibility="gone" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toStartOf="@id/filterWrapper" + app:layout_constraintTop_toTopOf="parent" + app:srcCompat="@drawable/ic_archive_white_24dp" + app:tint="?attr/colorAccent" + tools:targetApi="o" + tools:visibility="visible" /> + + + <FrameLayout + android:id="@+id/filterWrapper" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center_vertical|end" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toStartOf="@id/accountSwitcher" + app:layout_constraintTop_toTopOf="parent"> + + <ImageView + android:id="@+id/filter" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:background="?attr/selectableItemBackgroundBorderless" + android:contentDescription="@string/simple_filter" + android:padding="12dp" + android:tooltipText="@string/simple_filter" + app:srcCompat="@drawable/ic_filter_list_white_24dp" + app:tint="?attr/colorAccent" + tools:targetApi="o" /> + + <ImageView + android:id="@+id/filter_indicator" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="bottom|end" + android:layout_marginEnd="12dp" + android:layout_marginBottom="12dp" + android:contentDescription="@null" + android:src="@drawable/circle_grey600_8dp" + android:visibility="gone" + app:tint="@color/defaultBrand" + tools:visibility="visible" /> + </FrameLayout> + + <ImageView + android:id="@+id/accountSwitcher" + android:layout_width="?attr/actionBarSize" + android:layout_height="?attr/actionBarSize" + android:layout_gravity="center_vertical|end" + android:background="?attr/selectableItemBackgroundBorderless" + android:contentDescription="@string/choose_account" + android:padding="12dp" + android:tooltipText="@string/choose_account" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintTop_toTopOf="parent" + app:srcCompat="@drawable/ic_baseline_account_circle_24" + tools:targetApi="o" /> + </androidx.constraintlayout.widget.ConstraintLayout> + </androidx.appcompat.widget.Toolbar> + </com.google.android.material.card.MaterialCardView> <LinearLayout android:layout_width="match_parent" |