-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8055 from wordpress-mobile/issue/7996-actionable-…
…empty-states Issue/7996 actionable empty states (Part 1)
- Loading branch information
Showing
10 changed files
with
259 additions
and
21 deletions.
There are no files selected for viewing
91 changes: 91 additions & 0 deletions
91
WordPress/src/main/java/org/wordpress/android/ui/ActionableEmptyView.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package org.wordpress.android.ui | ||
|
||
import android.content.Context | ||
import android.support.annotation.DrawableRes | ||
import android.support.annotation.NonNull | ||
import android.support.v7.widget.AppCompatButton | ||
import android.util.AttributeSet | ||
import android.view.View | ||
import android.widget.ImageView | ||
import android.widget.LinearLayout | ||
import org.wordpress.android.R | ||
import org.wordpress.android.widgets.WPTextView | ||
|
||
/** | ||
* View shown when screen is in an empty state. It contains the following: | ||
* - Image showing related illustration (optional) | ||
* - Title describing cause for empty state (required) | ||
* - Subtitle detailing cause for empty state (optional) | ||
* - Button providing action to take (optional) | ||
*/ | ||
class ActionableEmptyView : LinearLayout { | ||
lateinit var button: AppCompatButton | ||
lateinit var image: ImageView | ||
lateinit var subtitle: WPTextView | ||
lateinit var title: WPTextView | ||
|
||
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) { | ||
initView(context, attrs) | ||
} | ||
|
||
constructor(context: Context, attrs: AttributeSet, defStyle: Int) : super(context, attrs, defStyle) { | ||
initView(context, attrs) | ||
} | ||
|
||
private fun initView(context: Context, attrs: AttributeSet) { | ||
val layout = View.inflate(context, R.layout.actionable_empty_view, this) | ||
|
||
image = layout.findViewById(R.id.image) | ||
title = layout.findViewById(R.id.title) | ||
subtitle = layout.findViewById(R.id.subtitle) | ||
button = layout.findViewById(R.id.button) | ||
|
||
attrs.let { | ||
val typedArray = context.obtainStyledAttributes(it, R.styleable.ActionableEmptyView, 0, 0) | ||
|
||
val imageResource = typedArray.getResourceId(R.styleable.ActionableEmptyView_aevImage, 0) | ||
val titleAttribute = typedArray.getString(R.styleable.ActionableEmptyView_aevTitle) | ||
val subtitleAttribute = typedArray.getString(R.styleable.ActionableEmptyView_aevSubtitle) | ||
val buttonAttribute = typedArray.getString(R.styleable.ActionableEmptyView_aevButton) | ||
|
||
if (imageResource != 0) { | ||
image.setImageResource(imageResource) | ||
image.visibility = View.VISIBLE | ||
} | ||
|
||
if (!titleAttribute.isNullOrEmpty()) { | ||
title.text = titleAttribute | ||
} else { | ||
throw RuntimeException(context.toString() + ": ActionableEmptyView must have a title (wpTitle)") | ||
} | ||
|
||
if (!subtitleAttribute.isNullOrEmpty()) { | ||
subtitle.text = subtitleAttribute | ||
subtitle.visibility = View.VISIBLE | ||
} | ||
|
||
if (!buttonAttribute.isNullOrEmpty()) { | ||
button.text = buttonAttribute | ||
button.visibility = View.VISIBLE | ||
} | ||
|
||
typedArray.recycle() | ||
} | ||
} | ||
|
||
fun setButtonClickListener(@NonNull listener: OnClickListener) { | ||
button.setOnClickListener(listener) | ||
} | ||
|
||
fun setImageResource(@NonNull @DrawableRes resId: Int) { | ||
image.setImageResource(resId) | ||
} | ||
|
||
fun setSubtitleText(@NonNull charSequence: CharSequence) { | ||
subtitle.text = charSequence | ||
} | ||
|
||
fun setTitleText(@NonNull charSequence: CharSequence) { | ||
title.text = charSequence | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
WordPress/src/main/res/drawable/img_illustration_media.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<vector | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:height="81dp" | ||
android:width="105dp" | ||
android:viewportHeight="81" | ||
android:viewportWidth="105" > | ||
|
||
<path | ||
android:fillColor="@color/grey_lighten_10" | ||
android:pathData="M36.6,79L59,78.7c0,0,15-0.1,22.4-0.1l22.4-0.1l-1,1l-0.2-9.7c-0.1-3.2-0.2-6.5-0.1-9.7V40.5l0.1-39l0.9,0.9 L58.9,2.2L36.5,2L14.2,1.8l0.4-0.4l-0.1,6.9c0,0.2-0.1,0.4-0.4,0.4c-0.2,0-0.4-0.1-0.4-0.4l-0.1-6.9c0-0.2,0.1-0.4,0.4-0.4l22.4-0.1 h22.2l44.7-0.2c0.5,0,0.9,0.4,0.9,0.9l0.1,39v19.6c0,6.5,0.2,13.1,0.3,19.6c0,0.6-0.4,1-1,1l-22.4-0.1c-7.5,0-15,0-22.4-0.1 s-15-0.1-22.4-0.3L14,79.8c-0.1,0-0.1-0.1-0.2-0.2c0.1-0.1,0.3-0.1,0.4-0.1C21.6,79.2,29.1,79,36.6,79z M14.9,33.3 c0-1.2-0.1-2.4-0.4-3.6c0-0.1-0.1-0.2-0.2-0.3H14c-0.1,0.1-0.1,0.1-0.1,0.2c-0.3,1.2-0.4,2.3-0.4,3.6c-0.1,1.2-0.1,2.3-0.1,3.6 c0,0.6,0,1.2,0.1,1.8c0.1,1.7,0.1,3.5,0.3,5.2c0,0.2,0.2,0.4,0.4,0.4c0.2,0,0.4-0.1,0.4-0.4c0.2-1.7,0.4-3.3,0.3-5 c0-0.7,0-1.3,0.1-2l-0.1-1.8V33.3z" > | ||
</path> | ||
|
||
<path | ||
android:fillColor="@color/grey_lighten_10" | ||
android:pathData="M95.6,70.7H91c-0.3,0-0.5-0.2-0.5-0.5s0.2-0.5,0.5-0.5h4.6c0.3,0,0.5,0.2,0.5,0.5S95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,19.7z" > | ||
</path> | ||
|
||
<path | ||
android:fillColor="@color/grey_lighten_10" | ||
android:pathData="M0.9,23.9l4.5-0.1c0.2,0,0.4,0.1,0.4,0.4c0,0.2-0.1,0.4-0.4,0.4l-4.5-0.1c-0.1,0-0.3-0.1-0.3-0.3C0.6,24,0.7,23.9,0.9,23.9z M7.8,21.7c0.4-1.5,1.2-2.9,2-4.2c0.1-0.2,0.4-0.2,0.6-0.1c0.2,0.1,0.2,0.4,0.1,0.6C9.6,19.2,9,20.6,8.6,22c-0.1,0.1-0.3,0.3-0.4,0.3C7.8,22,7.8,21.9,7.8,21.7z M13.5,14.4c0.7-0.3,1.6-0.4,2.4-0.4c0.8,0,1.6,0.1,2.4,0.4c0.2,0.1,0.4,0.4,0.3,0.6s-0.4,0.4-0.6,0.3c-1.3-0.5-2.8-0.6-4.1-0.1c-0.2,0.1-0.4,0-0.5-0.2V15C13.2,14.7,13.3,14.4,13.5,14.4z M21.4,17.8c0.2,0.1,0.4,0.1,0.6,0.1c0.4-0.2,0.7-0.4,1.1-0.4c0.8-0.2,1.6-0.3,2.4-0.3c0.3,0,0.4,0.2,0.4,0.4c0,0.3-0.2,0.4-0.4,0.4c-0.7,0-1.4,0.1-2.1,0.3c-0.4,0.1-0.7,0.3-1,0.4c-0.5,0.2-1.1,0.2-1.6-0.1c-0.2-0.2-0.2-0.6,0-0.8C20.9,17.8,21.1,17.7,21.4,17.8z M29.7,19.3c0.4,0.7,0.7,1.5,0.8,2.3c0.1,0.8,0.1,1.6,0.1,2.4c0,0.2-0.2,0.4-0.4,0.4s-0.4-0.1-0.4-0.4c0.1-1.5-0.2-3-0.9-4.2c-0.1-0.2-0.1-0.4,0.1-0.6C29.2,19,29.6,19,29.7,19.3z M34.6,23.9H38c0.1,0,0.3,0.1,0.3,0.3c0,0.1-0.1,0.3-0.2,0.3h-3.5c-0.2,0-0.4-0.1-0.4-0.4C34.3,24.1,34.4,23.9,34.6,23.9z" > | ||
</path> | ||
|
||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
|
||
<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:gravity="center" | ||
android:layout_height="match_parent" | ||
android:layout_width="match_parent" | ||
android:orientation="vertical" > | ||
|
||
<android.support.v4.widget.NestedScrollView | ||
android:layout_height="wrap_content" | ||
android:layout_width="match_parent" > | ||
|
||
<LinearLayout | ||
android:layout_height="wrap_content" | ||
android:layout_width="match_parent" | ||
android:gravity="center" | ||
android:orientation="vertical" > | ||
|
||
<ImageView | ||
android:id="@+id/image" | ||
android:adjustViewBounds="true" | ||
android:contentDescription="@string/content_description_person_reading_device_notification" | ||
android:layout_height="wrap_content" | ||
android:layout_marginBottom="@dimen/margin_extra_large" | ||
android:layout_marginTop="@dimen/margin_extra_large" | ||
android:layout_width="wrap_content" | ||
android:visibility="gone" | ||
tools:srcCompat="@drawable/jetpack_connection_notifications" | ||
tools:visibility="visible" > | ||
</ImageView> | ||
|
||
<org.wordpress.android.widgets.WPTextView | ||
android:id="@+id/title" | ||
android:layout_height="wrap_content" | ||
android:layout_width="wrap_content" | ||
app:fixWidowWords="true" | ||
tools:text="No comments yet" | ||
style="@style/ActionableEmptyStateTitle" > | ||
</org.wordpress.android.widgets.WPTextView> | ||
|
||
<org.wordpress.android.widgets.WPTextView | ||
android:id="@+id/subtitle" | ||
android:layout_height="wrap_content" | ||
android:layout_width="wrap_content" | ||
android:visibility="gone" | ||
app:fixWidowWords="true" | ||
tools:text="Join a conversation: comment on posts from blogs you follow" | ||
tools:visibility="visible" | ||
style="@style/ActionableEmptyStateSubtitle" > | ||
</org.wordpress.android.widgets.WPTextView> | ||
|
||
<android.support.v7.widget.AppCompatButton | ||
android:id="@+id/button" | ||
android:layout_height="wrap_content" | ||
android:layout_marginBottom="@dimen/margin_extra_large" | ||
android:layout_width="wrap_content" | ||
android:theme="@style/ActionableEmptyStateButton" | ||
android:visibility="gone" | ||
tools:text="Go to Reader" | ||
tools:visibility="visible" > | ||
</android.support.v7.widget.AppCompatButton> | ||
|
||
</LinearLayout> | ||
|
||
</android.support.v4.widget.NestedScrollView> | ||
|
||
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.