WIP comentarios
This commit is contained in:
parent
4fc72786af
commit
435d669399
@ -23,7 +23,7 @@
|
|||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
<activity android:name=".home.HomeActivity" android:theme="@style/Theme.Isolaatti" android:windowSoftInputMode="adjustResize" />
|
<activity android:name=".home.HomeActivity" android:theme="@style/Theme.Isolaatti" />
|
||||||
<activity android:name=".login.LogInActivity" android:theme="@style/Theme.Isolaatti" />
|
<activity android:name=".login.LogInActivity" android:theme="@style/Theme.Isolaatti" />
|
||||||
<activity android:name=".profile.ui.ProfileActivity"
|
<activity android:name=".profile.ui.ProfileActivity"
|
||||||
android:theme="@style/Theme.Isolaatti"
|
android:theme="@style/Theme.Isolaatti"
|
||||||
|
|||||||
@ -13,4 +13,13 @@ object Dialogs {
|
|||||||
.setNegativeButton(R.string.cancel) { _, _ -> onContinue(false)}
|
.setNegativeButton(R.string.cancel) { _, _ -> onContinue(false)}
|
||||||
.setOnCancelListener { onContinue(false) }
|
.setOnCancelListener { onContinue(false) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun buildDeleteCommentDialog(context: Context, onContinue: (delete: Boolean) -> Unit): MaterialAlertDialogBuilder {
|
||||||
|
return MaterialAlertDialogBuilder(context)
|
||||||
|
.setTitle(R.string.delete)
|
||||||
|
.setMessage(R.string.comment_will_be_dropped)
|
||||||
|
.setPositiveButton(R.string.yes_continue) {_, _ -> onContinue(true)}
|
||||||
|
.setNegativeButton(R.string.cancel) { _, _ -> onContinue(false)}
|
||||||
|
.setOnCancelListener { onContinue(false) }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -26,6 +26,8 @@ class CommentsViewModel @Inject constructor(private val getComments: GetComments
|
|||||||
val comments: LiveData<Pair<List<Comment>, UpdateEvent>> get() = _comments
|
val comments: LiveData<Pair<List<Comment>, UpdateEvent>> get() = _comments
|
||||||
val commentPosted: MutableLiveData<Boolean?> = MutableLiveData()
|
val commentPosted: MutableLiveData<Boolean?> = MutableLiveData()
|
||||||
val noMoreContent: MutableLiveData<Boolean?> = MutableLiveData()
|
val noMoreContent: MutableLiveData<Boolean?> = MutableLiveData()
|
||||||
|
val commentToEdit: MutableLiveData<Comment> = MutableLiveData()
|
||||||
|
val finishedEditingComment: MutableLiveData<Boolean?> = MutableLiveData()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* postId to query comments for. First page will be fetched when set.
|
* postId to query comments for. First page will be fetched when set.
|
||||||
@ -92,4 +94,8 @@ class CommentsViewModel @Inject constructor(private val getComments: GetComments
|
|||||||
commentsList.addAll(newList)
|
commentsList.addAll(newList)
|
||||||
_comments.postValue(Pair(commentsList, UpdateEvent(UpdateEvent.UpdateType.COMMENT_ADDED_TOP, null)))
|
_comments.postValue(Pair(commentsList, UpdateEvent(UpdateEvent.UpdateType.COMMENT_ADDED_TOP, null)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun switchToEditMode(comment: Comment) {
|
||||||
|
commentToEdit.postValue(comment)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -1,18 +1,23 @@
|
|||||||
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
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
|
import androidx.core.view.doOnLayout
|
||||||
import androidx.core.widget.doOnTextChanged
|
import androidx.core.widget.doOnTextChanged
|
||||||
import androidx.fragment.app.activityViewModels
|
import androidx.fragment.app.activityViewModels
|
||||||
import androidx.fragment.app.viewModels
|
import androidx.fragment.app.viewModels
|
||||||
import androidx.lifecycle.Observer
|
import androidx.lifecycle.Observer
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
||||||
|
import com.google.android.material.bottomsheet.BottomSheetBehavior.STATE_EXPANDED
|
||||||
|
import com.google.android.material.bottomsheet.BottomSheetBehavior.STATE_HALF_EXPANDED
|
||||||
import com.google.android.material.bottomsheet.BottomSheetDialog
|
import com.google.android.material.bottomsheet.BottomSheetDialog
|
||||||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
|
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
|
||||||
|
import com.isolaatti.R
|
||||||
import com.isolaatti.common.Dialogs
|
import com.isolaatti.common.Dialogs
|
||||||
import com.isolaatti.databinding.BottomSheetPostCommentsBinding
|
import com.isolaatti.databinding.BottomSheetPostCommentsBinding
|
||||||
import com.isolaatti.posting.comments.domain.model.Comment
|
import com.isolaatti.posting.comments.domain.model.Comment
|
||||||
@ -43,12 +48,12 @@ class BottomSheetPostComments() : BottomSheetDialogFragment(), OnUserInteractedC
|
|||||||
|
|
||||||
val optionsViewModel: BottomSheetPostOptionsViewModel by activityViewModels()
|
val optionsViewModel: BottomSheetPostOptionsViewModel by activityViewModels()
|
||||||
|
|
||||||
val optionsObserver: Observer<OptionClicked?> = Observer { optionClicked ->
|
private val optionsObserver: Observer<OptionClicked?> = Observer { optionClicked ->
|
||||||
if(optionClicked?.callerId == CALLER_ID) {
|
if(optionClicked?.callerId == CALLER_ID) {
|
||||||
val comment = optionClicked.payload as? Comment ?: return@Observer
|
val comment = optionClicked.payload as? Comment ?: return@Observer
|
||||||
when(optionClicked.optionId) {
|
when(optionClicked.optionId) {
|
||||||
Options.Option.OPTION_DELETE -> {
|
Options.Option.OPTION_DELETE -> {
|
||||||
Dialogs.buildDeletePostDialog(requireContext()) { delete ->
|
Dialogs.buildDeleteCommentDialog(requireContext()) { delete ->
|
||||||
optionsViewModel.handle()
|
optionsViewModel.handle()
|
||||||
if(delete) {
|
if(delete) {
|
||||||
// remove comment
|
// remove comment
|
||||||
@ -58,7 +63,7 @@ class BottomSheetPostComments() : BottomSheetDialogFragment(), OnUserInteractedC
|
|||||||
}
|
}
|
||||||
Options.Option.OPTION_EDIT -> {
|
Options.Option.OPTION_EDIT -> {
|
||||||
optionsViewModel.handle()
|
optionsViewModel.handle()
|
||||||
//editDiscussion.launch(post.id)
|
viewModel.switchToEditMode(comment)
|
||||||
}
|
}
|
||||||
Options.Option.OPTION_REPORT -> {
|
Options.Option.OPTION_REPORT -> {
|
||||||
optionsViewModel.handle()
|
optionsViewModel.handle()
|
||||||
@ -68,14 +73,14 @@ class BottomSheetPostComments() : BottomSheetDialogFragment(), OnUserInteractedC
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val commentPostedObserver: Observer<Boolean?> = Observer {
|
private val commentPostedObserver: Observer<Boolean?> = Observer {
|
||||||
when(it) {
|
when(it) {
|
||||||
true -> {
|
true -> {
|
||||||
clearNewCommentUi()
|
clearNewCommentUi()
|
||||||
Toast.makeText(requireContext(), "comment posted", Toast.LENGTH_SHORT).show()
|
Toast.makeText(requireContext(), R.string.comment_posted, Toast.LENGTH_SHORT).show()
|
||||||
}
|
}
|
||||||
false -> {
|
false -> {
|
||||||
Toast.makeText(requireContext(), "comment failed to post", Toast.LENGTH_SHORT).show()
|
Toast.makeText(requireContext(), R.string.comment_failed_to_post, Toast.LENGTH_SHORT).show()
|
||||||
}
|
}
|
||||||
null -> return@Observer
|
null -> return@Observer
|
||||||
}
|
}
|
||||||
@ -84,8 +89,7 @@ class BottomSheetPostComments() : BottomSheetDialogFragment(), OnUserInteractedC
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setObservers() {
|
private val commentsObserver: Observer<Pair<List<Comment>, UpdateEvent>> = Observer {
|
||||||
viewModel.comments.observe(viewLifecycleOwner) {
|
|
||||||
val (list, updateEvent) = it
|
val (list, updateEvent) = it
|
||||||
adapter.updateList(list, updateEvent)
|
adapter.updateList(list, updateEvent)
|
||||||
if(updateEvent.updateType == UpdateEvent.UpdateType.COMMENT_ADDED_TOP) {
|
if(updateEvent.updateType == UpdateEvent.UpdateType.COMMENT_ADDED_TOP) {
|
||||||
@ -94,15 +98,35 @@ class BottomSheetPostComments() : BottomSheetDialogFragment(), OnUserInteractedC
|
|||||||
adapter.newContentRequestFinished()
|
adapter.newContentRequestFinished()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
viewModel.noMoreContent.observe(viewLifecycleOwner) {
|
|
||||||
|
private val noMoreContentObserver: Observer<Boolean?> = Observer {
|
||||||
if(it == true) {
|
if(it == true) {
|
||||||
adapter.blockInfiniteScroll = true
|
adapter.blockInfiniteScroll = true
|
||||||
viewModel.noMoreContent.postValue(null)
|
viewModel.noMoreContent.postValue(null)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private val finishedEditingComment: Observer<Boolean?> = Observer {
|
||||||
|
if(it == true) {
|
||||||
|
switchEditionModeUi(false)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
optionsViewModel.optionClicked.observe(viewLifecycleOwner, optionsObserver)
|
|
||||||
|
private val commentToEditObserver: Observer<Comment> = Observer {
|
||||||
|
switchEditionModeUi(true)
|
||||||
|
|
||||||
|
viewBinding.newCommentTextField.editText?.setText(it.textContent)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun setObservers() {
|
||||||
|
viewModel.comments.observe(viewLifecycleOwner, commentsObserver)
|
||||||
|
viewModel.noMoreContent.observe(viewLifecycleOwner, noMoreContentObserver)
|
||||||
viewModel.commentPosted.observe(viewLifecycleOwner, commentPostedObserver)
|
viewModel.commentPosted.observe(viewLifecycleOwner, commentPostedObserver)
|
||||||
|
viewModel.commentToEdit.observe(viewLifecycleOwner, commentToEditObserver)
|
||||||
|
viewModel.finishedEditingComment.observe(viewLifecycleOwner, finishedEditingComment)
|
||||||
|
|
||||||
|
optionsViewModel.optionClicked.observe(viewLifecycleOwner, optionsObserver)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setListeners() {
|
private fun setListeners() {
|
||||||
@ -120,6 +144,15 @@ class BottomSheetPostComments() : BottomSheetDialogFragment(), OnUserInteractedC
|
|||||||
viewBinding.newCommentTextField.editText?.text?.clear()
|
viewBinding.newCommentTextField.editText?.text?.clear()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun switchEditionModeUi(editionMode: Boolean) {
|
||||||
|
if(editionMode) {
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
val postId = arguments?.getLong(ARG_POST_ID)
|
val postId = arguments?.getLong(ARG_POST_ID)
|
||||||
@ -135,12 +168,17 @@ class BottomSheetPostComments() : BottomSheetDialogFragment(), OnUserInteractedC
|
|||||||
): View {
|
): View {
|
||||||
viewBinding = BottomSheetPostCommentsBinding.inflate(inflater)
|
viewBinding = BottomSheetPostCommentsBinding.inflate(inflater)
|
||||||
|
|
||||||
(dialog as BottomSheetDialog).behavior.state = BottomSheetBehavior.STATE_EXPANDED
|
|
||||||
return viewBinding.root
|
return viewBinding.root
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
(dialog as BottomSheetDialog).also {
|
||||||
|
it.behavior.state = STATE_EXPANDED
|
||||||
|
it.behavior.skipCollapsed = true
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
viewBinding.recyclerComments.isNestedScrollingEnabled = true
|
viewBinding.recyclerComments.isNestedScrollingEnabled = true
|
||||||
|
|
||||||
@ -186,7 +224,7 @@ class BottomSheetPostComments() : BottomSheetDialogFragment(), OnUserInteractedC
|
|||||||
|
|
||||||
|
|
||||||
override fun onOptions(comment: Ownable) {
|
override fun onOptions(comment: Ownable) {
|
||||||
optionsViewModel.setOptions(Options.POST_OPTIONS, CALLER_ID, comment)
|
optionsViewModel.setOptions(Options.COMMENT_OPTIONS, CALLER_ID, comment)
|
||||||
val fragment = BottomSheetPostOptionsFragment()
|
val fragment = BottomSheetPostOptionsFragment()
|
||||||
fragment.show(parentFragmentManager, BottomSheetPostOptionsFragment.TAG)
|
fragment.show(parentFragmentManager, BottomSheetPostOptionsFragment.TAG)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout
|
<androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
@ -8,11 +8,7 @@
|
|||||||
<com.google.android.material.appbar.AppBarLayout
|
<com.google.android.material.appbar.AppBarLayout
|
||||||
android:id="@+id/topAppBar_layout"
|
android:id="@+id/topAppBar_layout"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content">
|
||||||
app:layout_constraintTop_toTopOf="parent"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintBottom_toTopOf="@id/recycler_comments">
|
|
||||||
|
|
||||||
<com.google.android.material.appbar.MaterialToolbar
|
<com.google.android.material.appbar.MaterialToolbar
|
||||||
android:id="@+id/topAppBar"
|
android:id="@+id/topAppBar"
|
||||||
@ -29,18 +25,29 @@
|
|||||||
<androidx.recyclerview.widget.RecyclerView
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
android:id="@+id/recycler_comments"
|
android:id="@+id/recycler_comments"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="400dp"
|
android:layout_height="match_parent"
|
||||||
app:layout_constraintBottom_toTopOf="@id/new_comment_area"
|
android:layout_marginBottom="184dp"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior" />
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintTop_toBottomOf="@id/topAppBar_layout" />
|
|
||||||
|
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout
|
<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="wrap_content"
|
android:layout_height="120dp"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
android:layout_gravity="bottom">
|
||||||
app:layout_constraintStart_toStartOf="parent">
|
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/comment_actions"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="40dp"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
<com.google.android.material.textfield.TextInputLayout
|
<com.google.android.material.textfield.TextInputLayout
|
||||||
android:id="@+id/newCommentTextField"
|
android:id="@+id/newCommentTextField"
|
||||||
@ -58,12 +65,10 @@
|
|||||||
app:boxCornerRadiusTopEnd="20dp"
|
app:boxCornerRadiusTopEnd="20dp"
|
||||||
app:boxCornerRadiusTopStart="20dp"
|
app:boxCornerRadiusTopStart="20dp"
|
||||||
|
|
||||||
app:startIconDrawable="@drawable/baseline_keyboard_voice_24"
|
|
||||||
|
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintEnd_toStartOf="@+id/submitCommentButton"
|
app:layout_constraintEnd_toStartOf="@+id/submitCommentButton"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent">
|
app:layout_constraintTop_toBottomOf="@id/comment_actions">
|
||||||
|
|
||||||
<com.google.android.material.textfield.TextInputEditText
|
<com.google.android.material.textfield.TextInputEditText
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
@ -84,8 +89,9 @@
|
|||||||
app:icon="@drawable/baseline_send_24"
|
app:icon="@drawable/baseline_send_24"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
app:layout_constraintTop_toBottomOf="@id/comment_actions" />
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
</com.google.android.material.bottomappbar.BottomAppBar>
|
||||||
|
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||||
@ -67,8 +67,11 @@
|
|||||||
<string name="people">People</string>
|
<string name="people">People</string>
|
||||||
<string name="about">About</string>
|
<string name="about">About</string>
|
||||||
<string name="post_will_dropped">This discussion and all related content will be dropped. Continue?</string>
|
<string name="post_will_dropped">This discussion and all related content will be dropped. Continue?</string>
|
||||||
|
<string name="comment_will_be_dropped">This comment will be removed. Continue?</string>
|
||||||
<string name="yes_continue">Yes, delete</string>
|
<string name="yes_continue">Yes, delete</string>
|
||||||
<string name="cancel">Cancel</string>
|
<string name="cancel">Cancel</string>
|
||||||
<string name="save">Save</string>
|
<string name="save">Save</string>
|
||||||
<string name="save_snapshot">Save snapshot</string>
|
<string name="save_snapshot">Save snapshot</string>
|
||||||
|
<string name="comment_posted">Comment posted!</string>
|
||||||
|
<string name="comment_failed_to_post">Comment failed to post</string>
|
||||||
</resources>
|
</resources>
|
||||||
Loading…
x
Reference in New Issue
Block a user