Search in sources :

Example 1 with Account

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);
    }
}
Also used : Account(fr.neamar.lolgamedata.pojo.Account) SharedPreferences(android.content.SharedPreferences)

Example 2 with Account

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);
}
Also used : Account(fr.neamar.lolgamedata.pojo.Account) AccountManager(fr.neamar.lolgamedata.AccountManager)

Example 3 with 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;
}
Also used : Account(fr.neamar.lolgamedata.pojo.Account) Player(fr.neamar.lolgamedata.pojo.Player) PlayerStandardTip(fr.neamar.lolgamedata.tips.PlayerStandardTip) ArrayList(java.util.ArrayList) PlayerStandardTip(fr.neamar.lolgamedata.tips.PlayerStandardTip) Tip(fr.neamar.lolgamedata.tips.Tip)

Example 4 with Account

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") + "&region=" + 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();
    }
}
Also used : VolleyError(com.android.volley.VolleyError) Account(fr.neamar.lolgamedata.pojo.Account) NoCacheRetryJsonRequest(fr.neamar.lolgamedata.volley.NoCacheRetryJsonRequest) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Intent(android.content.Intent) ProgressDialog(android.app.ProgressDialog) Response(com.android.volley.Response) JSONObject(org.json.JSONObject) RequestQueue(com.android.volley.RequestQueue) TextView(android.widget.TextView)

Example 5 with Account

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) {
        }
    });
}
Also used : Account(fr.neamar.lolgamedata.pojo.Account) SharedPreferences(android.content.SharedPreferences) Spinner(android.widget.Spinner) OnItemSelectedListener(android.widget.AdapterView.OnItemSelectedListener) RoleAdapter(fr.neamar.lolgamedata.adapter.RoleAdapter) SearchView(android.support.v7.widget.SearchView) View(android.view.View) AdapterView(android.widget.AdapterView) Toolbar(android.support.v7.widget.Toolbar)

Aggregations

Account (fr.neamar.lolgamedata.pojo.Account)10 Intent (android.content.Intent)4 View (android.view.View)3 SharedPreferences (android.content.SharedPreferences)2 AccountManager (fr.neamar.lolgamedata.AccountManager)2 ArrayList (java.util.ArrayList)2 JSONException (org.json.JSONException)2 JSONObject (org.json.JSONObject)2 ProgressDialog (android.app.ProgressDialog)1 BroadcastReceiver (android.content.BroadcastReceiver)1 Context (android.content.Context)1 IntentFilter (android.content.IntentFilter)1 FloatingActionButton (android.support.design.widget.FloatingActionButton)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 SearchView (android.support.v7.widget.SearchView)1 Toolbar (android.support.v7.widget.Toolbar)1 AdapterView (android.widget.AdapterView)1 OnItemSelectedListener (android.widget.AdapterView.OnItemSelectedListener)1 Spinner (android.widget.Spinner)1