1
1
package org .fossasia .openevent .core .about ;
2
2
3
3
import android .arch .lifecycle .LiveData ;
4
+ import android .arch .lifecycle .MutableLiveData ;
4
5
import android .arch .lifecycle .Transformations ;
5
6
import android .arch .lifecycle .ViewModel ;
7
+ import android .graphics .Bitmap ;
8
+ import android .graphics .drawable .Drawable ;
6
9
10
+ import com .squareup .picasso .Picasso ;
11
+ import com .squareup .picasso .RequestCreator ;
12
+ import com .squareup .picasso .Target ;
13
+
14
+ import org .fossasia .openevent .OpenEventApp ;
7
15
import org .fossasia .openevent .common .arch .LiveRealmData ;
8
16
import org .fossasia .openevent .common .date .DateConverter ;
9
17
import org .fossasia .openevent .data .Event ;
@@ -25,6 +33,7 @@ public class AboutFragmentViewModel extends ViewModel {
25
33
private List <String > dateList ;
26
34
private LiveData <Event > eventLiveData ;
27
35
private LiveData <List <Speaker >> featuredSpeakers ;
36
+ private MutableLiveData <Bitmap > eventLogo ;
28
37
29
38
public AboutFragmentViewModel () {
30
39
realmRepo = RealmDataRepository .getDefaultInstance ();
@@ -86,4 +95,29 @@ public LiveData<List<Speaker>> getFeaturedSpeakers() {
86
95
}
87
96
return featuredSpeakers ;
88
97
}
98
+
99
+ public LiveData <Bitmap > getEventLogo (String url ) {
100
+ if (eventLogo == null ) {
101
+ eventLogo = new MutableLiveData <>();
102
+ RequestCreator requestCreator = OpenEventApp .picassoWithCache .load (url );
103
+ final Target target = new Target () {
104
+ @ Override
105
+ public void onBitmapLoaded (Bitmap bitmap , Picasso .LoadedFrom from ) {
106
+ eventLogo .setValue (bitmap );
107
+ }
108
+
109
+ @ Override
110
+ public void onBitmapFailed (Drawable errorDrawable ) {
111
+ //no implementation
112
+ }
113
+
114
+ @ Override
115
+ public void onPrepareLoad (Drawable placeHolderDrawable ) {
116
+ //no implementation
117
+ }
118
+ };
119
+ requestCreator .into (target );
120
+ }
121
+ return eventLogo ;
122
+ }
89
123
}
0 commit comments