From 160e5ea1c8babf91da5f2376e3f4018a089afe2c Mon Sep 17 00:00:00 2001 From: Jeff Boek Date: Tue, 23 Apr 2019 16:40:26 -0700 Subject: [PATCH] For #1843 - Wires up add to collection button --- .../fenix/collections/CollectionCreationComponent.kt | 3 ++- .../collections/CollectionCreationTabListAdapter.kt | 1 - .../fenix/collections/CollectionCreationUIView.kt | 11 ++++++++++- .../fenix/collections/CreateCollectionFragment.kt | 11 +++++++---- .../fenix/collections/CreateCollectionViewModel.kt | 2 +- .../main/res/layout/component_collection_creation.xml | 2 ++ app/src/main/res/values/styles.xml | 2 +- 7 files changed, 23 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/org/mozilla/fenix/collections/CollectionCreationComponent.kt b/app/src/main/java/org/mozilla/fenix/collections/CollectionCreationComponent.kt index 8d9cf57764..d970f238d6 100644 --- a/app/src/main/java/org/mozilla/fenix/collections/CollectionCreationComponent.kt +++ b/app/src/main/java/org/mozilla/fenix/collections/CollectionCreationComponent.kt @@ -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) : CollectionCreationAction() } class CollectionCreationComponent( @@ -63,4 +64,4 @@ class CollectionCreationComponent( init { render(reducer) } -} \ No newline at end of file +} diff --git a/app/src/main/java/org/mozilla/fenix/collections/CollectionCreationTabListAdapter.kt b/app/src/main/java/org/mozilla/fenix/collections/CollectionCreationTabListAdapter.kt index bf7aec248f..2ac573f4bc 100644 --- a/app/src/main/java/org/mozilla/fenix/collections/CollectionCreationTabListAdapter.kt +++ b/app/src/main/java/org/mozilla/fenix/collections/CollectionCreationTabListAdapter.kt @@ -21,7 +21,6 @@ class CollectionCreationTabListAdapter( val actionEmitter: Observer ) : RecyclerView.Adapter() { - private var tabs: List = listOf() private var selectedTabs: Set = setOf() private lateinit var job: Job diff --git a/app/src/main/java/org/mozilla/fenix/collections/CollectionCreationUIView.kt b/app/src/main/java/org/mozilla/fenix/collections/CollectionCreationUIView.kt index 53748736e2..4305831305 100644 --- a/app/src/main/java/org/mozilla/fenix/collections/CollectionCreationUIView.kt +++ b/app/src/main/java/org/mozilla/fenix/collections/CollectionCreationUIView.kt @@ -29,6 +29,7 @@ class CollectionCreationUIView( .inflate(R.layout.component_collection_creation, container, true) private val collectionCreationTabListAdapter = CollectionCreationTabListAdapter(actionEmitter) + private var selectedTabs: Set = 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 { + 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 } -} \ No newline at end of file +} diff --git a/app/src/main/java/org/mozilla/fenix/collections/CreateCollectionFragment.kt b/app/src/main/java/org/mozilla/fenix/collections/CreateCollectionFragment.kt index c21bef1b31..f19cd18f2f 100644 --- a/app/src/main/java/org/mozilla/fenix/collections/CreateCollectionFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/collections/CreateCollectionFragment.kt @@ -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().subscribe { when (it) { is CollectionCreationAction.Close -> dismiss() + is CollectionCreationAction.SaveTabsToCollection -> { + dismiss() + ItsNotBrokenSnack(requireContext()) + .showSnackbar("1843") + } is CollectionCreationAction.AddTabToSelection -> getManagedEmitter() .onNext(CollectionCreationChange.TabAdded(it.tab)) is CollectionCreationAction.RemoveTabFromSelection -> getManagedEmitter() diff --git a/app/src/main/java/org/mozilla/fenix/collections/CreateCollectionViewModel.kt b/app/src/main/java/org/mozilla/fenix/collections/CreateCollectionViewModel.kt index 9d2ba952df..f605595080 100644 --- a/app/src/main/java/org/mozilla/fenix/collections/CreateCollectionViewModel.kt +++ b/app/src/main/java/org/mozilla/fenix/collections/CreateCollectionViewModel.kt @@ -6,6 +6,6 @@ package org.mozilla.fenix.collections import androidx.lifecycle.ViewModel -class CreateCollectionViewModel: ViewModel() { +class CreateCollectionViewModel : ViewModel() { var tabs = listOf() } diff --git a/app/src/main/res/layout/component_collection_creation.xml b/app/src/main/res/layout/component_collection_creation.xml index 75d5f5359f..0d538363ce 100644 --- a/app/src/main/res/layout/component_collection_creation.xml +++ b/app/src/main/res/layout/component_collection_creation.xml @@ -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" diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index f40cd9b397..e0d562240e 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -116,7 +116,7 @@ @style/TextAppearance.AppCompat ?accentHighContrast ?accentHighContrast - ?accent + ?accentBright @android:color/transparent @style/Animation.Design.BottomSheetDialog