|
1 | 1 | package servicestack.net.techstacks; |
2 | 2 |
|
| 3 | +import android.graphics.Bitmap; |
| 4 | + |
3 | 5 | import net.servicestack.android.AndroidServiceClient; |
| 6 | +import net.servicestack.android.AndroidUtils; |
4 | 7 | import net.servicestack.client.AsyncResult; |
5 | 8 | import net.servicestack.client.Utils; |
6 | 9 |
|
7 | 10 | import servicestack.net.techstacks.dto.*; |
8 | 11 |
|
| 12 | +import java.net.HttpURLConnection; |
9 | 13 | import java.util.ArrayList; |
| 14 | +import java.util.HashMap; |
10 | 15 |
|
11 | 16 | public class App { |
12 | 17 |
|
@@ -125,18 +130,63 @@ public void success(QueryResponse<Technology> response) { |
125 | 130 | public QueryResponse<Technology> getSearchTechnologiesResponse() { |
126 | 131 | return technologiesResponse; |
127 | 132 | } |
| 133 | + |
| 134 | + GetTechnologyResponse technology = null; |
| 135 | + public GetTechnologyResponse getTechnology() { |
| 136 | + return technology; |
| 137 | + } |
| 138 | + |
| 139 | + public void loadTechnology(String slug) { |
| 140 | + if (technology != null){ |
| 141 | + onUpdate(DataType.Technology); |
| 142 | + } |
| 143 | + |
| 144 | + client.getAsync(new GetTechnology().setSlug(slug), |
| 145 | + new AsyncResult<GetTechnologyResponse>() { |
| 146 | + @Override |
| 147 | + public void success(GetTechnologyResponse response) { |
| 148 | + technology = response; |
| 149 | + onUpdate(DataType.Technology); |
| 150 | + } |
| 151 | + }); |
| 152 | + } |
| 153 | + |
| 154 | + HashMap<String,Bitmap> imgCache = new HashMap<>(); |
| 155 | + public void loadImage(final String imgUrl, final ImageResult callback) { |
| 156 | + Bitmap img = imgCache.get(imgUrl); |
| 157 | + if (img != null){ |
| 158 | + callback.success(img); |
| 159 | + return; |
| 160 | + } |
| 161 | + |
| 162 | + client.getAsync(imgUrl, new AsyncResult<byte[]>() { |
| 163 | + @Override |
| 164 | + public void success(byte[] imgBytes) { |
| 165 | + Bitmap img = AndroidUtils.readBitmap(imgBytes); |
| 166 | + imgCache.put(imgUrl, img); |
| 167 | + callback.success(img); |
| 168 | + } |
| 169 | + }); |
| 170 | + } |
128 | 171 | } |
129 | 172 |
|
130 | 173 | public static interface AppDataListener |
131 | 174 | { |
132 | 175 | public void onUpdate(AppData data, DataType dataType); |
133 | 176 | } |
134 | 177 |
|
| 178 | + public static class ImageResult |
| 179 | + { |
| 180 | + public void success(Bitmap img){} |
| 181 | + } |
| 182 | + |
135 | 183 | public static enum DataType |
136 | 184 | { |
137 | 185 | AppOverview, |
138 | 186 | SearchTechStacks, |
139 | 187 | SearchTechnologies, |
| 188 | + Technology, |
| 189 | + TechStack, |
140 | 190 | } |
141 | 191 |
|
142 | 192 |
|
|
0 commit comments