Skip to content

Commit bc253b9

Browse files
committed
Add loadTechnology and loadImage API's with caching
1 parent 31614dd commit bc253b9

File tree

1 file changed

+50
-0
lines changed
  • src/AndroidClient/techstacks/src/main/java/servicestack/net/techstacks

1 file changed

+50
-0
lines changed

src/AndroidClient/techstacks/src/main/java/servicestack/net/techstacks/App.java

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
package servicestack.net.techstacks;
22

3+
import android.graphics.Bitmap;
4+
35
import net.servicestack.android.AndroidServiceClient;
6+
import net.servicestack.android.AndroidUtils;
47
import net.servicestack.client.AsyncResult;
58
import net.servicestack.client.Utils;
69

710
import servicestack.net.techstacks.dto.*;
811

12+
import java.net.HttpURLConnection;
913
import java.util.ArrayList;
14+
import java.util.HashMap;
1015

1116
public class App {
1217

@@ -125,18 +130,63 @@ public void success(QueryResponse<Technology> response) {
125130
public QueryResponse<Technology> getSearchTechnologiesResponse() {
126131
return technologiesResponse;
127132
}
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+
}
128171
}
129172

130173
public static interface AppDataListener
131174
{
132175
public void onUpdate(AppData data, DataType dataType);
133176
}
134177

178+
public static class ImageResult
179+
{
180+
public void success(Bitmap img){}
181+
}
182+
135183
public static enum DataType
136184
{
137185
AppOverview,
138186
SearchTechStacks,
139187
SearchTechnologies,
188+
Technology,
189+
TechStack,
140190
}
141191

142192

0 commit comments

Comments
 (0)