2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-02 03:40:16 +00:00

For #1843 - Wires up add to collection button

This commit is contained in:
Jeff Boek 2019-04-23 16:40:26 -07:00 committed by Emily Kager
parent f58400660a
commit 160e5ea1c8
7 changed files with 23 additions and 9 deletions

View File

@ -33,6 +33,7 @@ sealed class CollectionCreationAction : Action {
object SelectAllTapped : CollectionCreationAction()
data class AddTabToSelection(val tab: Tab) : CollectionCreationAction()
data class RemoveTabFromSelection(val tab: Tab) : CollectionCreationAction()
data class SaveTabsToCollection(val tabs: List<Tab>) : CollectionCreationAction()
}
class CollectionCreationComponent(
@ -63,4 +64,4 @@ class CollectionCreationComponent(
init {
render(reducer)
}
}
}

View File

@ -21,7 +21,6 @@ class CollectionCreationTabListAdapter(
val actionEmitter: Observer<CollectionCreationAction>
) : RecyclerView.Adapter<TabViewHolder>() {
private var tabs: List<Tab> = listOf()
private var selectedTabs: Set<Tab> = setOf()
private lateinit var job: Job

View File

@ -29,6 +29,7 @@ class CollectionCreationUIView(
.inflate(R.layout.component_collection_creation, container, true)
private val collectionCreationTabListAdapter = CollectionCreationTabListAdapter(actionEmitter)
private var selectedTabs: Set<Tab> = setOf()
init {
view.back_button.setOnClickListener {
@ -46,6 +47,10 @@ class CollectionCreationUIView(
}
}
view.add_tabs_button.setOnClickListener {
actionEmitter.onNext(CollectionCreationAction.SaveTabsToCollection(selectedTabs.toList()))
}
view.tab_list.run {
adapter = collectionCreationTabListAdapter
layoutManager = LinearLayoutManager(container.context, RecyclerView.VERTICAL, true)
@ -53,6 +58,7 @@ class CollectionCreationUIView(
}
override fun updateView() = Consumer<CollectionCreationState> {
this.selectedTabs = it.selectedTabs
collectionCreationTabListAdapter.updateData(it.tabs, it.selectedTabs)
val buttonText = if (it.selectedTabs.isEmpty()) {
@ -61,6 +67,9 @@ class CollectionCreationUIView(
view.context.getString(R.string.create_collection_save_to_collection_full, it.selectedTabs.size)
}
val enableSaveButton = it.selectedTabs.isNotEmpty()
view.add_tabs_button.isClickable = enableSaveButton
view.add_tabs_button.contentDescription = buttonText
view.add_tabs_button_text.text = buttonText
}
@ -68,4 +77,4 @@ class CollectionCreationUIView(
companion object {
private const val increaseButtonByDps = 16
}
}
}

View File

@ -15,6 +15,7 @@ import org.mozilla.fenix.R
import org.mozilla.fenix.mvi.ActionBusFactory
import org.mozilla.fenix.mvi.getAutoDisposeObservable
import org.mozilla.fenix.mvi.getManagedEmitter
import org.mozilla.fenix.utils.ItsNotBrokenSnack
class CreateCollectionFragment : DialogFragment() {
@ -25,10 +26,7 @@ class CreateCollectionFragment : DialogFragment() {
setStyle(DialogFragment.STYLE_NO_TITLE, R.style.CreateCollectionDialogStyle)
}
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view = inflater.inflate(R.layout.fragment_create_collection, container, false)
collectionCreationComponent = CollectionCreationComponent(
@ -50,6 +48,11 @@ class CreateCollectionFragment : DialogFragment() {
getAutoDisposeObservable<CollectionCreationAction>().subscribe {
when (it) {
is CollectionCreationAction.Close -> dismiss()
is CollectionCreationAction.SaveTabsToCollection -> {
dismiss()
ItsNotBrokenSnack(requireContext())
.showSnackbar("1843")
}
is CollectionCreationAction.AddTabToSelection -> getManagedEmitter<CollectionCreationChange>()
.onNext(CollectionCreationChange.TabAdded(it.tab))
is CollectionCreationAction.RemoveTabFromSelection -> getManagedEmitter<CollectionCreationChange>()

View File

@ -6,6 +6,6 @@ package org.mozilla.fenix.collections
import androidx.lifecycle.ViewModel
class CreateCollectionViewModel: ViewModel() {
class CreateCollectionViewModel : ViewModel() {
var tabs = listOf<Tab>()
}

View File

@ -57,6 +57,8 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:clickable="true"
android:focusable="true"
android:background="@drawable/add_tabs_to_collection_background"
android:foreground="?android:attr/selectableItemBackgroundBorderless"
android:clipToPadding="false"

View File

@ -116,7 +116,7 @@
<item name="android:textAppearance">@style/TextAppearance.AppCompat</item>
<item name="android:colorControlNormal">?accentHighContrast</item>
<item name="android:colorControlActivated">?accentHighContrast</item>
<item name="android:colorControlHighlight">?accent</item>
<item name="android:colorControlHighlight">?accentBright</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowAnimationStyle">@style/Animation.Design.BottomSheetDialog</item>