mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-19 09:25:34 +00:00
[fenix] For https://github.com/mozilla-mobile/fenix/issues/2732: Removes view model usage from collection creation
This commit is contained in:
parent
30807f9d8b
commit
3307cf3205
@ -54,7 +54,7 @@ sealed class CollectionCreationAction : Action {
|
|||||||
CollectionCreationAction()
|
CollectionCreationAction()
|
||||||
data class RenameCollection(val collection: TabCollection, val name: String) :
|
data class RenameCollection(val collection: TabCollection, val name: String) :
|
||||||
CollectionCreationAction()
|
CollectionCreationAction()
|
||||||
data class SelectCollection(val collection: TabCollection) :
|
data class SelectCollection(val collection: TabCollection, val tabs: List<Tab>) :
|
||||||
CollectionCreationAction()
|
CollectionCreationAction()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,6 @@ import io.reactivex.Observer
|
|||||||
import io.reactivex.functions.Consumer
|
import io.reactivex.functions.Consumer
|
||||||
import kotlinx.android.synthetic.main.component_collection_creation.*
|
import kotlinx.android.synthetic.main.component_collection_creation.*
|
||||||
import kotlinx.android.synthetic.main.component_collection_creation.view.*
|
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.hideKeyboard
|
||||||
import mozilla.components.support.ktx.android.view.showKeyboard
|
import mozilla.components.support.ktx.android.view.showKeyboard
|
||||||
import org.mozilla.fenix.R
|
import org.mozilla.fenix.R
|
||||||
@ -257,8 +256,7 @@ class CollectionCreationUIView(
|
|||||||
view.context.getString(R.string.create_collection_name_collection)
|
view.context.getString(R.string.create_collection_name_collection)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
collectionSaveListAdapter.updateData(it.tabCollections, it.selectedTabs)
|
||||||
collectionSaveListAdapter.reloadData(it.tabCollections)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onResumed() {
|
fun onResumed() {
|
||||||
|
@ -103,17 +103,17 @@ class CreateCollectionFragment : DialogFragment(), CoroutineScope {
|
|||||||
.onNext(CollectionCreationChange.StepChanged(SaveCollectionStep.SelectCollection))
|
.onNext(CollectionCreationChange.StepChanged(SaveCollectionStep.SelectCollection))
|
||||||
}
|
}
|
||||||
is CollectionCreationAction.AddTabToSelection -> {
|
is CollectionCreationAction.AddTabToSelection -> {
|
||||||
viewModel.selectedTabs.add(it.tab)
|
|
||||||
getManagedEmitter<CollectionCreationChange>()
|
getManagedEmitter<CollectionCreationChange>()
|
||||||
.onNext(CollectionCreationChange.TabAdded(it.tab))
|
.onNext(CollectionCreationChange.TabAdded(it.tab))
|
||||||
}
|
}
|
||||||
is CollectionCreationAction.RemoveTabFromSelection -> {
|
is CollectionCreationAction.RemoveTabFromSelection -> {
|
||||||
viewModel.selectedTabs.remove(it.tab)
|
|
||||||
getManagedEmitter<CollectionCreationChange>()
|
getManagedEmitter<CollectionCreationChange>()
|
||||||
.onNext(CollectionCreationChange.TabRemoved(it.tab))
|
.onNext(CollectionCreationChange.TabRemoved(it.tab))
|
||||||
}
|
}
|
||||||
is CollectionCreationAction.SelectAllTapped -> getManagedEmitter<CollectionCreationChange>()
|
is CollectionCreationAction.SelectAllTapped -> {
|
||||||
|
getManagedEmitter<CollectionCreationChange>()
|
||||||
.onNext(CollectionCreationChange.AddAllTabs)
|
.onNext(CollectionCreationChange.AddAllTabs)
|
||||||
|
}
|
||||||
is CollectionCreationAction.AddNewCollection -> getManagedEmitter<CollectionCreationChange>().onNext(
|
is CollectionCreationAction.AddNewCollection -> getManagedEmitter<CollectionCreationChange>().onNext(
|
||||||
CollectionCreationChange.StepChanged(SaveCollectionStep.NameCollection)
|
CollectionCreationChange.StepChanged(SaveCollectionStep.NameCollection)
|
||||||
)
|
)
|
||||||
@ -130,10 +130,10 @@ class CreateCollectionFragment : DialogFragment(), CoroutineScope {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
is CollectionCreationAction.SelectCollection -> {
|
is CollectionCreationAction.SelectCollection -> {
|
||||||
showSavedSnackbar(viewModel.selectedTabs.size)
|
showSavedSnackbar(it.tabs.size)
|
||||||
dismiss()
|
dismiss()
|
||||||
context?.let { context ->
|
context?.let { context ->
|
||||||
val sessionBundle = viewModel.selectedTabs.toList().toSessionBundle(context)
|
val sessionBundle = it.tabs.toList().toSessionBundle(context)
|
||||||
launch(Dispatchers.IO) {
|
launch(Dispatchers.IO) {
|
||||||
requireComponents.core.tabCollectionStorage
|
requireComponents.core.tabCollectionStorage
|
||||||
.addTabsToCollection(it.collection, sessionBundle)
|
.addTabsToCollection(it.collection, sessionBundle)
|
||||||
|
@ -14,6 +14,7 @@ import kotlinx.coroutines.CoroutineScope
|
|||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
import org.mozilla.fenix.R
|
import org.mozilla.fenix.R
|
||||||
|
import org.mozilla.fenix.home.sessioncontrol.Tab
|
||||||
import org.mozilla.fenix.home.sessioncontrol.TabCollection
|
import org.mozilla.fenix.home.sessioncontrol.TabCollection
|
||||||
import kotlin.coroutines.CoroutineContext
|
import kotlin.coroutines.CoroutineContext
|
||||||
|
|
||||||
@ -23,6 +24,7 @@ class SaveCollectionListAdapter(
|
|||||||
|
|
||||||
private lateinit var job: Job
|
private lateinit var job: Job
|
||||||
private var tabCollections = listOf<TabCollection>()
|
private var tabCollections = listOf<TabCollection>()
|
||||||
|
private var selectedTabs: Set<Tab> = setOf()
|
||||||
|
|
||||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CollectionViewHolder {
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CollectionViewHolder {
|
||||||
val view = LayoutInflater.from(parent.context)
|
val view = LayoutInflater.from(parent.context)
|
||||||
@ -34,6 +36,12 @@ class SaveCollectionListAdapter(
|
|||||||
override fun onBindViewHolder(holder: CollectionViewHolder, position: Int) {
|
override fun onBindViewHolder(holder: CollectionViewHolder, position: Int) {
|
||||||
val collection = tabCollections[position]
|
val collection = tabCollections[position]
|
||||||
holder.bind(collection)
|
holder.bind(collection)
|
||||||
|
holder.view.setOnClickListener {
|
||||||
|
collection.apply {
|
||||||
|
val action = CollectionCreationAction.SelectCollection(this, selectedTabs.toList())
|
||||||
|
actionEmitter.onNext(action)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getItemCount(): Int = tabCollections.size
|
override fun getItemCount(): Int = tabCollections.size
|
||||||
@ -48,8 +56,9 @@ class SaveCollectionListAdapter(
|
|||||||
job.cancel()
|
job.cancel()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun reloadData(tabCollections: List<TabCollection>) {
|
fun updateData(tabCollections: List<TabCollection>, selectedTabs: Set<Tab>) {
|
||||||
this.tabCollections = tabCollections
|
this.tabCollections = tabCollections
|
||||||
|
this.selectedTabs = selectedTabs
|
||||||
notifyDataSetChanged()
|
notifyDataSetChanged()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -66,17 +75,6 @@ class CollectionViewHolder(
|
|||||||
|
|
||||||
private var collection: TabCollection? = null
|
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) {
|
fun bind(collection: TabCollection) {
|
||||||
this.collection = collection
|
this.collection = collection
|
||||||
view.collection_item.text = collection.title
|
view.collection_item.text = collection.title
|
||||||
|
@ -45,7 +45,6 @@
|
|||||||
android:drawablePadding="8dp"
|
android:drawablePadding="8dp"
|
||||||
android:layout_marginEnd="16dp"
|
android:layout_marginEnd="16dp"
|
||||||
app:layout_constraintStart_toEndOf="@id/collection_icon"
|
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"/>
|
app:layout_constraintTop_toTopOf="parent" android:text="The quick brown fox jumps over the lazy dog"/>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
|
Loading…
Reference in New Issue
Block a user