-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #829 from hyperskill/feature/interview_preparation
Interview preparation
- Loading branch information
Showing
127 changed files
with
3,025 additions
and
177 deletions.
There are no files selected for viewing
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
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
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
49 changes: 49 additions & 0 deletions
49
...hyperskill/app/android/interview_preparation/delegate/InterviewPreparationCardDelegate.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,49 @@ | ||
package org.hyperskill.app.android.interview_preparation.delegate | ||
|
||
import androidx.compose.runtime.DisposableEffect | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.ui.platform.ComposeView | ||
import androidx.compose.ui.platform.ViewCompositionStrategy | ||
import androidx.lifecycle.LifecycleOwner | ||
import androidx.lifecycle.compose.collectAsStateWithLifecycle | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import org.hyperskill.app.android.core.view.ui.widget.compose.HyperskillTheme | ||
import org.hyperskill.app.android.interview_preparation.ui.InterviewPreparationCard | ||
import org.hyperskill.app.interview_preparation.presentation.InterviewPreparationWidgetFeature | ||
import org.hyperskill.app.interview_preparation.view.model.InterviewPreparationWidgetViewState | ||
|
||
class InterviewPreparationCardDelegate { | ||
private val stateFlow: MutableStateFlow<InterviewPreparationWidgetViewState?> = MutableStateFlow(null) | ||
fun setup( | ||
composeView: ComposeView, | ||
viewLifecycleOwner: LifecycleOwner, | ||
onNewMessage: (InterviewPreparationWidgetFeature.Message) -> Unit | ||
) { | ||
composeView.apply { | ||
setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnLifecycleDestroyed(viewLifecycleOwner)) | ||
setContent { | ||
HyperskillTheme { | ||
val viewState by stateFlow.collectAsStateWithLifecycle() | ||
DisposableEffect(viewLifecycleOwner) { | ||
onNewMessage(InterviewPreparationWidgetFeature.Message.ViewedEventMessage) | ||
onDispose { | ||
// no op | ||
} | ||
} | ||
viewState?.let { actualViewState -> | ||
InterviewPreparationCard( | ||
viewState = actualViewState, | ||
onNewMessage = onNewMessage | ||
) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
fun render( | ||
viewState: InterviewPreparationWidgetViewState | ||
) { | ||
stateFlow.value = viewState | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
...ll/app/android/interview_preparation/dialog/InterviewPreparationFinishedDialogFragment.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,70 @@ | ||
package org.hyperskill.app.android.interview_preparation.dialog | ||
|
||
import android.app.Dialog | ||
import android.content.DialogInterface | ||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import by.kirich1409.viewbindingdelegate.viewBinding | ||
import com.google.android.material.bottomsheet.BottomSheetBehavior | ||
import com.google.android.material.bottomsheet.BottomSheetDialog | ||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment | ||
import org.hyperskill.app.android.R | ||
import org.hyperskill.app.android.databinding.FragmentInterviewPreparationFinishedBinding | ||
import org.hyperskill.app.android.view.base.ui.extension.wrapWithTheme | ||
|
||
class InterviewPreparationFinishedDialogFragment : BottomSheetDialogFragment() { | ||
companion object { | ||
const val TAG = "InterviewPreparationFinishedBottomSheetTag" | ||
|
||
fun newInstance(): InterviewPreparationFinishedDialogFragment = | ||
InterviewPreparationFinishedDialogFragment() | ||
} | ||
|
||
private val binding: FragmentInterviewPreparationFinishedBinding by viewBinding( | ||
FragmentInterviewPreparationFinishedBinding::bind | ||
) | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setStyle(STYLE_NORMAL, R.style.TopCornersRoundedBottomSheetDialog) | ||
} | ||
|
||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog = | ||
BottomSheetDialog(requireContext(), theme).also { dialog -> | ||
dialog.setOnShowListener { | ||
dialog.behavior.state = BottomSheetBehavior.STATE_EXPANDED | ||
if (savedInstanceState == null) { | ||
(parentFragment as? Callback)?.onInterviewPreparationFinishedDialogShown() | ||
} | ||
} | ||
} | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, | ||
container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View? = | ||
inflater.wrapWithTheme(requireActivity()) | ||
.inflate(R.layout.fragment_interview_preparation_finished, container, false) | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
binding.interviewFinishedGoTrainingButton.setOnClickListener { | ||
(parentFragment as? Callback) | ||
?.onInterviewPreparationFinishedDialogGoTrainingClicked() | ||
} | ||
} | ||
|
||
override fun onDismiss(dialog: DialogInterface) { | ||
(parentFragment as? Callback)?.onInterviewPreparationFinishedDialogHidden() | ||
} | ||
|
||
interface Callback { | ||
fun onInterviewPreparationFinishedDialogShown() | ||
|
||
fun onInterviewPreparationFinishedDialogHidden() | ||
|
||
fun onInterviewPreparationFinishedDialogGoTrainingClicked() | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
...main/java/org/hyperskill/app/android/interview_preparation/ui/InterviewPreparationCard.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,52 @@ | ||
package org.hyperskill.app.android.interview_preparation.ui | ||
|
||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.unit.dp | ||
import org.hyperskill.app.R | ||
import org.hyperskill.app.android.core.view.ui.widget.compose.ShimmerLoading | ||
import org.hyperskill.app.android.core.view.ui.widget.compose.WidgetDataLoadingError | ||
import org.hyperskill.app.interview_preparation.presentation.InterviewPreparationWidgetFeature.Message | ||
import org.hyperskill.app.interview_preparation.view.model.InterviewPreparationWidgetViewState | ||
|
||
@Composable | ||
fun InterviewPreparationCard( | ||
viewState: InterviewPreparationWidgetViewState, | ||
onNewMessage: (Message) -> Unit | ||
) { | ||
when (viewState) { | ||
InterviewPreparationWidgetViewState.Idle, | ||
InterviewPreparationWidgetViewState.Empty -> { | ||
// no op | ||
} | ||
is InterviewPreparationWidgetViewState.Loading -> { | ||
if (viewState.shouldShowSkeleton) { | ||
ShimmerLoading( | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.height(120.dp) | ||
) | ||
} | ||
} | ||
InterviewPreparationWidgetViewState.Error -> { | ||
WidgetDataLoadingError( | ||
onRetryClick = { | ||
onNewMessage(Message.RetryContentLoading) | ||
}, | ||
modifier = Modifier.fillMaxWidth(), | ||
title = stringResource(id = R.string.interview_preparation_widget_network_error_text) | ||
) | ||
} | ||
is InterviewPreparationWidgetViewState.Content -> { | ||
InterviewPreparationContent( | ||
content = viewState, | ||
onClick = { | ||
onNewMessage(Message.WidgetClicked) | ||
} | ||
) | ||
} | ||
} | ||
} |
Oops, something went wrong.