Skip to content

Commit

Permalink
Merge branch 'release/v7.0.0-rc09'
Browse files Browse the repository at this point in the history
  • Loading branch information
mikepenz committed Dec 19, 2019
2 parents 8a0e246 + 8239d85 commit 0ae74d0
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 28 deletions.
3 changes: 3 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# These are supported funding model platforms

github: [mikepenz]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ You can find some frequently asked questions and other resources in the [WIKI /

## Latest releases

- Kotlin | [v7.0.0-rc07](https://github.com/mikepenz/MaterialDrawer/tree/v7.0.0-rc08)
- Kotlin | [v7.0.0-rc09](https://github.com/mikepenz/MaterialDrawer/tree/v7.0.1-a01)
- 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
22 changes: 9 additions & 13 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
buildscript {
ext {
kotlin_version = '1.3.50'

release = [
versionName: "7.0.0-rc08",
versionName: "7.0.0-rc09",
versionCode: 7000
]

Expand All @@ -16,18 +14,17 @@ buildscript {

versions = [
multiDex : '2.0.1',
androidX : '1.0.0',
annotation : '1.1.0',
recyclerView : '1.1.0-beta04',
material : '1.1.0-beta01',
recyclerView : '1.1.0',
material : '1.1.0-beta02',
appcompat : '1.1.0',
drawerlayout : '1.1.0-alpha03',
constraintLayout : '2.0.0-beta2',
constraintLayout : '2.0.0-beta4',
cardview : '1.0.0',
kotlin : "1.3.50",
fastadapter : "4.1.0",
iconics : "4.0.1-b02",
navigation : "2.1.0",
kotlin : "1.3.61",
fastadapter : "4.1.1",
iconics : "4.0.2",
navigation : "2.2.0-rc04",
slidingpaneLayout: "1.0.0"
]
}
Expand All @@ -38,12 +35,11 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.1'
classpath 'com.android.tools.build:gradle:3.5.3'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${versions.kotlin}"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:${versions.navigation}"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

Expand Down
68 changes: 54 additions & 14 deletions library/src/main/java/com/mikepenz/materialdrawer/Drawer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import com.mikepenz.materialdrawer.model.interfaces.Badgeable
import com.mikepenz.materialdrawer.model.interfaces.IDrawerItem
import com.mikepenz.materialdrawer.model.interfaces.Iconable
import com.mikepenz.materialdrawer.model.interfaces.Nameable
import com.mikepenz.materialdrawer.util.ifNotNull
import com.mikepenz.materialdrawer.util.otherwise
import com.mikepenz.materialize.Materialize
import com.mikepenz.materialize.view.ScrimInsetsRelativeLayout

Expand Down Expand Up @@ -299,7 +301,7 @@ open class Drawer(internal val drawerBuilder: DrawerBuilder) {
*
* @return
*/
var originalDrawerItems: List<IDrawerItem<*>>? = null
var originalDrawerItems: MutableList<IDrawerItem<*>>? = null
private set
private var originalDrawerState: Bundle? = null

Expand Down Expand Up @@ -636,7 +638,11 @@ open class Drawer(internal val drawerBuilder: DrawerBuilder) {
*/
fun updateItemAtPosition(drawerItem: IDrawerItem<*>, position: Int) {
if (drawerBuilder.checkDrawerItem(position, false)) {
drawerBuilder.itemAdapter[position] = drawerItem
originalDrawerItems.ifNotNull {
it[position] = drawerItem
} otherwise {
drawerBuilder.itemAdapter[position] = drawerItem
}
}
}

Expand All @@ -646,7 +652,11 @@ open class Drawer(internal val drawerBuilder: DrawerBuilder) {
* @param drawerItem
*/
fun addItem(drawerItem: IDrawerItem<*>) {
drawerBuilder.itemAdapter.add(drawerItem)
originalDrawerItems.ifNotNull {
it.add(drawerItem)
} otherwise {
drawerBuilder.itemAdapter.add(drawerItem)
}
}

/**
Expand All @@ -656,7 +666,11 @@ open class Drawer(internal val drawerBuilder: DrawerBuilder) {
* @param position
*/
fun addItemAtPosition(drawerItem: IDrawerItem<*>, position: Int) {
drawerBuilder.itemAdapter.add(position, drawerItem)
originalDrawerItems.ifNotNull {
it.add(position, drawerItem)
} otherwise {
drawerBuilder.itemAdapter.add(position, drawerItem)
}
}

/**
Expand All @@ -666,7 +680,11 @@ open class Drawer(internal val drawerBuilder: DrawerBuilder) {
* @param position
*/
fun setItemAtPosition(drawerItem: IDrawerItem<*>, position: Int) {
drawerBuilder.itemAdapter.add(position, drawerItem)
originalDrawerItems.ifNotNull {
it[position] = drawerItem
} otherwise {
drawerBuilder.itemAdapter[position] = drawerItem
}
}

/**
Expand All @@ -675,8 +693,12 @@ open class Drawer(internal val drawerBuilder: DrawerBuilder) {
* @param position
*/
fun removeItemByPosition(position: Int) {
if (drawerBuilder.checkDrawerItem(position, false)) {
drawerBuilder.itemAdapter.remove(position)
originalDrawerItems.ifNotNull {
it.removeAt(position)
} otherwise {
if (drawerBuilder.checkDrawerItem(position, false)) {
drawerBuilder.itemAdapter.remove(position)
}
}
}

Expand All @@ -686,7 +708,11 @@ open class Drawer(internal val drawerBuilder: DrawerBuilder) {
* @param identifier
*/
fun removeItem(identifier: Long) {
itemAdapter.removeByIdentifier(identifier)
originalDrawerItems.ifNotNull {
it.removeAll { item -> item.identifier == identifier }
} otherwise {
itemAdapter.removeByIdentifier(identifier)
}
}

/**
Expand All @@ -695,7 +721,9 @@ open class Drawer(internal val drawerBuilder: DrawerBuilder) {
* @param identifiers
*/
fun removeItems(vararg identifiers: Long) {
if (identifiers != null) {
originalDrawerItems.ifNotNull {
it.removeAll { item -> identifiers.contains(item.identifier) }
} otherwise {
for (identifier in identifiers) {
removeItem(identifier)
}
Expand All @@ -706,7 +734,11 @@ open class Drawer(internal val drawerBuilder: DrawerBuilder) {
* Removes all items from drawer
*/
fun removeAllItems() {
drawerBuilder.itemAdapter.clear()
originalDrawerItems.ifNotNull {
it.clear()
} otherwise {
drawerBuilder.itemAdapter.clear()
}
}

/**
Expand All @@ -715,7 +747,11 @@ open class Drawer(internal val drawerBuilder: DrawerBuilder) {
* @param drawerItems
*/
fun addItems(vararg drawerItems: IDrawerItem<*>) {
drawerBuilder.itemAdapter.add(*drawerItems)
originalDrawerItems.ifNotNull {
it.addAll(drawerItems)
} otherwise {
drawerBuilder.itemAdapter.add(drawerItems.asList())
}
}

/**
Expand All @@ -725,7 +761,11 @@ open class Drawer(internal val drawerBuilder: DrawerBuilder) {
* @param drawerItems
*/
fun addItemsAtPosition(position: Int, vararg drawerItems: IDrawerItem<*>) {
drawerBuilder.itemAdapter.add(position, *drawerItems)
originalDrawerItems.ifNotNull {
it.addAll(position, drawerItems.asList())
} otherwise {
drawerBuilder.itemAdapter.add(position, drawerItems.asList())
}
}

/**
Expand All @@ -746,7 +786,7 @@ open class Drawer(internal val drawerBuilder: DrawerBuilder) {
private fun setItems(drawerItems: List<IDrawerItem<*>>?, switchedItems: Boolean) {
//if we are currently at a switched list set the new reference
if (originalDrawerItems != null && !switchedItems) {
originalDrawerItems = drawerItems
originalDrawerItems = drawerItems?.toMutableList()
}
drawerBuilder.itemAdapter.setNewList(drawerItems ?: ArrayList())
}
Expand Down Expand Up @@ -855,7 +895,7 @@ open class Drawer(internal val drawerBuilder: DrawerBuilder) {
originalOnDrawerItemLongClickListener = onDrawerItemLongClickListener
originalDrawerState = adapter.saveInstanceState(Bundle())
drawerBuilder.mExpandableExtension.collapse(false)
originalDrawerItems = drawerItems
originalDrawerItems = drawerItems.toMutableList()
}

//set the new items
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.mikepenz.materialdrawer.util

/**
* Does an action if it is not null
*/
public inline infix fun <T> T?.ifNotNull(block: (T) -> Unit): Unit? {
return if (this != null) {
block(this)
} else {
null
}
}

/**
* Does an action if it is null
*/
public inline infix fun <T> T?.otherwise(block: () -> Unit): Unit = ifNull(block)

/**
* Does an action if it is null
*/
public inline infix fun <T> T?.ifNull(block: () -> Unit): Unit {
if (this == null) {
block()
}
}

0 comments on commit 0ae74d0

Please sign in to comment.