mirror of
https://github.com/oxen-io/session-android.git
synced 2025-10-27 22:38:53 +00:00
Image Editor - Undo button visibility.
This commit is contained in:
@@ -118,13 +118,14 @@ public final class ImageEditorFragment extends Fragment implements ImageEditorHu
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
imageEditorHud = view.findViewById(R.id.scribble_hud);
|
||||
imageEditorView = view.findViewById(R.id.image_editor_view);
|
||||
imageEditorHud = view.findViewById(R.id.scribble_hud);
|
||||
imageEditorView = view.findViewById(R.id.image_editor_view);
|
||||
|
||||
imageEditorHud.setEventListener(this);
|
||||
|
||||
imageEditorView.setTapListener(selectionListener);
|
||||
imageEditorView.setDrawingChangedListener(this::refreshUniqueColors);
|
||||
imageEditorView.setUndoRedoStackListener(this::onUndoRedoAvailabilityChanged);
|
||||
|
||||
EditorModel editorModel = null;
|
||||
|
||||
@@ -321,6 +322,10 @@ public final class ImageEditorFragment extends Fragment implements ImageEditorHu
|
||||
imageEditorHud.setColorPalette(imageEditorView.getModel().getUniqueColorsIgnoringAlpha());
|
||||
}
|
||||
|
||||
private void onUndoRedoAvailabilityChanged(boolean undoAvailable, boolean redoAvailable) {
|
||||
imageEditorHud.setUndoAvailability(undoAvailable);
|
||||
}
|
||||
|
||||
private final ImageEditorView.TapListener selectionListener = new ImageEditorView.TapListener() {
|
||||
|
||||
@Override
|
||||
|
||||
@@ -47,7 +47,10 @@ public final class ImageEditorHud extends LinearLayout {
|
||||
private ColorPaletteAdapter colorPaletteAdapter;
|
||||
|
||||
private final Map<Mode, Set<View>> visibilityModeMap = new HashMap<>();
|
||||
private final Set<View> allViews = new HashSet<>();
|
||||
private final Set<View> allViews = new HashSet<>();
|
||||
|
||||
private Mode currentMode;
|
||||
private boolean undoAvailable;
|
||||
|
||||
public ImageEditorHud(@NonNull Context context) {
|
||||
super(context);
|
||||
@@ -171,9 +174,10 @@ public final class ImageEditorHud extends LinearLayout {
|
||||
}
|
||||
|
||||
private void setMode(@NonNull Mode mode, boolean notify) {
|
||||
this.currentMode = mode;
|
||||
Set<View> visibleButtons = visibilityModeMap.get(mode);
|
||||
for (View button : allViews) {
|
||||
button.setVisibility(visibleButtons != null && visibleButtons.contains(button) ? VISIBLE : GONE);
|
||||
button.setVisibility(buttonIsVisible(visibleButtons, button) ? VISIBLE : GONE);
|
||||
}
|
||||
|
||||
switch (mode) {
|
||||
@@ -189,6 +193,12 @@ public final class ImageEditorHud extends LinearLayout {
|
||||
eventListener.onRequestFullScreen(mode != Mode.NONE);
|
||||
}
|
||||
|
||||
private boolean buttonIsVisible(@Nullable Set<View> visibleButtons, @NonNull View button) {
|
||||
return visibleButtons != null &&
|
||||
visibleButtons.contains(button) &&
|
||||
(button != undoButton || undoAvailable);
|
||||
}
|
||||
|
||||
private void presentModeCrop() {
|
||||
updateCropAspectLockImage(eventListener.isCropAspectLocked());
|
||||
}
|
||||
@@ -216,6 +226,12 @@ public final class ImageEditorHud extends LinearLayout {
|
||||
return color & ~0xff000000 | 0x80000000;
|
||||
}
|
||||
|
||||
public void setUndoAvailability(boolean undoAvailable) {
|
||||
this.undoAvailable = undoAvailable;
|
||||
|
||||
undoButton.setVisibility(buttonIsVisible(visibilityModeMap.get(currentMode), undoButton) ? VISIBLE : GONE);
|
||||
}
|
||||
|
||||
public enum Mode {
|
||||
NONE, DRAW, HIGHLIGHT, TEXT, MOVE_DELETE, CROP
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user