Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a donation popup to our application. #3984

Merged
merged 5 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class DeepLinksTest : BaseActivityTest() {
prefIsTest = true
playStoreRestrictionPermissionDialog = false
putPrefLanguage("en")
lastDonationPopupShownInMilliSeconds = System.currentTimeMillis()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ class DownloadTest : BaseActivityTest() {
putBoolean(SharedPreferenceUtil.PREF_IS_TEST, true)
putBoolean(SharedPreferenceUtil.PREF_PLAY_STORE_RESTRICTION, false)
putString(SharedPreferenceUtil.PREF_LANG, "en")
putLong(
SharedPreferenceUtil.PREF_LAST_DONATION_POPUP_SHOWN_IN_MILLISECONDS,
System.currentTimeMillis()
)
}
activityScenario = ActivityScenario.launch(KiwixMainActivity::class.java).apply {
moveToState(Lifecycle.State.RESUMED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ class HelpFragmentTest : BaseActivityTest() {
handleLocaleChange(
it,
"en",
SharedPreferenceUtil(context)
SharedPreferenceUtil(context).apply {
lastDonationPopupShownInMilliSeconds = System.currentTimeMillis()
}
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ class InitialDownloadTest : BaseActivityTest() {
putBoolean(SharedPreferenceUtil.PREF_IS_TEST, true)
putBoolean(SharedPreferenceUtil.PREF_PLAY_STORE_RESTRICTION, false)
putString(SharedPreferenceUtil.PREF_LANG, "en")
putLong(
SharedPreferenceUtil.PREF_LAST_DONATION_POPUP_SHOWN_IN_MILLISECONDS,
System.currentTimeMillis()
)
}
activityScenario = ActivityScenario.launch(KiwixMainActivity::class.java).apply {
moveToState(Lifecycle.State.RESUMED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ class IntroFragmentTest : BaseActivityTest() {
PreferenceManager.getDefaultSharedPreferences(context).edit {
putBoolean(SharedPreferenceUtil.PREF_SHOW_INTRO, true)
putString(SharedPreferenceUtil.PREF_LANG, "en")
putLong(
SharedPreferenceUtil.PREF_LAST_DONATION_POPUP_SHOWN_IN_MILLISECONDS,
System.currentTimeMillis()
)
}
activityScenario = ActivityScenario.launch(KiwixMainActivity::class.java).apply {
moveToState(Lifecycle.State.RESUMED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ class LanguageFragmentTest {
putBoolean(SharedPreferenceUtil.PREF_WIFI_ONLY, false)
putBoolean(SharedPreferenceUtil.PREF_PLAY_STORE_RESTRICTION, false)
putString(SharedPreferenceUtil.PREF_LANG, "en")
putLong(
SharedPreferenceUtil.PREF_LAST_DONATION_POPUP_SHOWN_IN_MILLISECONDS,
System.currentTimeMillis()
)
}
ActivityScenario.launch(KiwixMainActivity::class.java).apply {
moveToState(Lifecycle.State.RESUMED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ class CopyMoveFileHandlerTest : BaseActivityTest() {
putBoolean(SharedPreferenceUtil.PREF_IS_TEST, true)
putBoolean(SharedPreferenceUtil.PREF_PLAY_STORE_RESTRICTION, false)
putString(SharedPreferenceUtil.PREF_LANG, "en")
putLong(
SharedPreferenceUtil.PREF_LAST_DONATION_POPUP_SHOWN_IN_MILLISECONDS,
System.currentTimeMillis()
)
}
activityScenario = ActivityScenario.launch(KiwixMainActivity::class.java).apply {
moveToState(Lifecycle.State.RESUMED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ class TopLevelDestinationTest : BaseActivityTest() {
putBoolean(SharedPreferenceUtil.PREF_SHOW_SHOWCASE, false)
putBoolean(SharedPreferenceUtil.PREF_PLAY_STORE_RESTRICTION, false)
putString(SharedPreferenceUtil.PREF_LANG, "en")
putLong(
SharedPreferenceUtil.PREF_LAST_DONATION_POPUP_SHOWN_IN_MILLISECONDS,
System.currentTimeMillis()
)
}
activityScenario = ActivityScenario.launch(KiwixMainActivity::class.java).apply {
moveToState(Lifecycle.State.RESUMED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ class MimeTypeTest : BaseActivityTest() {
putBoolean(SharedPreferenceUtil.PREF_WIFI_ONLY, false)
putBoolean(SharedPreferenceUtil.PREF_PLAY_STORE_RESTRICTION, false)
putString(SharedPreferenceUtil.PREF_LANG, "en")
putLong(
SharedPreferenceUtil.PREF_LAST_DONATION_POPUP_SHOWN_IN_MILLISECONDS,
System.currentTimeMillis()
)
}
activityScenario = ActivityScenario.launch(KiwixMainActivity::class.java).apply {
moveToState(Lifecycle.State.RESUMED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ class LocalLibraryTest : BaseActivityTest() {
putBoolean(SharedPreferenceUtil.PREF_SHOW_MANAGE_PERMISSION_DIALOG_ON_REFRESH, false)
putBoolean(SharedPreferenceUtil.PREF_PLAY_STORE_RESTRICTION, false)
putString(SharedPreferenceUtil.PREF_LANG, "en")
putLong(
SharedPreferenceUtil.PREF_LAST_DONATION_POPUP_SHOWN_IN_MILLISECONDS,
System.currentTimeMillis()
)
}
activityScenario = ActivityScenario.launch(KiwixMainActivity::class.java).apply {
moveToState(Lifecycle.State.RESUMED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ class NoteFragmentTest : BaseActivityTest() {
putBoolean(SharedPreferenceUtil.PREF_IS_TEST, true)
putBoolean(SharedPreferenceUtil.PREF_PLAY_STORE_RESTRICTION, false)
putString(SharedPreferenceUtil.PREF_LANG, "en")
putLong(
SharedPreferenceUtil.PREF_LAST_DONATION_POPUP_SHOWN_IN_MILLISECONDS,
System.currentTimeMillis()
)
}
activityScenario = ActivityScenario.launch(KiwixMainActivity::class.java).apply {
moveToState(Lifecycle.State.RESUMED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ class ImportBookmarkTest : BaseActivityTest() {
putBoolean(SharedPreferenceUtil.PREF_IS_TEST, true)
putBoolean(SharedPreferenceUtil.PREF_PLAY_STORE_RESTRICTION, false)
putString(SharedPreferenceUtil.PREF_LANG, "en")
putLong(
SharedPreferenceUtil.PREF_LAST_DONATION_POPUP_SHOWN_IN_MILLISECONDS,
System.currentTimeMillis()
)
}
activityScenario = ActivityScenario.launch(KiwixMainActivity::class.java).apply {
moveToState(Lifecycle.State.RESUMED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ class LibkiwixBookmarkTest : BaseActivityTest() {
putBoolean(SharedPreferenceUtil.PREF_IS_TEST, true)
putBoolean(SharedPreferenceUtil.PREF_PLAY_STORE_RESTRICTION, false)
putString(SharedPreferenceUtil.PREF_LANG, "en")
putLong(
SharedPreferenceUtil.PREF_LAST_DONATION_POPUP_SHOWN_IN_MILLISECONDS,
System.currentTimeMillis()
)
}
activityScenario = ActivityScenario.launch(KiwixMainActivity::class.java).apply {
moveToState(Lifecycle.State.RESUMED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ class NavigationHistoryTest : BaseActivityTest() {
putBoolean(SharedPreferenceUtil.PREF_IS_TEST, true)
putBoolean(SharedPreferenceUtil.PREF_PLAY_STORE_RESTRICTION, false)
putString(SharedPreferenceUtil.PREF_LANG, "en")
putLong(
SharedPreferenceUtil.PREF_LAST_DONATION_POPUP_SHOWN_IN_MILLISECONDS,
System.currentTimeMillis()
)
}
activityScenario = ActivityScenario.launch(KiwixMainActivity::class.java).apply {
moveToState(Lifecycle.State.RESUMED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ class EncodedUrlTest : BaseActivityTest() {
putBoolean(SharedPreferenceUtil.PREF_WIFI_ONLY, false)
putBoolean(SharedPreferenceUtil.PREF_PLAY_STORE_RESTRICTION, false)
putString(SharedPreferenceUtil.PREF_LANG, "en")
putLong(
SharedPreferenceUtil.PREF_LAST_DONATION_POPUP_SHOWN_IN_MILLISECONDS,
System.currentTimeMillis()
)
}
activityScenario = ActivityScenario.launch(KiwixMainActivity::class.java).apply {
moveToState(Lifecycle.State.RESUMED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ class SearchFragmentTest : BaseActivityTest() {
putBoolean(SharedPreferenceUtil.PREF_IS_TEST, true)
putBoolean(SharedPreferenceUtil.PREF_PLAY_STORE_RESTRICTION, false)
putString(SharedPreferenceUtil.PREF_LANG, "en")
putLong(
SharedPreferenceUtil.PREF_LAST_DONATION_POPUP_SHOWN_IN_MILLISECONDS,
System.currentTimeMillis()
)
}
activityScenario = ActivityScenario.launch(KiwixMainActivity::class.java).apply {
moveToState(Lifecycle.State.RESUMED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class KiwixSettingsFragmentTest {
SharedPreferenceUtil(it).apply {
setIsPlayStoreBuildType(true)
playStoreRestrictionPermissionDialog = false
lastDonationPopupShownInMilliSeconds = System.currentTimeMillis()
}
)
it.navigate(R.id.introFragment)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ class ZimHostFragmentTest {
prefIsTest = true
playStoreRestrictionPermissionDialog = false
putPrefLanguage("en")
lastDonationPopupShownInMilliSeconds = System.currentTimeMillis()
}
}
activityScenario = ActivityScenario.launch(KiwixMainActivity::class.java).apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ abstract class CoreMainActivity : BaseActivity(), WebViewProvider {
drawerContainerLayout.closeDrawer(drawerNavView)
}

private fun openSupportKiwixExternalLink() {
fun openSupportKiwixExternalLink() {
externalLinkOpener.openExternalUrl(KIWIX_SUPPORT_URL.toUri().browserIntent())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import android.view.MenuItem
import android.view.MotionEvent
import android.view.View
import android.view.View.GONE
import android.view.View.VISIBLE
import android.view.ViewGroup
import android.view.animation.AnimationUtils
Expand Down Expand Up @@ -133,6 +134,8 @@
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.DonationDialogHandler
import org.kiwix.kiwixmobile.core.utils.DonationDialogHandler.ShowDonationDialogCallback
import org.kiwix.kiwixmobile.core.utils.ExternalLinkOpener
import org.kiwix.kiwixmobile.core.utils.LanguageUtils
import org.kiwix.kiwixmobile.core.utils.LanguageUtils.Companion.getCurrentLocale
Expand Down Expand Up @@ -173,7 +176,8 @@
FragmentActivityExtensions,
WebViewProvider,
ReadAloudCallbacks,
NavigationHistoryClickListener {
NavigationHistoryClickListener,
ShowDonationDialogCallback {
protected val webViewList: MutableList<KiwixWebView> = ArrayList()
private val webUrlsProcessor = BehaviorProcessor.create<String>()
private var fragmentReaderBinding: FragmentReaderBinding? = null
Expand Down Expand Up @@ -227,6 +231,10 @@
@Inject
var alertDialogShower: DialogShower? = null

@JvmField
@Inject
var donationDialogHandler: DonationDialogHandler? = null

@JvmField
@Inject
var painter: DarkModeViewPainter? = null
Expand Down Expand Up @@ -297,6 +305,7 @@
private var tableDrawerAdapter: TableDrawerAdapter? = null
private var tableDrawerRight: RecyclerView? = null
private var tabCallback: ItemTouchHelper.Callback? = null
private var donationLayout: FrameLayout? = null
private var bookmarkingDisposable: Disposable? = null
private var isBookmarked = false
private lateinit var serviceConnection: ServiceConnection
Expand Down Expand Up @@ -389,6 +398,7 @@
) {
super.onViewCreated(view, savedInstanceState)
setupMenu()
donationDialogHandler?.setDonationDialogCallBack(this)
val activity = requireActivity() as AppCompatActivity?
activity?.let {
WebView(it).destroy() // Workaround for buggy webViews see #710
Expand Down Expand Up @@ -511,6 +521,7 @@
tabRecyclerView = findViewById(R.id.tab_switcher_recycler_view)
snackBarRoot = findViewById(R.id.snackbar_root)
bottomToolbarToc = findViewById(R.id.bottom_toolbar_toc)
donationLayout = findViewById(R.id.donation_layout)
}
}
}
Expand Down Expand Up @@ -1213,6 +1224,8 @@
unRegisterReadAloudService()
storagePermissionForNotesLauncher?.unregister()
storagePermissionForNotesLauncher = null
donationDialogHandler?.setDonationDialogCallBack(null)
donationDialogHandler = null
}

private fun unBindViewsAndBinding() {
Expand Down Expand Up @@ -1243,6 +1256,8 @@
closeAllTabsButton = null
tableDrawerRightContainer = null
fragmentReaderBinding = null
donationLayout?.removeAllViews()
donationLayout = null
}

private fun updateTableOfContents() {
Expand Down Expand Up @@ -1846,6 +1861,76 @@
if (tts == null) {
setUpTTS()
}
donationDialogHandler?.attemptToShowDonationPopup()
}

@Suppress("InflateParams", "MagicNumber")
protected open fun showDonationLayout() {
val donationCardView = layoutInflater.inflate(R.layout.layout_donation_bottom_sheet, null)
val layoutParams = FrameLayout.LayoutParams(
FrameLayout.LayoutParams.MATCH_PARENT,
FrameLayout.LayoutParams.WRAP_CONTENT
).apply {
val rightAndLeftMargin = requireActivity().resources.getDimensionPixelSize(
org.kiwix.kiwixmobile.core.R.dimen.activity_horizontal_margin

Check warning on line 1875 in core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt#L1869-L1875

Added lines #L1869 - L1875 were not covered by tests
)
setMargins(
rightAndLeftMargin,
0,
rightAndLeftMargin,
getBottomMarginForDonationPopup()

Check warning on line 1881 in core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt#L1877-L1881

Added lines #L1877 - L1881 were not covered by tests
)
}

Check warning on line 1883 in core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt#L1883

Added line #L1883 was not covered by tests

donationCardView.layoutParams = layoutParams

Check warning on line 1885 in core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt#L1885

Added line #L1885 was not covered by tests
donationLayout?.apply {
removeAllViews()
addView(donationCardView)
setDonationLayoutVisibility(VISIBLE)
}
donationCardView.findViewById<TextView>(R.id.descriptionText).apply {
text = getString(
R.string.donation_dialog_description,
(requireActivity() as CoreMainActivity).appName

Check warning on line 1894 in core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt#L1887-L1894

Added lines #L1887 - L1894 were not covered by tests
)
}
val donateButton: TextView = donationCardView.findViewById(R.id.donateButton)
donateButton.setOnClickListener {

Check warning on line 1898 in core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt#L1896-L1898

Added lines #L1896 - L1898 were not covered by tests
donationDialogHandler?.updateLastDonationPopupShownTime()
setDonationLayoutVisibility(GONE)
openKiwixSupportUrl()
}

Check warning on line 1902 in core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt#L1900-L1902

Added lines #L1900 - L1902 were not covered by tests

val laterButton: TextView = donationCardView.findViewById(R.id.laterButton)
laterButton.setOnClickListener {

Check warning on line 1905 in core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt#L1904-L1905

Added lines #L1904 - L1905 were not covered by tests
donationDialogHandler?.donateLater()
setDonationLayoutVisibility(GONE)
}
}

Check warning on line 1909 in core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt#L1907-L1909

Added lines #L1907 - L1909 were not covered by tests

private fun getBottomMarginForDonationPopup(): Int {
var bottomMargin = requireActivity().resources.getDimensionPixelSize(
R.dimen.donation_popup_bottom_margin

Check warning on line 1913 in core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt#L1912-L1913

Added lines #L1912 - L1913 were not covered by tests
)
val bottomAppBar = requireActivity()
.findViewById<BottomAppBar>(R.id.bottom_toolbar)

Check warning on line 1916 in core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt#L1915-L1916

Added lines #L1915 - L1916 were not covered by tests
if (bottomAppBar.visibility == VISIBLE) {
// if bottomAppBar is visible then add the height of the bottomAppBar.
bottomMargin += requireActivity().resources.getDimensionPixelSize(
R.dimen.material_minimum_height_and_width

Check warning on line 1920 in core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt#L1919-L1920

Added lines #L1919 - L1920 were not covered by tests
)
bottomMargin += requireActivity().resources.getDimensionPixelSize(R.dimen.card_margin)

Check warning on line 1922 in core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt#L1922

Added line #L1922 was not covered by tests
}

return bottomMargin

Check warning on line 1925 in core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt#L1925

Added line #L1925 was not covered by tests
}

protected open fun openKiwixSupportUrl() {
(requireActivity() as CoreMainActivity).openSupportKiwixExternalLink()
}

Check warning on line 1930 in core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt#L1929-L1930

Added lines #L1929 - L1930 were not covered by tests

private fun setDonationLayoutVisibility(visibility: Int) {
donationLayout?.visibility = visibility
}

private fun openFullScreenIfEnabled() {
Expand Down Expand Up @@ -2388,6 +2473,10 @@
unbindService()
}

override fun showDonationDialog() {
showDonationLayout()
}

Check warning on line 2478 in core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt#L2477-L2478

Added lines #L2477 - L2478 were not covered by tests

private fun bindService() {
requireActivity().bindService(
Intent(requireActivity(), ReadAloudService::class.java), serviceConnection,
Expand Down
Loading
Loading