Search in sources :

Example 1 with Summoner

use of fr.neamar.lolgamedata.pojo.Summoner 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);
    }
}
Also used : Summoner(fr.neamar.lolgamedata.pojo.Summoner) Player(fr.neamar.lolgamedata.pojo.Player) DrawableRes(android.support.annotation.DrawableRes) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Intent(android.content.Intent) ImageView(android.widget.ImageView) View(android.view.View) ChampionPortraitView(fr.neamar.lolgamedata.view.ChampionPortraitView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) ChampionInGame(fr.neamar.lolgamedata.pojo.ChampionInGame) Game(fr.neamar.lolgamedata.pojo.Game) ActivityNotFoundException(android.content.ActivityNotFoundException) TextView(android.widget.TextView) Team(fr.neamar.lolgamedata.pojo.Team) ImageView(android.widget.ImageView) ChampionPortraitView(fr.neamar.lolgamedata.view.ChampionPortraitView) Toolbar(android.support.v7.widget.Toolbar)

Aggregations

ActivityNotFoundException (android.content.ActivityNotFoundException)1 Intent (android.content.Intent)1 DrawableRes (android.support.annotation.DrawableRes)1 RecyclerView (android.support.v7.widget.RecyclerView)1 Toolbar (android.support.v7.widget.Toolbar)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 ChampionInGame (fr.neamar.lolgamedata.pojo.ChampionInGame)1 Game (fr.neamar.lolgamedata.pojo.Game)1 Player (fr.neamar.lolgamedata.pojo.Player)1 Summoner (fr.neamar.lolgamedata.pojo.Summoner)1 Team (fr.neamar.lolgamedata.pojo.Team)1 ChampionPortraitView (fr.neamar.lolgamedata.view.ChampionPortraitView)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1