mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-23 16:19:54 +01:00
Compare commits
8 Commits
1242-displ
...
1483-only-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
115675d7b6 | ||
|
|
0089c1ac6d | ||
|
|
a37b6d81ed | ||
|
|
1d09a6708a | ||
|
|
d3b6f484c8 | ||
|
|
039c6edb66 | ||
|
|
8b9f89eab2 | ||
|
|
1e2c17b170 |
@@ -6,6 +6,8 @@ import android.support.annotation.Nullable;
|
|||||||
import android.support.media.ExifInterface;
|
import android.support.media.ExifInterface;
|
||||||
import android.webkit.MimeTypeMap;
|
import android.webkit.MimeTypeMap;
|
||||||
|
|
||||||
|
import com.bumptech.glide.util.MarkEnforcingInputStream;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.Pair;
|
import org.briarproject.bramble.api.Pair;
|
||||||
import org.briarproject.bramble.api.db.DatabaseExecutor;
|
import org.briarproject.bramble.api.db.DatabaseExecutor;
|
||||||
import org.briarproject.bramble.api.db.DbException;
|
import org.briarproject.bramble.api.db.DbException;
|
||||||
@@ -44,6 +46,7 @@ class AttachmentController {
|
|||||||
|
|
||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
getLogger(AttachmentController.class.getName());
|
getLogger(AttachmentController.class.getName());
|
||||||
|
private static final int READ_LIMIT = 1024 * 8192;
|
||||||
|
|
||||||
private final MessagingManager messagingManager;
|
private final MessagingManager messagingManager;
|
||||||
private final int defaultSize;
|
private final int defaultSize;
|
||||||
@@ -128,8 +131,9 @@ class AttachmentController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Size size = new Size();
|
Size size = new Size();
|
||||||
InputStream is = new BufferedInputStream(a.getStream());
|
InputStream is = new MarkEnforcingInputStream(
|
||||||
is.mark(Integer.MAX_VALUE);
|
new BufferedInputStream(a.getStream()));
|
||||||
|
is.mark(READ_LIMIT);
|
||||||
try {
|
try {
|
||||||
// use exif to get size
|
// use exif to get size
|
||||||
if (h.getContentType().equals("image/jpeg")) {
|
if (h.getContentType().equals("image/jpeg")) {
|
||||||
@@ -142,6 +146,8 @@ class AttachmentController {
|
|||||||
// use BitmapFactory to get size
|
// use BitmapFactory to get size
|
||||||
if (size.error) {
|
if (size.error) {
|
||||||
is.reset();
|
is.reset();
|
||||||
|
// need to mark again to re-add read limit
|
||||||
|
is.mark(READ_LIMIT);
|
||||||
size = getSizeFromBitmap(is);
|
size = getSizeFromBitmap(is);
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@@ -158,12 +164,11 @@ class AttachmentController {
|
|||||||
}
|
}
|
||||||
// get file extension
|
// get file extension
|
||||||
String extension = getExtensionFromMimeType(size.mimeType);
|
String extension = getExtensionFromMimeType(size.mimeType);
|
||||||
if (extension == null) {
|
boolean hasError = extension == null || size.error;
|
||||||
return new AttachmentItem(messageId, 0, 0, "", "", 0, 0, true);
|
if (extension == null) extension = "";
|
||||||
}
|
|
||||||
return new AttachmentItem(messageId, size.width, size.height,
|
return new AttachmentItem(messageId, size.width, size.height,
|
||||||
size.mimeType, extension, thumbnailSize.width,
|
size.mimeType, extension, thumbnailSize.width,
|
||||||
thumbnailSize.height, size.error);
|
thumbnailSize.height, hasError);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
|||||||
@@ -77,6 +77,7 @@ public class ImageFragment extends Fragment {
|
|||||||
viewModelFactory).get(ImageViewModel.class);
|
viewModelFactory).get(ImageViewModel.class);
|
||||||
|
|
||||||
photoView = v.findViewById(R.id.photoView);
|
photoView = v.findViewById(R.id.photoView);
|
||||||
|
photoView.setScaleLevels(1, 2, 4);
|
||||||
photoView.setOnClickListener(view -> viewModel.clickImage());
|
photoView.setOnClickListener(view -> viewModel.clickImage());
|
||||||
|
|
||||||
// Request Listener
|
// Request Listener
|
||||||
@@ -113,9 +114,10 @@ public class ImageFragment extends Fragment {
|
|||||||
// Load Image
|
// Load Image
|
||||||
GlideApp.with(this)
|
GlideApp.with(this)
|
||||||
.load(attachment)
|
.load(attachment)
|
||||||
|
// TODO allow if size < maxTextureSize ?
|
||||||
|
// .override(SIZE_ORIGINAL)
|
||||||
.diskCacheStrategy(NONE)
|
.diskCacheStrategy(NONE)
|
||||||
.error(R.drawable.ic_image_broken)
|
.error(R.drawable.ic_image_broken)
|
||||||
.dontTransform()
|
|
||||||
.addListener(listener)
|
.addListener(listener)
|
||||||
.into(photoView);
|
.into(photoView);
|
||||||
|
|
||||||
|
|||||||
@@ -50,9 +50,12 @@ public class ImageViewModel extends AndroidViewModel {
|
|||||||
@IoExecutor
|
@IoExecutor
|
||||||
private final Executor ioExecutor;
|
private final Executor ioExecutor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* true means there was an error saving the image, false if image was saved.
|
||||||
|
*/
|
||||||
|
private final MutableLiveData<Boolean> saveState = new MutableLiveData<>();
|
||||||
private final MutableLiveData<Boolean> imageClicked =
|
private final MutableLiveData<Boolean> imageClicked =
|
||||||
new MutableLiveData<>();
|
new MutableLiveData<>();
|
||||||
private final MutableLiveData<Boolean> saveState = new MutableLiveData<>();
|
|
||||||
private int toolbarTop, toolbarBottom;
|
private int toolbarTop, toolbarBottom;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@@ -106,8 +109,9 @@ public class ImageViewModel extends AndroidViewModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A LiveData that is true if the image was saved,
|
* A LiveData that is true if there was an error
|
||||||
* false if there was an error and null otherwise.
|
* and false if the image was saved.
|
||||||
|
* It can be null otherwise, if no image was saved recently.
|
||||||
*
|
*
|
||||||
* Call {@link #onSaveStateSeen()} after consuming an update.
|
* Call {@link #onSaveStateSeen()} after consuming an update.
|
||||||
*/
|
*/
|
||||||
@@ -126,7 +130,7 @@ public class ImageViewModel extends AndroidViewModel {
|
|||||||
@UiThread
|
@UiThread
|
||||||
void saveImage(AttachmentItem attachment, @Nullable Uri uri) {
|
void saveImage(AttachmentItem attachment, @Nullable Uri uri) {
|
||||||
if (uri == null) {
|
if (uri == null) {
|
||||||
saveState.setValue(false);
|
saveState.setValue(true);
|
||||||
} else {
|
} else {
|
||||||
saveImage(attachment, () -> getOutputStream(uri), null);
|
saveImage(attachment, () -> getOutputStream(uri), null);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -138,7 +138,6 @@ public class GroupActivity extends
|
|||||||
inviteMenuItem = menu.findItem(R.id.action_group_invite);
|
inviteMenuItem = menu.findItem(R.id.action_group_invite);
|
||||||
leaveMenuItem = menu.findItem(R.id.action_group_leave);
|
leaveMenuItem = menu.findItem(R.id.action_group_leave);
|
||||||
dissolveMenuItem = menu.findItem(R.id.action_group_dissolve);
|
dissolveMenuItem = menu.findItem(R.id.action_group_dissolve);
|
||||||
showMenuItems();
|
|
||||||
|
|
||||||
return super.onCreateOptionsMenu(menu);
|
return super.onCreateOptionsMenu(menu);
|
||||||
}
|
}
|
||||||
@@ -208,7 +207,6 @@ public class GroupActivity extends
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void showMenuItems() {
|
private void showMenuItems() {
|
||||||
if (leaveMenuItem == null || dissolveMenuItem == null) return;
|
|
||||||
if (isCreator) {
|
if (isCreator) {
|
||||||
revealMenuItem.setVisible(false);
|
revealMenuItem.setVisible(false);
|
||||||
inviteMenuItem.setVisible(true);
|
inviteMenuItem.setVisible(true);
|
||||||
|
|||||||
@@ -1,13 +1,16 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<menu
|
<menu
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools">
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/action_group_invite"
|
android:id="@+id/action_group_invite"
|
||||||
android:icon="@drawable/social_share_white"
|
android:icon="@drawable/social_share_white"
|
||||||
android:title="@string/groups_invite_members"
|
android:title="@string/groups_invite_members"
|
||||||
app:showAsAction="ifRoom"/>
|
android:visible="false"
|
||||||
|
app:showAsAction="ifRoom"
|
||||||
|
tools:visible="true"/>
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/action_group_member_list"
|
android:id="@+id/action_group_member_list"
|
||||||
@@ -19,18 +22,24 @@
|
|||||||
android:id="@+id/action_group_reveal"
|
android:id="@+id/action_group_reveal"
|
||||||
android:icon="@drawable/ic_visibility_white"
|
android:icon="@drawable/ic_visibility_white"
|
||||||
android:title="@string/groups_reveal_contacts"
|
android:title="@string/groups_reveal_contacts"
|
||||||
app:showAsAction="never"/>
|
android:visible="false"
|
||||||
|
app:showAsAction="never"
|
||||||
|
tools:visible="true"/>
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/action_group_leave"
|
android:id="@+id/action_group_leave"
|
||||||
android:icon="@drawable/action_delete_white"
|
android:icon="@drawable/action_delete_white"
|
||||||
android:title="@string/groups_leave"
|
android:title="@string/groups_leave"
|
||||||
app:showAsAction="never"/>
|
android:visible="false"
|
||||||
|
app:showAsAction="never"
|
||||||
|
tools:visible="true"/>
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/action_group_dissolve"
|
android:id="@+id/action_group_dissolve"
|
||||||
android:icon="@drawable/action_delete_white"
|
android:icon="@drawable/action_delete_white"
|
||||||
android:title="@string/groups_dissolve"
|
android:title="@string/groups_dissolve"
|
||||||
app:showAsAction="never"/>
|
android:visible="false"
|
||||||
|
app:showAsAction="never"
|
||||||
|
tools:visible="true"/>
|
||||||
|
|
||||||
</menu>
|
</menu>
|
||||||
Reference in New Issue
Block a user