Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
For #21037 - Add a delete history menu item
Browse files Browse the repository at this point in the history
This removes the existing "Delete history" button in the History in favour of a menu item
  • Loading branch information
gabrielluong committed Aug 30, 2021
1 parent fe8f4be commit 6213f81
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ class HistoryFragment : LibraryPageFragment<HistoryItem>(), UserInteractionHandl
}

private fun deleteHistoryItems(items: Set<HistoryItem>) {

updatePendingHistoryToDelete(items)
undoScope = CoroutineScope(IO)
undoScope?.allowUndo(
Expand Down Expand Up @@ -182,6 +181,8 @@ class HistoryFragment : LibraryPageFragment<HistoryItem>(), UserInteractionHandl
SpannableString(getString(R.string.bookmark_menu_delete_button)).apply {
setTextColor(requireContext(), R.attr.destructive)
}
} else {
inflater.inflate(R.menu.history_menu, menu)
}
}

Expand Down Expand Up @@ -220,6 +221,10 @@ class HistoryFragment : LibraryPageFragment<HistoryItem>(), UserInteractionHandl
showTabTray()
true
}
R.id.history_delete_all -> {
historyInteractor.onDeleteAll()
true
}
else -> super.onOptionsItemSelected(item)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,6 @@ class HistoryListItemViewHolder(
init {
setupMenu()

binding.deleteButton.setOnClickListener {
val selected = selectionHolder.selectedItems
if (selected.isEmpty()) {
historyInteractor.onDeleteAll()
} else {
historyInteractor.onDeleteSome(selected)
}
}

binding.recentlyClosedNavEmpty.recentlyClosedNav.setOnClickListener {
historyInteractor.onRecentlyClosedClicked()
}
Expand All @@ -49,7 +40,7 @@ class HistoryListItemViewHolder(
fun bind(
item: HistoryItem,
timeGroup: HistoryItemTimeGroup?,
showDeleteButton: Boolean,
showTopContent: Boolean,
mode: HistoryFragmentState.Mode,
isPendingDeletion: Boolean = false
) {
Expand All @@ -62,7 +53,7 @@ class HistoryListItemViewHolder(
binding.historyLayout.titleView.text = item.title
binding.historyLayout.urlView.text = item.url

toggleTopContent(showDeleteButton, mode === HistoryFragmentState.Mode.Normal)
toggleTopContent(showTopContent, mode === HistoryFragmentState.Mode.Normal)

val headerText = timeGroup?.humanReadable(itemView.context)
toggleHeader(headerText)
Expand Down Expand Up @@ -96,19 +87,9 @@ class HistoryListItemViewHolder(
showTopContent: Boolean,
isNormalMode: Boolean
) {
binding.deleteButton.isVisible = showTopContent
binding.recentlyClosedNavEmpty.recentlyClosedNav.isVisible = showTopContent

if (showTopContent) {
binding.deleteButton.run {
if (isNormalMode) {
isEnabled = true
alpha = 1f
} else {
isEnabled = false
alpha = DELETE_BUTTON_DISABLED_ALPHA
}
}
val numRecentTabs = itemView.context.components.core.store.state.closedTabs.size
binding.recentlyClosedNavEmpty.recentlyClosedTabsDescription.text = String.format(
itemView.context.getString(
Expand All @@ -123,7 +104,7 @@ class HistoryListItemViewHolder(
alpha = 1f
} else {
isEnabled = false
alpha = DELETE_BUTTON_DISABLED_ALPHA
alpha = DISABLED_BUTTON_ALPHA
}
}
}
Expand All @@ -145,7 +126,7 @@ class HistoryListItemViewHolder(
}

companion object {
const val DELETE_BUTTON_DISABLED_ALPHA = 0.7f
const val DISABLED_BUTTON_ALPHA = 0.7f
const val LAYOUT_ID = R.layout.history_list_item
}
}
9 changes: 0 additions & 9 deletions app/src/main/res/layout/history_list_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,6 @@
android:importantForAccessibility="no"
android:orientation="vertical">

<com.google.android.material.button.MaterialButton
android:id="@+id/delete_button"
style="@style/DestructiveButton"
android:layout_marginHorizontal="16dp"
android:layout_marginTop="8dp"
android:text="@string/history_delete_all"
android:visibility="gone"
tools:visibility="visible" />

<include
android:id="@+id/recently_closed_nav_empty"
layout="@layout/recently_closed_nav_item" />
Expand Down
13 changes: 13 additions & 0 deletions app/src/main/res/menu/history_menu.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/history_delete_all"
android:icon="@drawable/ic_delete"
android:title="@string/history_delete_all"
app:iconTint="?primaryText"
app:showAsAction="ifRoom" />
</menu>

0 comments on commit 6213f81

Please sign in to comment.