Skip to content

Commit

Permalink
Ensure old cached folder is always deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinsawicki committed Aug 20, 2013
1 parent 12d9242 commit 498c32b
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions app/src/main/java/com/github/mobile/util/AvatarLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,11 @@ private BitmapDrawable getImageBy(final String userId, final String filename) {
}
}

private void deleteCachedUserAvatars(File userAvatarDir) {
if (!userAvatarDir.isDirectory())
return;

for (File userAvatar : userAvatarDir.listFiles())
userAvatar.delete();
private void deleteCachedUserAvatars(final File userAvatarDir) {
if (userAvatarDir.isDirectory())
for (File userAvatar : userAvatarDir.listFiles())
userAvatar.delete();
userAvatarDir.delete();
}

private Bitmap decode(final File file) {
Expand All @@ -165,12 +164,8 @@ private String getAvatarFilenameForUrl(final String avatarUrl) {
protected BitmapDrawable fetchAvatar(final String url,
final String userId, final String cachedAvatarFilename) {
File userAvatarDir = new File(avatarDir, userId);
if (userAvatarDir.isDirectory())
deleteCachedUserAvatars(userAvatarDir);
else {
userAvatarDir.delete();
userAvatarDir.mkdirs();
}
deleteCachedUserAvatars(userAvatarDir);
userAvatarDir.mkdirs();

File rawAvatar = new File(userAvatarDir, cachedAvatarFilename + "-raw");
HttpRequest request = HttpRequest.get(url);
Expand Down

0 comments on commit 498c32b

Please sign in to comment.