Skip to content

Commit

Permalink
Shared: add reminders time to notifications onboarding (#786)
Browse files Browse the repository at this point in the history
^ALTAPPS-1069
  • Loading branch information
ivan-magda authored Dec 15, 2023
1 parent 9726f89 commit dab5f4a
Show file tree
Hide file tree
Showing 44 changed files with 353 additions and 440 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ class NotificationsOnboardingFragment : Fragment() {
ViewAction.RequestNotificationPermission -> {
notificationPermissionDelegate?.requestNotificationPermission()
}
is ViewAction.ShowDailyStudyRemindersIntervalStartHourPickerModal -> {
// TODO: ALTAPPS-1071 show modal
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ fun NotificationsOnboardingScreen(
onNewMessage: (NotificationsOnboardingFeature.Message) -> Unit
) {
val onAllowNotificationsClick by rememberUpdatedState {
onNewMessage(NotificationsOnboardingFeature.Message.AllowNotificationClicked)
onNewMessage(NotificationsOnboardingFeature.Message.AllowNotificationsClicked)
}
val onRemindMeLaterClick by rememberUpdatedState {
onNewMessage(NotificationsOnboardingFeature.Message.RemindMeLaterClicked)
onNewMessage(NotificationsOnboardingFeature.Message.NotNowClicked)
}
Column(
modifier = Modifier
Expand Down Expand Up @@ -124,7 +124,7 @@ fun NotificationsOnboardingButtons(
modifier = Modifier.fillMaxWidth()
) {
Text(
text = stringResource(id = R.string.notifications_onboarding_button_later)
text = stringResource(id = R.string.notifications_onboarding_button_not_now)
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import org.hyperskill.app.android.step.view.fragment.StepFragment
import org.hyperskill.app.android.step.view.model.StepCompletionHost
import org.hyperskill.app.android.step.view.model.StepCompletionView
import org.hyperskill.app.android.step_practice.view.fragment.StepPracticeDetailsFragment
import org.hyperskill.app.android.step_quiz.view.dialog.RequestDailyStudyReminderDialogFragment
import org.hyperskill.app.android.step_quiz.view.factory.StepQuizFragmentFactory
import org.hyperskill.app.step.domain.model.Step
import org.hyperskill.app.step.domain.model.StepRoute
Expand All @@ -42,7 +41,6 @@ class StageStepWrapperFragment :
Fragment(R.layout.fragment_stage_step_wrapper),
ReduxView<StepFeature.State, StepFeature.Action.ViewAction>,
StepCompletionHost,
RequestDailyStudyReminderDialogFragment.Callback,
ShareStreakDialogFragment.Callback {

companion object {
Expand Down Expand Up @@ -83,12 +81,7 @@ class StageStepWrapperFragment :
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
injectComponent()
stepDelegate = StepDelegate(
fragment = this,
onRequestDailyStudyRemindersPermissionResult = { isGranted ->
onNewMessage(StepCompletionFeature.Message.RequestDailyStudyRemindersPermissionResult(isGranted))
}
)
stepDelegate = StepDelegate(fragment = this)
}

private fun injectComponent() {
Expand Down Expand Up @@ -161,10 +154,6 @@ class StageStepWrapperFragment :
stepViewModel.onNewMessage(StepFeature.Message.StepCompletionMessage(message))
}

override fun onPermissionResult(isGranted: Boolean) {
stepDelegate?.onPermissionResult(isGranted)
}

override fun onShareStreakBottomSheetShown(streak: Int) {
stepViewModel.onShareStreakBottomSheetShown(streak)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,28 @@ import android.content.ActivityNotFoundException
import android.content.Context
import android.util.Log
import androidx.annotation.DrawableRes
import androidx.core.app.NotificationManagerCompat
import androidx.fragment.app.Fragment
import org.hyperskill.app.R
import org.hyperskill.app.android.core.extensions.ShareUtils
import org.hyperskill.app.android.core.extensions.checkNotificationChannelAvailability
import org.hyperskill.app.android.core.view.ui.navigation.requireRouter
import org.hyperskill.app.android.databinding.ErrorNoConnectionWithButtonBinding
import org.hyperskill.app.android.main.view.ui.navigation.MainScreen
import org.hyperskill.app.android.main.view.ui.navigation.MainScreenRouter
import org.hyperskill.app.android.main.view.ui.navigation.Tabs
import org.hyperskill.app.android.main.view.ui.navigation.switch
import org.hyperskill.app.android.notification.model.HyperskillNotificationChannel
import org.hyperskill.app.android.notification.permission.NotificationPermissionDelegate
import org.hyperskill.app.android.share_streak.fragment.ShareStreakDialogFragment
import org.hyperskill.app.android.step.view.dialog.TopicPracticeCompletedBottomSheet
import org.hyperskill.app.android.step.view.screen.StepScreen
import org.hyperskill.app.android.step_quiz.view.dialog.CompletedStepOfTheDayDialogFragment
import org.hyperskill.app.android.step_quiz.view.dialog.RequestDailyStudyReminderDialogFragment
import org.hyperskill.app.android.view.base.ui.extension.snackbar
import org.hyperskill.app.step.presentation.StepFeature
import org.hyperskill.app.step_completion.presentation.StepCompletionFeature
import ru.nobird.android.view.base.ui.extension.showIfNotExists

class StepDelegate<TFragment>(
private val fragment: TFragment,
private val onRequestDailyStudyRemindersPermissionResult: (Boolean) -> Unit
) : RequestDailyStudyReminderDialogFragment.Callback
where TFragment : Fragment,
TFragment : RequestDailyStudyReminderDialogFragment.Callback,
TFragment : ShareStreakDialogFragment.Callback {

private val notificationPermissionDelegate: NotificationPermissionDelegate =
NotificationPermissionDelegate(fragment, ::onNotificationPermissionResult)
private val fragment: TFragment
) where TFragment : Fragment,
TFragment : ShareStreakDialogFragment.Callback {

fun init(errorBinding: ErrorNoConnectionWithButtonBinding, onNewMessage: (StepFeature.Message) -> Unit) {
onNewMessage(StepFeature.Message.ViewedEventMessage)
Expand Down Expand Up @@ -80,10 +69,6 @@ class StepDelegate<TFragment>(
TopicPracticeCompletedBottomSheet.Tag
)
}
StepCompletionFeature.Action.ViewAction.RequestDailyStudyRemindersPermission -> {
RequestDailyStudyReminderDialogFragment.newInstance()
.showIfNotExists(fragment.childFragmentManager, RequestDailyStudyReminderDialogFragment.TAG)
}
is StepCompletionFeature.Action.ViewAction.ShowProblemOfDaySolvedModal -> {
CompletedStepOfTheDayDialogFragment
.newInstance(
Expand All @@ -108,35 +93,6 @@ class StepDelegate<TFragment>(
}
}

override fun onPermissionResult(isGranted: Boolean) {
if (isGranted) {
notificationPermissionDelegate.requestNotificationPermission()
} else {
onRequestDailyStudyRemindersPermissionResult(false)
}
}

private fun onNotificationPermissionResult(result: NotificationPermissionDelegate.Result) {
when (result) {
NotificationPermissionDelegate.Result.GRANTED -> {
onNotificationPermissionGranted()
}
NotificationPermissionDelegate.Result.DENIED,
NotificationPermissionDelegate.Result.DONT_ASK -> {
onRequestDailyStudyRemindersPermissionResult(false)
}
}
}

private fun onNotificationPermissionGranted() {
onRequestDailyStudyRemindersPermissionResult(true)
val context = fragment.context
if (context != null) {
NotificationManagerCompat.from(context)
.checkNotificationChannelAvailability(context, HyperskillNotificationChannel.DailyReminder)
}
}

@DrawableRes
private fun getShareStreakDrawableRes(streak: Int): Int =
when (streak) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import org.hyperskill.app.android.step.view.delegate.StepDelegate
import org.hyperskill.app.android.step.view.model.StepCompletionHost
import org.hyperskill.app.android.step.view.model.StepCompletionView
import org.hyperskill.app.android.step_practice.view.fragment.StepPracticeFragment
import org.hyperskill.app.android.step_quiz.view.dialog.RequestDailyStudyReminderDialogFragment
import org.hyperskill.app.android.step_theory.view.fragment.StepTheoryFragment
import org.hyperskill.app.step.domain.model.Step
import org.hyperskill.app.step.domain.model.StepRoute
Expand All @@ -31,7 +30,6 @@ class StepFragment :
Fragment(R.layout.fragment_step),
ReduxView<StepFeature.State, StepFeature.Action.ViewAction>,
StepCompletionHost,
RequestDailyStudyReminderDialogFragment.Callback,
ShareStreakDialogFragment.Callback {

companion object {
Expand Down Expand Up @@ -59,12 +57,7 @@ class StepFragment :
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
injectComponent()
stepDelegate = StepDelegate(
fragment = this,
onRequestDailyStudyRemindersPermissionResult = { isGranted ->
onNewMessage(StepCompletionFeature.Message.RequestDailyStudyRemindersPermissionResult(isGranted))
}
)
stepDelegate = StepDelegate(fragment = this)
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
Expand Down Expand Up @@ -129,10 +122,6 @@ class StepFragment :
)
}

override fun onPermissionResult(isGranted: Boolean) {
stepDelegate?.onPermissionResult(isGranted)
}

override fun onShareStreakBottomSheetShown(streak: Int) {
stepViewModel.onShareStreakBottomSheetShown(streak)
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,6 @@ enum Strings {
enum Step {
static let startPracticing = sharedStrings.step_start_practicing_text.localized()
static let theory = sharedStrings.step_theory_text.localized()

enum RequestDailyNotificationsAlert {
static let title = sharedStrings.after_daily_step_completed_dialog_title.localized()
static let text = sharedStrings.after_daily_step_completed_dialog_text.localized()
}
}

// MARK: - StepQuiz -
Expand Down Expand Up @@ -477,7 +472,7 @@ enum Strings {
static let subtitle = sharedStrings.notifications_onboarding_description.localized()

static let buttonPrimary = sharedStrings.notifications_onboarding_button_allow.localized()
static let buttonSecondary = sharedStrings.notifications_onboarding_button_later.localized()
static let buttonSecondary = sharedStrings.notifications_onboarding_button_not_now.localized()
}

// MARK: - FirstProblemOnboarding -
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Foundation
import shared

final class NotificationsOnboardingViewModel: FeatureViewModel<
NotificationsOnboardingFeature.State,
NotificationsOnboardingFeature.ViewState,
NotificationsOnboardingFeatureMessage,
NotificationsOnboardingFeatureActionViewAction
> {
Expand All @@ -19,18 +19,18 @@ final class NotificationsOnboardingViewModel: FeatureViewModel<
}

override func shouldNotifyStateDidChange(
oldState: NotificationsOnboardingFeature.State,
newState: NotificationsOnboardingFeature.State
oldState: NotificationsOnboardingFeature.ViewState,
newState: NotificationsOnboardingFeature.ViewState
) -> Bool {
false
}

func doPrimaryAction() {
onNewMessage(NotificationsOnboardingFeatureMessageAllowNotificationClicked())
onNewMessage(NotificationsOnboardingFeatureMessageAllowNotificationsClicked())
}

func doSecondaryAction() {
onNewMessage(NotificationsOnboardingFeatureMessageRemindMeLaterClicked())
onNewMessage(NotificationsOnboardingFeatureMessageNotNowClicked())
}

func doRequestNotificationPermission() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ private extension NotificationsOnboardingView {
viewModel.doCompleteOnboarding()
case .requestNotificationPermission:
viewModel.doRequestNotificationPermission()
case .showDailyStudyRemindersIntervalStartHourPickerModal:
#warning("TODO: ALTAPPS-1070 handle this")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ final class StepAssembly: Assembly, UIKitAssembly {
private func makeViewModel() -> StepViewModel {
let commonComponent = AppGraphBridge.sharedAppGraph.commonComponent
let stepComponent = AppGraphBridge.sharedAppGraph.buildStepComponent(stepRoute: stepRoute)
let notificationComponent = AppGraphBridge.sharedAppGraph.buildNotificationComponent()

return StepViewModel(
stepRoute: stepRoute,
Expand All @@ -64,10 +63,6 @@ final class StepAssembly: Assembly, UIKitAssembly {
resourceProvider: commonComponent.resourceProvider,
commentThreadTitleMapper: stepComponent.commentThreadTitleMapper
),
notificationService: NotificationsService(
notificationInteractor: notificationComponent.notificationInteractor
),
notificationsRegistrationService: .shared,
feature: stepComponent.stepFeature
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,17 @@ final class StepViewModel: FeatureViewModel<StepFeatureState, StepFeatureMessage

private let viewDataMapper: StepViewDataMapper

private let notificationService: NotificationsService
private let notificationsRegistrationService: NotificationsRegistrationService

var stateKs: StepFeatureStateKs { .init(state) }

var isStageImplement: Bool { stepRoute is StepRouteStageImplement }

init(
stepRoute: StepRoute,
viewDataMapper: StepViewDataMapper,
notificationService: NotificationsService,
notificationsRegistrationService: NotificationsRegistrationService,
feature: Presentation_reduxFeature
) {
self.stepRoute = stepRoute
self.viewDataMapper = viewDataMapper
self.notificationService = notificationService
self.notificationsRegistrationService = notificationsRegistrationService

super.init(feature: feature)

Expand Down Expand Up @@ -85,28 +78,6 @@ final class StepViewModel: FeatureViewModel<StepFeatureState, StepFeatureMessage
}
}

// MARK: Daily notifications request

func handleSendDailyStudyRemindersPermissionRequestResult(isGranted: Bool) {
let message = StepFeatureMessageStepCompletionMessage(
message: StepCompletionFeatureMessageRequestDailyStudyRemindersPermissionResult(
isGranted: isGranted
)
)

if isGranted {
Task(priority: .userInitiated) {
let _ = await notificationsRegistrationService.requestAuthorizationIfNeeded()

await MainActor.run {
onNewMessage(message)
}
}
} else {
onNewMessage(message)
}
}

// MARK: Analytic

func logViewedEvent() {
Expand Down
Loading

0 comments on commit dab5f4a

Please sign in to comment.