[android] address review comments for image fullscreen swiping

This commit is contained in:
Torsten Grote
2018-12-12 17:21:16 -02:00
parent 2bea581654
commit a994966095
3 changed files with 11 additions and 7 deletions

View File

@@ -134,7 +134,7 @@ public class ImageActivity extends BriarActivity
viewPager.setCurrentItem(position);
if (SDK_INT >= 16) {
viewModel.getOnImageClicked().observe(this, this::onPhotoClicked);
viewModel.getOnImageClicked().observe(this, this::onImageClicked);
window.getDecorView().setSystemUiVisibility(
SYSTEM_UI_FLAG_LAYOUT_STABLE |
SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
@@ -168,6 +168,8 @@ public class ImageActivity extends BriarActivity
);
if (SDK_INT >= 16) {
layout.getViewTreeObserver().removeOnGlobalLayoutListener(this);
} else {
layout.getViewTreeObserver().removeGlobalOnLayoutListener(this);
}
}
@@ -203,8 +205,9 @@ public class ImageActivity extends BriarActivity
supportFinishAfterTransition();
}
private void onPhotoClicked(@Nullable Boolean clicked) {
if (clicked != null&& clicked && SDK_INT >= 16) {
@RequiresApi(api = 16)
private void onImageClicked(@Nullable Boolean clicked) {
if (clicked != null && clicked) {
toggleSystemUi();
viewModel.onOnImageClickSeen();
}

View File

@@ -77,7 +77,7 @@ public class ImageFragment extends Fragment {
viewModelFactory).get(ImageViewModel.class);
photoView = v.findViewById(R.id.photoView);
photoView.setOnClickListener(view -> viewModel.clickPhoto());
photoView.setOnClickListener(view -> viewModel.clickImage());
// Request Listener
RequestListener<Drawable> listener = new RequestListener<Drawable>() {

View File

@@ -50,7 +50,8 @@ public class ImageViewModel extends AndroidViewModel {
@IoExecutor
private final Executor ioExecutor;
private final MutableLiveData<Boolean> imageClicked = new MutableLiveData<>();
private final MutableLiveData<Boolean> imageClicked =
new MutableLiveData<>();
private final MutableLiveData<Boolean> saveState = new MutableLiveData<>();
private int toolbarTop, toolbarBottom;
@@ -65,7 +66,7 @@ public class ImageViewModel extends AndroidViewModel {
this.ioExecutor = ioExecutor;
}
void clickPhoto() {
void clickImage() {
imageClicked.setValue(true);
}
@@ -97,7 +98,7 @@ public class ImageViewModel extends AndroidViewModel {
float scaleFactor = Math.min(widthPercentage, heightPercentage);
int realWidth = (int) (width * scaleFactor);
int realHeight = (int) (height * scaleFactor);
// return if photo doesn't use the full width,
// return if image doesn't use the full width,
// because it will be moved to the right otherwise
if (realWidth < screenView.getWidth()) return false;
int drawableTop = (screenView.getHeight() - realHeight) / 2;