Skip to content

Commit

Permalink
- add a new sample GmailDrawerItem.kt to showcase gmail like design
Browse files Browse the repository at this point in the history
  - use in the MultiDrawerActivity.kt
  - FIX #2616
  • Loading branch information
mikepenz committed Jun 11, 2020
1 parent 9bf7eb0 commit f769419
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.view.MenuItem
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.mikepenz.iconics.typeface.library.fontawesome.FontAwesome
import com.mikepenz.materialdrawer.app.drawerItems.GmailDrawerItem
import com.mikepenz.materialdrawer.iconics.withIcon
import com.mikepenz.materialdrawer.model.PrimaryDrawerItem
import com.mikepenz.materialdrawer.model.SecondaryDrawerItem
Expand All @@ -27,9 +28,9 @@ class MultiDrawerActivity : AppCompatActivity() {

slider.apply {
itemAdapter.add(
PrimaryDrawerItem().withName(R.string.drawer_item_home).withIcon(FontAwesome.Icon.faw_home).withIdentifier(1),
PrimaryDrawerItem().withName(R.string.drawer_item_free_play).withIcon(FontAwesome.Icon.faw_gamepad),
PrimaryDrawerItem().withName(R.string.drawer_item_custom).withIcon(FontAwesome.Icon.faw_eye).withIdentifier(5),
GmailDrawerItem().withName(R.string.drawer_item_home).withIcon(FontAwesome.Icon.faw_home).withIdentifier(1),
GmailDrawerItem().withName(R.string.drawer_item_free_play).withIcon(FontAwesome.Icon.faw_gamepad),
GmailDrawerItem().withName(R.string.drawer_item_custom).withIcon(FontAwesome.Icon.faw_eye).withIdentifier(5),
SectionDrawerItem().withName(R.string.drawer_item_section_header),
SecondaryDrawerItem().withName(R.string.drawer_item_settings).withIcon(FontAwesome.Icon.faw_cog),
SecondaryDrawerItem().withName(R.string.drawer_item_help).withIcon(FontAwesome.Icon.faw_question).withEnabled(false),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.mikepenz.materialdrawer.app.drawerItems

import android.content.Context
import android.view.View
import com.google.android.material.shape.CornerFamily
import com.google.android.material.shape.ShapeAppearanceModel
import com.mikepenz.materialdrawer.app.R
import com.mikepenz.materialdrawer.model.PrimaryDrawerItem
import com.mikepenz.materialdrawer.model.interfaces.IDrawerItem
import com.mikepenz.materialdrawer.util.themeDrawerItem

/**
* Describes the main [IDrawerItem] bing used as primary item, following the guidelines
*/
open class GmailDrawerItem : PrimaryDrawerItem() {

override val type: Int
get() = R.id.material_drawer_item_gmail_item

override fun applyDrawerItemTheme(ctx: Context, view: View, selected_color: Int, animate: Boolean, shapeAppearanceModel: ShapeAppearanceModel) {
themeDrawerItem(ctx, view, selected_color, animate, shapeAppearanceModel, R.dimen.gmail_material_drawer_item_background_padding_top_bottom, R.dimen.gmail_material_drawer_item_background_padding_start, R.dimen.gmail_material_drawer_item_background_padding_end)
}

override fun getShapeAppearanceModel(ctx: Context): ShapeAppearanceModel {
val cornerRadius = ctx.resources.getDimensionPixelSize(R.dimen.gmail_material_drawer_item_corner_radius)
return ShapeAppearanceModel.builder()
.setTopRightCorner(CornerFamily.ROUNDED, cornerRadius.toFloat())
.setBottomRightCorner(CornerFamily.ROUNDED, cornerRadius.toFloat())
.build()
}
}
5 changes: 5 additions & 0 deletions app/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,9 @@
<dimen name="material_drawer_padding_half">4dp</dimen>
<dimen name="material_drawer_persistent_height">48dp</dimen>
<dimen name="material_drawer_persistent_height_icon">32dp</dimen>

<dimen name="gmail_material_drawer_item_corner_radius">20dp</dimen>
<dimen name="gmail_material_drawer_item_background_padding_start">0dp</dimen>
<dimen name="gmail_material_drawer_item_background_padding_end">8dp</dimen>
<dimen name="gmail_material_drawer_item_background_padding_top_bottom">4dp</dimen>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/ids.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>

<resources>
<item name="material_drawer_item_gmail_item" type="id" />
<item name="material_drawer_item_custom_url_item" type="id" />
<item name="material_drawer_item_icon_only" type="id" />
<item name="material_drawer_item_centered_primary" type="id" />
Expand Down

0 comments on commit f769419

Please sign in to comment.