diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 78701ba78..04f8269fb 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -61,4 +61,4 @@ jobs: KEY_ALIAS: ${{ secrets.KEY_ALIAS }} KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }} KEY_STORE_PASSWORD: ${{ secrets.KEY_STORE_PASSWORD }} - run: ./gradlew publishReleaseBundle + run: ./gradlew publishPlayStoreBundle diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 9b9db8b5a..72702c9af 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -44,6 +44,7 @@ android { resValue("string", "app_search_string", "Search Kiwix") versionCode = generateVersionCode() versionName = generateVersionName() + manifestPlaceholders["permission"] = "android.permission.MANAGE_EXTERNAL_STORAGE" } lintOptions { isCheckDependencies = true @@ -53,14 +54,22 @@ android { getByName("debug") { multiDexKeepProguard = file("multidex-instrumentation-config.pro") buildConfigField("boolean", "KIWIX_ERROR_ACTIVITY", "false") + buildConfigField("boolean", "IS_PLAYSTORE", "false") } getByName("release") { buildConfigField("boolean", "KIWIX_ERROR_ACTIVITY", "true") + buildConfigField("boolean", "IS_PLAYSTORE", "false") if (properties.containsKey("disableSigning")) { signingConfig = null } } + create("playStore") { + initWith(getByName("release")) + matchingFallbacks = listOf("release") + buildConfigField("boolean", "IS_PLAYSTORE", "true") + manifestPlaceholders["permission"] = "android.permission.placeholder" + } } bundle { language { diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 3bc1f39af..9d8739a8b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -6,8 +6,7 @@ - + diff --git a/app/src/main/java/org/kiwix/kiwixmobile/main/KiwixMainActivity.kt b/app/src/main/java/org/kiwix/kiwixmobile/main/KiwixMainActivity.kt index 4bf34b77e..e724d14e6 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/main/KiwixMainActivity.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/main/KiwixMainActivity.kt @@ -33,6 +33,7 @@ import kotlinx.android.synthetic.main.activity_kiwix_main.bottom_nav_view import kotlinx.android.synthetic.main.activity_kiwix_main.drawer_nav_view import kotlinx.android.synthetic.main.activity_kiwix_main.navigation_container import kotlinx.android.synthetic.main.activity_kiwix_main.reader_drawer_nav_view +import org.kiwix.kiwixmobile.BuildConfig import org.kiwix.kiwixmobile.R import org.kiwix.kiwixmobile.core.base.FragmentActivityExtensions import org.kiwix.kiwixmobile.core.di.components.CoreComponent @@ -100,6 +101,7 @@ class KiwixMainActivity : CoreMainActivity() { if (sharedPreferenceUtil.showIntro()) { navigate(KiwixReaderFragmentDirections.actionReaderFragmentToIntroFragment()) } + sharedPreferenceUtil.setIsPlayStoreBuildType(BuildConfig.IS_PLAYSTORE) } override fun onSupportActionModeStarted(mode: ActionMode) { 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 ba91a0451..7add89e02 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 @@ -284,26 +284,30 @@ class LocalLibraryFragment : BaseFragment() { REQUEST_STORAGE_PERMISSION ) } else { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { - if (Environment.isExternalStorageManager()) { - // We already have permission!! - requestFileSystemCheck() - } else { - if (sharedPreferenceUtil.manageExternalFilesPermissionDialog) { - // We should only ask for first time, If the users wants to revoke settings - // then they can directly toggle this feature from settings screen - sharedPreferenceUtil.manageExternalFilesPermissionDialog = false - // Show Dialog and Go to settings to give permission - dialogShower.show( - KiwixDialog.ManageExternalFilesPermissionDialog, - { - this.activity?.let(FragmentActivity::navigateToSettings) - } - ) - } - } - } else { + if (sharedPreferenceUtil.isPlayStoreBuild) { requestFileSystemCheck() + } else { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { + if (Environment.isExternalStorageManager()) { + // We already have permission!! + requestFileSystemCheck() + } else { + if (sharedPreferenceUtil.manageExternalFilesPermissionDialog) { + // We should only ask for first time, If the users wants to revoke settings + // then they can directly toggle this feature from settings screen + sharedPreferenceUtil.manageExternalFilesPermissionDialog = false + // Show Dialog and Go to settings to give permission + dialogShower.show( + KiwixDialog.ManageExternalFilesPermissionDialog, + { + this.activity?.let(FragmentActivity::navigateToSettings) + } + ) + } + } + } else { + requestFileSystemCheck() + } } } } diff --git a/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/OnlineLibraryFragment.kt b/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/OnlineLibraryFragment.kt index 17fa04cc9..cc4ba3adf 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/OnlineLibraryFragment.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/OnlineLibraryFragment.kt @@ -300,16 +300,24 @@ class OnlineLibraryFragment : BaseFragment(), FragmentActivityExtensions { ) sharedPreferenceUtil.putStoragePosition(INTERNAL_SELECT_POSITION) } else { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { - val view = LayoutInflater.from(activity).inflate(R.layout.select_folder_dialog, null) - dialogShower.show(SelectFolder { view }, ::selectFolder) + if (sharedPreferenceUtil.isPlayStoreBuild) { + setExternalStoragePath(storageDevice) } else { - sharedPreferenceUtil.putPrefStorage(storageDevice.name) - sharedPreferenceUtil.putStoragePosition(EXTERNAL_SELECT_POSITION) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { + val view = LayoutInflater.from(activity).inflate(R.layout.select_folder_dialog, null) + dialogShower.show(SelectFolder { view }, ::selectFolder) + } else { + setExternalStoragePath(storageDevice) + } } } } + private fun setExternalStoragePath(storageDevice: StorageDevice) { + sharedPreferenceUtil.putPrefStorage(storageDevice.name) + sharedPreferenceUtil.putStoragePosition(EXTERNAL_SELECT_POSITION) + } + private fun selectFolder() { val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE) intent.addFlags( diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/settings/CorePrefsFragment.java b/core/src/main/java/org/kiwix/kiwixmobile/core/settings/CorePrefsFragment.java index 7b7cebb82..e31627df5 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/settings/CorePrefsFragment.java +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/settings/CorePrefsFragment.java @@ -292,21 +292,30 @@ public abstract class CorePrefsFragment extends PreferenceFragmentCompat impleme findPreference(PREF_STORAGE).setTitle(getString(R.string.internal_storage)); sharedPreferenceUtil.putStoragePosition(INTERNAL_SELECT_POSITION); } else { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { - @SuppressLint("InflateParams") View view = LayoutInflater.from(getActivity()).inflate(R.layout.select_folder_dialog, null); - alertDialogShower.show(new KiwixDialog.SelectFolder(() -> view), () -> { - selectFolder(); - return Unit.INSTANCE; - }); + if (sharedPreferenceUtil.isPlayStoreBuild()) { + setExternalStoragePath(storageDevice); } else { - sharedPreferenceUtil.putPrefStorage(storageDevice.getName()); - findPreference(PREF_STORAGE).setTitle(getString(R.string.external_storage)); - sharedPreferenceUtil.putStoragePosition(EXTERNAL_SELECT_POSITION); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { + @SuppressLint("InflateParams") View view = + LayoutInflater.from(getActivity()).inflate(R.layout.select_folder_dialog, null); + alertDialogShower.show(new KiwixDialog.SelectFolder(() -> view), () -> { + selectFolder(); + return Unit.INSTANCE; + }); + } else { + setExternalStoragePath(storageDevice); + } } } return Unit.INSTANCE; } + private void setExternalStoragePath(StorageDevice storageDevice) { + sharedPreferenceUtil.putPrefStorage(storageDevice.getName()); + findPreference(PREF_STORAGE).setTitle(getString(R.string.external_storage)); + sharedPreferenceUtil.putStoragePosition(EXTERNAL_SELECT_POSITION); + } + private void selectFolder() { Intent intent = new Intent(ACTION_OPEN_DOCUMENT_TREE); intent.addFlags( 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 b7d0b67db..2bc9badf9 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 @@ -70,6 +70,9 @@ class SharedPreferenceUtil @Inject constructor(val context: Context) { val prefExternalLinkPopup: Boolean get() = sharedPreferences.getBoolean(PREF_EXTERNAL_LINK_POPUP, true) + val isPlayStoreBuild: Boolean + get() = sharedPreferences.getBoolean(IS_PLAY_STORE_BUILD, false) + val prefLanguage: String get() = sharedPreferences.getString(PREF_LANG, "") ?: Locale.ROOT.toString() @@ -121,6 +124,10 @@ class SharedPreferenceUtil @Inject constructor(val context: Context) { sharedPreferences.edit { putInt(STORAGE_POSITION, pos) } } + fun setIsPlayStoreBuildType(isPlayStoreBuildType: Boolean) { + sharedPreferences.edit { putBoolean(IS_PLAY_STORE_BUILD, isPlayStoreBuildType) } + } + fun putPrefFullScreen(fullScreen: Boolean) = sharedPreferences.edit { putBoolean(PREF_FULLSCREEN, fullScreen) } @@ -174,7 +181,10 @@ class SharedPreferenceUtil @Inject constructor(val context: Context) { } fun getPublicDirectoryPath(path: String): String = - path.substringBefore(context.getString(R.string.android_directory_seperator)) + if (isPlayStoreBuild) + path + else + path.substringBefore(context.getString(R.string.android_directory_seperator)) companion object { // Prefs @@ -197,5 +207,6 @@ class SharedPreferenceUtil @Inject constructor(val context: Context) { private const val TEXT_ZOOM = "true_text_zoom" private const val DEFAULT_ZOOM = 100 private const val PREF_MANAGE_EXTERNAL_FILES = "pref_manage_external_files" + private const val IS_PLAY_STORE_BUILD = "is_play_store_build" } }