diff --git a/buildSrc/src/main/kotlin/custom/CustomApp.kt b/buildSrc/src/main/kotlin/custom/CustomApp.kt index 801198bf9..f33089b14 100644 --- a/buildSrc/src/main/kotlin/custom/CustomApp.kt +++ b/buildSrc/src/main/kotlin/custom/CustomApp.kt @@ -34,7 +34,8 @@ data class CustomApp( val versionName: String, val disableSideBar: Boolean = false, val disableTabs: Boolean = false, - val disableReadAloud: Boolean = false + val disableReadAloud: Boolean = false, + val disableTitle: Boolean = false ) { constructor(name: String, parsedJson: JSONObject) : this( name, @@ -44,7 +45,8 @@ data class CustomApp( readVersionOrInfer(parsedJson), parsedJson.getAndCast("disable_sidebar") ?: false, parsedJson.getAndCast("disable_tabs") ?: false, - parsedJson.getAndCast("disable_read_aloud") ?: false + parsedJson.getAndCast("disable_read_aloud") ?: false, + parsedJson.getAndCast("disable_title") ?: false ) 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 b4b05bc81..f5cc84637 100644 --- a/buildSrc/src/main/kotlin/custom/CustomApps.kt +++ b/buildSrc/src/main/kotlin/custom/CustomApps.kt @@ -51,6 +51,7 @@ fun ProductFlavors.create(customApps: List) { buildConfigField("Boolean", "DISABLE_SIDEBAR", "${customApp.disableSideBar}") buildConfigField("Boolean", "DISABLE_TABS", "${customApp.disableTabs}") buildConfigField("Boolean", "DISABLE_READ_ALOUD", "${customApp.disableReadAloud}") + buildConfigField("Boolean", "DISABLE_TITLE", "${customApp.disableTitle}") configureStrings(customApp.displayName) } } diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt index e91cfcc70..2de4b8343 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt @@ -938,7 +938,15 @@ abstract class CoreReaderFragment : } } - private fun updateTitle() { + /** + * Sets the title for toolbar, controlling the title of toolbar. + * Subclasses like CustomReaderFragment override this method to provide custom + * behavior, such as hiding the title when configured not to show it. + * + * WARNING: If modifying this method, ensure thorough testing with custom apps + * to verify proper functionality. + */ + open fun updateTitle() { if (isAdded) { actionBar?.title = getValidTitle(zimReaderContainer?.zimFileTitle) } diff --git a/custom/src/main/java/org/kiwix/kiwixmobile/custom/main/CustomReaderFragment.kt b/custom/src/main/java/org/kiwix/kiwixmobile/custom/main/CustomReaderFragment.kt index 8f963aca7..e117b9146 100644 --- a/custom/src/main/java/org/kiwix/kiwixmobile/custom/main/CustomReaderFragment.kt +++ b/custom/src/main/java/org/kiwix/kiwixmobile/custom/main/CustomReaderFragment.kt @@ -57,6 +57,7 @@ class CustomReaderFragment : CoreReaderFragment() { var dialogShower: DialogShower? = null private var permissionRequiredDialog: Dialog? = null private var appSettingsLaunched = false + @Suppress("NestedBlockDepth") override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) if (enforcedLanguage()) { @@ -71,7 +72,14 @@ class CustomReaderFragment : CoreReaderFragment() { } with(activity as AppCompatActivity) { supportActionBar?.setDisplayHomeAsUpEnabled(true) - toolbar?.let { setupDrawerToggle(it) } + toolbar?.let { + setupDrawerToggle(it) + if (BuildConfig.DISABLE_TITLE) { + // if the title is disable then set the app logo to hamburger icon, + // see https://github.com/kiwix/kiwix-android/issues/3528#issuecomment-1814905330 + it.setNavigationIcon(R.mipmap.ic_launcher) + } + } } loadPageFromNavigationArguments() } @@ -239,6 +247,23 @@ class CustomReaderFragment : CoreReaderFragment() { super.configureWebViewSelectionHandler(menu) } + /** + * Overrides the method to configure the title of toolbar. When the "setting title" is disabled + * in a custom app, this function set the empty toolbar title. + */ + override fun updateTitle() { + if (BuildConfig.DISABLE_TITLE) { + // Set an empty title for the toolbar because we are handling the toolbar click on behalf of this title. + // Since we have increased the zone for triggering search suggestions (see https://github.com/kiwix/kiwix-android/pull/3566), + // we need to set this title for handling the toolbar click, + // even if it is empty. If we do not set up this title, + // the search screen will open if the user clicks on the toolbar from the tabs screen. + actionBar?.title = " " + } else { + super.updateTitle() + } + } + override fun createNewTab() { newMainPageTab() }