Skip to content

Commit

Permalink
For mozilla-mobile#11112 - Adds save tabs to collection button to the…
Browse files Browse the repository at this point in the history
… no collections message
  • Loading branch information
boek committed Jun 12, 2020
1 parent 35fa445 commit 76ee736
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 127 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.annotation.LayoutRes
import androidx.annotation.StringRes
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
Expand All @@ -19,7 +18,7 @@ import org.mozilla.fenix.home.OnboardingState
import org.mozilla.fenix.home.Tab
import org.mozilla.fenix.home.sessioncontrol.viewholders.CollectionHeaderViewHolder
import org.mozilla.fenix.home.sessioncontrol.viewholders.CollectionViewHolder
import org.mozilla.fenix.home.sessioncontrol.viewholders.NoContentMessageViewHolder
import org.mozilla.fenix.home.sessioncontrol.viewholders.NoCollectionsMessageViewHolder
import org.mozilla.fenix.home.sessioncontrol.viewholders.PrivateBrowsingDescriptionViewHolder
import org.mozilla.fenix.home.sessioncontrol.viewholders.TabInCollectionViewHolder
import org.mozilla.fenix.home.sessioncontrol.viewholders.TopSiteViewHolder
Expand All @@ -42,10 +41,7 @@ sealed class AdapterItem(@LayoutRes val viewType: Int) {
ButtonTipViewHolder.LAYOUT_ID)
data class TopSiteList(val topSites: List<TopSite>) : AdapterItem(TopSiteViewHolder.LAYOUT_ID)
object PrivateBrowsingDescription : AdapterItem(PrivateBrowsingDescriptionViewHolder.LAYOUT_ID)
data class NoContentMessage(
@StringRes val header: Int,
@StringRes val description: Int
) : AdapterItem(NoContentMessageViewHolder.LAYOUT_ID)
object NoCollectionsMessage : AdapterItem(NoCollectionsMessageViewHolder.LAYOUT_ID)

object CollectionHeader : AdapterItem(CollectionHeaderViewHolder.LAYOUT_ID)
data class CollectionItem(
Expand Down Expand Up @@ -123,7 +119,7 @@ class SessionControlAdapter(
ButtonTipViewHolder.LAYOUT_ID -> ButtonTipViewHolder(view, interactor)
TopSiteViewHolder.LAYOUT_ID -> TopSiteViewHolder(view, interactor)
PrivateBrowsingDescriptionViewHolder.LAYOUT_ID -> PrivateBrowsingDescriptionViewHolder(view, interactor)
NoContentMessageViewHolder.LAYOUT_ID -> NoContentMessageViewHolder(view)
NoCollectionsMessageViewHolder.LAYOUT_ID -> NoCollectionsMessageViewHolder(view, interactor)
CollectionHeaderViewHolder.LAYOUT_ID -> CollectionHeaderViewHolder(view)
CollectionViewHolder.LAYOUT_ID -> CollectionViewHolder(view, interactor)
TabInCollectionViewHolder.LAYOUT_ID -> TabInCollectionViewHolder(view, interactor, differentLastItem = true)
Expand Down Expand Up @@ -155,10 +151,6 @@ class SessionControlAdapter(
is TopSiteViewHolder -> {
holder.bind((item as AdapterItem.TopSiteList).topSites)
}
is NoContentMessageViewHolder -> {
val (header, description) = item as AdapterItem.NoContentMessage
holder.bind(header, description)
}
is CollectionViewHolder -> {
val (collection, expanded) = item as AdapterItem.CollectionItem
holder.bindSession(collection, expanded)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ interface SessionControlController {
fun handleToggleCollectionExpanded(collection: TabCollection, expand: Boolean)

fun handleCloseTip(tip: Tip)

/**
* @see [CollectionInteractor.onAddTabsToCollectionTapped]
*/
fun handleCreateCollection()
}

@SuppressWarnings("TooManyFunctions", "LargeClass")
Expand Down Expand Up @@ -301,6 +306,10 @@ class DefaultSessionControlController(
navController.nav(R.id.homeFragment, directions)
}

override fun handleCreateCollection() {
showCollectionCreationFragment(step = SaveCollectionStep.SelectTabs)
}

private fun showShareFragment(data: List<ShareData>) {
val directions = HomeFragmentDirections.actionGlobalShareFragment(
data = data.toTypedArray()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ interface CollectionInteractor {
* @param expand True if the given tab collection should be expanded or collapse if false.
*/
fun onToggleCollectionExpanded(collection: TabCollection, expand: Boolean)

/**
* Opens the collection creator
*/
fun onAddTabsToCollectionTapped()
}

/**
Expand Down Expand Up @@ -219,6 +224,10 @@ class SessionControlInteractor(
controller.handleToggleCollectionExpanded(collection, expand)
}

override fun onAddTabsToCollectionTapped() {
controller.handleCreateCollection()
}

override fun onCloseTip(tip: Tip) {
controller.handleCloseTip(tip)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ import org.mozilla.fenix.home.Mode
import org.mozilla.fenix.home.OnboardingState
import org.mozilla.fenix.components.tips.Tip

val noCollectionMessage = AdapterItem.NoContentMessage(
R.string.no_collections_header1,
R.string.no_collections_description1
)

// This method got a little complex with the addition of the tab tray feature flag
// When we remove the tabs from the home screen this will get much simpler again.
@SuppressWarnings("LongParameterList", "ComplexMethod")
Expand All @@ -44,7 +39,7 @@ private fun normalModeAdapterItems(

if (collections.isEmpty()) {
items.add(AdapterItem.CollectionHeader)
items.add(noCollectionMessage)
items.add(AdapterItem.NoCollectionsMessage)
} else {
showCollections(collections, expandedCollections, items)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* 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/. */

package org.mozilla.fenix.home.sessioncontrol.viewholders

import android.view.View
import kotlinx.android.synthetic.main.no_collections_message.view.*
import org.mozilla.fenix.R
import org.mozilla.fenix.ext.ViewHolder
import org.mozilla.fenix.home.sessioncontrol.CollectionInteractor

open class NoCollectionsMessageViewHolder(
view: View,
interactor: CollectionInteractor
) : ViewHolder(view) {

init {
view.add_tabs_to_collections_button.setOnClickListener {
interactor.onAddTabsToCollectionTapped()
}
}
companion object {
const val LAYOUT_ID = R.layout.no_collections_message
}
}

This file was deleted.

44 changes: 44 additions & 0 deletions app/src/main/res/layout/no_collections_message.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?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/. -->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/no_collections_wrapper"
android:background="@drawable/empty_session_control_background"
android:layout_marginBottom="12dp"
android:padding="16dp"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<TextView
android:id="@+id/no_collections_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/no_collections_header1"
tools:drawableEnd="@drawable/ic_tab_collection"
android:textAppearance="@style/HeaderTextStyle"
android:textSize="16sp"
app:fontFamily="@font/metropolis_semibold" />

<TextView
android:id="@+id/no_collections_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:text="@string/no_collections_description1"
android:textColor="?primaryText"
android:textSize="14sp"
android:textAlignment="viewStart"
app:fontFamily="@font/metropolis_medium" />

<com.google.android.material.button.MaterialButton
android:id="@+id/add_tabs_to_collections_button"
style="@style/PositiveButton"
app:icon="@drawable/ic_tab_collection"
android:text="@string/tabs_menu_save_to_collection1"
android:layout_marginTop="8dp"/>
</LinearLayout>
38 changes: 0 additions & 38 deletions app/src/main/res/layout/no_content_message.xml

This file was deleted.

44 changes: 0 additions & 44 deletions app/src/main/res/layout/no_content_message_with_action.xml

This file was deleted.

0 comments on commit 76ee736

Please sign in to comment.