mirror of
https://github.com/oxen-io/session-android.git
synced 2025-10-25 12:38:39 +00:00
Insert profile creation into registration flow, fix capture
// FREEBIE
This commit is contained in:
49
src/org/thoughtcrime/securesms/profiles/AvatarHelper.java
Normal file
49
src/org/thoughtcrime/securesms/profiles/AvatarHelper.java
Normal file
@@ -0,0 +1,49 @@
|
||||
package org.thoughtcrime.securesms.profiles;
|
||||
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import org.thoughtcrime.securesms.database.Address;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
public class AvatarHelper {
|
||||
|
||||
private static final String AVATAR_DIRECTORY = "avatars";
|
||||
|
||||
public static InputStream getInputStreamFor(@NonNull Context context, @NonNull Address address)
|
||||
throws IOException
|
||||
{
|
||||
return new FileInputStream(getAvatarFile(context, address));
|
||||
}
|
||||
|
||||
public static void delete(@NonNull Context context, @NonNull Address address) {
|
||||
getAvatarFile(context, address).delete();
|
||||
}
|
||||
|
||||
public static @NonNull File getAvatarFile(@NonNull Context context, @NonNull Address address) {
|
||||
File avatarDirectory = new File(context.getFilesDir(), AVATAR_DIRECTORY);
|
||||
avatarDirectory.mkdirs();
|
||||
|
||||
return new File(avatarDirectory, new File(address.serialize()).getName());
|
||||
}
|
||||
|
||||
public static void setAvatar(@NonNull Context context, @NonNull Address address, @Nullable byte[] data)
|
||||
throws IOException
|
||||
{
|
||||
if (data == null) {
|
||||
delete(context, address);
|
||||
} else {
|
||||
FileOutputStream out = new FileOutputStream(getAvatarFile(context, address));
|
||||
out.write(data);
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -28,10 +28,8 @@ public class AvatarPhotoUriFetcher implements DataFetcher<InputStream> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream loadData(Priority priority) throws FileNotFoundException {
|
||||
File avatarsDir = new File(context.getFilesDir(), "avatars");
|
||||
inputStream = new FileInputStream(new File(avatarsDir, address.serialize()));
|
||||
|
||||
public InputStream loadData(Priority priority) throws IOException {
|
||||
inputStream = AvatarHelper.getInputStreamFor(context, address);
|
||||
return inputStream;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user