From e5f58f20c74457a88c6c51ad121fba6408dd0d8a Mon Sep 17 00:00:00 2001 From: TwistedUmbrellaX Date: Mon, 18 Mar 2024 18:18:35 -0400 Subject: [PATCH] fix: undo all of the margin hacks Using 72dp as the height appears to have been a bit of a hack to appear beyond the navigation bar. In cases where the bar is not present, such as landscape, this left a gap between the bottom of the screen and bar. On API 23, the result was the opposite. All of this can be addressed by simply relying on the actual measurements and not compensating for compensation. --- app/src/main/AndroidManifest.xml | 2 + app/src/main/java/ani/dantotsu/Functions.kt | 7 + .../main/java/ani/dantotsu/MainActivity.kt | 10 +- .../dantotsu/media/MediaDetailsActivity.kt | 17 ++- .../ani/dantotsu/profile/ProfileActivity.kt | 15 +- .../dantotsu/profile/activity/FeedActivity.kt | 20 ++- .../main/res/layout-land/activity_media.xml | 128 +++++++++--------- app/src/main/res/layout/activity_feed.xml | 5 +- app/src/main/res/layout/activity_media.xml | 1 - app/src/main/res/layout/activity_profile.xml | 3 +- 10 files changed, 124 insertions(+), 84 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index cf650323..5e5e6c34 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -108,6 +108,7 @@ android:parentActivityName=".MainActivity" /> Unit) { diff --git a/app/src/main/java/ani/dantotsu/media/MediaDetailsActivity.kt b/app/src/main/java/ani/dantotsu/media/MediaDetailsActivity.kt index 9a528b80..a680dd63 100644 --- a/app/src/main/java/ani/dantotsu/media/MediaDetailsActivity.kt +++ b/app/src/main/java/ani/dantotsu/media/MediaDetailsActivity.kt @@ -5,6 +5,7 @@ import android.annotation.SuppressLint import android.app.Activity import android.content.Intent import android.graphics.Rect +import android.content.res.Configuration import android.os.Bundle import android.text.SpannableStringBuilder import android.util.TypedValue @@ -24,6 +25,7 @@ import androidx.core.text.bold import androidx.core.text.color import androidx.core.view.marginBottom import androidx.core.view.updateLayoutParams +import androidx.core.view.updateMargins import androidx.fragment.app.Fragment import androidx.fragment.app.FragmentManager import androidx.lifecycle.Lifecycle @@ -105,7 +107,7 @@ class MediaDetailsActivity : AppCompatActivity(), AppBarLayout.OnOffsetChangedLi //Ui init initActivity(this) - binding.mediaViewPager.updateLayoutParams { bottomMargin += navBarHeight } + binding.mediaViewPager.updateLayoutParams { bottomMargin = navBarHeight } val oldMargin = binding.mediaViewPager.marginBottom AndroidBug5497Workaround.assistActivity(this) { if (it) { @@ -120,6 +122,9 @@ class MediaDetailsActivity : AppCompatActivity(), AppBarLayout.OnOffsetChangedLi binding.mediaTabContainer.visibility = View.VISIBLE } } + val navBarMargin = if (resources.configuration.orientation == + Configuration.ORIENTATION_LANDSCAPE) navBarHeight else 0 + binding.mediaTabContainer.updateLayoutParams { rightMargin = navBarMargin } binding.mediaBanner.updateLayoutParams { height += statusBarHeight } binding.mediaBannerNoKen.updateLayoutParams { height += statusBarHeight } binding.mediaClose.updateLayoutParams { topMargin += statusBarHeight } @@ -432,6 +437,14 @@ class MediaDetailsActivity : AppCompatActivity(), AppBarLayout.OnOffsetChangedLi return R.id.info } + override fun onConfigurationChanged(newConfig: Configuration) { + super.onConfigurationChanged(newConfig) + val margin = if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) navBarHeight else 0 + val params : ViewGroup.MarginLayoutParams = + binding.mediaTabContainer.layoutParams as ViewGroup.MarginLayoutParams + params.updateMargins(right = margin) + } + override fun onResume() { if (this::tabLayout.isInitialized) { tabLayout.selectTab(selected) @@ -602,4 +615,4 @@ class MediaDetailsActivity : AppCompatActivity(), AppBarLayout.OnOffsetChangedLi companion object { var mediaSingleton: Media? = null } -} \ No newline at end of file +} diff --git a/app/src/main/java/ani/dantotsu/profile/ProfileActivity.kt b/app/src/main/java/ani/dantotsu/profile/ProfileActivity.kt index 78867e37..668af45a 100644 --- a/app/src/main/java/ani/dantotsu/profile/ProfileActivity.kt +++ b/app/src/main/java/ani/dantotsu/profile/ProfileActivity.kt @@ -3,6 +3,7 @@ package ani.dantotsu.profile import android.animation.ObjectAnimator import android.annotation.SuppressLint import android.content.Intent +import android.content.res.Configuration import android.os.Bundle import android.util.TypedValue import android.view.View @@ -11,6 +12,7 @@ import android.widget.PopupMenu import androidx.appcompat.app.AppCompatActivity import androidx.core.content.ContextCompat import androidx.core.view.updateLayoutParams +import androidx.core.view.updateMargins import androidx.fragment.app.Fragment import androidx.fragment.app.FragmentManager import androidx.lifecycle.Lifecycle @@ -56,7 +58,9 @@ class ProfileActivity : AppCompatActivity(), AppBarLayout.OnOffsetChangedListene setContentView(binding.root) screenWidth = resources.displayMetrics.widthPixels.toFloat() navBar = binding.profileNavBar - navBar.updateLayoutParams { bottomMargin = navBarHeight } + val navBarMargin = if (resources.configuration.orientation == + Configuration.ORIENTATION_LANDSCAPE) 0 else navBarHeight + navBar.updateLayoutParams { bottomMargin = navBarMargin } val feedTab = navBar.createTab(R.drawable.ic_round_filter_24, "Feed") val profileTab = navBar.createTab(R.drawable.ic_round_person_24, "Profile") @@ -279,6 +283,13 @@ class ProfileActivity : AppCompatActivity(), AppBarLayout.OnOffsetChangedListene } } + override fun onConfigurationChanged(newConfig: Configuration) { + super.onConfigurationChanged(newConfig) + val margin = if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) 0 else navBarHeight + val params : ViewGroup.MarginLayoutParams = navBar.layoutParams as ViewGroup.MarginLayoutParams + params.updateMargins(bottom = margin) + } + override fun onResume() { if (this::navBar.isInitialized) { navBar.selectTabAt(selected) @@ -301,4 +312,4 @@ class ProfileActivity : AppCompatActivity(), AppBarLayout.OnOffsetChangedListene else -> ProfileFragment.newInstance(user) } } -} \ No newline at end of file +} diff --git a/app/src/main/java/ani/dantotsu/profile/activity/FeedActivity.kt b/app/src/main/java/ani/dantotsu/profile/activity/FeedActivity.kt index 98f0492b..6a85c640 100644 --- a/app/src/main/java/ani/dantotsu/profile/activity/FeedActivity.kt +++ b/app/src/main/java/ani/dantotsu/profile/activity/FeedActivity.kt @@ -1,9 +1,11 @@ package ani.dantotsu.profile.activity +import android.content.res.Configuration import android.os.Bundle import android.view.ViewGroup import androidx.appcompat.app.AppCompatActivity import androidx.core.view.updateLayoutParams +import androidx.core.view.updateMargins import androidx.fragment.app.Fragment import androidx.fragment.app.FragmentManager import androidx.lifecycle.Lifecycle @@ -28,14 +30,16 @@ class FeedActivity : AppCompatActivity() { binding = ActivityFeedBinding.inflate(layoutInflater) setContentView(binding.root) navBar = binding.feedNavBar - navBar.updateLayoutParams { bottomMargin += navBarHeight } + val navBarMargin = if (resources.configuration.orientation == + Configuration.ORIENTATION_LANDSCAPE) 0 else navBarHeight + navBar.updateLayoutParams { bottomMargin = navBarMargin } val personalTab = navBar.createTab(R.drawable.ic_round_person_24, "Following") val globalTab = navBar.createTab(R.drawable.ic_globe_24, "Global") navBar.addTab(personalTab) navBar.addTab(globalTab) binding.listTitle.text = getString(R.string.activities) binding.feedViewPager.updateLayoutParams { - bottomMargin += navBarHeight + bottomMargin = navBarMargin topMargin += statusBarHeight } binding.listToolbar.updateLayoutParams { topMargin += statusBarHeight } @@ -61,6 +65,16 @@ class FeedActivity : AppCompatActivity() { } } + override fun onConfigurationChanged(newConfig: Configuration) { + super.onConfigurationChanged(newConfig) + val margin = if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) 0 else navBarHeight + val params : ViewGroup.MarginLayoutParams = + binding.feedViewPager.layoutParams as ViewGroup.MarginLayoutParams + val paramsNav : ViewGroup.MarginLayoutParams = navBar.layoutParams as ViewGroup.MarginLayoutParams + params.updateMargins(bottom = margin) + paramsNav.updateMargins(bottom = margin) + } + override fun onResume() { super.onResume() navBar.selectTabAt(selected) @@ -80,4 +94,4 @@ class FeedActivity : AppCompatActivity() { } } } -} \ No newline at end of file +} diff --git a/app/src/main/res/layout-land/activity_media.xml b/app/src/main/res/layout-land/activity_media.xml index 247c86a9..d0a94b53 100644 --- a/app/src/main/res/layout-land/activity_media.xml +++ b/app/src/main/res/layout-land/activity_media.xml @@ -6,71 +6,10 @@ android:layout_height="match_parent" android:orientation="horizontal"> - - - - - - - - - + android:layout_height="match_parent" + android:layout_weight="1"> + + + + + + + + + diff --git a/app/src/main/res/layout/activity_feed.xml b/app/src/main/res/layout/activity_feed.xml index 295a8a10..6537b261 100644 --- a/app/src/main/res/layout/activity_feed.xml +++ b/app/src/main/res/layout/activity_feed.xml @@ -43,14 +43,13 @@ android:id="@+id/feedViewPager" android:layout_width="match_parent" android:layout_height="match_parent" - android:layout_marginBottom="72dp" android:layout_marginTop="48dp" tools:ignore="SpeakableTextPresentCheck" /> - \ No newline at end of file + diff --git a/app/src/main/res/layout/activity_media.xml b/app/src/main/res/layout/activity_media.xml index 3f7708a6..4f9590ed 100644 --- a/app/src/main/res/layout/activity_media.xml +++ b/app/src/main/res/layout/activity_media.xml @@ -235,7 +235,6 @@ android:id="@+id/mediaViewPager" android:layout_width="match_parent" android:layout_height="match_parent" - android:layout_marginBottom="72dp" android:nestedScrollingEnabled="true" tools:ignore="SpeakableTextPresentCheck" /> diff --git a/app/src/main/res/layout/activity_profile.xml b/app/src/main/res/layout/activity_profile.xml index 5b61ea3d..b88d8778 100644 --- a/app/src/main/res/layout/activity_profile.xml +++ b/app/src/main/res/layout/activity_profile.xml @@ -276,7 +276,6 @@ @@ -292,7 +291,7 @@