mirror of
https://github.com/kuba2k2/NavLib.git
synced 2025-01-18 14:16:44 -06:00
Update MaterialDrawer to v8.0.0. Update gradle and libraries.
This commit is contained in:
parent
5c8b13c0d9
commit
fd757f4228
@ -11,6 +11,8 @@ android {
|
|||||||
targetSdkVersion setup.targetSdk
|
targetSdkVersion setup.targetSdk
|
||||||
versionCode release.versionCode
|
versionCode release.versionCode
|
||||||
versionName release.versionName
|
versionName release.versionName
|
||||||
|
|
||||||
|
multiDexEnabled true
|
||||||
}
|
}
|
||||||
buildTypes {
|
buildTypes {
|
||||||
release {
|
release {
|
||||||
@ -34,14 +36,14 @@ dependencies {
|
|||||||
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
|
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
|
||||||
implementation "androidx.appcompat:appcompat:${versions.appcompat}"
|
implementation "androidx.appcompat:appcompat:${versions.appcompat}"
|
||||||
implementation "androidx.legacy:legacy-support-v4:${versions.legacy}"
|
implementation "androidx.legacy:legacy-support-v4:${versions.legacy}"
|
||||||
implementation "com.github.kuba2k2:MaterialDrawer:${versions.materialdrawer}"
|
implementation "com.mikepenz:materialdrawer:${versions.materialdrawer}"
|
||||||
//implementation "com.mikepenz:crossfader:1.6.0" // do not update
|
implementation "com.mikepenz:iconics-core:${versions.iconics}"
|
||||||
implementation "com.mikepenz:iconics-core:${versions.iconics}" // do not update. >3.1.0 Breaks jelly bean
|
implementation "com.mikepenz:iconics-views:${versions.iconics}"
|
||||||
implementation "com.mikepenz:iconics-views:${versions.iconics}" // do not update
|
|
||||||
implementation "com.mikepenz:community-material-typeface:${versions.font_cmd}@aar"
|
implementation "com.mikepenz:community-material-typeface:${versions.font_cmd}@aar"
|
||||||
implementation "androidx.core:core-ktx:${versions.ktx}"
|
implementation "androidx.core:core-ktx:${versions.ktx}"
|
||||||
implementation "androidx.constraintlayout:constraintlayout:${versions.constraintLayout}"
|
implementation "androidx.constraintlayout:constraintlayout:${versions.constraintLayout}"
|
||||||
implementation "com.google.android.material:material:${versions.material}"
|
implementation "com.google.android.material:material:${versions.material}"
|
||||||
implementation "pl.droidsonroids.gif:android-gif-drawable:${versions.gifdrawable}"
|
implementation "pl.droidsonroids.gif:android-gif-drawable:${versions.gifdrawable}"
|
||||||
|
implementation 'androidx.multidex:multidex:2.0.1'
|
||||||
implementation project(":navlib")
|
implementation project(":navlib")
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
android:roundIcon="@mipmap/ic_launcher_round"
|
android:roundIcon="@mipmap/ic_launcher_round"
|
||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
|
android:name="androidx.multidex.MultiDexApplication"
|
||||||
android:theme="@style/AppTheme.Light"><!--
|
android:theme="@style/AppTheme.Light"><!--
|
||||||
android:windowSoftInputMode="adjustResize"-->
|
android:windowSoftInputMode="adjustResize"-->
|
||||||
<activity android:name=".MainActivity"
|
<activity android:name=".MainActivity"
|
||||||
|
@ -12,12 +12,10 @@ import com.mikepenz.iconics.IconicsColor
|
|||||||
import com.mikepenz.iconics.IconicsDrawable
|
import com.mikepenz.iconics.IconicsDrawable
|
||||||
import com.mikepenz.iconics.IconicsSize
|
import com.mikepenz.iconics.IconicsSize
|
||||||
import com.mikepenz.iconics.typeface.library.community.material.CommunityMaterial
|
import com.mikepenz.iconics.typeface.library.community.material.CommunityMaterial
|
||||||
import com.mikepenz.materialdrawer.Drawer
|
|
||||||
import com.mikepenz.materialdrawer.holder.StringHolder
|
import com.mikepenz.materialdrawer.holder.StringHolder
|
||||||
import com.mikepenz.materialdrawer.model.PrimaryDrawerItem
|
|
||||||
import com.mikepenz.materialdrawer.model.ProfileDrawerItem
|
|
||||||
import com.mikepenz.materialdrawer.model.ProfileSettingDrawerItem
|
import com.mikepenz.materialdrawer.model.ProfileSettingDrawerItem
|
||||||
import com.mikepenz.materialdrawer.model.interfaces.IDrawerItem
|
import com.mikepenz.materialdrawer.model.interfaces.*
|
||||||
|
import com.mikepenz.materialdrawer.model.utils.withIsHiddenInMiniDrawer
|
||||||
import kotlinx.android.synthetic.main.sample_nav_view.*
|
import kotlinx.android.synthetic.main.sample_nav_view.*
|
||||||
import pl.szczodrzynski.navlib.SystemBarsUtil
|
import pl.szczodrzynski.navlib.SystemBarsUtil
|
||||||
import pl.szczodrzynski.navlib.SystemBarsUtil.Companion.COLOR_DO_NOT_CHANGE
|
import pl.szczodrzynski.navlib.SystemBarsUtil.Companion.COLOR_DO_NOT_CHANGE
|
||||||
@ -29,9 +27,9 @@ import pl.szczodrzynski.navlib.bottomsheet.NavBottomSheet.Companion.SORT_MODE_DE
|
|||||||
import pl.szczodrzynski.navlib.bottomsheet.NavBottomSheet.Companion.TOGGLE_GROUP_SORTING_ORDER
|
import pl.szczodrzynski.navlib.bottomsheet.NavBottomSheet.Companion.TOGGLE_GROUP_SORTING_ORDER
|
||||||
import pl.szczodrzynski.navlib.bottomsheet.items.BottomSheetPrimaryItem
|
import pl.szczodrzynski.navlib.bottomsheet.items.BottomSheetPrimaryItem
|
||||||
import pl.szczodrzynski.navlib.bottomsheet.items.BottomSheetSeparatorItem
|
import pl.szczodrzynski.navlib.bottomsheet.items.BottomSheetSeparatorItem
|
||||||
import pl.szczodrzynski.navlib.drawer.IDrawerProfile
|
|
||||||
import pl.szczodrzynski.navlib.drawer.items.DrawerPrimaryItem
|
import pl.szczodrzynski.navlib.drawer.items.DrawerPrimaryItem
|
||||||
import pl.szczodrzynski.navlib.getColorFromAttr
|
import pl.szczodrzynski.navlib.getColorFromAttr
|
||||||
|
import pl.szczodrzynski.navlib.withIcon
|
||||||
|
|
||||||
|
|
||||||
class MainActivity : AppCompatActivity() {
|
class MainActivity : AppCompatActivity() {
|
||||||
@ -262,7 +260,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
DrawerPrimaryItem().withName("Lock screen")
|
DrawerPrimaryItem().withName("Lock screen")
|
||||||
.withDescription("aaand not visible in Mini Drawer")
|
.withDescription("aaand not visible in Mini Drawer")
|
||||||
.withHiddenInMiniDrawer(true)
|
.withIsHiddenInMiniDrawer(true)
|
||||||
.withIdentifier(62)
|
.withIdentifier(62)
|
||||||
.withBadgeStyle(badgeStyle)
|
.withBadgeStyle(badgeStyle)
|
||||||
.withIcon(CommunityMaterial.Icon.cmd_fingerprint),
|
.withIcon(CommunityMaterial.Icon.cmd_fingerprint),
|
||||||
@ -307,15 +305,13 @@ class MainActivity : AppCompatActivity() {
|
|||||||
.withIcon(
|
.withIcon(
|
||||||
IconicsDrawable(context, CommunityMaterial.Icon2.cmd_plus)
|
IconicsDrawable(context, CommunityMaterial.Icon2.cmd_plus)
|
||||||
.actionBar()
|
.actionBar()
|
||||||
.padding(IconicsSize.dp(5))
|
.padding { IconicsSize.dp(5) }
|
||||||
.color(IconicsColor.colorRes(pl.szczodrzynski.navlib.R.color.material_drawer_dark_primary_text))
|
.color { IconicsColor.colorInt(getColorFromAttr(context, R.attr.materialDrawerPrimaryText)) }
|
||||||
)
|
)
|
||||||
.withOnDrawerItemClickListener(object : Drawer.OnDrawerItemClickListener {
|
.withOnDrawerItemClickListener { v, item, position ->
|
||||||
override fun onItemClick(view: View?, position: Int, drawerItem: IDrawerItem<*>): Boolean {
|
Toast.makeText(context, "Add account", Toast.LENGTH_SHORT).show()
|
||||||
Toast.makeText(context, "Add account", Toast.LENGTH_SHORT).show()
|
true
|
||||||
return true
|
},
|
||||||
}
|
|
||||||
}),
|
|
||||||
ProfileSettingDrawerItem()
|
ProfileSettingDrawerItem()
|
||||||
.withName("Manage Account")
|
.withName("Manage Account")
|
||||||
.withIcon(CommunityMaterial.Icon2.cmd_settings)
|
.withIcon(CommunityMaterial.Icon2.cmd_settings)
|
||||||
|
30
build.gradle
30
build.gradle
@ -6,8 +6,8 @@ buildscript {
|
|||||||
|
|
||||||
release = [
|
release = [
|
||||||
// major.minor.patch.rc.beta
|
// major.minor.patch.rc.beta
|
||||||
versionName: "0.5.0",
|
versionName: "0.6.0",
|
||||||
versionCode: 50099
|
versionCode: 60099
|
||||||
]
|
]
|
||||||
|
|
||||||
setup = [
|
setup = [
|
||||||
@ -18,14 +18,16 @@ buildscript {
|
|||||||
]
|
]
|
||||||
|
|
||||||
versions = [
|
versions = [
|
||||||
kotlin : "1.3.61",
|
gradleAndroid : "4.0.0-beta03",
|
||||||
ktx : "1.1.0",
|
|
||||||
|
kotlin : ext.kotlin_version,
|
||||||
|
ktx : "1.2.0",
|
||||||
|
|
||||||
androidX : '1.0.0',
|
androidX : '1.0.0',
|
||||||
annotation : '1.1.0',
|
annotation : '1.1.0',
|
||||||
recyclerView : '1.2.0-alpha01',
|
recyclerView : '1.2.0-alpha01',
|
||||||
material : '1.2.0-alpha03',
|
material : '1.2.0-alpha05',
|
||||||
appcompat : '1.2.0-alpha01',
|
appcompat : '1.2.0-alpha03',
|
||||||
constraintLayout : '2.0.0-beta4',
|
constraintLayout : '2.0.0-beta4',
|
||||||
cardview : '1.0.0',
|
cardview : '1.0.0',
|
||||||
gridLayout : '1.0.0',
|
gridLayout : '1.0.0',
|
||||||
@ -33,22 +35,22 @@ buildscript {
|
|||||||
navigationFragment: "1.0.0",
|
navigationFragment: "1.0.0",
|
||||||
legacy : "1.0.0",
|
legacy : "1.0.0",
|
||||||
|
|
||||||
room : "2.2.3",
|
room : "2.2.5",
|
||||||
lifecycle : "2.2.0-rc03",
|
lifecycle : "2.2.0",
|
||||||
work : "2.2.0",
|
work : "2.3.4",
|
||||||
|
|
||||||
firebase : '17.2.2',
|
firebase : '17.2.2',
|
||||||
firebasemessaging: "20.1.0",
|
firebasemessaging: "20.1.3",
|
||||||
play_services : "17.0.0",
|
play_services : "17.0.0",
|
||||||
|
|
||||||
materialdialogs : "0.9.6.0",
|
materialdialogs : "0.9.6.0",
|
||||||
materialdrawer : "cad66092a6",
|
materialdrawer : "8.0.0-rc02",
|
||||||
iconics : "4.0.1",
|
iconics : "4.0.1",
|
||||||
font_cmd : "3.5.95.1-kotlin",
|
font_cmd : "3.5.95.1-kotlin",
|
||||||
|
|
||||||
gifdrawable : "1.2.15",
|
gifdrawable : "1.2.15",
|
||||||
|
|
||||||
retrofit : '2.6.2'
|
retrofit : "2.6.4"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,8 +59,8 @@ buildscript {
|
|||||||
jcenter()
|
jcenter()
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.android.tools.build:gradle:3.5.3'
|
classpath "com.android.tools.build:gradle:${versions.gradleAndroid}"
|
||||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${versions.kotlin}"
|
||||||
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
|
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
|
||||||
// NOTE: Do not place your application dependencies here; they belong
|
// NOTE: Do not place your application dependencies here; they belong
|
||||||
// in the individual module build.gradle files
|
// in the individual module build.gradle files
|
||||||
|
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
|
|||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-6.2-all.zip
|
||||||
|
@ -45,9 +45,10 @@ dependencies {
|
|||||||
implementation "androidx.recyclerview:recyclerview:${versions.recyclerView}"
|
implementation "androidx.recyclerview:recyclerview:${versions.recyclerView}"
|
||||||
implementation "com.google.android.material:material:${versions.material}"
|
implementation "com.google.android.material:material:${versions.material}"
|
||||||
|
|
||||||
api "com.github.kuba2k2:MaterialDrawer:${versions.materialdrawer}"
|
api "com.mikepenz:materialdrawer:${versions.materialdrawer}"
|
||||||
api "com.mikepenz:community-material-typeface:${versions.font_cmd}@aar"
|
api "com.mikepenz:community-material-typeface:${versions.font_cmd}@aar"
|
||||||
api "com.mikepenz:iconics-core:${versions.iconics}"
|
api "com.mikepenz:iconics-core:${versions.iconics}"
|
||||||
|
implementation "com.mikepenz:materialize:1.2.1"
|
||||||
implementation "com.mikepenz:itemanimators:1.1.0"
|
implementation "com.mikepenz:itemanimators:1.1.0"
|
||||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${versions.kotlin}"
|
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${versions.kotlin}"
|
||||||
implementation "pl.droidsonroids.gif:android-gif-drawable:${versions.gifdrawable}"
|
implementation "pl.droidsonroids.gif:android-gif-drawable:${versions.gifdrawable}"
|
||||||
|
@ -10,7 +10,6 @@ import android.util.AttributeSet
|
|||||||
import android.view.MotionEvent
|
import android.view.MotionEvent
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewOutlineProvider
|
import android.view.ViewOutlineProvider
|
||||||
import androidx.appcompat.widget.AppCompatImageView
|
|
||||||
import androidx.core.view.ViewCompat
|
import androidx.core.view.ViewCompat
|
||||||
import com.mikepenz.materialdrawer.R
|
import com.mikepenz.materialdrawer.R
|
||||||
import com.mikepenz.materialdrawer.util.DrawerImageLoader
|
import com.mikepenz.materialdrawer.util.DrawerImageLoader
|
||||||
@ -22,7 +21,7 @@ import pl.droidsonroids.gif.GifImageView
|
|||||||
* drawable on top. This is useful for applying a beveled look to image contents, but is also
|
* drawable on top. This is useful for applying a beveled look to image contents, but is also
|
||||||
* flexible enough for use with other desired aesthetics.
|
* flexible enough for use with other desired aesthetics.
|
||||||
*/
|
*/
|
||||||
open class BezelGifImageView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyle: Int = 0) : GifImageView(context, attrs, defStyle) {
|
open class BezelImageView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyle: Int = 0) : GifImageView(context, attrs, defStyle) {
|
||||||
private val mBlackPaint: Paint
|
private val mBlackPaint: Paint
|
||||||
private val mMaskedPaint: Paint
|
private val mMaskedPaint: Paint
|
||||||
|
|
||||||
@ -54,14 +53,14 @@ open class BezelGifImageView @JvmOverloads constructor(context: Context, attrs:
|
|||||||
// Attribute initialization
|
// Attribute initialization
|
||||||
val a = context.obtainStyledAttributes(attrs, R.styleable.BezelImageView, defStyle, R.style.BezelImageView)
|
val a = context.obtainStyledAttributes(attrs, R.styleable.BezelImageView, defStyle, R.style.BezelImageView)
|
||||||
|
|
||||||
mMaskDrawable = a.getDrawable(R.styleable.BezelImageView_biv_maskDrawable)
|
mMaskDrawable = a.getDrawable(R.styleable.BezelImageView_materialDrawerMaskDrawable)
|
||||||
if (mMaskDrawable != null) {
|
if (mMaskDrawable != null) {
|
||||||
mMaskDrawable.callback = this
|
mMaskDrawable.callback = this
|
||||||
}
|
}
|
||||||
|
|
||||||
mDrawCircularShadow = a.getBoolean(R.styleable.BezelImageView_biv_drawCircularShadow, true)
|
mDrawCircularShadow = a.getBoolean(R.styleable.BezelImageView_materialDrawerDrawCircularShadow, true)
|
||||||
|
|
||||||
mSelectorColor = a.getColor(R.styleable.BezelImageView_biv_selectorOnPress, 0)
|
mSelectorColor = a.getColor(R.styleable.BezelImageView_materialDrawerSelectorOnPress, 0)
|
||||||
|
|
||||||
a.recycle()
|
a.recycle()
|
||||||
|
|
||||||
|
@ -1,11 +1,18 @@
|
|||||||
package pl.szczodrzynski.navlib
|
package pl.szczodrzynski.navlib
|
||||||
|
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import com.mikepenz.iconics.typeface.IIcon
|
||||||
import com.mikepenz.materialdrawer.*
|
import com.mikepenz.materialdrawer.*
|
||||||
import com.mikepenz.materialdrawer.model.interfaces.IDrawerItem
|
import com.mikepenz.materialdrawer.holder.StringHolder
|
||||||
import com.mikepenz.materialdrawer.model.interfaces.IProfile
|
import com.mikepenz.materialdrawer.model.AbstractDrawerItem
|
||||||
|
import com.mikepenz.materialdrawer.model.BaseDrawerItem
|
||||||
|
import com.mikepenz.materialdrawer.model.interfaces.*
|
||||||
|
import com.mikepenz.materialdrawer.util.getDrawerItem
|
||||||
|
import com.mikepenz.materialdrawer.util.updateItem
|
||||||
|
import com.mikepenz.materialdrawer.widget.MaterialDrawerSliderView
|
||||||
|
|
||||||
inline fun DrawerBuilder.withOnDrawerItemClickListener(crossinline listener: (view: View?, position: Int, drawerItem: IDrawerItem<*>) -> Boolean): DrawerBuilder {
|
/*inline fun DrawerBuilder.withOnDrawerItemClickListener(crossinline listener: (view: View?, position: Int, drawerItem: IDrawerItem<*>) -> Boolean): DrawerBuilder {
|
||||||
return this.withOnDrawerItemClickListener(object : Drawer.OnDrawerItemClickListener {
|
return this.withOnDrawerItemClickListener(object : Drawer.OnDrawerItemClickListener {
|
||||||
override fun onItemClick(view: View?, position: Int, drawerItem: IDrawerItem<*>): Boolean {
|
override fun onItemClick(view: View?, position: Int, drawerItem: IDrawerItem<*>): Boolean {
|
||||||
return listener(view, position, drawerItem)
|
return listener(view, position, drawerItem)
|
||||||
@ -65,4 +72,14 @@ inline fun MiniDrawer.withOnMiniDrawerItemClickListener(crossinline listener: (v
|
|||||||
return listener(view, position, drawerItem, type)
|
return listener(view, position, drawerItem, type)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
}*/
|
||||||
|
|
||||||
|
fun MaterialDrawerSliderView.updateBadge(identifier: Long, badge: StringHolder?) {
|
||||||
|
val drawerItem = getDrawerItem(identifier)
|
||||||
|
if (drawerItem is Badgeable) {
|
||||||
|
drawerItem.withBadge(badge)
|
||||||
|
updateItem(drawerItem)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun <T : Iconable> T.withIcon(icon: IIcon) = withIcon(pl.szczodrzynski.navlib.ImageHolder(icon))
|
||||||
|
@ -1,20 +1,21 @@
|
|||||||
package pl.szczodrzynski.navlib
|
package pl.szczodrzynski.navlib
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.content.res.ColorStateList
|
||||||
import android.graphics.Bitmap
|
import android.graphics.Bitmap
|
||||||
import android.graphics.PorterDuff
|
import android.graphics.PorterDuff
|
||||||
import android.graphics.PorterDuffColorFilter
|
import android.graphics.PorterDuffColorFilter
|
||||||
import android.graphics.drawable.Drawable
|
import android.graphics.drawable.Drawable
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.view.View
|
|
||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
import androidx.annotation.ColorInt
|
import androidx.annotation.ColorInt
|
||||||
import androidx.annotation.DrawableRes
|
import androidx.annotation.DrawableRes
|
||||||
import androidx.appcompat.content.res.AppCompatResources
|
import androidx.appcompat.content.res.AppCompatResources
|
||||||
import com.mikepenz.iconics.IconicsColor
|
import com.mikepenz.iconics.IconicsColor
|
||||||
import com.mikepenz.iconics.IconicsDrawable
|
import com.mikepenz.iconics.IconicsDrawable
|
||||||
import com.mikepenz.iconics.IconicsSize
|
|
||||||
import com.mikepenz.iconics.typeface.IIcon
|
import com.mikepenz.iconics.typeface.IIcon
|
||||||
|
import com.mikepenz.iconics.utils.paddingDp
|
||||||
|
import com.mikepenz.iconics.utils.sizeDp
|
||||||
import com.mikepenz.materialdrawer.util.DrawerImageLoader
|
import com.mikepenz.materialdrawer.util.DrawerImageLoader
|
||||||
import pl.droidsonroids.gif.GifDrawable
|
import pl.droidsonroids.gif.GifDrawable
|
||||||
import java.io.FileNotFoundException
|
import java.io.FileNotFoundException
|
||||||
@ -25,31 +26,24 @@ import java.io.FileNotFoundException
|
|||||||
|
|
||||||
open class ImageHolder : com.mikepenz.materialdrawer.holder.ImageHolder {
|
open class ImageHolder : com.mikepenz.materialdrawer.holder.ImageHolder {
|
||||||
|
|
||||||
constructor(url: String) : super(url) {}
|
|
||||||
|
|
||||||
constructor(uri: Uri) : super(uri) {}
|
|
||||||
|
|
||||||
constructor(icon: Drawable?) : super(icon) {}
|
|
||||||
|
|
||||||
constructor(bitmap: Bitmap?) : super(bitmap) {}
|
|
||||||
|
|
||||||
constructor(@DrawableRes iconRes: Int) : super(iconRes) {}
|
|
||||||
|
|
||||||
constructor(@DrawableRes iconRes: Int, colorFilter: Int?) : super(iconRes) {
|
constructor(@DrawableRes iconRes: Int, colorFilter: Int?) : super(iconRes) {
|
||||||
this.colorFilter = colorFilter
|
this.colorFilter = colorFilter
|
||||||
}
|
}
|
||||||
|
constructor(iicon: IIcon) : super(null as Drawable?) {
|
||||||
constructor(iicon: IIcon) : super(null as Bitmap?) {
|
this.iicon = iicon
|
||||||
this.iIcon = iicon
|
|
||||||
}
|
}
|
||||||
|
constructor() : super()
|
||||||
|
constructor(url: String) : super(url)
|
||||||
|
constructor(uri: Uri) : super(uri)
|
||||||
|
constructor(icon: Drawable?) : super(icon)
|
||||||
|
constructor(bitmap: Bitmap) : super(bitmap)
|
||||||
|
constructor(iconRes: Int) : super(iconRes)
|
||||||
|
|
||||||
|
var iicon: IIcon? = null
|
||||||
@ColorInt
|
@ColorInt
|
||||||
var colorFilter: Int? = null
|
var colorFilter: Int? = null
|
||||||
var colorFilterMode: PorterDuff.Mode = PorterDuff.Mode.DST_OVER
|
var colorFilterMode: PorterDuff.Mode = PorterDuff.Mode.DST_OVER
|
||||||
|
|
||||||
override fun applyTo(imageView: ImageView): Boolean {
|
|
||||||
return applyTo(imageView, null)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* sets an existing image to the imageView
|
* sets an existing image to the imageView
|
||||||
@ -59,14 +53,14 @@ open class ImageHolder : com.mikepenz.materialdrawer.holder.ImageHolder {
|
|||||||
* @return true if an image was set
|
* @return true if an image was set
|
||||||
*/
|
*/
|
||||||
override fun applyTo(imageView: ImageView, tag: String?): Boolean {
|
override fun applyTo(imageView: ImageView, tag: String?): Boolean {
|
||||||
val ii = iIcon
|
val ii = iicon
|
||||||
|
|
||||||
if (uri != null) {
|
if (uri != null) {
|
||||||
if (uri.toString().endsWith(".gif", true)) {
|
if (uri.toString().endsWith(".gif", true)) {
|
||||||
imageView.setImageDrawable(GifDrawable(uri.toString()))
|
imageView.setImageDrawable(GifDrawable(uri.toString()))
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
val consumed = DrawerImageLoader.instance.setImage(imageView, uri, tag)
|
val consumed = DrawerImageLoader.instance.setImage(imageView, uri!!, tag)
|
||||||
if (!consumed) {
|
if (!consumed) {
|
||||||
imageView.setImageURI(uri)
|
imageView.setImageURI(uri)
|
||||||
}
|
}
|
||||||
@ -90,4 +84,39 @@ open class ImageHolder : com.mikepenz.materialdrawer.holder.ImageHolder {
|
|||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* this only handles Drawables
|
||||||
|
*
|
||||||
|
* @param ctx
|
||||||
|
* @param iconColor
|
||||||
|
* @param tint
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
override fun decideIcon(ctx: Context, iconColor: ColorStateList, tint: Boolean, paddingDp: Int): Drawable? {
|
||||||
|
var icon: Drawable? = icon
|
||||||
|
val ii = iicon
|
||||||
|
val uri = uri
|
||||||
|
|
||||||
|
when {
|
||||||
|
ii != null -> icon = IconicsDrawable(ctx, ii).apply {
|
||||||
|
color(IconicsColor.colorList(iconColor))
|
||||||
|
sizeDp(24)
|
||||||
|
paddingDp(paddingDp)
|
||||||
|
}
|
||||||
|
iconRes != -1 -> icon = AppCompatResources.getDrawable(ctx, iconRes)
|
||||||
|
uri != null -> try {
|
||||||
|
val inputStream = ctx.contentResolver.openInputStream(uri)
|
||||||
|
icon = Drawable.createFromStream(inputStream, uri.toString())
|
||||||
|
} catch (e: FileNotFoundException) {
|
||||||
|
//no need to handle this
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//if we got an icon AND we have auto tinting enabled AND it is no IIcon, tint it ;)
|
||||||
|
if (icon != null && tint && iicon == null) {
|
||||||
|
icon = icon.mutate()
|
||||||
|
icon.setColorFilter(iconColor.defaultColor, PorterDuff.Mode.SRC_IN)
|
||||||
|
}
|
||||||
|
return icon
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,15 +13,12 @@ import android.view.ViewGroup.LayoutParams.MATCH_PARENT
|
|||||||
import android.widget.FrameLayout
|
import android.widget.FrameLayout
|
||||||
import android.widget.LinearLayout
|
import android.widget.LinearLayout
|
||||||
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||||
|
import androidx.core.view.children
|
||||||
import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
|
import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
|
||||||
import com.google.android.material.floatingactionbutton.FloatingActionButton
|
import com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||||
import kotlinx.android.synthetic.main.nav_view.view.*
|
import kotlinx.android.synthetic.main.nav_view.view.*
|
||||||
import pl.szczodrzynski.navlib.bottomsheet.NavBottomSheet
|
import pl.szczodrzynski.navlib.bottomsheet.NavBottomSheet
|
||||||
import pl.szczodrzynski.navlib.drawer.NavDrawer
|
import pl.szczodrzynski.navlib.drawer.NavDrawer
|
||||||
import android.graphics.drawable.RippleDrawable
|
|
||||||
import android.os.Build
|
|
||||||
import androidx.core.view.children
|
|
||||||
import com.mikepenz.materialize.util.UIUtils
|
|
||||||
|
|
||||||
|
|
||||||
class NavView : FrameLayout {
|
class NavView : FrameLayout {
|
||||||
@ -82,9 +79,8 @@ class NavView : FrameLayout {
|
|||||||
|
|
||||||
drawer = NavDrawer(
|
drawer = NavDrawer(
|
||||||
context,
|
context,
|
||||||
findViewById(R.id.nv_drawerContainer),
|
findViewById(R.id.nv_drawerLayout),
|
||||||
findViewById(R.id.nv_fixedDrawerContainer),
|
findViewById(R.id.nv_drawerContainerLandscape),
|
||||||
findViewById(R.id.nv_miniDrawerContainerLandscape),
|
|
||||||
findViewById(R.id.nv_miniDrawerContainerPortrait),
|
findViewById(R.id.nv_miniDrawerContainerPortrait),
|
||||||
findViewById(R.id.nv_miniDrawerElevation)
|
findViewById(R.id.nv_miniDrawerElevation)
|
||||||
)
|
)
|
||||||
@ -108,11 +104,17 @@ class NavView : FrameLayout {
|
|||||||
//bottomSheetBehavior.peekHeight = displayHeight
|
//bottomSheetBehavior.peekHeight = displayHeight
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun convertDpToPixel(dp: Float): Float {
|
||||||
|
val resources = context.resources
|
||||||
|
val metrics = resources.displayMetrics
|
||||||
|
return dp * (metrics.densityDpi / 160f)
|
||||||
|
}
|
||||||
|
|
||||||
fun gainAttentionOnBottomBar() {
|
fun gainAttentionOnBottomBar() {
|
||||||
var x = ripple.width.toFloat()
|
var x = ripple.width.toFloat()
|
||||||
var y = ripple.height.toFloat()
|
var y = ripple.height.toFloat()
|
||||||
x -= UIUtils.convertDpToPixel(56f, context) / 2
|
x -= convertDpToPixel(56f) / 2
|
||||||
y -= UIUtils.convertDpToPixel(56f, context) / 2
|
y -= convertDpToPixel(56f) / 2
|
||||||
ripple.performRipple(Point(x.toInt(), y.toInt()))
|
ripple.performRipple(Point(x.toInt(), y.toInt()))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,7 +124,7 @@ class NavView : FrameLayout {
|
|||||||
this.navigationBarBgView = navigationBarBackground
|
this.navigationBarBgView = navigationBarBackground
|
||||||
this.statusBarDarkView = nv_statusBarDarker
|
this.statusBarDarkView = nv_statusBarDarker
|
||||||
//this.navigationBarDarkView = navigationBarBackground
|
//this.navigationBarDarkView = navigationBarBackground
|
||||||
this.insetsListener = nv_drawerContainer
|
this.insetsListener = nv_drawerLayout
|
||||||
this.marginBySystemBars = mainView
|
this.marginBySystemBars = mainView
|
||||||
this.paddingByNavigationBar = bottomSheet.getContentView()
|
this.paddingByNavigationBar = bottomSheet.getContentView()
|
||||||
}
|
}
|
||||||
@ -185,7 +187,7 @@ class NavView : FrameLayout {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun onBackPressed(): Boolean {
|
fun onBackPressed(): Boolean {
|
||||||
if (drawer.isOpen) {
|
if (drawer.isOpen && !drawer.fixedDrawerEnabled()) {
|
||||||
if (drawer.profileSelectionIsOpen) {
|
if (drawer.profileSelectionIsOpen) {
|
||||||
drawer.profileSelectionClose()
|
drawer.profileSelectionClose()
|
||||||
return true
|
return true
|
||||||
|
@ -295,7 +295,7 @@ class SystemBarsUtil(private val activity: Activity) {
|
|||||||
|
|
||||||
// PADDING
|
// PADDING
|
||||||
if (insetsListener != null) {
|
if (insetsListener != null) {
|
||||||
if (SDK_INT >= LOLLIPOP) {
|
if (SDK_INT >= LOLLIPOP && false) {
|
||||||
ViewCompat.setOnApplyWindowInsetsListener(insetsListener!!) { _, insets ->
|
ViewCompat.setOnApplyWindowInsetsListener(insetsListener!!) { _, insets ->
|
||||||
Log.d("NavLib", "Got insets left = ${insets.systemWindowInsetLeft}, top = ${insets.systemWindowInsetTop}, right = ${insets.systemWindowInsetRight}, bottom = ${insets.systemWindowInsetBottom}")
|
Log.d("NavLib", "Got insets left = ${insets.systemWindowInsetLeft}, top = ${insets.systemWindowInsetTop}, right = ${insets.systemWindowInsetRight}, bottom = ${insets.systemWindowInsetBottom}")
|
||||||
if (insetsApplied)
|
if (insetsApplied)
|
||||||
|
@ -5,20 +5,18 @@ import android.content.Context
|
|||||||
import android.content.res.Configuration
|
import android.content.res.Configuration
|
||||||
import android.graphics.drawable.Drawable
|
import android.graphics.drawable.Drawable
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
|
import android.util.DisplayMetrics
|
||||||
import android.util.TypedValue
|
import android.util.TypedValue
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import android.view.WindowManager
|
||||||
import androidx.annotation.AttrRes
|
import androidx.annotation.AttrRes
|
||||||
|
import androidx.annotation.ColorInt
|
||||||
|
import androidx.annotation.ColorRes
|
||||||
import androidx.annotation.DrawableRes
|
import androidx.annotation.DrawableRes
|
||||||
import com.google.android.material.elevation.ElevationOverlayProvider
|
import com.google.android.material.elevation.ElevationOverlayProvider
|
||||||
import com.mikepenz.iconics.IconicsColor
|
import com.mikepenz.iconics.IconicsColor
|
||||||
import com.mikepenz.iconics.IconicsDrawable
|
import com.mikepenz.iconics.IconicsDrawable
|
||||||
import android.util.DisplayMetrics
|
import com.mikepenz.iconics.utils.colorInt
|
||||||
import android.view.WindowManager
|
|
||||||
import androidx.annotation.ColorInt
|
|
||||||
import androidx.annotation.ColorRes
|
|
||||||
import com.mikepenz.materialdrawer.Drawer
|
|
||||||
import com.mikepenz.materialdrawer.holder.StringHolder
|
|
||||||
import com.mikepenz.materialdrawer.model.interfaces.Badgeable
|
|
||||||
|
|
||||||
|
|
||||||
/*private val displayMetrics by lazy {
|
/*private val displayMetrics by lazy {
|
||||||
@ -122,7 +120,7 @@ fun hasNavigationBar(context: Context): Boolean {
|
|||||||
return hasNavigationBar
|
return hasNavigationBar
|
||||||
}
|
}
|
||||||
|
|
||||||
fun IconicsDrawable.colorAttr(context: Context, @AttrRes attrRes: Int) = color(IconicsColor.colorInt(getColorFromAttr(context, attrRes)))
|
fun IconicsDrawable.colorAttr(context: Context, @AttrRes attrRes: Int) = colorInt(getColorFromAttr(context, attrRes))
|
||||||
|
|
||||||
fun getColorFromAttr(context: Context, @AttrRes color: Int): Int {
|
fun getColorFromAttr(context: Context, @AttrRes color: Int): Int {
|
||||||
val typedValue = TypedValue()
|
val typedValue = TypedValue()
|
||||||
@ -149,14 +147,6 @@ fun Context.getColorFromRes(@ColorRes id: Int): Int {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Drawer.updateBadge(identifier: Long, badge: StringHolder?) {
|
|
||||||
val drawerItem = getDrawerItem(identifier)
|
|
||||||
if (drawerItem is Badgeable<*>) {
|
|
||||||
drawerItem.withBadge(badge)
|
|
||||||
updateItem(drawerItem)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun crc16(buffer: String): Int {
|
fun crc16(buffer: String): Int {
|
||||||
/* Note the change here */
|
/* Note the change here */
|
||||||
var crc = 0x1D0F
|
var crc = 0x1D0F
|
||||||
|
@ -10,9 +10,8 @@ import androidx.recyclerview.widget.RecyclerView
|
|||||||
import com.mikepenz.iconics.IconicsDrawable
|
import com.mikepenz.iconics.IconicsDrawable
|
||||||
import com.mikepenz.iconics.typeface.IIcon
|
import com.mikepenz.iconics.typeface.IIcon
|
||||||
import com.mikepenz.iconics.typeface.library.community.material.CommunityMaterial
|
import com.mikepenz.iconics.typeface.library.community.material.CommunityMaterial
|
||||||
import com.mikepenz.iconics.utils.colorInt
|
|
||||||
import com.mikepenz.iconics.utils.sizeDp
|
import com.mikepenz.iconics.utils.sizeDp
|
||||||
import com.mikepenz.materialize.holder.ImageHolder
|
import pl.szczodrzynski.navlib.ImageHolder
|
||||||
import pl.szczodrzynski.navlib.R
|
import pl.szczodrzynski.navlib.R
|
||||||
import pl.szczodrzynski.navlib.colorAttr
|
import pl.szczodrzynski.navlib.colorAttr
|
||||||
import pl.szczodrzynski.navlib.getColorFromAttr
|
import pl.szczodrzynski.navlib.getColorFromAttr
|
||||||
@ -45,7 +44,7 @@ data class BottomSheetPrimaryItem(override val isContextual: Boolean = true) : I
|
|||||||
|
|
||||||
viewHolder.image.setImageDrawable(IconicsDrawable(viewHolder.text.context)
|
viewHolder.image.setImageDrawable(IconicsDrawable(viewHolder.text.context)
|
||||||
.icon(iconicsIcon ?: CommunityMaterial.Icon.cmd_android)
|
.icon(iconicsIcon ?: CommunityMaterial.Icon.cmd_android)
|
||||||
.colorAttr(viewHolder.text.context, R.attr.material_drawer_primary_icon)
|
.colorAttr(viewHolder.text.context, android.R.attr.textColorSecondary)
|
||||||
.sizeDp(24))
|
.sizeDp(24))
|
||||||
|
|
||||||
viewHolder.description.visibility = View.VISIBLE
|
viewHolder.description.visibility = View.VISIBLE
|
||||||
@ -59,7 +58,7 @@ data class BottomSheetPrimaryItem(override val isContextual: Boolean = true) : I
|
|||||||
titleRes != null -> viewHolder.text.setText(titleRes!!)
|
titleRes != null -> viewHolder.text.setText(titleRes!!)
|
||||||
else -> viewHolder.text.text = title
|
else -> viewHolder.text.text = title
|
||||||
}
|
}
|
||||||
viewHolder.text.setTextColor(getColorFromAttr(viewHolder.text.context, R.attr.material_drawer_primary_text))
|
viewHolder.text.setTextColor(getColorFromAttr(viewHolder.text.context, android.R.attr.textColorPrimary))
|
||||||
}
|
}
|
||||||
|
|
||||||
/*_____ _
|
/*_____ _
|
||||||
|
@ -9,33 +9,42 @@ import android.graphics.Color
|
|||||||
import android.graphics.PorterDuff
|
import android.graphics.PorterDuff
|
||||||
import android.graphics.drawable.LayerDrawable
|
import android.graphics.drawable.LayerDrawable
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
|
import android.view.Gravity
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import android.view.ViewGroup.LayoutParams.MATCH_PARENT
|
||||||
|
import android.view.ViewGroup.LayoutParams.WRAP_CONTENT
|
||||||
import android.widget.FrameLayout
|
import android.widget.FrameLayout
|
||||||
import android.widget.LinearLayout
|
import android.widget.LinearLayout
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.customview.widget.ViewDragHelper
|
import androidx.customview.widget.ViewDragHelper
|
||||||
import androidx.drawerlayout.widget.DrawerLayout
|
import androidx.drawerlayout.widget.DrawerLayout
|
||||||
|
import com.mikepenz.fastadapter.IAdapter
|
||||||
import com.mikepenz.itemanimators.AlphaCrossFadeAnimator
|
import com.mikepenz.itemanimators.AlphaCrossFadeAnimator
|
||||||
import com.mikepenz.materialdrawer.*
|
import com.mikepenz.materialdrawer.*
|
||||||
import com.mikepenz.materialdrawer.holder.BadgeStyle
|
import com.mikepenz.materialdrawer.holder.BadgeStyle
|
||||||
|
import com.mikepenz.materialdrawer.holder.ColorHolder
|
||||||
import com.mikepenz.materialdrawer.holder.StringHolder
|
import com.mikepenz.materialdrawer.holder.StringHolder
|
||||||
import com.mikepenz.materialdrawer.model.BaseDrawerItem
|
import com.mikepenz.materialdrawer.model.BaseDrawerItem
|
||||||
|
import com.mikepenz.materialdrawer.model.MiniProfileDrawerItem
|
||||||
import com.mikepenz.materialdrawer.model.ProfileDrawerItem
|
import com.mikepenz.materialdrawer.model.ProfileDrawerItem
|
||||||
import com.mikepenz.materialdrawer.model.ProfileSettingDrawerItem
|
import com.mikepenz.materialdrawer.model.ProfileSettingDrawerItem
|
||||||
import com.mikepenz.materialdrawer.model.interfaces.Badgeable
|
import com.mikepenz.materialdrawer.model.interfaces.*
|
||||||
import com.mikepenz.materialdrawer.model.interfaces.IDrawerItem
|
import com.mikepenz.materialdrawer.util.*
|
||||||
import com.mikepenz.materialdrawer.model.interfaces.IProfile
|
import com.mikepenz.materialdrawer.widget.AccountHeaderView
|
||||||
|
import com.mikepenz.materialdrawer.widget.MaterialDrawerSliderView
|
||||||
|
import com.mikepenz.materialdrawer.widget.MiniDrawerSliderView
|
||||||
|
import com.mikepenz.materialize.util.UIUtils
|
||||||
import pl.szczodrzynski.navlib.*
|
import pl.szczodrzynski.navlib.*
|
||||||
import pl.szczodrzynski.navlib.R
|
import pl.szczodrzynski.navlib.R
|
||||||
import pl.szczodrzynski.navlib.drawer.items.DrawerPrimaryItem
|
import pl.szczodrzynski.navlib.drawer.items.DrawerPrimaryItem
|
||||||
|
|
||||||
class NavDrawer(
|
class NavDrawer(
|
||||||
val context: Context,
|
val context: Context,
|
||||||
val drawerContainer: LinearLayout,
|
val drawerLayout: DrawerLayout,
|
||||||
val fixedDrawerContainer: FrameLayout,
|
val drawerContainerLandscape: FrameLayout,
|
||||||
val miniDrawerContainerLandscape: FrameLayout,
|
val drawerContainerPortrait: FrameLayout,
|
||||||
val miniDrawerContainerPortrait: FrameLayout,
|
|
||||||
val miniDrawerElevation: View
|
val miniDrawerElevation: View
|
||||||
) {
|
) {
|
||||||
companion object {
|
companion object {
|
||||||
@ -51,11 +60,9 @@ class NavDrawer(
|
|||||||
internal lateinit var toolbar: NavToolbar
|
internal lateinit var toolbar: NavToolbar
|
||||||
internal lateinit var bottomBar: NavBottomBar
|
internal lateinit var bottomBar: NavBottomBar
|
||||||
|
|
||||||
private var drawer: Drawer? = null
|
private lateinit var drawer: MaterialDrawerSliderView
|
||||||
private var drawerView: View? = null
|
private lateinit var accountHeader: AccountHeaderView
|
||||||
private var accountHeader: AccountHeader? = null
|
private lateinit var miniDrawer: MiniDrawerSliderView
|
||||||
private var miniDrawer: MiniDrawer? = null
|
|
||||||
private var miniDrawerView: View? = null
|
|
||||||
|
|
||||||
private var drawerMode: Int = DRAWER_MODE_NORMAL
|
private var drawerMode: Int = DRAWER_MODE_NORMAL
|
||||||
private var selection: Int = -1
|
private var selection: Int = -1
|
||||||
@ -73,123 +80,109 @@ class NavDrawer(
|
|||||||
getColorFromAttr(context, R.attr.colorOnError)
|
getColorFromAttr(context, R.attr.colorOnError)
|
||||||
)*/
|
)*/
|
||||||
|
|
||||||
badgeStyle = BadgeStyle()
|
badgeStyle = BadgeStyle().apply {
|
||||||
.withTextColor(Color.WHITE)
|
textColor = ColorHolder.fromColor(Color.WHITE)
|
||||||
.withColorRes(R.color.md_red_700)
|
color = ColorHolder.fromColor(0xffd32f2f.toInt())
|
||||||
|
}
|
||||||
val drawerBuilder = DrawerBuilder()
|
|
||||||
.withActivity(activity)
|
drawerLayout.addDrawerListener(object : DrawerLayout.DrawerListener {
|
||||||
.withDrawerLayout(R.layout.material_drawer_fits_not)
|
override fun onDrawerStateChanged(newState: Int) {}
|
||||||
//.withHasStableIds(true)
|
override fun onDrawerSlide(drawerView: View, slideOffset: Float) {}
|
||||||
.withItemAnimator(AlphaCrossFadeAnimator())
|
override fun onDrawerClosed(drawerView: View) {
|
||||||
.withRootView(drawerContainer)
|
drawerClosedListener?.invoke()
|
||||||
.withFullscreen(true)
|
profileSelectionClose()
|
||||||
.withTranslucentStatusBar(false)
|
}
|
||||||
.withTranslucentNavigationBar(true)
|
override fun onDrawerOpened(drawerView: View) {
|
||||||
.withTranslucentNavigationBarProgrammatically(false)
|
drawerOpenedListener?.invoke()
|
||||||
//.withToolbar(bottomBar)
|
}
|
||||||
.withDisplayBelowStatusBar(false)
|
})
|
||||||
//.withActionBarDrawerToggleAnimated(true)
|
|
||||||
.withShowDrawerOnFirstLaunch(true)
|
accountHeader = AccountHeaderView(context).apply {
|
||||||
//.withShowDrawerUntilDraggedOpened(true)
|
headerBackground = ImageHolder(R.drawable.header)
|
||||||
.withGenerateMiniDrawer(true /* if it is not showing on screen, clicking items throws an exception */)
|
|
||||||
.withOnDrawerListener(object : Drawer.OnDrawerListener {
|
onAccountHeaderListener = { view, profile, current ->
|
||||||
override fun onDrawerSlide(drawerView: View, slideOffset: Float) {}
|
if (profile is ProfileSettingDrawerItem) {
|
||||||
override fun onDrawerOpened(drawerView: View) {
|
drawerProfileSettingClickListener?.invoke(profile.identifier.toInt(), view) ?: false
|
||||||
drawerOpenedListener?.invoke()
|
}
|
||||||
}
|
else {
|
||||||
override fun onDrawerClosed(drawerView: View) {
|
updateBadges()
|
||||||
drawerClosedListener?.invoke()
|
if (current) {
|
||||||
profileSelectionClose()
|
close()
|
||||||
}
|
profileSelectionClose()
|
||||||
})
|
true
|
||||||
.withOnDrawerItemClickListener { _, position, drawerItem ->
|
}
|
||||||
if (drawerItem.identifier.toInt() == selection) {
|
else {
|
||||||
return@withOnDrawerItemClickListener false
|
(drawerProfileSelectedListener?.invoke(profile.identifier.toInt(), profile, current, view) ?: false).also {
|
||||||
}
|
setToolbarProfileImage(profileList.singleOrNull { it.id == profile.identifier.toInt() })
|
||||||
when (drawerItemSelectedListener?.invoke(drawerItem.identifier.toInt(), position, drawerItem)) {
|
}
|
||||||
true -> {
|
}
|
||||||
when {
|
}
|
||||||
!drawerItem.isSelectable -> {
|
}
|
||||||
setSelection(selection, false)
|
|
||||||
return@withOnDrawerItemClickListener false
|
onAccountHeaderItemLongClickListener = { view, profile, current ->
|
||||||
}
|
if (profile is ProfileSettingDrawerItem) {
|
||||||
drawerItem is DrawerPrimaryItem -> toolbar.title = drawerItem.appTitle ?: drawerItem.name?.getText(context) ?: ""
|
drawerProfileSettingLongClickListener?.invoke(profile.identifier.toInt(), view) ?: true
|
||||||
drawerItem is BaseDrawerItem<*, *> -> toolbar.title = drawerItem.name?.getText(context) ?: ""
|
}
|
||||||
}
|
else {
|
||||||
//setSelection(drawerItem.identifier.toInt(), false)
|
drawerProfileLongClickListener?.invoke(profile.identifier.toInt(), profile, current, view) ?: false
|
||||||
return@withOnDrawerItemClickListener false
|
}
|
||||||
}
|
}
|
||||||
false -> {
|
|
||||||
setSelection(selection, false)
|
onAccountHeaderProfileImageListener = { view, profile, current ->
|
||||||
return@withOnDrawerItemClickListener true
|
drawerProfileImageClickListener?.invoke(profile.identifier.toInt(), profile, current, view) ?: false
|
||||||
}
|
}
|
||||||
else -> {
|
//.withTextColor(ContextCompat.getColor(context, R.color.material_drawer_dark_primary_text))
|
||||||
return@withOnDrawerItemClickListener false
|
}
|
||||||
}
|
|
||||||
}
|
drawer = MaterialDrawerSliderView(context).apply {
|
||||||
|
accountHeader = this@NavDrawer.accountHeader
|
||||||
}
|
itemAnimator = AlphaCrossFadeAnimator()
|
||||||
.withOnDrawerItemLongClickListener { _, position, drawerItem ->
|
//hasStableIds = true
|
||||||
drawerItemLongClickListener?.invoke(drawerItem.identifier.toInt(), position, drawerItem) ?: true
|
|
||||||
}
|
onDrawerItemClickListener = { _, drawerItem, position ->
|
||||||
|
if (drawerItem.identifier.toInt() == selection) {
|
||||||
|
false
|
||||||
val accountHeaderBuilder = AccountHeaderBuilder()
|
}
|
||||||
.withActivity(activity)
|
else {
|
||||||
.withTranslucentStatusBar(true)
|
val consumed = drawerItemSelectedListener?.invoke(drawerItem.identifier.toInt(), position, drawerItem)
|
||||||
.withOnAccountHeaderListener { view, profile, current ->
|
if (consumed == false || !drawerItem.isSelectable) {
|
||||||
if (profile is ProfileSettingDrawerItem) {
|
setSelection(selection, false)
|
||||||
return@withOnAccountHeaderListener drawerProfileSettingClickListener?.invoke(profile.identifier.toInt(), view) ?: false
|
consumed == false
|
||||||
}
|
}
|
||||||
updateBadges()
|
else if (consumed == true) {
|
||||||
if (current) {
|
when (drawerItem) {
|
||||||
close()
|
is DrawerPrimaryItem -> toolbar.title = drawerItem.appTitle ?: drawerItem.name?.getText(context) ?: ""
|
||||||
profileSelectionClose()
|
is BaseDrawerItem<*, *> -> toolbar.title = drawerItem.name?.getText(context) ?: ""
|
||||||
return@withOnAccountHeaderListener true
|
}
|
||||||
}
|
false
|
||||||
(drawerProfileSelectedListener?.invoke(profile.identifier.toInt(), profile, current, view) ?: false).also {
|
}
|
||||||
setToolbarProfileImage(profileList.singleOrNull { it.id == profile.identifier.toInt() })
|
else {
|
||||||
}
|
false
|
||||||
}
|
}
|
||||||
.withOnAccountHeaderItemLongClickListener { view, profile, current ->
|
}
|
||||||
if (profile is ProfileSettingDrawerItem) {
|
}
|
||||||
return@withOnAccountHeaderItemLongClickListener drawerProfileSettingLongClickListener?.invoke(profile.identifier.toInt(), view) ?: true
|
|
||||||
}
|
onDrawerItemLongClickListener = { _, drawerItem, position ->
|
||||||
drawerProfileLongClickListener?.invoke(profile.identifier.toInt(), profile, current, view) ?: false
|
drawerItemLongClickListener?.invoke(drawerItem.identifier.toInt(), position, drawerItem) ?: true
|
||||||
}
|
}
|
||||||
.withOnAccountHeaderProfileImageListener(
|
}
|
||||||
onClick = { view, profile, current ->
|
|
||||||
drawerProfileImageClickListener?.invoke(profile.identifier.toInt(), profile, current, view) ?: false
|
miniDrawer = MiniDrawerSliderView(context).apply {
|
||||||
},
|
drawer = this@NavDrawer.drawer
|
||||||
onLongClick = { view, profile, current ->
|
includeSecondaryDrawerItems = false
|
||||||
drawerProfileImageLongClickListener?.invoke(profile.identifier.toInt(), profile, current, view) ?: false
|
this::class.java.getDeclaredField("onMiniDrawerItemClickListener").let {
|
||||||
}
|
it.isAccessible = true
|
||||||
)
|
it.set(this, { v: View?, position: Int, item: IDrawerItem<*>, type: Int ->
|
||||||
.withHeaderBackground(R.drawable.header)
|
if (item is MiniProfileDrawerItem) {
|
||||||
.withTextColor(ContextCompat.getColor(context, R.color.material_drawer_dark_primary_text))
|
profileSelectionOpen()
|
||||||
|
open()
|
||||||
accountHeader = accountHeaderBuilder.build()
|
true
|
||||||
drawerBuilder.withAccountHeader(accountHeader!!)
|
}
|
||||||
drawer = drawerBuilder.build()
|
else false
|
||||||
|
})
|
||||||
drawerView = drawer?.slider
|
}
|
||||||
|
|
||||||
miniDrawer = drawer?.miniDrawer
|
|
||||||
miniDrawer?.withOnMiniDrawerItemClickListener { _, _, _, type ->
|
|
||||||
if (type == MiniDrawer.PROFILE) {
|
|
||||||
profileSelectionOpen()
|
|
||||||
open()
|
|
||||||
return@withOnMiniDrawerItemClickListener true
|
|
||||||
}
|
|
||||||
return@withOnMiniDrawerItemClickListener false
|
|
||||||
}
|
}
|
||||||
miniDrawer?.withIncludeSecondaryDrawerItems(false)
|
|
||||||
|
|
||||||
// TODO 2019-08-27 build miniDrawerView only if needed
|
|
||||||
// building in decideDrawerMode causes an exception when clicking drawer items
|
|
||||||
// also update method updateMiniDrawer...
|
|
||||||
miniDrawerView = miniDrawer?.build(context)
|
|
||||||
updateMiniDrawer()
|
updateMiniDrawer()
|
||||||
|
|
||||||
toolbar.profileImageClickListener = {
|
toolbar.profileImageClickListener = {
|
||||||
@ -215,62 +208,62 @@ class NavDrawer(
|
|||||||
appendItem(item)
|
appendItem(item)
|
||||||
}
|
}
|
||||||
fun appendItem(item: IDrawerItem<*>) {
|
fun appendItem(item: IDrawerItem<*>) {
|
||||||
drawer?.addItem(item)
|
drawer.addItems(item)
|
||||||
updateMiniDrawer()
|
updateMiniDrawer()
|
||||||
}
|
}
|
||||||
fun appendItems(vararg items: IDrawerItem<*>) {
|
fun appendItems(vararg items: IDrawerItem<*>) {
|
||||||
drawer?.addItems(*items)
|
drawer.addItems(*items)
|
||||||
updateMiniDrawer()
|
updateMiniDrawer()
|
||||||
}
|
}
|
||||||
fun prependItem(item: IDrawerItem<*>) {
|
fun prependItem(item: IDrawerItem<*>) {
|
||||||
drawer?.addItemAtPosition(item, 0)
|
drawer.addItemAtPosition(0, item)
|
||||||
updateMiniDrawer()
|
updateMiniDrawer()
|
||||||
}
|
}
|
||||||
fun prependItems(vararg items: IDrawerItem<*>) {
|
fun prependItems(vararg items: IDrawerItem<*>) {
|
||||||
drawer?.addItemsAtPosition(0, *items)
|
drawer.addItemsAtPosition(0, *items)
|
||||||
updateMiniDrawer()
|
updateMiniDrawer()
|
||||||
}
|
}
|
||||||
fun addItemAt(index: Int, item: IDrawerItem<*>) {
|
fun addItemAt(index: Int, item: IDrawerItem<*>) {
|
||||||
drawer?.addItemAtPosition(item, index)
|
drawer.addItemAtPosition(index, item)
|
||||||
updateMiniDrawer()
|
updateMiniDrawer()
|
||||||
}
|
}
|
||||||
fun addItemsAt(index: Int, vararg items: IDrawerItem<*>) {
|
fun addItemsAt(index: Int, vararg items: IDrawerItem<*>) {
|
||||||
drawer?.addItemsAtPosition(index, *items)
|
drawer.addItemsAtPosition(index, *items)
|
||||||
updateMiniDrawer()
|
updateMiniDrawer()
|
||||||
}
|
}
|
||||||
fun removeItemById(id: Int) {
|
fun removeItemById(id: Int) {
|
||||||
drawer?.removeItem(id.toLong())
|
drawer.removeItems(id.toLong())
|
||||||
updateMiniDrawer()
|
updateMiniDrawer()
|
||||||
}
|
}
|
||||||
fun removeItemAt(index: Int) {
|
fun removeItemAt(index: Int) {
|
||||||
drawer?.removeItemByPosition(index)
|
drawer.removeItemByPosition(index)
|
||||||
updateMiniDrawer()
|
updateMiniDrawer()
|
||||||
}
|
}
|
||||||
fun removeAllItems() {
|
fun removeAllItems() {
|
||||||
drawer?.removeAllItems()
|
drawer.removeAllItems()
|
||||||
updateMiniDrawer()
|
updateMiniDrawer()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getItemById(id: Int, run: (it: IDrawerItem<*>?) -> Unit) {
|
fun getItemById(id: Int, run: (it: IDrawerItem<*>?) -> Unit) {
|
||||||
drawer?.getDrawerItem(id.toLong()).also {
|
drawer.getDrawerItem(id.toLong()).also {
|
||||||
run(it)
|
run(it)
|
||||||
if (it != null)
|
if (it != null)
|
||||||
drawer?.updateItem(it)
|
drawer.updateItem(it)
|
||||||
updateMiniDrawer()
|
updateMiniDrawer()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fun getItemByIndex(index: Int, run: (it: IDrawerItem<*>?) -> Unit) {
|
fun getItemByIndex(index: Int, run: (it: IDrawerItem<*>?) -> Unit) {
|
||||||
drawer?.drawerItems?.getOrNull(index).also {
|
drawer.itemAdapter.itemList.get(index).also {
|
||||||
run(it)
|
run(it)
|
||||||
if (it != null)
|
if (it != null)
|
||||||
drawer?.updateItem(it)
|
drawer.updateItem(it)
|
||||||
updateMiniDrawer()
|
updateMiniDrawer()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setItems(vararg items: IDrawerItem<*>) {
|
fun setItems(vararg items: IDrawerItem<*>) {
|
||||||
drawer?.removeAllItems()
|
drawer.removeAllItems()
|
||||||
drawer?.addItems(*items)
|
drawer.addItems(*items)
|
||||||
updateMiniDrawer()
|
updateMiniDrawer()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -282,12 +275,12 @@ class NavDrawer(
|
|||||||
|_| |_| |_| \_/ \__,_|\__\___| |_| |_| |_|\___|\__|_| |_|\___/ \__,_|__*/
|
|_| |_| |_| \_/ \__,_|\__\___| |_| |_| |_|\___|\__|_| |_|\___/ \__,_|__*/
|
||||||
private fun drawerSetDragMargin(size: Float) {
|
private fun drawerSetDragMargin(size: Float) {
|
||||||
try {
|
try {
|
||||||
val mDrawerLayout = drawer?.drawerLayout
|
val mDrawerLayout = drawerLayout
|
||||||
val mDragger = mDrawerLayout?.javaClass?.getDeclaredField(
|
val mDragger = mDrawerLayout::class.java.getDeclaredField(
|
||||||
"mLeftDragger"
|
"mLeftDragger"
|
||||||
)//mRightDragger for right obviously
|
)//mRightDragger for right obviously
|
||||||
mDragger?.isAccessible = true
|
mDragger.isAccessible = true
|
||||||
val draggerObj = mDragger?.get(mDrawerLayout) as ViewDragHelper?
|
val draggerObj = mDragger.get(mDrawerLayout) as ViewDragHelper?
|
||||||
|
|
||||||
val mEdgeSize = draggerObj?.javaClass?.getDeclaredField(
|
val mEdgeSize = draggerObj?.javaClass?.getDeclaredField(
|
||||||
"mEdgeSize"
|
"mEdgeSize"
|
||||||
@ -327,36 +320,37 @@ class NavDrawer(
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal fun decideDrawerMode(orientation: Int, widthDp: Int, heightDp: Int) {
|
internal fun decideDrawerMode(orientation: Int, widthDp: Int, heightDp: Int) {
|
||||||
|
val drawerLayoutParams = DrawerLayout.LayoutParams(WRAP_CONTENT, MATCH_PARENT).apply {
|
||||||
|
gravity = Gravity.START
|
||||||
|
}
|
||||||
|
val fixedLayoutParams = FrameLayout.LayoutParams(UIUtils.convertDpToPixel(300f, context).toInt(), MATCH_PARENT)
|
||||||
|
|
||||||
Log.d("NavLib", "Deciding drawer mode:")
|
Log.d("NavLib", "Deciding drawer mode:")
|
||||||
if (orientation == Configuration.ORIENTATION_PORTRAIT) {
|
if (orientation == Configuration.ORIENTATION_PORTRAIT) {
|
||||||
if (fixedDrawerContainer.childCount > 0) {
|
|
||||||
fixedDrawerContainer.removeAllViews()
|
|
||||||
}
|
|
||||||
Log.d("NavLib", "- fixed container disabled")
|
Log.d("NavLib", "- fixed container disabled")
|
||||||
drawer?.drawerLayout?.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED)
|
|
||||||
if (drawer?.drawerLayout?.indexOfChild(drawerView) == -1) {
|
|
||||||
drawer?.drawerLayout?.addView(drawerView)
|
|
||||||
}
|
|
||||||
Log.d("NavLib", "- slider enabled")
|
|
||||||
|
|
||||||
if (miniDrawerContainerLandscape.childCount > 0) {
|
if (drawerContainerLandscape.childCount > 0) {
|
||||||
miniDrawerContainerLandscape.removeAllViews()
|
drawerContainerLandscape.removeAllViews()
|
||||||
}
|
}
|
||||||
Log.d("NavLib", "- mini drawer land disabled")
|
Log.d("NavLib", "- mini drawer land disabled")
|
||||||
|
|
||||||
|
if (drawerLayout.indexOfChild(drawer) == -1) {
|
||||||
|
drawerLayout.addView(drawer, drawerLayoutParams)
|
||||||
|
}
|
||||||
|
drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED)
|
||||||
|
Log.d("NavLib", "- slider enabled")
|
||||||
|
|
||||||
if ((widthDp >= 480 && miniDrawerVisiblePortrait != false) || miniDrawerVisiblePortrait == true) {
|
if ((widthDp >= 480 && miniDrawerVisiblePortrait != false) || miniDrawerVisiblePortrait == true) {
|
||||||
if (miniDrawerView == null)
|
if (drawerContainerPortrait.indexOfChild(miniDrawer) == -1)
|
||||||
miniDrawerView = miniDrawer?.build(context)
|
drawerContainerPortrait.addView(miniDrawer)
|
||||||
if (miniDrawerContainerPortrait.indexOfChild(miniDrawerView) == -1)
|
|
||||||
miniDrawerContainerPortrait.addView(miniDrawerView)
|
|
||||||
Log.d("NavLib", "- mini drawer port enabled")
|
Log.d("NavLib", "- mini drawer port enabled")
|
||||||
drawerSetDragMargin(72 * resources.displayMetrics.density)
|
drawerSetDragMargin(72 * resources.displayMetrics.density)
|
||||||
drawerMode = DRAWER_MODE_MINI
|
drawerMode = DRAWER_MODE_MINI
|
||||||
updateMiniDrawer()
|
updateMiniDrawer()
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (miniDrawerContainerPortrait.childCount > 0) {
|
if (drawerContainerPortrait.childCount > 0) {
|
||||||
miniDrawerContainerPortrait.removeAllViews()
|
drawerContainerPortrait.removeAllViews()
|
||||||
}
|
}
|
||||||
Log.d("NavLib", "- mini drawer port disabled")
|
Log.d("NavLib", "- mini drawer port disabled")
|
||||||
drawerSetDragMargin(20 * resources.displayMetrics.density)
|
drawerSetDragMargin(20 * resources.displayMetrics.density)
|
||||||
@ -364,68 +358,67 @@ class NavDrawer(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (miniDrawerContainerPortrait.childCount > 0) {
|
if (drawerContainerPortrait.childCount > 0) {
|
||||||
miniDrawerContainerPortrait.removeAllViews()
|
drawerContainerPortrait.removeAllViews()
|
||||||
}
|
}
|
||||||
Log.d("NavLib", "- mini drawer port disabled")
|
Log.d("NavLib", "- mini drawer port disabled")
|
||||||
|
|
||||||
if ((widthDp in 480 until 9000 && miniDrawerVisibleLandscape != false) || miniDrawerVisibleLandscape == true) {
|
if ((widthDp in 480 until 900 && miniDrawerVisibleLandscape != false) || miniDrawerVisibleLandscape == true) {
|
||||||
if (miniDrawerView == null)
|
if (drawerContainerLandscape.indexOfChild(miniDrawer) == -1)
|
||||||
miniDrawerView = miniDrawer?.build(context)
|
drawerContainerLandscape.addView(miniDrawer)
|
||||||
if (miniDrawerContainerLandscape.indexOfChild(miniDrawerView) == -1)
|
|
||||||
miniDrawerContainerLandscape.addView(miniDrawerView)
|
|
||||||
Log.d("NavLib", "- mini drawer land enabled")
|
Log.d("NavLib", "- mini drawer land enabled")
|
||||||
drawerSetDragMargin(72 * resources.displayMetrics.density)
|
drawerSetDragMargin(72 * resources.displayMetrics.density)
|
||||||
drawerMode = DRAWER_MODE_MINI
|
drawerMode = DRAWER_MODE_MINI
|
||||||
updateMiniDrawer()
|
updateMiniDrawer()
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (miniDrawerContainerLandscape.childCount > 0) {
|
if (drawerContainerLandscape.childCount > 0) {
|
||||||
miniDrawerContainerLandscape.removeAllViews()
|
drawerContainerLandscape.removeAllViews()
|
||||||
}
|
}
|
||||||
Log.d("NavLib", "- mini drawer land disabled")
|
Log.d("NavLib", "- mini drawer land disabled")
|
||||||
drawerSetDragMargin(20 * resources.displayMetrics.density)
|
drawerSetDragMargin(20 * resources.displayMetrics.density)
|
||||||
drawerMode = DRAWER_MODE_NORMAL
|
drawerMode = DRAWER_MODE_NORMAL
|
||||||
}
|
}
|
||||||
if (widthDp >= 9000) {
|
if (widthDp >= 900) {
|
||||||
// screen is big enough to show fixed drawer
|
// screen is big enough to show fixed drawer
|
||||||
if (drawer?.drawerLayout?.indexOfChild(drawerView) != -1) {
|
if (drawerLayout.indexOfChild(drawer) != -1) {
|
||||||
// remove from slider
|
// remove from slider
|
||||||
drawer?.drawerLayout?.removeView(drawerView)
|
drawerLayout.removeView(drawer)
|
||||||
}
|
}
|
||||||
// lock the slider
|
// lock the slider
|
||||||
drawer?.drawerLayout?.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED)
|
drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED)
|
||||||
Log.d("NavLib", "- slider disabled")
|
Log.d("NavLib", "- slider disabled")
|
||||||
// add to fixed container
|
// add to fixed container
|
||||||
if (fixedDrawerContainer.indexOfChild(drawerView) == -1)
|
if (drawerContainerLandscape.indexOfChild(drawer) == -1)
|
||||||
fixedDrawerContainer.addView(drawerView)
|
drawerContainerLandscape.addView(drawer, fixedLayoutParams)
|
||||||
|
drawer.visibility = View.VISIBLE
|
||||||
Log.d("NavLib", "- fixed container enabled")
|
Log.d("NavLib", "- fixed container enabled")
|
||||||
drawerMode = DRAWER_MODE_FIXED
|
drawerMode = DRAWER_MODE_FIXED
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// screen is too small for the fixed drawer
|
// screen is too small for the fixed drawer
|
||||||
if (fixedDrawerContainer.childCount > 0) {
|
if (drawerContainerLandscape.indexOfChild(drawer) != -1) {
|
||||||
// remove from fixed container
|
// remove from fixed container
|
||||||
fixedDrawerContainer.removeAllViews()
|
drawerContainerLandscape.removeView(drawer)
|
||||||
}
|
}
|
||||||
Log.d("NavLib", "- fixed container disabled")
|
Log.d("NavLib", "- fixed container disabled")
|
||||||
// unlock the slider
|
// unlock the slider
|
||||||
drawer?.drawerLayout?.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED)
|
drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED)
|
||||||
if (drawer?.drawerLayout?.indexOfChild(drawerView) == -1) {
|
if (drawerLayout.indexOfChild(drawer) == -1) {
|
||||||
// add to slider
|
// add to slider
|
||||||
drawer?.drawerLayout?.addView(drawerView)
|
drawerLayout.addView(drawer, drawerLayoutParams)
|
||||||
}
|
}
|
||||||
Log.d("NavLib", "- slider enabled")
|
Log.d("NavLib", "- slider enabled")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
miniDrawerElevation.visibility = if (drawerMode == DRAWER_MODE_MINI) View.VISIBLE else View.GONE
|
miniDrawerElevation.visibility = if (drawerMode == DRAWER_MODE_MINI || drawerMode == DRAWER_MODE_FIXED) View.VISIBLE else View.GONE
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateMiniDrawer() {
|
private fun updateMiniDrawer() {
|
||||||
selection = drawer?.currentSelection?.toInt() ?: -1
|
selection = drawer.selectedItemIdentifier.toInt()
|
||||||
//if (drawerMode == DRAWER_MODE_MINI)
|
//if (drawerMode == DRAWER_MODE_MINI)
|
||||||
miniDrawer?.createItems()
|
miniDrawer.createItems()
|
||||||
}
|
}
|
||||||
|
|
||||||
/* _____ _ _ _ _ _ _
|
/* _____ _ _ _ _ _ _
|
||||||
@ -435,45 +428,37 @@ class NavDrawer(
|
|||||||
| | | |_| | |_) | | | (__ | | | | | | __/ |_| | | | (_) | (_| \__ \
|
| | | |_| | |_) | | | (__ | | | | | | __/ |_| | | | (_) | (_| \__ \
|
||||||
|_| \__,_|_.__/|_|_|\___| |_| |_| |_|\___|\__|_| |_|\___/ \__,_|__*/
|
|_| \__,_|_.__/|_|_|\___| |_| |_| |_|\___|\__|_| |_|\___/ \__,_|__*/
|
||||||
var isOpen
|
var isOpen
|
||||||
get() = drawer?.isDrawerOpen ?: false || drawerMode == DRAWER_MODE_FIXED
|
get() = drawerLayout.isOpen || drawerMode == DRAWER_MODE_FIXED
|
||||||
set(value) {
|
set(value) {
|
||||||
if (drawerMode == DRAWER_MODE_FIXED)
|
if (drawerMode == DRAWER_MODE_FIXED)
|
||||||
return
|
return
|
||||||
if (value && !isOpen) drawer?.openDrawer() else if (!value && isOpen) drawer?.closeDrawer()
|
if (value && !isOpen) drawerLayout.open() else if (!value && isOpen) drawerLayout.close()
|
||||||
}
|
}
|
||||||
fun open() { isOpen = true }
|
fun open() { isOpen = true }
|
||||||
fun close() { isOpen = false }
|
fun close() { isOpen = false }
|
||||||
fun toggle() {
|
fun toggle() { isOpen = !isOpen }
|
||||||
if (drawer == null)
|
|
||||||
return
|
|
||||||
isOpen = !isOpen
|
|
||||||
}
|
|
||||||
|
|
||||||
var profileSelectionIsOpen
|
var profileSelectionIsOpen
|
||||||
get() = accountHeader?.isSelectionListShown == true
|
get() = accountHeader.selectionListShown
|
||||||
set(value) {
|
set(value) {
|
||||||
if (value != profileSelectionIsOpen)
|
if (value != profileSelectionIsOpen)
|
||||||
profileSelectionToggle()
|
profileSelectionToggle()
|
||||||
}
|
}
|
||||||
fun profileSelectionOpen() { profileSelectionIsOpen = true }
|
fun profileSelectionOpen() { profileSelectionIsOpen = true }
|
||||||
fun profileSelectionClose() { profileSelectionIsOpen = false }
|
fun profileSelectionClose() { profileSelectionIsOpen = false }
|
||||||
fun profileSelectionToggle() {
|
fun profileSelectionToggle() { accountHeader.selectionListShown = !accountHeader.selectionListShown }
|
||||||
accountHeader?.let {
|
|
||||||
it.toggleSelectionList(it.view.context)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var drawerOpenedListener: (() -> Unit)? = null
|
var drawerOpenedListener: (() -> Unit)? = null
|
||||||
var drawerClosedListener: (() -> Unit)? = null
|
var drawerClosedListener: (() -> Unit)? = null
|
||||||
var drawerItemSelectedListener: ((id: Int, position: Int, drawerItem: IDrawerItem<*>) -> Boolean)? = null
|
var drawerItemSelectedListener: ((id: Int, position: Int, drawerItem: IDrawerItem<*>) -> Boolean)? = null
|
||||||
var drawerItemLongClickListener: ((id: Int, position: Int, drawerItem: IDrawerItem<*>) -> Boolean)? = null
|
var drawerItemLongClickListener: ((id: Int, position: Int, drawerItem: IDrawerItem<*>) -> Boolean)? = null
|
||||||
var drawerProfileSelectedListener: ((id: Int, profile: IProfile<*>, current: Boolean, view: View?) -> Boolean)? = null
|
var drawerProfileSelectedListener: ((id: Int, profile: IProfile, current: Boolean, view: View?) -> Boolean)? = null
|
||||||
var drawerProfileLongClickListener: ((id: Int, profile: IProfile<*>, current: Boolean, view: View) -> Boolean)? = null
|
var drawerProfileLongClickListener: ((id: Int, profile: IProfile, current: Boolean, view: View?) -> Boolean)? = null
|
||||||
var drawerProfileImageClickListener: ((id: Int, profile: IProfile<*>, current: Boolean, view: View) -> Boolean)? = null
|
var drawerProfileImageClickListener: ((id: Int, profile: IProfile, current: Boolean, view: View) -> Boolean)? = null
|
||||||
var drawerProfileImageLongClickListener: ((id: Int, profile: IProfile<*>, current: Boolean, view: View) -> Boolean)? = null
|
var drawerProfileImageLongClickListener: ((id: Int, profile: IProfile, current: Boolean, view: View) -> Boolean)? = null
|
||||||
var drawerProfileListEmptyListener: (() -> Unit)? = null
|
var drawerProfileListEmptyListener: (() -> Unit)? = null
|
||||||
var drawerProfileSettingClickListener: ((id: Int, view: View?) -> Boolean)? = null
|
var drawerProfileSettingClickListener: ((id: Int, view: View?) -> Boolean)? = null
|
||||||
var drawerProfileSettingLongClickListener: ((id: Int, view: View) -> Boolean)? = null
|
var drawerProfileSettingLongClickListener: ((id: Int, view: View?) -> Boolean)? = null
|
||||||
|
|
||||||
fun miniDrawerEnabled(): Boolean = drawerMode == DRAWER_MODE_MINI
|
fun miniDrawerEnabled(): Boolean = drawerMode == DRAWER_MODE_MINI
|
||||||
fun fixedDrawerEnabled(): Boolean = drawerMode == DRAWER_MODE_FIXED
|
fun fixedDrawerEnabled(): Boolean = drawerMode == DRAWER_MODE_FIXED
|
||||||
@ -485,26 +470,26 @@ class NavDrawer(
|
|||||||
profileSelectionClose()
|
profileSelectionClose()
|
||||||
selection = id
|
selection = id
|
||||||
|
|
||||||
if (drawer?.currentSelection != id.toLong()) {
|
if (drawer.selectedItemIdentifier != id.toLong()) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (drawer?.currentSelection != id.toLong() || !fireOnClick)
|
if (drawer.selectedItemIdentifier != id.toLong() || !fireOnClick)
|
||||||
drawer?.setSelection(id.toLong(), fireOnClick)
|
drawer.setSelection(id.toLong(), fireOnClick)
|
||||||
|
|
||||||
miniDrawer?.setSelection(-1L)
|
miniDrawer.setSelection(-1L)
|
||||||
if (drawerMode == DRAWER_MODE_MINI)
|
if (drawerMode == DRAWER_MODE_MINI)
|
||||||
miniDrawer?.setSelection(id.toLong())
|
miniDrawer.setSelection(id.toLong())
|
||||||
}
|
}
|
||||||
fun getSelection(): Int = selection
|
fun getSelection(): Int = selection
|
||||||
|
|
||||||
// TODO 2019-08-27 add methods for Drawable, @DrawableRes
|
// TODO 2019-08-27 add methods for Drawable, @DrawableRes
|
||||||
fun setAccountHeaderBackground(path: String?) {
|
fun setAccountHeaderBackground(path: String?) {
|
||||||
if (path == null) {
|
if (path == null) {
|
||||||
accountHeader?.setBackgroundRes(R.drawable.header)
|
accountHeader.headerBackground = ImageHolder(R.drawable.header)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
accountHeader?.setHeaderBackground(ImageHolder(path))
|
accountHeader.headerBackground = ImageHolder(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* _____ __ _ _
|
/* _____ __ _ _
|
||||||
@ -516,12 +501,12 @@ class NavDrawer(
|
|||||||
private var profileList: MutableList<IDrawerProfile> = mutableListOf()
|
private var profileList: MutableList<IDrawerProfile> = mutableListOf()
|
||||||
|
|
||||||
fun addProfileSettings(vararg items: ProfileSettingDrawerItem) {
|
fun addProfileSettings(vararg items: ProfileSettingDrawerItem) {
|
||||||
accountHeader?.profiles?.addAll(items)
|
accountHeader.profiles?.addAll(items)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateProfileList() {
|
private fun updateProfileList() {
|
||||||
// remove all profile items
|
// remove all profile items
|
||||||
val profiles = accountHeader?.profiles?.filterNot { it is ProfileDrawerItem } as MutableList<IProfile<*>>?
|
val profiles = accountHeader.profiles?.filterNot { it is ProfileDrawerItem } as MutableList<IProfile>?
|
||||||
|
|
||||||
if (profileList.isEmpty())
|
if (profileList.isEmpty())
|
||||||
drawerProfileListEmptyListener?.invoke()
|
drawerProfileListEmptyListener?.invoke()
|
||||||
@ -537,7 +522,7 @@ class NavDrawer(
|
|||||||
.also { profiles?.add(index, it) }
|
.also { profiles?.add(index, it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
accountHeader?.profiles = profiles
|
accountHeader.profiles = profiles
|
||||||
|
|
||||||
updateMiniDrawer()
|
updateMiniDrawer()
|
||||||
}
|
}
|
||||||
@ -550,10 +535,10 @@ class NavDrawer(
|
|||||||
val profileListEmpty: Boolean
|
val profileListEmpty: Boolean
|
||||||
get() = profileList.isEmpty()
|
get() = profileList.isEmpty()
|
||||||
var currentProfile: Int
|
var currentProfile: Int
|
||||||
get() = accountHeader?.activeProfile?.identifier?.toInt() ?: -1
|
get() = accountHeader.activeProfile?.identifier?.toInt() ?: -1
|
||||||
set(value) {
|
set(value) {
|
||||||
Log.d("NavDebug", "currentProfile = $value")
|
Log.d("NavDebug", "currentProfile = $value")
|
||||||
accountHeader?.setActiveProfile(value.toLong(), false)
|
accountHeader.setActiveProfile(value.toLong(), false)
|
||||||
currentProfileObj = profileList.singleOrNull { it.id == value }
|
currentProfileObj = profileList.singleOrNull { it.id == value }
|
||||||
setToolbarProfileImage(currentProfileObj)
|
setToolbarProfileImage(currentProfileObj)
|
||||||
updateBadges()
|
updateBadges()
|
||||||
@ -595,7 +580,7 @@ class NavDrawer(
|
|||||||
updateProfileList()
|
updateProfileList()
|
||||||
}
|
}
|
||||||
fun removeAllProfileSettings() {
|
fun removeAllProfileSettings() {
|
||||||
accountHeader?.profiles = accountHeader?.profiles?.filterNot { it is ProfileSettingDrawerItem }?.toMutableList()
|
accountHeader.profiles = accountHeader.profiles?.filterNot { it is ProfileSettingDrawerItem }?.toMutableList()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getProfileById(id: Int, run: (it: IDrawerProfile?) -> Unit) {
|
fun getProfileById(id: Int, run: (it: IDrawerProfile?) -> Unit) {
|
||||||
@ -631,10 +616,10 @@ class NavDrawer(
|
|||||||
|
|
||||||
currentProfileObj = profileList.singleOrNull { it.id == currentProfile }
|
currentProfileObj = profileList.singleOrNull { it.id == currentProfile }
|
||||||
|
|
||||||
drawer?.drawerItems?.forEachIndexed { index, item ->
|
drawer.itemAdapter.itemList.items.forEachIndexed { index, item ->
|
||||||
if (item is Badgeable<*>) {
|
if (item is Badgeable) {
|
||||||
item.withBadge(null)
|
item.badge = null
|
||||||
drawer!!.updateItem(item)
|
drawer.updateItem(item)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -652,7 +637,7 @@ class NavDrawer(
|
|||||||
return@forEach
|
return@forEach
|
||||||
}
|
}
|
||||||
Log.d("NavDebug", "- Set badge ${it.count} for ${it.drawerItemId}")
|
Log.d("NavDebug", "- Set badge ${it.count} for ${it.drawerItemId}")
|
||||||
drawer?.updateBadge(
|
drawer.updateBadge(
|
||||||
it.drawerItemId?.toLong() ?: 0,
|
it.drawerItemId?.toLong() ?: 0,
|
||||||
when {
|
when {
|
||||||
it.count == 0 -> null
|
it.count == 0 -> null
|
||||||
|
@ -7,8 +7,8 @@
|
|||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
tools:parentTag="FrameLayout">
|
tools:parentTag="FrameLayout">
|
||||||
|
|
||||||
<LinearLayout
|
<androidx.drawerlayout.widget.DrawerLayout
|
||||||
android:id="@+id/nv_drawerContainer"
|
android:id="@+id/nv_drawerLayout"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
@ -37,10 +37,11 @@
|
|||||||
tools:paddingBottom="48dp">
|
tools:paddingBottom="48dp">
|
||||||
|
|
||||||
<FrameLayout
|
<FrameLayout
|
||||||
android:id="@+id/nv_miniDrawerContainerLandscape"
|
android:id="@+id/nv_drawerContainerLandscape"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:background="@color/colorSurface_4dp"/><!--tools:layout_width="72dp"-->
|
android:background="@color/colorSurface_4dp"
|
||||||
|
tools:layout_width="72dp" />
|
||||||
|
|
||||||
<androidx.coordinatorlayout.widget.CoordinatorLayout
|
<androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||||
android:id="@+id/nv_coordinator"
|
android:id="@+id/nv_coordinator"
|
||||||
@ -68,7 +69,7 @@
|
|||||||
android:layout_marginEnd="13dp"
|
android:layout_marginEnd="13dp"
|
||||||
android:layout_marginRight="13dp"
|
android:layout_marginRight="13dp"
|
||||||
android:scaleType="centerCrop"
|
android:scaleType="centerCrop"
|
||||||
app:biv_selectorOnPress="#80ffffff"
|
app:materialDrawerSelectorOnPress="#80ffffff"
|
||||||
tools:src="@tools:sample/backgrounds/scenic" />
|
tools:src="@tools:sample/backgrounds/scenic" />
|
||||||
|
|
||||||
</pl.szczodrzynski.navlib.NavToolbar>
|
</pl.szczodrzynski.navlib.NavToolbar>
|
||||||
@ -94,7 +95,8 @@
|
|||||||
android:id="@+id/nv_miniDrawerContainerPortrait"
|
android:id="@+id/nv_miniDrawerContainerPortrait"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:background="@color/colorSurface_4dp" /><!--tools:layout_width="72dp"-->
|
android:background="@color/colorSurface_4dp"
|
||||||
|
tools:layout_width="72dp" /><!--tools:layout_width="72dp"-->
|
||||||
|
|
||||||
<View
|
<View
|
||||||
android:id="@+id/nv_miniDrawerElevation"
|
android:id="@+id/nv_miniDrawerElevation"
|
||||||
@ -178,13 +180,7 @@
|
|||||||
|
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
|
|
||||||
<FrameLayout
|
</androidx.drawerlayout.widget.DrawerLayout>
|
||||||
android:id="@+id/nv_fixedDrawerContainer"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
tools:background="#4caf50"/><!--tools:layout_width="300dp"-->
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<View
|
<View
|
||||||
android:id="@+id/nv_statusBarDarker"
|
android:id="@+id/nv_statusBarDarker"
|
||||||
|
@ -95,16 +95,9 @@
|
|||||||
<item name="android:textViewStyle">@style/NavView.TextView</item>
|
<item name="android:textViewStyle">@style/NavView.TextView</item>
|
||||||
|
|
||||||
<!-- drawer & bottom sheet styling -->
|
<!-- drawer & bottom sheet styling -->
|
||||||
<item name="material_drawer_background">?android:colorBackground</item>
|
<item name="materialDrawerStyle">@style/Widget.MaterialDrawerStyle</item>
|
||||||
<item name="material_drawer_primary_text">?android:textColorPrimary</item>
|
<item name="materialDrawerHeaderStyle">@style/Widget.MaterialDrawerHeaderStyle</item>
|
||||||
<item name="material_drawer_primary_icon">#5F6368</item>
|
<!--<item name="materialDrawerPrimaryIcon">#5F6368</item>-->
|
||||||
<item name="material_drawer_secondary_text">?android:textColorSecondary</item>
|
|
||||||
<item name="material_drawer_hint_text">@color/material_drawer_hint_text</item>
|
|
||||||
<item name="material_drawer_divider">@color/material_drawer_divider</item>
|
|
||||||
<item name="material_drawer_selected">@color/material_drawer_selected</item> <!-- Material 2 defines 12% alpha, primary color -->
|
|
||||||
<item name="material_drawer_selected_text">#242424</item>
|
|
||||||
<item name="material_drawer_header_selection_text">@color/material_drawer_header_selection_text</item>
|
|
||||||
<item name="material_drawer_header_selection_subtext">@color/material_drawer_dark_header_selection_subtext</item>
|
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="NavView.Dark" parent="Theme.MaterialComponents.NoActionBar">
|
<style name="NavView.Dark" parent="Theme.MaterialComponents.NoActionBar">
|
||||||
@ -148,16 +141,9 @@
|
|||||||
<item name="android:textViewStyle">@style/NavView.TextView</item>
|
<item name="android:textViewStyle">@style/NavView.TextView</item>
|
||||||
|
|
||||||
<!-- drawer & bottom sheet styling -->
|
<!-- drawer & bottom sheet styling -->
|
||||||
<item name="material_drawer_background">?android:colorBackground</item>
|
<item name="materialDrawerStyle">@style/Widget.MaterialDrawerStyle</item>
|
||||||
<item name="material_drawer_primary_text">?android:textColorPrimary</item>
|
<item name="materialDrawerHeaderStyle">@style/Widget.MaterialDrawerHeaderStyle</item>
|
||||||
<item name="material_drawer_primary_icon">#9AA0A6</item>
|
<!--<item name="material_drawer_primary_icon">#9AA0A6</item>-->
|
||||||
<item name="material_drawer_secondary_text">?android:textColorSecondary</item>
|
|
||||||
<item name="material_drawer_hint_text">@color/material_drawer_dark_hint_text</item>
|
|
||||||
<item name="material_drawer_divider">@color/material_drawer_dark_divider</item>
|
|
||||||
<item name="material_drawer_selected">@color/material_drawer_dark_selected</item> <!-- Material 2 defines 12% alpha, primary color -->
|
|
||||||
<item name="material_drawer_selected_text">#FFFFFF</item>
|
|
||||||
<item name="material_drawer_header_selection_text">@color/material_drawer_dark_header_selection_text</item>
|
|
||||||
<item name="material_drawer_header_selection_subtext">@color/material_drawer_dark_header_selection_subtext</item>
|
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="NavView.Black" parent="NavView.Dark">
|
<style name="NavView.Black" parent="NavView.Dark">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user