Skip to content

Commit

Permalink
Initial commit for release build. Cloned from main and porting change…
Browse files Browse the repository at this point in the history
…s over

Critical changes in this commit for the new SpankyKong theme, new model for additional fields, updated stencils and adding lotties

Adding updates to scraping and views. Adding Chidori menu

Updating post view images and adding bookmark colour picker view

Slight cleanup and navigation bar changes

Fix lotties

Small fixes

Final cleanup pass 1

Cleanup

More cleanup

Fixed platinum-member.png and ghost.json locations. Removed my account from SmileyKeyboard signing settings

Changing posted toot back to 100x100
  • Loading branch information
nolanw committed Jun 12, 2022
1 parent ca8098a commit 8d92fb3
Show file tree
Hide file tree
Showing 276 changed files with 7,424 additions and 487 deletions.
7 changes: 4 additions & 3 deletions App/Composition/ComposeTextViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,13 @@ class ComposeTextViewController: ViewController {
fileprivate var imageUploadProgress: Progress?

fileprivate func submit() {
let overlay = MRProgressOverlayView.showOverlayAdded(to: viewToOverlay, title: submissionInProgressTitle, mode: .indeterminate, animated: true)
overlay?.tintColor = theme["tintColor"]
let loadingView = PostedTootLoadingView()
loadingView.backgroundColor = theme["backgroundColor"]

view.addSubview(loadingView)

imageUploadProgress = uploadImages(attachedTo: textView.attributedText, completion: { [weak self] (plainText, error) in
if let error = error {
overlay?.dismiss(false)

self?.enableEverything()

Expand Down
8 changes: 4 additions & 4 deletions App/Data Sources/ForumListDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -432,9 +432,9 @@ extension ForumListDataSource: UITableViewDataSource {
return ForumListCell.ViewModel(
backgroundColor: theme["listBackgroundColor"]!,
expansion: .none,
expansionTintColor: theme["tintColor"]!,
expansionTintColor: theme["expansionTintColor"]!,
favoriteStar: .isFavorite,
favoriteStarTintColor: theme["tintColor"]!,
favoriteStarTintColor: theme["favoriteStarTintColor"]!,
forumName: NSAttributedString(string: forum.name ?? "", attributes: [
.font: UIFont.preferredFont(forTextStyle: .body),
.foregroundColor: theme[color: "listTextColor"]!]),
Expand All @@ -455,9 +455,9 @@ extension ForumListDataSource: UITableViewDataSource {
return .canExpand
}
}(),
expansionTintColor: theme["tintColor"]!,
expansionTintColor: theme["expansionTintColor"]!,
favoriteStar: forum.metadata.favorite ? .hidden : .canFavorite,
favoriteStarTintColor: theme["tintColor"]!,
favoriteStarTintColor: theme["favoriteStarTintColor"]!,
forumName: NSAttributedString(string: forum.name ?? "", attributes: [
.font: UIFont.preferredFont(forTextStyle: .body),
.foregroundColor: theme[color: "listTextColor"]!]),
Expand Down
36 changes: 30 additions & 6 deletions App/Data Sources/MessageListDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import AwfulCore
import CoreData
import UIKit
import HTMLReader

private let Log = Logger.get()

Expand Down Expand Up @@ -97,7 +98,9 @@ extension MessageListDataSource: UITableViewDataSource {
let message = self.message(at: indexPath)
let theme = Theme.defaultTheme()

// Create Date Formatter
let dateFormatter = DateFormatter()
// Set Date/Time Style
dateFormatter.dateFormat = "d MMM"

var sentDateRawFont: UIFont
Expand All @@ -113,29 +116,50 @@ extension MessageListDataSource: UITableViewDataSource {
senderFont = UIFont.systemFont(ofSize: 15, weight: .regular)
subjectFont = UIFont.systemFont(ofSize: 15, weight: .regular)
}

return MessageListCell.ViewModel(
backgroundColor: theme["listBackgroundColor"]!,
selectedBackgroundColor: theme["listSelectedBackgroundColor"]!,
sender: NSAttributedString(string: message.fromUsername ?? "", attributes: [
.foregroundColor: theme[color: "listTextColor"]!]),
.font: senderFont,
.foregroundColor: theme[color: "listSecondaryTextColor"]!]),
sentDate: message.sentDate ?? .distantPast,
sentDateAttributes: [
.foregroundColor: theme[color: "listTextColor"]!],
sentDateAttributes: [:
// .font: UIFont.preferredFontForTextStyle(.body, fontName: nil, sizeAdjustment: -2),
// .foregroundColor: theme[color: "listTextColor"]!
],
sentDateRaw: NSAttributedString(string: dateFormatter.string(from: message.sentDate!), attributes: [
.font: sentDateRawFont,
.foregroundColor: theme[color: "listSecondaryTextColor"]!]),
subject: NSAttributedString(string: message.subject ?? "", attributes: [
.font: subjectFont,
.foregroundColor: theme[color: "listTextColor"]!]),
tagImage: .image(name: message.threadTag?.imageName, placeholder: .privateMessage),

tagOverlayImage: {
if message.replied {
return UIImage(named: "pmreplied")
let image = UIImage(named: "pmreplied")?
.stroked(with: theme["listBackgroundColor"]!, thickness: 3, quality: 1)
.withRenderingMode(.alwaysTemplate)

let imageView = UIImageView(image: image)
imageView.tintColor = theme["listBackgroundColor"]!

return imageView
} else if message.forwarded {
return UIImage(named: "pmforwarded")
let image = UIImage(named: "pmforwarded")?
.stroked(with: theme["listBackgroundColor"]!, thickness: 3, quality: 1)
.withRenderingMode(.alwaysTemplate)

let imageView = UIImageView(image: image)
imageView.tintColor = theme["listBackgroundColor"]!

return imageView
} else if !message.seen {
return UIImage(named: "newpm")
let image = UIImage(named: "newpm")
let imageView = UIImageView(image: image)

return imageView
} else {
return nil
}
Expand Down
15 changes: 13 additions & 2 deletions App/Data Sources/ThreadListDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,16 @@ extension ThreadListDataSource: UITableViewDataSource {
}
else {
text = String(format: LocalizedString("thread-list.posted-by"), thread.author?.username ?? "")
}/* killed by text */

var killedByFont: UIFont

if Theme.defaultTheme().roundedFonts {
killedByFont = roundedFont(ofSize: 13, weight: .semibold)
} else {
killedByFont = UIFont.systemFont(ofSize: 13, weight: .medium)
}

return NSAttributedString(string: text, attributes: [
.font: killedByFont,
.foregroundColor: theme[color: "listSecondaryTextColor"]!])
Expand All @@ -188,8 +191,16 @@ extension ThreadListDataSource: UITableViewDataSource {
if let tweaks = tweaks, tweaks.showRatingsAsThreadTags {
return nil
}

return thread.ratingImageName.flatMap { UIImage(named: $0) }

return thread.ratingImageName.flatMap {
if $0 != "Vote0.0" {
return UIImage(named: "Vote0")!
.withTintColor(Theme.defaultTheme()["ratingIconEmptyColor"]!)
.mergeWith(topImage: UIImage(named: $0)!)
}
return UIImage(named: "Vote0")!
.withTintColor(Theme.defaultTheme()["ratingIconEmptyColor"]!)
}
}(),
secondaryTagImageName: {
if !showsTagAndRating {
Expand Down
120 changes: 116 additions & 4 deletions App/Extensions/UIKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -181,15 +181,15 @@ extension UIImage {
return UIImage(cgImage: imageBitmapContext, scale: self.scale, orientation: UIImage.Orientation.up)
}
}

// THREAD TITLE
extension UINavigationItem {
/// A replacement label for the title that shows two lines on iPhone.
var titleLabel: UILabel {
if let label = titleView as? UILabel { return label }
let label = UILabel(frame: CGRect(x: 0, y: 0, width: 375, height: 44))
label.autoresizingMask = [.flexibleWidth, .flexibleHeight]
let label = UILabel(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.minY, height: 44))
// label.autoresizingMask = [.flexibleWidth, .flexibleHeight]
label.textAlignment = .center
label.textColor = .white
label.textColor = Theme.defaultTheme()["navigationBarTextColor"]!
label.accessibilityTraits.insert(UIAccessibilityTraits.header)

var font: UIFont
Expand All @@ -200,10 +200,13 @@ extension UINavigationItem {
}

switch UIDevice.current.userInterfaceIdiom {
/* thread title posts view text */
case .pad:
label.font = font
// label.font = UIFont.systemFont(ofSize: 17)
default:
label.font = font
// label.font = UIFont.systemFont(ofSize: 13)
label.numberOfLines = 2
}
titleView = label
Expand Down Expand Up @@ -403,3 +406,112 @@ extension UIViewController {
return nil
}
}

public extension UIImage {

/**
Returns the flat colorized version of the image, or self when something was wrong
- Parameters:
- color: The colors to user. By defaut, uses the ``UIColor.white`
- Returns: the flat colorized version of the image, or the self if something was wrong
*/
func colorized(with color: UIColor = .white) -> UIImage {
UIGraphicsBeginImageContextWithOptions(size, false, scale)

defer {
UIGraphicsEndImageContext()
}

guard let context = UIGraphicsGetCurrentContext(), let cgImage = cgImage else { return self }


let rect = CGRect(x: 0, y: 0, width: size.width, height: size.height)

color.setFill()
context.translateBy(x: 0, y: size.height)
context.scaleBy(x: 1.0, y: -1.0)
context.clip(to: rect, mask: cgImage)
context.fill(rect)

guard let colored = UIGraphicsGetImageFromCurrentImageContext() else { return self }

return colored
}

/**
Returns the stroked version of the fransparent image with the given stroke color and the thickness.
- Parameters:
- color: The colors to user. By defaut, uses the ``UIColor.white`
- thickness: the thickness of the border. Default to `2`
- quality: The number of degrees (out of 360): the smaller the best, but the slower. Defaults to `10`.
- Returns: the stroked version of the image, or self if something was wrong
*/

func stroked(with color: UIColor = .white, thickness: CGFloat = 2, quality: CGFloat = 10) -> UIImage {

guard let cgImage = cgImage else { return self }

// Colorize the stroke image to reflect border color
let strokeImage = colorized(with: color)

guard let strokeCGImage = strokeImage.cgImage else { return self }

/// Rendering quality of the stroke
let step = quality == 0 ? 10 : abs(quality)

let oldRect = CGRect(x: thickness, y: thickness, width: size.width, height: size.height).integral
let newSize = CGSize(width: size.width + 2 * thickness, height: size.height + 2 * thickness)
let translationVector = CGPoint(x: thickness, y: 0)


UIGraphicsBeginImageContextWithOptions(newSize, false, scale)

guard let context = UIGraphicsGetCurrentContext() else { return self }

defer {
UIGraphicsEndImageContext()
}
context.translateBy(x: 0, y: newSize.height)
context.scaleBy(x: 1.0, y: -1.0)
context.interpolationQuality = .high

for angle: CGFloat in stride(from: 0, to: 360, by: step) {
let vector = translationVector.rotated(around: .zero, byDegrees: angle)
let transform = CGAffineTransform(translationX: vector.x, y: vector.y)

context.concatenate(transform)

context.draw(strokeCGImage, in: oldRect)

let resetTransform = CGAffineTransform(translationX: -vector.x, y: -vector.y)
context.concatenate(resetTransform)
}

context.draw(cgImage, in: oldRect)

guard let stroked = UIGraphicsGetImageFromCurrentImageContext() else { return self }

return stroked
}
}


extension CGPoint {
/**
Rotates the point from the center `origin` by `byDegrees` degrees along the Z axis.
- Parameters:
- origin: The center of he rotation;
- byDegrees: Amount of degrees to rotate around the Z axis.
- Returns: The rotated point.
*/
func rotated(around origin: CGPoint, byDegrees: CGFloat) -> CGPoint {
let dx = x - origin.x
let dy = y - origin.y
let radius = sqrt(dx * dx + dy * dy)
let azimuth = atan2(dy, dx) // in radians
let newAzimuth = azimuth + byDegrees * .pi / 180.0 // to radians
let x = origin.x + radius * cos(newAzimuth)
let y = origin.y + radius * sin(newAzimuth)
return CGPoint(x: x, y: y)
}
}
12 changes: 12 additions & 0 deletions App/Main/RootViewControllerStack.swift
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,18 @@ extension RootViewControllerStack {

// This ugliness fixes the resulting navigation controller's toolbar appearing empty despite having the correct items. (i.e. none of the items' views are in the toolbar's view hierarchy.) Presumably if some fix is discovered for the grey screen mentioned atop kindaFixReallyAnnoyingSplitViewHideSidebarInLandscapeBehavior, I think this will be fixed too. Or at least it's worth testing out.
let toolbar = primaryNavigationController.toolbar

if #available(iOS 14.0, *) {
let barAppearance = UIToolbarAppearance()
barAppearance.backgroundColor = .clear

// below two lines prevent weird unwanted grey bar from appearing. can be confused with "hairline" border!
barAppearance.shadowImage = UIImage()
barAppearance.backgroundImage = UIImage()

toolbar?.standardAppearance = barAppearance
}

let items = toolbar?.items
toolbar?.items = nil
toolbar?.items = items
Expand Down
25 changes: 25 additions & 0 deletions App/Misc/HTMLRenderingHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,31 @@ extension HTMLDocument {
}
}

/**
Modifies the document in place, adding an additional element to quote blocks for quote-post.png.
This has been done to facilitate more styling than is possible with background-image in css, namely color changes.
The regular CSS files contain the styling required for this feature, applied against this injected element.
*/
func addQuoteIcons() {
for div in nodes(matchingSelector: ".bbc-block") {
let quoteposticon = HTMLElement(
tagName: "span",
attributes: [
"class": "quotepost-span"
])
div.addChild(quoteposticon)

let quoteHeaderSpan = HTMLElement(tagName: "span", attributes: [
"class": "quoteheader"])

for quoteheaderLink in div.nodes(matchingSelector: ".quote_link") {
let link = HTMLDocument(string: quoteheaderLink.parentElement!.innerHTML)
quoteHeaderSpan.addChild(link)
div.replace(child: quoteheaderLink.parent!, with: quoteHeaderSpan)
}
}
}

/**
Modifies the document in place, adding an additional class to quote blocks if the quoted post ID ends in 420.
The regular CSS files contain the styling required for this feature, applied against this injected class.
Expand Down
2 changes: 1 addition & 1 deletion App/Model Presentation/Thread+Presentation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ extension AwfulThread {
/// Name of an image suitable for showing the rating below the thread tag.
var ratingImageName: String? {
let rounded = lroundf(rating).clamp(0...5)
return rounded != 0 ? "rating\(rating)" : nil
return rounded != -1 ? "Vote\(rating)" : nil
}

/// Name of an image suitable for showing the rating as the thread tag itself.
Expand Down
Loading

0 comments on commit 8d92fb3

Please sign in to comment.