Skip to content

Commit

Permalink
feat: hide the home and notification tabs.
Browse files Browse the repository at this point in the history
  • Loading branch information
MainasuK committed Apr 25, 2023
1 parent 9c61dc9 commit cd1162e
Show file tree
Hide file tree
Showing 16 changed files with 127 additions and 100 deletions.
2 changes: 1 addition & 1 deletion TwidereSDK/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ let package = Package(
.package(url: "https://github.com/krzyzanowskim/CryptoSwift.git", from: "1.6.0"),
.package(url: "https://github.com/tid-kijyun/Kanna.git", from: "5.2.7"),
.package(url: "https://github.com/JohnSundell/CollectionConcurrencyKit.git", from: "0.2.0"),
.package(url: "https://github.com/TwidereProject/TwitterSDK.git", from: "0.1.0"),
.package(url: "https://github.com/TwidereProject/TwitterSDK.git", exact: "0.2.0"),
.package(name: "ArkanaKeys", path: "../dependencies/ArkanaKeys"),
.package(name: "CoverFlowStackLayout", path: "../CoverFlowStackLayout"),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ extension TwitterEntity.URLEntity {
)
}

public init(entity: Twitter.Entity.V2.Entities.URL) {
public init(entity: Twitter.Entity.V2.Entities.URLNode) {
self.init(
start: entity.start,
end: entity.end,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,35 +180,7 @@ extension APIService {
)
)
} // end .performChanges { … }

// query and update entity video/GIF attribute from V1 API
do {
let statusIDs: [Twitter.Entity.Tweet.ID] = {
var statusIDs: Set<Twitter.Entity.Tweet.ID> = Set()
for status in response.value.data ?? [] {
guard let mediaKeys = status.attachments?.mediaKeys else { continue }
for mediaKey in mediaKeys {
guard let media = dictionary.mediaDict[mediaKey],
media.attachmentKind == .video || media.attachmentKind == .animatedGIF
else { continue }

statusIDs.insert(status.id)
}
}
return Array(statusIDs)
}()
if !statusIDs.isEmpty {
logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public): fetch \(statusIDs.count) missing assetURL from V1 API…")
_ = try await twitterStatusV1(
statusIDs: statusIDs,
authenticationContext: authenticationContext
)
logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public): fetch missing assetURL from V1 API success")
}
} catch {
logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public): fetch missing assetURL from V1 API fail: \(error.localizedDescription)")
}


return response
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ extension StatusFetchViewModel.Timeline.Search {
switch self {
case .v2(let response):
guard let nextToken = response.value.meta.nextToken else { return nil }
guard fetchContext.nextToken != nextToken else { return nil }
guard let data = response.value.data, data.count > 1 else { return nil }

let fetchContext = fetchContext.map(untilID: response.value.meta.oldestID, nextToken: nextToken)
return .twitter(fetchContext)
case .v1(let response):
Expand Down Expand Up @@ -177,6 +180,7 @@ extension StatusFetchViewModel.Timeline.Search {
startTime: nil,
nextToken: fetchContext.nextToken
)
logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public): [Search] Searching…")
let response = try await api.searchTwitterStatus(
query: query,
authenticationContext: fetchContext.authenticationContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ extension StatusFetchViewModel.Timeline.User {
switch self {
case .v2(let response):
guard let nextToken = response.value.meta.nextToken else { return nil }
guard nextToken != fetchContext.paginationToken else { return nil }
let fetchContext = fetchContext.map(paginationToken: nextToken)
return .twitter(fetchContext)
case .v1(let response):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import os.log
import CoreData
import Combine
import Foundation
import TwitterSDK
import MastodonSDK
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,6 @@ extension MediaGridContainerView {
})
.overlay(alignment: .bottom) {
MediaMetaIndicatorView(viewModel: viewModels[index])
.padding(EdgeInsets(top: 0, leading: 11, bottom: 8, trailing: 11))
.allowsHitTesting(false)
}
.overlay(
RoundedRectangle(cornerRadius: MediaGridContainerView.cornerRadius)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ public struct MediaStackContainerView: View {
.clipShape(RoundedRectangle(cornerRadius: 12))
.overlay(alignment: .bottom) {
MediaMetaIndicatorView(viewModel: item)
.padding(EdgeInsets(top: 0, leading: 11, bottom: 8, trailing: 11))
.allowsHitTesting(false)
}
.overlay(
RoundedRectangle(cornerRadius: 12)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
// Created by MainasuK on 2023/2/28.
//

import os.log
import UIKit
import SwiftUI
import Combine
import AVKit
import AVFoundation

public struct GIFVideoPlayerRepresentable: UIViewRepresentable {

Expand Down Expand Up @@ -78,6 +80,19 @@ public struct GIFVideoPlayerRepresentable: UIViewRepresentable {
}
.store(in: &disposeBag)
} // end func

deinit {
os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s", ((#file as NSString).lastPathComponent), #line, #function)
disposeBag.removeAll()

player?.pause()
player = nil
playerLooper?.disableLooping()
playerLooper = nil
representable.controller.player = nil
representable.controller.removeFromParent()
representable.controller.view.removeFromSuperview()
}
} // end Coordinator

}
2 changes: 0 additions & 2 deletions TwidereX.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,6 @@
DB47AB1F27CCC18500CD73C7 /* ListItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListItem.swift; sourceTree = "<group>"; };
DB47AB2027CCC18500CD73C7 /* ListSection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListSection.swift; sourceTree = "<group>"; };
DB47AB2C27CE085800CD73C7 /* ListViewModel+Diffable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ListViewModel+Diffable.swift"; sourceTree = "<group>"; };
DB49977E29F25E83001C0843 /* TwitterSDK */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = TwitterSDK; path = ../TwitterSDK; sourceTree = "<group>"; };
DB51DC192715581E00A0D8FB /* ProfileDashboardView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileDashboardView.swift; sourceTree = "<group>"; };
DB51DC1B2715588E00A0D8FB /* ProfileDashboardMeterView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileDashboardMeterView.swift; sourceTree = "<group>"; };
DB51DC372716AEF000A0D8FB /* TabBarPager */ = {isa = PBXFileReference; lastKnownFileType = folder; path = TabBarPager; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2038,7 +2037,6 @@
DBDA8E1524FCF8A3006750DC = {
isa = PBXGroup;
children = (
DB49977E29F25E83001C0843 /* TwitterSDK */,
DBE399D829EFE3A7008FA278 /* CoverFlowStackLayout */,
DB51DC372716AEF000A0D8FB /* TabBarPager */,
DB43239D251491EB004FAAEC /* TwidereSDK */,
Expand Down
9 changes: 9 additions & 0 deletions TwidereX.xcworkspace/xcshareddata/swiftpm/Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,15 @@
"version": "0.0.3"
}
},
{
"package": "TwitterSDK",
"repositoryURL": "https://github.com/TwidereProject/TwitterSDK.git",
"state": {
"branch": null,
"revision": "da05cf601b1dccdac4c83421fca58f336dd48d3e",
"version": "0.2.0"
}
},
{
"package": "UITextView+Placeholder",
"repositoryURL": "https://github.com/MainasuK/UITextView-Placeholder.git",
Expand Down
1 change: 0 additions & 1 deletion TwidereX/Diffable/Status/StatusMediaGallerySection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ extension StatusMediaGallerySection {
MediaStackContainerView(viewModel: viewModel)
}
.margins(.vertical, 0) // remove vertical margins

}
}

Expand Down
45 changes: 3 additions & 42 deletions TwidereX/Scene/Profile/ProfileViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,51 +52,12 @@ final class ProfileViewController: UIViewController, NeedsDependency, DrawerSide
}()
private(set) lazy var profilePagingViewController: ProfilePagingViewController = {
let profilePagingViewController = ProfilePagingViewController()

let userTimelineViewModel = UserTimelineViewModel(
profilePagingViewController.viewModel = ProfilePagingViewModel(
context: context,
authContext: authContext,
timelineContext: .init(
timelineKind: .status,
userIdentifier: viewModel.$userIdentifier
)
coordinator: coordinator,
userIdentifier: viewModel.$userIdentifier
)
userTimelineViewModel.isFloatyButtonDisplay = false

let userMediaTimelineViewModel = UserMediaTimelineViewModel(
context: context,
authContext: authContext,
timelineContext: .init(
timelineKind: .media,
userIdentifier: viewModel.$userIdentifier
)
)
userMediaTimelineViewModel.isFloatyButtonDisplay = false

let userLikeTimelineViewModel = UserTimelineViewModel(
context: context,
authContext: authContext,
timelineContext: .init(
timelineKind: .like,
userIdentifier: viewModel.$userIdentifier
)
)
userLikeTimelineViewModel.isFloatyButtonDisplay = false

profilePagingViewController.viewModel = {
let profilePagingViewModel = ProfilePagingViewModel(
userTimelineViewModel: userTimelineViewModel,
userMediaTimelineViewModel: userMediaTimelineViewModel,
userLikeTimelineViewModel: userLikeTimelineViewModel
)
profilePagingViewModel.viewControllers.forEach { viewController in
if let viewController = viewController as? NeedsDependency {
viewController.context = context
viewController.coordinator = coordinator
}
}
return profilePagingViewModel
}()
return profilePagingViewController
}()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,88 @@ import TabBarPager
final class ProfilePagingViewModel: NSObject {

// input
let context: AppContext
let authContext: AuthContext
@Published var displayLikeTimeline: Bool = true

// output
let homeTimelineViewController = UserTimelineViewController()
let mediaTimelineViewController = UserMediaTimelineViewController()
let likeTimelineViewController = UserLikeTimelineViewController()
let userTimelineViewController: UserTimelineViewController
let mediaTimelineViewController: UserMediaTimelineViewController
let likeTimelineViewController: UserLikeTimelineViewController?

init(
userTimelineViewModel: UserTimelineViewModel,
userMediaTimelineViewModel: UserMediaTimelineViewModel,
userLikeTimelineViewModel: UserTimelineViewModel
context: AppContext,
authContext: AuthContext,
coordinator: SceneCoordinator,
userIdentifier: Published<UserIdentifier?>.Publisher?
) {
homeTimelineViewController.viewModel = userTimelineViewModel
mediaTimelineViewController.viewModel = userMediaTimelineViewModel
likeTimelineViewController.viewModel = userLikeTimelineViewModel
self.context = context
self.authContext = authContext
self.userTimelineViewController = {
let viewController = UserTimelineViewController()
let viewModel = UserTimelineViewModel(
context: context,
authContext: authContext,
timelineContext: .init(
timelineKind: .status,
userIdentifier: userIdentifier
)
)
viewModel.isFloatyButtonDisplay = false
viewController.context = context
viewController.coordinator = coordinator
viewController.viewModel = viewModel
return viewController
}()
self.mediaTimelineViewController = {
let viewController = UserMediaTimelineViewController()
let viewModel = UserMediaTimelineViewModel(
context: context,
authContext: authContext,
timelineContext: .init(
timelineKind: .media,
userIdentifier: userIdentifier
)
)
viewModel.isFloatyButtonDisplay = false
viewController.context = context
viewController.coordinator = coordinator
viewController.viewModel = viewModel
return viewController
}()
self.likeTimelineViewController = {
switch authContext.authenticationContext {
case .twitter: return nil
default: break
}
let viewController = UserTimelineViewController()
let viewModel = UserTimelineViewModel(
context: context,
authContext: authContext,
timelineContext: .init(
timelineKind: .like,
userIdentifier: userIdentifier
)
)
viewModel.isFloatyButtonDisplay = false
viewController.context = context
viewController.coordinator = coordinator
viewController.viewModel = viewModel
return viewController
}()
super.init()
// end init
}

var viewControllers: [UIViewController & TabBarPage] {
return [
homeTimelineViewController,
var viewControllers: [UIViewController & TabBarPage] = [
userTimelineViewController,
mediaTimelineViewController,
likeTimelineViewController,
]
if let likeTimelineViewController = likeTimelineViewController {
viewControllers.append(likeTimelineViewController)
}
return viewControllers
}

deinit {
Expand Down
27 changes: 20 additions & 7 deletions TwidereX/Scene/Root/MainTab/MainTabBarController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,8 @@ final class MainTabBarController: UITabBarController, NeedsDependency {

private let doubleTapGestureRecognizer = UITapGestureRecognizer.doubleTapGestureRecognizer

@Published var tabs: [TabBarItem] = [
.home,
.notification,
.search,
.me,
]
@Published var currentTab: TabBarItem = .home
@Published var tabs: [TabBarItem]
@Published var currentTab: TabBarItem

static var popToRootAfterActionTolerance: TimeInterval { 0.5 }
var lastPopToRootTime = CACurrentMediaTime()
Expand All @@ -47,6 +42,24 @@ final class MainTabBarController: UITabBarController, NeedsDependency {
self.context = context
self.coordinator = coordinator
self.authContext = authContext
let tabs: [TabBarItem] = {
switch authContext.authenticationContext {
case .twitter:
return [
.search,
.me,
]
case .mastodon:
return [
.home,
.notification,
.search,
.me,
]
} // end switch
}()
self.tabs = tabs
self.currentTab = tabs.first ?? .me
super.init(nibName: nil, bundle: nil)

UserDefaults.shared.publisher(for: \.tabBarTapScrollPreference)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ extension SearchResultViewModel {
case .twitter(let authenticationContext):
scopes = [
.status(title: L10n.Scene.Search.Tabs.tweets),
.media(title: L10n.Scene.Search.Tabs.media),
// .media(title: L10n.Scene.Search.Tabs.media),
.user(title: L10n.Scene.Search.Tabs.users),
]
userIdentifier = UserIdentifier.twitter(.init(id: authenticationContext.userID))
Expand Down

0 comments on commit cd1162e

Please sign in to comment.