Skip to content

Commit

Permalink
refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
ducanh2211 committed Jun 8, 2023
1 parent af5d41b commit 121ff81
Show file tree
Hide file tree
Showing 39 changed files with 1,285 additions and 863 deletions.
36 changes: 36 additions & 0 deletions InstagramClone.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

/* Begin PBXBuildFile section */
5386F2742F5FE4D9BD67E437 /* Pods_InstagramClone.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 93C2667D5D8E9DDDE5CBCC9E /* Pods_InstagramClone.framework */; };
5701430B2A30C8F900F1B8D5 /* PostDetailCellViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5701430A2A30C8F900F1B8D5 /* PostDetailCellViewModel.swift */; };
5701430D2A317D0400F1B8D5 /* HomePostCellViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5701430C2A317D0400F1B8D5 /* HomePostCellViewModel.swift */; };
5718EAF52A05E73C00C44428 /* PhotoCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5718EAF42A05E73C00C44428 /* PhotoCollectionViewCell.swift */; };
5718EAF72A05EC9000C44428 /* ProfileStoryCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5718EAF62A05EC9000C44428 /* ProfileStoryCell.swift */; };
571C48352A28378E009EECE0 /* LoadingIndicatorFooterView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 571C48342A28378E009EECE0 /* LoadingIndicatorFooterView.swift */; };
Expand Down Expand Up @@ -70,6 +72,9 @@
578574B12A26D7A400448BF4 /* ProfilePhotoDisplayViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 578574B02A26D7A400448BF4 /* ProfilePhotoDisplayViewModel.swift */; };
578574B42A27598200448BF4 /* ExploreViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 578574B32A27598200448BF4 /* ExploreViewModel.swift */; };
579BC7152A2C337200C81D91 /* HomeViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 579BC7142A2C337200C81D91 /* HomeViewModel.swift */; };
579BC7182A2CF4CA00C81D91 /* ProfileViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 579BC7172A2CF4CA00C81D91 /* ProfileViewModel.swift */; };
579BC71B2A2D791800C81D91 /* ProfileHeaderViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 579BC71A2A2D791800C81D91 /* ProfileHeaderViewModel.swift */; };
579BC71D2A2D83DE00C81D91 /* ProfileBottomViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 579BC71C2A2D83DE00C81D91 /* ProfileBottomViewModel.swift */; };
57AB72942A13309500FB5B09 /* ProfileHeaderController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57AB72932A13309500FB5B09 /* ProfileHeaderController.swift */; };
57AB72962A13316900FB5B09 /* ProfileBottomController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57AB72952A13316900FB5B09 /* ProfileBottomController.swift */; };
57AB729A2A13443000FB5B09 /* ProfilePhotoDisplayController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57AB72992A13443000FB5B09 /* ProfilePhotoDisplayController.swift */; };
Expand Down Expand Up @@ -124,6 +129,8 @@

/* Begin PBXFileReference section */
48C82344D17EAD6A024C44E7 /* Pods-InstagramClone.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-InstagramClone.debug.xcconfig"; path = "Target Support Files/Pods-InstagramClone/Pods-InstagramClone.debug.xcconfig"; sourceTree = "<group>"; };
5701430A2A30C8F900F1B8D5 /* PostDetailCellViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostDetailCellViewModel.swift; sourceTree = "<group>"; };
5701430C2A317D0400F1B8D5 /* HomePostCellViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomePostCellViewModel.swift; sourceTree = "<group>"; };
5718EAF42A05E73C00C44428 /* PhotoCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhotoCollectionViewCell.swift; sourceTree = "<group>"; };
5718EAF62A05EC9000C44428 /* ProfileStoryCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileStoryCell.swift; sourceTree = "<group>"; };
571C48342A28378E009EECE0 /* LoadingIndicatorFooterView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadingIndicatorFooterView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -186,6 +193,9 @@
578574B02A26D7A400448BF4 /* ProfilePhotoDisplayViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfilePhotoDisplayViewModel.swift; sourceTree = "<group>"; };
578574B32A27598200448BF4 /* ExploreViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExploreViewModel.swift; sourceTree = "<group>"; };
579BC7142A2C337200C81D91 /* HomeViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeViewModel.swift; sourceTree = "<group>"; };
579BC7172A2CF4CA00C81D91 /* ProfileViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileViewModel.swift; sourceTree = "<group>"; };
579BC71A2A2D791800C81D91 /* ProfileHeaderViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileHeaderViewModel.swift; sourceTree = "<group>"; };
579BC71C2A2D83DE00C81D91 /* ProfileBottomViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileBottomViewModel.swift; sourceTree = "<group>"; };
57AB72932A13309500FB5B09 /* ProfileHeaderController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileHeaderController.swift; sourceTree = "<group>"; };
57AB72952A13316900FB5B09 /* ProfileBottomController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileBottomController.swift; sourceTree = "<group>"; };
57AB72992A13443000FB5B09 /* ProfilePhotoDisplayController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfilePhotoDisplayController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -392,6 +402,7 @@
isa = PBXGroup;
children = (
5740391C2A16254200A9A2F6 /* View */,
579BC7192A2D790500C81D91 /* ViewModel */,
5740391B2A16253000A9A2F6 /* Controller */,
);
path = Header;
Expand Down Expand Up @@ -447,6 +458,7 @@
isa = PBXGroup;
children = (
574039222A16259800A9A2F6 /* View */,
579BC7162A2CF4A500C81D91 /* ViewModel */,
574039212A16258E00A9A2F6 /* Controller */,
);
path = Root;
Expand Down Expand Up @@ -521,6 +533,7 @@
578574B22A26FDBD00448BF4 /* ViewModel */ = {
isa = PBXGroup;
children = (
579BC71C2A2D83DE00C81D91 /* ProfileBottomViewModel.swift */,
578574B02A26D7A400448BF4 /* ProfilePhotoDisplayViewModel.swift */,
);
path = ViewModel;
Expand All @@ -538,6 +551,23 @@
isa = PBXGroup;
children = (
579BC7142A2C337200C81D91 /* HomeViewModel.swift */,
5701430C2A317D0400F1B8D5 /* HomePostCellViewModel.swift */,
);
path = ViewModel;
sourceTree = "<group>";
};
579BC7162A2CF4A500C81D91 /* ViewModel */ = {
isa = PBXGroup;
children = (
579BC7172A2CF4CA00C81D91 /* ProfileViewModel.swift */,
);
path = ViewModel;
sourceTree = "<group>";
};
579BC7192A2D790500C81D91 /* ViewModel */ = {
isa = PBXGroup;
children = (
579BC71A2A2D791800C81D91 /* ProfileHeaderViewModel.swift */,
);
path = ViewModel;
sourceTree = "<group>";
Expand Down Expand Up @@ -786,6 +816,7 @@
57B893202A24F39900128AAB /* Post Detail */ = {
isa = PBXGroup;
children = (
5701430A2A30C8F900F1B8D5 /* PostDetailCellViewModel.swift */,
57B893232A24F53A00128AAB /* PostDetailCell.swift */,
57B893212A24F40000128AAB /* PostDetailController.swift */,
);
Expand Down Expand Up @@ -1007,11 +1038,13 @@
575C4D5129F7BCC700C9287B /* NewPostViewModel.swift in Sources */,
5733AE502A13269F00193A85 /* DefaultPagingMenuCell.swift in Sources */,
57CA5F812A1A0A88001D1E4A /* ProfileSettingsSheetController.swift in Sources */,
579BC71B2A2D791800C81D91 /* ProfileHeaderViewModel.swift in Sources */,
576F57C929EAD014002F2A6E /* LoginViewModel.swift in Sources */,
57AB72962A13316900FB5B09 /* ProfileBottomController.swift in Sources */,
5733AE442A13268800193A85 /* MenuBottomIndicator.swift in Sources */,
57DE12662A147F2A00FDF302 /* UIImage + Extenstion.swift in Sources */,
57C817722A1B80CC0000445F /* ProfileHeaderController + Setup.swift in Sources */,
579BC71D2A2D83DE00C81D91 /* ProfileBottomViewModel.swift in Sources */,
57DE12582A13962800FDF302 /* String + Extension.swift in Sources */,
57DE126D2A14D8A500FDF302 /* HomePostCell.swift in Sources */,
5733AE4D2A13268800193A85 /* DefaultMenuItem.swift in Sources */,
Expand Down Expand Up @@ -1046,6 +1079,7 @@
57CA5F792A188AB4001D1E4A /* UINavigationController + Extension.swift in Sources */,
5733AE492A13268800193A85 /* PagingViewControllerDelegate.swift in Sources */,
5733AE582A1328E600193A85 /* BottomControllerProvider.swift in Sources */,
5701430B2A30C8F900F1B8D5 /* PostDetailCellViewModel.swift in Sources */,
57ABFC6329E9A64600FF1BEB /* LogInViewController.swift in Sources */,
57CA5F8C2A1B112C001D1E4A /* ProfileEditController + Setup.swift in Sources */,
57ABFC4A29E998FD00FF1BEB /* SceneDelegate.swift in Sources */,
Expand All @@ -1056,6 +1090,7 @@
57ABFC6F29E9A7BB00FF1BEB /* ProfileController.swift in Sources */,
57B8931A2A23A69000128AAB /* NewPostController + Setup.swift in Sources */,
57CA5F7D2A193334001D1E4A /* BottomSheetSettings.swift in Sources */,
579BC7182A2CF4CA00C81D91 /* ProfileViewModel.swift in Sources */,
57CA5F8E2A1B1E66001D1E4A /* BottomSheetViewController.swift in Sources */,
5718EAF72A05EC9000C44428 /* ProfileStoryCell.swift in Sources */,
578574B42A27598200448BF4 /* ExploreViewModel.swift in Sources */,
Expand All @@ -1075,6 +1110,7 @@
5733AE5A2A1328E600193A85 /* ContainerScrollViewDatasource.swift in Sources */,
57B893222A24F40000128AAB /* PostDetailController.swift in Sources */,
574039292A162E9100A9A2F6 /* ProfileEditCell.swift in Sources */,
5701430D2A317D0400F1B8D5 /* HomePostCellViewModel.swift in Sources */,
57B893272A250F3600128AAB /* LikeDetailController.swift in Sources */,
571C48432A2902A8009EECE0 /* FollowersDetailCell.swift in Sources */,
576F57D729EBB8B5002F2A6E /* TabBarViewModel.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,102 +3,4 @@
uuid = "37E211ED-062C-4B82-8CB9-3DEDE75C2BFD"
type = "0"
version = "2.0">
<Breakpoints>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "E24EEF3C-9D78-4E4A-989C-7C88BBC82F76"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "InstagramClone/Source/Profile/Bottom/Controller/ProfilePhotoDisplayViewModel.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "43"
endingLineNumber = "43"
landmarkName = "getPosts()"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "7644F67E-D454-421E-8B68-0B3CB831073B"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "InstagramClone/Source/Profile/Bottom/Controller/ProfilePhotoDisplayViewModel.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "79"
endingLineNumber = "79"
landmarkName = "paginate()"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "8A779931-52BB-4DF3-8DE4-90D19A8DF62E"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "InstagramClone/Source/Home/Controller/HomeController.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "86"
endingLineNumber = "86"
landmarkName = "handleRefresh()"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "1E2E77FA-A4FB-4D55-8209-064DD46637C2"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "InstagramClone/Source/Home/Controller/HomeController.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "77"
endingLineNumber = "77"
landmarkName = "bindViewModel()"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "65255650-CC9C-4E18-A9C6-4F25ACFD1E1A"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "InstagramClone/Source/Explore/Controller/ExploreController.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "114"
endingLineNumber = "114"
landmarkName = "collectionView(_:cellForItemAt:)"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "275B855B-6D14-4ECD-ABA0-440B853D0D48"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "InstagramClone/Source/Explore/Controller/ExploreController.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "106"
endingLineNumber = "106"
landmarkName = "collectionView(_:numberOfItemsInSection:)"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>
54 changes: 30 additions & 24 deletions InstagramClone/Helper/Extension/Extentsion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,44 @@
import UIKit

extension UITextField {
func setPadding(left: CGFloat? = nil, right: CGFloat? = nil) {
if let left = left {
let leftView = UIView(frame: CGRect(x: 0, y: 0, width: left, height: self.frame.height))
self.leftViewMode = .always
self.leftView = leftView
func setPadding(left: CGFloat? = nil, right: CGFloat? = nil) {
if let left = left {
let leftView = UIView(frame: CGRect(x: 0, y: 0, width: left, height: self.frame.height))
self.leftViewMode = .always
self.leftView = leftView
}
if let right = right {
let rightView = UIView(frame: CGRect(x: 0, y: 0, width: right, height: self.frame.height))
self.rightViewMode = .always
self.rightView = rightView
}
}
if let right = right {
let rightView = UIView(frame: CGRect(x: 0, y: 0, width: right, height: self.frame.height))
self.rightViewMode = .always
self.rightView = rightView
}
}
}

extension UILabel {
func isTextTruncated() -> Bool {
guard let text = text else { return false }
let labelTextHeight = text.height(constrainedWidth: bounds.width, font: font)
return labelTextHeight > bounds.height
}
func getSize(constrainedWidth width: CGFloat) -> CGSize {
let size = CGSize(width: width, height: UIView.layoutFittingCompressedSize.height)
return systemLayoutSizeFitting(size, withHorizontalFittingPriority: .required, verticalFittingPriority: .fittingSizeLevel)
}

func isTextTruncated() -> Bool {
guard let text = text else { return false }
let labelTextHeight = text.height(constrainedWidth: bounds.width, font: font)
return labelTextHeight > bounds.height
}
}

extension Notification.Name {
static let reloadUserProfileFeed = Notification.Name("reloadUserProfileFeed")
static let userDidUploadNewPost = Notification.Name("userDidUploadNewPost")
static let currentUserDidUpdateInfo = Notification.Name("currentUserDidUpdateInfo")
}

extension UIApplication {
var keyWindow: UIWindow? {
UIApplication
.shared
.connectedScenes
.compactMap { ($0 as? UIWindowScene)?.keyWindow }
.last
}
var keyWindow: UIWindow? {
UIApplication
.shared
.connectedScenes
.compactMap { ($0 as? UIWindowScene)?.keyWindow }
.last
}
}
2 changes: 1 addition & 1 deletion InstagramClone/Helper/Extension/String + Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ extension String {
options: .usesLineFragmentOrigin,
attributes: [.font: font],
context: nil)
return ceil(boundingBox.height)
return floor(boundingBox.height)
}
}

Expand Down
Loading

0 comments on commit 121ff81

Please sign in to comment.