Skip to content

Instantly share code, notes, and snippets.

View vasilevkin's full-sized avatar
👷‍♂️
working

Sergey Vasilevkin vasilevkin

👷‍♂️
working
View GitHub Profile
/**
Gets Movie data from themoviedb.org api
*/
protocol ApiThemoviedbMoviesProvider {
/**
Fetches popular movies from themoviedb.org api
- Returns: Optional observable array of 'Movie' type
*/
func fetchPopularMovies() -> Observable<[Movie]?>
/**
Service communicates with themoviedb.org api
Consists of separate providers
*/
protocol ApiThemoviedbService: ApiThemoviedbMoviesProvider,
ApiThemoviedbTVShowsProvider,
ApiThemoviedbAuthProvider {
}
class ItemDetailViewController: UIViewController {
@IBOutlet private weak var headerView: ItemDetailHeaderView!
@IBOutlet private weak var videoView: ItemDetailVideoView!
@IBOutlet private weak var tipsView: ItemDetailTipsView!
@IBOutlet private weak var posterImageView: GradientImageView!
@IBOutlet private weak var backButton: UIButton!
var viewModel: ItemDetailViewModel?
private let disposeBag = DisposeBag()
final class ItemDetailViewModel: ViewModelType {
struct Input {
let ready: Driver<Void>
let backTrigger: Driver<Void>
}
struct Output {
let data: Driver<ItemDetailData?>
let mediaData: Driver<AdditionalMediaItemDetailData?>
/**
Type to describe view model
Consists of:
Input: struct describing input parameters
Output: struct describing output parameters
Dependencies: services required for correct data processing inside a view model
Transform: transforming method
*/
protocol ViewModelType {
/**
class ItemDetailVideoView: UIView {
@IBOutlet private weak var trailerTitleLabel: UILabel!
@IBOutlet private weak var trailerSubtitleLabel: UILabel!
@IBOutlet private weak var videoPlayerView: VideoPlayerView!
@IBOutlet private var contentView: UIView!
override init(frame: CGRect) {
super.init(frame: frame)
setup()
/**
Data struct model for Movie
Detail description: https://developers.themoviedb.org/3/movies/get-movie-details
*/
struct Movie: Decodable {
let budget: Int?
let genres: [Genre]?
let homepage: String?
let movieId: Int
let imdbId: String?
extension ApplicationCoordinator: FeaturedCoordinatorDelegate {
/**
Invoked when the featured flow is no longer needed.
*/
func featuredCoordinatorDidFinish() {
dLog("ApplicationCoordinator:: childCoordinators[.featured] = nil")
childCoordinators[.featured] = nil
navigationController.popViewController(animated: true)
/**
Parent delegate protocol for FeaturedCoordinator.
Should be implemented by parent Coordinator who invoked FeaturedCoordinator.
*/
protocol FeaturedCoordinatorDelegate: AnyObject {
/**
Invoked when the featured flow is no longer needed
Coordinator never finishes by itself,
but calls its Parent Coordinator only when it finished work.
/**
Parent delegate protocol for Coordinator.
Should be implemented by Parent Coordinator who invoked Coordinator.
*/
protocol CoordinatorDelegate: AnyObject {
/**
Invoked when the Coordinator is no longer needed
Coordinator never finishes by itself,
but calls its Parent Coordinator only when it finished work.