use of fr.neamar.lolgamedata.pojo.Account in project teamward-client by Neamar.
the class LolApplication method identifyOnTrackers.
public void identifyOnTrackers() {
AccountManager accountManager = new AccountManager(getApplicationContext());
List<Account> accounts = accountManager.getAccounts();
Log.i(TAG, "Current size for accounts is " + accounts.size());
if (!accountManager.getAccounts().isEmpty()) {
Log.i(TAG, "Identifying as " + accounts.get(0).summonerName);
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
Tracker.trackUserProperties(getApplicationContext(), accounts.get(0), accounts.size(), sp);
}
}
use of fr.neamar.lolgamedata.pojo.Account in project teamward-client by Neamar.
the class SyncTokenService method onHandleIntent.
@Override
protected void onHandleIntent(Intent intent) {
AccountManager accountManager = new AccountManager(this);
ArrayList<Account> accounts = accountManager.getAccounts();
if (accounts.isEmpty()) {
Log.i(TAG, "No account yet, skipping token registration");
return;
}
Account account = accounts.get(0);
String token = FirebaseInstanceId.getInstance().getToken();
if (token == null || token.isEmpty()) {
Log.i(TAG, "Firebase token not ready yet, skipping token registration");
return;
}
// We have both a token and an account, send that to the server
sendTokenToServer(token, account);
}
use of fr.neamar.lolgamedata.pojo.Account in project teamward-client by Neamar.
the class PremadeNotUsingTeamwardTipBuilder method getTips.
@Override
public ArrayList<Tip> getTips(Game game, Context context) {
ArrayList<Tip> tips = new ArrayList<>();
Account mainAccount = game.associatedAccount;
Player mainPlayer = game.getPlayerByAccount(mainAccount);
if (mainPlayer == null) {
return tips;
}
List<Integer> premade = findPlayerPremade(game, mainPlayer);
if (premade == null) {
return tips;
}
List<String> playersNotUsingTeamward = new ArrayList<>();
for (Integer summonerId : premade) {
Player player = findPlayerById(game, summonerId);
if (player != null && !player.teamwardUser && player != mainPlayer) {
playersNotUsingTeamward.add(player.summoner.name);
}
}
if (!playersNotUsingTeamward.isEmpty()) {
String descriptionTemplate;
String description;
if (playersNotUsingTeamward.size() == 1) {
descriptionTemplate = context.getString(R.string.s_is_not_using_teamward);
description = String.format(descriptionTemplate, playersNotUsingTeamward.get(0));
} else {
descriptionTemplate = context.getString(R.string.s_are_not_using_teamward);
String lastPlayer = playersNotUsingTeamward.get(playersNotUsingTeamward.size() - 1);
playersNotUsingTeamward.remove(playersNotUsingTeamward.size() - 1);
String players = TextUtils.join(context.getString(R.string.standard_separator) + " ", playersNotUsingTeamward);
players += " " + context.getString(R.string.final_separator) + " " + lastPlayer;
description = String.format(descriptionTemplate, players);
}
tips.add(new PlayerStandardTip(game, null, R.mipmap.ic_launcher, context.getString(R.string.not_using_teamward), description));
}
return tips;
}
use of fr.neamar.lolgamedata.pojo.Account in project teamward-client by Neamar.
the class AddAccountActivity method saveAccount.
private void saveAccount(final String name, final String region) {
final Account newAccount = new Account(name, region, "");
final ProgressDialog dialog = ProgressDialog.show(this, "", String.format(getString(R.string.loading_summoner_data), name), true);
dialog.show();
// Instantiate the RequestQueue.
final RequestQueue queue = VolleyQueue.newRequestQueue(this);
try {
NoCacheRetryJsonRequest jsonRequest = new NoCacheRetryJsonRequest(Request.Method.GET, ((LolApplication) getApplication()).getApiUrl() + "/summoner/data?summoner=" + URLEncoder.encode(name, "UTF-8") + "®ion=" + region, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
if (dialog.isShowing()) {
dialog.dismiss();
}
} catch (IllegalArgumentException e) {
// View is not attached (rotation for instance)
}
newAccount.summonerImage = response.optString("profileIcon", "");
newAccount.summonerName = response.optString("name", newAccount.summonerName);
Intent intent = new Intent(NEW_ACCOUNT);
intent.putExtra("account", newAccount);
setResult(RESULT_OK, intent);
AccountManager accountManager = new AccountManager(AddAccountActivity.this);
accountManager.addAccount(newAccount);
Tracker.trackAccountAdded(AddAccountActivity.this, newAccount, accountManager.getAccountIndex(newAccount));
queue.stop();
finish();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
try {
if (dialog.isShowing()) {
dialog.dismiss();
}
} catch (IllegalArgumentException e) {
// View is not attached (rotation for instance)
}
Log.e(TAG, error.toString());
try {
String responseBody = new String(error.networkResponse.data, "utf-8");
String errorMessage = responseBody.isEmpty() ? "Unable to load player data" : responseBody;
Log.i(TAG, errorMessage);
Intent intent = new Intent();
intent.putExtra("type", NEW_ACCOUNT);
intent.putExtra("error", errorMessage);
setResult(RESULT_ERROR, intent);
Tracker.trackErrorAddingAccount(AddAccountActivity.this, newAccount, errorMessage);
} catch (UnsupportedEncodingException | NullPointerException e) {
e.printStackTrace();
}
queue.stop();
final TextView nameText = (TextView) findViewById(R.id.summonerText);
nameText.setError(getString(R.string.error_adding_account));
}
});
queue.add(jsonRequest);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
use of fr.neamar.lolgamedata.pojo.Account in project teamward-client by Neamar.
the class CounterChampionsActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_counter_champions);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
assert getSupportActionBar() != null;
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowTitleEnabled(false);
// Setup spinner
Spinner spinner = (Spinner) findViewById(R.id.spinner);
spinner.setAdapter(new RoleAdapter(toolbar.getContext(), ROLES));
final Account account = (Account) getIntent().getSerializableExtra("account");
final SharedPreferences prefs = getPreferences(MODE_PRIVATE);
spinner.setSelection(prefs.getInt("lastUsedPosition", 2));
spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
currentFragment = CounterChampionsFragment.newInstance(ROLES[position], account);
getSupportFragmentManager().beginTransaction().replace(R.id.container, currentFragment).commitAllowingStateLoss();
prefs.edit().putInt("lastUsedPosition", position).apply();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
}
Aggregations