From 3307cf32057987ea09df99b4dee9e02c804ab142 Mon Sep 17 00:00:00 2001 From: Sawyer Blatz Date: Thu, 23 May 2019 10:11:22 -0700 Subject: [PATCH] [fenix] For https://github.com/mozilla-mobile/fenix/issues/2732: Removes view model usage from collection creation --- .../CollectionCreationComponent.kt | 2 +- .../collections/CollectionCreationUIView.kt | 4 +--- .../collections/CreateCollectionFragment.kt | 12 +++++----- .../collections/SaveCollectionListAdapter.kt | 22 +++++++++---------- .../res/layout/collection_home_list_row.xml | 1 - 5 files changed, 18 insertions(+), 23 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 5922fc3766..363d683ed2 100644 --- a/app/src/main/java/org/mozilla/fenix/collections/CollectionCreationComponent.kt +++ b/app/src/main/java/org/mozilla/fenix/collections/CollectionCreationComponent.kt @@ -54,7 +54,7 @@ sealed class CollectionCreationAction : Action { CollectionCreationAction() data class RenameCollection(val collection: TabCollection, val name: String) : CollectionCreationAction() - data class SelectCollection(val collection: TabCollection) : + data class SelectCollection(val collection: TabCollection, val tabs: List) : CollectionCreationAction() } 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 3964851bbf..2f71aa6033 100644 --- a/app/src/main/java/org/mozilla/fenix/collections/CollectionCreationUIView.kt +++ b/app/src/main/java/org/mozilla/fenix/collections/CollectionCreationUIView.kt @@ -21,7 +21,6 @@ import io.reactivex.Observer import io.reactivex.functions.Consumer import kotlinx.android.synthetic.main.component_collection_creation.* import kotlinx.android.synthetic.main.component_collection_creation.view.* -import kotlinx.android.synthetic.main.sign_in_preference.* import mozilla.components.support.ktx.android.view.hideKeyboard import mozilla.components.support.ktx.android.view.showKeyboard import org.mozilla.fenix.R @@ -257,8 +256,7 @@ class CollectionCreationUIView( view.context.getString(R.string.create_collection_name_collection) } } - - collectionSaveListAdapter.reloadData(it.tabCollections) + collectionSaveListAdapter.updateData(it.tabCollections, it.selectedTabs) } fun onResumed() { 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 1914e0706a..8304b88d7e 100644 --- a/app/src/main/java/org/mozilla/fenix/collections/CreateCollectionFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/collections/CreateCollectionFragment.kt @@ -103,17 +103,17 @@ class CreateCollectionFragment : DialogFragment(), CoroutineScope { .onNext(CollectionCreationChange.StepChanged(SaveCollectionStep.SelectCollection)) } is CollectionCreationAction.AddTabToSelection -> { - viewModel.selectedTabs.add(it.tab) getManagedEmitter() .onNext(CollectionCreationChange.TabAdded(it.tab)) } is CollectionCreationAction.RemoveTabFromSelection -> { - viewModel.selectedTabs.remove(it.tab) getManagedEmitter() .onNext(CollectionCreationChange.TabRemoved(it.tab)) } - is CollectionCreationAction.SelectAllTapped -> getManagedEmitter() - .onNext(CollectionCreationChange.AddAllTabs) + is CollectionCreationAction.SelectAllTapped -> { + getManagedEmitter() + .onNext(CollectionCreationChange.AddAllTabs) + } is CollectionCreationAction.AddNewCollection -> getManagedEmitter().onNext( CollectionCreationChange.StepChanged(SaveCollectionStep.NameCollection) ) @@ -130,10 +130,10 @@ class CreateCollectionFragment : DialogFragment(), CoroutineScope { } } is CollectionCreationAction.SelectCollection -> { - showSavedSnackbar(viewModel.selectedTabs.size) + showSavedSnackbar(it.tabs.size) dismiss() context?.let { context -> - val sessionBundle = viewModel.selectedTabs.toList().toSessionBundle(context) + val sessionBundle = it.tabs.toList().toSessionBundle(context) launch(Dispatchers.IO) { requireComponents.core.tabCollectionStorage .addTabsToCollection(it.collection, sessionBundle) diff --git a/app/src/main/java/org/mozilla/fenix/collections/SaveCollectionListAdapter.kt b/app/src/main/java/org/mozilla/fenix/collections/SaveCollectionListAdapter.kt index 1bb52dd1ef..bf1e7bd7fe 100644 --- a/app/src/main/java/org/mozilla/fenix/collections/SaveCollectionListAdapter.kt +++ b/app/src/main/java/org/mozilla/fenix/collections/SaveCollectionListAdapter.kt @@ -14,6 +14,7 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job import org.mozilla.fenix.R +import org.mozilla.fenix.home.sessioncontrol.Tab import org.mozilla.fenix.home.sessioncontrol.TabCollection import kotlin.coroutines.CoroutineContext @@ -23,6 +24,7 @@ class SaveCollectionListAdapter( private lateinit var job: Job private var tabCollections = listOf() + private var selectedTabs: Set = setOf() override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CollectionViewHolder { val view = LayoutInflater.from(parent.context) @@ -34,6 +36,12 @@ class SaveCollectionListAdapter( override fun onBindViewHolder(holder: CollectionViewHolder, position: Int) { val collection = tabCollections[position] holder.bind(collection) + holder.view.setOnClickListener { + collection.apply { + val action = CollectionCreationAction.SelectCollection(this, selectedTabs.toList()) + actionEmitter.onNext(action) + } + } } override fun getItemCount(): Int = tabCollections.size @@ -48,8 +56,9 @@ class SaveCollectionListAdapter( job.cancel() } - fun reloadData(tabCollections: List) { + fun updateData(tabCollections: List, selectedTabs: Set) { this.tabCollections = tabCollections + this.selectedTabs = selectedTabs notifyDataSetChanged() } } @@ -66,17 +75,6 @@ class CollectionViewHolder( private var collection: TabCollection? = null - private val listener = View.OnClickListener { - collection?.apply { - val action = CollectionCreationAction.SelectCollection(this) - actionEmitter.onNext(action) - } - } - - init { - view.setOnClickListener(listener) - } - fun bind(collection: TabCollection) { this.collection = collection view.collection_item.text = collection.title diff --git a/app/src/main/res/layout/collection_home_list_row.xml b/app/src/main/res/layout/collection_home_list_row.xml index ea80a71599..d22bdd30e6 100644 --- a/app/src/main/res/layout/collection_home_list_row.xml +++ b/app/src/main/res/layout/collection_home_list_row.xml @@ -45,7 +45,6 @@ android:drawablePadding="8dp" android:layout_marginEnd="16dp" app:layout_constraintStart_toEndOf="@id/collection_icon" - app:layout_constraintEnd_toStartOf="@id/collection_share_button" app:layout_constraintTop_toTopOf="parent" android:text="The quick brown fox jumps over the lazy dog"/>