Skip to content

Commit

Permalink
Merge pull request #3602 from kiwix/Issue#3601
Browse files Browse the repository at this point in the history
Fixed: Made a small improvement to the sidebar entries for "About the app" and "Support app."
  • Loading branch information
kelson42 authored Dec 16, 2023
2 parents bff68c0 + dcc8a40 commit e33edbe
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,6 @@ class ZimHostRobot : BaseRobot() {
}

private fun pauseForBetterTestPerformance() {
BaristaSleepInteractions.sleep(TestUtils.TEST_PAUSE_MS.toLong())
BaristaSleepInteractions.sleep(TestUtils.TEST_PAUSE_MS_FOR_DOWNLOAD_TEST.toLong())
}
}
6 changes: 4 additions & 2 deletions buildSrc/src/main/kotlin/custom/CustomApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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()
Expand Down
1 change: 1 addition & 0 deletions buildSrc/src/main/kotlin/custom/CustomApps.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ fun ProductFlavors.create(customApps: List<CustomApp>) {
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}")
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
<string name="menu_read_aloud">Read aloud</string>
<string name="menu_read_aloud_stop">Stop reading aloud</string>
<string name="menu_support_kiwix">Support Kiwix</string>
<string name="menu_about_app">About the app</string>
<string name="menu_support_kiwix_for_custom_apps">Support %s</string>
<string name="menu_about_app">About %s app</string>
<string name="menu_wifi_hotspot">WiFi Hotspot</string>
<string name="save_media">Save Media</string>
<string name="save_media_error">An error occurred when trying to save the media!</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand Down

0 comments on commit e33edbe

Please sign in to comment.