Commit df131d2e authored by Sawyer Blatz's avatar Sawyer Blatz
Browse files

For #7563: Allow GeckoActions to be sorted

parent f70216b2
......@@ -42,6 +42,9 @@ class GeckoSelectionActionDelegateTest {
override fun isActionAvailable(id: String): Boolean = false
override fun getActionTitle(id: String): CharSequence? = ""
override fun performAction(id: String, selectedText: String): Boolean = false
override fun sortedActions(actions: Array<String>): Array<String> {
return actions
}
}
val geckoDelegate = TestGeckoSelectionActionDelegate(mock(), customDelegate)
......
......@@ -42,6 +42,9 @@ class GeckoSelectionActionDelegateTest {
override fun isActionAvailable(id: String): Boolean = false
override fun getActionTitle(id: String): CharSequence? = ""
override fun performAction(id: String, selectedText: String): Boolean = false
override fun sortedActions(actions: Array<String>): Array<String> {
return actions
}
}
val geckoDelegate = TestGeckoSelectionActionDelegate(mock(), customDelegate)
......
......@@ -37,7 +37,7 @@ open class GeckoSelectionActionDelegate(
}
override fun getAllActions(): Array<String> {
return super.getAllActions() + customDelegate.getAllActions()
return customDelegate.sortedActions(super.getAllActions() + customDelegate.getAllActions())
}
override fun isActionAvailable(id: String): Boolean {
......
......@@ -42,6 +42,9 @@ class GeckoSelectionActionDelegateTest {
override fun isActionAvailable(id: String): Boolean = false
override fun getActionTitle(id: String): CharSequence? = ""
override fun performAction(id: String, selectedText: String): Boolean = false
override fun sortedActions(actions: Array<String>): Array<String> {
return actions
}
}
val geckoDelegate = TestGeckoSelectionActionDelegate(mock(), customDelegate)
......
......@@ -36,4 +36,11 @@ interface SelectionActionDelegate {
* @returns [true] if the action was consumed.
*/
fun performAction(id: String, selectedText: String): Boolean
/**
* Takes in a list of actions and sorts them.
*
* @returns the sorted list.
*/
fun sortedActions(actions: Array<String>): Array<String>
}
......@@ -24,7 +24,8 @@ private val customActions = arrayOf(SEARCH, SEARCH_PRIVATELY, SHARE)
class DefaultSelectionActionDelegate(
private val searchAdapter: SearchAdapter,
resources: Resources,
private val shareTextClicked: ((String) -> Unit)? = null
private val shareTextClicked: ((String) -> Unit)? = null,
private val actionSorter: ((Array<String>) -> Array<String>)? = null
) : SelectionActionDelegate {
private val normalSearchText =
......@@ -64,4 +65,16 @@ class DefaultSelectionActionDelegate(
}
else -> false
}
/**
* Takes in a list of actions and sorts them.
* @returns the sorted list.
*/
override fun sortedActions(actions: Array<String>): Array<String> {
return if (actionSorter != null) {
actionSorter.invoke(actions)
} else {
actions
}
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment