From 2423b6b683111ef6e86690fcf0e8aa423b6b9770 Mon Sep 17 00:00:00 2001 From: MohitMaliFtechiz Date: Fri, 15 Dec 2023 16:44:25 +0530 Subject: [PATCH] * Fixed: Made a small improvement to the sidebar entries for "About the app" and "Support app." * Introduced the 'Support kiwix' option, which is configurable in the navigation for custom apps. If the custom app is set to display the "Support" menu item in navigation, it will be shown; otherwise, it will be hidden from the app. * Replaced the "kiwix" and "the" prefixes in "Support kiwix" and "About the app" with the app name in the navigation. --- buildSrc/src/main/kotlin/custom/CustomApp.kt | 6 +- buildSrc/src/main/kotlin/custom/CustomApps.kt | 1 + core/src/main/res/values/strings.xml | 3 +- .../custom/main/CustomMainActivity.kt | 55 ++++++++++++++++--- 4 files changed, 53 insertions(+), 12 deletions(-) diff --git a/buildSrc/src/main/kotlin/custom/CustomApp.kt b/buildSrc/src/main/kotlin/custom/CustomApp.kt index 48539e6f70..4c2041fcd4 100644 --- a/buildSrc/src/main/kotlin/custom/CustomApp.kt +++ b/buildSrc/src/main/kotlin/custom/CustomApp.kt @@ -37,7 +37,8 @@ data class CustomApp( val disableReadAloud: Boolean = false, val disableTitle: Boolean = false, val disableExternalLinks: Boolean = false, - val aboutAppUrl: String = "" + val aboutAppUrl: String = "", + val supportUrl: String = "" ) { constructor(name: String, parsedJson: JSONObject) : this( name, @@ -50,7 +51,8 @@ data class CustomApp( parsedJson.getAndCast("disable_read_aloud") ?: false, parsedJson.getAndCast("disable_title") ?: false, parsedJson.getAndCast("disable_external_links") ?: false, - parsedJson.getAndCast("about_app_url") ?: "" + parsedJson.getAndCast("about_app_url") ?: "", + parsedJson.getAndCast("support_url") ?: "" ) val versionCode: Int = formatCurrentDate("YYDDD0").toInt() diff --git a/buildSrc/src/main/kotlin/custom/CustomApps.kt b/buildSrc/src/main/kotlin/custom/CustomApps.kt index 5ba802a52d..d13c848278 100644 --- a/buildSrc/src/main/kotlin/custom/CustomApps.kt +++ b/buildSrc/src/main/kotlin/custom/CustomApps.kt @@ -47,6 +47,7 @@ fun ProductFlavors.create(customApps: List) { buildConfigField("String", "ZIM_URL", "\"${customApp.url}\"") buildConfigField("String", "ENFORCED_LANG", "\"${customApp.enforcedLanguage}\"") buildConfigField("String", "ABOUT_APP_URL", "\"${customApp.aboutAppUrl}\"") + buildConfigField("String", "SUPPORT_URL", "\"${customApp.supportUrl}\"") // Add asset file name in buildConfig file, we will use later to receive the zim file. buildConfigField("String", "PLAY_ASSET_FILE", "\"${customApp.name}.zim\"") buildConfigField("Boolean", "DISABLE_SIDEBAR", "${customApp.disableSideBar}") diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml index dfe288cdd8..2084cb4d7d 100644 --- a/core/src/main/res/values/strings.xml +++ b/core/src/main/res/values/strings.xml @@ -11,7 +11,8 @@ Read aloud Stop reading aloud Support Kiwix - About the app + Support %s + About %s app WiFi Hotspot Save Media An error occurred when trying to save the media! diff --git a/custom/src/main/java/org/kiwix/kiwixmobile/custom/main/CustomMainActivity.kt b/custom/src/main/java/org/kiwix/kiwixmobile/custom/main/CustomMainActivity.kt index 520422447a..b9337fb99b 100644 --- a/custom/src/main/java/org/kiwix/kiwixmobile/custom/main/CustomMainActivity.kt +++ b/custom/src/main/java/org/kiwix/kiwixmobile/custom/main/CustomMainActivity.kt @@ -119,11 +119,32 @@ class CustomMainActivity : CoreMainActivity() { menu.findItem(R.id.menu_help)?.isVisible = false /** - * If custom app is configured to show the "About the app" in navigation - * then show it navigation. + * If custom app is configured to show the "About app_name app" in navigation + * then show it navigation. "app_name" will be replaced with custom app name. */ if (BuildConfig.ABOUT_APP_URL.isNotEmpty()) { - menu.findItem(R.id.menu_about_app)?.isVisible = true + menu.findItem(R.id.menu_about_app)?.apply { + title = getString(R.string.menu_about_app, getString(R.string.app_name)) + isVisible = true + } + } + + /** + * If custom app is configured to show the "Support app_name" in navigation + * then show it navigation. "app_name" will be replaced with custom app name. + */ + if (BuildConfig.SUPPORT_URL.isNotEmpty()) { + menu.findItem(R.id.menu_support_kiwix)?.apply { + title = + getString(R.string.menu_support_kiwix_for_custom_apps, getString(R.string.app_name)) + isVisible = true + } + } else { + /** + * If custom app is not configured to show the "Support app_name" in navigation + * then hide it from navigation. + */ + menu.findItem(R.id.menu_support_kiwix)?.isVisible = false } setNavigationItemSelectedListener { item -> closeNavigationDrawer() @@ -133,15 +154,31 @@ class CustomMainActivity : CoreMainActivity() { } /** - * Overrides the method to configure the click of `About the app` - * When the "About the app" is enabled - * in a custom app, this function handled that click. + * Overrides the method to configure the click behavior of the "About the app" + * and "Support URL" features. When the "About the app" and "Support URL" + * are enabled in a custom app, this function handles those clicks. */ override fun onNavigationItemSelected(item: MenuItem): Boolean { - if (item.itemId == R.id.menu_about_app) { - externalLinkOpener.openExternalUrl(BuildConfig.ABOUT_APP_URL.toUri().browserIntent()) + return when (item.itemId) { + R.id.menu_about_app -> { + openExternalUrl(BuildConfig.ABOUT_APP_URL) + true + } + + R.id.menu_support_kiwix -> { + openExternalUrl(BuildConfig.SUPPORT_URL) + true + } + + else -> super.onNavigationItemSelected(item) + } + } + + private fun openExternalUrl(url: String) { + // check if the provided url is not empty. + if (url.isNotEmpty()) { + externalLinkOpener.openExternalUrl(url.toUri().browserIntent()) } - return super.onNavigationItemSelected(item) } override fun getIconResId() = R.mipmap.ic_launcher