From 1f22b211e9c0783f5f9d9facee8245c498514a7a Mon Sep 17 00:00:00 2001 From: Tyler Heck Date: Tue, 17 Jul 2018 15:57:41 -0700 Subject: [PATCH 01/10] Add attributes, dimensions, and styles for actionable empty view --- WordPress/src/main/res/values/attrs.xml | 14 ++++++++++++ WordPress/src/main/res/values/dimens.xml | 5 +++++ WordPress/src/main/res/values/styles.xml | 28 ++++++++++++++++++++++++ 3 files changed, 47 insertions(+) diff --git a/WordPress/src/main/res/values/attrs.xml b/WordPress/src/main/res/values/attrs.xml index e9d4d0af3de9..a7c828da791f 100644 --- a/WordPress/src/main/res/values/attrs.xml +++ b/WordPress/src/main/res/values/attrs.xml @@ -139,4 +139,18 @@ + + + + + + + + + + + + diff --git a/WordPress/src/main/res/values/dimens.xml b/WordPress/src/main/res/values/dimens.xml index cda195b15759..93b08812978b 100644 --- a/WordPress/src/main/res/values/dimens.xml +++ b/WordPress/src/main/res/values/dimens.xml @@ -314,4 +314,9 @@ 40dp 16dp + + + 120dp + 30dp + 300dp diff --git a/WordPress/src/main/res/values/styles.xml b/WordPress/src/main/res/values/styles.xml index be8defa5cf0c..3115fad6e6b6 100644 --- a/WordPress/src/main/res/values/styles.xml +++ b/WordPress/src/main/res/values/styles.xml @@ -698,4 +698,32 @@ @dimen/list_divider_height @color/grey_lighten_20 + + + + + + + From 86104eb27b33bb17be87c1a95702a45c17bb6d6c Mon Sep 17 00:00:00 2001 From: Tyler Heck Date: Tue, 17 Jul 2018 15:59:14 -0700 Subject: [PATCH 02/10] Add actionable empty view layout --- .../main/res/layout/actionable_empty_view.xml | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 WordPress/src/main/res/layout/actionable_empty_view.xml diff --git a/WordPress/src/main/res/layout/actionable_empty_view.xml b/WordPress/src/main/res/layout/actionable_empty_view.xml new file mode 100644 index 000000000000..25a370c28761 --- /dev/null +++ b/WordPress/src/main/res/layout/actionable_empty_view.xml @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + + + + + + + + + + + From dd38c41a538a626e3ef1faa54ab513018cade7e4 Mon Sep 17 00:00:00 2001 From: Tyler Heck Date: Tue, 17 Jul 2018 15:59:56 -0700 Subject: [PATCH 03/10] Add actionable empty view class --- .../android/ui/ActionableEmptyView.kt | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 WordPress/src/main/java/org/wordpress/android/ui/ActionableEmptyView.kt diff --git a/WordPress/src/main/java/org/wordpress/android/ui/ActionableEmptyView.kt b/WordPress/src/main/java/org/wordpress/android/ui/ActionableEmptyView.kt new file mode 100644 index 000000000000..0f4ec879ca06 --- /dev/null +++ b/WordPress/src/main/java/org/wordpress/android/ui/ActionableEmptyView.kt @@ -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 + } +} From fa060f484ad7426a973b5b190c8d1b622d9496d4 Mon Sep 17 00:00:00 2001 From: Tyler Heck Date: Tue, 17 Jul 2018 16:05:20 -0700 Subject: [PATCH 04/10] Add drawable and string resources for media actionable empty view --- .../res/drawable/img_illustration_media.xml | 44 +++++++++++++++++++ WordPress/src/main/res/values/strings.xml | 1 + 2 files changed, 45 insertions(+) create mode 100644 WordPress/src/main/res/drawable/img_illustration_media.xml diff --git a/WordPress/src/main/res/drawable/img_illustration_media.xml b/WordPress/src/main/res/drawable/img_illustration_media.xml new file mode 100644 index 000000000000..ea2e19f2591e --- /dev/null +++ b/WordPress/src/main/res/drawable/img_illustration_media.xml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + diff --git a/WordPress/src/main/res/values/strings.xml b/WordPress/src/main/res/values/strings.xml index 3b5a9e3790d3..d713f1f9473c 100644 --- a/WordPress/src/main/res/values/strings.xml +++ b/WordPress/src/main/res/values/strings.xml @@ -203,6 +203,7 @@ You don\'t have any videos You don\'t have any documents You don\'t have any audio + Upload media Delete Delete this image? Remove this image from the post? From 4f68d4959ffcfec915a2d97d09aed68743fa1784 Mon Sep 17 00:00:00 2001 From: Tyler Heck Date: Tue, 17 Jul 2018 16:05:58 -0700 Subject: [PATCH 05/10] Add media empty list string resource --- WordPress/src/main/res/values/strings.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WordPress/src/main/res/values/strings.xml b/WordPress/src/main/res/values/strings.xml index d713f1f9473c..e5190197a928 100644 --- a/WordPress/src/main/res/values/strings.xml +++ b/WordPress/src/main/res/values/strings.xml @@ -198,7 +198,7 @@ Some media can\'t be deleted at this time. Try again later. Media has been removed. Delete it from this post? - No media + You don\'t have any media You don\'t have any images You don\'t have any videos You don\'t have any documents From a4b83966f64f77aa17154e8ad8621ed2b432f079 Mon Sep 17 00:00:00 2001 From: Tyler Heck Date: Tue, 17 Jul 2018 16:07:23 -0700 Subject: [PATCH 06/10] Update media empty list from text to actionable empty view --- .../android/ui/media/MediaGridFragment.java | 8 +++---- .../main/res/layout/media_grid_fragment.xml | 24 +++++++------------ 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/media/MediaGridFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/media/MediaGridFragment.java index c8191648d124..524f8f144bd0 100755 --- a/WordPress/src/main/java/org/wordpress/android/ui/media/MediaGridFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/media/MediaGridFragment.java @@ -18,7 +18,6 @@ import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; -import android.widget.TextView; import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; @@ -34,6 +33,7 @@ import org.wordpress.android.fluxc.store.MediaStore.MediaErrorType; import org.wordpress.android.fluxc.store.MediaStore.OnMediaListFetched; import org.wordpress.android.fluxc.utils.MediaUtils; +import org.wordpress.android.ui.ActionableEmptyView; import org.wordpress.android.ui.EmptyViewMessageType; import org.wordpress.android.ui.media.MediaGridAdapter.MediaGridAdapterCallback; import org.wordpress.android.ui.media.services.MediaDeleteService; @@ -146,7 +146,7 @@ private static MediaFilter fromMimeType(@NonNull String mimeType) { private SwipeToRefreshHelper mSwipeToRefreshHelper; - private TextView mEmptyView; + private ActionableEmptyView mEmptyView; private EmptyViewMessageType mEmptyViewMessageType = EmptyViewMessageType.NO_CONTENT; private SiteModel mSite; @@ -241,7 +241,7 @@ public void onScrollStateChanged(RecyclerView recyclerView, int newState) { } }); - mEmptyView = (TextView) view.findViewById(R.id.empty_view); + mEmptyView = (ActionableEmptyView) view.findViewById(R.id.actionable_empty_view); mRecycler.setEmptyView(mEmptyView); // swipe to refresh setup @@ -599,7 +599,7 @@ private void updateEmptyView(EmptyViewMessageType emptyViewMessageType) { break; } - mEmptyView.setText(getText(stringId)); + mEmptyView.setTitleText(getText(stringId)); mEmptyView.setVisibility(View.VISIBLE); } else { mEmptyView.setVisibility(View.GONE); diff --git a/WordPress/src/main/res/layout/media_grid_fragment.xml b/WordPress/src/main/res/layout/media_grid_fragment.xml index d0b6c4e7fc60..3af8446c6f89 100644 --- a/WordPress/src/main/res/layout/media_grid_fragment.xml +++ b/WordPress/src/main/res/layout/media_grid_fragment.xml @@ -33,21 +33,15 @@ - + app:aevButton="@string/media_empty_upload_media" + app:aevImage="@drawable/img_illustration_media" + app:aevTitle="@string/media_empty_list" + tools:visibility="visible" > + From fc7d532e8a9bb06b74b5f3d6617daf3dde7bc17d Mon Sep 17 00:00:00 2001 From: Tyler Heck Date: Tue, 17 Jul 2018 16:09:20 -0700 Subject: [PATCH 07/10] Add button click listener to media actionable empty view --- .../wordpress/android/ui/media/MediaBrowserActivity.java | 2 +- .../org/wordpress/android/ui/media/MediaGridFragment.java | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/media/MediaBrowserActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/media/MediaBrowserActivity.java index 632ec1812be1..5fd3d67b3008 100755 --- a/WordPress/src/main/java/org/wordpress/android/ui/media/MediaBrowserActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/media/MediaBrowserActivity.java @@ -784,7 +784,7 @@ public void onReceive(Context context, Intent intent) { } }; - private void showAddMediaPopup() { + public void showAddMediaPopup() { View anchor = findViewById(R.id.menu_new_media); PopupMenu popup = new PopupMenu(this, anchor); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/media/MediaGridFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/media/MediaGridFragment.java index 524f8f144bd0..c958a6271b2a 100755 --- a/WordPress/src/main/java/org/wordpress/android/ui/media/MediaGridFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/media/MediaGridFragment.java @@ -17,6 +17,7 @@ import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; +import android.view.View.OnClickListener; import android.view.ViewGroup; import org.greenrobot.eventbus.Subscribe; @@ -242,6 +243,13 @@ public void onScrollStateChanged(RecyclerView recyclerView, int newState) { }); mEmptyView = (ActionableEmptyView) view.findViewById(R.id.actionable_empty_view); + mEmptyView.setButtonClickListener(new OnClickListener() { + @Override public void onClick(View view) { + if (isAdded() && getActivity() instanceof MediaBrowserActivity) { + ((MediaBrowserActivity) getActivity()).showAddMediaPopup(); + } + } + }); mRecycler.setEmptyView(mEmptyView); // swipe to refresh setup From 26a71c5ab96cbc7eb1725306643457b396a71eab Mon Sep 17 00:00:00 2001 From: Tyler Heck Date: Tue, 17 Jul 2018 22:13:44 -0700 Subject: [PATCH 08/10] Update media illustration vector drawable paths --- .../res/drawable/img_illustration_media.xml | 48 +++++++------------ 1 file changed, 16 insertions(+), 32 deletions(-) diff --git a/WordPress/src/main/res/drawable/img_illustration_media.xml b/WordPress/src/main/res/drawable/img_illustration_media.xml index ea2e19f2591e..e10c1486e3d3 100644 --- a/WordPress/src/main/res/drawable/img_illustration_media.xml +++ b/WordPress/src/main/res/drawable/img_illustration_media.xml @@ -5,40 +5,24 @@ android:viewportHeight="81" android:viewportWidth="105" > - - + + - - + + - - + + - - + + From f5224c7fe84c4e40191e0cee1542bae905f89ec6 Mon Sep 17 00:00:00 2001 From: Tyler Heck Date: Wed, 18 Jul 2018 10:44:20 -0700 Subject: [PATCH 09/10] Remove maximum height attribute from actionable empty view image --- WordPress/src/main/res/layout/actionable_empty_view.xml | 1 - WordPress/src/main/res/values/dimens.xml | 1 - 2 files changed, 2 deletions(-) diff --git a/WordPress/src/main/res/layout/actionable_empty_view.xml b/WordPress/src/main/res/layout/actionable_empty_view.xml index 25a370c28761..4feaa766f12b 100644 --- a/WordPress/src/main/res/layout/actionable_empty_view.xml +++ b/WordPress/src/main/res/layout/actionable_empty_view.xml @@ -27,7 +27,6 @@ android:layout_marginBottom="@dimen/margin_extra_large" android:layout_marginTop="@dimen/margin_extra_large" android:layout_width="wrap_content" - android:maxHeight="@dimen/actionable_empty_view_image_maximum_height" android:visibility="gone" tools:srcCompat="@drawable/jetpack_connection_notifications" tools:visibility="visible" > diff --git a/WordPress/src/main/res/values/dimens.xml b/WordPress/src/main/res/values/dimens.xml index 7d620bf84433..b76eedb391c4 100644 --- a/WordPress/src/main/res/values/dimens.xml +++ b/WordPress/src/main/res/values/dimens.xml @@ -316,7 +316,6 @@ 16dp - 120dp 30dp 300dp From 6f7364c9f8f8ba6da739c85978167b73f60fe89c Mon Sep 17 00:00:00 2001 From: Tyler Heck Date: Wed, 18 Jul 2018 10:45:06 -0700 Subject: [PATCH 10/10] Update maximum width value for actionable empty view title and subtitle --- WordPress/src/main/res/values/dimens.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WordPress/src/main/res/values/dimens.xml b/WordPress/src/main/res/values/dimens.xml index b76eedb391c4..f40b4f6a7ee5 100644 --- a/WordPress/src/main/res/values/dimens.xml +++ b/WordPress/src/main/res/values/dimens.xml @@ -317,7 +317,7 @@ 30dp - 300dp + 440dp 18dp