insertar imagenes y creador de links en comentarios
This commit is contained in:
parent
8c8219f5d8
commit
2bc27cca0c
@ -1,6 +1,7 @@
|
|||||||
package com.isolaatti.posting.comments.ui
|
package com.isolaatti.posting.comments.ui
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.util.Log
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
@ -31,6 +32,9 @@ import com.isolaatti.common.options_bottom_sheet.domain.OptionClicked
|
|||||||
import com.isolaatti.common.options_bottom_sheet.domain.Options
|
import com.isolaatti.common.options_bottom_sheet.domain.Options
|
||||||
import com.isolaatti.common.options_bottom_sheet.presentation.BottomSheetPostOptionsViewModel
|
import com.isolaatti.common.options_bottom_sheet.presentation.BottomSheetPostOptionsViewModel
|
||||||
import com.isolaatti.common.options_bottom_sheet.ui.BottomSheetPostOptionsFragment
|
import com.isolaatti.common.options_bottom_sheet.ui.BottomSheetPostOptionsFragment
|
||||||
|
import com.isolaatti.images.image_chooser.ui.ImageChooserContract
|
||||||
|
import com.isolaatti.posting.link_creator.presentation.LinkCreatorViewModel
|
||||||
|
import com.isolaatti.posting.link_creator.ui.LinkCreatorFragment
|
||||||
import com.isolaatti.profile.ui.ProfileActivity
|
import com.isolaatti.profile.ui.ProfileActivity
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import io.noties.markwon.AbstractMarkwonPlugin
|
import io.noties.markwon.AbstractMarkwonPlugin
|
||||||
@ -49,6 +53,7 @@ class BottomSheetPostComments() : BottomSheetDialogFragment(), OnUserInteractedC
|
|||||||
private lateinit var adapter: CommentsRecyclerViewAdapter
|
private lateinit var adapter: CommentsRecyclerViewAdapter
|
||||||
private val errorViewModel: ErrorMessageViewModel by activityViewModels()
|
private val errorViewModel: ErrorMessageViewModel by activityViewModels()
|
||||||
private val optionsViewModel: BottomSheetPostOptionsViewModel by activityViewModels()
|
private val optionsViewModel: BottomSheetPostOptionsViewModel by activityViewModels()
|
||||||
|
private val linkCreatorViewModel: LinkCreatorViewModel by viewModels()
|
||||||
|
|
||||||
private val optionsObserver: Observer<OptionClicked?> = Observer { optionClicked ->
|
private val optionsObserver: Observer<OptionClicked?> = Observer { optionClicked ->
|
||||||
if(optionClicked?.callerId == CALLER_ID) {
|
if(optionClicked?.callerId == CALLER_ID) {
|
||||||
@ -113,6 +118,14 @@ class BottomSheetPostComments() : BottomSheetDialogFragment(), OnUserInteractedC
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val imageChooserLauncher = registerForActivityResult(ImageChooserContract()) { image ->
|
||||||
|
Log.d("BottomSheetPostComment", "${image?.markdown}")
|
||||||
|
|
||||||
|
if(image != null) {
|
||||||
|
viewBinding.newCommentTextField.editText?.setText("${viewBinding.newCommentTextField.editText?.text}\n\n${image.markdown}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun setObservers() {
|
private fun setObservers() {
|
||||||
viewModel.comments.observe(viewLifecycleOwner, commentsObserver)
|
viewModel.comments.observe(viewLifecycleOwner, commentsObserver)
|
||||||
viewModel.noMoreContent.observe(viewLifecycleOwner, noMoreContentObserver)
|
viewModel.noMoreContent.observe(viewLifecycleOwner, noMoreContentObserver)
|
||||||
@ -123,6 +136,12 @@ class BottomSheetPostComments() : BottomSheetDialogFragment(), OnUserInteractedC
|
|||||||
}
|
}
|
||||||
|
|
||||||
optionsViewModel.optionClicked.observe(viewLifecycleOwner, optionsObserver)
|
optionsViewModel.optionClicked.observe(viewLifecycleOwner, optionsObserver)
|
||||||
|
linkCreatorViewModel.inserted.observe(viewLifecycleOwner) {
|
||||||
|
if(it) {
|
||||||
|
viewBinding.newCommentTextField.editText?.setText("${viewBinding.newCommentTextField.editText?.text} ${linkCreatorViewModel.markdown}")
|
||||||
|
linkCreatorViewModel.inserted.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setListeners() {
|
private fun setListeners() {
|
||||||
@ -134,18 +153,34 @@ class BottomSheetPostComments() : BottomSheetDialogFragment(), OnUserInteractedC
|
|||||||
val content = viewBinding.newCommentTextField.editText?.text ?: return@setOnClickListener
|
val content = viewBinding.newCommentTextField.editText?.text ?: return@setOnClickListener
|
||||||
viewModel.postComment(content.toString())
|
viewModel.postComment(content.toString())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
viewBinding.addImageButton.setOnClickListener {
|
||||||
|
insertImage()
|
||||||
|
}
|
||||||
|
|
||||||
|
viewBinding.addLinkButton.setOnClickListener {
|
||||||
|
insertLink()
|
||||||
|
}
|
||||||
|
|
||||||
|
viewBinding.enlargeTextBoxSwitch.setOnCheckedChangeListener { buttonView, isChecked ->
|
||||||
|
if(isChecked) {
|
||||||
|
viewBinding.newCommentTextField.editText?.setLines(5)
|
||||||
|
} else {
|
||||||
|
viewBinding.newCommentTextField.editText?.setLines(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun clearNewCommentUi() {
|
private fun clearNewCommentUi() {
|
||||||
viewBinding.newCommentTextField.editText?.text?.clear()
|
viewBinding.newCommentTextField.editText?.text?.clear()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun switchEditionModeUi(editionMode: Boolean) {
|
private fun insertImage() {
|
||||||
if(editionMode) {
|
imageChooserLauncher.launch(ImageChooserContract.Requester.UserPost)
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
private fun insertLink() {
|
||||||
|
LinkCreatorFragment().show(childFragmentManager, null)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -32,22 +32,46 @@
|
|||||||
<com.google.android.material.bottomappbar.BottomAppBar
|
<com.google.android.material.bottomappbar.BottomAppBar
|
||||||
android:id="@+id/new_comment_area"
|
android:id="@+id/new_comment_area"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="120dp"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="bottom">
|
android:layout_gravity="bottom">
|
||||||
|
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
<LinearLayout
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
android:id="@+id/comment_actions"
|
android:id="@+id/comment_actions"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="40dp"
|
android:layout_height="40dp"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
app:layout_constraintTop_toTopOf="parent"
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
android:orientation="horizontal">
|
android:orientation="horizontal">
|
||||||
|
|
||||||
</LinearLayout>
|
<com.google.android.material.button.MaterialButton
|
||||||
|
android:id="@+id/add_image_button"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
style="@style/Widget.Material3.Button.IconButton"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
app:icon="@drawable/baseline_image_24" />
|
||||||
|
<com.google.android.material.button.MaterialButton
|
||||||
|
android:id="@+id/add_link_button"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
style="@style/Widget.Material3.Button.IconButton"
|
||||||
|
app:layout_constraintStart_toEndOf="@id/add_image_button"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
app:icon="@drawable/baseline_add_link_24" />
|
||||||
|
<com.google.android.material.materialswitch.MaterialSwitch
|
||||||
|
android:id="@+id/enlarge_text_box_switch"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
android:text="@string/enlarge_text_box"/>
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|
||||||
<com.google.android.material.textfield.TextInputLayout
|
<com.google.android.material.textfield.TextInputLayout
|
||||||
android:id="@+id/newCommentTextField"
|
android:id="@+id/newCommentTextField"
|
||||||
|
|||||||
@ -132,4 +132,5 @@
|
|||||||
<string name="url">Url</string>
|
<string name="url">Url</string>
|
||||||
<string name="text">Text</string>
|
<string name="text">Text</string>
|
||||||
<string name="insert_url">Insert url</string>
|
<string name="insert_url">Insert url</string>
|
||||||
|
<string name="enlarge_text_box">Enlarge text box</string>
|
||||||
</resources>
|
</resources>
|
||||||
Loading…
x
Reference in New Issue
Block a user