From 300f68115680c397e771edaa42683a3c98934fea Mon Sep 17 00:00:00 2001 From: MohitMaliFtechiz Date: Mon, 7 Oct 2024 14:29:42 +0530 Subject: [PATCH] Fixed: The donation popup does not look well in tablet. * Added a maximum width for large screen devices such as tablets. If the device has a large screen, the donation popup will be set to the maximum width, ensuring a consistent appearance similar to mobile phones. --- .../core/extensions/ActivityExtensions.kt | 4 +++ .../core/main/CoreReaderFragment.kt | 25 ++++++++++++++++++- .../core/utils/DonationDialogHandler.kt | 4 ++- core/src/main/res/values/dimens.xml | 1 + 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/extensions/ActivityExtensions.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/extensions/ActivityExtensions.kt index 7c3538271c..61faf006d1 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/extensions/ActivityExtensions.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/extensions/ActivityExtensions.kt @@ -23,6 +23,7 @@ import android.annotation.SuppressLint import android.app.Activity import android.content.Intent import android.content.pm.PackageManager +import android.content.res.Configuration import android.os.Build import android.os.Bundle import android.os.Environment @@ -185,4 +186,7 @@ object ActivityExtensions { } else { true } + + fun Activity.isLandScapeMode(): Boolean = + resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE } diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt index 00a4015ab1..6bf336600c 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt @@ -40,6 +40,8 @@ import android.os.Looper import android.provider.Settings import android.util.AttributeSet import android.view.ActionMode +import android.view.Gravity.BOTTOM +import android.view.Gravity.CENTER_HORIZONTAL import android.view.LayoutInflater import android.view.Menu import android.view.MenuInflater @@ -73,6 +75,7 @@ import androidx.core.content.ContextCompat import androidx.core.view.GravityCompat import androidx.core.view.MenuHost import androidx.core.view.MenuProvider +import androidx.core.view.isVisible import androidx.core.widget.ContentLoadingProgressBar import androidx.drawerlayout.widget.DrawerLayout import androidx.lifecycle.Lifecycle @@ -102,6 +105,7 @@ import org.kiwix.kiwixmobile.core.dao.LibkiwixBookmarks import org.kiwix.kiwixmobile.core.databinding.FragmentReaderBinding import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.consumeObservable import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.hasNotificationPermission +import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.isLandScapeMode import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.observeNavigationResult import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.requestNotificationPermission import org.kiwix.kiwixmobile.core.extensions.ViewGroupExtensions.findFirstTextView @@ -134,6 +138,7 @@ import org.kiwix.kiwixmobile.core.reader.ZimReaderSource import org.kiwix.kiwixmobile.core.search.viewmodel.effects.SearchItemToOpen import org.kiwix.kiwixmobile.core.utils.AnimationUtils.rotate import org.kiwix.kiwixmobile.core.utils.DimenUtils.getToolbarHeight +import org.kiwix.kiwixmobile.core.utils.DimenUtils.getWindowWidth import org.kiwix.kiwixmobile.core.utils.DonationDialogHandler import org.kiwix.kiwixmobile.core.utils.DonationDialogHandler.ShowDonationDialogCallback import org.kiwix.kiwixmobile.core.utils.ExternalLinkOpener @@ -1868,7 +1873,7 @@ abstract class CoreReaderFragment : protected open fun showDonationLayout() { val donationCardView = layoutInflater.inflate(R.layout.layout_donation_bottom_sheet, null) val layoutParams = FrameLayout.LayoutParams( - FrameLayout.LayoutParams.MATCH_PARENT, + getDonationPopupWidth(), FrameLayout.LayoutParams.WRAP_CONTENT ).apply { val rightAndLeftMargin = requireActivity().resources.getDimensionPixelSize( @@ -1880,6 +1885,7 @@ abstract class CoreReaderFragment : rightAndLeftMargin, getBottomMarginForDonationPopup() ) + gravity = BOTTOM or CENTER_HORIZONTAL } donationCardView.layoutParams = layoutParams @@ -1908,6 +1914,19 @@ abstract class CoreReaderFragment : } } + private fun getDonationPopupWidth(): Int { + val deviceWidth = requireActivity().getWindowWidth() + val maximumDonationLayoutWidth = + requireActivity().resources.getDimensionPixelSize(R.dimen.maximum_donation_popup_width) + return when { + deviceWidth > maximumDonationLayoutWidth || requireActivity().isLandScapeMode() -> { + maximumDonationLayoutWidth + } + + else -> FrameLayout.LayoutParams.MATCH_PARENT + } + } + private fun getBottomMarginForDonationPopup(): Int { var bottomMargin = requireActivity().resources.getDimensionPixelSize( R.dimen.donation_popup_bottom_margin @@ -2108,6 +2127,10 @@ abstract class CoreReaderFragment : super.onConfigurationChanged(newConfig) // Forcing redraw of RecyclerView children so that the tabs are properly oriented on rotation tabRecyclerView?.adapter = tabsAdapter + // force redraw of donation layout if it is showing. + if (donationLayout?.isVisible == true) { + showDonationLayout() + } } private fun searchForTitle(title: String?, openInNewTab: Boolean) { diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/utils/DonationDialogHandler.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/utils/DonationDialogHandler.kt index c924a8d8e7..75e0dec317 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/utils/DonationDialogHandler.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/utils/DonationDialogHandler.kt @@ -50,7 +50,9 @@ class DonationDialogHandler @Inject constructor( } } - private fun shouldShowInitialPopup(lastPopupMillis: Long): Boolean = lastPopupMillis == 0L + private fun shouldShowInitialPopup(lastPopupMillis: Long): Boolean = + lastPopupMillis == 0L && isZimFilesAvailableInLibrary() + private fun isTimeToShowDonation(currentMillis: Long): Boolean = isLaterNotClicked() || isLaterPeriodOver(currentMillis) diff --git a/core/src/main/res/values/dimens.xml b/core/src/main/res/values/dimens.xml index aea27dfc0b..f570f844b2 100644 --- a/core/src/main/res/values/dimens.xml +++ b/core/src/main/res/values/dimens.xml @@ -25,4 +25,5 @@ 24dp 13dp 20dp + 400dp