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;
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;
});
// 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();
}
}
}
-
@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());
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);
}
}
useAuthentication.setOnCheckedChangeListener((buttonView, isChecked) -> {
Log.d("profiles", isChecked ? "auth enabled " : "auth disabled");
authParams.setVisibility(isChecked ? View.VISIBLE : View.GONE);
+ if (isChecked) userName.requestFocus();
});
if (mProfile != null) {