1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-11-22 06:37:30 +00:00

Fix fullscreen mode showing bottom nav bar and fix austinhuang0131/barinsta#1292

This commit is contained in:
Ammar Githam 2021-05-23 08:07:49 +09:00
parent 505d5acef3
commit b3680584bf
4 changed files with 55 additions and 52 deletions

View File

@ -689,7 +689,7 @@ public class MainActivity extends BaseLanguageActivity implements FragmentManage
if (mediaService == null) mediaService = MediaService.getInstance(null, null, 0L); if (mediaService == null) mediaService = MediaService.getInstance(null, null, 0L);
final ServiceCallback<Media> postCb = new ServiceCallback<Media>() { final ServiceCallback<Media> postCb = new ServiceCallback<Media>() {
@Override @Override
public void onSuccess(final Media feedModel){ public void onSuccess(final Media feedModel) {
if (feedModel != null) { if (feedModel != null) {
if (currentNavControllerLiveData == null) return; if (currentNavControllerLiveData == null) return;
final NavController navController = currentNavControllerLiveData.getValue(); final NavController navController = currentNavControllerLiveData.getValue();
@ -701,8 +701,7 @@ public class MainActivity extends BaseLanguageActivity implements FragmentManage
} catch (Exception e) { } catch (Exception e) {
Log.e(TAG, "showPostView: ", e); Log.e(TAG, "showPostView: ", e);
} }
} } else Toast.makeText(getApplicationContext(), R.string.post_not_found, Toast.LENGTH_SHORT).show();
else Toast.makeText(getApplicationContext(), R.string.post_not_found, Toast.LENGTH_SHORT).show();
alertDialog.dismiss(); alertDialog.dismiss();
} }

View File

@ -18,7 +18,6 @@ import android.view.MenuItem;
import android.view.MotionEvent; 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.widget.Toast; import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
@ -31,6 +30,8 @@ import androidx.appcompat.widget.Toolbar;
import androidx.constraintlayout.widget.ConstraintLayout; import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.core.content.PermissionChecker; import androidx.core.content.PermissionChecker;
import androidx.core.view.WindowCompat; import androidx.core.view.WindowCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.core.view.WindowInsetsControllerCompat;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentActivity;
import androidx.lifecycle.LiveData; import androidx.lifecycle.LiveData;
@ -52,6 +53,7 @@ import com.facebook.imagepipeline.request.ImageRequest;
import com.facebook.imagepipeline.request.ImageRequestBuilder; import com.facebook.imagepipeline.request.ImageRequestBuilder;
import com.google.android.exoplayer2.ui.StyledPlayerView; import com.google.android.exoplayer2.ui.StyledPlayerView;
import com.google.android.material.appbar.CollapsingToolbarLayout; import com.google.android.material.appbar.CollapsingToolbarLayout;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.google.android.material.snackbar.BaseTransientBottomBar; import com.google.android.material.snackbar.BaseTransientBottomBar;
import com.google.android.material.snackbar.Snackbar; import com.google.android.material.snackbar.Snackbar;
import com.skydoves.balloon.ArrowOrientation; import com.skydoves.balloon.ArrowOrientation;
@ -135,6 +137,7 @@ public class PostViewV2Fragment extends Fragment implements EditTextDialogFragme
private Drawable originalRootBackground; private Drawable originalRootBackground;
private ColorStateList originalLikeColorStateList; private ColorStateList originalLikeColorStateList;
private ColorStateList originalSaveColorStateList; private ColorStateList originalSaveColorStateList;
private WindowInsetsControllerCompat controller;
private final Observer<Object> backStackSavedStateObserver = result -> { private final Observer<Object> backStackSavedStateObserver = result -> {
if (result == null) return; if (result == null) return;
@ -162,6 +165,9 @@ public class PostViewV2Fragment extends Fragment implements EditTextDialogFragme
public void onCreate(@Nullable final Bundle savedInstanceState) { public void onCreate(@Nullable final Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
viewModel = new ViewModelProvider(this).get(PostViewV2ViewModel.class); viewModel = new ViewModelProvider(this).get(PostViewV2ViewModel.class);
final MainActivity activity = (MainActivity) getActivity();
if (activity == null) return;
controller = new WindowInsetsControllerCompat(activity.getWindow(), activity.getRootView());
} }
@Nullable @Nullable
@ -789,10 +795,6 @@ public class PostViewV2Fragment extends Fragment implements EditTextDialogFragme
originalHeight = widthHeight.second; originalHeight = widthHeight.second;
final ConstraintLayout.LayoutParams layoutParams = new ConstraintLayout.LayoutParams(ConstraintLayout.LayoutParams.MATCH_PARENT, final ConstraintLayout.LayoutParams layoutParams = new ConstraintLayout.LayoutParams(ConstraintLayout.LayoutParams.MATCH_PARENT,
originalHeight); originalHeight);
layoutParams.topToBottom = binding.topBarrier.getId();
layoutParams.bottomToTop = bottom.buttonsTopBarrier.getId();
layoutParams.startToStart = ConstraintLayout.LayoutParams.PARENT_ID;
layoutParams.endToEnd = ConstraintLayout.LayoutParams.PARENT_ID;
postImage.setLayoutParams(layoutParams); postImage.setLayoutParams(layoutParams);
postImage.setHierarchy(new GenericDraweeHierarchyBuilder(resources) postImage.setHierarchy(new GenericDraweeHierarchyBuilder(resources)
.setActualImageScaleType(ScalingUtils.ScaleType.FIT_CENTER) .setActualImageScaleType(ScalingUtils.ScaleType.FIT_CENTER)
@ -823,8 +825,7 @@ public class PostViewV2Fragment extends Fragment implements EditTextDialogFragme
} }
}; };
postImage.setTapListener(tapListener); postImage.setTapListener(tapListener);
// postImage.setAllowTouchInterceptionWhileZoomed(true); binding.postContainer.addView(postView);
binding.contentRoot.addView(postImage, 0);
} }
private void setupSlider() { private void setupSlider() {
@ -833,8 +834,9 @@ public class PostViewV2Fragment extends Fragment implements EditTextDialogFragme
final Context context = getContext(); final Context context = getContext();
if (context == null) return; if (context == null) return;
sliderParent = new ViewPager2(context); sliderParent = new ViewPager2(context);
final NullSafePair<Integer, Integer> maxHW = media final List<Media> carouselMedia = media.getCarouselMedia();
.getCarouselMedia() if (carouselMedia == null) return;
final NullSafePair<Integer, Integer> maxHW = carouselMedia
.stream() .stream()
.reduce(new NullSafePair<>(0, 0), .reduce(new NullSafePair<>(0, 0),
(prev, m) -> { (prev, m) -> {
@ -854,13 +856,10 @@ public class PostViewV2Fragment extends Fragment implements EditTextDialogFragme
originalHeight = widthHeight.second; originalHeight = widthHeight.second;
final ConstraintLayout.LayoutParams layoutParams = new ConstraintLayout.LayoutParams(ConstraintLayout.LayoutParams.MATCH_PARENT, final ConstraintLayout.LayoutParams layoutParams = new ConstraintLayout.LayoutParams(ConstraintLayout.LayoutParams.MATCH_PARENT,
originalHeight); originalHeight);
layoutParams.topToBottom = binding.topBarrier.getId();
layoutParams.bottomToTop = bottom.buttonsTopBarrier.getId();
layoutParams.startToStart = ConstraintLayout.LayoutParams.PARENT_ID;
layoutParams.endToEnd = ConstraintLayout.LayoutParams.PARENT_ID;
sliderParent.setLayoutParams(layoutParams); sliderParent.setLayoutParams(layoutParams);
postView = sliderParent; postView = sliderParent;
binding.contentRoot.addView(sliderParent, 0); // binding.contentRoot.addView(sliderParent, 0);
binding.postContainer.addView(postView);
final boolean hasVideo = media.getCarouselMedia() final boolean hasVideo = media.getCarouselMedia()
.stream() .stream()
@ -997,7 +996,7 @@ public class PostViewV2Fragment extends Fragment implements EditTextDialogFragme
} }
} }
}); });
final String text = "1/" + media.getCarouselMedia().size(); final String text = "1/" + carouselMedia.size();
binding.mediaCounter.setText(text); binding.mediaCounter.setText(text);
sliderItemsAdapter.submitList(media.getCarouselMedia()); sliderItemsAdapter.submitList(media.getCarouselMedia());
} }
@ -1040,12 +1039,8 @@ public class PostViewV2Fragment extends Fragment implements EditTextDialogFragme
layoutParams.width = ConstraintLayout.LayoutParams.MATCH_PARENT; layoutParams.width = ConstraintLayout.LayoutParams.MATCH_PARENT;
originalHeight = widthHeight.second; originalHeight = widthHeight.second;
layoutParams.height = originalHeight; layoutParams.height = originalHeight;
layoutParams.topToBottom = binding.topBarrier.getId();
layoutParams.bottomToTop = bottom.buttonsTopBarrier.getId();
layoutParams.startToStart = ConstraintLayout.LayoutParams.PARENT_ID;
layoutParams.endToEnd = ConstraintLayout.LayoutParams.PARENT_ID;
postView = videoPost.getRoot(); postView = videoPost.getRoot();
binding.contentRoot.addView(postView, 0); binding.postContainer.addView(postView);
// final GestureDetector gestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() { // final GestureDetector gestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
// @Override // @Override
@ -1279,16 +1274,16 @@ public class PostViewV2Fragment extends Fragment implements EditTextDialogFragme
binding.getRoot().setBackground(colorDrawable); binding.getRoot().setBackground(colorDrawable);
if (postView != null) { if (postView != null) {
// Make post match parent // Make post match parent
final ViewGroup.LayoutParams layoutParams = postView.getLayoutParams(); final int fullHeight = Utils.displayMetrics.heightPixels - Utils.getStatusBarHeight(context);
final int fullHeight = Utils.displayMetrics.heightPixels + Utils.getNavigationBarSize(context).y; postView.getLayoutParams().height = fullHeight;
layoutParams.height = fullHeight; binding.postContainer.getLayoutParams().height = fullHeight;
binding.contentRoot.getLayoutParams().height = fullHeight;
if (playerView != null) { if (playerView != null) {
playerViewOriginalHeight = playerView.getLayoutParams().height; playerViewOriginalHeight = playerView.getLayoutParams().height;
playerView.getLayoutParams().height = fullHeight; playerView.getLayoutParams().height = fullHeight;
} }
} }
detailsVisible = false; detailsVisible = false;
if (media.getUser() != null) { if (media.getUser() != null) {
binding.profilePic.setVisibility(View.GONE); binding.profilePic.setVisibility(View.GONE);
binding.title.setVisibility(View.GONE); binding.title.setVisibility(View.GONE);
@ -1322,9 +1317,8 @@ public class PostViewV2Fragment extends Fragment implements EditTextDialogFragme
} }
if (postView != null) { if (postView != null) {
// Make post height back to original // Make post height back to original
final ViewGroup.LayoutParams layoutParams = postView.getLayoutParams(); postView.getLayoutParams().height = originalHeight;
layoutParams.height = originalHeight; binding.postContainer.getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT;
binding.contentRoot.getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT;
if (playerView != null) { if (playerView != null) {
playerView.getLayoutParams().height = playerViewOriginalHeight; playerView.getLayoutParams().height = playerViewOriginalHeight;
playerView = null; playerView = null;
@ -1395,23 +1389,17 @@ public class PostViewV2Fragment extends Fragment implements EditTextDialogFragme
if (toolbar != null) { if (toolbar != null) {
toolbar.setVisibility(View.GONE); toolbar.setVisibility(View.GONE);
} }
final View decorView = activity.getWindow().getDecorView(); final BottomNavigationView bottomNavView = activity.getBottomNavView();
originalSystemUi = decorView.getSystemUiVisibility(); bottomNavView.setVisibility(View.GONE);
decorView.setSystemUiVisibility( binding.getRoot().setPadding(binding.getRoot().getPaddingLeft(),
View.SYSTEM_UI_FLAG_IMMERSIVE binding.getRoot().getPaddingTop(),
// Set the content to appear under the system bars so that the binding.getRoot().getPaddingRight(),
// content doesn't resize when the system bars hide and show. 0);
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE controller.hide(WindowInsetsCompat.Type.systemBars());
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION controller.setSystemBarsBehavior(WindowInsetsControllerCompat.BEHAVIOR_SHOW_BARS_BY_SWIPE);
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
// Hide the nav bar and status bar
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN);
isInFullScreenMode = true; isInFullScreenMode = true;
} }
// 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() { private void showSystemUI() {
if (!detailsVisible) { if (!detailsVisible) {
toggleDetails(); toggleDetails();
@ -1430,10 +1418,16 @@ public class PostViewV2Fragment extends Fragment implements EditTextDialogFragme
if (toolbar != null) { if (toolbar != null) {
toolbar.setVisibility(View.VISIBLE); toolbar.setVisibility(View.VISIBLE);
} }
final Window window = activity.getWindow(); final BottomNavigationView bottomNavView = activity.getBottomNavView();
final View decorView = window.getDecorView(); bottomNavView.setVisibility(View.VISIBLE);
decorView.setSystemUiVisibility(originalSystemUi); final Context context = getContext();
WindowCompat.setDecorFitsSystemWindows(window, false); if (context == null) return;
binding.getRoot().setPadding(binding.getRoot().getPaddingLeft(),
binding.getRoot().getPaddingTop(),
binding.getRoot().getPaddingRight(),
Utils.getActionBarHeight(context));
controller.show(WindowInsetsCompat.Type.systemBars());
WindowCompat.setDecorFitsSystemWindows(activity.getWindow(), false);
isInFullScreenMode = false; isInFullScreenMode = false;
} }

View File

@ -75,6 +75,14 @@
app:barrierAllowsGoneWidgets="true" app:barrierAllowsGoneWidgets="true"
app:barrierDirection="bottom" /> app:barrierDirection="bottom" />
<FrameLayout
android:id="@+id/post_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toTopOf="@id/buttons_top_barrier"
app:layout_constraintTop_toBottomOf="@id/top_barrier"
tools:layout_height="100dp" />
<androidx.appcompat.widget.AppCompatTextView <androidx.appcompat.widget.AppCompatTextView
android:id="@+id/media_counter" android:id="@+id/media_counter"
android:layout_width="wrap_content" android:layout_width="wrap_content"

View File

@ -9,7 +9,8 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:barrierAllowsGoneWidgets="true" app:barrierAllowsGoneWidgets="true"
app:barrierDirection="bottom" /> app:barrierDirection="bottom"
app:constraint_referenced_ids="post_container" />
<com.google.android.material.button.MaterialButton <com.google.android.material.button.MaterialButton
android:id="@+id/like" android:id="@+id/like"
@ -154,7 +155,7 @@
app:layout_constraintTop_toBottomOf="@id/buttons_bottom_barrier" app:layout_constraintTop_toBottomOf="@id/buttons_bottom_barrier"
tools:layout_constraintVertical_chainStyle="packed" tools:layout_constraintVertical_chainStyle="packed"
tools:text="2020-11-07 11:18:55" tools:text="2020-11-07 11:18:55"
tools:visibility="visible" /> tools:visibility="gone" />
<androidx.appcompat.widget.AppCompatTextView <androidx.appcompat.widget.AppCompatTextView
android:id="@+id/views_count" android:id="@+id/views_count"
@ -166,14 +167,15 @@
app:layout_constraintStart_toEndOf="@id/date" app:layout_constraintStart_toEndOf="@id/date"
app:layout_constraintTop_toTopOf="@id/date" app:layout_constraintTop_toTopOf="@id/date"
tools:text="9999999999 views" tools:text="9999999999 views"
tools:visibility="visible" /> tools:visibility="gone" />
<androidx.constraintlayout.widget.Barrier <androidx.constraintlayout.widget.Barrier
android:id="@+id/caption_barrier" android:id="@+id/caption_barrier"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="0dp" android:layout_height="0dp"
app:barrierAllowsGoneWidgets="true" app:barrierAllowsGoneWidgets="true"
app:barrierDirection="bottom" /> app:barrierDirection="bottom"
app:constraint_referenced_ids="like,likes_count,comment,comments_count,space_1,share,save,download" />
<awais.instagrabber.customviews.RamboTextViewV2 <awais.instagrabber.customviews.RamboTextViewV2
android:id="@+id/caption" android:id="@+id/caption"