Fix currently selected item not displaying selection background. Add support for profile unread badges.

This commit is contained in:
kubasz 2020-03-24 15:38:43 +01:00
parent 1d0e98a90e
commit 43f5ecdef5
6 changed files with 48 additions and 11 deletions

View File

@ -36,7 +36,9 @@ dependencies {
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "androidx.appcompat:appcompat:${versions.appcompat}"
implementation "androidx.legacy:legacy-support-v4:${versions.legacy}"
implementation "com.mikepenz:materialdrawer:${versions.materialdrawer}"
api("com.github.kuba2k2:MaterialDrawer:${versions.materialdrawer}") {
exclude module: 'library-iconics'
}
implementation "com.mikepenz:iconics-core:${versions.iconics}"
implementation "com.mikepenz:iconics-views:${versions.iconics}"
implementation "com.mikepenz:community-material-typeface:${versions.font_cmd}@aar"

View File

@ -260,8 +260,8 @@ class MainActivity : AppCompatActivity() {
DrawerPrimaryItem().withName("Lock screen")
.withDescription("aaand not visible in Mini Drawer")
.withIsHiddenInMiniDrawer(true)
.withIdentifier(62)
.withIsHiddenInMiniDrawer(true)
.withBadgeStyle(badgeStyle)
.withIcon(CommunityMaterial.Icon.cmd_fingerprint),
@ -284,9 +284,6 @@ class MainActivity : AppCompatActivity() {
.withIcon(CommunityMaterial.Icon2.cmd_internet_explorer)
)
setUnreadCount(2, 20, 30) // phil swift has 30 unreads on "Settings item"
setUnreadCount(4, 40, 1000) // mark has 99+ unreads on "Lock screen item"
//setAccountHeaderBackground("/sdcard/ban.gif")
appendProfiles(
@ -298,6 +295,9 @@ class MainActivity : AppCompatActivity() {
DrawerProfile(6, "Gandalf", "http://sax.hol.es/", null)
)
setUnreadCount(2, 20, 30) // phil swift has 30 unreads on "Settings item"
setUnreadCount(4, 40, 1000) // mark has 99+ unreads on "Lock screen item"
addProfileSettings(
ProfileSettingDrawerItem()
.withName("Add Account")
@ -354,6 +354,10 @@ class MainActivity : AppCompatActivity() {
}
}
setSelection.setOnClickListener {
navView.drawer.setSelection(id = 1, fireOnClick = false)
}
navView.bottomSheet.apply {
this += BottomSheetPrimaryItem(true)

View File

@ -35,6 +35,12 @@
android:layout_height="48dp"
android:text="Ripple bottombar" />
<Button
android:id="@+id/setSelection"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:text="Set selection" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"

View File

@ -44,7 +44,7 @@ buildscript {
play_services : "17.0.0",
materialdialogs : "0.9.6.0",
materialdrawer : "8.0.0-rc02",
materialdrawer : "817e45765c367034b03046aaea6e95eeabcb40e9",
iconics : "4.0.1",
font_cmd : "3.5.95.1-kotlin",

View File

@ -45,7 +45,9 @@ dependencies {
implementation "androidx.recyclerview:recyclerview:${versions.recyclerView}"
implementation "com.google.android.material:material:${versions.material}"
api "com.mikepenz:materialdrawer:${versions.materialdrawer}"
api("com.github.kuba2k2:MaterialDrawer:${versions.materialdrawer}") {
exclude module: 'library-iconics'
}
api "com.mikepenz:community-material-typeface:${versions.font_cmd}@aar"
api "com.mikepenz:iconics-core:${versions.iconics}"
implementation "com.mikepenz:materialize:1.2.1"

View File

@ -99,6 +99,7 @@ class NavDrawer(
accountHeader = AccountHeaderView(context).apply {
headerBackground = ImageHolder(R.drawable.header)
displayBadgesOnSmallProfileImages = true
onAccountHeaderListener = { view, profile, current ->
if (profile is ProfileSettingDrawerItem) {
@ -477,7 +478,7 @@ class NavDrawer(
if (drawer.selectedItemIdentifier != id.toLong() || !fireOnClick)
drawer.setSelection(id.toLong(), fireOnClick)
miniDrawer.setSelection(-1L)
//miniDrawer.setSelection(-1L)
if (drawerMode == DRAWER_MODE_MINI)
miniDrawer.setSelection(id.toLong())
}
@ -518,12 +519,14 @@ class NavDrawer(
.withName(profile.name)
.withEmail(profile.subname)
.also { it.icon = image }
.withBadgeStyle(badgeStyle)
.withNameShown(true)
.also { profiles?.add(index, it) }
}
accountHeader.profiles = profiles
updateBadges()
updateMiniDrawer()
}
@ -623,12 +626,32 @@ class NavDrawer(
}
}
var profileCounters = listOf<IUnreadCounter>()
accountHeader.profiles?.forEach { profile ->
if (profile !is ProfileDrawerItem) return@forEach
val counters = unreadCounterList.filter { it.profileId == profile.identifier.toInt() }
val count = counters.sumBy { it.count }
val badge = when {
count == 0 -> null
count >= 99 -> StringHolder("99+")
else -> StringHolder(count.toString())
}
if (profile.badge != badge) {
profile.badge = badge
accountHeader.updateProfile(profile)
}
if (currentProfile == profile.identifier.toInt())
profileCounters = counters
}
Log.d("NavDebug", "updateBadges()")
unreadCounterList.map {
profileCounters.map {
it.drawerItemId = unreadCounterTypeMap[it.type]
}
var totalCount = 0
unreadCounterList.forEach {
profileCounters.forEach {
if (it.drawerItemId == null)
return@forEach
if (it.profileId != currentProfile) {
@ -699,10 +722,10 @@ class NavDrawer(
}
if (item != null) {
item.count = count
updateBadges()
}
else {
unreadCounterList.add(UnreadCounter(profileId, type, null, count))
}
updateBadges()
}
}