Skip to content

Commit

Permalink
Merge pull request #15459 from wordpress-mobile/feature/follow-by-not…
Browse files Browse the repository at this point in the history
…ification

Follow conversation by push notification.
  • Loading branch information
develric committed Oct 15, 2021
2 parents 99b324f + fe94325 commit 838d755
Show file tree
Hide file tree
Showing 23 changed files with 1,039 additions and 140 deletions.
1 change: 1 addition & 0 deletions RELEASE-NOTES.txt
Expand Up @@ -2,6 +2,7 @@

18.5
-----
* [**] Reader: allow users to enable push notifications to follow a post comments conversation [WPAndroid - https://github.com/wordpress-mobile/WordPress-Android/pull/15459]
* [*] Fixed an issue where navigating through a couple of related posts in Reader caused the incorrect post to be loaded after rotation [https://github.com/wordpress-mobile/WordPress-Android/issues/14195]
* [*] Allow users to mark Posts as sticky [https://github.com/wordpress-mobile/WordPress-Android/pull/15351]
* [*] Fixed a crash in Page Template chooser [https://github.com/wordpress-mobile/WordPress-Android/pull/15415]
Expand Down
1 change: 1 addition & 0 deletions WordPress/build.gradle
Expand Up @@ -112,6 +112,7 @@ android {
buildConfigField "boolean", "RECOMMEND_THE_APP", "false"
buildConfigField "boolean", "UNIFIED_COMMENTS_COMMENT_EDIT", "false"
buildConfigField "boolean", "MY_SITE_DASHBOARD_PHASE_2", "false"
buildConfigField "boolean", "FOLLOW_BY_PUSH_NOTIFICATION", "false"

manifestPlaceholders = [magicLinkScheme:"wordpress"]
}
Expand Down
Expand Up @@ -166,6 +166,7 @@
import org.wordpress.android.ui.publicize.adapters.PublicizeServiceAdapter;
import org.wordpress.android.ui.quickstart.QuickStartFullScreenDialogFragment;
import org.wordpress.android.ui.quickstart.QuickStartReminderReceiver;
import org.wordpress.android.ui.reader.CommentNotificationsBottomSheetFragment;
import org.wordpress.android.ui.reader.ReaderBlogFragment;
import org.wordpress.android.ui.reader.ReaderCommentListActivity;
import org.wordpress.android.ui.reader.ReaderFragment;
Expand Down Expand Up @@ -706,6 +707,8 @@ public interface AppComponent extends AndroidInjector<WordPress> {

void inject(DomainRegistrationResultFragment object);

void inject(CommentNotificationsBottomSheetFragment object);

// Allows us to inject the application without having to instantiate any modules, and provides the Application
// in the app graph
@Component.Builder
Expand Down
@@ -0,0 +1,102 @@
package org.wordpress.android.ui.reader

import android.content.Context
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.widget.SwitchCompat
import androidx.lifecycle.ViewModelProvider
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialog
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import com.google.android.material.snackbar.Snackbar
import org.wordpress.android.R
import org.wordpress.android.WordPress
import org.wordpress.android.databinding.CommentNotificationsBottomSheetBinding
import org.wordpress.android.ui.utils.UiHelpers
import org.wordpress.android.viewmodel.ContextProvider
import org.wordpress.android.viewmodel.observeEvent
import org.wordpress.android.widgets.WPSnackbar
import javax.inject.Inject

class CommentNotificationsBottomSheetFragment : BottomSheetDialogFragment() {
@Inject lateinit var viewModelFactory: ViewModelProvider.Factory
@Inject lateinit var contextProvider: ContextProvider
@Inject lateinit var uiHelpers: UiHelpers
private lateinit var viewModel: ReaderCommentListViewModel

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.comment_notifications_bottom_sheet, container)
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

with(CommentNotificationsBottomSheetBinding.bind(view)) {
val isReceivingPushNotifications = requireArguments().getBoolean(ARG_IS_RECEIVING_PUSH_NOTIFICATIONS)

initViewModel()

if (savedInstanceState == null) {
enablePushNotifications.isChecked = isReceivingPushNotifications
}

unfollowConversation.setOnClickListener {
viewModel.onUnfollowTapped()
}

enablePushNotifications.setOnClickListener {
viewModel.onChangePushNotificationsRequest((it as SwitchCompat).isChecked)
}

initObservers()
}

(dialog as? BottomSheetDialog)?.apply {
behavior.state = BottomSheetBehavior.STATE_EXPANDED
behavior.skipCollapsed = true
}
}

private fun initViewModel() {
viewModel = ViewModelProvider(
requireActivity(),
viewModelFactory
).get(ReaderCommentListViewModel::class.java)
}

private fun CommentNotificationsBottomSheetBinding.initObservers() {
viewModel.snackbarEvents.observeEvent(viewLifecycleOwner, { messageHolder ->
if (!isAdded) return@observeEvent

WPSnackbar.make(
coordinator,
uiHelpers.getTextOfUiString(contextProvider.getContext(), messageHolder.message),
Snackbar.LENGTH_LONG
).show()
})

viewModel.pushNotificationsStatusUpdate.observeEvent(viewLifecycleOwner, { isReceivingPushNotifications ->
enablePushNotifications.isChecked = isReceivingPushNotifications
})
}

override fun onAttach(context: Context) {
super.onAttach(context)
(requireActivity().applicationContext as WordPress).component().inject(this)
}

companion object {
private const val ARG_IS_RECEIVING_PUSH_NOTIFICATIONS = "ARG_IS_RECEIVING_PUSH_NOTIFICATIONS"

@JvmStatic
fun newInstance(isReceivingPushNotifications: Boolean): CommentNotificationsBottomSheetFragment {
val fragment = CommentNotificationsBottomSheetFragment()
val bundle = Bundle()
bundle.putBoolean(ARG_IS_RECEIVING_PUSH_NOTIFICATIONS, isReceivingPushNotifications)
fragment.arguments = bundle
return fragment
}
}
}
Expand Up @@ -2,10 +2,17 @@ package org.wordpress.android.ui.reader

data class FollowCommentsUiState(
val type: FollowCommentsUiStateType,
val showFollowButton: Boolean = false,
val isFollowing: Boolean = false,
val animate: Boolean = false,
val onFollowButtonClick: ((Boolean) -> Unit)? = null
val showFollowButton: Boolean,
val isFollowing: Boolean,
val animate: Boolean,
val onFollowButtonClick: ((Boolean) -> Unit)?,
val isReceivingNotifications: Boolean,
val isMenuEnabled: Boolean,
val showMenuShimmer: Boolean,
val isBellMenuVisible: Boolean,
val isFollowMenuVisible: Boolean,
val onFollowTapped: (() -> Unit)?,
val onManageNotificationsTapped: () -> Unit
)

enum class FollowCommentsUiStateType {
Expand Down

0 comments on commit 838d755

Please sign in to comment.