Fix styles, themes & colors. Add some BottomSheet item adding methods. Implement BottomSheet ToggleGroup.

This commit is contained in:
kubasz 2019-08-24 20:39:34 +02:00
parent ab5bb48e61
commit 6918c36b8b
13 changed files with 430 additions and 147 deletions

View File

@ -24,6 +24,10 @@ android {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
packagingOptions {
exclude 'META-INF/library-core_release.kotlin_module'
}
}
dependencies {
@ -31,8 +35,8 @@ dependencies {
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation "androidx.legacy:legacy-support-v4:1.0.0"
implementation "com.mikepenz:materialdrawer:6.1.2"
implementation "com.mikepenz:crossfader:1.6.0" // do not update
//implementation "com.mikepenz:materialdrawer:7.0.0-rc05"
//implementation "com.mikepenz:crossfader:1.6.0" // do not update
implementation "com.mikepenz:iconics-core:${iconics}" // do not update. >3.1.0 Breaks jelly bean
implementation "com.mikepenz:iconics-views:${iconics}" // do not update
implementation "com.mikepenz:community-material-typeface:3.5.95.1-kotlin@aar"

View File

@ -2,18 +2,24 @@ package pl.szczodrzynski.navigation
import android.annotation.SuppressLint
import android.content.Context
import android.graphics.Color
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.view.Gravity
import android.view.View
import android.widget.Toast
import android.view.Gravity
import androidx.appcompat.app.AppCompatActivity
import com.mikepenz.iconics.typeface.library.community.material.CommunityMaterial
import kotlinx.android.synthetic.main.sample_nav_view.*
import pl.szczodrzynski.navlib.SystemBarsUtil
import pl.szczodrzynski.navlib.SystemBarsUtil.Companion.COLOR_DO_NOT_CHANGE
import pl.szczodrzynski.navlib.SystemBarsUtil.Companion.COLOR_HALF_TRANSPARENT
import pl.szczodrzynski.navlib.SystemBarsUtil.Companion.COLOR_PRIMARY_DARK
import pl.szczodrzynski.navlib.bottomsheet.NavBottomSheet
import pl.szczodrzynski.navlib.bottomsheet.NavBottomSheet.Companion.SORT_MODE_ASCENDING
import pl.szczodrzynski.navlib.bottomsheet.NavBottomSheet.Companion.SORT_MODE_DESCENDING
import pl.szczodrzynski.navlib.bottomsheet.NavBottomSheet.Companion.TOGGLE_GROUP_SORTING_ORDER
import pl.szczodrzynski.navlib.bottomsheet.items.PrimaryItem
import pl.szczodrzynski.navlib.bottomsheet.items.SeparatorItem
import pl.szczodrzynski.navlib.getColorFromAttr
@ -195,7 +201,55 @@ class MainActivity : AppCompatActivity() {
navView.bottomSheet.enableDragToOpen = isChecked
}
navView.bottomBar.fabIcon = CommunityMaterial.Icon2.cmd_pencil
navView.bottomBar.fabExtendedText = "Compose"
navView.bottomBar.fabExtended = false
navView.bottomSheet.apply {
this += PrimaryItem(true)
.withId(1)
.withTitle("Compose")
.withIcon(CommunityMaterial.Icon2.cmd_pencil)
.withOnClickListener(View.OnClickListener {
Toast.makeText(this@MainActivity, "Compose message", Toast.LENGTH_SHORT).show()
})
this += SeparatorItem(false)
this += PrimaryItem(false)
.withId(3)
.withTitle("Synchronise")
.withIcon(CommunityMaterial.Icon2.cmd_sync)
.withOnClickListener(View.OnClickListener {
Toast.makeText(this@MainActivity, "Synchronising...", Toast.LENGTH_SHORT).show()
})
this += PrimaryItem(false)
.withId(4)
.withTitle("Help")
.withIcon(CommunityMaterial.Icon2.cmd_help)
.withOnClickListener(View.OnClickListener {
Toast.makeText(this@MainActivity, "Want some help?", Toast.LENGTH_SHORT).show()
})
toggleGroupTitle = "Sort by"
toggleGroupRemoveItems()
toggleGroupSelectionMode = TOGGLE_GROUP_SORTING_ORDER
toggleGroupAddItem(0, "By date", null, SORT_MODE_DESCENDING)
toggleGroupAddItem(1, "By subject", null, SORT_MODE_ASCENDING)
toggleGroupAddItem(2, "By sender", null, SORT_MODE_ASCENDING)
toggleGroupAddItem(3, "By android", null, SORT_MODE_ASCENDING)
toggleGroupSortingOrderListener = object : NavBottomSheet.OnToggleGroupSortingListener {
override fun onSortingOrder(id: Int, sortMode: Int) {
Toast.makeText(
this@MainActivity,
"Sort mode $id ${if (sortMode == SORT_MODE_ASCENDING) "ascending" else "descending"}",
Toast.LENGTH_SHORT
).show()
}
}
toggleGroupCheck(1)
}
}
}

View File

@ -1,72 +1,35 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<style name="AppTheme.Widget" />
<style name="AppTheme.Widget.ExtendedFloatingActionButton" parent="Widget.MaterialComponents.ExtendedFloatingActionButton">
<item name="android:textColor">?colorOnSecondary</item>
<item name="android:iconTint" tools:targetApi="o">?colorSecondaryVariant</item>
<item name="iconTint">?colorSecondaryVariant</item>
</style>
<!-- Base application theme. -->
<style name="AppTheme" parent="NavView">
<!-- Customize your theme here. -->
<style name="AppTheme" parent="NavView.Black">
<item name="colorPrimary">#64b5f6</item>
<item name="colorPrimaryDark">#1976d2</item>
<item name="colorPrimaryVariant">#2196f3</item>
<item name="colorAccent">#ffb300</item>
<!--<item name="colorAccent">#ffb300</item>-->
<item name="colorAccent">#2962ff</item>
<item name="colorSecondary">?colorAccent</item>
<item name="colorSecondaryVariant">#fff59d</item>
<item name="android:colorBackground">@color/black</item>
<item name="android:windowBackground">?android:colorBackground</item>
<item name="colorSurface">#1f1f1f</item>
<!--<item name="android:statusBarColor" tools:targetApi="lollipop">@android:color/transparent</item>
<item name="android:windowTranslucentStatus" tools:targetApi="kitkat">false</item>
&lt;!&ndash;<item name="android:navigationBarColor" tools:targetApi="lollipop">@android:color/transparent</item>&ndash;&gt;
<item name="android:windowTranslucentNavigation" tools:targetApi="kitkat">true</item>-->
<item name="colorFab">#4CAF50</item>
<item name="colorFabIcon">#c8e6c9</item>
<item name="colorOnFab">#ffffff</item>
<item name="colorOnPrimary">#ffffff</item>
<item name="colorOnSecondary">#ffffff</item>
<item name="colorOnBackground">#ffffff</item>
<item name="colorOnSurface">#ffffff</item>
<item name="nv_actionBarBackground">?colorSurface</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="extendedFloatingActionButtonStyle">@style/AppTheme.Widget.ExtendedFloatingActionButton</item>
</style>
<style name="AppTheme.Light" parent="NavView.Light">
<!-- Customize your theme here. -->
<item name="colorPrimary">#2196f3</item>
<item name="colorPrimaryDark">#1976d2</item>
<item name="colorPrimaryVariant">#2196f3</item>
<item name="colorAccent">#ffb300</item>
<!--<item name="colorAccent">#ffb300</item>-->
<item name="colorAccent">#2962ff</item>
<item name="colorSecondary">?colorAccent</item>
<item name="colorSecondaryVariant">#fff59d</item>
<item name="android:colorBackground">@color/white</item>
<item name="android:windowBackground">?android:colorBackground</item>
<item name="colorSurface">#ffffff</item>
<!--<item name="android:statusBarColor" tools:targetApi="lollipop">@android:color/transparent</item>
<item name="android:windowTranslucentStatus" tools:targetApi="kitkat">false</item>
&lt;!&ndash;<item name="android:navigationBarColor" tools:targetApi="lollipop">@android:color/transparent</item>&ndash;&gt;
<item name="android:windowTranslucentNavigation" tools:targetApi="kitkat">true</item>-->
<item name="colorFab">#4CAF50</item>
<item name="colorFabIcon">#c8e6c9</item>
<item name="colorOnFab">#ffffff</item>
<item name="colorOnPrimary">#ffffff</item>
<item name="colorOnSecondary">#ffffff</item>
<item name="colorOnBackground">#000000</item>
<item name="colorOnSurface">#000000</item>
<item name="nv_actionBarBackground">?colorSurface</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="extendedFloatingActionButtonStyle">@style/AppTheme.Widget.ExtendedFloatingActionButton</item>
</style>
</resources>

View File

@ -41,7 +41,7 @@ dependencies {
implementation 'com.google.android.material:material:1.1.0-alpha09'
implementation "androidx.legacy:legacy-support-v4:1.0.0"
implementation "com.mikepenz:materialdrawer:6.1.2"
implementation "com.mikepenz:materialdrawer:7.0.0-rc05"
implementation "com.mikepenz:iconics-core:4.0.1-b01"
implementation 'com.mikepenz:community-material-typeface:3.5.95.1-kotlin@aar'
@ -50,4 +50,5 @@ dependencies {
implementation "androidx.annotation:annotation:1.1.0"
implementation "com.google.android.material:material:${googleMaterial}"
implementation "androidx.constraintlayout:constraintlayout:${androidXConstraintLayout}"
implementation 'androidx.gridlayout:gridlayout:1.0.0'
}

View File

@ -11,6 +11,7 @@ import com.google.android.material.bottomappbar.BottomAppBar
import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
import com.google.android.material.floatingactionbutton.FloatingActionButton
import com.mikepenz.iconics.IconicsDrawable
import com.mikepenz.iconics.typeface.IIcon
import com.mikepenz.iconics.typeface.library.community.material.CommunityMaterial
import com.mikepenz.iconics.utils.colorInt
import com.mikepenz.iconics.utils.sizeDp
@ -84,6 +85,15 @@ class NavBottomBar : BottomAppBar {
else
fabExtendedView?.shrink()
}
/**
* Set the FAB's icon.
*/
var fabIcon: IIcon = CommunityMaterial.Icon.cmd_android
set(value) {
field = value
fabView?.setImageDrawable(IconicsDrawable(context, value).colorInt(R.attr.colorFabIcon).sizeDp(24))
fabExtendedView?.icon = IconicsDrawable(context, value).colorInt(R.attr.colorFabIcon).sizeDp(24)
}
/**
* Set the ExtendedFAB's text.
*/
@ -101,6 +111,8 @@ class NavBottomBar : BottomAppBar {
true
}
elevation = 0f
navigationIcon = IconicsDrawable(context)
.icon(CommunityMaterial.Icon2.cmd_menu)
.sizeDp(20)

View File

@ -3,15 +3,18 @@ package pl.szczodrzynski.navlib
import android.annotation.SuppressLint
import android.app.Activity
import android.content.Context
import android.os.Build
import android.util.AttributeSet
import android.view.*
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.ViewGroup.LayoutParams.MATCH_PARENT
import android.widget.*
import android.widget.FrameLayout
import android.widget.LinearLayout
import android.widget.SeekBar
import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.core.view.ViewCompat
import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
import com.google.android.material.floatingactionbutton.FloatingActionButton
import com.mikepenz.iconics.typeface.library.community.material.CommunityMaterial
import com.mikepenz.materialdrawer.Drawer
import com.mikepenz.materialdrawer.DrawerBuilder
import com.mikepenz.materialdrawer.model.DividerDrawerItem
@ -146,8 +149,8 @@ class NavView : FrameLayout {
fun addDrawer(activity: Activity) {
//if you want to update the items at a later time it is recommended to keep it in a variable
val item1 = PrimaryDrawerItem().withIdentifier(1).withName("Home")
val item2 = SecondaryDrawerItem().withIdentifier(2).withName("Settings")
val item1 = PrimaryDrawerItem().withIdentifier(1).withName("Home").withIcon(CommunityMaterial.Icon.cmd_google_home)
val item2 = SecondaryDrawerItem().withIdentifier(2).withName("Settings").withIcon(CommunityMaterial.Icon2.cmd_settings)
drawer = DrawerBuilder(activity)
.withDrawerLayout(R.layout.material_drawer_fits_not)
@ -156,7 +159,7 @@ class NavView : FrameLayout {
.withTranslucentStatusBar(false)
.withTranslucentNavigationBar(false)
.withTranslucentNavigationBarProgrammatically(false)
.withToolbar(topBar)
.withToolbar(bottomBar)
.withDisplayBelowStatusBar(true)
.withActionBarDrawerToggleAnimated(true)
.addDrawerItems(
@ -165,9 +168,9 @@ class NavView : FrameLayout {
item2,
SecondaryDrawerItem().withName("Settings")
)
.withOnDrawerItemClickListener { view, position, drawerItem ->
/*.withOnDrawerItemClickListener { view, position, drawerItem ->
true
}
}*/
.build()
bottomBar.drawer = drawer

View File

@ -4,30 +4,46 @@ import android.app.Activity
import android.content.Context
import android.graphics.PorterDuff
import android.graphics.PorterDuffColorFilter
import android.graphics.drawable.Drawable
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.MotionEvent
import android.view.View
import android.view.View.OnClickListener
import android.view.ViewGroup.LayoutParams.WRAP_CONTENT
import android.view.inputmethod.InputMethodManager
import android.widget.LinearLayout
import android.widget.Toast
import android.widget.TextView
import androidx.annotation.DrawableRes
import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.core.widget.NestedScrollView
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.button.MaterialButton
import com.google.android.material.button.MaterialButtonToggleGroup
import com.mikepenz.iconics.IconicsDrawable
import com.mikepenz.iconics.typeface.IIcon
import com.mikepenz.iconics.typeface.library.community.material.CommunityMaterial
import kotlinx.android.synthetic.main.nav_bottom_sheet.view.*
import com.mikepenz.iconics.utils.paddingDp
import com.mikepenz.iconics.utils.sizeDp
import pl.szczodrzynski.navlib.Anim
import pl.szczodrzynski.navlib.bottomsheet.items.EditTextFilledItem
import pl.szczodrzynski.navlib.R
import pl.szczodrzynski.navlib.bottomsheet.items.IBottomSheetItem
import pl.szczodrzynski.navlib.bottomsheet.items.PrimaryItem
import pl.szczodrzynski.navlib.bottomsheet.items.SeparatorItem
import pl.szczodrzynski.navlib.bottomsheet.listeners.OnItemInputListener
import pl.szczodrzynski.navlib.getColorFromAttr
import pl.szczodrzynski.navlib.elevateSurface
import pl.szczodrzynski.navlib.getDrawableFromRes
class NavBottomSheet : CoordinatorLayout {
companion object {
const val TOGGLE_GROUP_SINGLE_SELECTION = 0
const val TOGGLE_GROUP_MULTIPLE_SELECTION = 1
const val TOGGLE_GROUP_SORTING_ORDER = 2
const val SORT_MODE_ASCENDING = 0
const val SORT_MODE_DESCENDING = 1
}
constructor(context: Context) : super(context) {
create(null, 0)
}
@ -42,12 +58,19 @@ class NavBottomSheet : CoordinatorLayout {
private lateinit var scrimView: View
private lateinit var bottomSheet: NestedScrollView
private lateinit var bottomSheetContent: LinearLayout
private lateinit var bottomSheetDragBar: View
private lateinit var content: LinearLayout
private lateinit var dragBar: View
private lateinit var toggleGroupContainer: LinearLayout
private lateinit var toggleGroup: MaterialButtonToggleGroup
private lateinit var toggleGroupTitleView: TextView
private lateinit var list: RecyclerView
private lateinit var bottomSheetBehavior: BottomSheetBehavior<View>
private var bottomSheetVisible = false
val items = ArrayList<IBottomSheetItem<*>>()
private val adapter = BottomSheetAdapter(items)
/**
* Enable the bottom sheet.
* This value is mostly relevant to the [pl.szczodrzynski.navlib.NavBottomBar].
@ -87,12 +110,16 @@ class NavBottomSheet : CoordinatorLayout {
private fun create(attrs: AttributeSet?, defStyle: Int) {
val layoutInflater = LayoutInflater.from(context)
layoutInflater.inflate(pl.szczodrzynski.navlib.R.layout.nav_bottom_sheet, this)
layoutInflater.inflate(R.layout.nav_bottom_sheet, this)
scrimView = findViewById(pl.szczodrzynski.navlib.R.id.nv_scrim)
bottomSheet = findViewById(pl.szczodrzynski.navlib.R.id.nv_bottomSheetView)
bottomSheetContent = findViewById(pl.szczodrzynski.navlib.R.id.nv_bottomSheetContent)
bottomSheetDragBar = findViewById(pl.szczodrzynski.navlib.R.id.nv_bottomSheetDragBar)
scrimView = findViewById(R.id.bs_scrim)
bottomSheet = findViewById(R.id.bs_view)
content = findViewById(R.id.bs_content)
dragBar = findViewById(R.id.bs_dragBar)
toggleGroupContainer = findViewById(R.id.bs_toggleGroupContainer)
toggleGroup = findViewById(R.id.bs_toggleGroup)
toggleGroupTitleView = findViewById(R.id.bs_toggleGroupTitle)
list = findViewById(R.id.bs_list)
bottomSheetBehavior = BottomSheetBehavior.from(bottomSheet)
@ -116,7 +143,7 @@ class NavBottomSheet : CoordinatorLayout {
if (scrimViewEnabled)
Anim.fadeOut(scrimView, 300, null)
// steal the focus from any EditTexts
bottomSheetDragBar.requestFocus()
dragBar.requestFocus()
hideKeyboard()
}
else if (!bottomSheetVisible) {
@ -127,59 +154,170 @@ class NavBottomSheet : CoordinatorLayout {
}
})
bottomSheetContent.background.colorFilter = PorterDuffColorFilter(
getColorFromAttr(
context,
pl.szczodrzynski.navlib.R.attr.colorBackgroundFloating
), PorterDuff.Mode.SRC_ATOP)
content.background.colorFilter = PorterDuffColorFilter(
elevateSurface(context, dp = 8),
PorterDuff.Mode.SRC_ATOP
)
// steal the focus from any EditTexts
bottomSheetDragBar.requestFocus()
dragBar.requestFocus()
val items = ArrayList<IBottomSheetItem<*>>()
items += EditTextFilledItem(true).apply {
id = 0
hint = "Search"
helperText = "0 results found"
onItemInputListener = object : OnItemInputListener {
override fun onItemInput(itemId: Int, item: EditTextFilledItem, text: CharSequence) {
item.helperText = "${text.length} results found"
bs_list.adapter?.notifyItemChanged(itemId)
}
}
}
items += PrimaryItem(true)
.withId(1)
.withTitle("Compose")
.withIcon(CommunityMaterial.Icon2.cmd_pencil)
.withOnClickListener(OnClickListener {
Toast.makeText(context, "Compose message", Toast.LENGTH_SHORT).show()
})
// TODO add separator item
items += SeparatorItem(true)
items += PrimaryItem(true)
.withId(3)
.withTitle("Synchronise")
.withIcon(CommunityMaterial.Icon2.cmd_sync)
.withOnClickListener(OnClickListener {
Toast.makeText(context, "Synchronising...", Toast.LENGTH_SHORT).show()
})
items += PrimaryItem(true)
.withId(4)
.withTitle("Help")
.withIcon(CommunityMaterial.Icon2.cmd_help)
.withOnClickListener(OnClickListener {
Toast.makeText(context, "Want some help?", Toast.LENGTH_SHORT).show()
})
bs_list.apply {
list.apply {
setHasFixedSize(true)
layoutManager = LinearLayoutManager(context)
adapter = BottomSheetAdapter(items)
adapter = this@NavBottomSheet.adapter
}
toggleGroup.addOnButtonCheckedListener(toggleGroupCheckedListener)
}
/* _____ _ _ _
|_ _| | ___ | | | |
| | | |_ ___ _ __ ___ ___ ( _ ) __| | __ _| |_ __ _
| | | __/ _ \ '_ ` _ \/ __| / _ \/\ / _` |/ _` | __/ _` |
_| |_| || __/ | | | | \__ \ | (_> < | (_| | (_| | || (_| |
|_____|\__\___|_| |_| |_|___/ \___/\/ \__,_|\__,_|\__\__,*/
operator fun plusAssign(item: IBottomSheetItem<*>) {
appendItem(item)
}
fun appendItem(item: IBottomSheetItem<*>) {
items += item
adapter.notifyItemInserted(items.size - 1)
}
fun prependItem(item: IBottomSheetItem<*>) {
items.add(0, item)
adapter.notifyItemInserted(0)
}
fun addItemAt(index: Int, item: IBottomSheetItem<*>) {
items.add(index, item)
adapter.notifyItemInserted(index)
}
fun removeItemAt(index: Int) {
items.removeAt(index)
adapter.notifyItemRemoved(index)
}
fun removeAllItems() {
items.clear()
adapter.notifyDataSetChanged()
}
fun removeAllStatic() {
items.filter { it.isContextual }
adapter.notifyDataSetChanged()
}
fun removeAllContextual() {
items.filter { !it.isContextual }
adapter.notifyDataSetChanged()
}
fun removeSeparators() {
items.filterNot { it is SeparatorItem }
adapter.notifyDataSetChanged()
}
var toggleGroupTitle
get() = toggleGroupTitleView.text.toString()
set(value) { toggleGroupTitleView.text = value }
var toggleGroupSelectionMode: Int = TOGGLE_GROUP_SORTING_ORDER
set(value) {
field = value
toggleGroup.isSingleSelection = value != TOGGLE_GROUP_MULTIPLE_SELECTION
}
private fun toggleGroupGetIconicsDrawable(context: Context, icon: IIcon?): Drawable? {
if (icon == null)
return null
return IconicsDrawable(context, icon).sizeDp(24).paddingDp(4)
}
fun toggleGroupAddItem(id: Int, text: String, @DrawableRes icon: Int, defaultSortOrder: Int = SORT_MODE_ASCENDING) {
toggleGroupAddItem(id, text, context.getDrawableFromRes(icon), defaultSortOrder)
}
fun toggleGroupAddItem(id: Int, text: String, icon: IIcon, defaultSortOrder: Int = SORT_MODE_ASCENDING) {
toggleGroupAddItem(id, text, toggleGroupGetIconicsDrawable(context, icon), defaultSortOrder)
}
fun toggleGroupAddItem(id: Int, text: String, icon: Drawable?, defaultSortOrder: Int = SORT_MODE_ASCENDING) {
if (id < 0)
throw IllegalArgumentException("ID cannot be less than 0")
toggleGroup.addView(MaterialButton(context, null, R.attr.materialButtonOutlinedStyle).apply {
this.id = id + 1
this.tag = defaultSortOrder
this.text = text
this.icon = icon
}, WRAP_CONTENT, WRAP_CONTENT)
}
fun toggleGroupCheck(id: Int) {
toggleGroup.check(id)
}
fun toggleGroupRemoveItems() {
toggleGroup.removeAllViews()
}
private val toggleGroupCheckedListener = MaterialButtonToggleGroup.OnButtonCheckedListener { group, checkedId, isChecked ->
if (group.checkedButtonId == View.NO_ID) {
group.check(checkedId)
return@OnButtonCheckedListener
}
/* TAG bit order
* bit 0 = default sorting mode
* bit 1 = is checked
* bit 2 = current sorting mode
*/
if (toggleGroupSelectionMode == TOGGLE_GROUP_SORTING_ORDER) {
val button = group.findViewById<MaterialButton>(checkedId)
var tag = button.tag as Int
var sortingMode: Int? = null
if (isChecked) {
sortingMode = if (tag and 0b010 == 1 shl 1) {
/* the view is checked and clicked once again */
if (tag and 0b100 == SORT_MODE_ASCENDING shl 2) SORT_MODE_DESCENDING else SORT_MODE_ASCENDING
} else {
/* the view is first clicked so use the default sorting mode */
if (tag and 0b001 == SORT_MODE_ASCENDING) SORT_MODE_ASCENDING else SORT_MODE_DESCENDING
}
tag = tag and 0b001 /* retain only default sorting mode */
tag = tag or 0b010 /* set as checked */
tag = tag or (sortingMode shl 2) /* set new sorting mode */
}
else {
tag = tag and 0b001 /* retain only default sorting mode */
}
button.tag = tag
button.icon = toggleGroupGetIconicsDrawable(context, when (sortingMode) {
SORT_MODE_ASCENDING -> CommunityMaterial.Icon2.cmd_sort_ascending
SORT_MODE_DESCENDING -> CommunityMaterial.Icon2.cmd_sort_descending
else -> null
})
if (sortingMode != null) {
toggleGroupSortingOrderListener?.onSortingOrder(checkedId, sortingMode)
}
}
else if (toggleGroup.isSingleSelection && isChecked) {
toggleGroupSingleSelectionListener?.onSingleSelection(checkedId - 1)
}
else {
toggleGroupMultipleSelectionListener?.onMultipleSelection(checkedId - 1, isChecked)
}
}
interface OnToggleGroupChangeListener {
fun onSingleSelection(id: Int)
}
var toggleGroupSingleSelectionListener: OnToggleGroupChangeListener? = null
interface OnToggleGroupCheckedListener {
fun onMultipleSelection(id: Int, checked: Boolean)
}
var toggleGroupMultipleSelectionListener: OnToggleGroupCheckedListener? = null
interface OnToggleGroupSortingListener {
fun onSortingOrder(id: Int, sortMode: Int)
}
var toggleGroupSortingOrderListener: OnToggleGroupSortingListener? = null
fun dispatchBottomBarEvent(event: MotionEvent) {
val location = IntArray(2)
bottomSheet.getLocationOnScreen(location)
@ -188,9 +326,9 @@ class NavBottomSheet : CoordinatorLayout {
}
fun setContentPadding(left: Int, top: Int, right: Int, bottom: Int) {
bottomSheetContent.setPadding(left, top, right, bottom)
content.setPadding(left, top, right, bottom)
}
fun getContentView() = bottomSheetContent
fun getContentView() = content
var isOpen
get() = bottomSheetBehavior.state != BottomSheetBehavior.STATE_HIDDEN

View File

@ -12,6 +12,8 @@ import com.mikepenz.iconics.typeface.library.community.material.CommunityMateria
import com.mikepenz.iconics.utils.sizeDp
import com.mikepenz.materialize.holder.ImageHolder
import pl.szczodrzynski.navlib.R
import pl.szczodrzynski.navlib.colorAttr
import pl.szczodrzynski.navlib.getColorFromAttr
data class PrimaryItem(override val isContextual: Boolean = true) : IBottomSheetItem<PrimaryItem.ViewHolder> {
@ -37,9 +39,11 @@ data class PrimaryItem(override val isContextual: Boolean = true) : IBottomSheet
override fun bindViewHolder(viewHolder: ViewHolder) {
viewHolder.root.setOnClickListener(onClickListener)
viewHolder.text.text = title
viewHolder.text.setTextColor(getColorFromAttr(viewHolder.text.context, R.attr.material_drawer_primary_text))
viewHolder.text.setCompoundDrawables(
IconicsDrawable(viewHolder.text.context)
.icon(iconicsIcon?:CommunityMaterial.Icon.cmd_android)
.colorAttr(viewHolder.text.context, R.attr.material_drawer_primary_icon)
.sizeDp(20),
null,
null,

View File

@ -10,7 +10,7 @@
tools:targetApi="lollipop">
<View
android:id="@+id/nv_scrim"
android:id="@+id/bs_scrim"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#99000000"
@ -18,7 +18,7 @@
tools:visibility="gone" />
<androidx.core.widget.NestedScrollView
android:id="@+id/nv_bottomSheetView"
android:id="@+id/bs_view"
style="@style/width_max_600dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
@ -28,7 +28,7 @@
tools:visibility="visible">
<LinearLayout
android:id="@+id/nv_bottomSheetContent"
android:id="@+id/bs_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/bottom_sheet_background"
@ -38,7 +38,7 @@
android:orientation="vertical">
<ImageView
android:id="@+id/nv_bottomSheetDragBar"
android:id="@+id/bs_dragBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
@ -50,48 +50,70 @@
tools:ignore="ContentDescription" />
<LinearLayout
android:id="@+id/bs_toggleGroupContainer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical">
<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:id="@+id/bs_toggleGroupTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="Sorting order" />
<com.google.android.material.button.MaterialButtonToggleGroup
<androidx.gridlayout.widget.GridLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:singleSelection="true">
android:visibility="gone">
<Button
android:id="@+id/button2"
<com.google.android.material.button.MaterialButton
style="?materialButtonOutlinedStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="By date"
app:icon="@drawable/ic_android"/>
app:icon="@drawable/ic_android" />
<Button
android:id="@+id/button3"
<com.google.android.material.button.MaterialButton
style="?materialButtonOutlinedStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="By subject" />
<com.google.android.material.button.MaterialButton
android:id="@+id/button4"
style="?materialButtonOutlinedStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="By sender" />
</com.google.android.material.button.MaterialButtonToggleGroup>
<com.google.android.material.button.MaterialButton
style="?materialButtonOutlinedStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="By date"
app:icon="@drawable/ic_android" />
<com.google.android.material.button.MaterialButton
style="?materialButtonOutlinedStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="By subject" />
<com.google.android.material.button.MaterialButton
style="?materialButtonOutlinedStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="By sender" />
</androidx.gridlayout.widget.GridLayout>
<com.google.android.material.button.MaterialButtonToggleGroup
android:id="@+id/bs_toggleGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:singleSelection="true"/>
</LinearLayout>
@ -99,6 +121,7 @@
android:id="@+id/bs_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:overScrollMode="never"
android:minHeight="50dp"
tools:listitem="@layout/nav_bs_item_primary"/>

View File

@ -89,8 +89,8 @@
android:focusable="true"
android:visibility="gone"
app:layout_anchor="@id/nv_bottomBar"
app:backgroundTint="?colorAccent"
app:srcCompat="@android:drawable/ic_menu_edit"/>
app:backgroundTint="?colorFab"
tools:srcCompat="@android:drawable/ic_menu_edit"/>
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
android:id="@+id/nv_extendedFloatingActionButton"
@ -101,8 +101,8 @@
android:focusable="true"
android:visibility="visible"
android:text=""
app:backgroundTint="?colorAccent"
app:icon="@android:drawable/ic_menu_edit"
app:backgroundTint="?colorFab"
tools:icon="@android:drawable/ic_menu_edit"
app:layout_anchor="@+id/nv_bottomBar"
app:layout_anchorGravity="center|top"/>

View File

@ -1,4 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<attr name="nv_actionBarBackground" format="color" />
<attr name="colorFab" format="color" />
<attr name="colorFabIcon" format="color" />
<attr name="colorOnFab" format="color" />
</resources>

View File

@ -2,4 +2,8 @@
<resources>
<color name="color">#202196f3</color>
<color name="blue">#154FBC</color>
<color name="background_light">#ffffff</color>
<color name="background_dark">#242424</color>
<color name="background_black">#000000</color>
</resources>

View File

@ -1,10 +1,84 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="NavView" parent="Theme.MaterialComponents.NoActionBar">
<resources xmlns:tools="http://schemas.android.com/tools">
<style name="NavView" />
<style name="NavView.Widget" />
<style name="NavView.Widget.FloatingActionButton" parent="Widget.MaterialComponents.FloatingActionButton">
<item name="backgroundTint">?colorFab</item>
<item name="android:textColor">?colorOnFab</item>
</style>
<style name="NavView.Widget.ExtendedFloatingActionButton" parent="Widget.MaterialComponents.ExtendedFloatingActionButton">
<item name="backgroundTint">?colorFab</item>
<item name="android:textColor">?colorOnFab</item>
</style>
<style name="NavView.Light" parent="Theme.MaterialComponents.Light.NoActionBar">
<item name="android:colorBackground">@color/background_light</item>
<item name="android:windowBackground">?android:colorBackground</item>
<item name="colorSurface">#ffffff</item>
<item name="elevationOverlayColor">#ffffff</item>
<item name="colorOnBackground">#000000</item>
<item name="colorOnSurface">#000000</item>
<item name="nv_actionBarBackground">?colorSurface</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="floatingActionButtonStyle">@style/NavView.Widget.FloatingActionButton</item>
<item name="extendedFloatingActionButtonStyle">@style/NavView.Widget.ExtendedFloatingActionButton</item>
<item name="material_drawer_background">?android:colorBackground</item>
<item name="material_drawer_primary_text">#242424</item>
<item name="material_drawer_primary_icon">#5F6368</item>
<item name="material_drawer_secondary_text">@color/material_drawer_secondary_text</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 name="NavView.Dark" parent="Theme.MaterialComponents.NoActionBar">
<item name="android:colorBackground">@color/background_dark</item>
<item name="android:windowBackground">?android:colorBackground</item>
<item name="colorSurface">#303030</item>
<item name="colorOnBackground">#ffffff</item>
<item name="colorOnSurface">#ffffff</item>
<item name="nv_actionBarBackground">?colorSurface</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="floatingActionButtonStyle">@style/NavView.Widget.FloatingActionButton</item>
<item name="extendedFloatingActionButtonStyle">@style/NavView.Widget.ExtendedFloatingActionButton</item>
<item name="material_drawer_background">?android:colorBackground</item>
<item name="material_drawer_primary_text">#FFFFFF</item>
<item name="material_drawer_primary_icon">#9AA0A6</item>
<item name="material_drawer_secondary_text">@color/material_drawer_dark_secondary_text</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 name="NavView.Black" parent="NavView.Dark">
<item name="android:colorBackground">@color/background_black</item>
<item name="android:windowBackground">?android:colorBackground</item>
<item name="colorSurface">#121212</item>
</style>
<style name="width_max_600dp">
<item name="android:layout_width">match_parent</item>
</style>