|
29 | 29 | import java.util.ArrayList;
|
30 | 30 | import java.util.Arrays;
|
31 | 31 | import java.util.HashMap;
|
| 32 | +import java.util.Objects; |
32 | 33 | import java.util.concurrent.TimeUnit;
|
33 | 34 |
|
34 | 35 | import cz.vutbr.web.css.CSSFactory;
|
@@ -300,34 +301,35 @@ public String getPluginName() {
|
300 | 301 | return "Custom View";
|
301 | 302 | }
|
302 | 303 |
|
303 |
| - public class DrawableCache { |
304 |
| - private LoadingCache<String, Drawable> drawableCache; |
| 304 | + public static class DrawableCache { |
| 305 | + private final LoadingCache<String, Drawable> drawableCache; |
305 | 306 |
|
306 | 307 | public DrawableCache() {
|
307 | 308 | drawableCache = CacheBuilder.newBuilder()
|
308 | 309 | .maximumSize(100)
|
309 | 310 | .expireAfterWrite(30, TimeUnit.MINUTES)
|
310 | 311 | .build(new CacheLoader<>() {
|
| 312 | + @NonNull |
311 | 313 | @Override
|
312 |
| - public Drawable load(String key) throws Exception { |
313 |
| - return loadDrawableFromFile(key); |
| 314 | + public Drawable load(@NonNull String key) throws Exception { |
| 315 | + return Objects.requireNonNull(loadDrawableFromFile(key)); |
314 | 316 | }
|
315 | 317 | });
|
316 | 318 | }
|
317 | 319 |
|
318 | 320 | private Drawable loadDrawableFromFile(String filePath) {
|
319 | 321 | File file = new File(filePath);
|
320 |
| - if (!file.exists()) return null; |
| 322 | + if (!file.exists()) return new ColorDrawable(0); |
321 | 323 | return Drawable.createFromPath(file.getAbsolutePath());
|
322 | 324 | }
|
323 | 325 |
|
324 | 326 | public Drawable getDrawable(String key) {
|
325 | 327 | return drawableCache.getUnchecked(key);
|
326 | 328 | }
|
327 | 329 |
|
328 |
| - public void invalidateCache() { |
329 |
| - drawableCache.invalidateAll(); |
330 |
| - } |
| 330 | +// public void invalidateCache() { |
| 331 | +// drawableCache.invalidateAll(); |
| 332 | +// } |
331 | 333 | }
|
332 | 334 |
|
333 | 335 | }
|
0 commit comments