Skip to content

Commit

Permalink
Implement Info > Event CTAs.
Browse files Browse the repository at this point in the history
Bug: 37666512
Change-Id: Ia54cc204603941efc8c52fa1c626f44da6786c4a
  • Loading branch information
nickbutcher committed May 12, 2017
1 parent 47e8b01 commit df8721a
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
Expand All @@ -32,7 +33,6 @@
public class EventView extends FrameLayout {

private HtmlTextView mDescriptionView;
private String mSessionFilterTag;
private EventViewClickListener mListener;

public interface EventViewClickListener {
Expand All @@ -50,13 +50,16 @@ public EventView(Context context, @Nullable AttributeSet attrs) {

public EventView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
TypedArray arr = context.obtainStyledAttributes(attrs, R.styleable.EventView, 0, 0);
final TypedArray arr = context.obtainStyledAttributes(attrs, R.styleable.EventView,
defStyleAttr, 0);
final String eventTitle = arr.getString(R.styleable.EventView_eventTitle);
String eventDescription = arr.getString(R.styleable.EventView_eventDescription);
Drawable eventIconDrawable = arr.getDrawable(R.styleable.EventView_eventIcon);
int boxColor = arr.getColor(R.styleable.EventView_boxColor,
final String eventDescription = arr.getString(R.styleable.EventView_eventDescription);
final Drawable eventIconDrawable = arr.getDrawable(R.styleable.EventView_eventIcon);
final int boxColor = arr.getColor(R.styleable.EventView_boxColor,
ContextCompat.getColor(getContext(), R.color.sunflower_yellow));
mSessionFilterTag = arr.getString(R.styleable.EventView_scheduleFilterTag);
final String sessionFilterTag = arr.getString(R.styleable.EventView_scheduleFilterTag);
final String sessionsText = arr.getString(R.styleable.EventView_sessionsText);
final String mapUri = arr.getString(R.styleable.EventView_mapLinkUri);
arr.recycle();

View rootView = LayoutInflater.from(context)
Expand All @@ -69,24 +72,37 @@ public EventView(Context context, @Nullable AttributeSet attrs, int defStyleAttr
titleView.setText(eventTitle);
header.setBackgroundColor(boxColor);
iconView.setImageDrawable(eventIconDrawable);
rootView.findViewById(R.id.event_view_sessions).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (mListener != null) {
mListener.onViewSessionsClicked(EventView.this, mSessionFilterTag);
AnalyticsHelper.sendEvent(eventTitle, "Event Info", "view sessions");
}
Button viewSessions = (Button) rootView.findViewById(R.id.event_view_sessions);
if (sessionFilterTag != null) {
if (sessionsText != null) {
viewSessions.setText(sessionsText);
}
});
rootView.findViewById(R.id.event_view_map).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (mListener != null) {
mListener.onViewMapClicked(EventView.this, null);
AnalyticsHelper.sendEvent(eventTitle, "Event Info", "view map");
viewSessions.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (mListener != null) {
mListener.onViewSessionsClicked(EventView.this, sessionFilterTag);
AnalyticsHelper.sendEvent(eventTitle, "Event Info", "view sessions");
}
}
}
});
});
} else {
viewSessions.setVisibility(GONE);
}
View viewMap = rootView.findViewById(R.id.event_view_map);
if (mapUri != null) {
viewMap.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (mListener != null) {
mListener.onViewMapClicked(EventView.this, mapUri);
AnalyticsHelper.sendEvent(eventTitle, "Event Info", "view map");
}
}
});
} else {
viewMap.setVisibility(GONE);
}
}

public void setEventDescription(CharSequence description) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,20 @@ public Tag getTag(String searchString) {
}
}

/**
* @param searchString A comma separated list of tag ids or names.
*/
public Tag[] getTags(@NonNull String searchString) {
if (TextUtils.isEmpty(searchString)) return null;

String[] queries = searchString.split(",");
Tag[] tags = new Tag[queries.length];
for (int i = 0; i < queries.length; i++) {
tags[i] = getTag(queries[i]);
}
return tags;
}

public List<Tag> getTagsInCategory(String category) {
return mTagsInCategory.containsKey(category) ?
Collections.unmodifiableList(mTagsInCategory.get(category)) : null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,14 @@ private void onTagMetadataLoaded(TagMetadata tagMetadata) {

private void maybeApplyPendingFilterTag() {
if (mTagMetadata != null && mFilterTag != null) {
Tag tag = mTagMetadata.getTag(mFilterTag);
if (tag != null) {
mAdapter.clearAllFilters();
mAdapter.addTag(tag);
mFilterTag = null; // we don't have to run this again
mAdapter.clearAllFilters();
Tag[] tags = mTagMetadata.getTags(mFilterTag);
for (Tag tag : tags) {
if (tag != null) {
mAdapter.addTag(tag);
}
}
mFilterTag = null; // we don't have to run this again
}
}

Expand Down
21 changes: 15 additions & 6 deletions lib/src/main/res/layout/info_event_content_card_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
<merge
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">
xmlns:tools="http://schemas.android.com/tools"
tools:parentTag="android.widget.FrameLayout">

<!-- It seems that ConstraintLayout currently doesn't support merge tags so we need a
(otherwise useless) wrapping FrameLayout :( -->
Expand All @@ -38,10 +39,10 @@

<TextView
android:id="@+id/event_title"
style="@style/ProductSans.Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="@dimen/padding_normal"
android:textAppearance="?android:textAppearanceLarge"
app:layout_constraintBottom_toBottomOf="@id/header"
app:layout_constraintStart_toStartOf="parent"
tools:text="Office Hours &amp; App Reviews" />
Expand All @@ -60,19 +61,27 @@
android:id="@+id/event_content_description"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/padding_normal"
android:padding="@dimen/padding_normal"
android:paddingLeft="@dimen/padding_normal"
android:paddingRight="@dimen/padding_normal"
android:paddingTop="@dimen/padding_normal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/header"
tools:text="@string/placeholder_lorem_ipsum" />

<!-- space maintains bottom margins if buttons aren't shown -->
<Space
android:layout_width="0dp"
android:layout_height="@dimen/padding_normal"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/event_content_description" />

<Button
android:id="@+id/event_view_sessions"
style="@style/Widget.AppCompat.Button.Borderless.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="@dimen/padding_normal"
android:layout_marginStart="@dimen/event_button_margin"
android:text="@string/view_sessions_text"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/event_content_description" />
Expand All @@ -82,7 +91,7 @@
style="@style/Widget.AppCompat.Button.Borderless.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="@dimen/padding_normal"
android:layout_marginStart="@dimen/event_button_margin"
android:text="@string/view_map_text"
app:layout_constraintStart_toEndOf="@id/event_view_sessions"
app:layout_constraintTop_toBottomOf="@id/event_content_description" />
Expand Down
23 changes: 14 additions & 9 deletions lib/src/main/res/layout/info_event_frag.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
<android.support.v4.widget.NestedScrollView
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:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:scrollbarStyle="insideOverlay"
android:scrollbars="vertical">

Expand Down Expand Up @@ -99,9 +100,7 @@
android:layout_marginTop="@dimen/padding_normal"
app:boxColor="@color/neon_blue"
app:eventIcon="@drawable/ic_sandbox"
app:eventTitle="@string/event_sandbox_title"
app:mapLinkUri="@string/view_sandbox_map_url"
app:scheduleFilterTag="@string/sandbox_filter_tag" />
app:eventTitle="@string/event_sandbox_title" />

<com.google.samples.apps.iosched.info.event.EventView
android:id="@+id/codelabs_event"
Expand All @@ -110,7 +109,8 @@
app:boxColor="@color/aqua_marine"
app:eventIcon="@drawable/ic_codelab"
app:eventTitle="@string/event_codelabs_title"
app:mapLinkUri="@string/view_sandbox_map_url"
app:sessionsText="@string/view_codelabs_text"
app:mapLinkUri="@string/view_codelabs_map_url"
app:scheduleFilterTag="@string/codelabs_filter_tag" />

<com.google.samples.apps.iosched.info.event.EventView
Expand All @@ -120,6 +120,7 @@
app:boxColor="@color/off_white"
app:eventIcon="@drawable/ic_officehours"
app:eventTitle="@string/event_officehours_title"
app:sessionsText="@string/view_events_text"
app:mapLinkUri="@string/view_officehours_map_url"
app:scheduleFilterTag="@string/officehours_filter_tag" />

Expand All @@ -129,9 +130,13 @@
android:layout_height="wrap_content"
app:boxColor="@color/light_periwinkle"
app:eventIcon="@drawable/ic_afterhours"
app:eventTitle="@string/event_afterhours_title"
app:mapLinkUri="@string/view_afterhours_map_url"
app:scheduleFilterTag="@string/afterhours_filter_tag" />
app:eventTitle="@string/event_afterhours_title" />

<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/io17_logo"
tools:ignore="ContentDescription" />

</LinearLayout>

Expand Down
1 change: 1 addition & 0 deletions lib/src/main/res/values-sw600dp/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<dimen name="padding_normal">24dp</dimen>
<dimen name="padding_normal_button">20dp</dimen>
<dimen name="borderless_button_margin">8dp</dimen>
<dimen name="event_button_margin">12dp</dimen>

<!-- UI elements -->
<dimen name="action_button_min_width">64dp</dimen>
Expand Down
1 change: 1 addition & 0 deletions lib/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
<declare-styleable name="EventView">
<attr name="eventTitle" format="string" />
<attr name="eventDescription" format="string" />
<attr name="sessionsText" format="string" />
<attr name="scheduleFilterTag" format="string" />
<attr name="mapLinkUri" format="string" />
<attr name="boxColor" format="color" />
Expand Down
1 change: 1 addition & 0 deletions lib/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@

<!-- Info -->
<dimen name="event_header_height">140dp</dimen>
<dimen name="event_button_margin">4dp</dimen>
<dimen name="settings_content_padding">32dp</dimen>

<dimen name="status_bar_height">25dp</dimen>
Expand Down
13 changes: 4 additions & 9 deletions lib/src/main/res/values/donottranslate.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,9 @@
translatable="false">feed_default_first_priority</string>

<!-- Filter tags for Info > Events screen "View sessions" buttons -->
<string name="afterhours_filter_tag" translatable="false">TYPE_AFTERHOURS</string>
<string name="codelabs_filter_tag" translatable="false">TYPE_CODELABS</string>
<string name="officehours_filter_tag" translatable="false">TYPE_OFFICEHOURS</string>
<string name="sandbox_filter_tag" translatable="false">TYPE_SANDBOXDEMO</string>
<!-- Map links for Info > Events screen "View map" buttons.
TODO make these URLs the correct deep link -->
<string name="view_sandbox_map_url" translatable="false">sandboxmapurl</string>
<string name="view_codelabs_map_url" translatable="false">codelabsmapurl</string>
<string name="view_officehours_map_url" translatable="false">officehoursmapurl</string>
<string name="view_afterhours_map_url" translatable="false">afterhoursmapurl</string>
<string name="officehours_filter_tag" translatable="false">TYPE_OFFICEHOURS,TYPE_APPREVIEWS</string>
<!-- Map links for Info > Events screen "View map" buttons. -->
<string name="view_codelabs_map_url" translatable="false">4748d33e-f935-4c9e-bca6-67b61b875dc7</string>
<string name="view_officehours_map_url" translatable="false">officehours</string>
</resources>
2 changes: 2 additions & 0 deletions lib/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,8 @@
<string name="wifi_install_error_message">Sorry, unable to save wifi network</string>

<string name="view_sessions_text">View Sessions</string>
<string name="view_codelabs_text">View Codelabs</string>
<string name="view_events_text">View Events</string>
<string name="view_map_text">View Map</string>

<string name="event_sandbox_title">Sandbox</string>
Expand Down

0 comments on commit df8721a

Please sign in to comment.