Commit a9949660 authored by Torsten Grote's avatar Torsten Grote

[android] address review comments for image fullscreen swiping

parent 2bea5816
Pipeline #2898 passed with stage
in 11 minutes and 11 seconds
...@@ -134,7 +134,7 @@ public class ImageActivity extends BriarActivity ...@@ -134,7 +134,7 @@ public class ImageActivity extends BriarActivity
viewPager.setCurrentItem(position); viewPager.setCurrentItem(position);
if (SDK_INT >= 16) { if (SDK_INT >= 16) {
viewModel.getOnImageClicked().observe(this, this::onPhotoClicked); viewModel.getOnImageClicked().observe(this, this::onImageClicked);
window.getDecorView().setSystemUiVisibility( window.getDecorView().setSystemUiVisibility(
SYSTEM_UI_FLAG_LAYOUT_STABLE | SYSTEM_UI_FLAG_LAYOUT_STABLE |
SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
...@@ -168,6 +168,8 @@ public class ImageActivity extends BriarActivity ...@@ -168,6 +168,8 @@ public class ImageActivity extends BriarActivity
); );
if (SDK_INT >= 16) { if (SDK_INT >= 16) {
layout.getViewTreeObserver().removeOnGlobalLayoutListener(this); layout.getViewTreeObserver().removeOnGlobalLayoutListener(this);
} else {
layout.getViewTreeObserver().removeGlobalOnLayoutListener(this);
} }
} }
...@@ -203,8 +205,9 @@ public class ImageActivity extends BriarActivity ...@@ -203,8 +205,9 @@ public class ImageActivity extends BriarActivity
supportFinishAfterTransition(); supportFinishAfterTransition();
} }
private void onPhotoClicked(@Nullable Boolean clicked) { @RequiresApi(api = 16)
if (clicked != null&& clicked && SDK_INT >= 16) { private void onImageClicked(@Nullable Boolean clicked) {
if (clicked != null && clicked) {
toggleSystemUi(); toggleSystemUi();
viewModel.onOnImageClickSeen(); viewModel.onOnImageClickSeen();
} }
......
...@@ -77,7 +77,7 @@ public class ImageFragment extends Fragment { ...@@ -77,7 +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.setOnClickListener(view -> viewModel.clickPhoto()); photoView.setOnClickListener(view -> viewModel.clickImage());
// Request Listener // Request Listener
RequestListener<Drawable> listener = new RequestListener<Drawable>() { RequestListener<Drawable> listener = new RequestListener<Drawable>() {
......
...@@ -50,7 +50,8 @@ public class ImageViewModel extends AndroidViewModel { ...@@ -50,7 +50,8 @@ public class ImageViewModel extends AndroidViewModel {
@IoExecutor @IoExecutor
private final Executor 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 final MutableLiveData<Boolean> saveState = new MutableLiveData<>();
private int toolbarTop, toolbarBottom; private int toolbarTop, toolbarBottom;
...@@ -65,7 +66,7 @@ public class ImageViewModel extends AndroidViewModel { ...@@ -65,7 +66,7 @@ public class ImageViewModel extends AndroidViewModel {
this.ioExecutor = ioExecutor; this.ioExecutor = ioExecutor;
} }
void clickPhoto() { void clickImage() {
imageClicked.setValue(true); imageClicked.setValue(true);
} }
...@@ -97,7 +98,7 @@ public class ImageViewModel extends AndroidViewModel { ...@@ -97,7 +98,7 @@ public class ImageViewModel extends AndroidViewModel {
float scaleFactor = Math.min(widthPercentage, heightPercentage); float scaleFactor = Math.min(widthPercentage, heightPercentage);
int realWidth = (int) (width * scaleFactor); int realWidth = (int) (width * scaleFactor);
int realHeight = (int) (height * 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 // because it will be moved to the right otherwise
if (realWidth < screenView.getWidth()) return false; if (realWidth < screenView.getWidth()) return false;
int drawableTop = (screenView.getHeight() - realHeight) / 2; int drawableTop = (screenView.getHeight() - realHeight) / 2;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment