Skip to content

Commit

Permalink
Merge pull request #4012 from kiwix/Fixes#3736
Browse files Browse the repository at this point in the history
Fixed: The donation popup does not look well in tablet.
  • Loading branch information
kelson42 authored Oct 8, 2024
2 parents fc1b8dd + 300f681 commit 83899c6
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -185,4 +186,7 @@ object ActivityExtensions {
} else {
true
}

fun Activity.isLandScapeMode(): Boolean =
resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -1880,6 +1885,7 @@ abstract class CoreReaderFragment :
rightAndLeftMargin,
getBottomMarginForDonationPopup()
)
gravity = BOTTOM or CENTER_HORIZONTAL
}

donationCardView.layoutParams = layoutParams
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
1 change: 1 addition & 0 deletions core/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@
<dimen name="close_tab_button_size">24dp</dimen>
<dimen name="find_in_page_button_padding">13dp</dimen>
<dimen name="donation_popup_bottom_margin">20dp</dimen>
<dimen name="maximum_donation_popup_width">400dp</dimen>
</resources>

0 comments on commit 83899c6

Please sign in to comment.