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
c6c2fe9d
Commit
c6c2fe9d
authored
Jun 29, 2018
by
Leonardo Aramaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove sheetMenu dependency in favor of framework bottomsheet
parent
847d6e6f
Changes
14
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
184 additions
and
149 deletions
+184
-149
build.gradle
app/build.gradle
+0
-2
BaseViewHolder.kt
...va/chat/rocket/android/chatroom/adapter/BaseViewHolder.kt
+15
-7
BottomSheetMenu.kt
...rocket/android/chatroom/ui/bottomsheet/BottomSheetMenu.kt
+0
-30
MessageActionsBottomSheet.kt
...roid/chatroom/ui/bottomsheet/MessageActionsBottomSheet.kt
+77
-0
ActionListAdapter.kt
...roid/chatroom/ui/bottomsheet/adapter/ActionListAdapter.kt
+0
-37
ListBottomSheetAdapter.kt
...chatroom/ui/bottomsheet/adapter/ListBottomSheetAdapter.kt
+0
-63
ChatRoomsFragment.kt
...ava/chat/rocket/android/chatrooms/ui/ChatRoomsFragment.kt
+1
-1
Ui.kt
app/src/main/java/chat/rocket/android/util/extensions/Ui.kt
+26
-1
message_action_item.xml
app/src/main/res/layout/message_action_item.xml
+42
-0
message_bottomsheet.xml
app/src/main/res/layout/message_bottomsheet.xml
+19
-0
chatroom_actions.xml
app/src/main/res/menu/chatroom_actions.xml
+1
-1
message_actions.xml
app/src/main/res/menu/message_actions.xml
+2
-1
build.gradle
build.gradle
+1
-1
dependencies.gradle
dependencies.gradle
+0
-5
No files found.
app/build.gradle
View file @
c6c2fe9d
...
...
@@ -114,8 +114,6 @@ dependencies {
implementation
libraries
.
markwon
implementation
libraries
.
sheetMenu
implementation
libraries
.
aVLoadingIndicatorView
implementation
"com.github.luciofm:livedata-ktx:b1e8bbc25a"
...
...
app/src/main/java/chat/rocket/android/chatroom/adapter/BaseViewHolder.kt
View file @
c6c2fe9d
package
chat.rocket.android.chatroom.adapter
import
android
x.recyclerview.widget.RecyclerView
import
android
.view.ContextThemeWrapper
import
android.view.MenuItem
import
android.view.View
import
android.view.ViewGroup
import
androidx.appcompat.app.AppCompatActivity
import
androidx.core.view.children
import
androidx.recyclerview.widget.RecyclerView
import
chat.rocket.android.R
import
chat.rocket.android.chatroom.ui.bottomsheet.BottomSheetMenu
import
chat.rocket.android.chatroom.ui.bottomsheet.adapter.ActionListAdapter
import
chat.rocket.android.chatroom.ui.bottomsheet.MessageActionsBottomSheet
import
chat.rocket.android.chatroom.uimodel.BaseUiModel
import
chat.rocket.android.emoji.Emoji
import
chat.rocket.android.emoji.EmojiReactionListener
import
chat.rocket.android.util.extensions.inflate
import
chat.rocket.android.util.extensions.toList
import
chat.rocket.core.model.Message
import
chat.rocket.core.model.isSystemMessage
import
com.google.android.flexbox.FlexDirection
import
com.google.android.flexbox.FlexboxLayoutManager
import
ru.whalemare.sheetmenu.extension.inflate
import
ru.whalemare.sheetmenu.extension.toList
abstract
class
BaseViewHolder
<
T
:
BaseUiModel
<*>>(
itemView
:
View
,
...
...
@@ -89,8 +90,15 @@ abstract class BaseViewHolder<T : BaseUiModel<*>>(
setTitle
(
if
(
isStarred
)
R
.
string
.
action_msg_unstar
else
R
.
string
.
action_msg_star
)
isChecked
=
isStarred
}
val
adapter
=
ActionListAdapter
(
menuItems
,
this
@BaseViewHolder
)
BottomSheetMenu
(
adapter
).
show
(
view
.
context
)
view
.
context
?.
let
{
if
(
it
is
ContextThemeWrapper
&&
it
.
baseContext
is
AppCompatActivity
)
{
with
(
it
.
baseContext
as
AppCompatActivity
)
{
val
actionsBottomSheet
=
MessageActionsBottomSheet
()
actionsBottomSheet
.
addItems
(
menuItems
,
this
@BaseViewHolder
)
actionsBottomSheet
.
show
(
supportFragmentManager
,
null
)
}
}
}
}
}
}
...
...
app/src/main/java/chat/rocket/android/chatroom/ui/bottomsheet/BottomSheetMenu.kt
deleted
100644 → 0
View file @
847d6e6f
package
chat.rocket.android.chatroom.ui.bottomsheet
import
com.google.android.material.bottomsheet.BottomSheetDialog
import
androidx.recyclerview.widget.LinearLayoutManager
import
androidx.recyclerview.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
)
}
// Superclass SheetMenu adapter property is nullable MenuAdapter? but this class enforces
// passing one at the constructor, so we assume it's always non-null.
val
adapter
=
adapter
!!
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/MessageActionsBottomSheet.kt
0 → 100644
View file @
c6c2fe9d
package
chat.rocket.android.chatroom.ui.bottomsheet
import
android.os.Bundle
import
android.view.LayoutInflater
import
android.view.MenuItem
import
android.view.View
import
android.view.ViewGroup
import
androidx.recyclerview.widget.LinearLayoutManager
import
androidx.recyclerview.widget.RecyclerView
import
chat.rocket.android.R
import
com.google.android.material.bottomsheet.BottomSheetDialogFragment
import
kotlinx.android.synthetic.main.message_action_item.view.*
import
kotlinx.android.synthetic.main.message_bottomsheet.*
class
MessageActionsBottomSheet
:
BottomSheetDialogFragment
()
{
private
lateinit
var
adapter
:
MessageActionAdapter
override
fun
onCreateView
(
inflater
:
LayoutInflater
,
container
:
ViewGroup
?,
savedInstanceState
:
Bundle
?):
View
{
return
inflater
.
inflate
(
R
.
layout
.
message_bottomsheet
,
container
,
false
)
}
fun
addItems
(
items
:
List
<
MenuItem
>,
itemClickListener
:
MenuItem
.
OnMenuItemClickListener
)
{
adapter
=
MessageActionAdapter
()
adapter
.
addItems
(
items
,
ActionItemClickListener
(
dismissAction
=
{
dismiss
()
},
itemClickListener
=
itemClickListener
))
}
override
fun
onViewCreated
(
view
:
View
,
savedInstanceState
:
Bundle
?)
{
super
.
onViewCreated
(
view
,
savedInstanceState
)
bottomsheet_recycler_view
.
layoutManager
=
LinearLayoutManager
(
context
)
bottomsheet_recycler_view
.
adapter
=
adapter
}
private
class
ActionItemClickListener
(
val
dismissAction
:
()
->
Unit
,
val
itemClickListener
:
MenuItem
.
OnMenuItemClickListener
)
private
class
MessageActionAdapter
:
RecyclerView
.
Adapter
<
MessageActionViewHolder
>()
{
private
lateinit
var
itemClickListener
:
ActionItemClickListener
private
val
menuItems
=
mutableListOf
<
MenuItem
>()
override
fun
onCreateViewHolder
(
parent
:
ViewGroup
,
viewType
:
Int
):
MessageActionViewHolder
{
return
MessageActionViewHolder
(
LayoutInflater
.
from
(
parent
.
context
).
inflate
(
R
.
layout
.
message_action_item
,
parent
,
false
)
)
}
override
fun
getItemCount
()
=
menuItems
.
size
override
fun
onBindViewHolder
(
holder
:
MessageActionViewHolder
,
position
:
Int
)
{
holder
.
bind
(
menuItems
[
position
],
itemClickListener
)
}
fun
addItems
(
items
:
List
<
MenuItem
>,
itemClickListener
:
ActionItemClickListener
)
{
this
.
itemClickListener
=
itemClickListener
menuItems
.
clear
()
menuItems
.
addAll
(
items
)
}
}
private
class
MessageActionViewHolder
(
itemView
:
View
)
:
RecyclerView
.
ViewHolder
(
itemView
)
{
fun
bind
(
item
:
MenuItem
,
itemClickListener
:
ActionItemClickListener
)
{
with
(
itemView
)
{
message_action_title
.
text
=
item
.
title
message_action_icon
.
setImageDrawable
(
item
.
icon
)
setOnClickListener
{
itemClickListener
.
itemClickListener
.
onMenuItemClick
(
item
)
itemClickListener
.
dismissAction
.
invoke
()
}
}
}
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/chatroom/ui/bottomsheet/adapter/ActionListAdapter.kt
deleted
100644 → 0
View file @
847d6e6f
package
chat.rocket.android.chatroom.ui.bottomsheet.adapter
import
android.view.MenuItem
import
chat.rocket.android.R
import
chat.rocket.android.util.extensions.setVisible
/**
* 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
)
{
holder
.
imageIcon
.
setVisible
(
item
.
icon
!=
null
)
}
else
{
holder
.
imageIcon
.
setVisible
(
false
)
}
holder
.
imageIcon
.
setImageDrawable
(
item
.
icon
)
holder
.
textTitle
.
text
=
item
.
title
holder
.
itemView
.
setOnClickListener
{
callback
?.
onMenuItemClick
(
item
)
}
val
deleteTextColor
=
holder
.
itemView
.
context
.
resources
.
getColor
(
R
.
color
.
colorRed
)
val
color
=
if
(
item
.
itemId
==
R
.
id
.
action_message_delete
)
{
deleteTextColor
}
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/adapter/ListBottomSheetAdapter.kt
deleted
100644 → 0
View file @
847d6e6f
package
chat.rocket.android.chatroom.ui.bottomsheet.adapter
import
android.graphics.Color
import
androidx.annotation.ColorInt
import
androidx.annotation.IdRes
import
android.util.SparseIntArray
import
android.view.MenuItem
import
chat.rocket.android.R
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
)
:
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
)
init
{
for
(
item
in
menuItems
)
{
textColors
.
put
(
item
.
itemId
,
Color
.
BLACK
)
}
}
/**
* Hide a menu item and disable it.
*
* @param itemId The id of the menu item to disable and hide.
*/
fun
hideMenuItem
(
@IdRes
itemId
:
Int
)
{
menuItems
.
firstOrNull
{
it
.
itemId
==
itemId
}
?.
apply
{
setVisible
(
false
)
setEnabled
(
false
)
}
}
/**
* Show a menu item and enable it.
*
* @param itemId The id of the menu item to enable and show.
*/
fun
showMenuItem
(
@IdRes
itemId
:
Int
)
{
menuItems
.
firstOrNull
{
it
.
itemId
==
itemId
}
?.
apply
{
setVisible
(
true
)
setEnabled
(
true
)
}
}
/**
* 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
)
{
val
itemIndex
=
menuItems
.
indexOfFirst
{
it
.
itemId
==
itemId
}
if
(
itemIndex
>
-
1
)
{
textColors
.
put
(
itemId
,
color
)
}
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/chatrooms/ui/ChatRoomsFragment.kt
View file @
c6c2fe9d
...
...
@@ -148,7 +148,7 @@ class ChatRoomsFragment : Fragment(), ChatRoomsView {
inflater
.
inflate
(
R
.
menu
.
chatrooms
,
menu
)
val
searchItem
=
menu
.
findItem
(
R
.
id
.
action_search
)
searchView
=
searchItem
?.
actionView
as
SearchView
searchView
=
searchItem
?.
actionView
as
SearchView
?
searchView
?.
maxWidth
=
Integer
.
MAX_VALUE
searchView
?.
setOnQueryTextListener
(
object
:
SearchView
.
OnQueryTextListener
{
override
fun
onQueryTextSubmit
(
query
:
String
?):
Boolean
{
...
...
app/src/main/java/chat/rocket/android/util/extensions/Ui.kt
View file @
c6c2fe9d
package
chat.rocket.android.util.extensions
import
android.annotation.SuppressLint
import
android.app.Activity
import
android.content.Context
import
android.view.LayoutInflater
import
android.view.Menu
import
android.view.MenuItem
import
android.view.View
import
android.view.ViewGroup
import
android.view.inputmethod.InputMethodManager
import
android.widget.Toast
import
androidx.annotation.LayoutRes
import
androidx.annotation.MenuRes
import
androidx.annotation.StringRes
import
androidx.appcompat.app.AppCompatActivity
import
androidx.appcompat.view.SupportMenuInflater
import
androidx.appcompat.view.menu.MenuBuilder
import
androidx.fragment.app.Fragment
import
chat.rocket.android.R
...
...
@@ -86,4 +92,23 @@ fun Fragment.showToast(@StringRes resource: Int, duration: Int = Toast.LENGTH_SH
showToast
(
getString
(
resource
),
duration
)
fun
Fragment
.
showToast
(
message
:
String
,
duration
:
Int
=
Toast
.
LENGTH_SHORT
)
=
activity
?.
showToast
(
message
,
duration
)
\ No newline at end of file
activity
?.
showToast
(
message
,
duration
)
@SuppressLint
(
"RestrictedApi"
)
fun
Context
.
inflate
(
@MenuRes
menuRes
:
Int
):
Menu
{
val
menu
=
MenuBuilder
(
this
)
val
menuInflater
=
SupportMenuInflater
(
this
)
menuInflater
.
inflate
(
menuRes
,
menu
)
return
menu
}
/**
* Developed by Magora-Systems.com
* @since 2017
* @author Anton Vlasov - whalemare
*/
fun
Menu
.
toList
():
List
<
MenuItem
>
{
val
menuItems
=
ArrayList
<
MenuItem
>(
this
.
size
())
(
0
until
this
.
size
()).
mapTo
(
menuItems
)
{
this
.
getItem
(
it
)
}
return
menuItems
}
\ No newline at end of file
app/src/main/res/layout/message_action_item.xml
0 → 100644
View file @
c6c2fe9d
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
xmlns:tools=
"http://schemas.android.com/tools"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:background=
"?attr/selectableItemBackground"
android:paddingStart=
"16dp"
android:paddingTop=
"8dp"
android:paddingEnd=
"16dp"
android:paddingBottom=
"8dp"
>
<ImageView
android:id=
"@+id/message_action_icon"
android:layout_width=
"24dp"
android:layout_height=
"24dp"
android:layout_marginStart=
"8dp"
android:layout_marginTop=
"8dp"
android:layout_marginEnd=
"32dp"
android:layout_marginBottom=
"8dp"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintEnd_toStartOf=
"@+id/message_action_title"
app:layout_constraintHorizontal_bias=
"0.5"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_toTopOf=
"parent"
tools:srcCompat=
"@drawable/ic_action_message_reply_24dp"
/>
<TextView
android:id=
"@+id/message_action_title"
android:layout_width=
"0dp"
android:layout_height=
"wrap_content"
android:layout_marginTop=
"8dp"
android:layout_marginEnd=
"8dp"
android:layout_marginBottom=
"8dp"
android:textSize=
"16sp"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintHorizontal_bias=
"0.5"
app:layout_constraintStart_toEndOf=
"@+id/message_action_icon"
app:layout_constraintTop_toTopOf=
"parent"
tools:text=
"Responder"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
app/src/main/res/layout/message_bottomsheet.xml
0 → 100644
View file @
c6c2fe9d
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
>
<androidx.recyclerview.widget.RecyclerView
android:id=
"@+id/bottomsheet_recycler_view"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:layout_marginStart=
"8dp"
android:layout_marginTop=
"8dp"
android:layout_marginEnd=
"8dp"
android:layout_marginBottom=
"8dp"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_toTopOf=
"parent"
/>
</LinearLayout>
\ No newline at end of file
app/src/main/res/menu/chatroom_actions.xml
View file @
c6c2fe9d
...
...
@@ -9,7 +9,7 @@
<item
android:id=
"@+id/action_mentions"
android:title=
"@string/msg_mentions"
a
pp
:showAsAction=
"never"
/>
a
ndroid
:showAsAction=
"never"
/>
<item
android:id=
"@+id/action_pinned_messages"
...
...
app/src/main/res/menu/message_actions.xml
View file @
c6c2fe9d
<?xml version="1.0" encoding="utf-8"?>
<menu
xmlns:android=
"http://schemas.android.com/apk/res/android"
>
<menu
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
>
<item
android:id=
"@+id/action_message_reply"
...
...
build.gradle
View file @
c6c2fe9d
...
...
@@ -10,7 +10,7 @@ buildscript {
}
dependencies
{
classpath
'com.android.tools.build:gradle:3.2.0-
alpha18
'
classpath
'com.android.tools.build:gradle:3.2.0-
beta02
'
classpath
"org.jetbrains.kotlin:kotlin-gradle-plugin:${versions.kotlin}"
classpath
"org.jetbrains.dokka:dokka-gradle-plugin:${versions.dokka}"
classpath
'com.google.gms:google-services:3.2.0'
...
...
dependencies.gradle
View file @
c6c2fe9d
...
...
@@ -34,7 +34,6 @@ ext {
kotshi
:
'1.0.2'
,
frescoImageViewer
:
'0.5.1'
,
markwon
:
'1.0.3'
,
sheetMenu
:
'5ff79ccf14'
,
aVLoadingIndicatorView:
'2.1.3'
,
flexbox
:
'0.3.2'
,
...
...
@@ -102,12 +101,8 @@ ext {
markwon
:
"ru.noties:markwon:${versions.markwon}"
,
//sheetMenu : "com.github.whalemare:sheetmenu:${versions.sheetMenu}",
sheetMenu
:
"com.github.luciofm:sheetmenu:${versions.sheetMenu}"
,
aVLoadingIndicatorView:
"com.wang.avi:library:${versions.aVLoadingIndicatorView}"
,
//For the wear app
wearable
:
"com.google.android.support:wearable:${versions.wear}"
,
playServicesWearable
:
"com.google.android.gms:play-services-wearable:${versions.playServicesWearable}"
,
...
...
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