The app icon will no longer automatically be replaced with three lines after closing the tabs screen in custom apps when the custom app is configured not to show the title.

This commit is contained in:
MohitMaliFtechiz 2023-12-04 16:47:42 +05:30
parent 2c1c678819
commit 88475d8601
2 changed files with 45 additions and 15 deletions

View File

@ -64,6 +64,7 @@ import androidx.annotation.AnimRes
import androidx.appcompat.app.ActionBar
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.constraintlayout.widget.Group
import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.core.app.ActivityCompat
@ -183,6 +184,10 @@ abstract class CoreReaderFragment :
@BindView(R2.id.toolbar)
var toolbar: Toolbar? = null
@JvmField
@BindView(R2.id.toolbarWithSearchPlaceholder)
var toolbarWithSearchPlaceholder: ConstraintLayout? = null
@JvmField
@BindView(R2.id.fragment_main_app_bar)
var toolbarContainer: AppBarLayout? = null
@ -763,7 +768,7 @@ abstract class CoreReaderFragment :
actionBar?.apply {
setDisplayShowTitleEnabled(true)
}
toolbar?.let((requireActivity() as CoreMainActivity)::setupDrawerToggle)
toolbar?.let(::setUpDrawerToggle)
setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED)
closeAllTabsButton?.setImageDrawable(
ContextCompat.getDrawable(requireActivity(), R.drawable.ic_close_black_24dp)
@ -784,6 +789,18 @@ abstract class CoreReaderFragment :
setTopMarginToWebViews(0)
}
/**
* Sets the drawer toggle, controlling the toolbar.
* Subclasses like CustomReaderFragment override this method to provide custom
* behavior, such as set the app icon on hamburger when configure to not show the title.
*
* WARNING: If modifying this method, ensure thorough testing with custom apps
* to verify proper functionality.
*/
open fun setUpDrawerToggle(toolbar: Toolbar) {
toolbar.let((requireActivity() as CoreMainActivity)::setupDrawerToggle)
}
/**
* Sets the lock mode for the drawer, controlling whether the drawer can be opened or closed.
* Subclasses like CustomReaderFragment override this method to provide custom

View File

@ -23,12 +23,14 @@ import android.os.Bundle
import android.view.Menu
import android.view.MenuInflater
import android.view.View
import android.view.View.GONE
import android.view.View.VISIBLE
import android.widget.ImageView
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar
import androidx.drawerlayout.widget.DrawerLayout
import androidx.navigation.fragment.findNavController
import org.kiwix.kiwixmobile.core.base.BaseActivity
import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.setupDrawerToggle
import org.kiwix.kiwixmobile.core.extensions.getResizedDrawable
import org.kiwix.kiwixmobile.core.extensions.isFileExist
import org.kiwix.kiwixmobile.core.main.CoreReaderFragment
@ -75,23 +77,31 @@ class CustomReaderFragment : CoreReaderFragment() {
}
with(activity as AppCompatActivity) {
supportActionBar?.setDisplayHomeAsUpEnabled(true)
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
val iconSize =
resources.getDimensionPixelSize(dimen.hamburger_icon_size)
getResizedDrawable(R.mipmap.ic_launcher, iconSize, iconSize)?.let { drawable ->
it.navigationIcon = drawable
}
}
}
toolbar?.let(::setUpDrawerToggle)
}
loadPageFromNavigationArguments()
}
}
/**
* Overrides the method to configure the hamburger icon. When the "setting title" is disabled
* in a custom app, this function set the app logo on hamburger.
*/
override fun setUpDrawerToggle(toolbar: Toolbar) {
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
val iconSize =
resources.getDimensionPixelSize(dimen.hamburger_icon_size)
requireActivity().getResizedDrawable(R.mipmap.ic_launcher, iconSize, iconSize)
?.let { drawable ->
toolbar.navigationIcon = drawable
}
} else {
super.setUpDrawerToggle(toolbar)
}
}
private fun loadPageFromNavigationArguments() {
val args = CustomReaderFragmentArgs.fromBundle(requireArguments())
if (args.pageUrl.isNotEmpty()) {
@ -226,7 +236,8 @@ class CustomReaderFragment : CoreReaderFragment() {
urlIsValid(),
this,
BuildConfig.DISABLE_READ_ALOUD,
BuildConfig.DISABLE_TABS
BuildConfig.DISABLE_TABS,
BuildConfig.DISABLE_TITLE
)
}
}
@ -266,7 +277,9 @@ class CustomReaderFragment : CoreReaderFragment() {
// 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 = " "
toolbarWithSearchPlaceholder?.visibility = VISIBLE
} else {
toolbarWithSearchPlaceholder?.visibility = GONE
super.updateTitle()
}
}