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,71 +314,38 @@ public class MediaActivity extends BaseTransparentActivity implements OnDownload
} }
} }
@Override private void toggleScreenContain(boolean fullscreen) {
public boolean dispatchTouchEvent(MotionEvent event) { if (!fullscreen) {
String description = attachments.get(binding.mediaViewpager.getCurrentItem()).description;
switch (event.getAction()) { if (description != null && description.trim().length() > 0 && description.trim().compareTo("null") != 0) {
case MotionEvent.ACTION_DOWN: binding.mediaDescription.setText(description);
startX = event.getX(); if (attachments.get(binding.mediaViewpager.getCurrentItem()).translation != null) {
startY = event.getY(); binding.mediaDescription.setVisibility(View.GONE);
break; binding.mediaDescriptionTranslated.setText(attachments.get(binding.mediaViewpager.getCurrentItem()).translation);
case MotionEvent.ACTION_UP: binding.mediaDescriptionTranslated.setVisibility(View.VISIBLE);
float endX = event.getX(); } else {
float endY = event.getY(); binding.mediaDescription.setVisibility(View.VISIBLE);
if (endY > minTouch && endY < maxTouch && isAClick(startX, endX, startY, endY)) { binding.mediaDescriptionTranslated.setVisibility(View.GONE);
setFullscreen(!fullscreen);
if (!fullscreen) {
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) {
binding.mediaDescription.setText(description);
if (attachments.get(binding.mediaViewpager.getCurrentItem()).translation != null) {
binding.mediaDescription.setVisibility(View.GONE);
binding.mediaDescriptionTranslated.setText(attachments.get(binding.mediaViewpager.getCurrentItem()).translation);
binding.mediaDescriptionTranslated.setVisibility(View.VISIBLE);
} else {
binding.mediaDescription.setVisibility(View.VISIBLE);
binding.mediaDescriptionTranslated.setVisibility(View.GONE);
}
} else {
binding.translate.setVisibility(View.GONE);
if (status != null) {
binding.originalMessage.setVisibility(View.VISIBLE);
} else {
binding.originalMessage.setVisibility(View.INVISIBLE);
}
binding.mediaDescriptionTranslated.setVisibility(View.GONE);
binding.mediaDescription.setVisibility(View.GONE);
}
} else {
binding.originalMessage.setVisibility(View.INVISIBLE);
binding.translate.setVisibility(View.GONE);
binding.mediaDescriptionTranslated.setVisibility(View.GONE);
binding.mediaDescription.setVisibility(View.GONE);
}
} }
break; } else {
} binding.translate.setVisibility(View.GONE);
try { if (status != null) {
return super.dispatchTouchEvent(event); binding.originalMessage.setVisibility(View.VISIBLE);
} catch (IllegalArgumentException ex) { } else {
ex.printStackTrace(); binding.originalMessage.setVisibility(View.INVISIBLE);
}
binding.mediaDescriptionTranslated.setVisibility(View.GONE);
binding.mediaDescription.setVisibility(View.GONE);
}
} else {
binding.originalMessage.setVisibility(View.INVISIBLE);
binding.translate.setVisibility(View.GONE);
binding.mediaDescriptionTranslated.setVisibility(View.GONE);
binding.mediaDescription.setVisibility(View.GONE);
} }
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() {
unregisterReceiver(onDownloadComplete); unregisterReceiver(onDownloadComplete);
@ -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