X-Git-Url: https://git.ktnx.net/?p=mobile-ledger.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fui%2Factivity%2FProfileListActivity.java;h=857e7c394a65830d60beb0f4a0480ef7855e877d;hp=3cd61712ff96dcfc6f31a487209747bd62b0ab6f;hb=94aa0aa57db3dce40f31fc0321c718998d9cb48b;hpb=3b365016042215dd73cb4600840aa8199b8322b9 diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/activity/ProfileListActivity.java b/app/src/main/java/net/ktnx/mobileledger/ui/activity/ProfileListActivity.java index 3cd61712..857e7c39 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/activity/ProfileListActivity.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/activity/ProfileListActivity.java @@ -111,15 +111,13 @@ public class ProfileListActivity extends AppCompatActivity { } private void setupRecyclerView(@NonNull RecyclerView recyclerView) { - List list = MobileLedgerProfile.loadAllFromDB(); - recyclerView.setAdapter(new ProfilesRecyclerViewAdapter(this, list, mTwoPane)); + recyclerView.setAdapter(new ProfilesRecyclerViewAdapter(this, mTwoPane)); } public static class ProfilesRecyclerViewAdapter extends RecyclerView.Adapter { private final ProfileListActivity mParentActivity; - private final List mValues; private final boolean mTwoPane; private final View.OnClickListener mOnClickListener = new View.OnClickListener() { @Override @@ -128,11 +126,13 @@ public class ProfileListActivity extends AppCompatActivity { editProfile(view, item); } }; - ProfilesRecyclerViewAdapter(ProfileListActivity parent, List items, - boolean twoPane) { - mValues = items; + ProfilesRecyclerViewAdapter(ProfileListActivity parent, boolean twoPane) { mParentActivity = parent; mTwoPane = twoPane; + Data.profiles.addObserver((o, arg) ->{ + Log.d("profiles", "profile list changed"); + notifyDataSetChanged(); + }); } private void editProfile(View view, MobileLedgerProfile item) { if (mTwoPane) { @@ -171,7 +171,7 @@ public class ProfileListActivity extends AppCompatActivity { } @Override public void onBindViewHolder(@NonNull final ProfileListViewHolder holder, int position) { - final MobileLedgerProfile profile = mValues.get(position); + final MobileLedgerProfile profile = Data.profiles.get(position); final MobileLedgerProfile currentProfile = Data.profile.get(); Log.d("profiles", String.format("pos %d: %s, current: %s", position, profile.getUuid(), currentProfile.getUuid())); @@ -193,7 +193,7 @@ public class ProfileListActivity extends AppCompatActivity { } @Override public int getItemCount() { - return mValues.size(); + return Data.profiles.size(); } class ProfileListViewHolder extends RecyclerView.ViewHolder { final RadioButton mRadioView;