mirror of
				https://codeberg.org/tom79/Fedilab.git
				synced 2025-10-20 11:20:16 +03:00 
			
		
		
		
	Improve behavior
This commit is contained in:
		
							parent
							
								
									a5d1e8efe0
								
							
						
					
					
						commit
						27423a6ab5
					
				
					 6 changed files with 204 additions and 239 deletions
				
			
		|  | @ -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() { | ||||
|  |  | |||
|  | @ -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<Attachment>) 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; | ||||
|     } | ||||
|  |  | |||
|  | @ -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<Bitmap>() { | ||||
|                                 @Override | ||||
|                                 public void onResourceReady(@NonNull final Bitmap resource, Transition<? super Bitmap> transition) { | ||||
|                                     binding.mediaPicture.setImageBitmap(resource); | ||||
|                                     scheduleStartPostponedTransition(binding.mediaPicture); | ||||
|                                     if (attachment.type.equalsIgnoreCase("image") && !attachment.url.toLowerCase().endsWith(".gif")) { | ||||
|                                         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; | ||||
|                                     } | ||||
|                                     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 (Helper.isValidContextForGlide(requireActivity()) && isAdded()) { | ||||
|                                                 Glide.with(requireActivity()) | ||||
|                                                         .asBitmap() | ||||
|  | @ -147,18 +147,12 @@ public class FragmentMedia extends Fragment { | |||
|                                                                 new CustomTarget<Bitmap>() { | ||||
|                                                                     @Override | ||||
|                                                                     public void onResourceReady(@NonNull final Bitmap resource, Transition<? super Bitmap> transition) { | ||||
|                                                                         if (binding != null) { | ||||
|                                                                         if (binding == null || !isAdded() || getActivity() == null) { | ||||
|                                                                             return; | ||||
|                                                                         } | ||||
|                                                                         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); | ||||
|                                                                             }); | ||||
|                                                                         } | ||||
|                                                                         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; | ||||
|         } | ||||
|     } | ||||
|  |  | |||
|  | @ -14,16 +14,9 @@ | |||
|     You should have received a copy of the GNU General Public License along with Fedilab; if not, | ||||
|     see <http://www.gnu.org/licenses>. | ||||
| --> | ||||
| <app.futured.hauler.HaulerView xmlns:android="http://schemas.android.com/apk/res/android" | ||||
| <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||||
|     xmlns:app="http://schemas.android.com/apk/res-auto" | ||||
|     xmlns:tools="http://schemas.android.com/tools" | ||||
|     android:id="@+id/haulerView" | ||||
|     android:layout_width="match_parent" | ||||
|     android:layout_height="match_parent" | ||||
|     android:background="@color/transparent" | ||||
|     app:dragUpEnabled="true"> | ||||
| 
 | ||||
|     <androidx.constraintlayout.widget.ConstraintLayout | ||||
|     android:layout_width="match_parent" | ||||
|     android:layout_height="match_parent" | ||||
|     android:animateLayoutChanges="true" | ||||
|  | @ -100,6 +93,4 @@ | |||
|         app:layout_constraintStart_toStartOf="parent" | ||||
|         app:layout_constraintTop_toBottomOf="@+id/translate" | ||||
|         tools:visibility="visible" /> | ||||
|     </androidx.constraintlayout.widget.ConstraintLayout> | ||||
| 
 | ||||
| </app.futured.hauler.HaulerView> | ||||
| </androidx.constraintlayout.widget.ConstraintLayout> | ||||
|  | @ -1,17 +1,10 @@ | |||
| <?xml version="1.0" encoding="utf-8"?> | ||||
| <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||||
|     xmlns:app="http://schemas.android.com/apk/res-auto" | ||||
|     android:id="@+id/main_container" | ||||
|     android:layout_width="match_parent" | ||||
|     android:layout_height="match_parent" | ||||
|     android:background="@android:color/transparent"> | ||||
| 
 | ||||
|     <androidx.core.widget.NestedScrollView | ||||
|         android:layout_width="match_parent" | ||||
|         android:layout_height="match_parent" | ||||
|         android:fillViewport="true" | ||||
|         android:keepScreenOn="true"> | ||||
| 
 | ||||
|     <RelativeLayout | ||||
|         android:id="@+id/media_fragment_container" | ||||
|         android:layout_width="match_parent" | ||||
|  | @ -72,54 +65,5 @@ | |||
|             android:layout_centerInParent="true" | ||||
|             android:visibility="gone" /> | ||||
| 
 | ||||
| 
 | ||||
|             <ImageView | ||||
|                 android:id="@+id/media_prev" | ||||
|                 android:layout_width="30dp" | ||||
|                 android:layout_height="50dp" | ||||
|                 android:layout_alignParentStart="true" | ||||
|                 android:layout_centerVertical="true" | ||||
|                 android:layout_marginStart="5dp" | ||||
|                 android:layout_marginLeft="5dp" | ||||
|                 android:layout_marginTop="5dp" | ||||
|                 android:layout_marginEnd="5dp" | ||||
|                 android:layout_marginRight="5dp" | ||||
|                 android:layout_marginBottom="5dp" | ||||
|                 android:background="@color/transparent_grey" | ||||
|                 android:contentDescription="@string/previous" | ||||
|                 android:src="@drawable/ic_baseline_first_page_24" | ||||
|                 android:visibility="gone" | ||||
|                 app:tint="@color/white" /> | ||||
| 
 | ||||
|             <ImageView | ||||
|                 android:id="@+id/media_next" | ||||
|                 android:layout_width="30dp" | ||||
|                 android:layout_height="50dp" | ||||
|                 android:layout_alignParentEnd="true" | ||||
|                 android:layout_centerVertical="true" | ||||
|                 android:layout_marginStart="5dp" | ||||
|                 android:layout_marginLeft="5dp" | ||||
|                 android:layout_marginTop="5dp" | ||||
|                 android:layout_marginEnd="5dp" | ||||
|                 android:layout_marginRight="5dp" | ||||
|                 android:layout_marginBottom="5dp" | ||||
|                 android:background="@color/transparent_grey" | ||||
|                 android:contentDescription="@string/next" | ||||
|                 android:src="@drawable/ic_baseline_last_page_24" | ||||
|                 android:visibility="gone" /> | ||||
| 
 | ||||
| 
 | ||||
|             <TextView | ||||
|                 android:id="@+id/message_ready" | ||||
|                 android:layout_width="match_parent" | ||||
|                 android:layout_height="40dp" | ||||
|                 android:layout_alignBottom="@+id/media_picture_container" | ||||
|                 android:layout_marginBottom="40dp" | ||||
|                 android:background="@drawable/media_message_border" | ||||
|                 android:gravity="center" | ||||
|                 android:text="@string/media_ready" | ||||
|                 android:textSize="14sp" | ||||
|                 android:visibility="gone" /> | ||||
|     </RelativeLayout> | ||||
|     </androidx.core.widget.NestedScrollView> | ||||
| </FrameLayout> | ||||
|  |  | |||
|  | @ -90,6 +90,14 @@ | |||
|         <item name="android:windowIsFloating">false</item> | ||||
|         <item name="android:windowIsTranslucent">true</item> | ||||
|         <item name="android:windowNoTitle">true</item> | ||||
| 
 | ||||
|         <item name="android:windowBackground">@android:color/transparent</item> | ||||
|         <item name="android:windowContentTransitions">true</item> | ||||
|         <item name="android:windowActivityTransitions">true</item> | ||||
|         <item name="android:windowLayoutInDisplayCutoutMode" tools:targetApi="o_mr1">shortEdges | ||||
|         </item> | ||||
|         <item name="android:windowTranslucentStatus">true</item> | ||||
|         <item name="android:windowTranslucentNavigation">true</item> | ||||
|     </style> | ||||
| 
 | ||||
|     <style name="AppThemeAlertDialog" parent="Theme.Material3.Light.Dialog.Alert"> | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue