Skip to content
Snippets Groups Projects
Commit b8d0001b authored by Taras's avatar Taras
Browse files

Create DmMenuBottomSheet

parent 98df681e
No related branches found
No related tags found
No related merge requests found
package org.futo.circles.feature.direct.timeline.menu
import android.content.Context
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.viewModels
import androidx.navigation.fragment.navArgs
import dagger.hilt.android.AndroidEntryPoint
import org.futo.circles.core.base.fragment.TransparentBackgroundBottomSheetDialogFragment
import org.futo.circles.core.extensions.setIsVisible
import org.futo.circles.core.provider.PreferencesProvider
import org.futo.circles.databinding.BottomSheetDmMenuBinding
import org.futo.circles.feature.direct.timeline.listeners.DmOptionsListener
import org.futo.circles.feature.timeline.post.menu.PostMenuBottomSheetArgs
import org.futo.circles.feature.timeline.post.menu.PostMenuViewModel
@AndroidEntryPoint
class DmMenuBottomSheet : TransparentBackgroundBottomSheetDialogFragment() {
private var binding: BottomSheetDmMenuBinding? = null
private val args: PostMenuBottomSheetArgs by navArgs()
private val viewModel by viewModels<PostMenuViewModel>()
private val preferencesProvider by lazy { PreferencesProvider(requireContext()) }
private var menuListener: DmOptionsListener? = null
override fun onAttach(context: Context) {
super.onAttach(context)
menuListener =
parentFragmentManager.fragments.firstOrNull { it is DmOptionsListener } as? DmOptionsListener
}
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
): View? {
binding = BottomSheetDmMenuBinding.inflate(inflater, container, false)
return binding?.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
setupViews()
}
private fun setupViews() {
binding?.let {
with(it) {
tvDelete.apply {
setIsVisible(viewModel.canDeletePost())
setOnClickListener {
menuListener?.onRemove(args.roomId, args.eventId)
dismiss()
}
}
tvEdit.apply {
setIsVisible(viewModel.canEditPost())
setOnClickListener {
navigator.navigateToEditPost(args.roomId, args.eventId)
}
}
tvSaveToDevice.apply {
setIsVisible(viewModel.isMediaPost())
setOnClickListener {
viewModel.getPostContent()?.let { menuListener?.onSaveToDevice(it) }
dismiss()
}
}
tvReact.apply {
setIsVisible(viewModel.isMyPost().not())
setOnClickListener {
navigator.navigateToReport(args.roomId, args.eventId)
}
}
tvReply.apply {
setIsVisible(viewModel.isMyPost().not())
setOnClickListener {
viewModel.getSenderId()?.let { menuListener?.onIgnore(it) }
dismiss()
}
}
tvInfo.apply {
setIsVisible(preferencesProvider.isDeveloperModeEnabled())
setOnClickListener {
navigator.navigateToInfo(args.roomId, args.eventId)
}
}
}
}
}
override fun onDestroyView() {
super.onDestroyView()
binding = null
}
}
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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="wrap_content"
android:paddingHorizontal="16dp"
android:paddingBottom="16dp">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardBackgroundColor="@color/post_card_background_color"
app:cardCornerRadius="16dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="4dp">
<View
android:layout_width="48dp"
android:layout_height="2dp"
android:layout_gravity="center_horizontal"
android:background="@color/divider_color" />
<org.futo.circles.core.view.SettingsMenuItemView
android:id="@+id/tvInfo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:optionIcon="@drawable/ic_info"
app:optionName="@string/info" />
<org.futo.circles.core.view.SettingsMenuItemView
android:id="@+id/tvReply"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:optionIcon="@drawable/ic_reply"
app:optionName="@string/reply" />
<org.futo.circles.core.view.SettingsMenuItemView
android:id="@+id/tvReact"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:optionIcon="@drawable/ic_emoji"
app:optionName="@string/react" />
<org.futo.circles.core.view.SettingsMenuItemView
android:id="@+id/tvEdit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:optionIcon="@drawable/ic_edit"
app:optionName="@string/edit" />
<org.futo.circles.core.view.SettingsMenuItemView
android:id="@+id/tvSaveToDevice"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:optionIcon="@drawable/ic_download"
app:optionName="@string/save_to_device" />
<org.futo.circles.core.view.SettingsMenuItemView
android:id="@+id/tvDelete"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:optionIcon="@drawable/ic_delete"
app:optionName="@string/delete" />
</LinearLayout>
</androidx.cardview.widget.CardView>
</FrameLayout>
\ No newline at end of file
......@@ -75,6 +75,8 @@
<string name="create_your_first_circle_to_be_able_to_accept_invite">Create your first Circle to be able to accept invite</string>
<string name="show_more">Show more</string>
<string name="edit">Edit</string>
<string name="reply">Reply</string>
<string name="react">React</string>
<string name="edit_post">Edit post</string>
<string name="edited_label">(Edited)</string>
<string name="edit_poll">Edit poll</string>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment