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<>();
}
}
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();
}
}
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);
}
}
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));
}
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());
}
}
Aggregations