Adjusted the size of the hamburger icon. * To address unexpected behavior, where setting the icon directly to the hamburger resulted in it taking the full width and height of the toolbar, we resized the app icon and applied it to the hamburger icon.

This commit is contained in:
MohitMaliFtechiz 2023-12-01 21:30:52 +05:30 committed by MohitMaliFtechiz
parent f46f2f324b
commit cd7b988fe1
3 changed files with 50 additions and 1 deletions

View File

@ -21,9 +21,14 @@ package org.kiwix.kiwixmobile.core.extensions
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.graphics.Bitmap
import android.graphics.Canvas
import android.graphics.drawable.BitmapDrawable
import android.graphics.drawable.Drawable
import android.util.TypedValue
import android.widget.Toast
import androidx.annotation.AttrRes
import androidx.core.content.ContextCompat
import org.kiwix.kiwixmobile.core.base.BaseBroadcastReceiver
import java.util.Locale
@ -59,3 +64,40 @@ fun Context.getAttribute(@AttrRes attributeRes: Int) = with(TypedValue()) {
else
throw RuntimeException("invalid attribute $attributeRes")
}
fun Context.getResizedDrawable(resourceId: Int, width: Int, height: Int): Drawable? {
val drawable = ContextCompat.getDrawable(this, resourceId)
return if (drawable != null) {
val bitmap = Bitmap.createScaledBitmap(
getBitmapFromDrawable(drawable),
width,
height,
false
)
BitmapDrawable(resources, bitmap).apply {
bounds = drawable.bounds
}
} else {
null
}
}
fun Context.getBitmapFromDrawable(drawable: Drawable): Bitmap {
if (drawable is BitmapDrawable) {
return drawable.bitmap
}
val bitmap = Bitmap.createBitmap(
drawable.intrinsicWidth,
drawable.intrinsicHeight,
Bitmap.Config.ARGB_8888
)
val canvas = Canvas(bitmap)
drawable.setBounds(0, 0, canvas.width, canvas.height)
drawable.draw(canvas)
return bitmap
}

View File

@ -20,4 +20,5 @@
<dimen name="fab_vertical_offset">25dp</dimen>
<dimen name="material_design_appbar_size">48dp</dimen>
<dimen name="hamburger_icon_size">36dp</dimen>
</resources>

View File

@ -29,6 +29,7 @@ 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
import org.kiwix.kiwixmobile.core.main.MainMenu
@ -57,6 +58,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)
@ -77,7 +79,11 @@ class CustomReaderFragment : CoreReaderFragment() {
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)
val iconSize =
resources.getDimensionPixelSize(org.kiwix.kiwixmobile.core.R.dimen.hamburger_icon_size)
getResizedDrawable(R.mipmap.ic_launcher, iconSize, iconSize)?.let { drawable ->
it.navigationIcon = drawable
}
}
}
}