use of fr.neamar.lolgamedata.pojo.Game in project teamward-client by Neamar.
the class PerformanceActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_performance);
final Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
assert getSupportActionBar() != null;
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
Game game = (Game) getIntent().getSerializableExtra("game");
player = (Player) getIntent().getSerializableExtra("player");
// Doing this in two steps, got some crash reports on the Store and trying to understand
// what can be Null: player.summoner, or summoner.name.
Summoner summoner = player.summoner;
// HERO
setTitle(summoner.name);
// CHAMPION MASTERY
View masteryHolder = findViewById(R.id.masteryHolder);
ImageView championMasteryImage = (ImageView) findViewById(R.id.championMasteryImage);
TextView championMasteryText = (TextView) findViewById(R.id.championMasteryText);
TextView championPointsText = (TextView) findViewById(R.id.championPointsText);
@DrawableRes int championMasteryResource = CHAMPION_MASTERIES_RESOURCES[player.champion.mastery];
if (championMasteryResource == 0) {
masteryHolder.setVisibility(View.GONE);
} else {
championMasteryImage.setImageResource(CHAMPION_MASTERIES_RESOURCES[player.champion.mastery]);
championMasteryText.setText(String.format(getString(R.string.champion_mastery_lvl), player.champion.mastery));
if (player.champion.mastery >= 5) {
championPointsText.setText(String.format(getString(R.string.champion_points), NumberFormat.getInstance().format(player.champion.points)));
} else {
championPointsText.setVisibility(View.GONE);
}
masteryHolder.setVisibility(View.VISIBLE);
}
// RANKED INFORMATION
View rankingHolder = findViewById(R.id.rankingHolder);
ImageView rankingTierImage = (ImageView) rankingHolder.findViewById(R.id.rankingTierImage);
TextView rankingText = (TextView) rankingHolder.findViewById(R.id.rankingText);
TextView rankingQueue = (TextView) rankingHolder.findViewById(R.id.rankingQueue);
if (player.rank.tier.isEmpty() || !RANKING_TIER_RESOURCES.containsKey(player.rank.tier.toLowerCase(Locale.ROOT))) {
rankingHolder.setVisibility(View.GONE);
} else {
rankingTierImage.setImageResource(RANKING_TIER_RESOURCES.get(player.rank.tier.toLowerCase(Locale.ROOT)));
rankingText.setText(String.format(getString(R.string.ranking), player.rank.tier.toUpperCase(Locale.ROOT), player.rank.division));
rankingHolder.setVisibility(View.VISIBLE);
rankingQueue.setText(getQueueName(player.rank.queue));
}
rankingHolder.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
try {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://" + player.region + ".op.gg/summoner/userName=" + URLEncoder.encode(player.summoner.name, "UTF-8")));
startActivity(browserIntent);
Tracker.trackClickOnOpGG(PerformanceActivity.this, player);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ActivityNotFoundException e) {
Toast.makeText(PerformanceActivity.this, R.string.unable_to_open_browser, Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
}
});
// LAST SEASON RANKED INFORMATION
View lastSeasonRankHolder = findViewById(R.id.lastSeasonRankHolder);
ImageView lastRankingTierImage = (ImageView) lastSeasonRankHolder.findViewById(R.id.rankingTierImage);
TextView lastRankingText = (TextView) lastSeasonRankHolder.findViewById(R.id.rankingText);
// Do not display unranked, null, or any rank similar to current rank
if (player.rank.oldTier.isEmpty() || player.rank.oldTier.equals(player.rank.tier) || !RANKING_TIER_RESOURCES.containsKey(player.rank.oldTier.toLowerCase(Locale.ROOT))) {
lastSeasonRankHolder.setVisibility(View.GONE);
} else {
lastRankingTierImage.setImageResource(RANKING_TIER_RESOURCES.get(player.rank.oldTier.toLowerCase(Locale.ROOT)));
lastRankingText.setText(String.format(getString(R.string.ranking_last_season), player.rank.oldTier.toUpperCase(Locale.ROOT)));
lastSeasonRankHolder.setVisibility(View.VISIBLE);
}
// MATCHUP INFORMATION
View matchupHolder = findViewById(R.id.matchupHolder);
ImageView ownChampion = (ImageView) findViewById(R.id.ownChampion);
ImageView enemyChampion = (ImageView) findViewById(R.id.enemyChampion);
TextView matchupTextView = (TextView) findViewById(R.id.matchupStats);
final Team playerTeam = game.getTeamForPlayer(player);
Player oppositePlayer = null;
if (game.teams.size() > 1) {
Team otherTeam = game.teams.get(0) == playerTeam ? game.teams.get(1) : game.teams.get(0);
for (Player tplayer : otherTeam.players) {
if (player.champion.role.equals(tplayer.champion.role)) {
oppositePlayer = tplayer;
break;
}
}
}
if (playerTeam == null || player.champion.role.equals(ChampionInGame.UNKNOWN_ROLE) || oppositePlayer == null) {
matchupHolder.setVisibility(View.GONE);
} else {
ImageLoader.getInstance().displayImage(player.champion.imageUrl, ownChampion);
ImageLoader.getInstance().displayImage(oppositePlayer.champion.imageUrl, enemyChampion);
if (player.champion.winRate >= 0) {
matchupTextView.setText(String.format(Locale.getDefault(), "%d%%", player.champion.winRate));
if (player.champion.winRate > 50) {
matchupTextView.setTextColor(getResources().getColor(R.color.colorGoodMatchup));
} else if (player.champion.winRate < 50) {
matchupTextView.setTextColor(getResources().getColor(R.color.colorBadMatchup));
}
} else {
matchupTextView.setText("?");
matchupTextView.setTextColor(getResources().getColor(R.color.colorUnknownMatchup));
}
}
matchupHolder.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(player.champion.ggUrl));
try {
startActivity(browserIntent);
} catch (ActivityNotFoundException e) {
Toast.makeText(PerformanceActivity.this, R.string.unable_to_open_browser, Toast.LENGTH_SHORT).show();
}
Tracker.trackClickOnGG(PerformanceActivity.this, player.champion.name, player.champion.id, "player_details");
}
});
// MAIN CHAMPIONS
if (player.mainChampions.size() == 0) {
findViewById(R.id.mainsHolder).setVisibility(View.GONE);
} else {
ChampionPortraitView main1 = ((ChampionPortraitView) findViewById(R.id.main1));
ChampionPortraitView main2 = ((ChampionPortraitView) findViewById(R.id.main2));
ChampionPortraitView main3 = ((ChampionPortraitView) findViewById(R.id.main3));
main1.setChampion(player.mainChampions.get(0));
if (player.mainChampions.size() == 3) {
main2.setChampion(player.mainChampions.get(1));
main3.setChampion(player.mainChampions.get(2));
} else if (player.mainChampions.size() == 2) {
main2.setChampion(player.mainChampions.get(1));
main3.setVisibility(View.GONE);
} else {
main2.setVisibility(View.GONE);
main3.setVisibility(View.GONE);
}
}
// RECENT MATCHES
TextView recentMatchesText = (TextView) findViewById(R.id.recentMatchesTitle);
recentMatchesText.setText(String.format(getString(R.string.recent_matches), player.champion.name));
findViewById(R.id.aggregate).setVisibility(View.GONE);
downloadPerformance();
// TEAMWARD USER
if (player.teamwardUser) {
findViewById(R.id.teamwardUser).setVisibility(View.VISIBLE);
}
}
use of fr.neamar.lolgamedata.pojo.Game in project teamward-client by Neamar.
the class GameActivity method loadCurrentGame.
private void loadCurrentGame(final String summonerName, final String region) {
final ProgressDialog dialog = ProgressDialog.show(this, "", String.format(getString(R.string.loading_game_data), summonerName), true);
dialog.show();
// Instantiate the RequestQueue.
final RequestQueue queue = VolleyQueue.newRequestQueue(this);
try {
String version = "unknown";
try {
PackageInfo pInfo = this.getPackageManager().getPackageInfo(getPackageName(), 0);
version = pInfo.versionName;
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
String url = ((LolApplication) getApplication()).getApiUrl() + "/game/data?summoner=" + URLEncoder.encode(summonerName, "UTF-8") + "®ion=" + region + "&version=" + version;
if (BuildConfig.DEBUG && summonerName.equalsIgnoreCase("MOCK")) {
url = "https://gist.githubusercontent.com/Neamar/eb278b4d5f188546f56028c3a0310507/raw/game.json";
}
NoCacheRetryJsonRequest jsonRequest = new NoCacheRetryJsonRequest(Request.Method.GET, url, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
game = new Game(response, region, account, shouldUseRelativeTeamColor());
GameActivity.this.summonerName = summonerName;
displayGame(summonerName, game);
Log.i(TAG, "Displaying game #" + game.gameId);
String source = getIntent() != null && getIntent().hasExtra("source") && !getIntent().getStringExtra("source").isEmpty() ? getIntent().getStringExtra("source") : "unknown";
Tracker.trackGameViewed(GameActivity.this, account, game, getDefaultTabName(), shouldDisplayChampionName(), source);
} catch (JSONException e) {
e.printStackTrace();
} finally {
try {
if (dialog.isShowing()) {
dialog.dismiss();
}
} catch (IllegalArgumentException e) {
// View is not attached (rotation for instance)
}
lastLoaded = new Date();
queue.stop();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
game = null;
lastLoaded = null;
try {
if (dialog.isShowing()) {
dialog.dismiss();
}
} catch (IllegalArgumentException e) {
// View is not attached (rotation for instance)
}
Log.e(TAG, error.toString());
queue.stop();
setUiMode(UI_MODE_NO_INTERNET);
if (error instanceof NoConnectionError) {
displaySnack(getString(R.string.no_internet_connection));
return;
}
try {
String responseBody = new String(error.networkResponse.data, "utf-8");
Log.i(TAG, responseBody);
if (!responseBody.contains("ummoner not in game")) {
displaySnack(responseBody);
Tracker.trackErrorViewingGame(GameActivity.this, account, responseBody.replace("Error:", ""));
} else {
setUiMode(UI_MODE_NOT_IN_GAME);
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (NullPointerException e) {
// Do nothing, no text content in the HTTP reply.
}
}
});
queue.add(jsonRequest);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
use of fr.neamar.lolgamedata.pojo.Game in project teamward-client by Neamar.
the class TeamFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_team, container, false);
RecyclerView recyclerView = (RecyclerView) rootView.findViewById(R.id.recyclerView);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(rootView.getContext()));
team = (Team) getArguments().getSerializable(ARG_SECTION_TEAM);
assert team != null;
Game game = (Game) getArguments().getSerializable(ARG_SECTION_GAME);
assert game != null;
PlayerAdapter adapter = new PlayerAdapter(team.players, game);
recyclerView.setAdapter(adapter);
return rootView;
}
use of fr.neamar.lolgamedata.pojo.Game in project teamward-client by Neamar.
the class PremadeTipHolder method bind.
public void bind(Tip tip) {
PremadeTip premadeTip = (PremadeTip) tip;
Game game = premadeTip.game;
drawChampions(game.teams.get(0));
// Custom game
if (game.teams.size() != 2) {
return;
}
drawChampions(game.teams.get(1));
if (game.teams.get(0).premades.size() == 1 && game.teams.get(1).premades.size() == 1) {
// One big premade on both teams, we can't really be wrong...
disclaimer.setVisibility(View.GONE);
} else {
// Never forget that this is no exact science
disclaimer.setVisibility(View.VISIBLE);
}
}
Aggregations