Improve media activity

maths
Thomas 2 years ago
parent 27423a6ab5
commit ae7394888d

@ -30,7 +30,6 @@ import android.os.Handler;
import android.view.Display; import android.view.Display;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.Window; import android.view.Window;
@ -222,6 +221,11 @@ public class MediaActivity extends BaseTransparentActivity implements OnDownload
} }
public void toogleFullScreen() {
fullscreen = !fullscreen;
setFullscreen(fullscreen);
}
@Override @Override
public boolean onCreateOptionsMenu(@NonNull Menu menu) { public boolean onCreateOptionsMenu(@NonNull Menu menu) {
getMenuInflater().inflate(R.menu.menu_media, menu); getMenuInflater().inflate(R.menu.menu_media, menu);
@ -310,25 +314,9 @@ public class MediaActivity extends BaseTransparentActivity implements OnDownload
} }
} }
@Override private void toggleScreenContain(boolean fullscreen) {
public boolean dispatchTouchEvent(MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
startX = event.getX();
startY = event.getY();
break;
case MotionEvent.ACTION_UP:
float endX = event.getX();
float endY = event.getY();
if (endY > minTouch && endY < maxTouch && isAClick(startX, endX, startY, endY)) {
setFullscreen(!fullscreen);
if (!fullscreen) { if (!fullscreen) {
String description = attachments.get(binding.mediaViewpager.getCurrentItem()).description; String description = attachments.get(binding.mediaViewpager.getCurrentItem()).description;
if (handler != null) {
handler.removeCallbacksAndMessages(null);
}
handler = new Handler();
if (description != null && description.trim().length() > 0 && description.trim().compareTo("null") != 0) { if (description != null && description.trim().length() > 0 && description.trim().compareTo("null") != 0) {
binding.mediaDescription.setText(description); binding.mediaDescription.setText(description);
if (attachments.get(binding.mediaViewpager.getCurrentItem()).translation != null) { if (attachments.get(binding.mediaViewpager.getCurrentItem()).translation != null) {
@ -356,24 +344,7 @@ public class MediaActivity extends BaseTransparentActivity implements OnDownload
binding.mediaDescription.setVisibility(View.GONE); binding.mediaDescription.setVisibility(View.GONE);
} }
} }
break;
}
try {
return super.dispatchTouchEvent(event);
} catch (IllegalArgumentException ex) {
ex.printStackTrace();
}
return false;
}
private boolean isAClick(float startX, float endX, float startY, float endY) {
float differenceX = Math.abs(startX - endX);
float differenceY = Math.abs(startY - endY);
int CLICK_ACTION_THRESHOLD = 200;
return !(differenceX > CLICK_ACTION_THRESHOLD/* =5 */ || differenceY > CLICK_ACTION_THRESHOLD);
}
@Override @Override
public void onDestroy() { public void onDestroy() {
@ -425,6 +396,7 @@ public class MediaActivity extends BaseTransparentActivity implements OnDownload
binding.translate.setVisibility(View.GONE); binding.translate.setVisibility(View.GONE);
binding.originalMessage.setVisibility(View.INVISIBLE); binding.originalMessage.setVisibility(View.INVISIBLE);
} }
toggleScreenContain(fullscreen);
} }
private void hideSystemUI() { private void hideSystemUI() {

@ -14,6 +14,7 @@ package app.fedilab.android.ui.fragment.media;
* You should have received a copy of the GNU General Public License along with Fedilab; if not, * You should have received a copy of the GNU General Public License along with Fedilab; if not,
* see <http://www.gnu.org/licenses>. */ * see <http://www.gnu.org/licenses>. */
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.Color; import android.graphics.Color;
@ -104,6 +105,14 @@ public class FragmentMedia extends Fragment {
enableSliding(true); enableSliding(true);
} }
}); });
binding.mediaPicture.setOnClickListener(v -> {
((MediaActivity) requireActivity()).toogleFullScreen();
});
binding.mediaVideo.setOnClickListener(v -> {
((MediaActivity) requireActivity()).toogleFullScreen();
});
String type = attachment.type; String type = attachment.type;
String preview_url = attachment.preview_url; String preview_url = attachment.preview_url;
if (type.equalsIgnoreCase("unknown")) { if (type.equalsIgnoreCase("unknown")) {
@ -119,6 +128,7 @@ public class FragmentMedia extends Fragment {
binding.mediaPicture.setZoomable(false); binding.mediaPicture.setZoomable(false);
binding.mediaPicture.setTransitionName(attachment.url); binding.mediaPicture.setTransitionName(attachment.url);
binding.mediaPicture.setVisibility(View.VISIBLE); binding.mediaPicture.setVisibility(View.VISIBLE);
binding.pbarInf.setScaleY(1f); binding.pbarInf.setScaleY(1f);
binding.pbarInf.setIndeterminate(true); binding.pbarInf.setIndeterminate(true);
binding.loader.setVisibility(View.VISIBLE); binding.loader.setVisibility(View.VISIBLE);
@ -322,6 +332,7 @@ public class FragmentMedia extends Fragment {
}); });
} }
private void enableSliding(boolean enable) { private void enableSliding(boolean enable) {
if (enable && !swipeEnabled) { if (enable && !swipeEnabled) {
swipeEnabled = true; swipeEnabled = true;

Loading…
Cancel
Save