This repository was archived by the owner on Jun 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 553
[NEW] Add bottomSheet in Chatrooms #1929
Open
shubhsherl
wants to merge
7
commits into
RocketChat:develop
Choose a base branch
from
shubhsherl:new_1055
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
56bc23c
add bottomsheet and favorite functionality
shubhsherl d4ebb4b
add markAsRead functionality
shubhsherl 2832329
add leave/hide room and markunread
shubhsherl 18426e4
remove unnecessary imports/lines
shubhsherl 8015de3
change icons color
shubhsherl 5da8aef
remove repeated strings
shubhsherl 66629f1
add missing translation string
shubhsherl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 58 additions & 2 deletions
60
app/src/main/java/chat/rocket/android/chatrooms/adapter/ViewHolder.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,73 @@ | ||
package chat.rocket.android.chatrooms.adapter | ||
|
||
import android.view.ContextThemeWrapper | ||
import android.view.MenuItem | ||
import android.view.View | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.recyclerview.widget.RecyclerView | ||
import chat.rocket.android.R | ||
import chat.rocket.android.chatroom.ui.bottomsheet.ChatRoomActionBottomSheet | ||
import chat.rocket.android.chatrooms.adapter.model.RoomUiModel | ||
import chat.rocket.android.util.extensions.inflate | ||
import chat.rocket.android.util.extensions.toList | ||
|
||
abstract class ViewHolder<T : ItemHolder<*>>( | ||
itemView: View | ||
) : RecyclerView.ViewHolder(itemView) { | ||
itemView: View, | ||
private val listener: ActionsListener | ||
) : RecyclerView.ViewHolder(itemView), | ||
MenuItem.OnMenuItemClickListener { | ||
var data: T? = null | ||
|
||
init { | ||
setupActionMenu(itemView) | ||
} | ||
|
||
fun bind(data: T) { | ||
this.data = data | ||
bindViews(data) | ||
} | ||
|
||
abstract fun bindViews(data: T) | ||
|
||
interface ActionsListener { | ||
fun isActionsEnabled(): Boolean | ||
fun onActionSelected(item: MenuItem, room: RoomUiModel) | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove this empty line. |
||
internal fun setupActionMenu(view: View) { | ||
view.setOnLongClickListener{ | ||
if (data?.data is RoomUiModel) { | ||
data?.let { vm -> | ||
vm.data.let { | ||
val menuItems = view.context.inflate(R.menu.chatrooms_action).toList() | ||
menuItems.find { it.itemId == R.id.action_favorite_room }?.apply { | ||
setTitle(if ((it as RoomUiModel).favorite == true) R.string.action_unfavorite else R.string.action_favorite) | ||
setIcon(if (it.favorite == true) R.drawable.ic_star_24dp else R.drawable.ic_star_border_24dp) | ||
isChecked = (it.favorite==true) | ||
} | ||
menuItems.find { it.itemId == R.id.action_read }?.apply { | ||
setTitle(if ((it as RoomUiModel).unread.isNullOrEmpty()) R.string.action_mark_unread else R.string.action_mark_read) | ||
} | ||
view.context?.let { | ||
if (it is ContextThemeWrapper && it is AppCompatActivity) { | ||
with(it) { | ||
val actionsBottomSheet = ChatRoomActionBottomSheet() | ||
actionsBottomSheet.addItems(menuItems, this@ViewHolder) | ||
actionsBottomSheet.show(supportFragmentManager, null) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
true | ||
} | ||
} | ||
|
||
override fun onMenuItemClick(item: MenuItem): Boolean { | ||
data?.let { | ||
listener.onActionSelected(item, (it as RoomItemHolder).data) | ||
} | ||
return true | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For a better coding style this initializer block comes after the property declaration.
https://kotlinlang.org/docs/reference/coding-conventions.html