diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/download/DownloadTest.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/download/DownloadTest.kt index 4d2db7b40..08e5a1bd9 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/download/DownloadTest.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/download/DownloadTest.kt @@ -73,6 +73,7 @@ class DownloadTest : BaseActivityTest() { putBoolean(SharedPreferenceUtil.PREF_SHOW_STORAGE_OPTION, false) putBoolean(SharedPreferenceUtil.IS_PLAY_STORE_BUILD, true) putBoolean(SharedPreferenceUtil.PREF_IS_TEST, true) + putBoolean(SharedPreferenceUtil.PREF_PLAY_STORE_RESTRICTION, false) } activityScenario = ActivityScenario.launch(KiwixMainActivity::class.java).apply { moveToState(Lifecycle.State.RESUMED) diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/help/HelpFragmentTest.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/help/HelpFragmentTest.kt index 59a2b09f0..f3c514096 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/help/HelpFragmentTest.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/help/HelpFragmentTest.kt @@ -17,23 +17,32 @@ */ package org.kiwix.kiwixmobile.help +import android.os.Build +import androidx.core.content.edit import androidx.lifecycle.Lifecycle +import androidx.preference.PreferenceManager import androidx.test.core.app.ActivityScenario +import androidx.test.espresso.IdlingRegistry import androidx.test.platform.app.InstrumentationRegistry import androidx.test.uiautomator.UiDevice import leakcanary.LeakAssertions +import org.junit.After import org.junit.Before import org.junit.Rule import org.junit.Test import org.kiwix.kiwixmobile.BaseActivityTest import org.kiwix.kiwixmobile.R +import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil import org.kiwix.kiwixmobile.main.KiwixMainActivity import org.kiwix.kiwixmobile.testutils.RetryRule import org.kiwix.kiwixmobile.testutils.TestUtils.closeSystemDialogs import org.kiwix.kiwixmobile.testutils.TestUtils.isSystemUINotRespondingDialogVisible +import org.kiwix.kiwixmobile.utils.KiwixIdlingResource class HelpFragmentTest : BaseActivityTest() { + private lateinit var sharedPreferenceUtil: SharedPreferenceUtil + @Before override fun waitForIdle() { UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()).apply { @@ -53,6 +62,7 @@ class HelpFragmentTest : BaseActivityTest() { @Test fun verifyHelpActivity() { + setShowPlayStoreRestriction(false) activityScenario.onActivity { it.navigate(R.id.helpFragment) } @@ -66,8 +76,55 @@ class HelpFragmentTest : BaseActivityTest() { clickOnHowToUpdateContent() assertHowToUpdateContentIsExpanded() clickOnHowToUpdateContent() + assertZimFileNotShowingIsNotVisible() clickOnSendFeedback() } LeakAssertions.assertNoLeaks() } + + @Test + fun verifyHelpActivityWithPlayStoreRestriction() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { + setShowPlayStoreRestriction(true) + activityScenario.onActivity { + it.navigate(R.id.helpFragment) + } + help { + clickOnWhatDoesKiwixDo() + assertWhatDoesKiwixDoIsExpanded() + clickOnWhatDoesKiwixDo() + clickOnWhereIsContent() + assertWhereIsContentIsExpanded() + clickOnWhereIsContent() + clickOnHowToUpdateContent() + assertHowToUpdateContentIsExpanded() + clickOnHowToUpdateContent() + clickOnZimFileNotShowing() + assertZimFileNotShowingIsExpanded() + clickOnZimFileNotShowing() + clickOnSendFeedback() + } + LeakAssertions.assertNoLeaks() + } + } + + private fun setShowPlayStoreRestriction(showRestriction: Boolean) { + context.let { + sharedPreferenceUtil = SharedPreferenceUtil(it).apply { + setIntroShown() + putPrefWifiOnly(false) + setIsPlayStoreBuildType(showRestriction) + prefIsTest = true + } + } + } + + @After + fun finish() { + IdlingRegistry.getInstance().unregister(KiwixIdlingResource.getInstance()) + PreferenceManager.getDefaultSharedPreferences(context).edit { + putBoolean(SharedPreferenceUtil.IS_PLAY_STORE_BUILD, false) + putBoolean(SharedPreferenceUtil.PREF_IS_TEST, false) + } + } } diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/help/HelpRobot.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/help/HelpRobot.kt index efbc89db0..cc5bdc8c4 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/help/HelpRobot.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/help/HelpRobot.kt @@ -17,6 +17,9 @@ */ package org.kiwix.kiwixmobile.help +import androidx.test.espresso.Espresso.onView +import androidx.test.espresso.assertion.ViewAssertions.doesNotExist +import androidx.test.espresso.matcher.ViewMatchers.withText import org.kiwix.kiwixmobile.BaseRobot import org.kiwix.kiwixmobile.Findable.StringId.TextId import org.kiwix.kiwixmobile.Findable.Text @@ -78,6 +81,19 @@ class HelpRobot : BaseRobot() { clickOn(ViewId(id.activity_help_feedback_text_view)) } + fun clickOnZimFileNotShowing() { + clickOn(TextId(string.zim_files_not_showing)) + } + + fun assertZimFileNotShowingIsExpanded() { + isVisible(TextId(string.zim_files_not_showing_description)) + } + + fun assertZimFileNotShowingIsNotVisible() { + onView(withText("Zim files not showing?")) + .check(doesNotExist()) + } + private fun helpTextFormat(vararg stringIds: Int) = stringIds.joinToString(separator = "\n", transform = context::getString) } diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/initial/download/InitialDownloadTest.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/initial/download/InitialDownloadTest.kt index eb7531ec2..bed20071d 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/initial/download/InitialDownloadTest.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/initial/download/InitialDownloadTest.kt @@ -63,6 +63,7 @@ class InitialDownloadTest : BaseActivityTest() { putBoolean(SharedPreferenceUtil.PREF_SHOW_STORAGE_OPTION, true) putBoolean(SharedPreferenceUtil.IS_PLAY_STORE_BUILD, true) putBoolean(SharedPreferenceUtil.PREF_IS_TEST, true) + putBoolean(SharedPreferenceUtil.PREF_PLAY_STORE_RESTRICTION, false) } activityScenario = ActivityScenario.launch(KiwixMainActivity::class.java).apply { moveToState(Lifecycle.State.RESUMED) diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/language/LanguageFragmentTest.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/language/LanguageFragmentTest.kt index e49692736..79300b463 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/language/LanguageFragmentTest.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/language/LanguageFragmentTest.kt @@ -75,6 +75,7 @@ class LanguageFragmentTest { .edit { putBoolean(SharedPreferenceUtil.PREF_SHOW_INTRO, false) putBoolean(SharedPreferenceUtil.PREF_WIFI_ONLY, false) + putBoolean(SharedPreferenceUtil.PREF_PLAY_STORE_RESTRICTION, false) } } diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/localFileTransfer/LocalFileTransferTest.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/localFileTransfer/LocalFileTransferTest.kt index c27e3f077..9364beb3e 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/localFileTransfer/LocalFileTransferTest.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/localFileTransfer/LocalFileTransferTest.kt @@ -166,6 +166,7 @@ class LocalFileTransferTest { putBoolean(SharedPreferenceUtil.PREF_WIFI_ONLY, false) putBoolean(SharedPreferenceUtil.PREF_IS_TEST, true) putBoolean(SharedPreferenceUtil.PREF_SHOW_SHOWCASE, shouldShowShowCase) + putBoolean(SharedPreferenceUtil.PREF_PLAY_STORE_RESTRICTION, false) } if (isResetShowCaseId) { // To clear showCaseID to ensure the showcase view will show. diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/main/TopLevelDestinationTest.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/main/TopLevelDestinationTest.kt index 147dd0313..400542c36 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/main/TopLevelDestinationTest.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/main/TopLevelDestinationTest.kt @@ -61,6 +61,7 @@ class TopLevelDestinationTest : BaseActivityTest() { putBoolean(SharedPreferenceUtil.PREF_IS_TEST, true) putBoolean(SharedPreferenceUtil.PREF_EXTERNAL_LINK_POPUP, true) putBoolean(SharedPreferenceUtil.PREF_SHOW_SHOWCASE, false) + putBoolean(SharedPreferenceUtil.PREF_PLAY_STORE_RESTRICTION, false) } activityScenario = ActivityScenario.launch(KiwixMainActivity::class.java).apply { moveToState(Lifecycle.State.RESUMED) diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/mimetype/MimeTypeTest.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/mimetype/MimeTypeTest.kt index f007019c0..948374a6b 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/mimetype/MimeTypeTest.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/mimetype/MimeTypeTest.kt @@ -52,6 +52,7 @@ class MimeTypeTest : BaseActivityTest() { PreferenceManager.getDefaultSharedPreferences(context).edit { putBoolean(SharedPreferenceUtil.PREF_SHOW_INTRO, false) putBoolean(SharedPreferenceUtil.PREF_WIFI_ONLY, false) + putBoolean(SharedPreferenceUtil.PREF_PLAY_STORE_RESTRICTION, false) } activityScenario = ActivityScenario.launch(KiwixMainActivity::class.java).apply { moveToState(Lifecycle.State.RESUMED) diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/nav/destination/PlayStoreRestrictionDialogRobot.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/nav/destination/PlayStoreRestrictionDialogRobot.kt new file mode 100644 index 000000000..c2d7a39fc --- /dev/null +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/nav/destination/PlayStoreRestrictionDialogRobot.kt @@ -0,0 +1,65 @@ +/* + * Kiwix Android + * Copyright (c) 2023 Kiwix + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package org.kiwix.kiwixmobile.nav.destination + +import androidx.test.espresso.Espresso.onView +import androidx.test.espresso.action.ViewActions.click +import androidx.test.espresso.assertion.ViewAssertions.doesNotExist +import androidx.test.espresso.assertion.ViewAssertions.matches +import androidx.test.espresso.matcher.ViewMatchers.withText +import androidx.test.espresso.matcher.ViewMatchers.isDisplayed +import applyWithViewHierarchyPrinting +import com.adevinta.android.barista.interaction.BaristaSleepInteractions +import org.kiwix.kiwixmobile.BaseRobot +import org.kiwix.kiwixmobile.Findable.ViewId +import org.kiwix.kiwixmobile.R +import org.kiwix.kiwixmobile.testutils.TestUtils + +fun playStoreRestriction(func: PlayStoreRestrictionDialogRobot.() -> Unit) = + PlayStoreRestrictionDialogRobot().applyWithViewHierarchyPrinting(func) + +class PlayStoreRestrictionDialogRobot : BaseRobot() { + + fun clickLibraryOnBottomNav() { + pauseForBetterTestPerformance() + clickOn(ViewId(R.id.libraryFragment)) + } + + fun assertPlayStoreRestrictionDialogDisplayed() { + pauseForBetterTestPerformance() + onView(withText("UNDERSTOOD")) + .check(matches(isDisplayed())) + } + + fun assetPlayStoreRestrictionDialogNotDisplayed() { + pauseForBetterTestPerformance() + onView(withText("UNDERSTOOD")) + .check(doesNotExist()) + } + + fun clickOnUnderstood() { + pauseForBetterTestPerformance() + onView(withText("UNDERSTOOD")) + .perform(click()) + } + + private fun pauseForBetterTestPerformance() { + BaristaSleepInteractions.sleep(TestUtils.TEST_PAUSE_MS.toLong()) + } +} diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/nav/destination/PlayStoreRestrictionDialogTest.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/nav/destination/PlayStoreRestrictionDialogTest.kt new file mode 100644 index 000000000..495a4a26b --- /dev/null +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/nav/destination/PlayStoreRestrictionDialogTest.kt @@ -0,0 +1,121 @@ +/* + * Kiwix Android + * Copyright (c) 2023 Kiwix + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package org.kiwix.kiwixmobile.nav.destination + +import android.Manifest +import android.content.Context +import android.os.Build +import androidx.lifecycle.Lifecycle +import androidx.test.core.app.ActivityScenario +import androidx.test.platform.app.InstrumentationRegistry +import androidx.test.rule.GrantPermissionRule +import androidx.test.uiautomator.UiDevice +import leakcanary.LeakAssertions +import org.junit.Before +import org.junit.Rule +import org.junit.Test +import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil +import org.kiwix.kiwixmobile.main.KiwixMainActivity +import org.kiwix.kiwixmobile.testutils.RetryRule +import org.kiwix.kiwixmobile.testutils.TestUtils + +class PlayStoreRestrictionDialogTest { + @Rule + @JvmField + var retryRule = RetryRule() + + private lateinit var sharedPreferenceUtil: SharedPreferenceUtil + + private lateinit var activityScenario: ActivityScenario + + private val permissions = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + arrayOf( + Manifest.permission.READ_EXTERNAL_STORAGE, + Manifest.permission.WRITE_EXTERNAL_STORAGE, + Manifest.permission.NEARBY_WIFI_DEVICES + ) + } else { + arrayOf( + Manifest.permission.READ_EXTERNAL_STORAGE, + Manifest.permission.WRITE_EXTERNAL_STORAGE, + Manifest.permission.ACCESS_COARSE_LOCATION, + Manifest.permission.ACCESS_FINE_LOCATION + ) + } + + @Rule + @JvmField + var permissionRules: GrantPermissionRule = + GrantPermissionRule.grant(*permissions) + private var context: Context? = null + + @Before + fun waitForIdle() { + context = InstrumentationRegistry.getInstrumentation().targetContext + UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()).apply { + if (TestUtils.isSystemUINotRespondingDialogVisible(this)) { + TestUtils.closeSystemDialogs(context) + } + waitForIdle() + } + } + + @Test + fun showPlayStoreRestrictionDialog() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { + setShowPlayStoreRestrictionDialog(true) + activityScenario = ActivityScenario.launch(KiwixMainActivity::class.java).apply { + moveToState(Lifecycle.State.RESUMED) + } + playStoreRestriction { + clickLibraryOnBottomNav() + assertPlayStoreRestrictionDialogDisplayed() + clickOnUnderstood() + } + LeakAssertions.assertNoLeaks() + } + } + + @Test + fun testPlayStoreDialogShowOnlyOnce() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { + setShowPlayStoreRestrictionDialog(false) + activityScenario = ActivityScenario.launch(KiwixMainActivity::class.java).apply { + moveToState(Lifecycle.State.RESUMED) + } + playStoreRestriction { + clickLibraryOnBottomNav() + assetPlayStoreRestrictionDialogNotDisplayed() + } + LeakAssertions.assertNoLeaks() + } + } + + private fun setShowPlayStoreRestrictionDialog(showDialog: Boolean) { + context?.let { + sharedPreferenceUtil = SharedPreferenceUtil(it).apply { + setIntroShown() + putPrefWifiOnly(false) + setIsPlayStoreBuildType(true) + prefIsTest = true + playStoreRestrictionPermissionDialog = showDialog + } + } + } +} diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/nav/destination/library/LocalLibraryTest.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/nav/destination/library/LocalLibraryTest.kt index 583f33732..65f39e17a 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/nav/destination/library/LocalLibraryTest.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/nav/destination/library/LocalLibraryTest.kt @@ -70,6 +70,7 @@ class LocalLibraryTest : BaseActivityTest() { // the manage external storage permission dialog on Android 11 and above // while refreshing the content in LocalLibraryFragment. putBoolean(SharedPreferenceUtil.PREF_SHOW_MANAGE_PERMISSION_DIALOG_ON_REFRESH, false) + putBoolean(SharedPreferenceUtil.PREF_PLAY_STORE_RESTRICTION, false) } activityScenario = ActivityScenario.launch(KiwixMainActivity::class.java).apply { moveToState(Lifecycle.State.RESUMED) diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/page/history/NavigationHistoryTest.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/page/history/NavigationHistoryTest.kt index e2e1aa4c6..ab2d1c89d 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/page/history/NavigationHistoryTest.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/page/history/NavigationHistoryTest.kt @@ -63,6 +63,7 @@ class NavigationHistoryTest : BaseActivityTest() { putBoolean(SharedPreferenceUtil.PREF_SHOW_INTRO, false) putBoolean(SharedPreferenceUtil.PREF_WIFI_ONLY, false) putBoolean(SharedPreferenceUtil.PREF_IS_TEST, true) + putBoolean(SharedPreferenceUtil.PREF_PLAY_STORE_RESTRICTION, false) } activityScenario = ActivityScenario.launch(KiwixMainActivity::class.java).apply { moveToState(Lifecycle.State.RESUMED) diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/reader/KiwixReaderFragmentTest.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/reader/KiwixReaderFragmentTest.kt index 28466b8a3..3590d25b0 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/reader/KiwixReaderFragmentTest.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/reader/KiwixReaderFragmentTest.kt @@ -62,6 +62,7 @@ class KiwixReaderFragmentTest : BaseActivityTest() { putBoolean(SharedPreferenceUtil.PREF_SHOW_INTRO, false) putBoolean(SharedPreferenceUtil.PREF_WIFI_ONLY, false) putBoolean(SharedPreferenceUtil.PREF_IS_TEST, true) + putBoolean(SharedPreferenceUtil.PREF_PLAY_STORE_RESTRICTION, false) } activityScenario = ActivityScenario.launch(KiwixMainActivity::class.java).apply { moveToState(Lifecycle.State.RESUMED) diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/search/SearchFragmentTest.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/search/SearchFragmentTest.kt index 350d42ef0..d15df1e6f 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/search/SearchFragmentTest.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/search/SearchFragmentTest.kt @@ -62,6 +62,7 @@ class SearchFragmentTest : BaseActivityTest() { putBoolean(SharedPreferenceUtil.PREF_SHOW_INTRO, false) putBoolean(SharedPreferenceUtil.PREF_WIFI_ONLY, false) putBoolean(SharedPreferenceUtil.PREF_IS_TEST, true) + putBoolean(SharedPreferenceUtil.PREF_PLAY_STORE_RESTRICTION, false) } activityScenario = ActivityScenario.launch(KiwixMainActivity::class.java).apply { moveToState(Lifecycle.State.RESUMED) diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/webserver/ZimHostFragmentTest.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/webserver/ZimHostFragmentTest.kt index a359a4431..78f74903e 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/webserver/ZimHostFragmentTest.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/webserver/ZimHostFragmentTest.kt @@ -85,6 +85,7 @@ class ZimHostFragmentTest { putPrefWifiOnly(false) setIsPlayStoreBuildType(true) prefIsTest = true + playStoreRestrictionPermissionDialog = false } } activityScenario = ActivityScenario.launch(KiwixMainActivity::class.java).apply { diff --git a/app/src/main/java/org/kiwix/kiwixmobile/help/KiwixHelpFragment.kt b/app/src/main/java/org/kiwix/kiwixmobile/help/KiwixHelpFragment.kt index 9dedd6bd8..60f003439 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/help/KiwixHelpFragment.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/help/KiwixHelpFragment.kt @@ -22,9 +22,19 @@ import org.kiwix.kiwixmobile.core.R import org.kiwix.kiwixmobile.core.help.HelpFragment class KiwixHelpFragment : HelpFragment() { - override fun rawTitleDescriptionMap() = listOf( - R.string.help_2 to R.array.description_help_2, - R.string.help_5 to R.array.description_help_5, - R.string.how_to_update_content to R.array.update_content_description - ) + override fun rawTitleDescriptionMap() = + if (sharedPreferenceUtil.isPlayStoreBuildWithAndroid11OrAbove()) { + listOf( + R.string.help_2 to R.array.description_help_2, + R.string.help_5 to R.array.description_help_5, + R.string.how_to_update_content to R.array.update_content_description, + R.string.zim_files_not_showing to R.array.description_help_6 + ) + } else { + listOf( + R.string.help_2 to R.array.description_help_2, + R.string.help_5 to R.array.description_help_5, + R.string.how_to_update_content to R.array.update_content_description + ) + } } diff --git a/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/LocalLibraryFragment.kt b/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/LocalLibraryFragment.kt index 8b1ed5f8f..a8e049ad1 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/LocalLibraryFragment.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/LocalLibraryFragment.kt @@ -64,10 +64,12 @@ import org.kiwix.kiwixmobile.core.base.BaseFragment import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.isManageExternalStoragePermissionGranted import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.navigate import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.viewModel +import org.kiwix.kiwixmobile.core.extensions.browserIntent import org.kiwix.kiwixmobile.core.extensions.coreMainActivity import org.kiwix.kiwixmobile.core.extensions.setBottomMarginToFragmentContainerView import org.kiwix.kiwixmobile.core.extensions.toast import org.kiwix.kiwixmobile.core.main.CoreMainActivity +import org.kiwix.kiwixmobile.core.main.KIWIX_APK_WEBSITE_URL import org.kiwix.kiwixmobile.core.navigateToAppSettings import org.kiwix.kiwixmobile.core.navigateToSettings import org.kiwix.kiwixmobile.core.utils.LanguageUtils @@ -363,7 +365,11 @@ class LocalLibraryFragment : BaseFragment() { override fun onResume() { super.onResume() - if (!sharedPreferenceUtil.isPlayStoreBuildWithAndroid11OrAbove() && + if (sharedPreferenceUtil.isPlayStoreBuildWithAndroid11OrAbove() && + sharedPreferenceUtil.playStoreRestrictionPermissionDialog + ) { + showPlayStoreRestrictionInformationToUser() + } else if (!sharedPreferenceUtil.isPlayStoreBuildWithAndroid11OrAbove() && !sharedPreferenceUtil.prefIsTest && !permissionDeniedLayoutShowing ) { checkPermissions() @@ -372,6 +378,21 @@ class LocalLibraryFragment : BaseFragment() { } } + private fun showPlayStoreRestrictionInformationToUser() { + // We should only ask for first time + sharedPreferenceUtil.playStoreRestrictionPermissionDialog = false + // Show Dialog to the user to inform about the play store restriction + dialogShower.show( + KiwixDialog.PlayStoreRestrictionPopup, + {}, + ::openKiwixWebsiteForDownloadingApk + ) + } + + private fun openKiwixWebsiteForDownloadingApk() { + requireActivity().startActivity(KIWIX_APK_WEBSITE_URL.toUri().browserIntent()) + } + override fun onDestroyView() { super.onDestroyView() actionMode = null diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/help/HelpAdapter.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/help/HelpAdapter.kt index 904688a44..dadc3e034 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/help/HelpAdapter.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/help/HelpAdapter.kt @@ -18,6 +18,7 @@ package org.kiwix.kiwixmobile.core.help import android.animation.ObjectAnimator +import android.text.method.LinkMovementMethod import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -62,7 +63,10 @@ internal class HelpAdapter(titleDescriptionMap: Map) : override fun bind(item: HelpItem) { itemHelpBinding.itemHelpTitle.setOnClickListener { toggleDescriptionVisibility() } itemHelpBinding.itemHelpToggleExpand.setOnClickListener { toggleDescriptionVisibility() } - itemHelpBinding.itemHelpDescription.text = item.description + itemHelpBinding.itemHelpDescription.apply { + text = item.description + movementMethod = LinkMovementMethod.getInstance() + } itemHelpBinding.itemHelpTitle.text = item.title } } diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/help/HelpFragment.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/help/HelpFragment.kt index 3db5702af..0bcf66930 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/help/HelpFragment.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/help/HelpFragment.kt @@ -39,9 +39,13 @@ import org.kiwix.kiwixmobile.core.extensions.toast import org.kiwix.kiwixmobile.core.main.CoreMainActivity import org.kiwix.kiwixmobile.core.utils.CONTACT_EMAIL_ADDRESS import org.kiwix.kiwixmobile.core.utils.LanguageUtils.Companion.getCurrentLocale +import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil +import javax.inject.Inject @Suppress("UnnecessaryAbstractClass") abstract class HelpFragment : BaseFragment() { + @Inject + lateinit var sharedPreferenceUtil: SharedPreferenceUtil private var fragmentHelpBinding: FragmentHelpBinding? = null protected open fun rawTitleDescriptionMap(): List> = emptyList() override val fragmentToolbar: Toolbar? by lazy { diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreMainActivity.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreMainActivity.kt index 5d61f77ef..978816689 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreMainActivity.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreMainActivity.kt @@ -55,6 +55,7 @@ import javax.inject.Inject import kotlin.system.exitProcess const val KIWIX_SUPPORT_URL = "https://www.kiwix.org/support" +const val KIWIX_APK_WEBSITE_URL = "https://download.kiwix.org/release/kiwix-android/" const val PAGE_URL_KEY = "pageUrl" const val SHOULD_OPEN_IN_NEW_TAB = "shouldOpenInNewTab" const val FIND_IN_PAGE_SEARCH_STRING = "findInPageSearchString" diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/utils/SharedPreferenceUtil.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/utils/SharedPreferenceUtil.kt index 741e423be..212233689 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/utils/SharedPreferenceUtil.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/utils/SharedPreferenceUtil.kt @@ -206,6 +206,12 @@ class SharedPreferenceUtil @Inject constructor(val context: Context) { manageExternalFilesPermissionDialogOnRefresh ) } + var playStoreRestrictionPermissionDialog: Boolean + get() = sharedPreferences.getBoolean(PREF_PLAY_STORE_RESTRICTION, true) + set(playStoreRestrictionPermissionDialog) = + sharedPreferences.edit { + putBoolean(PREF_PLAY_STORE_RESTRICTION, playStoreRestrictionPermissionDialog) + } var hostedBooks: Set get() = sharedPreferences.getStringSet(PREF_HOSTED_BOOKS, null)?.toHashSet() ?: HashSet() @@ -266,5 +272,6 @@ class SharedPreferenceUtil @Inject constructor(val context: Context) { const val PREF_MANAGE_EXTERNAL_FILES = "pref_manage_external_files" const val PREF_SHOW_MANAGE_PERMISSION_DIALOG_ON_REFRESH = "pref_show_manage_external_files" const val IS_PLAY_STORE_BUILD = "is_play_store_build" + const val PREF_PLAY_STORE_RESTRICTION = "pref_play_store_restriction" } } diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/utils/dialog/KiwixDialog.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/utils/dialog/KiwixDialog.kt index b9cb22a67..6482ebec3 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/utils/dialog/KiwixDialog.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/utils/dialog/KiwixDialog.kt @@ -170,6 +170,14 @@ sealed class KiwixDialog( neutralMessage = R.string.do_not_ask_anymore ) + object PlayStoreRestrictionPopup : KiwixDialog( + null, + R.string.zim_files_not_showing_description, + R.string.understood, + R.string.download, + cancelable = false + ) + data class ShowRate(override val args: List, val customIcon: Int?) : KiwixDialog( R.string.rate_dialog_title, diff --git a/core/src/main/res/layout/item_help.xml b/core/src/main/res/layout/item_help.xml index a6a56cc28..4426a612d 100644 --- a/core/src/main/res/layout/item_help.xml +++ b/core/src/main/res/layout/item_help.xml @@ -35,6 +35,7 @@ android:paddingTop="@dimen/activity_vertical_margin" android:textColor="?textSecondary" android:visibility="gone" + android:autoLink="web" app:layout_constraintTop_toBottomOf="@id/item_help_title" tools:text="@string/help_3" tools:visibility="visible" /> diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml index a5e756b18..dfe288cdd 100644 --- a/core/src/main/res/values/strings.xml +++ b/core/src/main/res/values/strings.xml @@ -209,6 +209,9 @@ @string/help_10 @string/help_11 + + @string/zim_files_not_showing_description + View Bookmarks From All Books Search bookmarks Switch tabs @@ -300,6 +303,9 @@ Tabs restored Open Drawer Close Drawer + Zim files not showing? + Due to Google Play policies on Android 11 and above, this Google Store app can\’t open sideloaded ZIM files. You can either download them through the app or, instead, install the full version of kiwix app from our official website https://download.kiwix.org/release/kiwix-android/ + Understood How to update content? To update content (a zim file) you need to download the full latest version of this very same content. You can do that via the download section. All Files Permission Needed