Search in sources :

Example 6 with Account

use of fr.neamar.lolgamedata.pojo.Account in project teamward-client by Neamar.

the class AccountManager method getAccounts.

public ArrayList<Account> getAccounts() {
    String accountsString = getSharedPreferences().getString(ACCOUNTS_KEY, DEFAULT_VALUE);
    try {
        JSONArray accountsJson = new JSONArray(accountsString);
        ArrayList<Account> accounts = new ArrayList<>();
        for (int i = 0; i < accountsJson.length(); i += 1) {
            Account account = new Account(accountsJson.getJSONObject(i));
            accounts.add(account);
        }
        return accounts;
    } catch (JSONException e) {
        Toast.makeText(context, "Accounts got corrupted, resetting app.", Toast.LENGTH_SHORT).show();
        e.printStackTrace();
        getSharedPreferences().edit().clear().apply();
        return new ArrayList<>();
    }
}
Also used : Account(fr.neamar.lolgamedata.pojo.Account) JSONArray(org.json.JSONArray) ArrayList(java.util.ArrayList) JSONException(org.json.JSONException)

Example 7 with Account

use of fr.neamar.lolgamedata.pojo.Account in project teamward-client by Neamar.

the class AccountsActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_accounts);
    AccountManager accountManager = new AccountManager(this);
    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    assert fab != null;
    fab.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            addAccount();
        }
    });
    ArrayList<Account> accounts = accountManager.getAccounts();
    JSONObject j = new JSONObject();
    try {
        j.put("accounts_count", accounts.size());
    } catch (JSONException e) {
        e.printStackTrace();
    }
    if (!accounts.isEmpty()) {
        Account mainAccount = accounts.get(0);
        Intent i = new Intent(this, GameActivity.class);
        i.putExtra("account", mainAccount);
        i.putExtra("source", "accounts");
        startActivityForResult(i, GAME_DETAILS);
        finish();
    }
}
Also used : Account(fr.neamar.lolgamedata.pojo.Account) JSONObject(org.json.JSONObject) FloatingActionButton(android.support.design.widget.FloatingActionButton) JSONException(org.json.JSONException) Intent(android.content.Intent) View(android.view.View)

Example 8 with Account

use of fr.neamar.lolgamedata.pojo.Account in project teamward-client by Neamar.

the class AccountsActivity method onActivityResult.

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == ADD_NEW_ACCOUNT && resultCode == RESULT_OK) {
        Account newAccount = (Account) data.getSerializableExtra("account");
        displaySnack(String.format("Added account %s", newAccount.summonerName));
        Intent i = new Intent(this, GameActivity.class);
        i.putExtra("account", newAccount);
        i.putExtra("source", "account_added");
        startActivityForResult(i, GAME_DETAILS);
        finish();
    } else if (requestCode == ADD_NEW_ACCOUNT && resultCode == AddAccountActivity.RESULT_ERROR) {
        displaySnack(data.getStringExtra("error"));
    } else {
        super.onActivityResult(requestCode, resultCode, data);
    }
}
Also used : Account(fr.neamar.lolgamedata.pojo.Account) Intent(android.content.Intent)

Example 9 with Account

use of fr.neamar.lolgamedata.pojo.Account in project teamward-client by Neamar.

the class DrawerFragment method onActivityCreated.

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    accountManager = new AccountManager(getActivity());
    assert getView() != null;
    RecyclerView recyclerView = (RecyclerView) getView().findViewById(R.id.recyclerView);
    assert recyclerView != null;
    recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
    ArrayList<Account> accounts = accountManager.getAccounts();
    final AccountAdapter adapter = new AccountAdapter(accounts);
    recyclerView.setAdapter(adapter);
    getView().findViewById(R.id.addLayout).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent i = new Intent(getActivity(), AddAccountActivity.class);
            startActivity(i);
        }
    });
    getView().findViewById(R.id.settingsLayout).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent i = new Intent(getActivity(), SettingsActivity.class);
            startActivity(i);
        }
    });
    mBroadcastReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            adapter.updateAccounts(accountManager.getAccounts());
        }
    };
    Log.i(TAG, "Starting account change receiver");
    LocalBroadcastManager.getInstance(getActivity()).registerReceiver(mBroadcastReceiver, new IntentFilter(AccountManager.ACCOUNTS_CHANGE));
}
Also used : Context(android.content.Context) Account(fr.neamar.lolgamedata.pojo.Account) IntentFilter(android.content.IntentFilter) Intent(android.content.Intent) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) BroadcastReceiver(android.content.BroadcastReceiver) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) AddAccountActivity(fr.neamar.lolgamedata.AddAccountActivity) AccountManager(fr.neamar.lolgamedata.AccountManager) RecyclerView(android.support.v7.widget.RecyclerView) AccountAdapter(fr.neamar.lolgamedata.adapter.AccountAdapter) SettingsActivity(fr.neamar.lolgamedata.SettingsActivity)

Example 10 with Account

use of fr.neamar.lolgamedata.pojo.Account in project teamward-client by Neamar.

the class NotificationService method onMessageReceived.

/**
 * Called when message is received.
 */
@Override
public void onMessageReceived(RemoteMessage message) {
    Map<String, String> data = message.getData();
    Log.i(TAG, "Received notification from " + message.getFrom());
    if (data.containsKey("gameId")) {
        long gameId = Long.parseLong(data.get("gameId"));
        String summonerName = data.get("summonerName");
        String region = data.get("region");
        int mapId = Integer.parseInt(data.get("mapId"));
        Account account = new Account(summonerName, region, "");
        displayNotification(account, gameId, mapId);
    } else if (data.containsKey("removeGameId")) {
        long gameId = Long.parseLong(data.get("removeGameId"));
        Log.i(TAG, "End of game, hiding notification.");
        getNotificationManager().cancel(Long.toString(gameId).hashCode());
    } else if (data.containsKey("mp_message")) {
        String title = data.containsKey("mp_title") ? data.get("mp_title") : getString(R.string.app_name);
        String content = data.get("mp_message");
        String url = data.containsKey("mp_url") ? data.get("mp_url") : "";
        displayCustomNotification(title, content, url);
    } else {
        Log.i(TAG, "Received unknown notification:" + data.toString());
    }
}
Also used : Account(fr.neamar.lolgamedata.pojo.Account)

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