-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into feature/ALTAPPS-882/iOS_profile_badges
- Loading branch information
Showing
16 changed files
with
323 additions
and
118 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
...n/java/org/hyperskill/app/android/core/view/ui/adapter/DataLoadingErrorAdapterDelegate.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package org.hyperskill.app.android.core.view.ui.adapter | ||
|
||
import org.hyperskill.app.android.R | ||
import org.hyperskill.app.android.databinding.WidgetDataLoadingErrorBinding | ||
import ru.nobird.android.ui.adapterdelegates.AdapterDelegate | ||
import ru.nobird.android.ui.adapterdelegates.DelegateViewHolder | ||
import ru.nobird.android.ui.adapterdelegates.dsl.adapterDelegate | ||
|
||
object DataLoadingErrorAdapterDelegate { | ||
// adapterDelegate function is used instead of creating a special class | ||
// because class casting requires a reified type | ||
inline operator fun <D, reified DT : D> invoke( | ||
crossinline onReloadClick: (DT) -> Unit | ||
): AdapterDelegate<D, DelegateViewHolder<D>> = | ||
adapterDelegate<D, DT>(R.layout.widget_data_loading_error) { | ||
val viewBinding = WidgetDataLoadingErrorBinding.bind(itemView) | ||
viewBinding.reloadButton.setOnClickListener { | ||
item?.let(onReloadClick) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
...perskill/app/android/next_learning_activity/view/delegate/NextLearningActivityDelegate.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package org.hyperskill.app.android.next_learning_activity.view.delegate | ||
|
||
import android.content.Context | ||
import android.graphics.drawable.Drawable | ||
import androidx.core.content.ContextCompat | ||
import androidx.fragment.app.Fragment | ||
import androidx.recyclerview.widget.LinearLayoutManager | ||
import org.hyperskill.app.android.R | ||
import org.hyperskill.app.android.core.view.ui.adapter.DataLoadingErrorAdapterDelegate | ||
import org.hyperskill.app.android.core.view.ui.adapter.decoration.HorizontalMarginItemDecoration | ||
import org.hyperskill.app.android.databinding.LayoutNextLearningActivityBinding | ||
import org.hyperskill.app.android.next_learning_activity.view.model.NextLearningActivityLoadingErrorRecyclerItem | ||
import org.hyperskill.app.android.stage_implementation.view.dialog.UnsupportedStageBottomSheet | ||
import org.hyperskill.app.android.study_plan.adapter.ActivityLoadingAdapterDelegate | ||
import org.hyperskill.app.android.study_plan.adapter.StudyPlanActivityAdapterDelegate | ||
import org.hyperskill.app.android.study_plan.delegate.LearningActivityTargetViewActionHandler | ||
import org.hyperskill.app.android.study_plan.model.StudyPlanRecyclerItem | ||
import org.hyperskill.app.next_learning_activity_widget.presentation.NextLearningActivityWidgetFeature | ||
import org.hyperskill.app.next_learning_activity_widget.presentation.NextLearningActivityWidgetFeature.ViewState.Content | ||
import org.hyperskill.app.next_learning_activity_widget.presentation.NextLearningActivityWidgetFeature.ViewState.Empty | ||
import org.hyperskill.app.next_learning_activity_widget.presentation.NextLearningActivityWidgetFeature.ViewState.Idle | ||
import org.hyperskill.app.next_learning_activity_widget.presentation.NextLearningActivityWidgetFeature.ViewState.Loading | ||
import org.hyperskill.app.next_learning_activity_widget.presentation.NextLearningActivityWidgetFeature.ViewState.NetworkError | ||
import org.hyperskill.app.next_learning_activity_widget.view.mapper.NextLearningActivityWidgetViewStateMapper | ||
import ru.nobird.android.ui.adapters.DefaultDelegateAdapter | ||
|
||
class NextLearningActivityDelegate( | ||
context: Context, | ||
onNewMessage: (NextLearningActivityWidgetFeature.Message) -> Unit | ||
) { | ||
|
||
private val nextLearningActivityAdapter by lazy(LazyThreadSafetyMode.NONE) { | ||
DefaultDelegateAdapter<StudyPlanRecyclerItem>().apply { | ||
addDelegate( | ||
StudyPlanActivityAdapterDelegate { | ||
onNewMessage(NextLearningActivityWidgetFeature.Message.NextLearningActivityClicked) | ||
} | ||
) | ||
addDelegate(ActivityLoadingAdapterDelegate()) | ||
addDelegate( | ||
DataLoadingErrorAdapterDelegate<StudyPlanRecyclerItem, NextLearningActivityLoadingErrorRecyclerItem> { | ||
onNewMessage(NextLearningActivityWidgetFeature.Message.RetryContentLoading) | ||
} | ||
) | ||
} | ||
} | ||
|
||
private val nextLearningActivityTitleTextColor: Int = | ||
ContextCompat.getColor(context, StudyPlanRecyclerItem.Activity.activeTextColorRes) | ||
private val nextLearningActivityEndIcon: Drawable? = | ||
ContextCompat.getDrawable(context, StudyPlanRecyclerItem.Activity.nextActivityIconRes) | ||
|
||
fun setup(context: Context, viewBinding: LayoutNextLearningActivityBinding) { | ||
with(viewBinding) { | ||
with(homeNextLearningActivityRecycler) { | ||
adapter = nextLearningActivityAdapter | ||
layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false) | ||
addItemDecoration( | ||
HorizontalMarginItemDecoration( | ||
horizontalMargin = context.resources.getDimensionPixelOffset(R.dimen.screen_horizontal_padding) | ||
) | ||
) | ||
} | ||
} | ||
} | ||
|
||
fun render(state: NextLearningActivityWidgetFeature.State) { | ||
val viewState = NextLearningActivityWidgetViewStateMapper.map(state.contentState) | ||
nextLearningActivityAdapter.items = when (viewState) { | ||
Idle, Empty -> emptyList() | ||
Loading -> listOf(StudyPlanRecyclerItem.ActivityLoading(0, 0)) | ||
is Content -> listOf(mapContentToRecyclerItem(viewState)) | ||
NetworkError -> listOf(NextLearningActivityLoadingErrorRecyclerItem) | ||
} | ||
} | ||
|
||
private fun mapContentToRecyclerItem(content: Content): StudyPlanRecyclerItem.Activity = | ||
StudyPlanRecyclerItem.Activity( | ||
id = content.id, | ||
title = content.title, | ||
subtitle = content.subtitle, | ||
titleTextColor = nextLearningActivityTitleTextColor, | ||
progress = content.progress, | ||
formattedProgress = content.formattedProgress, | ||
endIcon = nextLearningActivityEndIcon, | ||
isClickable = true, | ||
isIdeRequired = content.isIdeRequired | ||
) | ||
|
||
fun <TFragment> handleAction( | ||
fragment: TFragment, | ||
action: NextLearningActivityWidgetFeature.Action.ViewAction | ||
) where TFragment : Fragment, TFragment : UnsupportedStageBottomSheet.Callback { | ||
when (action) { | ||
is NextLearningActivityWidgetFeature.Action.ViewAction.NavigateTo.LearningActivityTarget -> | ||
LearningActivityTargetViewActionHandler.handle( | ||
fragment = fragment, | ||
viewAction = action.viewAction | ||
) | ||
} | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
...android/next_learning_activity/view/model/NextLearningActivityLoadingErrorRecyclerItem.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package org.hyperskill.app.android.next_learning_activity.view.model | ||
|
||
import org.hyperskill.app.android.study_plan.model.StudyPlanRecyclerItem | ||
|
||
object NextLearningActivityLoadingErrorRecyclerItem : StudyPlanRecyclerItem |
19 changes: 19 additions & 0 deletions
19
...main/java/org/hyperskill/app/android/study_plan/adapter/ActivityLoadingAdapterDelegate.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.hyperskill.app.android.study_plan.adapter | ||
|
||
import android.view.ViewGroup | ||
import org.hyperskill.app.android.R | ||
import org.hyperskill.app.android.study_plan.model.StudyPlanRecyclerItem | ||
import ru.nobird.android.ui.adapterdelegates.AdapterDelegate | ||
import ru.nobird.android.ui.adapterdelegates.DelegateViewHolder | ||
|
||
class ActivityLoadingAdapterDelegate : AdapterDelegate< | ||
StudyPlanRecyclerItem, | ||
DelegateViewHolder<StudyPlanRecyclerItem>>() { | ||
override fun isForViewType(position: Int, data: StudyPlanRecyclerItem): Boolean = | ||
data is StudyPlanRecyclerItem.ActivityLoading | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup): DelegateViewHolder<StudyPlanRecyclerItem> = | ||
object : DelegateViewHolder<StudyPlanRecyclerItem>( | ||
createView(parent, R.layout.item_study_plan_activities_loading) | ||
) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
...org/hyperskill/app/android/study_plan/delegate/LearningActivityTargetViewActionHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package org.hyperskill.app.android.study_plan.delegate | ||
|
||
import androidx.fragment.app.Fragment | ||
import org.hyperskill.app.android.core.view.ui.navigation.requireRouter | ||
import org.hyperskill.app.android.projects_selection.list.navigation.ProjectSelectionListScreen | ||
import org.hyperskill.app.android.stage_implementation.view.dialog.UnsupportedStageBottomSheet | ||
import org.hyperskill.app.android.stage_implementation.view.navigation.StageImplementationScreen | ||
import org.hyperskill.app.android.step.view.screen.StepScreen | ||
import org.hyperskill.app.android.track_selection.list.navigation.TrackSelectionListScreen | ||
import org.hyperskill.app.learning_activities.presentation.model.LearningActivityTargetViewAction | ||
import org.hyperskill.app.project_selection.list.injection.ProjectSelectionListParams | ||
import org.hyperskill.app.track_selection.list.injection.TrackSelectionListParams | ||
import ru.nobird.android.view.base.ui.extension.showIfNotExists | ||
|
||
object LearningActivityTargetViewActionHandler { | ||
fun <TFragment> handle( | ||
fragment: TFragment, | ||
viewAction: LearningActivityTargetViewAction | ||
) where TFragment : Fragment, TFragment : UnsupportedStageBottomSheet.Callback { | ||
when (viewAction) { | ||
is LearningActivityTargetViewAction.NavigateTo.SelectProject -> { | ||
fragment.requireRouter().navigateTo( | ||
ProjectSelectionListScreen( | ||
ProjectSelectionListParams( | ||
trackId = viewAction.trackId, | ||
isNewUserMode = false | ||
) | ||
) | ||
) | ||
} | ||
LearningActivityTargetViewAction.NavigateTo.SelectTrack -> { | ||
fragment.requireRouter().navigateTo( | ||
TrackSelectionListScreen( | ||
TrackSelectionListParams(isNewUserMode = false) | ||
) | ||
) | ||
} | ||
is LearningActivityTargetViewAction.NavigateTo.StageImplement -> { | ||
fragment.requireRouter().navigateTo( | ||
StageImplementationScreen( | ||
projectId = viewAction.projectId, | ||
stageId = viewAction.stageId | ||
) | ||
) | ||
} | ||
is LearningActivityTargetViewAction.NavigateTo.Step -> { | ||
fragment.requireRouter().navigateTo(StepScreen(viewAction.stepRoute)) | ||
} | ||
LearningActivityTargetViewAction.ShowStageImplementIDERequiredModal -> { | ||
UnsupportedStageBottomSheet.newInstance() | ||
.showIfNotExists(fragment.childFragmentManager, UnsupportedStageBottomSheet.TAG) | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.