use of com.thebluealliance.androidclient.types.WebcastType in project the-blue-alliance-android by the-blue-alliance.
the class UpcomingMatchNotification method buildNotification.
/**
* @param context a Context object for use by the notification builder
* @param followsChecker for checking which teams the user follows
* @return A constructed notification
*/
@Override
public Notification buildNotification(Context context, FollowsChecker followsChecker) {
String scheduledStartTimeString;
if (JSONHelper.isNull(matchTime)) {
scheduledStartTimeString = "";
} else {
long scheduledStartTimeUNIX = matchTime.getAsLong();
// We multiply by 1000 because the Date constructor expects ms
Date scheduledStartTime = new Date(scheduledStartTimeUNIX * 1000);
java.text.DateFormat format = android.text.format.DateFormat.getTimeFormat(context);
scheduledStartTimeString = format.format(scheduledStartTime);
}
// Boldify the team numbers that the user is following, but only if the system supports
// java 8 language features
CharSequence redTeamNumbers;
CharSequence blueTeamNumbers;
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) {
Predicate<String> isFollowing = teamNumber -> followsChecker.followsTeam(context, teamNumber, matchKey, NotificationTypes.UPCOMING_MATCH);
redTeamNumbers = Utilities.boldNameList(Arrays.asList(redTeams), isFollowing);
blueTeamNumbers = Utilities.boldNameList(Arrays.asList(blueTeams), isFollowing);
} else {
redTeamNumbers = Utilities.stringifyListOfStrings(context, Arrays.asList(redTeams));
blueTeamNumbers = Utilities.stringifyListOfStrings(context, Arrays.asList(blueTeams));
}
String matchTitle = MatchHelper.getMatchTitleFromMatchKey(context, matchKey);
String matchAbbrevTitle = MatchHelper.getAbbrevMatchTitleFromMatchKey(context, matchKey);
String eventShortName = EventHelper.shortName(eventName);
String template = scheduledStartTimeString.isEmpty() ? context.getString(R.string.notification_upcoming_match_no_time) : context.getString(R.string.notification_upcoming_match);
CharSequence contentText = TextUtils.expandTemplate(template, eventShortName, matchTitle, redTeamNumbers, blueTeamNumbers, scheduledStartTimeString);
Intent instance = getIntent(context);
stored = new StoredNotification();
stored.setType(getNotificationType());
String eventCode = EventHelper.getEventCode(matchKey);
String notificationTitle = context.getString(R.string.notification_upcoming_match_title, eventCode, matchAbbrevTitle);
stored.setTitle(notificationTitle);
stored.setBody(contentText.toString());
stored.setMessageData(messageData);
stored.setIntent(MyTBAHelper.serializeIntent(instance));
stored.setTime(Calendar.getInstance().getTime());
stored.setSystemId(getNotificationId());
PendingIntent watchIntent = null;
String watchTitle = null;
if (webcast != null && webcast.isJsonObject()) {
JsonObject webcastJson = webcast.getAsJsonObject();
WebcastType webcastType = WebcastHelper.getType(webcastJson.get("type").getAsString());
if (webcastType != WebcastType.NONE) {
watchTitle = webcastType.render(context);
Intent webcastIntent = WebcastHelper.getIntentForWebcast(context, matchKey, webcastType, webcastJson, 0);
watchIntent = PendingIntent.getActivity(context, (int) System.currentTimeMillis(), webcastIntent, 0);
}
}
NotificationCompat.Builder builder = getBaseBuilder(context, instance).setContentTitle(notificationTitle).setContentText(contentText);
// Add Watch button
if (watchIntent != null) {
builder.addAction(R.drawable.ic_videocam_black_24dp, watchTitle, watchIntent);
}
NotificationCompat.BigTextStyle style = new NotificationCompat.BigTextStyle().bigText(contentText);
builder.setStyle(style);
return builder.build();
}
use of com.thebluealliance.androidclient.types.WebcastType in project the-blue-alliance-android by the-blue-alliance.
the class EventInfoBinder method buildMultiWebcastDialog.
private Dialog buildMultiWebcastDialog(final JsonArray webcasts, final String eventKey) {
String[] choices = new String[webcasts.size()];
for (int i = 0; i < webcasts.size(); i++) {
JsonObject webcastDetails = webcasts.get(i).getAsJsonObject();
WebcastType webcastType = WebcastHelper.getType(webcastDetails.get("type").getAsString());
choices[i] = mActivity.getString(R.string.select_multi_webcast_stream_format, i + 1, webcastType.render(mActivity));
}
AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
builder.setTitle(R.string.select_multi_webcast).setItems(choices, (dialog, which) -> {
JsonObject details = webcasts.get(which).getAsJsonObject();
WebcastType type = WebcastHelper.getType(details.get("type").getAsString());
Intent intent = WebcastHelper.getIntentForWebcast(mActivity, eventKey, type, details, which + 1);
try {
mActivity.startActivity(intent);
dialog.dismiss();
} catch (ActivityNotFoundException ex) {
// Unable to find an activity to handle the webcast
// Fall back by just opening Gameday in browser
String url = mActivity.getString(R.string.webcast_gameday_pattern, eventKey, which + 1);
Intent gamedayIntent = WebcastHelper.getWebIntentForUrl(url);
mActivity.startActivity(gamedayIntent);
dialog.dismiss();
}
});
return builder.create();
}
use of com.thebluealliance.androidclient.types.WebcastType in project the-blue-alliance-android by the-blue-alliance.
the class WebcastListElement method getView.
@Override
public View getView(final Context c, LayoutInflater inflater, View convertView) {
ViewHolder holder;
if (convertView == null || !(convertView.getTag() instanceof ViewHolder)) {
convertView = inflater.inflate(R.layout.list_item_carded_webcast, null);
holder = new ViewHolder();
holder.label = (TextView) convertView.findViewById(R.id.label);
holder.value = (TextView) convertView.findViewById(R.id.value);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.label.setText(String.format(c.getString(R.string.webcast_event_format), eventName, number));
final String service = webcast.get("type").getAsString();
final WebcastType type = WebcastHelper.getType(service);
if (service != null) {
holder.value.setVisibility(View.VISIBLE);
holder.value.setText(type.render(c));
holder.value.setTypeface(null, Typeface.NORMAL);
convertView.setOnClickListener(new WebcastClickListener(c, eventKey, type, webcast, number));
} else {
holder.value.setVisibility(View.GONE);
}
return convertView;
}
use of com.thebluealliance.androidclient.types.WebcastType in project the-blue-alliance-android by the-blue-alliance.
the class EventInfoBinder method updateData.
@Override
public void updateData(@Nullable Model data) {
if (data == null) {
if (!isDataBound()) {
bindNoDataView();
}
return;
}
mSocialClickListener.setModelKey(data.eventKey);
mIsLive = data.isLive;
eventName.setText(data.nameString);
if (data.dateString == null || data.dateString.isEmpty()) {
eventDateContainer.setVisibility(View.GONE);
} else {
eventDate.setText(data.dateString);
}
// Show a venue if it is available, otherwise show just the location. If neither is available, hide
if (data.venueString != null && !data.venueString.isEmpty()) {
eventVenue.setText(data.venueString);
} else if (data.locationString != null && !data.locationString.isEmpty()) {
eventVenue.setText(data.locationString);
} else {
eventVenue.setText(R.string.no_location_available);
eventVenueContainer.setVisibility(View.GONE);
}
// setup social media intents
// Default to showing the nav arrow in the venue view and the venue view being clickable
// We need to set these again even though they're defined in XML in case we gain a location
// or venue on a refresh and we're reusing the same view.
eventVenueContainer.setFocusable(true);
eventVenueContainer.setClickable(true);
eventVenueContainer.setOnClickListener(mSocialClickListener);
if (data.venueString != null && !data.venueString.isEmpty()) {
// Set the tag to the event venue if it is available
eventVenueContainer.setTag("geo:0,0?q=" + Uri.encode(data.venueString));
} else if (data.locationString != null && !data.locationString.isEmpty()) {
// Otherwise, use the location
eventVenueContainer.setTag("geo:0,0?q=" + Uri.encode(data.locationString));
} else {
// If neither location nor venue are available, hide the nav arrow, remove the tag,
// and set the view to not clickable so the user cannot interact with it.
// It will contain the text "No location available".
eventVenueContainer.setTag(null);
eventVenueContainer.setFocusable(false);
eventVenueContainer.setClickable(false);
}
// If the event doesn't have a defined website, create a Google search for the event name
if (data.eventWebsite != null && data.eventWebsite.isEmpty()) {
eventWebsiteContainer.setTag("https://www.google.com/search?q=" + Uri.encode(data.nameString));
eventWebsiteTitle.setText(R.string.find_event_on_google);
} else {
eventWebsiteContainer.setTag(data.eventWebsite);
eventWebsiteTitle.setText(R.string.view_event_website);
}
eventWebsiteContainer.setOnClickListener(mSocialClickListener);
eventTwitterContainer.setTag("https://twitter.com/search?q=%23" + data.eventKey);
eventTwitterTitle.setText(mActivity.getString(R.string.view_event_twitter, data.eventKey));
eventTwitterContainer.setOnClickListener(mSocialClickListener);
eventYoutubeContainer.setTag("https://www.youtube.com/results?search_query=" + data.eventKey);
eventYoutubeTitle.setText(mActivity.getString(R.string.view_event_youtube, data.eventKey));
eventYoutubeContainer.setOnClickListener(mSocialClickListener);
eventCdContainer.setTag("https://www.chiefdelphi.com/search?q=category%3A11%20tags%3A" + data.eventKey);
eventCdContainer.setOnClickListener(mSocialClickListener);
if (data.isLive && data.webcasts != null && data.webcasts.size() > 0) {
if (data.webcasts.size() == 1) {
// Only one webcast, we can link directly to that
JsonObject eventWebcast = data.webcasts.get(0).getAsJsonObject();
WebcastType webcastType = WebcastHelper.getType(eventWebcast.get("type").getAsString());
webcastButton.setText(webcastType.render(mActivity));
webcastButton.setOnClickListener(new WebcastClickListener(mActivity, data.eventKey, webcastType, eventWebcast, 1));
} else {
webcastButton.setText(R.string.view_webcast_button);
webcastButton.setOnClickListener(v -> {
Dialog chooserDialog = buildMultiWebcastDialog(data.webcasts, data.eventKey);
chooserDialog.show();
});
}
webcastContainer.setVisibility(View.VISIBLE);
}
content.setVisibility(View.VISIBLE);
progressBar.setVisibility(View.GONE);
EventBus.getDefault().post(new ActionBarTitleEvent(data.actionBarTitle, data.actionBarSubtitle));
mNoDataBinder.unbindData();
setDataBound(true);
}
Aggregations