Set file size also for cached avatars
This commit is contained in:
parent
4aab45533a
commit
52af62d298
|
@ -318,11 +318,12 @@ public class FileBackend {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean save(Avatar avatar) {
|
public boolean save(Avatar avatar) {
|
||||||
|
File file;
|
||||||
if (isAvatarCached(avatar)) {
|
if (isAvatarCached(avatar)) {
|
||||||
return true;
|
file = new File(getAvatarPath(avatar.getFilename()));
|
||||||
}
|
} else {
|
||||||
String filename = getAvatarPath(avatar.getFilename());
|
String filename = getAvatarPath(avatar.getFilename());
|
||||||
File file = new File(filename + ".tmp");
|
file = new File(filename + ".tmp");
|
||||||
file.getParentFile().mkdirs();
|
file.getParentFile().mkdirs();
|
||||||
try {
|
try {
|
||||||
file.createNewFile();
|
file.createNewFile();
|
||||||
|
@ -334,11 +335,9 @@ public class FileBackend {
|
||||||
mDigestOutputStream.write(avatar.getImageAsBytes());
|
mDigestOutputStream.write(avatar.getImageAsBytes());
|
||||||
mDigestOutputStream.flush();
|
mDigestOutputStream.flush();
|
||||||
mDigestOutputStream.close();
|
mDigestOutputStream.close();
|
||||||
avatar.size = file.length();
|
|
||||||
String sha1sum = CryptoHelper.bytesToHex(digest.digest());
|
String sha1sum = CryptoHelper.bytesToHex(digest.digest());
|
||||||
if (sha1sum.equals(avatar.sha1sum)) {
|
if (sha1sum.equals(avatar.sha1sum)) {
|
||||||
file.renameTo(new File(filename));
|
file.renameTo(new File(filename));
|
||||||
return true;
|
|
||||||
} else {
|
} else {
|
||||||
Log.d(Config.LOGTAG, "sha1sum mismatch for " + avatar.owner);
|
Log.d(Config.LOGTAG, "sha1sum mismatch for " + avatar.owner);
|
||||||
file.delete();
|
file.delete();
|
||||||
|
@ -352,6 +351,9 @@ public class FileBackend {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
avatar.size = file.length();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public String getAvatarPath(String avatar) {
|
public String getAvatarPath(String avatar) {
|
||||||
return mXmppConnectionService.getFilesDir().getAbsolutePath()
|
return mXmppConnectionService.getFilesDir().getAbsolutePath()
|
||||||
|
|
Loading…
Reference in New Issue