/** * Add a new profile at a specific position to the list * * @param profile * @param position */ public void addProfile(@NonNull IProfile profile, int position) { if (mAccountHeaderBuilder.mProfiles == null) { mAccountHeaderBuilder.mProfiles = new ArrayList<>(); } mAccountHeaderBuilder.mProfiles.add(position, IdDistributor.checkId(profile)); mAccountHeaderBuilder.updateHeaderAndList(); }
/** Clear the header */ public void clear() { mAccountHeaderBuilder.mProfiles = null; // calculate the profiles to set mAccountHeaderBuilder.calculateProfiles(); // process and build the profiles mAccountHeaderBuilder.buildProfiles(); }
/** * Add new profiles to the existing list of profiles * * @param profiles */ public void addProfiles(@NonNull IProfile... profiles) { if (mAccountHeaderBuilder.mProfiles == null) { mAccountHeaderBuilder.mProfiles = new ArrayList<>(); } Collections.addAll(mAccountHeaderBuilder.mProfiles, IdDistributor.checkIds(profiles)); mAccountHeaderBuilder.updateHeaderAndList(); }
/** * add the values to the bundle for saveInstanceState * * @param savedInstanceState * @return */ public Bundle saveInstanceState(Bundle savedInstanceState) { if (savedInstanceState != null) { savedInstanceState.putInt( BUNDLE_SELECTION_HEADER, mAccountHeaderBuilder.getCurrentSelection()); } return savedInstanceState; }
/** * try to remove the given profile * * @param profile */ public void removeProfile(@NonNull IProfile profile) { if (mAccountHeaderBuilder.mProfiles != null) { mAccountHeaderBuilder.mProfiles.remove(profile); } mAccountHeaderBuilder.updateHeaderAndList(); }
/** * remove a profile from the given position * * @param position */ public void removeProfile(int position) { if (mAccountHeaderBuilder.mProfiles != null && mAccountHeaderBuilder.mProfiles.size() > position) { mAccountHeaderBuilder.mProfiles.remove(position); } mAccountHeaderBuilder.updateHeaderAndList(); }
/** * Selects the given profile and sets it to the new active profile * * @param profile */ public void setActiveProfile(IProfile profile, boolean fireOnProfileChanged) { final boolean isCurrentSelectedProfile = mAccountHeaderBuilder.switchProfiles(profile); // if the selectionList is shown we should also update the current selected profile in the list if (mAccountHeaderBuilder.mDrawer != null && isSelectionListShown()) { mAccountHeaderBuilder.mDrawer.setSelection(profile.getIdentifier(), false); } // fire the event if enabled and a listener is set if (fireOnProfileChanged && mAccountHeaderBuilder.mOnAccountHeaderListener != null) { mAccountHeaderBuilder.mOnAccountHeaderListener.onProfileChanged( null, profile, isCurrentSelectedProfile); } }
/** * Helper method to update a profile using it's identifier * * @param newProfile */ @Deprecated public void updateProfileByIdentifier(@NonNull IProfile newProfile) { if (mAccountHeaderBuilder.mProfiles != null && newProfile.getIdentifier() >= 0) { int found = -1; for (int i = 0; i < mAccountHeaderBuilder.mProfiles.size(); i++) { if (mAccountHeaderBuilder.mProfiles.get(i) instanceof Identifyable) { if (mAccountHeaderBuilder.mProfiles.get(i).getIdentifier() == newProfile.getIdentifier()) { found = i; break; } } } if (found > -1) { mAccountHeaderBuilder.mProfiles.set(found, newProfile); mAccountHeaderBuilder.updateHeaderAndList(); } } }
/** * Toggle the selection list (show or hide it) * * @param ctx */ public void toggleSelectionList(Context ctx) { mAccountHeaderBuilder.toggleSelectionList(ctx); }
/** * Set the drawer for the AccountHeader so we can use it for the select * * @param drawer */ public void setDrawer(Drawer drawer) { mAccountHeaderBuilder.mDrawer = drawer; }
/** * Set a new list of profiles for the header * * @param profiles */ public void setProfiles(ArrayList<IProfile> profiles) { mAccountHeaderBuilder.mProfiles = IdDistributor.checkIds(profiles); mAccountHeaderBuilder.updateHeaderAndList(); }
/** * set this to define the second line in the selection area if there is no profile note this will * block any values from profiles! * * @param selectionSecondLine */ public void setSelectionSecondLine(String selectionSecondLine) { mAccountHeaderBuilder.mSelectionSecondLine = selectionSecondLine; mAccountHeaderBuilder.updateHeaderAndList(); }
/** * set this to false if you want to hide the second line of the selection box in the header * (second line would be the e-mail) * * @param selectionSecondLineShown */ public void setSelectionSecondLineShown(boolean selectionSecondLineShown) { mAccountHeaderBuilder.mSelectionSecondLineShown = selectionSecondLineShown; mAccountHeaderBuilder.updateHeaderAndList(); }