diff --git a/app/build.gradle b/app/build.gradle index 456658a0..68926a26 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -142,7 +142,7 @@ dependencies { androidTestImplementation 'androidx.test.ext:junit:1.1.4' androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0' // debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.8.1' - + implementation 'com.r0adkll:slidableactivity:2.1.0' coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5' } def getCurrentFlavor() { diff --git a/app/src/main/java/app/fedilab/android/activities/MediaActivity.java b/app/src/main/java/app/fedilab/android/activities/MediaActivity.java index 66dcb5b9..2934b361 100644 --- a/app/src/main/java/app/fedilab/android/activities/MediaActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/MediaActivity.java @@ -110,7 +110,6 @@ public class MediaActivity extends BaseTransparentActivity implements OnDownload binding = ActivityMediaPagerBinding.inflate(getLayoutInflater()); setContentView(binding.getRoot()); - fullscreen = false; flags = getWindow().getDecorView().getSystemUiVisibility(); Bundle b = getIntent().getExtras(); @@ -119,21 +118,19 @@ public class MediaActivity extends BaseTransparentActivity implements OnDownload attachments = (ArrayList) b.getSerializable(Helper.ARG_MEDIA_ARRAY); status = (Status) b.getSerializable(Helper.ARG_STATUS); } + + if (attachments == null || attachments.size() == 0) + finish(); if (getSupportActionBar() != null) { getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayShowHomeEnabled(true); } - - if (attachments == null || attachments.size() == 0) - finish(); - setTitle(""); ScreenSlidePagerAdapter mPagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager()); binding.mediaViewpager.setAdapter(mPagerAdapter); binding.mediaViewpager.setSaveEnabled(false); binding.mediaViewpager.setCurrentItem(mediaPosition - 1); - binding.haulerView.setOnDragDismissedListener(dragDirection -> ActivityCompat.finishAfterTransition(MediaActivity.this)); registerReceiver(onDownloadComplete, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); String description = attachments.get(mediaPosition - 1).description; handler = new Handler(); @@ -214,8 +211,6 @@ public class MediaActivity extends BaseTransparentActivity implements OnDownload } } }); - - setFullscreen(true); Display display = getWindowManager().getDefaultDisplay(); Point size = new Point(); @@ -401,6 +396,15 @@ public class MediaActivity extends BaseTransparentActivity implements OnDownload super.onPostResume(); } + // Shows the system bars by removing all the flags + // except for the ones that make the content appear under the system bars. + private void showSystemUI() { + View decorView = getWindow().getDecorView(); + decorView.setSystemUiVisibility(flags | + View.SYSTEM_UI_FLAG_LAYOUT_STABLE + | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION + | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); + } public boolean getFullScreen() { return this.fullscreen; @@ -416,10 +420,10 @@ public class MediaActivity extends BaseTransparentActivity implements OnDownload binding.originalMessage.setVisibility(View.VISIBLE); } } else { + hideSystemUI(); binding.mediaDescription.setVisibility(View.GONE); binding.translate.setVisibility(View.GONE); binding.originalMessage.setVisibility(View.INVISIBLE); - hideSystemUI(); } } @@ -440,16 +444,6 @@ public class MediaActivity extends BaseTransparentActivity implements OnDownload | View.SYSTEM_UI_FLAG_FULLSCREEN); } - // Shows the system bars by removing all the flags - // except for the ones that make the content appear under the system bars. - private void showSystemUI() { - View decorView = getWindow().getDecorView(); - decorView.setSystemUiVisibility(flags | - View.SYSTEM_UI_FLAG_LAYOUT_STABLE - | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION - | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); - } - public FragmentMedia getCurrentFragment() { return mCurrentFragment; } diff --git a/app/src/main/java/app/fedilab/android/ui/fragment/media/FragmentMedia.java b/app/src/main/java/app/fedilab/android/ui/fragment/media/FragmentMedia.java index 061f756e..869b9bed 100644 --- a/app/src/main/java/app/fedilab/android/ui/fragment/media/FragmentMedia.java +++ b/app/src/main/java/app/fedilab/android/ui/fragment/media/FragmentMedia.java @@ -16,6 +16,7 @@ package app.fedilab.android.ui.fragment.media; import android.content.SharedPreferences; import android.graphics.Bitmap; +import android.graphics.Color; import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Bundle; @@ -42,8 +43,11 @@ import com.google.android.exoplayer2.Player; import com.google.android.exoplayer2.source.ProgressiveMediaSource; import com.google.android.exoplayer2.upstream.DataSource; import com.google.android.exoplayer2.upstream.DefaultDataSource; - -import java.util.Timer; +import com.r0adkll.slidr.Slidr; +import com.r0adkll.slidr.model.SlidrConfig; +import com.r0adkll.slidr.model.SlidrInterface; +import com.r0adkll.slidr.model.SlidrListener; +import com.r0adkll.slidr.model.SlidrPosition; import app.fedilab.android.R; import app.fedilab.android.activities.MediaActivity; @@ -58,13 +62,12 @@ public class FragmentMedia extends Fragment { private ExoPlayer player; - private Timer timer; private String url; private boolean canSwipe; private Attachment attachment; private boolean swipeEnabled; private FragmentSlideMediaBinding binding; - + private SlidrInterface slidrInterface; public FragmentMedia() { } @@ -113,9 +116,12 @@ public class FragmentMedia extends Fragment { url = attachment.remote_url; attachment.type = type; } - - binding.mediaPicture.setVisibility(View.VISIBLE); + 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); if (Helper.isValidContextForGlide(requireActivity()) && isAdded()) { Glide.with(requireActivity()) .asBitmap() @@ -124,21 +130,15 @@ public class FragmentMedia extends Fragment { new CustomTarget() { @Override public void onResourceReady(@NonNull final Bitmap resource, Transition transition) { + if (binding == null || !isAdded() || getActivity() == null) { + return; + } binding.mediaPicture.setImageBitmap(resource); scheduleStartPostponedTransition(binding.mediaPicture); if (attachment.type.equalsIgnoreCase("image") && !attachment.url.toLowerCase().endsWith(".gif")) { + binding.mediaPicture.setVisibility(View.VISIBLE); final Handler handler = new Handler(); handler.postDelayed(() -> { - if (binding == null) { - return; - } - binding.pbarInf.setScaleY(1f); - binding.mediaPicture.setVisibility(View.VISIBLE); - binding.pbarInf.setIndeterminate(true); - binding.loader.setVisibility(View.VISIBLE); - if (binding == null || !isAdded() || getActivity() == null) { - return; - } if (Helper.isValidContextForGlide(requireActivity()) && isAdded()) { Glide.with(requireActivity()) .asBitmap() @@ -147,18 +147,12 @@ public class FragmentMedia extends Fragment { new CustomTarget() { @Override public void onResourceReady(@NonNull final Bitmap resource, Transition transition) { - if (binding != null) { - binding.loader.setVisibility(View.GONE); - if (binding.mediaPicture.getScale() < 1.1) { - binding.mediaPicture.setImageBitmap(resource); - } else { - binding.messageReady.setVisibility(View.VISIBLE); - } - binding.messageReady.setOnClickListener(view -> { - binding.mediaPicture.setImageBitmap(resource); - binding.messageReady.setVisibility(View.GONE); - }); + if (binding == null || !isAdded() || getActivity() == null) { + return; } + binding.loader.setVisibility(View.GONE); + binding.mediaPicture.setImageBitmap(resource); + binding.mediaPicture.setZoomable(true); } @Override @@ -168,16 +162,15 @@ public class FragmentMedia extends Fragment { } ); } - }, 1000); - - + }, 500); } else if (attachment.type.equalsIgnoreCase("image") && attachment.url.toLowerCase().endsWith(".gif")) { binding.loader.setVisibility(View.GONE); + binding.mediaPicture.setVisibility(View.VISIBLE); if (Helper.isValidContextForGlide(requireActivity())) { + binding.mediaPicture.setZoomable(true); Glide.with(requireActivity()) .load(url).into(binding.mediaPicture); } - scheduleStartPostponedTransition(binding.mediaPicture); } } @@ -271,10 +264,6 @@ public class FragmentMedia extends Fragment { } } catch (Exception ignored) { } - if (timer != null) { - timer.cancel(); - timer = null; - } } @Override @@ -283,6 +272,43 @@ public class FragmentMedia extends Fragment { if (player != null) { player.setPlayWhenReady(true); } + if (slidrInterface == null) { + slidrInterface = Slidr.replace(binding.mediaFragmentContainer, new SlidrConfig.Builder().sensitivity(1f) + .scrimColor(Color.BLACK) + .scrimStartAlpha(0.8f) + .scrimEndAlpha(0f) + .position(SlidrPosition.VERTICAL) + .velocityThreshold(2400) + .distanceThreshold(0.25f) + .edgeSize(0.18f) + .listener(new SlidrListener() { + @Override + public void onSlideStateChanged(int state) { + + } + + @Override + public void onSlideChange(float percent) { + if (percent < 0.70) { + binding.mediaVideo.setVisibility(View.GONE); + binding.videoLayout.setVisibility(View.GONE); + ActivityCompat.finishAfterTransition(requireActivity()); + } + + } + + @Override + public void onSlideOpened() { + + } + + @Override + public boolean onSlideClosed() { + return false; + } + }) + .build()); + } } private void scheduleStartPostponedTransition(final ImageView imageView) { @@ -299,7 +325,9 @@ public class FragmentMedia extends Fragment { private void enableSliding(boolean enable) { if (enable && !swipeEnabled) { swipeEnabled = true; + slidrInterface.unlock(); } else if (!enable && swipeEnabled) { + slidrInterface.lock(); swipeEnabled = false; } } diff --git a/app/src/main/res/layout/activity_media_pager.xml b/app/src/main/res/layout/activity_media_pager.xml index d4fdbd08..497fe139 100644 --- a/app/src/main/res/layout/activity_media_pager.xml +++ b/app/src/main/res/layout/activity_media_pager.xml @@ -14,92 +14,83 @@ You should have received a copy of the GNU General Public License along with Fedilab; if not, see . --> - + android:animateLayoutChanges="true" + android:background="@android:color/transparent"> - + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" /> - + - + - + - - - - - - + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_slide_media.xml b/app/src/main/res/layout/fragment_slide_media.xml index bb91ac89..b5361e12 100644 --- a/app/src/main/res/layout/fragment_slide_media.xml +++ b/app/src/main/res/layout/fragment_slide_media.xml @@ -1,125 +1,69 @@ - - + android:background="@color/black"> + - - + + - - - - - - - - - - - - - - - - - - - - - + android:indeterminate="false" + android:max="100" + android:progress="0" /> + android:textSize="12sp" /> - + + + + + + + + + + + + diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml index d13d71d9..f3fba982 100644 --- a/app/src/main/res/values/themes.xml +++ b/app/src/main/res/values/themes.xml @@ -90,6 +90,14 @@ false true true + + @android:color/transparent + true + true + shortEdges + + true + true