2424
2525package rebus .header .view ;
2626
27- import android .graphics .drawable .Drawable ;
2827import android .net .Uri ;
2928import android .os .Parcel ;
3029import android .os .Parcelable ;
30+ import android .support .annotation .DrawableRes ;
3131import android .support .annotation .IntRange ;
3232import android .support .annotation .NonNull ;
3333import 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 }
0 commit comments