Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
AloqaIM-Android
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
AloqaIM-Android
Commits
5da0491d
Commit
5da0491d
authored
Feb 08, 2018
by
Leonardo Aramaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Separate BottomSheet and adapters in separate packages
parent
8c419945
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
129 additions
and
0 deletions
+129
-0
ChatRoomAdapter.kt
...n/java/chat/rocket/android/chatroom/ui/ChatRoomAdapter.kt
+2
-0
BottomSheetMenu.kt
...rocket/android/chatroom/ui/bottomsheet/BottomSheetMenu.kt
+27
-0
ActionListAdapter.kt
...roid/chatroom/ui/bottomsheet/adapter/ActionListAdapter.kt
+35
-0
ListBottomSheetAdapter.kt
...chatroom/ui/bottomsheet/adapter/ListBottomSheetAdapter.kt
+65
-0
No files found.
app/src/main/java/chat/rocket/android/chatroom/ui/ChatRoomAdapter.kt
View file @
5da0491d
...
@@ -9,6 +9,8 @@ import android.widget.ImageView
...
@@ -9,6 +9,8 @@ import android.widget.ImageView
import
android.widget.TextView
import
android.widget.TextView
import
chat.rocket.android.R
import
chat.rocket.android.R
import
chat.rocket.android.chatroom.presentation.ChatRoomPresenter
import
chat.rocket.android.chatroom.presentation.ChatRoomPresenter
import
chat.rocket.android.chatroom.ui.bottomsheet.adapter.ActionListAdapter
import
chat.rocket.android.chatroom.ui.bottomsheet.BottomSheetMenu
import
chat.rocket.android.chatroom.viewmodel.AttachmentType
import
chat.rocket.android.chatroom.viewmodel.AttachmentType
import
chat.rocket.android.chatroom.viewmodel.MessageViewModel
import
chat.rocket.android.chatroom.viewmodel.MessageViewModel
import
chat.rocket.android.player.PlayerActivity
import
chat.rocket.android.player.PlayerActivity
...
...
app/src/main/java/chat/rocket/android/chatroom/ui/bottomsheet/BottomSheetMenu.kt
0 → 100644
View file @
5da0491d
package
chat.rocket.android.chatroom.ui.bottomsheet
import
android.support.design.widget.BottomSheetDialog
import
android.support.v7.widget.LinearLayoutManager
import
android.support.v7.widget.RecyclerView
import
android.view.MenuItem
import
ru.whalemare.sheetmenu.SheetMenu
import
ru.whalemare.sheetmenu.adapter.MenuAdapter
class
BottomSheetMenu
(
adapter
:
MenuAdapter
)
:
SheetMenu
(
adapter
=
adapter
)
{
override
fun
processRecycler
(
recycler
:
RecyclerView
,
dialog
:
BottomSheetDialog
)
{
if
(
layoutManager
==
null
)
{
layoutManager
=
LinearLayoutManager
(
recycler
.
context
,
LinearLayoutManager
.
VERTICAL
,
false
)
}
val
callback
=
adapter
?.
callback
adapter
?.
callback
=
MenuItem
.
OnMenuItemClickListener
{
callback
?.
onMenuItemClick
(
it
)
dialog
.
cancel
()
true
}
recycler
.
adapter
=
adapter
recycler
.
layoutManager
=
layoutManager
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/chatroom/ui/bottomsheet/adapter/ActionListAdapter.kt
0 → 100644
View file @
5da0491d
package
chat.rocket.android.chatroom.ui.bottomsheet.adapter
import
android.graphics.Color
import
android.view.MenuItem
import
android.view.View
import
chat.rocket.android.R
/**
* An adapter for bottomsheet menu that lists all the actions that could be taken over a chat message.
*/
class
ActionListAdapter
(
menuItems
:
List
<
MenuItem
>
=
emptyList
(),
callback
:
MenuItem
.
OnMenuItemClickListener
)
:
ListBottomSheetAdapter
(
menuItems
=
menuItems
,
callback
=
callback
)
{
override
fun
onBindViewHolder
(
holder
:
ViewHolder
,
position
:
Int
)
{
val
item
=
menuItems
[
position
]
if
(
showIcons
)
{
if
(
item
.
icon
==
null
)
{
holder
.
imageIcon
.
visibility
=
View
.
GONE
}
else
{
holder
.
imageIcon
.
visibility
=
View
.
VISIBLE
}
}
else
{
holder
.
imageIcon
.
visibility
=
View
.
GONE
}
holder
.
imageIcon
.
setImageDrawable
(
item
.
icon
)
holder
.
textTitle
.
text
=
item
.
title
holder
.
itemView
.
setOnClickListener
{
callback
?.
onMenuItemClick
(
item
)
}
val
color
=
if
(
item
.
itemId
==
R
.
id
.
action_menu_msg_delete
)
Color
.
RED
else
textColors
.
get
(
item
.
itemId
)
holder
.
textTitle
.
setTextColor
(
color
)
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/chatroom/ui/
BottomSheet
.kt
→
app/src/main/java/chat/rocket/android/chatroom/ui/
bottomsheet/adapter/ListBottomSheetAdapter
.kt
View file @
5da0491d
package
chat.rocket.android.chatroom.ui
package
chat.rocket.android.chatroom.ui
.bottomsheet.adapter
import
android.graphics.Color
import
android.graphics.Color
import
android.support.annotation.ColorInt
import
android.support.annotation.ColorInt
import
android.support.annotation.IdRes
import
android.support.annotation.IdRes
import
android.support.design.widget.BottomSheetDialog
import
android.support.v7.widget.LinearLayoutManager
import
android.support.v7.widget.RecyclerView
import
android.util.SparseIntArray
import
android.util.SparseIntArray
import
android.view.MenuItem
import
android.view.MenuItem
import
android.view.View
import
chat.rocket.android.R
import
chat.rocket.android.R
import
ru.whalemare.sheetmenu.SheetMenu
import
ru.whalemare.sheetmenu.adapter.MenuAdapter
import
ru.whalemare.sheetmenu.adapter.MenuAdapter
/**
* A regular bottomsheet adapter with added possibility to hide or show a menu item given its item id.
* Also added the possibility to change text colors for the menu items.
*/
open
class
ListBottomSheetAdapter
(
menuItems
:
List
<
MenuItem
>
=
emptyList
(),
callback
:
MenuItem
.
OnMenuItemClickListener
)
:
open
class
ListBottomSheetAdapter
(
menuItems
:
List
<
MenuItem
>
=
emptyList
(),
callback
:
MenuItem
.
OnMenuItemClickListener
)
:
MenuAdapter
(
menuItems
=
menuItems
,
callback
=
callback
,
itemLayoutId
=
R
.
layout
.
item_linear
,
showIcons
=
true
)
{
MenuAdapter
(
menuItems
=
menuItems
,
callback
=
callback
,
itemLayoutId
=
R
.
layout
.
item_linear
,
showIcons
=
true
)
{
// Maps menu item ids to colors.
protected
val
textColors
:
SparseIntArray
=
SparseIntArray
(
menuItems
.
size
)
protected
val
textColors
:
SparseIntArray
=
SparseIntArray
(
menuItems
.
size
)
init
{
init
{
...
@@ -50,6 +50,12 @@ open class ListBottomSheetAdapter(menuItems: List<MenuItem> = emptyList(), callb
...
@@ -50,6 +50,12 @@ open class ListBottomSheetAdapter(menuItems: List<MenuItem> = emptyList(), callb
}
}
}
}
/**
* Change a menu item text color given by its id to the given color.
*
* @param itemId The id of menu item.
* @param color The color (not the resource color id) of the menu item.
*/
fun
setMenuItemTextColor
(
@IdRes
itemId
:
Int
,
@ColorInt
color
:
Int
)
{
fun
setMenuItemTextColor
(
@IdRes
itemId
:
Int
,
@ColorInt
color
:
Int
)
{
val
itemIndex
=
menuItems
.
indexOfFirst
{
it
.
itemId
==
itemId
}
val
itemIndex
=
menuItems
.
indexOfFirst
{
it
.
itemId
==
itemId
}
if
(
itemIndex
>
-
1
)
{
if
(
itemIndex
>
-
1
)
{
...
@@ -57,51 +63,3 @@ open class ListBottomSheetAdapter(menuItems: List<MenuItem> = emptyList(), callb
...
@@ -57,51 +63,3 @@ open class ListBottomSheetAdapter(menuItems: List<MenuItem> = emptyList(), callb
}
}
}
}
}
}
\ No newline at end of file
class
ActionListAdapter
(
menuItems
:
List
<
MenuItem
>
=
emptyList
(),
callback
:
MenuItem
.
OnMenuItemClickListener
)
:
ListBottomSheetAdapter
(
menuItems
=
menuItems
,
callback
=
callback
)
{
override
fun
onBindViewHolder
(
holder
:
ViewHolder
,
position
:
Int
)
{
val
item
=
menuItems
[
position
]
if
(
showIcons
)
{
if
(
item
.
icon
==
null
)
{
holder
.
imageIcon
.
visibility
=
View
.
GONE
}
else
{
holder
.
imageIcon
.
visibility
=
View
.
VISIBLE
}
}
else
{
holder
.
imageIcon
.
visibility
=
View
.
GONE
}
holder
.
imageIcon
.
setImageDrawable
(
item
.
icon
)
holder
.
textTitle
.
text
=
item
.
title
holder
.
itemView
.
setOnClickListener
{
callback
?.
onMenuItemClick
(
item
)
}
val
color
=
if
(
item
.
itemId
==
R
.
id
.
action_menu_msg_delete
)
Color
.
RED
else
textColors
.
get
(
item
.
itemId
)
holder
.
textTitle
.
setTextColor
(
color
)
}
}
class
BottomSheetMenu
(
adapter
:
MenuAdapter
)
:
SheetMenu
(
adapter
=
adapter
)
{
override
fun
processRecycler
(
recycler
:
RecyclerView
,
dialog
:
BottomSheetDialog
)
{
if
(
layoutManager
==
null
)
{
layoutManager
=
LinearLayoutManager
(
recycler
.
context
,
LinearLayoutManager
.
VERTICAL
,
false
)
}
val
callback
=
adapter
?.
callback
adapter
?.
callback
=
MenuItem
.
OnMenuItemClickListener
{
callback
?.
onMenuItemClick
(
it
)
dialog
.
cancel
()
true
}
recycler
.
adapter
=
adapter
recycler
.
layoutManager
=
layoutManager
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment