Search in sources :

Example 1 with AccountManager

use of fr.neamar.lolgamedata.AccountManager 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 2 with AccountManager

use of fr.neamar.lolgamedata.AccountManager 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)

Aggregations

AccountManager (fr.neamar.lolgamedata.AccountManager)2 Account (fr.neamar.lolgamedata.pojo.Account)2 BroadcastReceiver (android.content.BroadcastReceiver)1 Context (android.content.Context)1 Intent (android.content.Intent)1 IntentFilter (android.content.IntentFilter)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 AddAccountActivity (fr.neamar.lolgamedata.AddAccountActivity)1 SettingsActivity (fr.neamar.lolgamedata.SettingsActivity)1 AccountAdapter (fr.neamar.lolgamedata.adapter.AccountAdapter)1