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

Changed Default Icon, Organized App Icons #735

Closed
wants to merge 3 commits into from
Closed
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
4 changes: 4 additions & 0 deletions Mlem.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@
CD05E7792A4E381A0081D102 /* PostSize.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD05E7782A4E381A0081D102 /* PostSize.swift */; };
CD05E77F2A4F263B0081D102 /* Menu Function.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD05E77E2A4F263B0081D102 /* Menu Function.swift */; };
CD05E7812A4F7A4B0081D102 /* Inbox Tracker.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD05E7802A4F7A4B0081D102 /* Inbox Tracker.swift */; };
CD06123A2AF09FAB00BD0EC7 /* AlternativeIconLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD0612392AF09FAB00BD0EC7 /* AlternativeIconLabel.swift */; };
CD0BE42F2A65A73600314B24 /* Haptic Manager.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD0BE42E2A65A73600314B24 /* Haptic Manager.swift */; };
CD1446182A58FC3B00610EF1 /* InfoStackView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD1446172A58FC3B00610EF1 /* InfoStackView.swift */; };
CD14461B2A5A4B6D00610EF1 /* PostSettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD14461A2A5A4B6D00610EF1 /* PostSettingsView.swift */; };
Expand Down Expand Up @@ -800,6 +801,7 @@
CD05E7782A4E381A0081D102 /* PostSize.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostSize.swift; sourceTree = "<group>"; };
CD05E77E2A4F263B0081D102 /* Menu Function.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Menu Function.swift"; sourceTree = "<group>"; };
CD05E7802A4F7A4B0081D102 /* Inbox Tracker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Inbox Tracker.swift"; sourceTree = "<group>"; };
CD0612392AF09FAB00BD0EC7 /* AlternativeIconLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlternativeIconLabel.swift; sourceTree = "<group>"; };
CD0BE42E2A65A73600314B24 /* Haptic Manager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Haptic Manager.swift"; sourceTree = "<group>"; };
CD1446172A58FC3B00610EF1 /* InfoStackView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InfoStackView.swift; sourceTree = "<group>"; };
CD14461A2A5A4B6D00610EF1 /* PostSettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostSettingsView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1060,6 +1062,7 @@
children = (
CD4E98A22A69BEDC0026C4D9 /* IconSettingsView.swift */,
CD4E98A02A69BE980026C4D9 /* AlternativeIconCell.swift */,
CD0612392AF09FAB00BD0EC7 /* AlternativeIconLabel.swift */,
);
path = Icon;
sourceTree = "<group>";
Expand Down Expand Up @@ -2987,6 +2990,7 @@
03B643572A6864CD00F65700 /* TabBarSettingsView.swift in Sources */,
CDF842642A49EAFA00723DA0 /* GetPersonMentions.swift in Sources */,
6D405B052A43E82300C65F9C /* Sidebar Header.swift in Sources */,
CD06123A2AF09FAB00BD0EC7 /* AlternativeIconLabel.swift in Sources */,
50811B302A92049B006BA3F2 /* APICommunityView+Mock.swift in Sources */,
CDA217F32A63202600BDA173 /* NSFW Overlay.swift in Sources */,
6372184E2A3A2AAD008C4816 /* APIPersonView.swift in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion Mlem/Assets.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"images" : [
{
"filename" : "mlemmy-brighter.png",
"filename" : "logo.png",
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions Mlem/Assets.xcassets/Icons/Aaron Schneider/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
6 changes: 6 additions & 0 deletions Mlem/Assets.xcassets/Icons/Clays/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"images" : [
{
"filename" : "mlemmy-brighter.png",
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
6 changes: 6 additions & 0 deletions Mlem/Assets.xcassets/Icons/Eric Andrews/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
6 changes: 6 additions & 0 deletions Mlem/Assets.xcassets/Icons/Sjmarf/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"images" : [
{
"filename" : "logo.png",
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion Mlem/Assets.xcassets/logo.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"images" : [
{
"filename" : "mlem-reasonable.png",
"filename" : "logo.png",
"idiom" : "universal"
}
],
Expand Down
Binary file added Mlem/Assets.xcassets/logo.imageset/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
40 changes: 1 addition & 39 deletions Mlem/Extensions/AlternativeIconCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,47 +17,9 @@ struct AlternativeIconCell: View {
await setAppIcon(icon.id)
}
} label: {
HStack {
getImage()
.resizable()
.scaledToFit()
.frame(width: AppConstants.appIconSize, height: AppConstants.appIconSize)
.foregroundColor(Color.white)
.cornerRadius(AppConstants.appIconCornerRadius)
.overlay {
RoundedRectangle(cornerRadius: AppConstants.appIconCornerRadius)
.stroke(Color(.secondarySystemBackground), lineWidth: 1)
}
VStack(alignment: .leading) {
Text(icon.name)
if let author = icon.author {
Text(author)
.font(.footnote)
.foregroundColor(.secondary)
}
}
Spacer()
if icon.selected {
Image(systemName: Icons.success)
}
}
AlternativeIconLabel(icon: icon)
}.accessibilityElement(children: .combine)
}

func getImage() -> Image {
let image = {
guard let id = icon.id else {
return Bundle.main.iconFileName
.flatMap { UIImage(named: $0) }
.map {
Image(uiImage: $0)
} ?? Image(systemName: Icons.noFile)
}
return Image(uiImage: UIImage(named: id) ?? UIImage(imageLiteralResourceName: id))
}

return image()
}
}

struct AlternativeIconCellPreview: PreviewProvider {
Expand Down
76 changes: 50 additions & 26 deletions Mlem/Extensions/IconSettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,54 +28,70 @@ struct IconSettingsView: View {

var body: some View {
List {
ForEach(getAllIcons()) { icon in
AlternativeIconCell(icon: icon, setAppIcon: setAppIcon)
}
iconsList()
}
.fancyTabScrollCompatible()
}

@ViewBuilder
func iconsList() -> some View {
let allIcons = getAllIcons()
let creators = allIcons.keys.sorted()

ForEach(creators, id: \.self) { creator in
if let icons = allIcons[creator], !icons.isEmpty {
DisclosureGroup {
ForEach(icons) { icon in
AlternativeIconCell(icon: icon, setAppIcon: setAppIcon)
}
} label: {
AlternativeIconLabel(icon: AlternativeIcon(id: icons[0].id, name: creator, author: nil, selected: false))
}
}
}
}

func getAllIcons() -> [AlternativeIcon] {
guard let iconsBundle = Bundle.main.object(forInfoDictionaryKey: "CFBundleIcons") as? [String: Any?]
else { return [] }
func getAllIcons() -> [String: [AlternativeIcon]] {
guard let iconsBundle = Bundle.main.object(forInfoDictionaryKey: "CFBundleIcons") as? [String: Any?] else { return [:] }

guard let altIcons = iconsBundle["CFBundleAlternateIcons"] as? [String: Any?]
else { return [] }
guard let altIcons = iconsBundle["CFBundleAlternateIcons"] as? [String: Any?] else { return [:] }

let currentIconSelection = UIApplication.shared.alternateIconName

var allIcons = [
AlternativeIcon(id: nil, name: "Mlem", author: "By Clay/s", selected: currentIconSelection == nil)
]
allIcons.append(contentsOf: altIcons.keys.map { key in
var ret: [String: [AlternativeIcon]] = .init()

altIcons.keys.forEach { key in
// parse AlternativeIcon from icon data
print("found icon: \(key)")
let match = key.firstMatch(of: iconFinder)
let name = (match?.output.1 != nil) ? String(match!.output.1) : key
var author = (match?.output.2 != nil) ? "By \(String(match!.output.2))" : ""
var author = (match?.output.2 != nil) ? "\(String(match!.output.2))" : "Anonymous"
author = author.replacingOccurrences(of: "Clays", with: "Clay/s")
return AlternativeIcon(id: key, name: name, author: author, selected: currentIconSelection == key)
}.filter {
if let id = IconId(rawValue: $0.id ?? "Default"),
let requiredEasterFlag = easterDependentIcons[id] {
return easterTracker.flags.contains(requiredEasterFlag)
let icon = AlternativeIcon(id: key, name: name, author: author, selected: currentIconSelection == key)
// if we should show this icon, add to map
if shouldShowIcon(icon: icon) {
ret[author, default: []].append(icon)
}
return true
}.sorted(by: { lhs, rhs in
lhs.name < rhs.name
}))
}

ret.keys.forEach { key in
ret[key] = ret[key]?.sorted {
$0.name < $1.name
}
}

return allIcons
return ret
}

// static func getCurrentIcon() -> some View {
static func getCurrentIcon() -> Image {
let icon = AlternativeIcon(
id: UIApplication.shared.alternateIconName,
name: "",
author: "",
selected: false
)
return AlternativeIconCell(icon: icon) { _ in }.getImage()
return AlternativeIconLabel(icon: icon).getImage()
}

@MainActor
Expand All @@ -87,6 +103,14 @@ struct IconSettingsView: View {
// do nothing!
}
}

private func shouldShowIcon(icon: AlternativeIcon) -> Bool {
if let id = IconId(rawValue: icon.id ?? "Default"),
let requiredEasterFlag = easterDependentIcons[id] {
return easterTracker.flags.contains(requiredEasterFlag)
}
return true
}
}

struct AlternativeIconsPreview: PreviewProvider {
Expand Down
Loading