Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update cell models #46

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion SampleProject/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 240bbaaf597009e1611ff399ef5269ba297f09b1

COCOAPODS: 1.11.2
COCOAPODS: 1.11.3
311 changes: 275 additions & 36 deletions SampleProject/SampleProject.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

10 changes: 4 additions & 6 deletions SampleProject/SampleProject/Delegates/PhotoBrowserDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ import SKPhotoBrowser

final class PhotoBrowserDelegate: SKPhotoBrowserDelegate {

var willDismissAtPage: IntClosure?

func willDismissAtPageIndex(_ index: Int) {
if let didDismiss = willDismissAtPage {
didDismiss(index)
}
var didScrollToRow: IntClosure?

func didScrollToIndex(_ browser: SKPhotoBrowser, index: Int) {
didScrollToRow?(index)
}

}
70 changes: 70 additions & 0 deletions SampleProject/SampleProject/Resources/Localizable.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// swiftlint:disable all
// Generated using SwiftGen — https://github.com/SwiftGen/SwiftGen

import Foundation

// swiftlint:disable superfluous_disable_command file_length implicit_return

// MARK: - Strings

// swiftlint:disable explicit_type_interface function_parameter_count identifier_name line_length
// swiftlint:disable nesting type_body_length type_name vertical_whitespace_opening_braces
internal enum Localizable {
internal enum CommentList {
/// %d Tarif %d Takipçi
internal static func userStats(_ p1: Int, _ p2: Int) -> String {
return Localizable.tr("CommentList", "userStats", p1, p2)
}
}
internal enum Favorites {
/// %d Yorum %d Beğeni
internal static func recipeStats(_ p1: Int, _ p2: Int) -> String {
return Localizable.tr("Favorites", "recipeStats", p1, p2)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use Self.tr... for static method calls, rather than Localizable.tr("Favorites", "recipeStats", p1, p2) for more readability

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is automatically generated by Swiftgen. We do not enforce any rules (swiftlint or style guide) for this file.

}
/// TÜMÜNÜ GÖR
internal static let seeAllButtonTitle = Localizable.tr("Favorites", "seeAllButtonTitle")
/// %d Tarif %d Takipçi
internal static func userStats(_ p1: Int, _ p2: Int) -> String {
return Localizable.tr("Favorites", "userStats", p1, p2)
}
}
internal enum RecipeDetail {
/// %d Tarif %d Takipçi
internal static func userStats(_ p1: Int, _ p2: Int) -> String {
return Localizable.tr("RecipeDetail", "userStats", p1, p2)
}
}
internal enum Recipes {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to explicit internal? I'm not sure your requirements right here but it is looking unnecessary.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is automatically generated by Swiftgen. We do not enforce any rules (swiftlint or style guide) for this file.

/// %d Yorum %d Beğeni
internal static func recipeStats(_ p1: Int, _ p2: Int) -> String {
return Localizable.tr("Recipes", "recipeStats", p1, p2)
}
/// %d Tarif %d Takipçi
internal static func userStats(_ p1: Int, _ p2: Int) -> String {
return Localizable.tr("Recipes", "userStats", p1, p2)
}
}
}
// swiftlint:enable explicit_type_interface function_parameter_count identifier_name line_length
// swiftlint:enable nesting type_body_length type_name vertical_whitespace_opening_braces

// MARK: - Implementation Details

extension Localizable {
private static func tr(_ table: String, _ key: String, _ args: CVarArg...) -> String {
let format = BundleToken.bundle.localizedString(forKey: key, value: nil, table: table)
return String(format: format, locale: Locale.current, arguments: args)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use shortened style rather than Locale.current

here is the rule:
Use compiler inferred context to write shorter, clear code.
https://github.com/mobillium/iOS-Guidelines/blob/master/swift-guideline.md

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is automatically generated by Swiftgen. We do not enforce any rules (swiftlint or style guide) for this file.

}
}

// swiftlint:disable convenience_type
private final class BundleToken {
static let bundle: Bundle = {
#if SWIFT_PACKAGE
return Bundle.module
#else
return Bundle(for: BundleToken.self)
#endif
}()
}
// swiftlint:enable convenience_type
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ extension PasswordResetViewModel {
guard let self = self else { return }
self.hideLoading?()
switch result {
case .success(_):
case .success:
self.router.close()
case .failure(let error):
self.showWarningToast?(error.localizedDescription)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ extension CommentEditViewModel {
guard let self = self else { return }
self.hideLoading?()
switch result {
case .success(_):
case .success:
self.editCommentDidSuccess?(commentText)
self.router.close()
case .failure(let error):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
// CommentListCellModel.swift
// SampleProject
//
// Created by Mehmet Salih Aslan on 11.08.2022.
// Copyright © 2022 Mobillium. All rights reserved.
//

import MobilliumUserDefaults

class CommentListCellModel: CommentCellProtocol {

let commentId: Int
let userId: Int
var imageUrl: String?
var username: String?
var userFollowerCount: Int
var userRecipeCount: Int
var userRecipeAndFollowerCountText: String? {
return Localizable.CommentList.userStats(userRecipeCount, userFollowerCount)
}
var timeDifferenceText: String?
var commentText: String?
var isOwner: Bool
var moreButtonTapped: VoidClosure?
var commentTextDidChanged: VoidClosure?

public init(comment: RecipeComment) {
self.userId = comment.user.id
self.imageUrl = comment.user.image?.url
self.username = comment.user.username
self.userFollowerCount = comment.user.followedCount
self.userRecipeCount = comment.user.recipeCount

let isOwner = comment.user.id == DefaultsKey.userId.value
self.commentId = comment.id
self.timeDifferenceText = comment.timeDifference
self.commentText = comment.text
self.isOwner = isOwner
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
CommentList.strings
SampleProject

Created by Mehmet Salih Aslan on 11.08.2022.
Copyright © 2022 Mobillium. All rights reserved.
*/

"userStats" = "%d Tarif %d Takipçi";
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ protocol CommentListViewDataSource {
var title: String { get }

func numberOfItemsAt(section: Int) -> Int
func cellItemAt(indexPath: IndexPath) -> CommentCellProtocol
func cellItemAt(indexPath: IndexPath) -> CommentListCellModel
}

protocol CommentListViewEventSource {
Expand Down Expand Up @@ -52,11 +52,11 @@ final class CommentListViewModel: BaseViewModel<CommentListRouter>, CommentListV
return cellItems.count
}

func cellItemAt(indexPath: IndexPath) -> CommentCellProtocol {
func cellItemAt(indexPath: IndexPath) -> CommentListCellModel {
return cellItems[indexPath.row]
}

var cellItems: [CommentCellProtocol] = []
var cellItems: [CommentListCellModel] = []
}

// MARK: - Actions
Expand Down Expand Up @@ -101,7 +101,6 @@ extension CommentListViewModel {
}

// MARK: - Network
// swiftlint:disable line_length
extension CommentListViewModel {

func fetchComments() {
Expand All @@ -117,7 +116,7 @@ extension CommentListViewModel {
if self.page == 1 {
self.cellItems.removeAll()
}
let cellItems = response.data.map({ CommentCellModel(comment: $0) })
let cellItems = response.data.map({ CommentListCellModel(comment: $0) })
self.cellItems.append(contentsOf: cellItems)
self.isPagingEnabled = response.pagination.currentPage < response.pagination.lastPage
if self.isPagingEnabled { self.page += 1 }
Expand All @@ -127,7 +126,6 @@ extension CommentListViewModel {
}
}
}
// swiftlint:enable line_length

private func deleteCommentRequest(indexPath: IndexPath) {
let commentId = cellItems[indexPath.row].commentId
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// FavoritesCellModel.swift
// SampleProject
//
// Created by Mehmet Salih Aslan on 27.07.2022.
// Copyright © 2022 Mobillium. All rights reserved.
//

import Foundation

public final class FavoritesCellModel: CategoryWithRecipesCellProtocol {
public let categoryId: Int
public let categoryImageURL: String?
public let categoryName: String?
public let seeAllButtonTitle: String? = Localizable.Favorites.seeAllButtonTitle
public var seeAllButtonTapped: TwoVariablesClosure<Int, String>?
public let cellItems: [RecipeSmallCellProtocol]
public var didSelectRecipe: IntClosure?

init(category: MainCategory) {
let cellItems = category.recipes.map({ FavoritesRecipeCellModel(recipe: $0) })
self.categoryId = category.id
self.categoryImageURL = nil
self.categoryName = category.name
self.cellItems = cellItems
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// FavoritesRecipeCellModel.swift
// SampleProject
//
// Created by Mehmet Salih Aslan on 27.07.2022.
// Copyright © 2022 Mobillium. All rights reserved.
//

class FavoritesRecipeCellModel: RecipeSmallCellProtocol {

let recipeId: Int
let userId: Int
let userImageUrl: String?
let username: String?
let recipeTitle: String?
let categoryName: String?
let recipeImageUrl: String?
let commentCount: Int
let likeCount: Int
lazy var recipeCommnetAndLikeCountText: String? = {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why need to use lazy var? both count variables were declared with var,

 var commentCount: Int
 var likeCount: Int

and here is the corner case:
if the count will change after the text was created, the string will look like the wrong count just because of lazy var.

I'm not sure your requirements here but, it's looking like a problematic

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

both commentCount and likeCount both updated to let.

return Localizable.Recipes.recipeStats(commentCount, likeCount)
}()
let isEditorChoice: Bool
var followButtonTapped: VoidClosure?

init(recipe: Recipe) {
self.recipeId = recipe.id
self.userId = recipe.user.id
self.userImageUrl = recipe.user.image?.url
self.username = recipe.user.username
self.recipeTitle = recipe.title
self.categoryName = recipe.category.name
self.recipeImageUrl = recipe.images.first?.url
self.commentCount = recipe.commentCount
self.likeCount = recipe.likeCount
self.isEditorChoice = recipe.isEditorChoice
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
Favorites.strings
SampleProject

Created by Mehmet Salih Aslan on 4.08.2022.
Copyright © 2022 Mobillium. All rights reserved.
*/

"userStats" = "%d Tarif %d Takipçi";
"recipeStats" = "%d Yorum %d Beğeni";
"seeAllButtonTitle" = "TÜMÜNÜ GÖR";
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ final class FavoritesViewModel: BaseViewModel<FavoritesRouter>, FavoritesViewPro
private var page = 1
var isRequestEnabled = false
var isPagingEnabled = false
var cellItems: [CategoryWithRecipesCellModel] = []
var cellItems: [FavoritesCellModel] = []
var didSuccessFetchCategories: VoidClosure?
var didSuccesLogout: VoidClosure?

Expand Down Expand Up @@ -75,12 +75,12 @@ extension FavoritesViewModel {
self.isRequestEnabled = true
switch result {
case .success(let response):
let cellItems = response.data.map({ CategoryWithRecipesCellModel(category: $0) })
let cellItems = response.data.map({ FavoritesCellModel(category: $0) })
self.cellItems.append(contentsOf: cellItems)
self.page += 1
self.isPagingEnabled = response.pagination.currentPage < response.pagination.lastPage
self.didSuccessFetchCategories?()
case .failure(_ ):
case .failure:
if self.page == 1 { self.showWarningToast?(L10n.Error.refreshFromTop) }
}
}
Expand All @@ -93,7 +93,7 @@ extension FavoritesViewModel {
guard let self = self else { return }
self.hideLoading?()
switch result {
case .success(_ ):
case .success:
self.didSuccesLogout?()
case .failure(let error):
self.showWarningToast?(error.localizedDescription)
Expand Down
3 changes: 1 addition & 2 deletions SampleProject/SampleProject/Scenes/Home/HomeViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@ extension HomeViewModel {
guard let self = self else { return }
self.hideLoading?()
switch result {
case .success(let response):
case .success:
self.didSuccesLogout?()
print(response.message)
case .failure(let error):
self.showWarningToast?(error.localizedDescription)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// RecipeDetailComentCellModel.swift
// SampleProject
//
// Created by Mehmet Salih Aslan on 11.08.2022.
// Copyright © 2022 Mobillium. All rights reserved.
//

import MobilliumUserDefaults

class RecipeDetailComentCellModel: CommentCellProtocol {

let commentId: Int
let userId: Int
var imageUrl: String?
var username: String?
var userFollowerCount: Int
var userRecipeCount: Int
var userRecipeAndFollowerCountText: String? {
return Localizable.RecipeDetail.userStats(userRecipeCount, userFollowerCount)
}
var timeDifferenceText: String?
var commentText: String?
var isOwner: Bool
var moreButtonTapped: VoidClosure?
var commentTextDidChanged: VoidClosure?

public init(comment: RecipeComment) {
self.userId = comment.user.id
self.imageUrl = comment.user.image?.url
self.username = comment.user.username
self.userFollowerCount = comment.user.followedCount
self.userRecipeCount = comment.user.recipeCount

let isOwner = comment.user.id == DefaultsKey.userId.value
self.commentId = comment.id
self.timeDifferenceText = comment.timeDifference
self.commentText = comment.text
self.isOwner = isOwner
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// RecipeDetailCommentHeaderCell.swift
// SampleProject
//
// Created by Mehmet Salih Aslan on 11.08.2022.
// Copyright © 2022 Mobillium. All rights reserved.
//

final class RecipeDetailCommentHeaderCell: RecipeHeaderCellProtocol {
var imageUrl: String
var isEditorChoice: Bool

init?(imageUrl: String?, isEditorChoice: Bool) {
guard let imageUrl = imageUrl else {
return nil
}
self.imageUrl = imageUrl
self.isEditorChoice = isEditorChoice
}
}
Loading