Skip to content

Instantly share code, notes, and snippets.

@waninkoko
Created May 22, 2015 16:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save waninkoko/4909ce286ee9c3671efd to your computer and use it in GitHub Desktop.
Save waninkoko/4909ce286ee9c3671efd to your computer and use it in GitHub Desktop.
diff --git a/library/src/main/java/com/mikepenz/materialdrawer/accountswitcher/AccountHeader.java b/library/src/main/java/com/mikepenz/materialdrawer/accountswitcher/AccountHeader.java
index 41afac8..b9a9267 100644
--- a/library/src/main/java/com/mikepenz/materialdrawer/accountswitcher/AccountHeader.java
+++ b/library/src/main/java/com/mikepenz/materialdrawer/accountswitcher/AccountHeader.java
@@ -1189,14 +1189,14 @@ public class AccountHeader {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
+ if (mDrawer != null && view.getContext() != null) {
+ resetDrawerContent(view.getContext());
+ }
if (drawerItem != null && drawerItem instanceof IProfile) {
if (mOnAccountHeaderListener != null) {
mOnAccountHeaderListener.onProfileChanged(view, (IProfile) drawerItem, isCurrentSelectedProfile);
}
}
- if (mDrawer != null && view.getContext() != null) {
- resetDrawerContent(view.getContext());
- }
}
}, 350);
@@ -1313,27 +1313,50 @@ public class AccountHeader {
mAccountHeader.mProfiles = profiles;
mAccountHeader.updateHeaderAndList();
}
-
- /**
+
+ /**
* Selects the given profile and sets it to the new active profile
*
* @param profile
*/
public void setActiveProfile(IProfile profile) {
- mAccountHeader.switchProfiles(profile);
- }
+ setActiveProfile(profile, false);
+ }
/**
+ * Selects the given profile and sets it to the new active profile
+ *
+ * @param profile
+ * @param fireOnProfileChanged
+ */
+ public void setActiveProfile(IProfile profile, boolean fireOnProfileChanged) {
+ final boolean isCurrentSelectedProfile = mAccountHeader.switchProfiles(profile);
+ if (fireOnProfileChanged && mAccountHeader.mOnAccountHeaderListener != null) {
+ mAccountHeader.mOnAccountHeaderListener.onProfileChanged(null, profile, isCurrentSelectedProfile);
+ }
+ }
+
+ /**
* Selects a profile by its identifier
*
* @param identifier
*/
public void setActiveProfile(int identifier) {
+ setActiveProfile(identifier, false);
+ }
+
+ /**
+ * Selects a profile by its identifier
+ *
+ * @param identifier
+ * @param fireOnProfileChanged
+ */
+ public void setActiveProfile(int identifier, boolean fireOnProfileChanged) {
if (mAccountHeader.mProfiles != null) {
for (IProfile profile : mAccountHeader.mProfiles) {
if (profile instanceof Identifyable) {
if (profile.getIdentifier() == identifier) {
- mAccountHeader.switchProfiles(profile);
+ setActiveProfile(profile, fireOnProfileChanged);
return;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment