use of com.thebluealliance.api.model.IMatchAlliancesContainer in project the-blue-alliance-android by the-blue-alliance.
the class MatchRenderer method renderFromModel.
/**
* Renders a MatchListElement for displaying this match. ASSUMES 3v3 match structure with
* red/blue alliances Use different render methods for other structures
*/
@WorkerThread
@Override
@Nullable
public MatchListElement renderFromModel(Match match, Integer renderMode) {
RenderArgs args = argsFromMode(renderMode);
@Nullable IMatchAlliancesContainer alliances = match.getAlliances();
@Nullable List<IMatchVideo> videos = match.getVideos();
String key = match.getKey();
if (key.isEmpty()) {
return null;
}
String redScore = (alliances == null) ? "-1" : Integer.toString(alliances.getRed().getScore());
String blueScore = (alliances == null) ? "-1" : Integer.toString(alliances.getBlue().getScore());
if (Integer.parseInt(redScore) < 0)
redScore = "?";
if (Integer.parseInt(blueScore) < 0)
blueScore = "?";
String youTubeVideoKey = null;
if (videos != null) {
for (IMatchVideo video : videos) {
if ("youtube".equals(video.getType())) {
youTubeVideoKey = video.getKey();
break;
}
}
}
String[] redAlliance, blueAlliance;
// Add teams based on alliance size (or none if there isn't for some reason)
List<String> redTeams = (alliances != null) ? alliances.getRed().getTeamKeys() : null;
if (redTeams != null && redTeams.size() == 3) {
redAlliance = new String[] { redTeams.get(0).substring(3), redTeams.get(1).substring(3), redTeams.get(2).substring(3) };
} else if (redTeams != null && redTeams.size() == 2) {
redAlliance = new String[] { redTeams.get(0).substring(3), redTeams.get(1).substring(3) };
} else {
redAlliance = new String[] { "", "", "" };
}
List<String> blueTeams = (alliances != null) ? alliances.getBlue().getTeamKeys() : null;
if (blueTeams != null && blueTeams.size() == 3) {
blueAlliance = new String[] { blueTeams.get(0).substring(3), blueTeams.get(1).substring(3), blueTeams.get(2).substring(3) };
} else if (blueTeams != null && blueTeams.size() == 2) {
blueAlliance = new String[] { blueTeams.get(0).substring(3), blueTeams.get(1).substring(3) };
} else {
blueAlliance = new String[] { "", "", "" };
}
long matchTime = match.getTime() != null ? match.getTime() : -1;
int redExtraRp = 0;
int blueExtraRp = 0;
if (match.getYear() >= 2016) {
JsonObject scoreBreakdown = JSONHelper.getasJsonObject(match.getScoreBreakdown());
JsonObject redScoreBreakdown = null;
if (scoreBreakdown.has("red")) {
redScoreBreakdown = scoreBreakdown.get("red").getAsJsonObject();
}
JsonObject blueScoreBreakdown = null;
if (scoreBreakdown.has("blue")) {
blueScoreBreakdown = scoreBreakdown.get("blue").getAsJsonObject();
}
String rpName1 = null;
String rpName2 = null;
switch(match.getYear()) {
case 2016:
rpName1 = "teleopDefensesBreached";
rpName2 = "teleopTowerCaptured";
break;
case 2017:
rpName1 = "kPaRankingPointAchieved";
rpName2 = "rotorRankingPointAchieved";
break;
case 2018:
rpName1 = "autoQuestRankingPoint";
rpName2 = "faceTheBossRankingPoint";
break;
case 2019:
rpName1 = "habDockingRankingPoint";
rpName2 = "completeRocketRankingPoint";
break;
case 2020:
rpName1 = "shieldOperationalRankingPoint";
rpName2 = "shieldEnergizedRankingPoint";
break;
}
if (rpName1 != null) {
if (redScoreBreakdown != null && redScoreBreakdown.get(rpName1).getAsBoolean()) {
redExtraRp++;
}
if (blueScoreBreakdown != null && blueScoreBreakdown.get(rpName1).getAsBoolean()) {
blueExtraRp++;
}
}
if (rpName2 != null) {
if (redScoreBreakdown != null && redScoreBreakdown.get(rpName2).getAsBoolean()) {
redExtraRp++;
}
if (blueScoreBreakdown != null && blueScoreBreakdown.get(rpName2).getAsBoolean()) {
blueExtraRp++;
}
}
}
return new MatchListElement(youTubeVideoKey, match.getTitle(mResources, true), redAlliance, blueAlliance, redScore, blueScore, match.getWinningAlliance(), key, matchTime, match.getSelectedTeam(), args.showVideo, args.showHeaders, args.showMatchTitle, args.clickable, redExtraRp, blueExtraRp);
}
use of com.thebluealliance.api.model.IMatchAlliancesContainer in project the-blue-alliance-android by the-blue-alliance.
the class ScoreNotification method buildNotification.
@Override
public Notification buildNotification(Context context, FollowsChecker followsChecker) {
Resources r = context.getResources();
matchKey = match.getKey();
String matchTitle = MatchHelper.getMatchTitleFromMatchKey(context, matchKey);
String matchAbbrevTitle = MatchHelper.getAbbrevMatchTitleFromMatchKey(context, matchKey);
IMatchAlliancesContainer alliances = match.getAlliances();
int redScore = Match.getRedScore(alliances);
int blueScore = Match.getBlueScore(alliances);
// Boldify the team numbers that the user is following, but only if the system supports
// java 8 language features
CharSequence firstTeams;
CharSequence secondTeams;
ArrayList<String> redTeams = Match.teamNumbers(Match.getRedTeams(alliances));
ArrayList<String> blueTeams = Match.teamNumbers(Match.getBlueTeams(alliances));
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) {
Predicate<String> isFollowing = teamNumber -> followsChecker.followsTeam(context, teamNumber, matchKey, NotificationTypes.MATCH_SCORE);
firstTeams = Utilities.boldNameList(redTeams, isFollowing);
secondTeams = Utilities.boldNameList(blueTeams, isFollowing);
} else {
firstTeams = Utilities.stringifyListOfStrings(context, redTeams);
secondTeams = Utilities.stringifyListOfStrings(context, blueTeams);
}
// Make sure the score string is formatted properly with the winning score first
String scoreString;
if (blueScore > redScore) {
scoreString = blueScore + "-" + redScore;
CharSequence temp = firstTeams;
firstTeams = secondTeams;
secondTeams = temp;
} else {
scoreString = redScore + "-" + blueScore;
}
MatchType matchType = MatchType.fromShortType(match.getCompLevel());
boolean useSpecial2015Format = match.getYear() == 2015 && matchType != MatchType.FINAL;
String eventShortName = EventHelper.shortName(eventName);
String template;
if (useSpecial2015Format) {
// firstTeams played secondTeams (for 2015 non-finals matches)
template = context.getString(R.string.notification_score_teams_played_teams);
} else if (blueScore == redScore) {
// firstTeams tied secondTeams
template = context.getString(R.string.notification_score_teams_tied_teams);
} else {
// firstTeams beat secondTeams
template = context.getString(R.string.notification_score_teams_beat_teams);
}
CharSequence notificationBody = TextUtils.expandTemplate(template, eventShortName, matchTitle, firstTeams, secondTeams, scoreString);
// We can finally build the notification!
Intent instance = getIntent(context);
stored = new StoredNotification();
stored.setType(getNotificationType());
String eventCode = EventHelper.getEventCode(matchKey);
String notificationTitle = r.getString(R.string.notification_score_title, eventCode, matchAbbrevTitle);
stored.setTitle(notificationTitle);
stored.setBody(notificationBody.toString());
stored.setIntent(MyTBAHelper.serializeIntent(instance));
stored.setTime(Calendar.getInstance().getTime());
stored.setMessageData(messageData);
stored.setSystemId(getNotificationId());
NotificationCompat.Builder builder = getBaseBuilder(context, instance).setContentTitle(notificationTitle).setContentText(notificationBody);
NotificationCompat.BigTextStyle style = new NotificationCompat.BigTextStyle().bigText(notificationBody);
builder.setStyle(style);
return builder.build();
}
use of com.thebluealliance.api.model.IMatchAlliancesContainer in project the-blue-alliance-android by the-blue-alliance.
the class MatchTest method testMatchModel.
@Test
public void testMatchModel() {
assertNotNull(mMatch);
assertEquals(mMatch.getKey(), "2014cmp_f1m1");
assertEquals(mMatch.getMatchNumber().intValue(), 1);
assertEquals(mMatch.getSetNumber().intValue(), 1);
assertEquals(mMatch.getEventKey(), "2014cmp");
assertNotNull(mMatch.getTime());
assertEquals(mMatch.getTime().intValue(), 1398551880);
assertNotNull(mMatch.getVideos());
assertNotNull(mMatch.getAlliances());
List<IMatchVideo> videos = mMatch.getVideos();
assertEquals(videos.size(), 2);
IMatchVideo video1 = videos.get(0);
assertEquals(video1.getType(), "youtube");
assertEquals(video1.getKey(), "jdJutaggCMk");
IMatchAlliancesContainer alliances = mMatch.getAlliances();
IMatchAlliance blueAlliance = alliances.getBlue();
assertEquals(blueAlliance.getScore().intValue(), 361);
List<String> blueTeams = blueAlliance.getTeamKeys();
assertEquals(blueTeams.size(), 3);
assertEquals(blueTeams.get(0), "frc469");
}
use of com.thebluealliance.api.model.IMatchAlliancesContainer in project the-blue-alliance-android by the-blue-alliance.
the class MatchBreakdownSubscriber method parseData.
@Override
public void parseData() {
JsonObject scoreBreakdown;
IMatchAlliancesContainer alliances;
boolean shouldShowBreakdown = false;
switch(mAPIData.getYear()) {
case 2015:
case 2016:
shouldShowBreakdown = true;
break;
case 2017:
shouldShowBreakdown = mConfig.getBoolean(SHOW_2017_KEY);
TbaLogger.i("Showing 2017 breakdowns? " + shouldShowBreakdown);
break;
case 2018:
shouldShowBreakdown = mConfig.getBoolean(SHOW_2018_KEY);
TbaLogger.i("Showing 2018 breakdowns? " + shouldShowBreakdown);
break;
case 2019:
shouldShowBreakdown = mConfig.getBoolean(SHOW_2019_KEY);
TbaLogger.i("Showing 2019 breakdowns? " + shouldShowBreakdown);
break;
case 2020:
shouldShowBreakdown = mConfig.getBoolean(SHOW_2020_KEY);
TbaLogger.i("Showing 2020 breakdown? " + shouldShowBreakdown);
break;
case 2022:
shouldShowBreakdown = mConfig.getBoolean(SHOW_2022_KEY);
TbaLogger.i("Showing 2020 breakdown? " + shouldShowBreakdown);
break;
}
mDataToBind = null;
if (shouldShowBreakdown) {
scoreBreakdown = mGson.fromJson(mAPIData.getScoreBreakdown(), JsonObject.class);
alliances = mAPIData.getAlliances();
if (scoreBreakdown == null || scoreBreakdown.entrySet().isEmpty() || alliances == null) {
mDataToBind = null;
return;
}
mDataToBind = new MatchBreakdownBinder.Model(mAPIData.getType(), mAPIData.getYear(), mAPIData.getWinningAlliance(), alliances, scoreBreakdown);
}
}
Aggregations