From 25eab4e5fbb99715c77e0720234ae5080dab885c Mon Sep 17 00:00:00 2001 From: MohitMaliFtechiz Date: Wed, 13 Dec 2023 18:38:06 +0530 Subject: [PATCH] Introduced the 'About the app' option in the navigation for custom apps. * If the custom app is configured to display the 'About the app' option in navigation, it will be visible. Clicking on it will redirect the user to the configured URL. --- buildSrc/src/main/kotlin/custom/CustomApp.kt | 6 ++-- buildSrc/src/main/kotlin/custom/CustomApps.kt | 1 + .../main/res/drawable/ic_baseline_info.xml | 30 +++++++++++++++++++ core/src/main/res/menu/menu_drawer_main.xml | 7 +++++ core/src/main/res/values/strings.xml | 1 + .../custom/main/CustomMainActivity.kt | 24 +++++++++++++++ 6 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 core/src/main/res/drawable/ic_baseline_info.xml diff --git a/buildSrc/src/main/kotlin/custom/CustomApp.kt b/buildSrc/src/main/kotlin/custom/CustomApp.kt index 25eb40180..48539e6f7 100644 --- a/buildSrc/src/main/kotlin/custom/CustomApp.kt +++ b/buildSrc/src/main/kotlin/custom/CustomApp.kt @@ -36,7 +36,8 @@ data class CustomApp( val disableTabs: Boolean = false, val disableReadAloud: Boolean = false, val disableTitle: Boolean = false, - val disableExternalLinks: Boolean = false + val disableExternalLinks: Boolean = false, + val aboutAppUrl: String = "" ) { constructor(name: String, parsedJson: JSONObject) : this( name, @@ -48,7 +49,8 @@ data class CustomApp( parsedJson.getAndCast("disable_tabs") ?: false, parsedJson.getAndCast("disable_read_aloud") ?: false, parsedJson.getAndCast("disable_title") ?: false, - parsedJson.getAndCast("disable_external_links") ?: false + parsedJson.getAndCast("disable_external_links") ?: false, + parsedJson.getAndCast("about_app_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 ff16d2274..5ba802a52 100644 --- a/buildSrc/src/main/kotlin/custom/CustomApps.kt +++ b/buildSrc/src/main/kotlin/custom/CustomApps.kt @@ -46,6 +46,7 @@ fun ProductFlavors.create(customApps: List) { applicationIdSuffix = ".kiwixcustom${customApp.name}" buildConfigField("String", "ZIM_URL", "\"${customApp.url}\"") buildConfigField("String", "ENFORCED_LANG", "\"${customApp.enforcedLanguage}\"") + buildConfigField("String", "ABOUT_APP_URL", "\"${customApp.aboutAppUrl}\"") // 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/drawable/ic_baseline_info.xml b/core/src/main/res/drawable/ic_baseline_info.xml new file mode 100644 index 000000000..b9c284bb0 --- /dev/null +++ b/core/src/main/res/drawable/ic_baseline_info.xml @@ -0,0 +1,30 @@ + + + + + + + diff --git a/core/src/main/res/menu/menu_drawer_main.xml b/core/src/main/res/menu/menu_drawer_main.xml index 929dca42a..99977e194 100644 --- a/core/src/main/res/menu/menu_drawer_main.xml +++ b/core/src/main/res/menu/menu_drawer_main.xml @@ -51,6 +51,13 @@ android:icon="@drawable/ic_support_24px" android:title="@string/menu_support_kiwix" app:showAsAction="never" /> + + diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml index a03068b19..a5e756b18 100644 --- a/core/src/main/res/values/strings.xml +++ b/core/src/main/res/values/strings.xml @@ -11,6 +11,7 @@ Read aloud Stop reading aloud Support Kiwix + About the 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 d424fc627..520422447 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 @@ -19,14 +19,18 @@ package org.kiwix.kiwixmobile.custom.main import android.os.Bundle +import android.view.MenuItem import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.widget.Toolbar +import androidx.core.net.toUri import androidx.drawerlayout.widget.DrawerLayout import androidx.navigation.NavController import androidx.navigation.fragment.NavHostFragment import com.google.android.material.navigation.NavigationView import org.kiwix.kiwixmobile.core.di.components.CoreComponent +import org.kiwix.kiwixmobile.core.extensions.browserIntent import org.kiwix.kiwixmobile.core.main.CoreMainActivity +import org.kiwix.kiwixmobile.custom.BuildConfig import org.kiwix.kiwixmobile.custom.R import org.kiwix.kiwixmobile.custom.customActivityComponent import org.kiwix.kiwixmobile.custom.databinding.ActivityCustomMainBinding @@ -113,6 +117,14 @@ class CustomMainActivity : CoreMainActivity() { * For more information, see https://github.com/kiwix/kiwix-android/issues/3584 */ 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 (BuildConfig.ABOUT_APP_URL.isNotEmpty()) { + menu.findItem(R.id.menu_about_app)?.isVisible = true + } setNavigationItemSelectedListener { item -> closeNavigationDrawer() onNavigationItemSelected(item) @@ -120,5 +132,17 @@ 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. + */ + override fun onNavigationItemSelected(item: MenuItem): Boolean { + if (item.itemId == R.id.menu_about_app) { + externalLinkOpener.openExternalUrl(BuildConfig.ABOUT_APP_URL.toUri().browserIntent()) + } + return super.onNavigationItemSelected(item) + } + override fun getIconResId() = R.mipmap.ic_launcher }