WIP comentarios

This commit is contained in:
Erik Cavazos 2023-09-02 18:08:05 -06:00
parent 4fc72786af
commit 435d669399
6 changed files with 142 additions and 80 deletions

View File

@ -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"

View File

@ -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) }
}
} }

View File

@ -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)
}
} }

View File

@ -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,25 +89,44 @@ 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) { (viewBinding.recyclerComments.layoutManager as LinearLayoutManager).scrollToPosition(0)
(viewBinding.recyclerComments.layoutManager as LinearLayoutManager).scrollToPosition(0) } else {
} else { adapter.newContentRequestFinished()
adapter.newContentRequestFinished()
}
} }
viewModel.noMoreContent.observe(viewLifecycleOwner) { }
if(it == true) {
adapter.blockInfiniteScroll = true
viewModel.noMoreContent.postValue(null)
}
private val noMoreContentObserver: Observer<Boolean?> = Observer {
if(it == true) {
adapter.blockInfiniteScroll = true
viewModel.noMoreContent.postValue(null)
} }
optionsViewModel.optionClicked.observe(viewLifecycleOwner, optionsObserver) }
private val finishedEditingComment: Observer<Boolean?> = Observer {
if(it == true) {
switchEditionModeUi(false)
}
}
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)
} }

View File

@ -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,63 +25,73 @@
<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">
<com.google.android.material.textfield.TextInputLayout <androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/newCommentTextField" android:layout_width="match_parent"
style="?attr/textInputOutlinedStyle" android:layout_height="match_parent">
android:layout_width="0dp" <LinearLayout
android:layout_height="wrap_content" android:id="@+id/comment_actions"
android:layout_margin="8dp"
android:layout_marginStart="4dp"
android:layout_marginTop="4dp"
android:layout_marginEnd="4dp"
android:layout_marginBottom="4dp"
android:hint="@string/new_comment"
app:boxCornerRadiusBottomEnd="20dp"
app:boxCornerRadiusBottomStart="20dp"
app:boxCornerRadiusTopEnd="20dp"
app:boxCornerRadiusTopStart="20dp"
app:startIconDrawable="@drawable/baseline_keyboard_voice_24"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/submitCommentButton"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent" 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
android:id="@+id/newCommentTextField"
style="?attr/textInputOutlinedStyle"
android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:maxLines="1"/> android:layout_margin="8dp"
android:layout_marginStart="4dp"
android:layout_marginTop="4dp"
android:layout_marginEnd="4dp"
android:layout_marginBottom="4dp"
android:hint="@string/new_comment"
app:boxCornerRadiusBottomEnd="20dp"
app:boxCornerRadiusBottomStart="20dp"
app:boxCornerRadiusTopEnd="20dp"
app:boxCornerRadiusTopStart="20dp"
</com.google.android.material.textfield.TextInputLayout> app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/submitCommentButton"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/comment_actions">
<com.google.android.material.button.MaterialButton <com.google.android.material.textfield.TextInputEditText
android:id="@+id/submitCommentButton" android:layout_width="match_parent"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_height="0dp" android:maxLines="1"/>
android:layout_margin="8dp"
android:layout_marginTop="4dp" </com.google.android.material.textfield.TextInputLayout>
android:layout_marginEnd="4dp"
android:layout_marginBottom="4dp" <com.google.android.material.button.MaterialButton
android:enabled="false" android:id="@+id/submitCommentButton"
app:icon="@drawable/baseline_send_24" android:layout_width="wrap_content"
app:layout_constraintBottom_toBottomOf="parent" android:layout_height="0dp"
app:layout_constraintEnd_toEndOf="parent" android:layout_margin="8dp"
app:layout_constraintTop_toTopOf="parent" /> android:layout_marginTop="4dp"
</androidx.constraintlayout.widget.ConstraintLayout> android:layout_marginEnd="4dp"
android:layout_marginBottom="4dp"
android:enabled="false"
app:icon="@drawable/baseline_send_24"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/comment_actions" />
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.bottomappbar.BottomAppBar>
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.coordinatorlayout.widget.CoordinatorLayout>

View File

@ -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>