Search in sources :

Example 1 with AccountAdapter

use of fr.neamar.lolgamedata.adapter.AccountAdapter 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

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 AccountManager (fr.neamar.lolgamedata.AccountManager)1 AddAccountActivity (fr.neamar.lolgamedata.AddAccountActivity)1 SettingsActivity (fr.neamar.lolgamedata.SettingsActivity)1 AccountAdapter (fr.neamar.lolgamedata.adapter.AccountAdapter)1 Account (fr.neamar.lolgamedata.pojo.Account)1