Skip to content

Commit

Permalink
Bookmarks: New toolbar for sorting feature flag (#5452)
Browse files Browse the repository at this point in the history
Task/Issue URL:
https://app.asana.com/0/1174433894299346/1209107275709085/f

### Description
This PR adds the new toolbar for the Bookmarks screen under the feature
flag
Note that the select sort icon doesn’t react to changes yet

### Steps to test this PR

_Toolbar functionality_
- [x] Enable “bookmarksSorting” feature flag
- [x] Add a 4 bookmarks and open the bookmarks screen
- [x] Tap on the add folder icon
- [x] Verify Add folder screen opens
- [x] Tap on the overflow menu
- [x] Verify the new menu appear (Sort options available)
- [x] Go back and add another bookmark
- [x] Open bookmarks again
- [x] Verify Search icon appears
- [x] Tap on search icon
- [x] Run some queries verify filter still works

### UI changes
| New  | Old |
| ------ | ----- |

![Screenshot_20250110_135355](https://github.com/user-attachments/assets/14adc6e7-1b01-42df-8449-b80f57c73ec1)|![Screenshot_20250110_135419](https://github.com/user-attachments/assets/ed828856-d103-4a48-94d8-f400c7cf9141)|
  • Loading branch information
malmstein authored Jan 16, 2025
1 parent 9da9110 commit 399d328
Show file tree
Hide file tree
Showing 26 changed files with 975 additions and 210 deletions.
29 changes: 0 additions & 29 deletions app/src/main/res/drawable/ic_folder_add_24.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@
package com.duckduckgo.common.ui.view

import android.content.Context
import android.graphics.drawable.Drawable
import android.text.SpannableString
import android.text.style.ForegroundColorSpan
import android.util.AttributeSet
import android.widget.LinearLayout
import androidx.annotation.DrawableRes
import androidx.core.content.ContextCompat
import com.duckduckgo.common.ui.view.PopupMenuItemView.PopupMenuItemType.DESTRUCTIVE
import com.duckduckgo.common.ui.view.PopupMenuItemView.PopupMenuItemType.PRIMARY
Expand Down Expand Up @@ -55,6 +59,13 @@ constructor(
}
setPrimaryTextType(primaryTextType)
}

if (hasValue(R.styleable.PopupMenuItemView_trailingIcon)) {
setTrailingIconDrawable(getDrawable(R.styleable.PopupMenuItemView_trailingIcon)!!)
} else {
setTrailingIconVisibility(false)
}

binding.label.text = getString(R.styleable.PopupMenuItemView_primaryText) ?: ""
updateContentDescription()
recycle()
Expand All @@ -66,6 +77,10 @@ constructor(
updateContentDescription()
}

fun setPrimaryText(label: CharSequence) {
binding.label.text = label
}

fun setPrimaryText(label: () -> String) {
binding.label.text = label()
updateContentDescription()
Expand All @@ -82,6 +97,33 @@ constructor(
binding.root.contentDescription = binding.label.text
}

fun setDisabled() {
val textColorAttr = R.attr.daxColorTextDisabled
val spannable = SpannableString(binding.label.text)
spannable.setSpan(ForegroundColorSpan(binding.root.context.getColorFromAttr(textColorAttr)), 0, spannable.length, 0)
setPrimaryText(spannable)
isEnabled = false
}

fun setTrailingIconDrawable(drawable: Drawable) {
binding.trailingIcon.setImageDrawable(drawable)
setTrailingIconVisibility(true)
}

fun setTrailingIconResource(@DrawableRes resource: Int) {
binding.trailingIcon.setImageResource(resource)
setTrailingIconVisibility(true)
}

/** Sets the leading icon image visibility */
fun setTrailingIconVisibility(visible: Boolean) {
if (visible) {
binding.trailingIcon.show()
} else {
binding.trailingIcon.gone()
}
}

enum class PopupMenuItemType {
PRIMARY,
DESTRUCTIVE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,21 @@ abstract class DaxListItem(
itemContainer.setOnClickListener { onClick() }
}

/** Sets the item long click listener */
fun setLongClickListener(onClick: () -> Unit) {
itemContainer.setOnLongClickListener {
onClick()
true
}
}

/** Sets the item click listener */
fun removeLongClickListener() {
itemContainer.setOnLongClickListener {
false
}
}

/** Sets the primary text title */
fun setPrimaryText(title: CharSequence?) {
primaryText.text = title
Expand Down Expand Up @@ -146,7 +161,10 @@ abstract class DaxListItem(
* depends on the size of the image
*/

fun setLeadingIconSize(imageSize: IconSize, type: ImageBackground) {
fun setLeadingIconSize(
imageSize: IconSize,
type: ImageBackground,
) {
val iconSize = resources.getDimensionPixelSize(IconSize.dimension(imageSize))
val backgroundSize = if (type == ImageBackground.None) {
iconSize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,10 @@
app:primaryText="Destructive Type"
app:primaryTextType="destructive" />

<com.duckduckgo.common.ui.view.PopupMenuItemView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:primaryText="With trailing icon"
app:trailingIcon="@drawable/ic_bookmark_16"/>

</LinearLayout>
27 changes: 22 additions & 5 deletions common/common-ui/src/main/res/layout/view_popup_menu_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,38 @@
~ limitations under the License.
-->

<merge xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:parentTag="android.widget.LinearLayout">
android:background="?attr/selectableItemBackground"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<com.duckduckgo.common.ui.view.text.DaxTextView
android:id="@+id/label"
android:layout_width="match_parent"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:gravity="center_vertical"
android:minWidth="@dimen/popupMenuItemWidth"
android:minHeight="@dimen/popupMenuItemHeight"
android:paddingStart="@dimen/keyline_4"
android:paddingEnd="@dimen/keyline_4"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@id/trailingIcon"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:typography="body1"
tools:text="Text label" />
</merge>

<ImageView
android:id="@+id/trailingIcon"
android:layout_width="@dimen/keyline_4"
android:layout_height="@dimen/keyline_4"
android:layout_marginEnd="24dp"
android:src="@drawable/ic_check_24"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/label"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="ContentDescription" />
</androidx.constraintlayout.widget.ConstraintLayout>
1 change: 1 addition & 0 deletions common/common-ui/src/main/res/values/attrs-menu-item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<declare-styleable name="PopupMenuItemView">
<attr name="primaryText" />
<attr name="primaryTextType" />
<attr name="trailingIcon" />
</declare-styleable>

</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
<!-- Android Components -->
<item name="actionOverflowMenuStyle">@style/Widget.DuckDuckGo.PopUpOverflowMenu</item>
<item name="actionOverflowButtonStyle">@style/Widget.DuckDuckGo.OverflowButton</item>
<item name="popupMenuStyle">@style/Widget.DuckDuckGo.PopupMenu</item>
<item name="bottomSheetDialogTheme">@style/Widget.DuckDuckGo.BottomSheetDialog</item>
<item name="tabStyle">@style/Widget.DuckDuckGo.TabLayout</item>
<item name="radioButtonStyle">@style/Widget.DuckDuckGo.RadioButton</item>
Expand Down
7 changes: 6 additions & 1 deletion common/common-ui/src/main/res/values/widgets.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,12 @@
</style>

<style name="Widget.DuckDuckGo.PopupMenu" parent="Widget.MaterialComponents.PopupMenu">
<item name="android:background">@drawable/popup_menu_bg</item>
<item name="android:textColor">?daxColorPrimaryText</item>
<item name="android:itemBackground">?attr/selectableItemBackground</item>
<item name="android:popupBackground">@drawable/popup_menu_bg</item>
<item name="popupMenuBackground">@drawable/popup_menu_bg</item>
<item name="textAppearanceLargePopupMenu">?attr/textAppearanceBody1</item>
<item name="textAppearanceSmallPopupMenu">?attr/textAppearanceBody1</item>
</style>

<style name="Widget.DuckDuckGo.PopupMenuItem" parent="Typography.DuckDuckGo.Body1">
Expand Down
1 change: 1 addition & 0 deletions saved-sites/saved-sites-impl/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ dependencies {
anvil project(path: ':anvil-compiler')
implementation project(path: ':anvil-annotations')

implementation AndroidX.dataStore.preferences
implementation "io.reactivex.rxjava2:rxjava:_"
implementation "io.reactivex.rxjava2:rxandroid:_"
implementation AndroidX.appCompat
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ class BookmarkItemTouchHelperCallback(
override fun onSelectedChanged(viewHolder: RecyclerView.ViewHolder?, actionState: Int) {
super.onSelectedChanged(viewHolder, actionState)
if (actionState == ItemTouchHelper.ACTION_STATE_DRAG) {
adapter.isReorderingModeEnabled = true
adapter.isReordering = true
updateDragHandle(viewHolder, true)
} else if (actionState == ItemTouchHelper.ACTION_STATE_IDLE) {
adapter.isReorderingModeEnabled = false
adapter.isReordering = false
}
}

Expand Down
Loading

0 comments on commit 399d328

Please sign in to comment.