Fixed: Impossible to download full Wikipedia in English.

* Updating the UI correctly when there is some error while creating the kiwixService(Specially when failed to connect with the server).
* Minor improvement in showing right drawer.
This commit is contained in:
MohitMaliFtechiz 2024-12-01 16:21:51 +05:30
parent 116180e6f0
commit c136380945
6 changed files with 22 additions and 14 deletions

View File

@ -83,7 +83,7 @@ class KiwixReaderFragment : CoreReaderFragment() {
)
}
activity.supportActionBar?.setDisplayHomeAsUpEnabled(true)
toolbar?.let(activity::setupDrawerToggle)
toolbar?.let { activity.setupDrawerToggle(it, true) }
setFragmentContainerBottomMarginToSizeOfNavBar()
openPageInBookFromNavigationArguments()
}
@ -167,7 +167,7 @@ class KiwixReaderFragment : CoreReaderFragment() {
override fun hideTabSwitcher() {
actionBar?.let { actionBar ->
actionBar.setDisplayShowTitleEnabled(true)
toolbar?.let { activity?.setupDrawerToggle(it) }
toolbar?.let { activity?.setupDrawerToggle(it, true) }
setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED)

View File

@ -205,11 +205,15 @@ class ZimManageViewModel @Inject constructor(
.callTimeout(CALL_TIMEOUT, SECONDS)
.addNetworkInterceptor(UserAgentInterceptor(USER_AGENT))
.build()
client.newCall(headRequest).execute().use { response ->
if (response.isSuccessful) {
return@getContentLengthOfLibraryXmlFile response.header("content-length")?.toLongOrNull()
?: DEFAULT_INT_VALUE.toLong()
try {
client.newCall(headRequest).execute().use { response ->
if (response.isSuccessful) {
return@getContentLengthOfLibraryXmlFile response.header("content-length")?.toLongOrNull()
?: DEFAULT_INT_VALUE.toLong()
}
}
} catch (ignore: Exception) {
// do nothing
}
return DEFAULT_INT_VALUE.toLong()
}

View File

@ -100,8 +100,8 @@ object ActivityExtensions {
val Activity.cachedComponent: CoreActivityComponent
get() = coreMainActivity.cachedComponent
fun Activity.setupDrawerToggle(toolbar: Toolbar) =
coreMainActivity.setupDrawerToggle(toolbar)
fun Activity.setupDrawerToggle(toolbar: Toolbar, shouldEnableRightDrawer: Boolean = false) =
coreMainActivity.setupDrawerToggle(toolbar, shouldEnableRightDrawer)
fun Activity.navigate(fragmentId: Int) {
coreMainActivity.navigate(fragmentId)

View File

@ -220,7 +220,7 @@ abstract class CoreMainActivity : BaseActivity(), WebViewProvider {
override fun onSupportNavigateUp(): Boolean =
navController.navigateUp() || super.onSupportNavigateUp()
open fun setupDrawerToggle(toolbar: Toolbar) {
open fun setupDrawerToggle(toolbar: Toolbar, shouldEnableRightDrawer: Boolean = false) {
// Set the initial contentDescription to the hamburger icon.
// This method is called from various locations after modifying the navigationIcon.
// For example, we previously changed this icon/contentDescription to the "+" button
@ -241,8 +241,10 @@ abstract class CoreMainActivity : BaseActivity(), WebViewProvider {
it.syncState()
}
drawerContainerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED)
// Enable the right drawer
drawerContainerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, GravityCompat.END)
if (shouldEnableRightDrawer) {
// Enable the right drawer
drawerContainerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, GravityCompat.END)
}
}
open fun disableDrawer() {

View File

@ -893,7 +893,9 @@ abstract class CoreReaderFragment :
* to verify proper functionality.
*/
open fun setUpDrawerToggle(toolbar: Toolbar) {
toolbar.let((requireActivity() as CoreMainActivity)::setupDrawerToggle)
toolbar.let {
(requireActivity() as CoreMainActivity).setupDrawerToggle(it, true)
}
}
/**

View File

@ -98,8 +98,8 @@ class CustomMainActivity : CoreMainActivity() {
}
}
override fun setupDrawerToggle(toolbar: Toolbar) {
super.setupDrawerToggle(toolbar)
override fun setupDrawerToggle(toolbar: Toolbar, shouldEnableRightDrawer: Boolean) {
super.setupDrawerToggle(toolbar, shouldEnableRightDrawer)
activityCustomMainBinding.drawerNavView.apply {
/**
* Hide the 'ZimHostFragment' option from the navigation menu