X-Git-Url: https://git.ktnx.net/?p=mobile-ledger.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fui%2Fprofiles%2FProfileDetailFragment.java;h=67f28439553cf010d5e530f1d71dcd43ff52a24d;hp=5a1b729a205cb4bc9e3c1e434012659500593a7b;hb=9e8a289a85a65d372b47ccd2c2261299972ae4dd;hpb=5288da587233a9203d4abcaf7840dc62db2fb294 diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfileDetailFragment.java b/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfileDetailFragment.java index 5a1b729a..67f28439 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfileDetailFragment.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfileDetailFragment.java @@ -18,9 +18,9 @@ package net.ktnx.mobileledger.ui.profiles; import android.app.Activity; -import android.content.Context; import android.os.Bundle; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.support.design.widget.CollapsingToolbarLayout; import android.support.design.widget.FloatingActionButton; import android.support.v4.app.Fragment; @@ -81,8 +81,9 @@ public class ProfileDetailFragment extends Fragment { Log.d("profiles", String.format("[fragment] removing profile %s", mProfile.getUuid())); mProfile.removeFromDB(); Data.profiles.remove(mProfile); - if (Data.profile.get().getUuid().equals(mProfile.getUuid())) { - Data.profile.set(Data.profiles.get(0)); + if (Data.profile.get().equals(mProfile)) { + Log.d("profiles", "[fragment] setting current profile to 0"); + Data.setCurrentProfile(Data.profiles.get(0)); } return false; }); @@ -96,9 +97,8 @@ public class ProfileDetailFragment extends Fragment { // Load the dummy content specified by the fragment // arguments. In a real-world scenario, use a Loader // to load content from a content provider. - String uuid = getArguments().getString(ARG_ITEM_ID); - if (uuid != null) mProfile = - MobileLedgerProfile.loadUUIDFromDB(getArguments().getString(ARG_ITEM_ID)); + int index = getArguments().getInt(ARG_ITEM_ID, -1); + if (index != -1) mProfile = Data.profiles.get(index); Activity activity = this.getActivity(); if (activity == null) throw new AssertionError(); @@ -109,11 +109,13 @@ public class ProfileDetailFragment extends Fragment { } } } - @Override - public void onAttach(Context context) { - super.onAttach(context); - fab = ((Activity) context).findViewById(R.id.fab); + public void onActivityCreated(@Nullable Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + Activity context = getActivity(); + if (context == null) return; + + fab = context.findViewById(R.id.fab); fab.setOnClickListener(v -> { if (mProfile != null) { mProfile.setName(profileName.getText()); @@ -122,9 +124,12 @@ public class ProfileDetailFragment extends Fragment { mProfile.setAuthUserName(userName.getText()); mProfile.setAuthPassword(password.getText()); mProfile.storeInDB(); + Log.d("profiles", "profile stored in DB"); + Data.profiles.triggerItemChangedNotification(mProfile); if (mProfile.getUuid().equals(Data.profile.get().getUuid())) { + // dummy update to notify the observers of the possibly new name/URL Data.profile.set(mProfile); } }