forked from mirrors/Fedilab
Improve media activity
This commit is contained in:
parent
27423a6ab5
commit
ae7394888d
2 changed files with 44 additions and 61 deletions
|
@ -30,7 +30,6 @@ import android.os.Handler;
|
|||
import android.view.Display;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.Window;
|
||||
|
@ -222,6 +221,11 @@ public class MediaActivity extends BaseTransparentActivity implements OnDownload
|
|||
}
|
||||
|
||||
|
||||
public void toogleFullScreen() {
|
||||
fullscreen = !fullscreen;
|
||||
setFullscreen(fullscreen);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(@NonNull Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.menu_media, menu);
|
||||
|
@ -310,71 +314,38 @@ public class MediaActivity extends BaseTransparentActivity implements OnDownload
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
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) {
|
||||
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);
|
||||
}
|
||||
private void toggleScreenContain(boolean fullscreen) {
|
||||
if (!fullscreen) {
|
||||
String description = attachments.get(binding.mediaViewpager.getCurrentItem()).description;
|
||||
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);
|
||||
}
|
||||
break;
|
||||
} 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);
|
||||
}
|
||||
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
|
||||
public void onDestroy() {
|
||||
unregisterReceiver(onDownloadComplete);
|
||||
|
@ -425,6 +396,7 @@ public class MediaActivity extends BaseTransparentActivity implements OnDownload
|
|||
binding.translate.setVisibility(View.GONE);
|
||||
binding.originalMessage.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
toggleScreenContain(fullscreen);
|
||||
}
|
||||
|
||||
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,
|
||||
* see <http://www.gnu.org/licenses>. */
|
||||
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Color;
|
||||
|
@ -104,6 +105,14 @@ public class FragmentMedia extends Fragment {
|
|||
enableSliding(true);
|
||||
}
|
||||
});
|
||||
binding.mediaPicture.setOnClickListener(v -> {
|
||||
((MediaActivity) requireActivity()).toogleFullScreen();
|
||||
});
|
||||
|
||||
binding.mediaVideo.setOnClickListener(v -> {
|
||||
((MediaActivity) requireActivity()).toogleFullScreen();
|
||||
});
|
||||
|
||||
String type = attachment.type;
|
||||
String preview_url = attachment.preview_url;
|
||||
if (type.equalsIgnoreCase("unknown")) {
|
||||
|
@ -119,6 +128,7 @@ public class FragmentMedia extends Fragment {
|
|||
binding.mediaPicture.setZoomable(false);
|
||||
binding.mediaPicture.setTransitionName(attachment.url);
|
||||
binding.mediaPicture.setVisibility(View.VISIBLE);
|
||||
|
||||
binding.pbarInf.setScaleY(1f);
|
||||
binding.pbarInf.setIndeterminate(true);
|
||||
binding.loader.setVisibility(View.VISIBLE);
|
||||
|
@ -322,6 +332,7 @@ public class FragmentMedia extends Fragment {
|
|||
});
|
||||
}
|
||||
|
||||
|
||||
private void enableSliding(boolean enable) {
|
||||
if (enable && !swipeEnabled) {
|
||||
swipeEnabled = true;
|
||||
|
|
Loading…
Reference in a new issue