For #1843 - Displays tabs on the tab selection screen

nightly-build-test
Jeff Boek 5 years ago committed by Emily Kager
parent 8be0d6fea5
commit ba90b58d32

@ -1,5 +1,9 @@
package org.mozilla.fenix.collections
/* This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import android.view.ViewGroup
import org.mozilla.fenix.mvi.Action
import org.mozilla.fenix.mvi.ActionBusFactory
@ -8,16 +12,17 @@ import org.mozilla.fenix.mvi.Reducer
import org.mozilla.fenix.mvi.UIComponent
import org.mozilla.fenix.mvi.ViewState
/* This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/. */
data class Tab(
val sessionId: String,
val url: String,
val hostname: String,
val title: String
)
sealed class CollectionCreationState : ViewState {
object Empty : CollectionCreationState()
}
data class CollectionCreationState(val tabs: List<Tab> = listOf()) : ViewState
sealed class CollectionCreationChange : Change {
data class TabListChange(val tabs: List<Tab>) : CollectionCreationChange()
}
sealed class CollectionCreationAction : Action {
@ -27,13 +32,15 @@ sealed class CollectionCreationAction : Action {
class CollectionCreationComponent(
private val container: ViewGroup,
bus: ActionBusFactory,
override var initialState: CollectionCreationState = CollectionCreationState.Empty
override var initialState: CollectionCreationState = CollectionCreationState()
) : UIComponent<CollectionCreationState, CollectionCreationAction, CollectionCreationChange>(
bus.getManagedEmitter(CollectionCreationAction::class.java),
bus.getSafeManagedObservable(CollectionCreationChange::class.java)
) {
override val reducer: Reducer<CollectionCreationState, CollectionCreationChange> = { state, change ->
CollectionCreationState.Empty
when (change) {
is CollectionCreationChange.TabListChange -> state.copy(tabs = change.tabs)
}
}
override fun initView() = CollectionCreationUIView(container, actionEmitter, changesObservable)

@ -0,0 +1,86 @@
package org.mozilla.fenix.collections
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import io.reactivex.Observer
import kotlinx.android.synthetic.main.collection_tab_list_row.view.*
import kotlinx.android.synthetic.main.tab_list_row.*
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import mozilla.components.browser.icons.IconRequest
import org.mozilla.fenix.R
import org.mozilla.fenix.ext.components
import kotlin.coroutines.CoroutineContext
class CollectionCreationTabListAdapter(
val actionEmitter: Observer<CollectionCreationAction>
) : RecyclerView.Adapter<TabViewHolder>() {
private var data: List<Tab> = listOf()
private lateinit var job: Job
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): TabViewHolder {
val view = LayoutInflater.from(parent.context).inflate(TabViewHolder.LAYOUT_ID, parent, false)
return TabViewHolder(view, actionEmitter, job)
}
override fun onBindViewHolder(holder: TabViewHolder, position: Int) {
holder.bind(data[position])
}
override fun getItemCount(): Int = data.size
override fun onAttachedToRecyclerView(recyclerView: RecyclerView) {
super.onAttachedToRecyclerView(recyclerView)
job = Job()
}
override fun onDetachedFromRecyclerView(recyclerView: RecyclerView) {
super.onDetachedFromRecyclerView(recyclerView)
job.cancel()
}
fun updateData(tabs: List<Tab>) {
data = tabs
notifyDataSetChanged()
}
}
class TabViewHolder(
val view: View,
actionEmitter: Observer<CollectionCreationAction>,
val job: Job
) :
RecyclerView.ViewHolder(view), CoroutineScope {
override val coroutineContext: CoroutineContext
get() = Dispatchers.IO + job
var tab: Tab? = null
init { }
fun bind(tab: Tab) {
this.tab = tab
view.hostname.text = tab.hostname
view.tab_title.text = tab.title
launch(Dispatchers.IO) {
val bitmap = view.favicon_image.context.components.utils.icons
.loadIcon(IconRequest(tab.url)).await().bitmap
launch(Dispatchers.Main) {
view.favicon_image.setImageBitmap(bitmap)
}
}
}
companion object {
const val LAYOUT_ID = R.layout.collection_tab_list_row
}
}

@ -4,12 +4,16 @@ package org.mozilla.fenix.collections
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import android.util.Log
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import org.mozilla.fenix.R
import io.reactivex.Observer
import io.reactivex.Observable
import io.reactivex.functions.Consumer
import kotlinx.android.synthetic.main.component_collection_creation.view.*
import org.mozilla.fenix.mvi.UIView
class CollectionCreationUIView(
@ -24,7 +28,24 @@ class CollectionCreationUIView(
override val view = LayoutInflater.from(container.context)
.inflate(R.layout.component_collection_creation, container, true)
override fun updateView() = Consumer<CollectionCreationState> {
private val collectionCreationTabListAdapter = CollectionCreationTabListAdapter(actionEmitter)
init {
view.back_button.setOnClickListener {
Log.e("Collection Creation", "Back button tapped")
}
view.select_all_button.setOnClickListener {
Log.e("Collection Creation", "Select All Tapped!")
}
view.tab_list.run {
adapter = collectionCreationTabListAdapter
layoutManager = LinearLayoutManager(container.context, RecyclerView.VERTICAL, true)
}
}
override fun updateView() = Consumer<CollectionCreationState> {
collectionCreationTabListAdapter.updateData(it.tabs)
}
}

@ -9,9 +9,11 @@ import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.lifecycle.ViewModelProviders
import kotlinx.android.synthetic.main.fragment_create_collection.view.*
import org.mozilla.fenix.R
import org.mozilla.fenix.mvi.ActionBusFactory
import org.mozilla.fenix.mvi.getManagedEmitter
class CreateCollectionFragment : Fragment() {
@ -30,4 +32,13 @@ class CreateCollectionFragment : Fragment() {
return view
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val tabs = activity?.run {
ViewModelProviders.of(this).get(CreateCollectionViewModel::class.java)
}!!.tabs
getManagedEmitter<CollectionCreationChange>().onNext(CollectionCreationChange.TabListChange(tabs))
}
}

@ -0,0 +1,11 @@
package org.mozilla.fenix.collections
/* This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import androidx.lifecycle.ViewModel
class CreateCollectionViewModel: ViewModel() {
var tabs = listOf<Tab>()
}

@ -17,6 +17,7 @@ import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProviders
import androidx.navigation.Navigation
import kotlinx.android.synthetic.main.fragment_home.*
import kotlinx.android.synthetic.main.fragment_home.view.*
@ -32,6 +33,8 @@ import org.mozilla.fenix.BrowsingModeManager
import org.mozilla.fenix.DefaultThemeManager
import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.R
import org.mozilla.fenix.collections.CreateCollectionViewModel
import org.mozilla.fenix.collections.Tab
import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.ext.requireComponents
import org.mozilla.fenix.ext.share
@ -177,6 +180,13 @@ class HomeFragment : Fragment(), CoroutineScope {
private fun handleTabAction(action: TabAction) {
Do exhaustive when (action) {
is TabAction.SaveTabGroup -> {
val tabs = requireComponents.core.sessionManager.sessions
.map { Tab(it.id, it.url, it.url.urlToHost(), it.title) }
activity?.run {
ViewModelProviders.of(this).get(CreateCollectionViewModel::class.java)
}!!.tabs = tabs
val direction = HomeFragmentDirections.actionHomeFragmentToCreateCollectionFragment()
Navigation.findNavController(view!!).navigate(direction)
}

@ -0,0 +1,68 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/collection_item_tab"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:clickable="true"
android:clipToPadding="false"
android:focusable="true"
android:foreground="?android:attr/selectableItemBackground"
app:cardBackgroundColor="?above"
app:cardCornerRadius="@dimen/tab_corner_radius"
app:cardElevation="5dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/favicon_image"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_margin="8dp"
android:adjustViewBounds="true"
android:importantForAccessibility="no"
android:scaleType="fitCenter"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/hostname"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:ellipsize="none"
android:singleLine="true"
android:textColor="?secondaryText"
android:textSize="12sp"
android:textStyle="bold"
app:layout_constraintEnd_toStartOf="@id/close_tab_button"
app:layout_constraintStart_toEndOf="@id/favicon_image"
app:layout_constraintTop_toTopOf="@id/favicon_image" />
<TextView
android:id="@+id/tab_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:layout_marginStart="8dp"
android:layout_marginBottom="8dp"
android:ellipsize="end"
android:maxLines="2"
android:minLines="2"
android:textColor="?primaryText"
android:textSize="15sp"
app:layout_constraintStart_toEndOf="@id/favicon_image"
app:layout_constraintEnd_toEndOf="@id/hostname"
app:layout_constraintTop_toBottomOf="@id/hostname"
app:layout_constraintBottom_toBottomOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>

@ -24,6 +24,7 @@
app:layout_constraintStart_toStartOf="parent" />
<Button
android:id="@+id/select_all_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackgroundBorderless"
@ -34,4 +35,14 @@
android:layout_margin="16dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/tab_list"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_margin="16dp"
app:layout_constraintTop_toBottomOf="@id/back_button"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

@ -291,5 +291,6 @@
android:id="@+id/createCollectionFragment"
android:name="org.mozilla.fenix.collections.CreateCollectionFragment"
android:label="fragment_create_collection"
tools:layout="@layout/fragment_create_collection" />
tools:layout="@layout/fragment_create_collection" >
</fragment>
</navigation>
Loading…
Cancel
Save