Always show sticker icon in image editor.
Fixes flicker seen jumping toggling view once.
This commit is contained in:
parent
2d502213e4
commit
544a5386ad
3 changed files with 5 additions and 87 deletions
|
@ -14,7 +14,6 @@ import android.widget.Toast;
|
|||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.ViewModelProviders;
|
||||
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.imageeditor.ColorableRenderer;
|
||||
|
@ -55,10 +54,9 @@ public final class ImageEditorFragment extends Fragment implements ImageEditorHu
|
|||
|
||||
private EditorModel restoredModel;
|
||||
|
||||
@Nullable private EditorElement currentSelection;
|
||||
private int imageMaxHeight;
|
||||
private int imageMaxWidth;
|
||||
private ImageEditorFragmentViewModel viewModel;
|
||||
@Nullable private EditorElement currentSelection;
|
||||
private int imageMaxHeight;
|
||||
private int imageMaxWidth;
|
||||
|
||||
public static class Data {
|
||||
private final Bundle bundle;
|
||||
|
@ -123,11 +121,6 @@ public final class ImageEditorFragment extends Fragment implements ImageEditorHu
|
|||
imageMaxHeight = mediaConstraints.getImageMaxHeight(requireContext());
|
||||
|
||||
StickerSearchRepository repository = new StickerSearchRepository(requireContext());
|
||||
|
||||
viewModel = ViewModelProviders.of(this, new ImageEditorFragmentViewModel.Factory(requireActivity().getApplication(), repository))
|
||||
.get(ImageEditorFragmentViewModel.class);
|
||||
|
||||
viewModel.getStickersAvailability().observe(this, isAvailable -> imageEditorHud.setStickersAvailable(isAvailable));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
|
|
@ -1,65 +0,0 @@
|
|||
package org.thoughtcrime.securesms.scribbles;
|
||||
|
||||
import android.app.Application;
|
||||
import android.database.ContentObserver;
|
||||
import android.os.Handler;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
import org.thoughtcrime.securesms.database.DatabaseContentProviders;
|
||||
import org.thoughtcrime.securesms.stickers.StickerSearchRepository;
|
||||
import org.thoughtcrime.securesms.util.Throttler;
|
||||
|
||||
public final class ImageEditorFragmentViewModel extends ViewModel {
|
||||
|
||||
private final Application application;
|
||||
private final StickerSearchRepository repository;
|
||||
private final MutableLiveData<Boolean> stickersAvailable;
|
||||
private final Throttler availabilityThrottler;
|
||||
private final ContentObserver packObserver;
|
||||
|
||||
private ImageEditorFragmentViewModel(@NonNull Application application, @NonNull StickerSearchRepository repository) {
|
||||
this.application = application;
|
||||
this.repository = repository;
|
||||
this.stickersAvailable = new MutableLiveData<>();
|
||||
this.availabilityThrottler = new Throttler(500);
|
||||
this.packObserver = new ContentObserver(new Handler()) {
|
||||
@Override
|
||||
public void onChange(boolean selfChange) {
|
||||
availabilityThrottler.publish(() -> repository.getStickerFeatureAvailability(stickersAvailable::postValue));
|
||||
}
|
||||
};
|
||||
|
||||
application.getContentResolver().registerContentObserver(DatabaseContentProviders.StickerPack.CONTENT_URI, true, packObserver);
|
||||
}
|
||||
|
||||
@NonNull LiveData<Boolean> getStickersAvailability() {
|
||||
repository.getStickerFeatureAvailability(stickersAvailable::postValue);
|
||||
return stickersAvailable;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCleared() {
|
||||
application.getContentResolver().unregisterContentObserver(packObserver);
|
||||
}
|
||||
|
||||
static class Factory extends ViewModelProvider.NewInstanceFactory {
|
||||
private final Application application;
|
||||
private final StickerSearchRepository repository;
|
||||
|
||||
public Factory(@NonNull Application application, @NonNull StickerSearchRepository repository) {
|
||||
this.application = application;
|
||||
this.repository = repository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
|
||||
//noinspection ConstantConditions
|
||||
return modelClass.cast(new ImageEditorFragmentViewModel(application, repository));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -82,7 +82,7 @@ public final class ImageEditorHud extends LinearLayout {
|
|||
drawButton = findViewById(R.id.scribble_draw_button);
|
||||
highlightButton = findViewById(R.id.scribble_highlight_button);
|
||||
textButton = findViewById(R.id.scribble_text_button);
|
||||
stickerButton = findViewById(R.id.scribble_sticker_button);
|
||||
stickerButton = findViewById(R.id.scribble_sticker_button);
|
||||
undoButton = findViewById(R.id.scribble_undo_button);
|
||||
saveButton = findViewById(R.id.scribble_save_button);
|
||||
deleteButton = findViewById(R.id.scribble_delete_button);
|
||||
|
@ -104,7 +104,7 @@ public final class ImageEditorHud extends LinearLayout {
|
|||
}
|
||||
|
||||
private void initializeVisibilityMap() {
|
||||
setStickersAvailable(false);
|
||||
setVisibleViewsWhenInMode(Mode.NONE, drawButton, highlightButton, textButton, stickerButton, cropButton, undoButton, saveButton);
|
||||
|
||||
setVisibleViewsWhenInMode(Mode.DRAW, confirmButton, undoButton, colorPicker, colorPalette);
|
||||
|
||||
|
@ -129,16 +129,6 @@ public final class ImageEditorHud extends LinearLayout {
|
|||
visibilityModeMap.put(mode, new HashSet<>(Arrays.asList(views)));
|
||||
}
|
||||
|
||||
@MainThread
|
||||
public void setStickersAvailable(boolean stickersAvailable) {
|
||||
if (stickersAvailable) {
|
||||
setVisibleViewsWhenInMode(Mode.NONE, drawButton, highlightButton, textButton, stickerButton, cropButton, undoButton, saveButton);
|
||||
} else {
|
||||
setVisibleViewsWhenInMode(Mode.NONE, drawButton, highlightButton, textButton, cropButton, undoButton, saveButton);
|
||||
}
|
||||
updateButtonVisibility(currentMode);
|
||||
}
|
||||
|
||||
private void initializeViews() {
|
||||
undoButton.setOnClickListener(v -> eventListener.onUndo());
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue