Skip to content

Commit

Permalink
version 2.0.0-BETA-4
Browse files Browse the repository at this point in the history
- remove drawable from Profile and replace with int
- add dismissProfileChooser
  • Loading branch information
raphaelbussa committed Jan 24, 2017
1 parent 0ca5d85 commit c937db3
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 53 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ repositories {
```
```Gradle
dependencies {
compile 'rebus:header-view:2.0.0-BETA-3'
compile 'rebus:header-view:2.0.0-BETA-4'
}
```
### How to use
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/rebus/header/view/sample/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ public boolean onAdd() {
.build();
headerView.addProfile(newProfile);
headerView.setProfileActive(100);
return true;
headerView.dismissProfileChooser();
return false;
}

});
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ buildscript {
buildTools: "25.0.2",
minSdk : 11,
targetSdk : 25,
version : "2.0.0-BETA-3",
version : "2.0.0-BETA-4",
supportLib: "25.1.0"
]
}
Expand Down
45 changes: 30 additions & 15 deletions library/src/main/java/rebus/header/view/HeaderView.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,12 @@

public class HeaderView extends ViewGroup implements ProfileChooserCallback {

private static final String TAG = HeaderView.class.getName();
private static final String PROFILE_LIST = "PROFILE_LIST";

public static final int STYLE_NORMAL = 1;
public static final int STYLE_COMPACT = 2;
public static final int THEME_LIGHT = 1;
public static final int THEME_DARK = 2;

private static final String TAG = HeaderView.class.getName();
private static final String PROFILE_LIST = "PROFILE_LIST";
private int statusBarHeight;

private CircleImageView avatar;
Expand Down Expand Up @@ -110,6 +108,7 @@ public class HeaderView extends ViewGroup implements ProfileChooserCallback {

private HeaderCallback headerCallback;
private FragmentManager hvFragmentManager;
private ProfileChooser profileChooser;

public HeaderView(Context context) {
super(context);
Expand Down Expand Up @@ -375,6 +374,21 @@ public void setDialogTitle(String dialogTitle) {
hvDialogTitle = dialogTitle;
}

/**
* dismiss profile chooser dialog
*/
public void dismissProfileChooser() {
if (hvFragmentManager != null) {
ProfileChooserFragment profileChooserFragment = (ProfileChooserFragment) hvFragmentManager.findFragmentByTag(ProfileChooserFragment.FRAGMENT_TAG);
if (profileChooserFragment != null) {
profileChooserFragment.dismiss();
}
}
if (profileChooser != null && profileChooser.isShowing()) {
profileChooser.dismiss();
}
}

private void populateAvatar() {
int size = profileSparseArray.size();
Log.d(TAG, "profileSparseArray.size() [" + profileSparseArray.size() + "]");
Expand Down Expand Up @@ -414,10 +428,10 @@ private void setDefaultValues() {
private void setFirstProfile(Profile profile) {
username.setText(profile.getUsername());
email.setText(profile.getEmail());
if (profile.getAvatarDrawable() != null)
avatar.setImageDrawable(profile.getAvatarDrawable());
if (profile.getBackgroundDrawable() != null)
background.setImageDrawable(profile.getBackgroundDrawable());
if (profile.getAvatarRes() != 0)
avatar.setImageResource(profile.getAvatarRes());
if (profile.getBackgroundRes() != 0)
background.setImageResource(profile.getBackgroundRes());
if (profile.getAvatarUri() != null)
ImageLoader.loadImage(profile.getAvatarUri(), avatar, ImageLoader.AVATAR);
if (profile.getBackgroundUri() != null)
Expand All @@ -435,8 +449,8 @@ public void onClick(View v) {
}

private void setSecondProfile(Profile profile) {
if (profile.getAvatarDrawable() != null)
avatar2.setImageDrawable(profile.getAvatarDrawable());
if (profile.getAvatarRes() != 0)
avatar2.setImageResource(profile.getAvatarRes());
if (profile.getAvatarUri() != null)
ImageLoader.loadImage(profile.getAvatarUri(), avatar2, ImageLoader.AVATAR);
avatar2.setVisibility(VISIBLE);
Expand All @@ -451,8 +465,8 @@ public void onClick(View v) {
}

private void setThirdProfile(Profile profile) {
if (profile.getAvatarDrawable() != null)
avatar3.setImageDrawable(profile.getAvatarDrawable());
if (profile.getAvatarRes() != 0)
avatar3.setImageResource(profile.getAvatarRes());
if (profile.getAvatarUri() != null)
ImageLoader.loadImage(profile.getAvatarUri(), avatar3, ImageLoader.AVATAR);
avatar3.setVisibility(VISIBLE);
Expand Down Expand Up @@ -523,12 +537,13 @@ private void setupAttributeSet(AttributeSet attrs, int defStyle) {

if ((hvUsername != null && !hvUsername.isEmpty()) || (hvEmail != null && !hvEmail.isEmpty()) || hvAvatar != 0 || hvBackground != 0) {
Log.d(TAG, "profile created from XML");

Profile profile = new Profile.Builder()
.setId(1)
.setUsername(hvUsername)
.setEmail(hvEmail)
.setAvatar(Utils.getDrawable(getContext(), hvAvatar))
.setBackground(Utils.getDrawable(getContext(), hvBackground))
.setAvatar(hvAvatar)
.setBackground(hvBackground)
.build();

profileSparseArray.put(profile.getId(), profile);
Expand Down Expand Up @@ -613,7 +628,7 @@ public void onClick(View v) {
profileChooserFragment.setCallback(HeaderView.this);
profileChooserFragment.show(hvFragmentManager, ProfileChooserFragment.FRAGMENT_TAG);
} else {
ProfileChooser profileChooser = new ProfileChooser(getContext(), profileSparseArray, itemArrayList, hvHighlightColor, hvShowAddButton, hvDialogTitle, hvAddIconDrawable);
profileChooser = new ProfileChooser(getContext(), profileSparseArray, itemArrayList, hvHighlightColor, hvShowAddButton, hvDialogTitle, hvAddIconDrawable);
profileChooser.setCallback(HeaderView.this);
profileChooser.show();
}
Expand Down
4 changes: 2 additions & 2 deletions library/src/main/java/rebus/header/view/ImageLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ private void setImageLoaderInterface(ImageLoaderInterface imageLoaderInterface)

public interface ImageLoaderInterface {
/**
* @param url uri of image
* @param url uri of image
* @param imageView reference of ImageView
* @param type type of image to load AVATAR or HEADER
* @param type type of image to load AVATAR or HEADER
*/
void loadImage(Uri url, ImageView imageView, @Type int type);
}
Expand Down
58 changes: 29 additions & 29 deletions library/src/main/java/rebus/header/view/Profile.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@

package rebus.header.view;

import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.DrawableRes;
import android.support.annotation.IntRange;
import android.support.annotation.NonNull;
import android.support.annotation.RestrictTo;
Expand Down Expand Up @@ -58,28 +58,28 @@ public Profile[] newArray(int size) {
@IdValue
private int id;
private Uri avatarUri;
private Drawable avatarDrawable;
private int avatarRes;
private Uri backgroundUri;
private Drawable backgroundDrawable;
private int backgroundRes;
private Spanned username;
private Spanned email;

private Profile(int id, Uri avatarUri, Drawable avatarDrawable, Uri backgroundUri, Drawable backgroundDrawable, Spanned username, Spanned email) {
private Profile(int id, Uri avatarUri, int avatarRes, Uri backgroundUri, int backgroundRes, Spanned username, Spanned email) {
this.id = id;
this.avatarUri = avatarUri;
this.avatarDrawable = avatarDrawable;
this.avatarRes = avatarRes;
this.backgroundUri = backgroundUri;
this.backgroundDrawable = backgroundDrawable;
this.backgroundRes = backgroundRes;
this.username = username;
this.email = email;
}

private Profile(Parcel in) {
id = in.readInt();
avatarUri = (Uri) in.readValue(Uri.class.getClassLoader());
avatarDrawable = (Drawable) in.readValue(Drawable.class.getClassLoader());
avatarRes = in.readInt();
backgroundUri = (Uri) in.readValue(Uri.class.getClassLoader());
backgroundDrawable = (Drawable) in.readValue(Drawable.class.getClassLoader());
backgroundRes = in.readInt();
username = (Spanned) in.readValue(Spanned.class.getClassLoader());
email = (Spanned) in.readValue(Spanned.class.getClassLoader());
}
Expand All @@ -92,16 +92,16 @@ Uri getAvatarUri() {
return avatarUri;
}

Drawable getAvatarDrawable() {
return avatarDrawable;
int getAvatarRes() {
return avatarRes;
}

Uri getBackgroundUri() {
return backgroundUri;
}

Drawable getBackgroundDrawable() {
return backgroundDrawable;
int getBackgroundRes() {
return backgroundRes;
}

Spanned getUsername() {
Expand All @@ -117,9 +117,9 @@ public String toString() {
return "Profile{" +
"id=" + id +
", avatarUri=" + avatarUri +
", avatarDrawable=" + avatarDrawable +
", avatarRes=" + avatarRes +
", backgroundUri=" + backgroundUri +
", backgroundDrawable=" + backgroundDrawable +
", backgroundRes=" + backgroundRes +
", username=" + username +
", email=" + email +
'}';
Expand All @@ -134,9 +134,9 @@ public int describeContents() {
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(id);
dest.writeValue(avatarUri);
dest.writeValue(avatarDrawable);
dest.writeValue(avatarRes);
dest.writeValue(backgroundUri);
dest.writeValue(backgroundDrawable);
dest.writeValue(backgroundRes);
dest.writeValue(username);
dest.writeValue(email);
}
Expand All @@ -152,9 +152,9 @@ public static class Builder {
@IdValue
private int id;
private Uri avatarUri;
private Drawable avatarDrawable;
private int avatarRes;
private Uri backgroundUri;
private Drawable backgroundDrawable;
private int backgroundRes;
private Spanned username;
private Spanned email;

Expand All @@ -176,7 +176,7 @@ public Builder setId(@IdValue int id) {
*/
public Builder setAvatar(@NonNull Uri avatar) {
this.avatarUri = avatar;
this.avatarDrawable = null;
this.avatarRes = 0;
return this;
}

Expand All @@ -186,16 +186,16 @@ public Builder setAvatar(@NonNull Uri avatar) {
*/
public Builder setAvatar(@NonNull String avatar) {
this.avatarUri = Uri.parse(avatar);
this.avatarDrawable = null;
this.avatarRes = 0;
return this;
}

/**
* @param avatar set avatar drawable
* @param avatar set avatar drawable res
* @return current builder instance
*/
public Builder setAvatar(Drawable avatar) {
this.avatarDrawable = avatar;
public Builder setAvatar(@DrawableRes int avatar) {
this.avatarRes = avatar;
this.avatarUri = null;
return this;
}
Expand All @@ -206,7 +206,7 @@ public Builder setAvatar(Drawable avatar) {
*/
public Builder setBackground(@NonNull Uri background) {
this.backgroundUri = background;
this.backgroundDrawable = null;
this.backgroundRes = 0;
return this;
}

Expand All @@ -216,16 +216,16 @@ public Builder setBackground(@NonNull Uri background) {
*/
public Builder setBackground(@NonNull String background) {
this.backgroundUri = Uri.parse(background);
this.backgroundDrawable = null;
this.backgroundRes = 0;
return this;
}

/**
* @param background set background drawable
* @param background set background drawable res
* @return current builder instance
*/
public Builder setBackground(Drawable background) {
this.backgroundDrawable = background;
public Builder setBackground(@DrawableRes int background) {
this.backgroundRes = background;
this.backgroundUri = null;
return this;
}
Expand Down Expand Up @@ -270,7 +270,7 @@ public Builder setEmail(String email) {
* @return build Profile and return it
*/
public Profile build() {
return new Profile(id, avatarUri, avatarDrawable, backgroundUri, backgroundDrawable, username, email);
return new Profile(id, avatarUri, avatarRes, backgroundUri, backgroundRes, username, email);
}

}
Expand Down
4 changes: 2 additions & 2 deletions library/src/main/java/rebus/header/view/RowProfileView.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ public void setProfile(Profile profile, boolean active) {
email.setTypeface(active ? Typeface.DEFAULT_BOLD : Typeface.DEFAULT);
username.setText(hvProfile.getUsername());
email.setText(hvProfile.getEmail());
if (hvProfile.getAvatarDrawable() != null)
avatar.setImageDrawable(hvProfile.getAvatarDrawable());
if (hvProfile.getAvatarRes() != 0)
avatar.setImageResource(hvProfile.getAvatarRes());
if (hvProfile.getAvatarUri() != null)
ImageLoader.loadImage(hvProfile.getAvatarUri(), avatar, ImageLoader.AVATAR);
}
Expand Down
2 changes: 0 additions & 2 deletions library/src/main/java/rebus/header/view/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
import android.text.Spanned;
import android.util.TypedValue;

import java.util.Locale;

/**
* Created by raphaelbussa on 13/01/17.
*/
Expand Down

0 comments on commit c937db3

Please sign in to comment.