Skip to content

Commit

Permalink
Merge pull request #2684 from mikepenz/develop
Browse files Browse the repository at this point in the history
dev -> main
  • Loading branch information
mikepenz authored Nov 23, 2020
2 parents 8c9a36c + 9473d56 commit 8ce3449
Show file tree
Hide file tree
Showing 30 changed files with 357 additions and 302 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

## Latest releases 🛠

- Kotlin && New | [v8.1.8](https://github.com/mikepenz/MaterialDrawer/tree/v8.1.8)
- Kotlin && New | [v8.2.0](https://github.com/mikepenz/MaterialDrawer/tree/v8.2.0)
- Kotlin | [v7.0.0](https://github.com/mikepenz/MaterialDrawer/tree/v7.0.0) | (Builder approach like v6.x)
- Java && AndroidX | [v6.1.2](https://github.com/mikepenz/MaterialDrawer/tree/v6.1.2)
- Java && AppCompat | [v6.0.9](https://github.com/mikepenz/MaterialDrawer/tree/v6.0.9)
Expand Down
5 changes: 4 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: "androidx.navigation.safeargs.kotlin"
apply plugin: 'com.mikepenz.aboutlibraries.plugin'
Expand Down Expand Up @@ -45,6 +44,10 @@ android {
abortOnError false
}

buildFeatures {
viewBinding true
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,36 @@ 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.iconics.withIcon
import com.mikepenz.materialdrawer.app.databinding.ActivitySampleActionbarBinding
import com.mikepenz.materialdrawer.iconics.iconicsIcon
import com.mikepenz.materialdrawer.model.PrimaryDrawerItem
import com.mikepenz.materialdrawer.model.SecondaryDrawerItem
import com.mikepenz.materialdrawer.model.interfaces.Nameable
import com.mikepenz.materialdrawer.model.interfaces.withName
import kotlinx.android.synthetic.main.activity_sample_actionbar.*
import com.mikepenz.materialdrawer.model.interfaces.nameRes

class ActionBarActivity : AppCompatActivity() {
private lateinit var binding: ActivitySampleActionbarBinding

override fun onCreate(savedInstanceState: Bundle?) {
//supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_sample_actionbar)
binding = ActivitySampleActionbarBinding.inflate(layoutInflater).also {
setContentView(it.root)
}
setTitle(R.string.drawer_item_action_bar_drawer)

slider.apply {
binding.slider.apply {
itemAdapter.add(
PrimaryDrawerItem().withName(R.string.drawer_item_home).withIcon(FontAwesome.Icon.faw_home),
SecondaryDrawerItem().withName(R.string.drawer_item_settings).withIcon(FontAwesome.Icon.faw_cog)
PrimaryDrawerItem().apply {
nameRes = R.string.drawer_item_home
iconicsIcon = FontAwesome.Icon.faw_home
},
SecondaryDrawerItem().apply {
nameRes = R.string.drawer_item_settings
iconicsIcon = FontAwesome.Icon.faw_cog
}
)
onDrawerItemClickListener = { v, drawerItem, position ->
onDrawerItemClickListener = { _, drawerItem, _ ->
if (drawerItem is Nameable) {
Toast.makeText(this@ActionBarActivity, (drawerItem as Nameable).name!!.getText(this@ActionBarActivity), Toast.LENGTH_SHORT).show()
}
Expand All @@ -40,7 +49,7 @@ class ActionBarActivity : AppCompatActivity() {

override fun onSaveInstanceState(_outState: Bundle) {
//add the values which need to be saved from the drawer to the bundle
super.onSaveInstanceState(slider?.saveInstanceState(_outState) ?: _outState)
super.onSaveInstanceState(binding.slider.saveInstanceState(_outState))
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
Expand All @@ -55,8 +64,8 @@ class ActionBarActivity : AppCompatActivity() {

override fun onBackPressed() {
//handle the back press :D close the drawer first and if the drawer is closed close the activity
if (root?.isDrawerOpen(slider) == true) {
root?.closeDrawer(slider)
if (binding.root.isDrawerOpen(binding.slider)) {
binding.root.closeDrawer(binding.slider)
} else {
super.onBackPressed()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,21 @@ import com.mikepenz.iconics.utils.actionBar
import com.mikepenz.iconics.utils.backgroundColorRes
import com.mikepenz.iconics.utils.paddingDp
import com.mikepenz.iconics.utils.sizeDp
import com.mikepenz.materialdrawer.app.databinding.ActivitySampleBinding
import com.mikepenz.materialdrawer.app.drawerItems.CustomPrimaryDrawerItem
import com.mikepenz.materialdrawer.app.drawerItems.CustomUrlPrimaryDrawerItem
import com.mikepenz.materialdrawer.app.drawerItems.OverflowMenuDrawerItem
import com.mikepenz.materialdrawer.holder.ColorHolder
import com.mikepenz.materialdrawer.holder.ImageHolder
import com.mikepenz.materialdrawer.iconics.withIcon
import com.mikepenz.materialdrawer.holder.StringHolder
import com.mikepenz.materialdrawer.iconics.iconicsIcon
import com.mikepenz.materialdrawer.model.*
import com.mikepenz.materialdrawer.model.interfaces.*
import com.mikepenz.materialdrawer.util.addStickyDrawerItems
import com.mikepenz.materialdrawer.widget.AccountHeaderView
import kotlinx.android.synthetic.main.activity_sample.*

class AdvancedActivity : AppCompatActivity() {
private lateinit var binding: ActivitySampleBinding

private lateinit var headerView: AccountHeaderView
private lateinit var actionBarDrawerToggle: ActionBarDrawerToggle
Expand All @@ -39,50 +42,56 @@ class AdvancedActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_sample)
binding = ActivitySampleBinding.inflate(layoutInflater).also {
setContentView(it.root)
}

// Handle Toolbar
setSupportActionBar(toolbar)
setSupportActionBar(binding.toolbar)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.setHomeButtonEnabled(true)
supportActionBar?.setTitle(R.string.drawer_item_advanced_drawer)

actionBarDrawerToggle = ActionBarDrawerToggle(this, root, toolbar, com.mikepenz.materialdrawer.R.string.material_drawer_open, com.mikepenz.materialdrawer.R.string.material_drawer_close)
actionBarDrawerToggle = ActionBarDrawerToggle(this, binding.root, binding.toolbar, com.mikepenz.materialdrawer.R.string.material_drawer_open, com.mikepenz.materialdrawer.R.string.material_drawer_close)

// Create a few sample profile
profile = ProfileDrawerItem().withName("Mike Penz").withEmail("[email protected]").withIcon(resources.getDrawable(R.drawable.profile))
profile2 = ProfileDrawerItem().withName("Max Muster").withEmail("[email protected]").withIcon(resources.getDrawable(R.drawable.profile2)).withIdentifier(2)
profile3 = ProfileDrawerItem().withName("Felix House").withEmail("[email protected]").withIcon(resources.getDrawable(R.drawable.profile3))
profile4 = ProfileDrawerItem().withName("Mr. X").withEmail("[email protected]").withIcon(resources.getDrawable(R.drawable.profile4)).withIdentifier(4)
profile5 = ProfileDrawerItem().withName("Batman").withEmail("[email protected]").withIcon(resources.getDrawable(R.drawable.profile5))
profile = ProfileDrawerItem().apply { nameText = "Mike Penz"; descriptionText = "[email protected]"; iconRes = R.drawable.profile }
profile2 = ProfileDrawerItem().apply { nameText = "Max Muster"; descriptionText = "[email protected]"; iconRes = R.drawable.profile2; identifier = 2 }
profile3 = ProfileDrawerItem().apply { nameText = "Felix House"; descriptionText = "[email protected]"; iconRes = R.drawable.profile3 }
profile4 = ProfileDrawerItem().apply { nameText = "Mr. X"; descriptionText = "[email protected]"; iconRes = R.drawable.profile4; identifier = 4 }
profile5 = ProfileDrawerItem().apply { nameText = "Batman"; descriptionText = "[email protected]"; iconRes = R.drawable.profile5 }

// Create the AccountHeader
buildHeader(false, savedInstanceState)

slider.apply {
binding.slider.apply {
itemAdapter.add(
PrimaryDrawerItem().withName(R.string.drawer_item_home).withIcon(FontAwesome.Icon.faw_home),
PrimaryDrawerItem().apply { nameRes = R.string.drawer_item_home; iconicsIcon = FontAwesome.Icon.faw_home },
//here we use a customPrimaryDrawerItem we defined in our sample app
//this custom DrawerItem extends the PrimaryDrawerItem so it just overwrites some methods
OverflowMenuDrawerItem().withName(R.string.drawer_item_menu_drawer_item).withDescription(R.string.drawer_item_menu_drawer_item_desc).withMenu(R.menu.fragment_menu).withOnMenuItemClickListener(PopupMenu.OnMenuItemClickListener { item ->
Toast.makeText(this@AdvancedActivity, item.title, Toast.LENGTH_SHORT).show()
false
}).withIcon(GoogleMaterial.Icon.gmd_filter_center_focus),
CustomPrimaryDrawerItem().withBackgroundRes(R.color.accent).withName(R.string.drawer_item_free_play).withIcon(FontAwesome.Icon.faw_gamepad),
PrimaryDrawerItem().withName(R.string.drawer_item_custom).withDescription("This is a description").withIcon(FontAwesome.Icon.faw_eye),
CustomUrlPrimaryDrawerItem().withName(R.string.drawer_item_fragment_drawer).withDescription(R.string.drawer_item_fragment_drawer_desc).withIcon("https://avatars3.githubusercontent.com/u/1476232?v=3&s=460"),
SectionDrawerItem().withName(R.string.drawer_item_section_header),
SecondaryDrawerItem().withName(R.string.drawer_item_settings).withIcon(FontAwesome.Icon.faw_cart_plus),
SecondaryDrawerItem().withName(R.string.drawer_item_help).withIcon(FontAwesome.Icon.faw_database).withEnabled(false),
SecondaryDrawerItem().withName(R.string.drawer_item_open_source).withIcon(FontAwesome.Icon.faw_github),
SecondaryDrawerItem().withName(R.string.drawer_item_contact).withIconTintingEnabled(true).withIcon(IconicsDrawable(this@AdvancedActivity, GoogleMaterial.Icon.gmd_add).apply { actionBar(); paddingDp = 5 }).withTag("Bullhorn"),
SecondaryDrawerItem().withName(R.string.drawer_item_help).withIcon(FontAwesome.Icon.faw_question).withEnabled(false)
OverflowMenuDrawerItem().apply {
nameRes = R.string.drawer_item_menu_drawer_item; descriptionRes = R.string.drawer_item_menu_drawer_item_desc; menu = R.menu.fragment_menu
onMenuItemClickListener = PopupMenu.OnMenuItemClickListener { item ->
Toast.makeText(this@AdvancedActivity, item.title, Toast.LENGTH_SHORT).show()
false
}
iconicsIcon = GoogleMaterial.Icon.gmd_filter_center_focus
},
CustomPrimaryDrawerItem().apply { nameRes = R.string.drawer_item_free_play; iconicsIcon = FontAwesome.Icon.faw_gamepad; background = ColorHolder.fromColorRes(R.color.accent) },
PrimaryDrawerItem().apply { nameRes = R.string.drawer_item_custom; descriptionText = "This is a description"; iconicsIcon = FontAwesome.Icon.faw_eye },
CustomUrlPrimaryDrawerItem().apply { nameRes = R.string.drawer_item_fragment_drawer; description = StringHolder(R.string.drawer_item_fragment_drawer_desc); iconUrl = "https://avatars3.githubusercontent.com/u/1476232?v=3&s=460" },
SectionDrawerItem().apply { nameRes = R.string.drawer_item_section_header },
SecondaryDrawerItem().apply { nameRes = R.string.drawer_item_settings; iconicsIcon = FontAwesome.Icon.faw_cart_plus },
SecondaryDrawerItem().apply { nameRes = R.string.drawer_item_help; iconicsIcon = FontAwesome.Icon.faw_database; isEnabled = false },
SecondaryDrawerItem().apply { nameRes = R.string.drawer_item_open_source; iconicsIcon = FontAwesome.Icon.faw_github },
SecondaryDrawerItem().apply { nameRes = R.string.drawer_item_contact; tag = "Bullhorn"; iconDrawable = IconicsDrawable(this@AdvancedActivity, GoogleMaterial.Icon.gmd_add).apply { actionBar(); paddingDp = 5 }; isIconTinted = true },
SecondaryDrawerItem().apply { nameRes = R.string.drawer_item_help; iconicsIcon = FontAwesome.Icon.faw_question; isEnabled = false }
)
addStickyDrawerItems(
SecondaryDrawerItem().withName(R.string.drawer_item_settings).withIcon(FontAwesome.Icon.faw_cog).withIdentifier(10),
SecondaryDrawerItem().withName(R.string.drawer_item_open_source).withIcon(FontAwesome.Icon.faw_github)
SecondaryDrawerItem().apply { nameRes = R.string.drawer_item_settings; iconicsIcon = FontAwesome.Icon.faw_cog; identifier = 10 },
SecondaryDrawerItem().apply { nameRes = R.string.drawer_item_open_source; iconicsIcon = FontAwesome.Icon.faw_github }
)
onDrawerItemClickListener = { v, drawerItem, position ->
onDrawerItemClickListener = { _, drawerItem, _ ->
if (drawerItem is Nameable) {
Toast.makeText(this@AdvancedActivity, drawerItem.name?.getText(this@AdvancedActivity), Toast.LENGTH_SHORT).show()
}
Expand All @@ -102,25 +111,23 @@ class AdvancedActivity : AppCompatActivity() {
private fun buildHeader(compact: Boolean, savedInstanceState: Bundle?) {
// Create the AccountHeader
headerView = AccountHeaderView(this, compact = compact).apply {
attachToSliderView(slider)
attachToSliderView(binding.slider)
headerBackground = ImageHolder(R.drawable.header)
// TODO withCompactStyle(compact)
addProfiles(
profile,
profile2,
profile3,
profile4,
profile5,
//don't ask but google uses 14dp for the add account icon in gmail but 20dp for the normal icons (like manage account)
ProfileSettingDrawerItem().withName("Add Account").withDescription("Add new GitHub Account").withIcon(IconicsDrawable(this@AdvancedActivity, GoogleMaterial.Icon.gmd_add).apply { actionBar(); paddingDp = 5 }).withIdentifier(PROFILE_SETTING.toLong()),
ProfileSettingDrawerItem().withName("Manage Account").withIcon(GoogleMaterial.Icon.gmd_settings)
ProfileSettingDrawerItem().apply { nameText = "Add Account"; descriptionText = "Add new GitHub Account"; iconDrawable = IconicsDrawable(this@AdvancedActivity, GoogleMaterial.Icon.gmd_add).apply { actionBar(); paddingDp = 5 }; identifier = PROFILE_SETTING.toLong() },
ProfileSettingDrawerItem().apply { nameText = "Manage Account"; iconicsIcon = GoogleMaterial.Icon.gmd_settings }
)
onAccountHeaderListener = { view, profile, current ->
onAccountHeaderListener = { _, profile, _ ->
//sample usage of the onProfileChanged listener
//if the clicked item has the identifier 1 add a new profile ;)
if (profile is IDrawerItem<*> && (profile as IDrawerItem<*>).identifier == PROFILE_SETTING.toLong()) {
val newProfile = ProfileDrawerItem().withNameShown(true).withName("Batman").withEmail("[email protected]").withIcon(resources.getDrawable(R.drawable.profile5))

val newProfile = ProfileDrawerItem().apply { nameText = "Batman"; descriptionText = "[email protected]"; iconRes = R.drawable.profile5; isNameShown = true }
val profiles = headerView.profiles
if (profiles != null) {
//we know that there are 2 setting elements. set the new profile above them ;)
Expand Down Expand Up @@ -158,29 +165,21 @@ class AdvancedActivity : AppCompatActivity() {
when (item.itemId) {
R.id.menu_1 -> {
//update the profile2 and set a new image.
profile2.withIcon(IconicsDrawable(this, GoogleMaterial.Icon.gmd_android).apply { backgroundColorRes = R.color.accent; paddingDp = 4; sizeDp = 48 })
profile2.iconDrawable = IconicsDrawable(this, GoogleMaterial.Icon.gmd_android).apply { backgroundColorRes = R.color.accent; paddingDp = 4; sizeDp = 48 }
headerView.updateProfile(profile2)
return true
}
R.id.menu_4 -> {
//we want to replace our current header with a compact header
//build the new compact header
buildHeader(true, null)
//set the view to the result
//result.header = headerResult.view
//set the drawer to the header (so it will manage the profile list correctly)
// TODO headerResult.setDrawer(result)
return true
}
R.id.menu_5 -> {
//we want to replace our current header with a normal header
//build the new compact header
buildHeader(false, null)
slider.invalidate()
//set the view to the result
//result.header = headerResult.view
//set the drawer to the header (so it will manage the profile list correctly)
//TODO headerResult.setDrawer(result)
binding.slider.invalidate()
return true
}
else -> {
Expand All @@ -192,7 +191,7 @@ class AdvancedActivity : AppCompatActivity() {
override fun onSaveInstanceState(_outState: Bundle) {
var outState = _outState
//add the values which need to be saved from the drawer to the bundle
outState = slider.saveInstanceState(outState)
outState = binding.slider.saveInstanceState(outState)

//add the values which need to be saved from the accountHeader to the bundle
outState = headerView.saveInstanceState(outState)
Expand All @@ -201,8 +200,8 @@ class AdvancedActivity : AppCompatActivity() {

override fun onBackPressed() {
//handle the back press :D close the drawer first and if the drawer is closed close the activity
if (root.isDrawerOpen(slider)) {
root.closeDrawer(slider)
if (binding.root.isDrawerOpen(binding.slider)) {
binding.root.closeDrawer(binding.slider)
} else {
super.onBackPressed()
}
Expand Down
Loading

0 comments on commit 8ce3449

Please sign in to comment.