Skip to content

Commit c937db3

Browse files
committed
version 2.0.0-BETA-4
- remove drawable from Profile and replace with int - add dismissProfileChooser
1 parent 0ca5d85 commit c937db3

File tree

8 files changed

+67
-53
lines changed

8 files changed

+67
-53
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ repositories {
1818
```
1919
```Gradle
2020
dependencies {
21-
compile 'rebus:header-view:2.0.0-BETA-3'
21+
compile 'rebus:header-view:2.0.0-BETA-4'
2222
}
2323
```
2424
### How to use

app/src/main/java/rebus/header/view/sample/MainActivity.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ public boolean onAdd() {
164164
.build();
165165
headerView.addProfile(newProfile);
166166
headerView.setProfileActive(100);
167-
return true;
167+
headerView.dismissProfileChooser();
168+
return false;
168169
}
169170

170171
});

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ buildscript {
3030
buildTools: "25.0.2",
3131
minSdk : 11,
3232
targetSdk : 25,
33-
version : "2.0.0-BETA-3",
33+
version : "2.0.0-BETA-4",
3434
supportLib: "25.1.0"
3535
]
3636
}

library/src/main/java/rebus/header/view/HeaderView.java

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,12 @@
6464

6565
public class HeaderView extends ViewGroup implements ProfileChooserCallback {
6666

67-
private static final String TAG = HeaderView.class.getName();
68-
private static final String PROFILE_LIST = "PROFILE_LIST";
69-
7067
public static final int STYLE_NORMAL = 1;
7168
public static final int STYLE_COMPACT = 2;
7269
public static final int THEME_LIGHT = 1;
7370
public static final int THEME_DARK = 2;
74-
71+
private static final String TAG = HeaderView.class.getName();
72+
private static final String PROFILE_LIST = "PROFILE_LIST";
7573
private int statusBarHeight;
7674

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

111109
private HeaderCallback headerCallback;
112110
private FragmentManager hvFragmentManager;
111+
private ProfileChooser profileChooser;
113112

114113
public HeaderView(Context context) {
115114
super(context);
@@ -375,6 +374,21 @@ public void setDialogTitle(String dialogTitle) {
375374
hvDialogTitle = dialogTitle;
376375
}
377376

377+
/**
378+
* dismiss profile chooser dialog
379+
*/
380+
public void dismissProfileChooser() {
381+
if (hvFragmentManager != null) {
382+
ProfileChooserFragment profileChooserFragment = (ProfileChooserFragment) hvFragmentManager.findFragmentByTag(ProfileChooserFragment.FRAGMENT_TAG);
383+
if (profileChooserFragment != null) {
384+
profileChooserFragment.dismiss();
385+
}
386+
}
387+
if (profileChooser != null && profileChooser.isShowing()) {
388+
profileChooser.dismiss();
389+
}
390+
}
391+
378392
private void populateAvatar() {
379393
int size = profileSparseArray.size();
380394
Log.d(TAG, "profileSparseArray.size() [" + profileSparseArray.size() + "]");
@@ -414,10 +428,10 @@ private void setDefaultValues() {
414428
private void setFirstProfile(Profile profile) {
415429
username.setText(profile.getUsername());
416430
email.setText(profile.getEmail());
417-
if (profile.getAvatarDrawable() != null)
418-
avatar.setImageDrawable(profile.getAvatarDrawable());
419-
if (profile.getBackgroundDrawable() != null)
420-
background.setImageDrawable(profile.getBackgroundDrawable());
431+
if (profile.getAvatarRes() != 0)
432+
avatar.setImageResource(profile.getAvatarRes());
433+
if (profile.getBackgroundRes() != 0)
434+
background.setImageResource(profile.getBackgroundRes());
421435
if (profile.getAvatarUri() != null)
422436
ImageLoader.loadImage(profile.getAvatarUri(), avatar, ImageLoader.AVATAR);
423437
if (profile.getBackgroundUri() != null)
@@ -435,8 +449,8 @@ public void onClick(View v) {
435449
}
436450

437451
private void setSecondProfile(Profile profile) {
438-
if (profile.getAvatarDrawable() != null)
439-
avatar2.setImageDrawable(profile.getAvatarDrawable());
452+
if (profile.getAvatarRes() != 0)
453+
avatar2.setImageResource(profile.getAvatarRes());
440454
if (profile.getAvatarUri() != null)
441455
ImageLoader.loadImage(profile.getAvatarUri(), avatar2, ImageLoader.AVATAR);
442456
avatar2.setVisibility(VISIBLE);
@@ -451,8 +465,8 @@ public void onClick(View v) {
451465
}
452466

453467
private void setThirdProfile(Profile profile) {
454-
if (profile.getAvatarDrawable() != null)
455-
avatar3.setImageDrawable(profile.getAvatarDrawable());
468+
if (profile.getAvatarRes() != 0)
469+
avatar3.setImageResource(profile.getAvatarRes());
456470
if (profile.getAvatarUri() != null)
457471
ImageLoader.loadImage(profile.getAvatarUri(), avatar3, ImageLoader.AVATAR);
458472
avatar3.setVisibility(VISIBLE);
@@ -523,12 +537,13 @@ private void setupAttributeSet(AttributeSet attrs, int defStyle) {
523537

524538
if ((hvUsername != null && !hvUsername.isEmpty()) || (hvEmail != null && !hvEmail.isEmpty()) || hvAvatar != 0 || hvBackground != 0) {
525539
Log.d(TAG, "profile created from XML");
540+
526541
Profile profile = new Profile.Builder()
527542
.setId(1)
528543
.setUsername(hvUsername)
529544
.setEmail(hvEmail)
530-
.setAvatar(Utils.getDrawable(getContext(), hvAvatar))
531-
.setBackground(Utils.getDrawable(getContext(), hvBackground))
545+
.setAvatar(hvAvatar)
546+
.setBackground(hvBackground)
532547
.build();
533548

534549
profileSparseArray.put(profile.getId(), profile);
@@ -613,7 +628,7 @@ public void onClick(View v) {
613628
profileChooserFragment.setCallback(HeaderView.this);
614629
profileChooserFragment.show(hvFragmentManager, ProfileChooserFragment.FRAGMENT_TAG);
615630
} else {
616-
ProfileChooser profileChooser = new ProfileChooser(getContext(), profileSparseArray, itemArrayList, hvHighlightColor, hvShowAddButton, hvDialogTitle, hvAddIconDrawable);
631+
profileChooser = new ProfileChooser(getContext(), profileSparseArray, itemArrayList, hvHighlightColor, hvShowAddButton, hvDialogTitle, hvAddIconDrawable);
617632
profileChooser.setCallback(HeaderView.this);
618633
profileChooser.show();
619634
}

library/src/main/java/rebus/header/view/ImageLoader.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ private void setImageLoaderInterface(ImageLoaderInterface imageLoaderInterface)
7070

7171
public interface ImageLoaderInterface {
7272
/**
73-
* @param url uri of image
73+
* @param url uri of image
7474
* @param imageView reference of ImageView
75-
* @param type type of image to load AVATAR or HEADER
75+
* @param type type of image to load AVATAR or HEADER
7676
*/
7777
void loadImage(Uri url, ImageView imageView, @Type int type);
7878
}

library/src/main/java/rebus/header/view/Profile.java

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424

2525
package rebus.header.view;
2626

27-
import android.graphics.drawable.Drawable;
2827
import android.net.Uri;
2928
import android.os.Parcel;
3029
import android.os.Parcelable;
30+
import android.support.annotation.DrawableRes;
3131
import android.support.annotation.IntRange;
3232
import android.support.annotation.NonNull;
3333
import android.support.annotation.RestrictTo;
@@ -58,28 +58,28 @@ public Profile[] newArray(int size) {
5858
@IdValue
5959
private int id;
6060
private Uri avatarUri;
61-
private Drawable avatarDrawable;
61+
private int avatarRes;
6262
private Uri backgroundUri;
63-
private Drawable backgroundDrawable;
63+
private int backgroundRes;
6464
private Spanned username;
6565
private Spanned email;
6666

67-
private Profile(int id, Uri avatarUri, Drawable avatarDrawable, Uri backgroundUri, Drawable backgroundDrawable, Spanned username, Spanned email) {
67+
private Profile(int id, Uri avatarUri, int avatarRes, Uri backgroundUri, int backgroundRes, Spanned username, Spanned email) {
6868
this.id = id;
6969
this.avatarUri = avatarUri;
70-
this.avatarDrawable = avatarDrawable;
70+
this.avatarRes = avatarRes;
7171
this.backgroundUri = backgroundUri;
72-
this.backgroundDrawable = backgroundDrawable;
72+
this.backgroundRes = backgroundRes;
7373
this.username = username;
7474
this.email = email;
7575
}
7676

7777
private Profile(Parcel in) {
7878
id = in.readInt();
7979
avatarUri = (Uri) in.readValue(Uri.class.getClassLoader());
80-
avatarDrawable = (Drawable) in.readValue(Drawable.class.getClassLoader());
80+
avatarRes = in.readInt();
8181
backgroundUri = (Uri) in.readValue(Uri.class.getClassLoader());
82-
backgroundDrawable = (Drawable) in.readValue(Drawable.class.getClassLoader());
82+
backgroundRes = in.readInt();
8383
username = (Spanned) in.readValue(Spanned.class.getClassLoader());
8484
email = (Spanned) in.readValue(Spanned.class.getClassLoader());
8585
}
@@ -92,16 +92,16 @@ Uri getAvatarUri() {
9292
return avatarUri;
9393
}
9494

95-
Drawable getAvatarDrawable() {
96-
return avatarDrawable;
95+
int getAvatarRes() {
96+
return avatarRes;
9797
}
9898

9999
Uri getBackgroundUri() {
100100
return backgroundUri;
101101
}
102102

103-
Drawable getBackgroundDrawable() {
104-
return backgroundDrawable;
103+
int getBackgroundRes() {
104+
return backgroundRes;
105105
}
106106

107107
Spanned getUsername() {
@@ -117,9 +117,9 @@ public String toString() {
117117
return "Profile{" +
118118
"id=" + id +
119119
", avatarUri=" + avatarUri +
120-
", avatarDrawable=" + avatarDrawable +
120+
", avatarRes=" + avatarRes +
121121
", backgroundUri=" + backgroundUri +
122-
", backgroundDrawable=" + backgroundDrawable +
122+
", backgroundRes=" + backgroundRes +
123123
", username=" + username +
124124
", email=" + email +
125125
'}';
@@ -134,9 +134,9 @@ public int describeContents() {
134134
public void writeToParcel(Parcel dest, int flags) {
135135
dest.writeInt(id);
136136
dest.writeValue(avatarUri);
137-
dest.writeValue(avatarDrawable);
137+
dest.writeValue(avatarRes);
138138
dest.writeValue(backgroundUri);
139-
dest.writeValue(backgroundDrawable);
139+
dest.writeValue(backgroundRes);
140140
dest.writeValue(username);
141141
dest.writeValue(email);
142142
}
@@ -152,9 +152,9 @@ public static class Builder {
152152
@IdValue
153153
private int id;
154154
private Uri avatarUri;
155-
private Drawable avatarDrawable;
155+
private int avatarRes;
156156
private Uri backgroundUri;
157-
private Drawable backgroundDrawable;
157+
private int backgroundRes;
158158
private Spanned username;
159159
private Spanned email;
160160

@@ -176,7 +176,7 @@ public Builder setId(@IdValue int id) {
176176
*/
177177
public Builder setAvatar(@NonNull Uri avatar) {
178178
this.avatarUri = avatar;
179-
this.avatarDrawable = null;
179+
this.avatarRes = 0;
180180
return this;
181181
}
182182

@@ -186,16 +186,16 @@ public Builder setAvatar(@NonNull Uri avatar) {
186186
*/
187187
public Builder setAvatar(@NonNull String avatar) {
188188
this.avatarUri = Uri.parse(avatar);
189-
this.avatarDrawable = null;
189+
this.avatarRes = 0;
190190
return this;
191191
}
192192

193193
/**
194-
* @param avatar set avatar drawable
194+
* @param avatar set avatar drawable res
195195
* @return current builder instance
196196
*/
197-
public Builder setAvatar(Drawable avatar) {
198-
this.avatarDrawable = avatar;
197+
public Builder setAvatar(@DrawableRes int avatar) {
198+
this.avatarRes = avatar;
199199
this.avatarUri = null;
200200
return this;
201201
}
@@ -206,7 +206,7 @@ public Builder setAvatar(Drawable avatar) {
206206
*/
207207
public Builder setBackground(@NonNull Uri background) {
208208
this.backgroundUri = background;
209-
this.backgroundDrawable = null;
209+
this.backgroundRes = 0;
210210
return this;
211211
}
212212

@@ -216,16 +216,16 @@ public Builder setBackground(@NonNull Uri background) {
216216
*/
217217
public Builder setBackground(@NonNull String background) {
218218
this.backgroundUri = Uri.parse(background);
219-
this.backgroundDrawable = null;
219+
this.backgroundRes = 0;
220220
return this;
221221
}
222222

223223
/**
224-
* @param background set background drawable
224+
* @param background set background drawable res
225225
* @return current builder instance
226226
*/
227-
public Builder setBackground(Drawable background) {
228-
this.backgroundDrawable = background;
227+
public Builder setBackground(@DrawableRes int background) {
228+
this.backgroundRes = background;
229229
this.backgroundUri = null;
230230
return this;
231231
}
@@ -270,7 +270,7 @@ public Builder setEmail(String email) {
270270
* @return build Profile and return it
271271
*/
272272
public Profile build() {
273-
return new Profile(id, avatarUri, avatarDrawable, backgroundUri, backgroundDrawable, username, email);
273+
return new Profile(id, avatarUri, avatarRes, backgroundUri, backgroundRes, username, email);
274274
}
275275

276276
}

library/src/main/java/rebus/header/view/RowProfileView.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ public void setProfile(Profile profile, boolean active) {
112112
email.setTypeface(active ? Typeface.DEFAULT_BOLD : Typeface.DEFAULT);
113113
username.setText(hvProfile.getUsername());
114114
email.setText(hvProfile.getEmail());
115-
if (hvProfile.getAvatarDrawable() != null)
116-
avatar.setImageDrawable(hvProfile.getAvatarDrawable());
115+
if (hvProfile.getAvatarRes() != 0)
116+
avatar.setImageResource(hvProfile.getAvatarRes());
117117
if (hvProfile.getAvatarUri() != null)
118118
ImageLoader.loadImage(hvProfile.getAvatarUri(), avatar, ImageLoader.AVATAR);
119119
}

library/src/main/java/rebus/header/view/Utils.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@
3434
import android.text.Spanned;
3535
import android.util.TypedValue;
3636

37-
import java.util.Locale;
38-
3937
/**
4038
* Created by raphaelbussa on 13/01/17.
4139
*/

0 commit comments

Comments
 (0)