Skip to content

Commit

Permalink
For mozilla-mobile#6607 Allow adding button to no content view holder
Browse files Browse the repository at this point in the history
  • Loading branch information
mcarare committed Feb 25, 2020
1 parent 0f609b1 commit 11b5c80
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 34 deletions.
3 changes: 2 additions & 1 deletion app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@ class HomeFragment : Fragment() {
registerCollectionStorageObserver = ::registerCollectionStorageObserver,
scrollToTheTop = ::scrollToTheTop,
showDeleteCollectionPrompt = ::showDeleteCollectionPrompt,
openSettingsScreen = :: openSettingsScreen
openSettingsScreen = :: openSettingsScreen,
openSearchScreen = ::navigateToSearch
)
)
updateLayout(view)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ sealed class AdapterItem(@LayoutRes val viewType: Int) {
data class NoContentMessage(
@DrawableRes val icon: Int,
@StringRes val header: Int,
@StringRes val description: Int
@StringRes val description: Int,
@DrawableRes val buttonIcon: Int = 0,
@StringRes val buttonText: Int = 0,
val listener: (() -> Unit)? = null
) : AdapterItem(NoContentMessageViewHolder.LAYOUT_ID)

object CollectionHeader : AdapterItem(CollectionHeaderViewHolder.LAYOUT_ID)
Expand Down Expand Up @@ -196,8 +199,8 @@ class SessionControlAdapter(
holder.bind((item as AdapterItem.TopSiteList).topSites)
}
is NoContentMessageViewHolder -> {
val (icon, header, description) = item as AdapterItem.NoContentMessage
holder.bind(icon, header, description)
val (icon, header, description, buttonIcon, buttonText, listener) = item as AdapterItem.NoContentMessage
holder.bind(icon, header, description, buttonIcon, buttonText, listener)
}
is CollectionViewHolder -> {
val (collection, expanded, sessionHasOpenTabs) = item as AdapterItem.CollectionItem
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ interface SessionControlController {
* @see [CollectionInteractor.onToggleCollectionExpanded]
*/
fun handleToggleCollectionExpanded(collection: TabCollection, expand: Boolean)

/**
* @see [TabSessionInteractor.onOpenNewTabClicked]
*/
fun handleonOpenNewTabClicked()
}

@SuppressWarnings("TooManyFunctions", "LargeClass")
Expand All @@ -165,7 +170,8 @@ class DefaultSessionControlController(
private val registerCollectionStorageObserver: () -> Unit,
private val scrollToTheTop: () -> Unit,
private val showDeleteCollectionPrompt: (tabCollection: TabCollection) -> Unit,
private val openSettingsScreen: () -> Unit
private val openSettingsScreen: () -> Unit,
private val openSearchScreen: () -> Unit
) : SessionControlController {
private val metrics: MetricController
get() = activity.components.analytics.metrics
Expand Down Expand Up @@ -379,6 +385,10 @@ class DefaultSessionControlController(
store.dispatch(HomeFragmentAction.CollectionExpanded(collection, expand))
}

override fun handleonOpenNewTabClicked() {
openSearchScreen()
}

private fun showCollectionCreationFragment(
step: SaveCollectionStep,
selectedTabIds: Array<String>? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ interface TabSessionInteractor {
* mode or tab header menu item.
*/
fun onShareTabs()

fun onOpenNewTabClicked()
}

/**
Expand Down Expand Up @@ -274,4 +276,8 @@ class SessionControlInteractor(
override fun onToggleCollectionExpanded(collection: TabCollection, expand: Boolean) {
controller.handleToggleCollectionExpanded(collection, expand)
}

override fun onOpenNewTabClicked() {
controller.handleonOpenNewTabClicked()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ import org.mozilla.fenix.home.Tab
val noTabMessage = AdapterItem.NoContentMessage(
R.drawable.ic_tabs,
R.string.no_open_tabs_header_2,
R.string.no_open_tabs_description
R.string.no_open_tabs_description,
R.drawable.ic_new,
R.string.home_screen_shortcut_open_new_tab_2
)

val noCollectionMessage = AdapterItem.NoContentMessage(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,46 @@ package org.mozilla.fenix.home.sessioncontrol.viewholders
import android.view.View
import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import androidx.core.view.isVisible
import androidx.recyclerview.widget.RecyclerView
import kotlinx.android.synthetic.main.no_content_message.view.*
import mozilla.components.support.ktx.android.view.putCompoundDrawablesRelativeWithIntrinsicBounds
import org.mozilla.fenix.R

/**
* A ViewHolder for displaying messages and optional button on home screen
*/
class NoContentMessageViewHolder(private val view: View) : RecyclerView.ViewHolder(view) {

/**
* @param icon The visible label for header text this menu item.
* @param header ID of string resource for title text.
* @param description ID of string resource for description text.
* @param buttonIcon Optional ID of drawable resource for button icon.
* @param buttonText Optional ID of string resource for button text.
* @param listener Optional Callback to be invoked when the button is clicked.
*/
@Suppress("LongParameterList")
fun bind(
@DrawableRes icon: Int,
@StringRes header: Int,
@StringRes description: Int
@StringRes description: Int,
@DrawableRes buttonIcon: Int = 0,
@StringRes buttonText: Int = 0,
listener: (() -> Unit)? = null
) {
with(view.context) {
view.no_content_header.putCompoundDrawablesRelativeWithIntrinsicBounds(end = getDrawable(icon))
view.no_content_header.text = getString(header)
view.no_content_description.text = getString(description)

if (buttonIcon != 0 || buttonText != 0) {
view.button_layout.isVisible = true
view.button_icon.setImageDrawable(getDrawable(buttonIcon))
view.button_text.text = getString(buttonText)
view.button_layout.setOnClickListener {
listener?.invoke()
}
}
}
}

Expand Down
90 changes: 64 additions & 26 deletions app/src/main/res/layout/no_content_message.xml
Original file line number Diff line number Diff line change
@@ -1,39 +1,77 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- This Source Code Form is subject to the terms of the Mozilla Public
<?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_content_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">
<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_content_wrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="12dp"
android:background="@drawable/empty_session_control_background"
android:orientation="vertical"
android:padding="8dp">

<TextView
android:id="@+id/no_content_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="4dp"
android:drawablePadding="8dp"
android:textAppearance="@style/HeaderTextStyle"
android:textSize="16sp"
app:drawableTint="?primaryText"
tools:drawableEnd="@drawable/ic_tab_collection"
tools:text="@tools:sample/lorem" />

<TextView
android:id="@+id/no_content_header"
android:id="@+id/no_content_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:textAlignment="viewStart"
android:textColor="?primaryText"
android:textSize="14sp"
android:textStyle="normal"
tools:text="@tools:sample/lorem" />

<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/button_layout"
android:layout_width="match_parent"
android:layout_height="36dp"
android:layout_marginTop="6dp"
android:layout_marginBottom="4dp"
android:background="@drawable/button_background_grey"
android:clickable="true"
android:focusable="true"
android:visibility="gone"
tools:visibility="visible">

<ImageView
android:id="@+id/button_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:drawableTint="?primaryText"
android:drawablePadding="8dp"
tools:text="@tools:sample/lorem"
tools:drawableEnd="@drawable/ic_tab_collection"
android:textAppearance="@style/HeaderTextStyle"
android:textSize="16sp" />
android:layout_margin="5dp"
android:importantForAccessibility="no"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/button_text"
app:layout_constraintTop_toTopOf="parent"
tools:srcCompat="@drawable/ic_new" />

<TextView
android:id="@+id/no_content_description"
<TextView
android:id="@+id/button_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
tools:text="@tools:sample/lorem"
android:importantForAccessibility="no"
android:textColor="?primaryText"
android:textSize="14sp"
android:textStyle="normal"
android:textAlignment="viewStart"/>
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="@string/home_screen_shortcut_open_new_tab_2" />
</androidx.constraintlayout.widget.ConstraintLayout>

</LinearLayout>

0 comments on commit 11b5c80

Please sign in to comment.